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

Parser support for explicit storage locations #15463

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

matheusaaguiar
Copy link
Collaborator

First step for #597.

@@ -591,6 +593,7 @@ class ContractDefinition: public Declaration, public StructurallyDocumented, pub
std::vector<ASTPointer<ASTNode>> m_subNodes;
ContractKind m_contractKind;
bool m_abstract{false};
ASTPointer<Expression> m_storageBaseLocationExpression;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we create a dedicated AST node for it?

);

advance();
return parseExpression();
Copy link
Collaborator Author

@matheusaaguiar matheusaaguiar Sep 30, 2024

Choose a reason for hiding this comment

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

I guess it should be something more specific, because expression will accept anything. Or is it fine?

Copy link
Member

@r0qs r0qs Sep 30, 2024

Choose a reason for hiding this comment

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

Yes, I also believe that we should have something more specific. If I recall correctly, it must be a constant expression that can be evaluate at compile-time. So maybe we should have a new parse function that is restricted to TokenTraits::isArithmeticOp, Literals and the erc7201 helper only.

Copy link
Collaborator Author

@matheusaaguiar matheusaaguiar Sep 30, 2024

Choose a reason for hiding this comment

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

I am assuming that we will check those kind of things later (constant, compile-time eval, etc) at type checking phase.
I am worried about parsing something weird (like a function declaration or a nested contract declaration), but I think I should look more closely to the behaviour of parseExpression to get a better feeling for that.

@matheusaaguiar matheusaaguiar marked this pull request as ready for review October 14, 2024 18:34
Comment on lines +375 to +378
solAssert(m_scanner->currentLiteral() == "layout");
expectToken(Token::Identifier);
if (
m_scanner->currentToken() != Token::Identifier ||
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Identifier check is redundant here - it'll throw a fatal parsing error in expectToken(...) if it's not an identifier.

commented previously here.

@nikola-matic , I am not sure if you were suggesting that we use expectToken instead of if to check the identifier with literal at.
I used if here because we also need to check for the literal value at.
Or were you referring to expectToken in line 376? (in which case, it actually is consuming the identifier with literal layout).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants