Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add location for storage class declaration #14720

Merged
merged 1 commit into from Mar 3, 2023
Merged

Conversation

lucica28
Copy link
Contributor

Currently there is no possibility of setting the location for a StorageClassDeclaration. This pr creates a way for StorageClassDeclarations to be instantiated with a location

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @lucica28! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#14720"

@lucica28 lucica28 force-pushed the scd-loc branch 2 times, most recently from b33b3ff to c81cdfc Compare December 19, 2022 17:45
@@ -1274,6 +1274,13 @@ struct ASTBase
this.stc = stc;
}

final extern (D) this(StorageClass stc, Dsymbols* decl, const ref Loc loc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention in dmd is normally Loc as the first constructor argument

@@ -269,6 +269,12 @@ extern (C++) class Dsymbol : ASTNode
loc = Loc(null, 0, 0);
}

final extern (D) this(const ref Loc loc) nothrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, why is this needed? Can't you just set the loc in the constructor in attrib.d?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because loc field is declared const, so it can be set only by a constructor
https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dsymbol.d#L258

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which you are declaring in StorageClassDeclaration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, why is this needed? Can't you just set the loc in the constructor in attrib.d?

in the constructor in attrib.d

extern (D) this(const ref Loc loc, StorageClass stc, Dsymbols* decl)
{
super(loc, decl);
this.stc = stc;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a constructor. You can set the loc here and ditch the dsymbol and attrib constructors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I initially tried, but this code

extern (D) this(const ref Loc loc, StorageClass stc, Dsymbols* decl)
    {
        super(decl);
        this.stc = stc;
        this.loc = loc;
    }

Does not work, it results in the following error: Error: cannot modify constexpressionthis.loc``

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can use the existing constructor in AttribDeclaration, but pass a null identifier.

@RazvanN7
Copy link
Contributor

RazvanN7 commented Jan 5, 2023

ping @lucica28

@lucica28
Copy link
Contributor Author

lucica28 commented Mar 2, 2023

ping @lucica28

@RazvanN7 I know it's been a minute since I opened this PR, but I think at this point it should be good to go, isn't that the case?

@RazvanN7 RazvanN7 merged commit f9c78b7 into dlang:master Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants