From 7123f25210c200f225c5988452d9e2c35d668223 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 11 Feb 2017 03:13:36 +0000 Subject: Rename FunctionType::Location to FunctionType::Kind --- libsolidity/ast/Types.cpp | 178 +++++++++++++++++++++++----------------------- libsolidity/ast/Types.h | 21 +++--- 2 files changed, 99 insertions(+), 100 deletions(-) (limited to 'libsolidity/ast') diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index e7f53422..b76733d4 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1967,7 +1967,7 @@ TypePointer TupleType::closestTemporaryType(TypePointer const& _targetType) cons } FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal): - m_location(_isInternal ? Location::Internal : Location::External), + m_kind(_isInternal ? Kind::Internal : Kind::External), m_isConstant(_function.isDeclaredConst()), m_isPayable(_isInternal ? false : _function.isPayable()), m_declaration(&_function) @@ -1998,7 +1998,7 @@ FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal } FunctionType::FunctionType(VariableDeclaration const& _varDecl): - m_location(Location::External), m_isConstant(true), m_declaration(&_varDecl) + m_kind(Kind::External), m_isConstant(true), m_declaration(&_varDecl) { TypePointers paramTypes; vector paramNames; @@ -2058,7 +2058,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): } FunctionType::FunctionType(EventDefinition const& _event): - m_location(Location::Event), m_isConstant(true), m_declaration(&_event) + m_kind(Kind::Event), m_isConstant(true), m_declaration(&_event) { TypePointers params; vector paramNames; @@ -2074,19 +2074,19 @@ FunctionType::FunctionType(EventDefinition const& _event): } FunctionType::FunctionType(FunctionTypeName const& _typeName): - m_location(_typeName.visibility() == VariableDeclaration::Visibility::External ? Location::External : Location::Internal), + m_kind(_typeName.visibility() == VariableDeclaration::Visibility::External ? Kind::External : Kind::Internal), m_isConstant(_typeName.isDeclaredConst()), m_isPayable(_typeName.isPayable()) { if (_typeName.isPayable()) { - solAssert(m_location == Location::External, "Internal payable function type used."); + solAssert(m_kind == Kind::External, "Internal payable function type used."); solAssert(!m_isConstant, "Payable constant function"); } for (auto const& t: _typeName.parameterTypes()) { solAssert(t->annotation().type, "Type not set for parameter."); - if (m_location == Location::External) + if (m_kind == Kind::External) solAssert( t->annotation().type->canBeUsedExternally(false), "Internal type used as parameter for external function." @@ -2096,7 +2096,7 @@ FunctionType::FunctionType(FunctionTypeName const& _typeName): for (auto const& t: _typeName.returnParameterTypes()) { solAssert(t->annotation().type, "Type not set for return parameter."); - if (m_location == Location::External) + if (m_kind == Kind::External) solAssert( t->annotation().type->canBeUsedExternally(false), "Internal type used as return parameter for external function." @@ -2126,7 +2126,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c TypePointers{make_shared(_contract)}, parameterNames, strings{""}, - Location::Creation, + Kind::Creation, false, nullptr, false, @@ -2151,38 +2151,38 @@ TypePointers FunctionType::parameterTypes() const string FunctionType::identifier() const { string id = "t_function_"; - switch (location()) + switch (m_kind) { - case Location::Internal: id += "internal"; break; - case Location::External: id += "external"; break; - case Location::CallCode: id += "callcode"; break; - case Location::DelegateCall: id += "delegatecall"; break; - case Location::Bare: id += "bare"; break; - case Location::BareCallCode: id += "barecallcode"; break; - case Location::BareDelegateCall: id += "baredelegatecall"; break; - case Location::Creation: id += "creation"; break; - case Location::Send: id += "send"; break; - case Location::Transfer: id += "transfer"; break; - case Location::SHA3: id += "sha3"; break; - case Location::Selfdestruct: id += "selfdestruct"; break; - case Location::Revert: id += "revert"; break; - case Location::ECRecover: id += "ecrecover"; break; - case Location::SHA256: id += "sha256"; break; - case Location::RIPEMD160: id += "ripemd160"; break; - case Location::Log0: id += "log0"; break; - case Location::Log1: id += "log1"; break; - case Location::Log2: id += "log2"; break; - case Location::Log3: id += "log3"; break; - case Location::Log4: id += "log4"; break; - case Location::Event: id += "event"; break; - case Location::SetGas: id += "setgas"; break; - case Location::SetValue: id += "setvalue"; break; - case Location::BlockHash: id += "blockhash"; break; - case Location::AddMod: id += "addmod"; break; - case Location::MulMod: id += "mulmod"; break; - case Location::ArrayPush: id += "arraypush"; break; - case Location::ByteArrayPush: id += "bytearraypush"; break; - case Location::ObjectCreation: id += "objectcreation"; break; + case Kind::Internal: id += "internal"; break; + case Kind::External: id += "external"; break; + case Kind::CallCode: id += "callcode"; break; + case Kind::DelegateCall: id += "delegatecall"; break; + case Kind::Bare: id += "bare"; break; + case Kind::BareCallCode: id += "barecallcode"; break; + case Kind::BareDelegateCall: id += "baredelegatecall"; break; + case Kind::Creation: id += "creation"; break; + case Kind::Send: id += "send"; break; + case Kind::Transfer: id += "transfer"; break; + case Kind::SHA3: id += "sha3"; break; + case Kind::Selfdestruct: id += "selfdestruct"; break; + case Kind::Revert: id += "revert"; break; + case Kind::ECRecover: id += "ecrecover"; break; + case Kind::SHA256: id += "sha256"; break; + case Kind::RIPEMD160: id += "ripemd160"; break; + case Kind::Log0: id += "log0"; break; + case Kind::Log1: id += "log1"; break; + case Kind::Log2: id += "log2"; break; + case Kind::Log3: id += "log3"; break; + case Kind::Log4: id += "log4"; break; + case Kind::Event: id += "event"; break; + case Kind::SetGas: id += "setgas"; break; + case Kind::SetValue: id += "setvalue"; break; + case Kind::BlockHash: id += "blockhash"; break; + case Kind::AddMod: id += "addmod"; break; + case Kind::MulMod: id += "mulmod"; break; + case Kind::ArrayPush: id += "arraypush"; break; + case Kind::ByteArrayPush: id += "bytearraypush"; break; + case Kind::ObjectCreation: id += "objectcreation"; break; default: solAssert(false, "Unknown function location."); break; } if (isConstant()) @@ -2203,7 +2203,7 @@ bool FunctionType::operator==(Type const& _other) const return false; FunctionType const& other = dynamic_cast(_other); - if (m_location != other.m_location) + if (m_kind != other.m_kind) return false; if (m_isConstant != other.isConstant()) return false; @@ -2231,7 +2231,7 @@ bool FunctionType::operator==(Type const& _other) const bool FunctionType::isExplicitlyConvertibleTo(Type const& _convertTo) const { - if (m_location == Location::External && _convertTo.category() == Category::Integer) + if (m_kind == Kind::External && _convertTo.category() == Category::Integer) { IntegerType const& convertTo = dynamic_cast(_convertTo); if (convertTo.isAddress()) @@ -2249,7 +2249,7 @@ TypePointer FunctionType::unaryOperatorResult(Token::Value _operator) const string FunctionType::canonicalName(bool) const { - solAssert(m_location == Location::External, ""); + solAssert(m_kind == Kind::External, ""); return "function"; } @@ -2263,7 +2263,7 @@ string FunctionType::toString(bool _short) const name += " constant"; if (m_isPayable) name += " payable"; - if (m_location == Location::External) + if (m_kind == Kind::External) name += " external"; if (!m_returnParameterTypes.empty()) { @@ -2285,7 +2285,7 @@ unsigned FunctionType::calldataEncodedSize(bool _padded) const u256 FunctionType::storageSize() const { - if (m_location == Location::External || m_location == Location::Internal) + if (m_kind == Kind::External || m_kind == Kind::Internal) return 1; else BOOST_THROW_EXCEPTION( @@ -2295,9 +2295,9 @@ u256 FunctionType::storageSize() const unsigned FunctionType::storageBytes() const { - if (m_location == Location::External) + if (m_kind == Kind::External) return 20 + 4; - else if (m_location == Location::Internal) + else if (m_kind == Kind::Internal) return 8; // it should really not be possible to create larger programs else BOOST_THROW_EXCEPTION( @@ -2307,21 +2307,21 @@ unsigned FunctionType::storageBytes() const unsigned FunctionType::sizeOnStack() const { - Location location = m_location; - if (m_location == Location::SetGas || m_location == Location::SetValue) + Kind kind = m_kind; + if (m_kind == Kind::SetGas || m_kind == Kind::SetValue) { solAssert(m_returnParameterTypes.size() == 1, ""); - location = dynamic_cast(*m_returnParameterTypes.front()).m_location; + kind = dynamic_cast(*m_returnParameterTypes.front()).m_kind; } unsigned size = 0; - if (location == Location::External || location == Location::CallCode || location == Location::DelegateCall) + if (kind == Kind::External || kind == Kind::CallCode || kind == Kind::DelegateCall) size = 2; - else if (location == Location::Bare || location == Location::BareCallCode || location == Location::BareDelegateCall) + else if (kind == Kind::Bare || kind == Kind::BareCallCode || kind == Kind::BareDelegateCall) size = 1; - else if (location == Location::Internal) + else if (kind == Kind::Internal) size = 1; - else if (location == Location::ArrayPush || location == Location::ByteArrayPush) + else if (kind == Kind::ArrayPush || kind == Kind::ByteArrayPush) size = 1; if (m_gasSet) size++; @@ -2362,26 +2362,26 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const return make_shared( paramTypes, retParamTypes, m_parameterNames, m_returnParameterNames, - m_location, m_arbitraryParameters, + m_kind, m_arbitraryParameters, m_declaration, m_isConstant, m_isPayable ); } MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) const { - switch (m_location) + switch (m_kind) { - case Location::External: - case Location::Creation: - case Location::ECRecover: - case Location::SHA256: - case Location::RIPEMD160: - case Location::Bare: - case Location::BareCallCode: - case Location::BareDelegateCall: + case Kind::External: + case Kind::Creation: + case Kind::ECRecover: + case Kind::SHA256: + case Kind::RIPEMD160: + case Kind::Bare: + case Kind::BareCallCode: + case Kind::BareDelegateCall: { MemberList::MemberMap members; - if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall) + if (m_kind != Kind::BareDelegateCall && m_kind != Kind::DelegateCall) { if (m_isPayable) members.push_back(MemberList::Member( @@ -2391,7 +2391,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con TypePointers{copyAndSetGasOrValue(false, true)}, strings(), strings(), - Location::SetValue, + Kind::SetValue, false, nullptr, false, @@ -2401,7 +2401,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con ) )); } - if (m_location != Location::Creation) + if (m_kind != Kind::Creation) members.push_back(MemberList::Member( "gas", make_shared( @@ -2409,7 +2409,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con TypePointers{copyAndSetGasOrValue(true, false)}, strings(), strings(), - Location::SetGas, + Kind::SetGas, false, nullptr, false, @@ -2428,7 +2428,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con TypePointer FunctionType::encodingType() const { // Only external functions can be encoded, internal functions cannot leave code boundaries. - if (m_location == Location::External) + if (m_kind == Kind::External) return shared_from_this(); else return TypePointer(); @@ -2436,7 +2436,7 @@ TypePointer FunctionType::encodingType() const TypePointer FunctionType::interfaceType(bool /*_inLibrary*/) const { - if (m_location == Location::External) + if (m_kind == Kind::External) return shared_from_this(); else return TypePointer(); @@ -2478,14 +2478,14 @@ bool FunctionType::hasEqualArgumentTypes(FunctionType const& _other) const bool FunctionType::isBareCall() const { - switch (m_location) + switch (m_kind) { - case Location::Bare: - case Location::BareCallCode: - case Location::BareDelegateCall: - case Location::ECRecover: - case Location::SHA256: - case Location::RIPEMD160: + case Kind::Bare: + case Kind::BareCallCode: + case Kind::BareDelegateCall: + case Kind::ECRecover: + case Kind::SHA256: + case Kind::RIPEMD160: return true; default: return false; @@ -2520,13 +2520,13 @@ u256 FunctionType::externalIdentifier() const bool FunctionType::isPure() const { return - m_location == Location::SHA3 || - m_location == Location::ECRecover || - m_location == Location::SHA256 || - m_location == Location::RIPEMD160 || - m_location == Location::AddMod || - m_location == Location::MulMod || - m_location == Location::ObjectCreation; + m_kind == Kind::SHA3 || + m_kind == Kind::ECRecover || + m_kind == Kind::SHA256 || + m_kind == Kind::RIPEMD160 || + m_kind == Kind::AddMod || + m_kind == Kind::MulMod || + m_kind == Kind::ObjectCreation; } TypePointers FunctionType::parseElementaryTypeVector(strings const& _types) @@ -2545,7 +2545,7 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con m_returnParameterTypes, m_parameterNames, m_returnParameterNames, - m_location, + m_kind, m_arbitraryParameters, m_declaration, m_isConstant, @@ -2571,18 +2571,18 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound) parameterTypes.push_back(t); } - Location location = m_location; + Kind kind = m_kind; if (_inLibrary) { solAssert(!!m_declaration, "Declaration has to be available."); if (!m_declaration->isPublic()) - location = Location::Internal; // will be inlined + kind = Kind::Internal; // will be inlined else - location = Location::DelegateCall; + kind = Kind::DelegateCall; } TypePointers returnParameterTypes = m_returnParameterTypes; - if (location != Location::Internal) + if (kind != Kind::Internal) { // Alter dynamic types to be non-accessible. for (auto& param: returnParameterTypes) @@ -2595,7 +2595,7 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound) returnParameterTypes, m_parameterNames, m_returnParameterNames, - location, + kind, m_arbitraryParameters, m_declaration, m_isConstant, diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 78326aa6..c4ffc44c 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -817,8 +817,7 @@ class FunctionType: public Type { public: /// How this function is invoked on the EVM. - /// @todo This documentation is outdated, and Location should rather be named "Type" - enum class Location + enum class Kind { Internal, ///< stack-call using plain JUMP External, ///< external call using CALL @@ -868,7 +867,7 @@ public: FunctionType( strings const& _parameterTypes, strings const& _returnParameterTypes, - Location _location = Location::Internal, + Kind _kind = Kind::Internal, bool _arbitraryParameters = false, bool _constant = false, bool _payable = false @@ -877,7 +876,7 @@ public: parseElementaryTypeVector(_returnParameterTypes), strings(), strings(), - _location, + _kind, _arbitraryParameters, nullptr, _constant, @@ -895,7 +894,7 @@ public: TypePointers const& _returnParameterTypes, strings _parameterNames = strings(), strings _returnParameterNames = strings(), - Location _location = Location::Internal, + Kind _kind = Kind::Internal, bool _arbitraryParameters = false, Declaration const* _declaration = nullptr, bool _isConstant = false, @@ -908,7 +907,7 @@ public: m_returnParameterTypes(_returnParameterTypes), m_parameterNames(_parameterNames), m_returnParameterNames(_returnParameterNames), - m_location(_location), + m_kind(_kind), m_arbitraryParameters(_arbitraryParameters), m_gasSet(_gasSet), m_valueSet(_valueSet), @@ -937,11 +936,11 @@ public: virtual std::string canonicalName(bool /*_addDataLocation*/) const override; virtual std::string toString(bool _short) const override; virtual unsigned calldataEncodedSize(bool _padded) const override; - virtual bool canBeStored() const override { return m_location == Location::Internal || m_location == Location::External; } + virtual bool canBeStored() const override { return m_kind == Kind::Internal || m_kind == Kind::External; } virtual u256 storageSize() const override; virtual unsigned storageBytes() const override; virtual bool isValueType() const override { return true; } - virtual bool canLiveOutsideStorage() const override { return m_location == Location::Internal || m_location == Location::External; } + virtual bool canLiveOutsideStorage() const override { return m_kind == Kind::Internal || m_kind == Kind::External; } virtual unsigned sizeOnStack() const override; virtual MemberList::MemberMap nativeMembers(ContractDefinition const* _currentScope) const override; virtual TypePointer encodingType() const override; @@ -964,7 +963,7 @@ public: /// @returns true if the ABI is used for this call (only meaningful for external calls) bool isBareCall() const; - Location const& location() const { return m_location; } + Kind const& kind() const { return m_kind; } /// @returns the external signature of this function type given the function name std::string externalSignature() const; /// @returns the external identifier of this function (the hash of the signature). @@ -986,7 +985,7 @@ public: ASTPointer documentation() const; /// true iff arguments are to be padded to multiples of 32 bytes for external calls - bool padArguments() const { return !(m_location == Location::SHA3 || m_location == Location::SHA256 || m_location == Location::RIPEMD160); } + bool padArguments() const { return !(m_kind == Kind::SHA3 || m_kind == Kind::SHA256 || m_kind == Kind::RIPEMD160); } bool takesArbitraryParameters() const { return m_arbitraryParameters; } bool gasSet() const { return m_gasSet; } bool valueSet() const { return m_valueSet; } @@ -1012,7 +1011,7 @@ private: TypePointers m_returnParameterTypes; std::vector m_parameterNames; std::vector m_returnParameterNames; - Location const m_location; + Kind const m_kind; /// true if the function takes an arbitrary number of arguments of arbitrary types bool const m_arbitraryParameters = false; bool const m_gasSet = false; ///< true iff the gas value to be used is on the stack -- cgit