mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Common class that contains AST node documentations.
This commit is contained in:
parent
c568df4a03
commit
11d068bbbb
80
AST.h
80
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<std::shared_ptr<FunctionType const>, 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<VariableDeclaration const*> const& getLocalVariables() const { return m_localVariables; }
|
||||
|
||||
private:
|
||||
std::vector<VariableDeclaration const*> m_localVariables;
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract class that is added to each AST node that can receive documentation.
|
||||
*/
|
||||
class Documented
|
||||
{
|
||||
public:
|
||||
explicit Documented(ASTPointer<ASTString> const& _documentation): m_documentation(_documentation) {}
|
||||
|
||||
/// @return A shared pointer of an ASTString.
|
||||
/// Can contain a nullptr in which case indicates absence of documentation
|
||||
ASTPointer<ASTString> const& getDocumentation() const { return m_documentation; }
|
||||
|
||||
protected:
|
||||
ASTPointer<ASTString> 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<ASTPointer<VariableDeclaration>> const& _stateVariables,
|
||||
std::vector<ASTPointer<FunctionDefinition>> const& _definedFunctions,
|
||||
std::vector<ASTPointer<ModifierDefinition>> 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<ASTString> const& getDocumentation() const { return m_documentation; }
|
||||
|
||||
/// @returns a map of canonical function signatures to FunctionDefinitions
|
||||
/// as intended for use by the ABI.
|
||||
std::map<FixedHash<4>, FunctionDescription> getInterfaceFunctions() const;
|
||||
@ -284,7 +314,6 @@ private:
|
||||
std::vector<ASTPointer<VariableDeclaration>> m_stateVariables;
|
||||
std::vector<ASTPointer<FunctionDefinition>> m_definedFunctions;
|
||||
std::vector<ASTPointer<ModifierDefinition>> m_functionModifiers;
|
||||
ASTPointer<ASTString> m_documentation;
|
||||
|
||||
std::vector<ContractDefinition const*> m_linearizedBaseContracts;
|
||||
mutable std::unique_ptr<std::vector<std::tuple<FixedHash<4>, std::shared_ptr<FunctionType const>, Declaration const*>>> m_interfaceFunctionList;
|
||||
@ -355,20 +384,7 @@ private:
|
||||
std::vector<ASTPointer<VariableDeclaration>> 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<VariableDeclaration const*> const& getLocalVariables() const { return m_localVariables; }
|
||||
|
||||
private:
|
||||
std::vector<VariableDeclaration const*> m_localVariables;
|
||||
};
|
||||
|
||||
class FunctionDefinition: public Declaration, public VariableScope
|
||||
class FunctionDefinition: public Declaration, public VariableScope, public Documented
|
||||
{
|
||||
public:
|
||||
FunctionDefinition(Location const& _location, ASTPointer<ASTString> const& _name,
|
||||
@ -380,13 +396,13 @@ public:
|
||||
std::vector<ASTPointer<ModifierInvocation>> const& _modifiers,
|
||||
ASTPointer<ParameterList> const& _returnParameters,
|
||||
ASTPointer<Block> 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<ASTPointer<VariableDeclaration>> const& getReturnParameters() const { return m_returnParameters->getParameters(); }
|
||||
ASTPointer<ParameterList> 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<ASTString> const& getDocumentation() const { return m_documentation; }
|
||||
|
||||
virtual TypePointer getType(ContractDefinition const*) const override;
|
||||
|
||||
@ -423,7 +436,6 @@ private:
|
||||
std::vector<ASTPointer<ModifierInvocation>> m_functionModifiers;
|
||||
ASTPointer<ParameterList> m_returnParameters;
|
||||
ASTPointer<Block> m_body;
|
||||
ASTPointer<ASTString> 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<ASTString> const& _documentation,
|
||||
ASTPointer<ParameterList> const& _parameters,
|
||||
ASTPointer<Block> 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<ASTString> const& getDocumentation() const { return m_documentation; }
|
||||
|
||||
void checkTypeRequirements();
|
||||
|
||||
private:
|
||||
ASTPointer<ASTString> m_documentation;
|
||||
ASTPointer<ParameterList> m_parameters;
|
||||
ASTPointer<Block> m_body;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user