mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Camelcasing enums in Types.h
This commit is contained in:
parent
6f621f8486
commit
3ef75bae6b
2
AST.cpp
2
AST.cpp
@ -565,7 +565,7 @@ void NewExpression::checkTypeRequirements()
|
||||
shared_ptr<ContractType const> contractType = make_shared<ContractType>(*m_contract);
|
||||
TypePointers const& parameterTypes = contractType->getConstructorType()->getParameterTypes();
|
||||
m_type = make_shared<FunctionType>(parameterTypes, TypePointers{contractType},
|
||||
FunctionType::Location::CREATION);
|
||||
FunctionType::Location::Creation);
|
||||
}
|
||||
|
||||
void MemberAccess::checkTypeRequirements()
|
||||
|
@ -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<EventDefinition const&>(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<Location, u256> contractAddresses{{Location::ECRECOVER, 1},
|
||||
static const map<Location, u256> contractAddresses{{Location::ECRecover, 1},
|
||||
{Location::SHA256, 2},
|
||||
{Location::RIPEMD160, 3}};
|
||||
m_context << contractAddresses.find(function.getLocation())->second;
|
||||
|
@ -34,27 +34,27 @@ namespace solidity
|
||||
{
|
||||
|
||||
GlobalContext::GlobalContext():
|
||||
m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::BLOCK)),
|
||||
make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::MSG)),
|
||||
make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::TX)),
|
||||
m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block)),
|
||||
make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message)),
|
||||
make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::Transaction)),
|
||||
make_shared<MagicVariableDeclaration>("suicide",
|
||||
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::SUICIDE)),
|
||||
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)),
|
||||
make_shared<MagicVariableDeclaration>("sha3",
|
||||
make_shared<FunctionType>(strings{"hash"}, strings{"hash"}, FunctionType::Location::SHA3)),
|
||||
make_shared<MagicVariableDeclaration>("log0",
|
||||
make_shared<FunctionType>(strings{"hash"},strings{}, FunctionType::Location::LOG0)),
|
||||
make_shared<FunctionType>(strings{"hash"},strings{}, FunctionType::Location::Log0)),
|
||||
make_shared<MagicVariableDeclaration>("log1",
|
||||
make_shared<FunctionType>(strings{"hash", "hash"},strings{}, FunctionType::Location::LOG1)),
|
||||
make_shared<FunctionType>(strings{"hash", "hash"},strings{}, FunctionType::Location::Log1)),
|
||||
make_shared<MagicVariableDeclaration>("log2",
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash"},strings{}, FunctionType::Location::LOG2)),
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash"},strings{}, FunctionType::Location::Log2)),
|
||||
make_shared<MagicVariableDeclaration>("log3",
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::LOG3)),
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::Log3)),
|
||||
make_shared<MagicVariableDeclaration>("log4",
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::LOG4)),
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::Log4)),
|
||||
make_shared<MagicVariableDeclaration>("sha256",
|
||||
make_shared<FunctionType>(strings{"hash"}, strings{"hash"}, FunctionType::Location::SHA256)),
|
||||
make_shared<MagicVariableDeclaration>("ecrecover",
|
||||
make_shared<FunctionType>(strings{"hash", "hash8", "hash", "hash"}, strings{"address"}, FunctionType::Location::ECRECOVER)),
|
||||
make_shared<FunctionType>(strings{"hash", "hash8", "hash", "hash"}, strings{"address"}, FunctionType::Location::ECRecover)),
|
||||
make_shared<MagicVariableDeclaration>("ripemd160",
|
||||
make_shared<FunctionType>(strings{"hash"}, strings{"hash160"}, FunctionType::Location::RIPEMD160))})
|
||||
{
|
||||
|
52
Types.cpp
52
Types.cpp
@ -45,8 +45,8 @@ shared_ptr<Type const> Type::fromElementaryTypeName(Token::Value _typeToken)
|
||||
bytes = 32;
|
||||
int modifier = offset / 33;
|
||||
return make_shared<IntegerType>(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<IntegerType >(256)},
|
||||
{"callstring32", make_shared<FunctionType>(strings{"string32"}, strings{},
|
||||
FunctionType::Location::BARE)},
|
||||
FunctionType::Location::Bare)},
|
||||
{"callstring32string32", make_shared<FunctionType>(strings{"string32", "string32"},
|
||||
strings{}, FunctionType::Location::BARE)},
|
||||
{"send", make_shared<FunctionType>(strings{"uint"}, strings{}, FunctionType::Location::SEND)}});
|
||||
strings{}, FunctionType::Location::Bare)},
|
||||
{"send", make_shared<FunctionType>(strings{"uint"}, strings{}, FunctionType::Location::Send)}});
|
||||
|
||||
IntegerConstantType::IntegerConstantType(Literal const& _literal)
|
||||
{
|
||||
@ -374,8 +374,8 @@ shared_ptr<IntegerType const> IntegerConstantType::getIntegerType() const
|
||||
return shared_ptr<IntegerType const>();
|
||||
else
|
||||
return make_shared<IntegerType>(max(bytesRequired(value), 1u) * 8,
|
||||
negative ? IntegerType::Modifier::SIGNED
|
||||
: IntegerType::Modifier::UNSIGNED);
|
||||
negative ? IntegerType::Modifier::Signed
|
||||
: IntegerType::Modifier::Unsigned);
|
||||
}
|
||||
|
||||
shared_ptr<StaticStringType> 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<string> 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<string> 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<string, TypePointer> members{
|
||||
{"gas", make_shared<FunctionType>(parseElementaryTypeVector({"uint"}),
|
||||
TypePointers{copyAndSetGasOrValue(true, false)},
|
||||
Location::SET_GAS, m_gasSet, m_valueSet)},
|
||||
Location::SetGas, m_gasSet, m_valueSet)},
|
||||
{"value", make_shared<FunctionType>(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<IntegerType>(0, IntegerType::Modifier::Address)},
|
||||
{"timestamp", make_shared<IntegerType>(256)},
|
||||
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"hash"}, FunctionType::Location::BLOCKHASH)},
|
||||
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"hash"}, FunctionType::Location::BlockHash)},
|
||||
{"difficulty", make_shared<IntegerType>(256)},
|
||||
{"number", make_shared<IntegerType>(256)},
|
||||
{"gaslimit", make_shared<IntegerType>(256)}});
|
||||
break;
|
||||
case Kind::MSG:
|
||||
case Kind::Message:
|
||||
m_members = MemberList({{"sender", make_shared<IntegerType>(0, IntegerType::Modifier::Address)},
|
||||
{"gas", make_shared<IntegerType>(256)},
|
||||
{"value", make_shared<IntegerType>(256)}});
|
||||
break;
|
||||
case Kind::TX:
|
||||
case Kind::Transaction:
|
||||
m_members = MemberList({{"origin", make_shared<IntegerType>(0, IntegerType::Modifier::Address)},
|
||||
{"gasprice", make_shared<IntegerType>(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."));
|
||||
|
24
Types.h
24
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);
|
||||
|
Loading…
Reference in New Issue
Block a user