Added location to user defined attributes#12524
Added location to user defined attributes#12524AsterMiha wants to merge 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @AsterMiha! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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 referencesYour 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 locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12524" |
src/dmd/parse.d
Outdated
| udas.push(exp); | ||
| udas.push(new AST.UadItem(udastart, exp, parens)); |
There was a problem hiding this comment.
And why can't exp have its loc set to udastart?
There was a problem hiding this comment.
Because udas can be written in any of these ways: @ e, @(e), @(e1, e2)
In the first 2 cases changing the loc of the exp would work but in the last it would be confusing to set all of them to the loc of '@', especially when the expressions are on different lines.
There was a problem hiding this comment.
I also think that introducing a new AST type to represent this is overkill, and will not scale well.
There was a problem hiding this comment.
That's a lot of changes to have the position so I wont give my mind on this aspect.
The changes requested are more about
- The coverage that is not really good.
- The style a bit inconsistent with the use of
isUadItem()and most importantly the name of the new node is not good. the offical name for those attribs are UDA, soUDAItemis better. - ASTBase declaration
| TupleExp te = cast(TupleExp)e; | ||
| eval(sc, te.exps, lastTag); | ||
| } | ||
| if (e.op == TOK.at) |
There was a problem hiding this comment.
However now I see that the way you write the cast is consistent with the other cast in the block.
|
I will not do an extended review of this, but the tests are a bit lacking. They need to include:
|
ef903b2 to
872e34c
Compare
|
@tungstenheart Renamed the node and added the ASTBase declaration. I forgot to remove some of the code from previous attempts and that caused the coverage issues, but I fixed that now. Also added a couple more tests. |
|
thanks, (someone can cancel my request for changes) |
| { | ||
| // None of these can be value parameters | ||
| if (e.op == TOK.tuple || e.op == TOK.scope_ || | ||
| if (e.op == TOK.tuple || e.op == TOK.at || e.op == TOK.scope_ || |
There was a problem hiding this comment.
I am confused by this addition. What do UDAs have to do with value parameters? Do you have a code snippet that is directly affected by this?
There was a problem hiding this comment.
Semantic2 attempts to interpret all expressions in UserAttributeDeclaration [1]. Now that the actual expressions are inside a UDAItem node we need to reach its contents first. An alternative would be to add UDAItem to the Interpretor visitor to unpack the node there.
[1]
Lines 573 to 574 in 2453350
RazvanN7
left a comment
There was a problem hiding this comment.
Looks good to me. I'll wait for @jacob-carlborg 's review
I've already done the review I'll be doing. |
|
SInce this was not discussed (here at least), what is the value added , what are the use cases ? |
|
Currently, UDAs do not contain the location, as a result third-party tools using dmd-as-a-lib that want to properly expose the location of UDAs cannot do that. This PR fixes that. More info: #11788 (comment) |
ghost
left a comment
There was a problem hiding this comment.
see comments. Mostly the assert that will avoid to merge possibly dead code.
| } | ||
| } | ||
|
|
||
| extern (C++) class UDAItem : Expression |
There was a problem hiding this comment.
No new class should be introduced without a proper documentation. Someone should be able to look at this code and know why this class exists and when it should be used / where one can expect to find it in the tree.
src/dmd/parse.d
Outdated
| udas.push(exp); | ||
| udas.push(new AST.UadItem(udastart, exp, parens)); |
There was a problem hiding this comment.
I also think that introducing a new AST type to represent this is overkill, and will not scale well.
Created a new node (UadItem) to preserve the location of all user defined attributes