diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 103dfbb33..8d889730c 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1674,7 +1674,7 @@ string const Main::getFunctionHashes(dev::solidity::CompilerStack const &_compil { ret += it.first.abridged(); ret += " :"; - ret += it.second.getName() + "\n"; + ret += it.second->getDeclaration().getName() + "\n"; } return ret; } diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index d95a254e9..bc6be6008 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -66,24 +66,24 @@ void ContractDefinition::checkTypeRequirements() // check for hash collisions in function signatures set> hashes; - for (auto const& hashAndFunction: getInterfaceFunctionList()) + for (auto const& it: getInterfaceFunctionList()) { - FixedHash<4> const& hash = std::get<0>(hashAndFunction); + FixedHash<4> const& hash = it.first; if (hashes.count(hash)) BOOST_THROW_EXCEPTION(createTypeError( std::string("Function signature hash collision for ") + - std::get<1>(hashAndFunction)->getCanonicalSignature(std::get<2>(hashAndFunction)->getName()))); + it.second->getCanonicalSignature())); hashes.insert(hash); } } -map, FunctionDescription> ContractDefinition::getInterfaceFunctions() const +map, FunctionTypePointer> ContractDefinition::getInterfaceFunctions() const { auto exportedFunctionList = getInterfaceFunctionList(); - map, FunctionDescription> 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); solAssert(exportedFunctionList.size() == exportedFunctions.size(), "Hash collision at Function Definition Hash calculation"); @@ -138,12 +138,12 @@ void ContractDefinition::checkIllegalOverrides() const } } -vector, std::shared_ptr, Declaration const*>> const& ContractDefinition::getInterfaceFunctionList() const +vector, FunctionTypePointer>> const& ContractDefinition::getInterfaceFunctionList() const { if (!m_interfaceFunctionList) { set functionsSeen; - m_interfaceFunctionList.reset(new vector, std::shared_ptr, Declaration const*>>()); + m_interfaceFunctionList.reset(new vector, FunctionTypePointer>>()); for (ContractDefinition const* contract: getLinearizedBaseContracts()) { for (ASTPointer const& f: contract->getDefinedFunctions()) @@ -151,7 +151,7 @@ vector, std::shared_ptr, Declaration cons { functionsSeen.insert(f->getName()); FixedHash<4> hash(dev::sha3(f->getCanonicalSignature())); - m_interfaceFunctionList->push_back(make_tuple(hash, make_shared(*f, false), f.get())); + m_interfaceFunctionList->push_back(make_pair(hash, make_shared(*f, false))); } for (ASTPointer const& v: contract->getStateVariables()) @@ -160,7 +160,7 @@ vector, std::shared_ptr, Declaration cons FunctionType ftype(*v); functionsSeen.insert(v->getName()); FixedHash<4> hash(dev::sha3(ftype.getCanonicalSignature(v->getName()))); - m_interfaceFunctionList->push_back(make_tuple(hash, make_shared(*v), v.get())); + m_interfaceFunctionList->push_back(make_pair(hash, make_shared(*v))); } } } @@ -519,103 +519,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/libsolidity/AST.h b/libsolidity/AST.h index f3b18d392..6c207290c 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -156,71 +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. */ @@ -252,7 +187,6 @@ protected: /// @} - /** * 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 +228,7 @@ public: /// @returns a map of canonical function signatures to FunctionDefinitions /// as intended for use by the ABI. - std::map, FunctionDescription> 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 +241,7 @@ public: private: void checkIllegalOverrides() const; - std::vector, std::shared_ptr, Declaration const*>> const& getInterfaceFunctionList() const; + std::vector, FunctionTypePointer>> const& getInterfaceFunctionList() const; std::vector> m_baseContracts; std::vector> m_definedStructs; @@ -316,7 +250,7 @@ private: std::vector> m_functionModifiers; std::vector m_linearizedBaseContracts; - mutable std::unique_ptr, std::shared_ptr, Declaration const*>>> m_interfaceFunctionList; + mutable std::unique_ptr, FunctionTypePointer>>> m_interfaceFunctionList; }; class InheritanceSpecifier: public ASTNode diff --git a/libsolidity/Compiler.cpp b/libsolidity/Compiler.cpp index 93784adf2..1fa31ce7d 100644 --- a/libsolidity/Compiler.cpp +++ b/libsolidity/Compiler.cpp @@ -142,7 +142,7 @@ void Compiler::appendConstructorCall(FunctionDefinition const& _constructor) void Compiler::appendFunctionSelector(ContractDefinition const& _contract) { - map, FunctionDescription> interfaceFunctions = _contract.getInterfaceFunctions(); + map, FunctionTypePointer> interfaceFunctions = _contract.getInterfaceFunctions(); map, const eth::AssemblyItem> callDataUnpackerEntryPoints; // retrieve the function signature hash from the calldata @@ -160,11 +160,11 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract) for (auto const& it: interfaceFunctions) { - FunctionType const* functionType = it.second.getFunctionType(); + FunctionTypePointer const& functionType = it.second; m_context << callDataUnpackerEntryPoints.at(it.first); eth::AssemblyItem returnTag = m_context.pushNewTag(); appendCalldataUnpacker(functionType->getParameterTypes()); - m_context.appendJumpTo(m_context.getFunctionEntryLabel(*it.second.getDeclaration())); + m_context.appendJumpTo(m_context.getFunctionEntryLabel(it.second->getDeclaration())); m_context << returnTag; appendReturnValuePacker(functionType->getReturnParameterTypes()); } diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index 9b6327782..92cd51562 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -45,23 +45,26 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio Json::Value inputs(Json::arrayValue); Json::Value outputs(Json::arrayValue); - auto populateParameters = [](vector const& _params) + auto populateParameters = [](vector const& _paramNames, + vector const& _paramTypes) { Json::Value params(Json::arrayValue); - for (auto const& param: _params) + solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match"); + for (unsigned i = 0; i < _paramNames.size(); ++i) { Json::Value input; - input["name"] = param.getName(); - input["type"] = param.getType(); + input["name"] = _paramNames[i]; + input["type"] = _paramTypes[i]; params.append(input); } return params; }; - - method["name"] = it.second.getName(); - method["constant"] = it.second.isConstant(); - method["inputs"] = populateParameters(it.second.getParameters()); - method["outputs"] = populateParameters(it.second.getReturnParameters()); + method["name"] = it.second->getDeclaration().getName(); + method["constant"] = it.second->isConstant(); + method["inputs"] = populateParameters(it.second->getParameterNames(), + it.second->getParameterTypeNames()); + method["outputs"] = populateParameters(it.second->getReturnParameterNames(), + it.second->getReturnParameterTypeNames()); methods.append(method); } return std::unique_ptr(new std::string(m_writer.write(methods))); @@ -72,16 +75,20 @@ unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition string ret = "contract " + _contractDef.getName() + "{"; for (auto const& it: _contractDef.getInterfaceFunctions()) { - auto populateParameters = [](vector const& _params) + auto populateParameters = [](vector const& _paramNames, + vector const& _paramTypes) { string r = ""; - for (auto const& param: _params) - r += (r.size() ? "," : "(") + param.getType() + " " + param.getName(); + solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match"); + for (unsigned i = 0; i < _paramNames.size(); ++i) + r += (r.size() ? "," : "(") + _paramTypes[i] + " " + _paramNames[i]; return r.size() ? r + ")" : "()"; }; - ret += "function " + it.second.getName() + populateParameters(it.second.getParameters()) + (it.second.isConstant() ? "constant " : ""); - if (it.second.getReturnParameters().size()) - ret += "returns" + populateParameters(it.second.getReturnParameters()); + ret += "function " + it.second->getDeclaration().getName() + + populateParameters(it.second->getParameterNames(), it.second->getParameterTypeNames()) + + (it.second->isConstant() ? "constant " : ""); + if (it.second->getReturnParameterTypes().size()) + ret += "returns" + populateParameters(it.second->getReturnParameterNames(), it.second->getReturnParameterTypeNames()); else if (ret.back() == ' ') ret.pop_back(); ret += "{}"; @@ -97,7 +104,7 @@ std::unique_ptr InterfaceHandler::getUserDocumentation(ContractDefi for (auto const& it: _contractDef.getInterfaceFunctions()) { Json::Value user; - auto strPtr = it.second.getDocumentation(); + auto strPtr = it.second->getDocumentation(); if (strPtr) { resetUser(); @@ -105,7 +112,7 @@ std::unique_ptr InterfaceHandler::getUserDocumentation(ContractDefi if (!m_notice.empty()) {// since @notice is the only user tag if missing function should not appear user["notice"] = Json::Value(m_notice); - methods[it.second.getSignature()] = user; + methods[it.second->getCanonicalSignature()] = user; } } } @@ -138,7 +145,7 @@ std::unique_ptr InterfaceHandler::getDevDocumentation(ContractDefin for (auto const& it: _contractDef.getInterfaceFunctions()) { Json::Value method; - auto strPtr = it.second.getDocumentation(); + auto strPtr = it.second->getDocumentation(); if (strPtr) { resetDev(); @@ -161,7 +168,7 @@ std::unique_ptr InterfaceHandler::getDevDocumentation(ContractDefin method["return"] = m_return; if (!method.empty()) // add the function, only if we have any documentation to add - methods[it.second.getSignature()] = method; + methods[it.second->getCanonicalSignature()] = method; } } doc["methods"] = methods; diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 3d6c4e96c..bebb4be17 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -499,7 +499,7 @@ MemberList const& ContractType::getMembers() const } else for (auto const& it: m_contract.getInterfaceFunctions()) - members[it.second.getName()] = it.second.getFunctionTypeShared(); + members[it.second->getDeclaration().getName()] = it.second; m_members.reset(new MemberList(members)); } return *m_members; @@ -522,7 +522,7 @@ u256 ContractType::getFunctionIdentifier(string const& _functionName) const { auto interfaceFunctions = m_contract.getInterfaceFunctions(); for (auto const& it: m_contract.getInterfaceFunctions()) - if (it.second.getName() == _functionName) + if (it.second->getDeclaration().getName() == _functionName) return FixedHash<4>::Arith(it.first); return Invalid256; @@ -589,12 +589,15 @@ u256 StructType::getStorageOffsetOfMember(string const& _name) const } FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal): - m_location(_isInternal ? Location::INTERNAL : Location::EXTERNAL) + m_location(_isInternal ? Location::INTERNAL : Location::EXTERNAL), + m_isConstant(_function.isDeclaredConst()), + m_declaration(&_function) { TypePointers params; vector paramNames; TypePointers retParams; vector retParamNames; + params.reserve(_function.getParameters().size()); paramNames.reserve(_function.getParameters().size()); for (ASTPointer const& var: _function.getParameters()) @@ -616,7 +619,7 @@ FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal } FunctionType::FunctionType(VariableDeclaration const& _varDecl): - m_location(Location::EXTERNAL) + m_location(Location::EXTERNAL), m_isConstant(true), m_declaration(&_varDecl) { TypePointers params({}); vector paramNames({}); @@ -638,6 +641,9 @@ bool FunctionType::operator==(Type const& _other) const if (m_location != other.m_location) return false; + if (m_isConstant != other.isConstant()) + return false; + if (m_parameterTypes.size() != other.m_parameterTypes.size() || m_returnParameterTypes.size() != other.m_returnParameterTypes.size()) return false; @@ -711,7 +717,13 @@ MemberList const& FunctionType::getMembers() const string FunctionType::getCanonicalSignature(std::string const& _name) const { - string ret = _name + "("; + std::string funcName = _name; + if (_name == "") + { + solAssert(m_declaration != nullptr, "Function type without name needs a declaration"); + funcName = m_declaration->getName(); + } + string ret = funcName + "("; for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it) ret += (*it)->toString() + (it + 1 == m_parameterTypes.cend() ? "" : ","); @@ -734,6 +746,33 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con m_gasSet || _setGas, m_valueSet || _setValue); } +vector const FunctionType::getParameterTypeNames() const +{ + vector names; + for (TypePointer const& t: m_parameterTypes) + names.push_back(t->toString()); + + return names; +} + +vector const FunctionType::getReturnParameterTypeNames() const +{ + vector names; + for (TypePointer const& t: m_returnParameterTypes) + names.push_back(t->toString()); + + return names; +} + +ASTPointer FunctionType::getDocumentation() const +{ + auto function = dynamic_cast(m_declaration); + if (function) + return function->getDocumentation(); + + return ASTPointer(); +} + bool MappingType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) diff --git a/libsolidity/Types.h b/libsolidity/Types.h index 3f6df13ee..4b4d17d0a 100644 --- a/libsolidity/Types.h +++ b/libsolidity/Types.h @@ -41,6 +41,7 @@ namespace solidity class Type; // forward class FunctionType; // forward using TypePointer = std::shared_ptr; +using FunctionTypePointer = std::shared_ptr; using TypePointers = std::vector; /** @@ -295,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. @@ -307,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; }; @@ -371,8 +372,10 @@ public: TypePointers const& getParameterTypes() const { return m_parameterTypes; } std::vector const& getParameterNames() const { return m_parameterNames; } + std::vector const getParameterTypeNames() const; TypePointers const& getReturnParameterTypes() const { return m_returnParameterTypes; } std::vector const& getReturnParameterNames() const { return m_returnParameterNames; } + std::vector const getReturnParameterTypeNames() const; virtual bool operator==(Type const& _other) const override; virtual std::string toString() const override; @@ -383,7 +386,20 @@ public: virtual MemberList const& getMembers() const override; Location const& getLocation() const { return m_location; } - std::string getCanonicalSignature(std::string const& _name) const; + /// @returns the canonical signature of this function type given the function name + /// If @a _name is not provided (empty string) then the @c m_declaration member of the + /// function type is used + std::string getCanonicalSignature(std::string const& _name = "") const; + Declaration const& getDeclaration() const + { + solAssert(m_declaration, "Requested declaration from a FunctionType that has none"); + return *m_declaration; + } + bool hasDeclaration() const { return !!m_declaration; } + bool isConstant() const { return m_isConstant; } + /// @return A shared pointer of an ASTString. + /// Can contain a nullptr in which case indicates absence of documentation + ASTPointer getDocumentation() const; bool gasSet() const { return m_gasSet; } bool valueSet() const { return m_valueSet; } @@ -402,7 +418,9 @@ private: Location const m_location; bool const m_gasSet = false; ///< true iff the gas value to be used is on the stack bool const m_valueSet = false; ///< true iff the value to be sent is on the stack + bool m_isConstant; mutable std::unique_ptr m_members; + Declaration const* m_declaration = nullptr; }; /** diff --git a/mix/QContractDefinition.cpp b/mix/QContractDefinition.cpp index 503f93c39..c94de17c7 100644 --- a/mix/QContractDefinition.cpp +++ b/mix/QContractDefinition.cpp @@ -34,10 +34,7 @@ using namespace dev::mix; QContractDefinition::QContractDefinition(dev::solidity::ContractDefinition const* _contract): QBasicNodeDefinition(_contract) { if (_contract->getConstructor() != nullptr) - { - FunctionDescription desc(_contract->getConstructor()); - m_constructor = new QFunctionDefinition(desc); - } + m_constructor = new QFunctionDefinition(ContractType(*_contract).getConstructorType()); else m_constructor = new QFunctionDefinition(); diff --git a/mix/QFunctionDefinition.cpp b/mix/QFunctionDefinition.cpp index 3c1e800ca..20dbe070b 100644 --- a/mix/QFunctionDefinition.cpp +++ b/mix/QFunctionDefinition.cpp @@ -28,29 +28,15 @@ using namespace dev::solidity; using namespace dev::mix; -QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionDescription const& _f): QBasicNodeDefinition(_f.getDeclaration()), m_hash(dev::sha3(_f.getSignature())) +QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(&_f->getDeclaration()), m_hash(dev::sha3(_f->getCanonicalSignature())) { - FunctionDefinition const* funcDef; - VariableDeclaration const* varDecl; - if ((funcDef = _f.getFunctionDefinition())) - { - std::vector> parameters = funcDef->getParameterList().getParameters(); - for (unsigned i = 0; i < parameters.size(); i++) - m_parameters.append(new QVariableDeclaration(parameters.at(i).get())); - - std::vector> returnParameters = funcDef->getReturnParameters(); - for (unsigned i = 0; i < returnParameters.size(); i++) - m_returnParameters.append(new QVariableDeclaration(returnParameters.at(i).get())); - } - else - { - if (!(varDecl = _f.getVariableDeclaration())) - BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Malformed FunctionDescription. Should never happen.")); - - // only the return parameter for now. - // TODO: change this for other state variables like mapping and maybe abstract this inside solidity and not here - auto returnParams = _f.getReturnParameters(); - m_returnParameters.append(new QVariableDeclaration(returnParams[0])); - - } + auto paramNames = _f->getParameterNames(); + auto paramTypes = _f->getParameterTypeNames(); + auto returnNames = _f->getReturnParameterNames(); + auto returnTypes = _f->getReturnParameterTypeNames(); + for (unsigned i = 0; i < paramNames.size(); ++i) + m_parameters.append(new QVariableDeclaration(paramNames[i], paramTypes[i])); + + for (unsigned i = 0; i < returnNames.size(); ++i) + m_returnParameters.append(new QVariableDeclaration(returnNames[i], returnTypes[i])); } diff --git a/mix/QFunctionDefinition.h b/mix/QFunctionDefinition.h index 2b7084206..0bbf093b5 100644 --- a/mix/QFunctionDefinition.h +++ b/mix/QFunctionDefinition.h @@ -39,7 +39,7 @@ class QFunctionDefinition: public QBasicNodeDefinition public: QFunctionDefinition() {} - QFunctionDefinition(solidity::FunctionDescription const& _f); + QFunctionDefinition(solidity::FunctionTypePointer const& _f); /// Get all input parameters of this function. QList const& parametersList() const { return m_parameters; } /// Get all input parameters of this function as QML property. diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index ff4018fa3..f9cc5265f 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -37,7 +37,7 @@ class QVariableDeclaration: public QBasicNodeDefinition public: QVariableDeclaration() {} QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {} - QVariableDeclaration(solidity::ParamDescription const& _v): QBasicNodeDefinition(_v.getName()), m_type(QString::fromStdString(_v.getType())) {} + QVariableDeclaration(std::string const& _name, std::string const& _type): QBasicNodeDefinition(_name), m_type(QString::fromStdString(_type)) {} QString type() const { return m_type; } private: QString m_type; diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index 5ae854bc0..07f2d638a 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -93,7 +93,7 @@ static ContractDefinition const* retrieveContract(ASTPointer _source return NULL; } -static FunctionDescription const& retrieveFunctionBySignature(ContractDefinition const* _contract, +static FunctionTypePointer const& retrieveFunctionBySignature(ContractDefinition const* _contract, std::string const& _signature) { FixedHash<4> hash(dev::sha3(_signature)); @@ -643,11 +643,11 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) ContractDefinition const* contract; BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); BOOST_REQUIRE((contract = retrieveContract(source, 0)) != nullptr); - FunctionDescription function = retrieveFunctionBySignature(contract, "foo()"); - BOOST_REQUIRE(function.getDeclaration() != nullptr); - auto returnParams = function.getReturnParameters(); - BOOST_CHECK_EQUAL(returnParams.at(0).getType(), "uint256"); - BOOST_CHECK(function.isConstant()); + FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()"); + BOOST_REQUIRE(function->hasDeclaration()); + auto returnParams = function->getReturnParameterTypeNames(); + BOOST_CHECK_EQUAL(returnParams.at(0), "uint256"); + BOOST_CHECK(function->isConstant()); } BOOST_AUTO_TEST_CASE(function_clash_with_state_variable_accessor) @@ -676,8 +676,8 @@ BOOST_AUTO_TEST_CASE(private_state_variable) ContractDefinition const* contract; BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr); - FunctionDescription function = retrieveFunctionBySignature(contract, "foo()"); - BOOST_CHECK_MESSAGE(function.getDeclaration() == nullptr, "Accessor function of a private variable should not exist"); + FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()"); + BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a private variable should not exist"); } BOOST_AUTO_TEST_SUITE_END()