From 74cacce2da23afc33972919b9187e4a574d5de2f Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 29 Jan 2015 12:17:37 +0100 Subject: [PATCH] Common class that contains AST node documentations. --- libsolidity/AST.h | 80 ++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/libsolidity/AST.h b/libsolidity/AST.h index f397c13ad..f3b18d392 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -157,6 +157,10 @@ private: }; + +/// Traits and Helpers (@todo: move to their own header) +/// @{ + /** * Generic Parameter description used by @see FunctionDescription to return * a descripton of its parameters. @@ -217,13 +221,44 @@ struct FunctionDescription std::pair, Declaration const*> m_description; }; +/** + * Abstract class that is added to each AST node that can store local variables. + */ +class VariableScope +{ +public: + void addLocalVariable(VariableDeclaration const& _localVariable) { m_localVariables.push_back(&_localVariable); } + std::vector const& getLocalVariables() const { return m_localVariables; } + +private: + std::vector m_localVariables; +}; + +/** + * Abstract class that is added to each AST node that can receive documentation. + */ +class Documented +{ +public: + explicit Documented(ASTPointer const& _documentation): m_documentation(_documentation) {} + + /// @return A shared pointer of an ASTString. + /// Can contain a nullptr in which case indicates absence of documentation + ASTPointer const& getDocumentation() const { return m_documentation; } + +protected: + ASTPointer m_documentation; +}; + +/// @} + /** * Definition of a contract. This is the only AST nodes where child nodes are not visited in * document order. It first visits all struct declarations, then all variable declarations and * finally all function declarations. */ -class ContractDefinition: public Declaration +class ContractDefinition: public Declaration, public Documented { public: ContractDefinition(Location const& _location, @@ -234,13 +269,12 @@ public: std::vector> const& _stateVariables, std::vector> const& _definedFunctions, std::vector> const& _functionModifiers): - Declaration(_location, _name), + Declaration(_location, _name), Documented(_documentation), m_baseContracts(_baseContracts), m_definedStructs(_definedStructs), m_stateVariables(_stateVariables), m_definedFunctions(_definedFunctions), - m_functionModifiers(_functionModifiers), - m_documentation(_documentation) + m_functionModifiers(_functionModifiers) {} virtual void accept(ASTVisitor& _visitor) override; @@ -258,10 +292,6 @@ public: /// and calls checkTypeRequirements on all its functions. void checkTypeRequirements(); - /// @return A shared pointer of an ASTString. - /// Can contain a nullptr in which case indicates absence of documentation - ASTPointer const& getDocumentation() const { return m_documentation; } - /// @returns a map of canonical function signatures to FunctionDefinitions /// as intended for use by the ABI. std::map, FunctionDescription> getInterfaceFunctions() const; @@ -284,7 +314,6 @@ private: std::vector> m_stateVariables; std::vector> m_definedFunctions; std::vector> m_functionModifiers; - ASTPointer m_documentation; std::vector m_linearizedBaseContracts; mutable std::unique_ptr, std::shared_ptr, Declaration const*>>> m_interfaceFunctionList; @@ -355,20 +384,7 @@ private: std::vector> m_parameters; }; -/** - * Abstract class that is added to each AST node that can store local variables. - */ -class VariableScope -{ -public: - void addLocalVariable(VariableDeclaration const& _localVariable) { m_localVariables.push_back(&_localVariable); } - std::vector const& getLocalVariables() const { return m_localVariables; } - -private: - std::vector m_localVariables; -}; - -class FunctionDefinition: public Declaration, public VariableScope +class FunctionDefinition: public Declaration, public VariableScope, public Documented { public: FunctionDefinition(Location const& _location, ASTPointer const& _name, @@ -380,13 +396,13 @@ public: std::vector> const& _modifiers, ASTPointer const& _returnParameters, ASTPointer const& _body): - Declaration(_location, _name), m_isPublic(_isPublic), m_isConstructor(_isConstructor), + Declaration(_location, _name), Documented(_documentation), + m_isPublic(_isPublic), m_isConstructor(_isConstructor), m_parameters(_parameters), m_isDeclaredConst(_isDeclaredConst), m_functionModifiers(_modifiers), m_returnParameters(_returnParameters), - m_body(_body), - m_documentation(_documentation) + m_body(_body) {} virtual void accept(ASTVisitor& _visitor) override; @@ -401,9 +417,6 @@ public: std::vector> const& getReturnParameters() const { return m_returnParameters->getParameters(); } ASTPointer const& getReturnParameterList() const { return m_returnParameters; } Block const& getBody() const { return *m_body; } - /// @return A shared pointer of an ASTString. - /// Can contain a nullptr in which case indicates absence of documentation - ASTPointer const& getDocumentation() const { return m_documentation; } virtual TypePointer getType(ContractDefinition const*) const override; @@ -423,7 +436,6 @@ private: std::vector> m_functionModifiers; ASTPointer m_returnParameters; ASTPointer m_body; - ASTPointer m_documentation; }; /** @@ -463,7 +475,7 @@ private: /** * Definition of a function modifier. */ -class ModifierDefinition: public Declaration, public VariableScope +class ModifierDefinition: public Declaration, public VariableScope, public Documented { public: ModifierDefinition(Location const& _location, @@ -471,7 +483,7 @@ public: ASTPointer const& _documentation, ASTPointer const& _parameters, ASTPointer const& _body): - Declaration(_location, _name), m_documentation(_documentation), + Declaration(_location, _name), Documented(_documentation), m_parameters(_parameters), m_body(_body) {} virtual void accept(ASTVisitor& _visitor) override; @@ -483,14 +495,10 @@ public: virtual TypePointer getType(ContractDefinition const* = nullptr) const override; - /// @return A shared pointer of an ASTString. - /// Can contain a nullptr in which case indicates absence of documentation - ASTPointer const& getDocumentation() const { return m_documentation; } void checkTypeRequirements(); private: - ASTPointer m_documentation; ASTPointer m_parameters; ASTPointer m_body; };