-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Implement parsing of override keyword #7233
Conversation
Needs changes in ast export (and import...) |
libsolidity/ast/AST.h
Outdated
@@ -624,6 +625,7 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public | |||
ImplementationOptional(_body != nullptr), | |||
m_stateMutability(_stateMutability), | |||
m_isConstructor(_isConstructor), | |||
m_isOverriding(_isOverriding), |
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.
maybe just overriding
?
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.
wouldn't that be inconsistent with the existing naming isContructor
and isIndexed
etc?
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.
actually the coding style says that is
prefixes should be avoided, but yeah, we have a lot of them here.
libsolidity/ast/AST.h
Outdated
@@ -753,6 +760,7 @@ class VariableDeclaration: public Declaration | |||
bool m_isStateVariable; ///< Whether or not this is a contract state variable | |||
bool m_isIndexed; ///< Whether this is an indexed variable (used by events). | |||
bool m_isConstant; ///< Whether the variable is a compile-time constant. | |||
bool m_isOverriding; ///< whether the variable is overriding a public base class variable |
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.
bool m_isOverriding; ///< whether the variable is overriding a public base class variable | |
bool m_isOverriding; ///< whether the variable is overriding an external base contract function |
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.
A state variable can override a function fro the base contract?
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.
The only situation where override
is meaningful for state variables is if the getter of the state variable overrides a function, and for that, the function in the base contract has to be external.
Looks good otherwise! |
updated |
Tests failing, I think expectations need to be updated. |
fixed now. Had to investigate another bug that turned out to be just due to a missing |
Are you planning to change this again to support the arguments? |
Yes, currently working on exactly that |
libsolidity/parsing/Parser.cpp
Outdated
if (m_scanner->currentToken() == Token::LParen) | ||
{ | ||
m_scanner->next(); | ||
while (m_scanner->currentToken() == Token::Identifier) |
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.
What happens for let's say override(A, address)
?
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 using while (m_scanner->currentToken() != Token::RParen)
should fix that.
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.
That might still fail (resp. "fail to fail") for override(A,)
, right? (which could be fixed by expectToken(Token::RParen)
after the loop - by the way expectToken
advances by default, doesn't it? Which means the m->scanner->next()
after the expectToken(Token::Comma);
might also have to be removed.)
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.
Both should be test cases in any case.
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.
Also override()
should be a test case - I'd disallow that as well, but we could also say it's fine.
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.
Oh of course, I did not mean that just modifying the while condition is the only required change.
"modifiers" : [], | ||
"name" : "faa", | ||
"nodeType" : "FunctionDefinition", | ||
"overrides" : |
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.
Yep, this swallowed the B
due to advancing after the expectToken
above.
Updated. Should fix all your concerns :> |
@@ -604,6 +604,28 @@ class CallableDeclaration: public Declaration, public VariableScope | |||
ASTPointer<ParameterList> m_returnParameters; | |||
}; | |||
|
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.
Please document.
libsolidity/ast/AST.h
Outdated
void accept(ASTVisitor& _visitor) override; | ||
void accept(ASTConstVisitor& _visitor) const override; | ||
|
||
///< Returns the list of specific overrides, if any |
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.
///< Returns the list of specific overrides, if any | |
/// @returns the list of specific overrides, if any |
libsolidity/ast/AST.h
Outdated
void accept(ASTConstVisitor& _visitor) const override; | ||
|
||
///< Returns the list of specific overrides, if any | ||
std::vector<ASTPointer<UserDefinedTypeName>> overrides() const { return m_overrides; } |
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.
Why not return by const&
?
@@ -613,6 +635,7 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public | |||
Declaration::Visibility _visibility, | |||
StateMutability _stateMutability, | |||
bool _isConstructor, | |||
ASTPointer<OverrideSpecifier> const& _overrides, |
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.
Does it make sense to move this all the way up to Declaration
?
Please also update grammar.txt |
libsolidity/parsing/Parser.cpp
Outdated
@@ -493,6 +522,13 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN | |||
else | |||
result.stateMutability = parseStateMutability(); | |||
} | |||
else if (token == Token::Override) |
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 should also take allowModifiers &&
, at least override
should not be allowed for function types, where allowModifiers
is set to false. Maybe allowModifiers
could be renamed.
@@ -540,6 +576,7 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable() | |||
header.visibility, |
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.
Could also add header.overrides
to the condition in line 520/556, I think.
fixed all points but this one, wasn't sure how you meant this |
libsolidity/ast/AST.h
Outdated
@@ -604,6 +604,32 @@ class CallableDeclaration: public Declaration, public VariableScope | |||
ASTPointer<ParameterList> m_returnParameters; | |||
}; | |||
|
|||
/** | |||
* Function override specifier. Consists of a single override keyword or a list of |
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.
* Function override specifier. Consists of a single override keyword or a list of | |
* Function override specifier. Consists of a single override keyword potentially followed by a parenthesized list of base contract names. |
Hm, test seems to be failing, can you check, please? |
The failing test is the thing I mentioned in the meeting.. it seems the order of values in an json array is not consistent |
I'll take care of it |
This will now work once current develop is merged into develop_060 |
f4f0f3e
to
a624237
Compare
I pushed some small fixes and rebased on latest develop_060. Here is the diff of my fixes only: https://github.com/ethereum/solidity/compare/aa0a53c0282391ae45dd7c118f918fea6ed72ac5..f4f0f3e84c2e2c02bb6319ab7418977260b5e3f6 |
I investigated the doc failure. It's caused by a change @ekpyron sponsored. So it's safe to ignore this for this PR. |
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.
Looks good! Need to track the removal of chk_docs_examples
from Circle for develop_060
as suggested by @ekpyron though.
I forgot to add one test case that is now added. |
Doesn't break any compability yet, so still targeting develop at this point.
prepares for #5424