From 46dfdc97aff9f7c0f2388f1e4bb3b75939f666d1 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 9 Feb 2015 14:08:48 +0100 Subject: [PATCH] Camelcasing enums in Types.h --- libsolidity/AST.cpp | 2 +- libsolidity/ExpressionCompiler.cpp | 40 +++++++++++----------- libsolidity/GlobalContext.cpp | 20 +++++------ libsolidity/Types.cpp | 52 ++++++++++++++--------------- libsolidity/Types.h | 24 ++++++------- test/SolidityExpressionCompiler.cpp | 2 +- 6 files changed, 70 insertions(+), 70 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 962097ed2..124283d85 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -565,7 +565,7 @@ void NewExpression::checkTypeRequirements() shared_ptr contractType = make_shared(*m_contract); TypePointers const& parameterTypes = contractType->getConstructorType()->getParameterTypes(); m_type = make_shared(parameterTypes, TypePointers{contractType}, - FunctionType::Location::CREATION); + FunctionType::Location::Creation); } void MemberAccess::checkTypeRequirements() diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index b7f8dab91..1da309e67 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -227,7 +227,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) switch (function.getLocation()) { - case Location::INTERNAL: + case Location::Internal: { // Calling convention: Caller pushes return address and arguments // Callee removes them and pushes return values @@ -253,12 +253,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) CompilerUtils(m_context).popStackElement(*function.getReturnParameterTypes()[i]); break; } - case Location::EXTERNAL: - case Location::BARE: + case Location::External: + case Location::Bare: _functionCall.getExpression().accept(*this); - appendExternalFunctionCall(function, arguments, function.getLocation() == Location::BARE); + appendExternalFunctionCall(function, arguments, function.getLocation() == Location::Bare); break; - case Location::CREATION: + case Location::Creation: { _functionCall.getExpression().accept(*this); solAssert(!function.gasSet(), "Gas limit set for contract creation."); @@ -287,7 +287,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << eth::swapInstruction(1) << eth::Instruction::POP; break; } - case Location::SET_GAS: + case Location::SetGas: { // stack layout: contract_address function_id [gas] [value] _functionCall.getExpression().accept(*this); @@ -302,7 +302,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << eth::Instruction::POP; break; } - case Location::SET_VALUE: + case Location::SetValue: // stack layout: contract_address function_id [gas] [value] _functionCall.getExpression().accept(*this); // Note that function is not the original function, but the ".value" function. @@ -311,16 +311,16 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << eth::Instruction::POP; arguments.front()->accept(*this); break; - case Location::SEND: + case Location::Send: _functionCall.getExpression().accept(*this); m_context << u256(0); // 0 gas, we do not want to execute code arguments.front()->accept(*this); appendTypeConversion(*arguments.front()->getType(), *function.getParameterTypes().front(), true); appendExternalFunctionCall(FunctionType(TypePointers{}, TypePointers{}, - Location::EXTERNAL, true, true), {}, true); + Location::External, true, true), {}, true); break; - case Location::SUICIDE: + case Location::Suicide: arguments.front()->accept(*this); appendTypeConversion(*arguments.front()->getType(), *function.getParameterTypes().front(), true); m_context << eth::Instruction::SUICIDE; @@ -331,13 +331,13 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << u256(length) << u256(0) << eth::Instruction::SHA3; break; } - case Location::LOG0: - case Location::LOG1: - case Location::LOG2: - case Location::LOG3: - case Location::LOG4: + case Location::Log0: + case Location::Log1: + case Location::Log2: + case Location::Log3: + case Location::Log4: { - unsigned logNumber = int(function.getLocation()) - int(Location::LOG0); + unsigned logNumber = int(function.getLocation()) - int(Location::Log0); for (unsigned arg = logNumber; arg > 0; --arg) { arguments[arg]->accept(*this); @@ -349,7 +349,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << u256(length) << u256(0) << eth::logInstruction(logNumber); break; } - case Location::EVENT: + case Location::Event: { _functionCall.getExpression().accept(*this); auto const& event = dynamic_cast(function.getDeclaration()); @@ -375,18 +375,18 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << u256(memLength) << u256(0) << eth::logInstruction(numIndexed); break; } - case Location::BLOCKHASH: + case Location::BlockHash: { arguments[0]->accept(*this); appendTypeConversion(*arguments[0]->getType(), *function.getParameterTypes()[0], true); m_context << eth::Instruction::BLOCKHASH; break; } - case Location::ECRECOVER: + case Location::ECRecover: case Location::SHA256: case Location::RIPEMD160: { - static const map contractAddresses{{Location::ECRECOVER, 1}, + static const map contractAddresses{{Location::ECRecover, 1}, {Location::SHA256, 2}, {Location::RIPEMD160, 3}}; m_context << contractAddresses.find(function.getLocation())->second; diff --git a/libsolidity/GlobalContext.cpp b/libsolidity/GlobalContext.cpp index 687c9c9d4..8443e7bd9 100644 --- a/libsolidity/GlobalContext.cpp +++ b/libsolidity/GlobalContext.cpp @@ -34,27 +34,27 @@ namespace solidity { GlobalContext::GlobalContext(): -m_magicVariables(vector>{make_shared("block", make_shared(MagicType::Kind::BLOCK)), - make_shared("msg", make_shared(MagicType::Kind::MSG)), - make_shared("tx", make_shared(MagicType::Kind::TX)), +m_magicVariables(vector>{make_shared("block", make_shared(MagicType::Kind::Block)), + make_shared("msg", make_shared(MagicType::Kind::Message)), + make_shared("tx", make_shared(MagicType::Kind::Transaction)), make_shared("suicide", - make_shared(strings{"address"}, strings{}, FunctionType::Location::SUICIDE)), + make_shared(strings{"address"}, strings{}, FunctionType::Location::Suicide)), make_shared("sha3", make_shared(strings{"hash"}, strings{"hash"}, FunctionType::Location::SHA3)), make_shared("log0", - make_shared(strings{"hash"},strings{}, FunctionType::Location::LOG0)), + make_shared(strings{"hash"},strings{}, FunctionType::Location::Log0)), make_shared("log1", - make_shared(strings{"hash", "hash"},strings{}, FunctionType::Location::LOG1)), + make_shared(strings{"hash", "hash"},strings{}, FunctionType::Location::Log1)), make_shared("log2", - make_shared(strings{"hash", "hash", "hash"},strings{}, FunctionType::Location::LOG2)), + make_shared(strings{"hash", "hash", "hash"},strings{}, FunctionType::Location::Log2)), make_shared("log3", - make_shared(strings{"hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::LOG3)), + make_shared(strings{"hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::Log3)), make_shared("log4", - make_shared(strings{"hash", "hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::LOG4)), + make_shared(strings{"hash", "hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::Log4)), make_shared("sha256", make_shared(strings{"hash"}, strings{"hash"}, FunctionType::Location::SHA256)), make_shared("ecrecover", - make_shared(strings{"hash", "hash8", "hash", "hash"}, strings{"address"}, FunctionType::Location::ECRECOVER)), + make_shared(strings{"hash", "hash8", "hash", "hash"}, strings{"address"}, FunctionType::Location::ECRecover)), make_shared("ripemd160", make_shared(strings{"hash"}, strings{"hash160"}, FunctionType::Location::RIPEMD160))}) { diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 1046e65e2..85340fd2c 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -45,8 +45,8 @@ shared_ptr Type::fromElementaryTypeName(Token::Value _typeToken) bytes = 32; int modifier = offset / 33; return make_shared(bytes * 8, - modifier == 0 ? IntegerType::Modifier::SIGNED : - modifier == 1 ? IntegerType::Modifier::UNSIGNED : + modifier == 0 ? IntegerType::Modifier::Signed : + modifier == 1 ? IntegerType::Modifier::Unsigned : IntegerType::Modifier::Hash); } else if (_typeToken == Token::Address) @@ -211,10 +211,10 @@ TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointe const MemberList IntegerType::AddressMemberList = MemberList({{"balance", make_shared(256)}, {"callstring32", make_shared(strings{"string32"}, strings{}, - FunctionType::Location::BARE)}, + FunctionType::Location::Bare)}, {"callstring32string32", make_shared(strings{"string32", "string32"}, - strings{}, FunctionType::Location::BARE)}, - {"send", make_shared(strings{"uint"}, strings{}, FunctionType::Location::SEND)}}); + strings{}, FunctionType::Location::Bare)}, + {"send", make_shared(strings{"uint"}, strings{}, FunctionType::Location::Send)}}); IntegerConstantType::IntegerConstantType(Literal const& _literal) { @@ -374,8 +374,8 @@ shared_ptr IntegerConstantType::getIntegerType() const return shared_ptr(); else return make_shared(max(bytesRequired(value), 1u) * 8, - negative ? IntegerType::Modifier::SIGNED - : IntegerType::Modifier::UNSIGNED); + negative ? IntegerType::Modifier::Signed + : IntegerType::Modifier::Unsigned); } shared_ptr StaticStringType::smallestTypeForLiteral(string const& _literal) @@ -616,7 +616,7 @@ 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) { @@ -646,7 +646,7 @@ FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal } FunctionType::FunctionType(VariableDeclaration const& _varDecl): - m_location(Location::EXTERNAL), m_isConstant(true), m_declaration(&_varDecl) + m_location(Location::External), m_isConstant(true), m_declaration(&_varDecl) { TypePointers params; vector paramNames; @@ -683,7 +683,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): } FunctionType::FunctionType(const EventDefinition& _event): - m_location(Location::EVENT), m_declaration(&_event) + m_location(Location::Event), m_declaration(&_event) { TypePointers params; vector paramNames; @@ -740,9 +740,9 @@ string FunctionType::toString() const unsigned FunctionType::getSizeOnStack() const { unsigned size = 0; - if (m_location == Location::EXTERNAL) + if (m_location == Location::External) size = 2; - else if (m_location == Location::INTERNAL || m_location == Location::BARE) + else if (m_location == Location::Internal || m_location == Location::Bare) size = 1; if (m_gasSet) size++; @@ -755,22 +755,22 @@ MemberList const& FunctionType::getMembers() const { switch (m_location) { - case Location::EXTERNAL: - case Location::CREATION: - case Location::ECRECOVER: + case Location::External: + case Location::Creation: + case Location::ECRecover: case Location::SHA256: case Location::RIPEMD160: - case Location::BARE: + case Location::Bare: if (!m_members) { map members{ {"gas", make_shared(parseElementaryTypeVector({"uint"}), TypePointers{copyAndSetGasOrValue(true, false)}, - Location::SET_GAS, m_gasSet, m_valueSet)}, + Location::SetGas, m_gasSet, m_valueSet)}, {"value", make_shared(parseElementaryTypeVector({"uint"}), TypePointers{copyAndSetGasOrValue(false, true)}, - Location::SET_VALUE, m_gasSet, m_valueSet)}}; - if (m_location == Location::CREATION) + Location::SetValue, m_gasSet, m_valueSet)}}; + if (m_location == Location::Creation) members.erase("gas"); m_members.reset(new MemberList(members)); } @@ -919,20 +919,20 @@ MagicType::MagicType(MagicType::Kind _kind): { switch (m_kind) { - case Kind::BLOCK: + case Kind::Block: m_members = MemberList({{"coinbase", make_shared(0, IntegerType::Modifier::Address)}, {"timestamp", make_shared(256)}, - {"blockhash", make_shared(strings{"uint"}, strings{"hash"}, FunctionType::Location::BLOCKHASH)}, + {"blockhash", make_shared(strings{"uint"}, strings{"hash"}, FunctionType::Location::BlockHash)}, {"difficulty", make_shared(256)}, {"number", make_shared(256)}, {"gaslimit", make_shared(256)}}); break; - case Kind::MSG: + case Kind::Message: m_members = MemberList({{"sender", make_shared(0, IntegerType::Modifier::Address)}, {"gas", make_shared(256)}, {"value", make_shared(256)}}); break; - case Kind::TX: + case Kind::Transaction: m_members = MemberList({{"origin", make_shared(0, IntegerType::Modifier::Address)}, {"gasprice", make_shared(256)}}); break; @@ -953,11 +953,11 @@ string MagicType::toString() const { switch (m_kind) { - case Kind::BLOCK: + case Kind::Block: return "block"; - case Kind::MSG: + case Kind::Message: return "msg"; - case Kind::TX: + case Kind::Transaction: return "tx"; default: BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown kind of magic.")); diff --git a/libsolidity/Types.h b/libsolidity/Types.h index 57d0c3aee..4d8a9aedf 100644 --- a/libsolidity/Types.h +++ b/libsolidity/Types.h @@ -160,11 +160,11 @@ class IntegerType: public Type public: enum class Modifier { - UNSIGNED, SIGNED, Hash, Address + Unsigned, Signed, Hash, Address }; virtual Category getCategory() const override { return Category::Integer; } - explicit IntegerType(int _bits, Modifier _modifier = Modifier::UNSIGNED); + explicit IntegerType(int _bits, Modifier _modifier = Modifier::Unsigned); virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; @@ -184,7 +184,7 @@ public: int getNumBits() const { return m_bits; } bool isHash() const { return m_modifier == Modifier::Hash || m_modifier == Modifier::Address; } bool isAddress() const { return m_modifier == Modifier::Address; } - bool isSigned() const { return m_modifier == Modifier::SIGNED; } + bool isSigned() const { return m_modifier == Modifier::Signed; } static const MemberList AddressMemberList; @@ -357,23 +357,23 @@ public: /// BARE: contract address (non-abi contract call) /// OTHERS: special virtual function, nothing on the stack /// @todo This documentation is outdated, and Location should rather be named "Type" - enum class Location { INTERNAL, EXTERNAL, CREATION, SEND, - SHA3, SUICIDE, - ECRECOVER, SHA256, RIPEMD160, - LOG0, LOG1, LOG2, LOG3, LOG4, EVENT, - SET_GAS, SET_VALUE, BLOCKHASH, - BARE }; + enum class Location { Internal, External, Creation, Send, + SHA3, Suicide, + ECRecover, SHA256, RIPEMD160, + Log0, Log1, Log2, Log3, Log4, Event, + SetGas, SetValue, BlockHash, + Bare }; virtual Category getCategory() const override { return Category::Function; } explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true); explicit FunctionType(VariableDeclaration const& _varDecl); explicit FunctionType(EventDefinition const& _event); FunctionType(strings const& _parameterTypes, strings const& _returnParameterTypes, - Location _location = Location::INTERNAL): + Location _location = Location::Internal): FunctionType(parseElementaryTypeVector(_parameterTypes), parseElementaryTypeVector(_returnParameterTypes), _location) {} FunctionType(TypePointers const& _parameterTypes, TypePointers const& _returnParameterTypes, - Location _location = Location::INTERNAL, + Location _location = Location::Internal, bool _gasSet = false, bool _valueSet = false): m_parameterTypes(_parameterTypes), m_returnParameterTypes(_returnParameterTypes), m_location(_location), m_gasSet(_gasSet), m_valueSet(_valueSet) {} @@ -530,7 +530,7 @@ private: class MagicType: public Type { public: - enum class Kind { BLOCK, MSG, TX }; + enum class Kind { Block, Message, Transaction }; virtual Category getCategory() const override { return Category::Magic; } explicit MagicType(Kind _kind); diff --git a/test/SolidityExpressionCompiler.cpp b/test/SolidityExpressionCompiler.cpp index 3c3ea1baa..9cd13dcfd 100644 --- a/test/SolidityExpressionCompiler.cpp +++ b/test/SolidityExpressionCompiler.cpp @@ -477,7 +477,7 @@ BOOST_AUTO_TEST_CASE(blockhash) " }\n" "}\n"; bytes code = compileFirstExpression(sourceCode, {}, {}, - {make_shared("block", make_shared(MagicType::Kind::BLOCK))}); + {make_shared("block", make_shared(MagicType::Kind::Block))}); bytes expectation({byte(eth::Instruction::PUSH1), 0x03, byte(eth::Instruction::BLOCKHASH)});