diff --git a/AST.cpp b/AST.cpp index bd333b91e..74d40da43 100644 --- a/AST.cpp +++ b/AST.cpp @@ -77,11 +77,11 @@ void ContractDefinition::checkTypeRequirements() } } -map, std::shared_ptr> ContractDefinition::getInterfaceFunctions() const +map, FunctionTypePointer> ContractDefinition::getInterfaceFunctions() const { auto exportedFunctionList = getInterfaceFunctionList(); - map, std::shared_ptr> exportedFunctions; + map, FunctionTypePointer> exportedFunctions; for (auto const& it: exportedFunctionList) // exportedFunctions.insert(make_pair(std::get<0>(it), FunctionDescription(std::get<1>(it), std::get<2>(it)))); exportedFunctions.insert(it); @@ -520,103 +520,5 @@ void Literal::checkTypeRequirements() BOOST_THROW_EXCEPTION(createTypeError("Invalid literal value.")); } -std::string const& ParamDescription::getName() const -{ - return m_description.first; -} - -std::string const& ParamDescription::getType() const -{ - return m_description.second; -} - -ASTPointer FunctionDescription::getDocumentation() const -{ - auto function = dynamic_cast(m_description.second); - if (function) - return function->getDocumentation(); - - return ASTPointer(); -} - -string FunctionDescription::getSignature() const -{ - return m_description.first->getCanonicalSignature(m_description.second->getName()); -} - -string FunctionDescription::getName() const -{ - return m_description.second->getName(); -} - -bool FunctionDescription::isConstant() const -{ - auto function = dynamic_cast(m_description.second); - if (function) - return function->isDeclaredConst(); - - return true; -} - -vector const FunctionDescription::getParameters() const -{ - auto function = dynamic_cast(m_description.second); - if (function) - { - vector paramsDescription; - for (auto const& param: function->getParameters()) - paramsDescription.push_back(ParamDescription(param->getName(), param->getType()->toString())); - - return paramsDescription; - } - - // else for now let's assume no parameters to accessors - // LTODO: fix this for mapping types - return {}; -} - -vector const FunctionDescription::getReturnParameters() const -{ - auto function = dynamic_cast(m_description.second); - if (function) - { - vector paramsDescription; - for (auto const& param: function->getReturnParameters()) - paramsDescription.push_back(ParamDescription(param->getName(), param->getType()->toString())); - - return paramsDescription; - } - - auto vardecl = dynamic_cast(m_description.second); - return {ParamDescription(vardecl->getName(), vardecl->getType()->toString())}; -} - -Declaration const* FunctionDescription::getDeclaration() const -{ - return m_description.second; -} - -VariableDeclaration const* FunctionDescription::getVariableDeclaration() const -{ - return dynamic_cast(m_description.second); -} - -FunctionDefinition const* FunctionDescription::getFunctionDefinition() const -{ - return dynamic_cast(m_description.second); -} - -shared_ptr FunctionDescription::getFunctionTypeShared() const -{ - return m_description.first; -} - - -FunctionType const* FunctionDescription::getFunctionType() const -{ - return m_description.first.get(); -} - - } } diff --git a/AST.h b/AST.h index e0fb14854..9ea6c144b 100755 --- a/AST.h +++ b/AST.h @@ -156,103 +156,6 @@ private: Declaration const* m_scope; }; - - -/// Traits and Helpers (@todo: move to their own header) -/// @{ - -/** - * Generic Parameter description used by @see FunctionDescription to return - * a descripton of its parameters. - */ -struct ParamDescription -{ - ParamDescription(std::string const& _name, std::string const& _type): - m_description(_name, _type){} - - std::string const& getName() const; - std::string const& getType() const; - - std::pair m_description; -}; - - -/** - * Generic function description able to describe both normal functions and - * functions that should be made as accessors to state variables - */ -struct FunctionDescription -{ - FunctionDescription(std::shared_ptr _type, Declaration const* _decl): - m_description(_type, _decl){} - - /// constructor for a constructor's function definition. Used only inside mix. - FunctionDescription(Declaration const* _def): - m_description(nullptr, _def){} - - FunctionDescription(): - m_description(nullptr, nullptr){} - - /// @returns the natspec documentation of the function if existing. Accessor (for now) don't have natspec doc - ASTPointer getDocumentation() const; - /// @returns the canonical signature of the function - std::string getSignature() const; - /// @returns the name of the function, basically that of the declaration - std::string getName() const; - /// @returns whether the function is constant. IF it's an accessor this is always true - bool isConstant() const; - /// @returns the argument parameters of the function - std::vector const getParameters() const; - /// @returns the return parameters of the function - std::vector const getReturnParameters() const; - /// @returns a generic Declaration AST Node pointer which can be either a FunctionDefinition or a VariableDeclaration - Declaration const* getDeclaration() const; - /// @returns the VariableDeclaration AST Node pointer or nullptr if it's not a VariableDeclaration - VariableDeclaration const* getVariableDeclaration() const; - /// @returns the FunctionDefinition AST Node pointer or nullptr if it's not a FunctionDefinition - FunctionDefinition const* getFunctionDefinition() const; - /// @returns a created shared pointer with the type of the function - std::shared_ptr makeFunctionType() const; - /// @returns a pointer to the function type - FunctionType const* getFunctionType() const; - /// @returns a shared pointer to the function type - std::shared_ptr getFunctionTypeShared() const; - - 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 @@ -294,7 +197,7 @@ public: /// @returns a map of canonical function signatures to FunctionDefinitions /// as intended for use by the ABI. - std::map, std::shared_ptr> getInterfaceFunctions() const; + std::map, FunctionTypePointer> getInterfaceFunctions() const; /// List of all (direct and indirect) base contracts in order from derived to base, including /// the contract itself. Available after name resolution @@ -307,7 +210,7 @@ public: private: void checkIllegalOverrides() const; - std::vector, std::shared_ptr>> const& getInterfaceFunctionList() const; + std::vector, FunctionTypePointer>> const& getInterfaceFunctionList() const; std::vector> m_baseContracts; std::vector> m_definedStructs; @@ -316,7 +219,7 @@ private: std::vector> m_functionModifiers; std::vector m_linearizedBaseContracts; - mutable std::unique_ptr, std::shared_ptr>>> m_interfaceFunctionList; + mutable std::unique_ptr, FunctionTypePointer>>> m_interfaceFunctionList; }; class InheritanceSpecifier: public ASTNode diff --git a/Types.h b/Types.h index e23939699..b8ad7449e 100644 --- a/Types.h +++ b/Types.h @@ -296,7 +296,7 @@ public: /// Returns the function type of the constructor. Note that the location part of the function type /// is not used, as this type cannot be the type of a variable or expression. - std::shared_ptr const& getConstructorType() const; + FunctionTypePointer const& getConstructorType() const; /// @returns the identifier of the function with the given name or Invalid256 if such a name does /// not exist. @@ -308,7 +308,7 @@ private: /// members. bool m_super; /// Type of the constructor, @see getConstructorType. Lazily initialized. - mutable std::shared_ptr m_constructorType; + mutable FunctionTypePointer m_constructorType; /// List of member types, will be lazy-initialized because of recursive references. mutable std::unique_ptr m_members; };