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

Implement parsing of override keyword #7233

Merged
merged 1 commit into from
Aug 26, 2019
Merged

Implement parsing of override keyword #7233

merged 1 commit into from
Aug 26, 2019

Conversation

Marenz
Copy link
Contributor

@Marenz Marenz commented Aug 13, 2019

Doesn't break any compability yet, so still targeting develop at this point.
prepares for #5424

@chriseth
Copy link
Contributor

Needs changes in ast export (and import...)

@@ -624,6 +625,7 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public
ImplementationOptional(_body != nullptr),
m_stateMutability(_stateMutability),
m_isConstructor(_isConstructor),
m_isOverriding(_isOverriding),
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe just overriding?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@chriseth
Copy link
Contributor

Looks good otherwise!

@Marenz
Copy link
Contributor Author

Marenz commented Aug 13, 2019

updated

@leonardoalt
Copy link
Member

Tests failing, I think expectations need to be updated.

@Marenz
Copy link
Contributor Author

Marenz commented Aug 14, 2019

fixed now. Had to investigate another bug that turned out to be just due to a missing make clean

@chriseth
Copy link
Contributor

Are you planning to change this again to support the arguments?

@Marenz
Copy link
Contributor Author

Marenz commented Aug 15, 2019

Yes, currently working on exactly that

if (m_scanner->currentToken() == Token::LParen)
{
m_scanner->next();
while (m_scanner->currentToken() == Token::Identifier)
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

@ekpyron ekpyron Aug 15, 2019

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

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" :
Copy link
Member

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.

@Marenz
Copy link
Contributor Author

Marenz commented Aug 19, 2019

Updated. Should fix all your concerns :>

@@ -604,6 +604,28 @@ class CallableDeclaration: public Declaration, public VariableScope
ASTPointer<ParameterList> m_returnParameters;
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Please document.

void accept(ASTVisitor& _visitor) override;
void accept(ASTConstVisitor& _visitor) const override;

///< Returns the list of specific overrides, if any
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
///< Returns the list of specific overrides, if any
/// @returns the list of specific overrides, if any

void accept(ASTConstVisitor& _visitor) const override;

///< Returns the list of specific overrides, if any
std::vector<ASTPointer<UserDefinedTypeName>> overrides() const { return m_overrides; }
Copy link
Contributor

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,
Copy link
Contributor

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?

@Marenz Marenz changed the base branch from develop to develop_060 August 19, 2019 10:17
@chriseth
Copy link
Contributor

Please also update grammar.txt

@@ -493,6 +522,13 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN
else
result.stateMutability = parseStateMutability();
}
else if (token == Token::Override)
Copy link
Contributor

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,
Copy link
Contributor

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.

@Marenz
Copy link
Contributor Author

Marenz commented Aug 19, 2019

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

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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.

@chriseth
Copy link
Contributor

Hm, test seems to be failing, can you check, please?

@Marenz
Copy link
Contributor Author

Marenz commented Aug 19, 2019

The failing test is the thing I mentioned in the meeting.. it seems the order of values in an json array is not consistent

@Marenz
Copy link
Contributor Author

Marenz commented Aug 19, 2019

I'll take care of it

@Marenz
Copy link
Contributor Author

Marenz commented Aug 20, 2019

This will now work once current develop is merged into develop_060

@Marenz Marenz force-pushed the override-5424 branch 2 times, most recently from f4f0f3e to a624237 Compare August 26, 2019 08:31
@Marenz
Copy link
Contributor Author

Marenz commented Aug 26, 2019

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

@Marenz
Copy link
Contributor Author

Marenz commented Aug 26, 2019

I investigated the doc failure. It's caused by a change @ekpyron sponsored. solhint runs on older grammar and thus will keep failing for this until we released 060 and they have updated their grammar.

So it's safe to ignore this for this PR.

Copy link
Collaborator

@erak erak left a 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.

@Marenz
Copy link
Contributor Author

Marenz commented Aug 26, 2019

I forgot to add one test case that is now added.

@Marenz Marenz merged commit 25a3a83 into develop_060 Aug 26, 2019
@Marenz Marenz deleted the override-5424 branch August 26, 2019 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants