-
Notifications
You must be signed in to change notification settings - Fork 53
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
Change DeclarativeExpression's management of visibility and storage specifiers #57
Change DeclarativeExpression's management of visibility and storage specifiers #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this goes in a good direction, but give me a few days to better understand the tradeoffs.
In terms of style, I would have gone further and cleaned up the SourceElement rule, moving the logic to a StateVariableDeclaration.
exp.left.type === 'DeclarativeExpression' && | ||
exp.left.storage_location === null | ||
) | ||
}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really a fan of this. It complicates the grammar unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. It's ugly. But look down the AssignmentExpression path. Won't enforcing this distinction involve something like the above or writing separate path that reaches quite a way down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily. Just a single rule matching the official specification:
https://github.com/federicobond/solidity-antlr4/blob/master/Solidity.g4#L57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So get rid of AssignmentExpression
up there and replace with a StateVariableDeclaration
that has an optional = expression
, visibility and constant specifiers, no storage_location field, a value
field that may be an expression or null, and don't preserve the equality operator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would also get rid of nasty stuff like uint foo += 1;
getting parsed incorrectly as a state variable declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll revise to that. We have all the pieces here. Getting slightly closer.
@federicobond Made those revisions and cleaned things up a bit. Also updated AST gist |
This PR is based on @federicobond's review of PR #44. He suggested the parser should distinguish between StateVariable declarations (which may be constant and have an optional visibility specifier) and local declarations which only have an optional storage specifier. The solution discussed in #44 involved moving constant and visibility handling to a new
StateVariableDeclaration
rule underSourceElement
and leaving DeclarativeExpression for locals.The PR below takes a slightly different approach, in part because subsequent developments in #56. It keeps all specifier management in the DelcarativeExpression and adds a check at
SourceElement --> AssignmentExpression
which verifies thatAssignmentExpression
's left node does not have a storage specifier. It also modifies the entry forDeclarativeExpression
atSourceElement
to return only the node, in preparation for whatever will be done for #56.Additionally, one line has been commented out in the existing
.sol
test-bed because solc doesn't seem to compile it.In sum: PR fixes #26. StateVariables can no longer be assigned a storage specifier and locals can no longer be designated
constant
or have visibility specifiers.A gist of the AST for the added test can be found here.
@federicobond I'm about to add you as a collaborator on my fork of solidty-parser so you are free to revise / simplify this PR as you wish. I'm also happy to update with any suggestions you have. Also happy to close if this is not the solution you're looking for. 😄
Build not included.