-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Add modifier areas #3939
Add modifier areas #3939
Changes from all commits
bb1c74a
b66d15f
fd81f00
06baee1
17524b3
69d6bef
812e4de
0c6c673
0c1faa7
bac10ee
4c9d283
9109367
9bd8646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,7 +385,8 @@ class ContractDefinition: public Declaration, public Documented | |
std::vector<EnumDefinition const*> definedEnums() const { return filteredNodes<EnumDefinition>(m_subNodes); } | ||
std::vector<VariableDeclaration const*> stateVariables() const { return filteredNodes<VariableDeclaration>(m_subNodes); } | ||
std::vector<ModifierDefinition const*> functionModifiers() const { return filteredNodes<ModifierDefinition>(m_subNodes); } | ||
std::vector<FunctionDefinition const*> definedFunctions() const { return filteredNodes<FunctionDefinition>(m_subNodes); } | ||
std::vector<FunctionDefinition const*> definedFunctions() const; | ||
std::vector<ModifierArea const*> modifierAreas() const { return filteredNodes<ModifierArea>(m_subNodes); } | ||
std::vector<EventDefinition const*> events() const { return filteredNodes<EventDefinition>(m_subNodes); } | ||
std::vector<EventDefinition const*> const& interfaceEvents() const; | ||
bool isLibrary() const { return m_contractKind == ContractKind::Library; } | ||
|
@@ -599,16 +600,9 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public | |
ASTPointer<ParameterList> const& _parameters, | ||
std::vector<ASTPointer<ModifierInvocation>> const& _modifiers, | ||
ASTPointer<ParameterList> const& _returnParameters, | ||
ASTPointer<Block> const& _body | ||
): | ||
CallableDeclaration(_location, _name, _visibility, _parameters, _returnParameters), | ||
Documented(_documentation), | ||
ImplementationOptional(_body != nullptr), | ||
m_stateMutability(_stateMutability), | ||
m_isConstructor(_isConstructor), | ||
m_functionModifiers(_modifiers), | ||
m_body(_body) | ||
{} | ||
ASTPointer<Block> const& _body, | ||
ModifierArea* const& _modifierArea = nullptr | ||
); | ||
|
||
virtual void accept(ASTVisitor& _visitor) override; | ||
virtual void accept(ASTConstVisitor& _visitor) const override; | ||
|
@@ -620,6 +614,8 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public | |
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; } | ||
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); } | ||
Block const& body() const { solAssert(m_body, ""); return *m_body; } | ||
ModifierArea* modifierArea() const { return m_modifierArea; } | ||
|
||
virtual bool isVisibleInContract() const override | ||
{ | ||
return Declaration::isVisibleInContract() && !isConstructor() && !isFallback(); | ||
|
@@ -646,6 +642,7 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public | |
bool m_isConstructor; | ||
std::vector<ASTPointer<ModifierInvocation>> m_functionModifiers; | ||
ASTPointer<Block> m_body; | ||
ModifierArea* m_modifierArea; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was something @ekpyron mentioned. We can''t use a smart pointer here because then there is a dependency loop and neither ModifierArea nor FunctionDefinition would be destructed. |
||
}; | ||
|
||
/** | ||
|
@@ -723,6 +720,42 @@ class VariableDeclaration: public Declaration | |
Location m_location; ///< Location of the variable if it is of reference type. | ||
}; | ||
|
||
class ModifierArea: public ASTNode | ||
{ | ||
public: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think indentation here is off. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied it from surrounding classes |
||
ModifierArea( | ||
SourceLocation const& _location, | ||
std::vector<ASTPointer<ModifierInvocation>> const& _modifiers, | ||
Declaration::Visibility const& _visibility, | ||
StateMutability const& _mutability, | ||
ASTPointer<std::vector<ASTPointer<FunctionDefinition>>> const& _functions, | ||
ASTPointer<std::vector<ASTPointer<ModifierArea>>> const& _subAreas, | ||
ModifierArea* _parent = nullptr | ||
); | ||
|
||
virtual void accept(ASTVisitor& _visitor) override; | ||
virtual void accept(ASTConstVisitor& _visitor) const override; | ||
|
||
/// Returns only modifiers defined | ||
std::vector<ASTPointer<ModifierInvocation>> const& declaredModifiers() const { return m_declaredModifiers; } | ||
/// Returns all modifiers in effect (including ones from parents) | ||
std::vector<ASTPointer<ModifierInvocation>> const& totalModifiers() const { return m_totalModifiers; } | ||
Declaration::Visibility const& visibility() const { return m_visibility; } | ||
StateMutability const& stateMutability() const { return m_mutability; } | ||
std::vector<ASTPointer<FunctionDefinition>> const& definedFunctions() const { return *m_functions; } | ||
std::vector<ASTPointer<ModifierArea>> const& subAreas() const { return *m_subAreas; } | ||
ModifierArea const* parent() const { return m_parent; } | ||
|
||
private: | ||
std::vector<ASTPointer<ModifierInvocation>> m_declaredModifiers; | ||
std::vector<ASTPointer<ModifierInvocation>> m_totalModifiers; | ||
Declaration::Visibility m_visibility; | ||
StateMutability m_mutability; | ||
ASTPointer<std::vector<ASTPointer<FunctionDefinition>> const> m_functions; | ||
ASTPointer<std::vector<ASTPointer<ModifierArea>> const> m_subAreas; | ||
ModifierArea* m_parent; | ||
}; | ||
|
||
/** | ||
* Definition of a function modifier. | ||
*/ | ||
|
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 a line break may be good.