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 8 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.

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).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, you are correct. You could do the same as above (check that literal is at and then expectToken(Identifier), but then you'd just get the generic error Expected identifier but got..., and since we're not introducing new tokens (at, layout), it makes sense for error to be specifically tailored like it is here.

One suggestion I could make is to have the error follow the general expectToken() convention, I.e. Expected 'at' but got '..', since I assume we're gonna introduce layout and at tokens (as well as transient) for the next breaking release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One suggestion I could make is to have the error follow the general expectToken() convention

Yeah, I will make this change.

Copy link

This pull request is stale because it has been open for 14 days with no activity.
It will be closed in 7 days unless the stale label is removed.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Nov 14, 2024
@matheusaaguiar matheusaaguiar removed the stale The issue/PR was marked as stale because it has been open for too long. label Nov 15, 2024
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.

3 participants