Merge pull request #6543 from ethereum/typeprovider-bits

TypeProvider bits
This commit is contained in:
chriseth 2019-04-17 15:50:08 +02:00 committed by GitHub
commit 4509e8efbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 321 additions and 344 deletions

View File

@ -57,7 +57,7 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
setType( setType(
_operation, _operation,
TokenTraits::isCompareOp(_operation.getOperator()) ? TokenTraits::isCompareOp(_operation.getOperator()) ?
TypeProvider::boolType() : TypeProvider::boolean() :
commonType commonType
); );
} }

View File

@ -245,13 +245,13 @@ void ContractLevelChecker::checkAbstractFunctions(ContractDefinition const& _con
{ {
for (VariableDeclaration const* v: contract->stateVariables()) for (VariableDeclaration const* v: contract->stateVariables())
if (v->isPartOfExternalInterface()) if (v->isPartOfExternalInterface())
registerFunction(*v, TypeProvider::functionType(*v), true); registerFunction(*v, TypeProvider::function(*v), true);
for (FunctionDefinition const* function: contract->definedFunctions()) for (FunctionDefinition const* function: contract->definedFunctions())
if (!function->isConstructor()) if (!function->isConstructor())
registerFunction( registerFunction(
*function, *function,
TypeProvider::functionType(*function)->asCallableFunction(false), TypeProvider::function(*function)->asCallableFunction(false),
function->isImplemented() function->isImplemented()
); );
} }
@ -408,7 +408,7 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
for (FunctionDefinition const* f: contract->definedFunctions()) for (FunctionDefinition const* f: contract->definedFunctions())
if (f->isPartOfExternalInterface()) if (f->isPartOfExternalInterface())
{ {
auto functionType = TypeProvider::functionType(*f); auto functionType = TypeProvider::function(*f);
// under non error circumstances this should be true // under non error circumstances this should be true
if (functionType->interfaceFunctionType()) if (functionType->interfaceFunctionType())
externalDeclarations[functionType->externalSignature()].emplace_back( externalDeclarations[functionType->externalSignature()].emplace_back(
@ -418,7 +418,7 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
for (VariableDeclaration const* v: contract->stateVariables()) for (VariableDeclaration const* v: contract->stateVariables())
if (v->isPartOfExternalInterface()) if (v->isPartOfExternalInterface())
{ {
auto functionType = TypeProvider::functionType(*v); auto functionType = TypeProvider::function(*v);
// under non error circumstances this should be true // under non error circumstances this should be true
if (functionType->interfaceFunctionType()) if (functionType->interfaceFunctionType())
externalDeclarations[functionType->externalSignature()].emplace_back( externalDeclarations[functionType->externalSignature()].emplace_back(

View File

@ -42,33 +42,33 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
}; };
return { return {
magicVarDecl("abi", TypeProvider::magicType(MagicType::Kind::ABI)), magicVarDecl("abi", TypeProvider::magic(MagicType::Kind::ABI)),
magicVarDecl("addmod", TypeProvider::functionType(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)), magicVarDecl("addmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)),
magicVarDecl("assert", TypeProvider::functionType(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)), magicVarDecl("assert", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)),
magicVarDecl("block", TypeProvider::magicType(MagicType::Kind::Block)), magicVarDecl("block", TypeProvider::magic(MagicType::Kind::Block)),
magicVarDecl("blockhash", TypeProvider::functionType(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)), magicVarDecl("blockhash", TypeProvider::function(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)),
magicVarDecl("ecrecover", TypeProvider::functionType(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)), magicVarDecl("ecrecover", TypeProvider::function(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)),
magicVarDecl("gasleft", TypeProvider::functionType(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, false, StateMutability::View)), magicVarDecl("gasleft", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, false, StateMutability::View)),
magicVarDecl("keccak256", TypeProvider::functionType(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)), magicVarDecl("keccak256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)),
magicVarDecl("log0", TypeProvider::functionType(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)), magicVarDecl("log0", TypeProvider::function(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
magicVarDecl("log1", TypeProvider::functionType(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log1)), magicVarDecl("log1", TypeProvider::function(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log1)),
magicVarDecl("log2", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log2)), magicVarDecl("log2", TypeProvider::function(strings{"bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log2)),
magicVarDecl("log3", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log3)), magicVarDecl("log3", TypeProvider::function(strings{"bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log3)),
magicVarDecl("log4", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)), magicVarDecl("log4", TypeProvider::function(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
magicVarDecl("msg", TypeProvider::magicType(MagicType::Kind::Message)), magicVarDecl("msg", TypeProvider::magic(MagicType::Kind::Message)),
magicVarDecl("mulmod", TypeProvider::functionType(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)), magicVarDecl("mulmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)),
magicVarDecl("now", TypeProvider::uint256()), magicVarDecl("now", TypeProvider::uint256()),
magicVarDecl("require", TypeProvider::functionType(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)), magicVarDecl("require", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)),
magicVarDecl("require", TypeProvider::functionType(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)), magicVarDecl("require", TypeProvider::function(strings{"bool", "string memory"}, strings{}, FunctionType::Kind::Require, false, StateMutability::Pure)),
magicVarDecl("revert", TypeProvider::functionType(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)), magicVarDecl("revert", TypeProvider::function(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)),
magicVarDecl("revert", TypeProvider::functionType(strings{"string memory"}, strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)), magicVarDecl("revert", TypeProvider::function(strings{"string memory"}, strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)),
magicVarDecl("ripemd160", TypeProvider::functionType(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, false, StateMutability::Pure)), magicVarDecl("ripemd160", TypeProvider::function(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, false, StateMutability::Pure)),
magicVarDecl("selfdestruct", TypeProvider::functionType(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)), magicVarDecl("selfdestruct", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
magicVarDecl("sha256", TypeProvider::functionType(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, false, StateMutability::Pure)), magicVarDecl("sha256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, false, StateMutability::Pure)),
magicVarDecl("sha3", TypeProvider::functionType(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)), magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)),
magicVarDecl("suicide", TypeProvider::functionType(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)), magicVarDecl("suicide", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
magicVarDecl("tx", TypeProvider::magicType(MagicType::Kind::Transaction)), magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
magicVarDecl("type", TypeProvider::functionType( magicVarDecl("type", TypeProvider::function(
strings{"address"} /* accepts any contract type, handled by the type checker */, strings{"address"} /* accepts any contract type, handled by the type checker */,
strings{} /* returns a MagicType, handled by the type checker */, strings{} /* returns a MagicType, handled by the type checker */,
FunctionType::Kind::MetaType, FunctionType::Kind::MetaType,
@ -99,7 +99,7 @@ vector<Declaration const*> GlobalContext::declarations() const
MagicVariableDeclaration const* GlobalContext::currentThis() const MagicVariableDeclaration const* GlobalContext::currentThis() const
{ {
if (!m_thisPointer[m_currentContract]) if (!m_thisPointer[m_currentContract])
m_thisPointer[m_currentContract] = make_shared<MagicVariableDeclaration>("this", TypeProvider::contractType(*m_currentContract)); m_thisPointer[m_currentContract] = make_shared<MagicVariableDeclaration>("this", TypeProvider::contract(*m_currentContract));
return m_thisPointer[m_currentContract].get(); return m_thisPointer[m_currentContract].get();
} }
@ -107,7 +107,7 @@ MagicVariableDeclaration const* GlobalContext::currentThis() const
MagicVariableDeclaration const* GlobalContext::currentSuper() const MagicVariableDeclaration const* GlobalContext::currentSuper() const
{ {
if (!m_superPointer[m_currentContract]) if (!m_superPointer[m_currentContract])
m_superPointer[m_currentContract] = make_shared<MagicVariableDeclaration>("super", TypeProvider::contractType(*m_currentContract, true)); m_superPointer[m_currentContract] = make_shared<MagicVariableDeclaration>("super", TypeProvider::contract(*m_currentContract, true));
return m_superPointer[m_currentContract].get(); return m_superPointer[m_currentContract].get();
} }

View File

@ -129,10 +129,10 @@ bool ReferencesResolver::visit(ElementaryTypeName const& _typeName)
switch(*_typeName.stateMutability()) switch(*_typeName.stateMutability())
{ {
case StateMutability::Payable: case StateMutability::Payable:
_typeName.annotation().type = TypeProvider::payableAddressType(); _typeName.annotation().type = TypeProvider::payableAddress();
break; break;
case StateMutability::NonPayable: case StateMutability::NonPayable:
_typeName.annotation().type = TypeProvider::addressType(); _typeName.annotation().type = TypeProvider::address();
break; break;
default: default:
m_errorReporter.typeError( m_errorReporter.typeError(
@ -186,10 +186,10 @@ void ReferencesResolver::endVisit(UserDefinedTypeName const& _typeName)
else if (EnumDefinition const* enumDef = dynamic_cast<EnumDefinition const*>(declaration)) else if (EnumDefinition const* enumDef = dynamic_cast<EnumDefinition const*>(declaration))
_typeName.annotation().type = TypeProvider::enumType(*enumDef); _typeName.annotation().type = TypeProvider::enumType(*enumDef);
else if (ContractDefinition const* contract = dynamic_cast<ContractDefinition const*>(declaration)) else if (ContractDefinition const* contract = dynamic_cast<ContractDefinition const*>(declaration))
_typeName.annotation().type = TypeProvider::contractType(*contract); _typeName.annotation().type = TypeProvider::contract(*contract);
else else
{ {
_typeName.annotation().type = TypeProvider::emptyTupleType(); _typeName.annotation().type = TypeProvider::emptyTuple();
typeError(_typeName.location(), "Name has to refer to a struct, enum or contract."); typeError(_typeName.location(), "Name has to refer to a struct, enum or contract.");
} }
} }
@ -223,7 +223,7 @@ void ReferencesResolver::endVisit(FunctionTypeName const& _typeName)
} }
} }
_typeName.annotation().type = TypeProvider::functionType(_typeName); _typeName.annotation().type = TypeProvider::function(_typeName);
} }
void ReferencesResolver::endVisit(Mapping const& _typeName) void ReferencesResolver::endVisit(Mapping const& _typeName)
@ -231,10 +231,10 @@ void ReferencesResolver::endVisit(Mapping const& _typeName)
TypePointer keyType = _typeName.keyType().annotation().type; TypePointer keyType = _typeName.keyType().annotation().type;
TypePointer valueType = _typeName.valueType().annotation().type; TypePointer valueType = _typeName.valueType().annotation().type;
// Convert key type to memory. // Convert key type to memory.
keyType = ReferenceType::copyForLocationIfReference(DataLocation::Memory, keyType); keyType = TypeProvider::withLocationIfReference(DataLocation::Memory, keyType);
// Convert value type to storage reference. // Convert value type to storage reference.
valueType = ReferenceType::copyForLocationIfReference(DataLocation::Storage, valueType); valueType = TypeProvider::withLocationIfReference(DataLocation::Storage, valueType);
_typeName.annotation().type = TypeProvider::mappingType(keyType, valueType); _typeName.annotation().type = TypeProvider::mapping(keyType, valueType);
} }
void ReferencesResolver::endVisit(ArrayTypeName const& _typeName) void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
@ -262,10 +262,10 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
else if (lengthType->isNegative()) else if (lengthType->isNegative())
fatalTypeError(length->location(), "Array with negative length specified."); fatalTypeError(length->location(), "Array with negative length specified.");
else else
_typeName.annotation().type = TypeProvider::arrayType(DataLocation::Storage, baseType, lengthType->literalValue(nullptr)); _typeName.annotation().type = TypeProvider::array(DataLocation::Storage, baseType, lengthType->literalValue(nullptr));
} }
else else
_typeName.annotation().type = TypeProvider::arrayType(DataLocation::Storage, baseType); _typeName.annotation().type = TypeProvider::array(DataLocation::Storage, baseType);
} }
bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly) bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)

View File

@ -138,7 +138,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
if (arguments.size() >= 1) if (arguments.size() >= 1)
{ {
BoolResult result = type(*arguments.front())->isImplicitlyConvertibleTo(*TypeProvider::bytesMemoryType()); BoolResult result = type(*arguments.front())->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory());
if (!result) if (!result)
m_errorReporter.typeErrorConcatenateDescriptions( m_errorReporter.typeErrorConcatenateDescriptions(
@ -180,7 +180,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
actualType = TypeProvider::withLocationIfReference(DataLocation::Memory, actualType); actualType = TypeProvider::withLocationIfReference(DataLocation::Memory, actualType);
// We force address payable for address types. // We force address payable for address types.
if (actualType->category() == Type::Category::Address) if (actualType->category() == Type::Category::Address)
actualType = TypeProvider::payableAddressType(); actualType = TypeProvider::payableAddress();
solAssert( solAssert(
!actualType->dataStoredIn(DataLocation::CallData) && !actualType->dataStoredIn(DataLocation::CallData) &&
!actualType->dataStoredIn(DataLocation::Storage), !actualType->dataStoredIn(DataLocation::Storage),
@ -196,7 +196,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
else else
{ {
m_errorReporter.typeError(typeArgument->location(), "Argument has to be a type name."); m_errorReporter.typeError(typeArgument->location(), "Argument has to be a type name.");
components.push_back(TypeProvider::emptyTupleType()); components.push_back(TypeProvider::emptyTuple());
} }
} }
return components; return components;
@ -231,7 +231,7 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
return {}; return {};
} }
return {MagicType::metaType(dynamic_cast<TypeType const&>(*firstArgType).actualType())}; return {TypeProvider::meta(dynamic_cast<TypeType const&>(*firstArgType).actualType())};
} }
void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance) void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
@ -717,7 +717,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
bool TypeChecker::visit(IfStatement const& _ifStatement) bool TypeChecker::visit(IfStatement const& _ifStatement)
{ {
expectType(_ifStatement.condition(), *TypeProvider::boolType()); expectType(_ifStatement.condition(), *TypeProvider::boolean());
_ifStatement.trueStatement().accept(*this); _ifStatement.trueStatement().accept(*this);
if (_ifStatement.falseStatement()) if (_ifStatement.falseStatement())
_ifStatement.falseStatement()->accept(*this); _ifStatement.falseStatement()->accept(*this);
@ -726,7 +726,7 @@ bool TypeChecker::visit(IfStatement const& _ifStatement)
bool TypeChecker::visit(WhileStatement const& _whileStatement) bool TypeChecker::visit(WhileStatement const& _whileStatement)
{ {
expectType(_whileStatement.condition(), *TypeProvider::boolType()); expectType(_whileStatement.condition(), *TypeProvider::boolean());
_whileStatement.body().accept(*this); _whileStatement.body().accept(*this);
return false; return false;
} }
@ -736,7 +736,7 @@ bool TypeChecker::visit(ForStatement const& _forStatement)
if (_forStatement.initializationExpression()) if (_forStatement.initializationExpression())
_forStatement.initializationExpression()->accept(*this); _forStatement.initializationExpression()->accept(*this);
if (_forStatement.condition()) if (_forStatement.condition())
expectType(*_forStatement.condition(), *TypeProvider::boolType()); expectType(*_forStatement.condition(), *TypeProvider::boolean());
if (_forStatement.loopExpression()) if (_forStatement.loopExpression())
_forStatement.loopExpression()->accept(*this); _forStatement.loopExpression()->accept(*this);
_forStatement.body().accept(*this); _forStatement.body().accept(*this);
@ -951,7 +951,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
else else
solAssert(false, ""); solAssert(false, "");
} }
else if (*var.annotation().type == *TypeProvider::emptyTupleType()) else if (*var.annotation().type == *TypeProvider::emptyTuple())
solAssert(false, "Cannot declare variable with void (empty tuple) type."); solAssert(false, "Cannot declare variable with void (empty tuple) type.");
else if (valueComponentType->category() == Type::Category::RationalNumber) else if (valueComponentType->category() == Type::Category::RationalNumber)
{ {
@ -1073,7 +1073,7 @@ void TypeChecker::endVisit(ExpressionStatement const& _statement)
bool TypeChecker::visit(Conditional const& _conditional) bool TypeChecker::visit(Conditional const& _conditional)
{ {
expectType(_conditional.condition(), *TypeProvider::boolType()); expectType(_conditional.condition(), *TypeProvider::boolean());
_conditional.trueExpression().accept(*this); _conditional.trueExpression().accept(*this);
_conditional.falseExpression().accept(*this); _conditional.falseExpression().accept(*this);
@ -1177,7 +1177,7 @@ bool TypeChecker::visit(Assignment const& _assignment)
"Compound assignment is not allowed for tuple types." "Compound assignment is not allowed for tuple types."
); );
// Sequenced assignments of tuples is not valid, make the result a "void" type. // Sequenced assignments of tuples is not valid, make the result a "void" type.
_assignment.annotation().type = TypeProvider::emptyTupleType(); _assignment.annotation().type = TypeProvider::emptyTuple();
expectType(_assignment.rightHandSide(), *tupleType); expectType(_assignment.rightHandSide(), *tupleType);
@ -1229,7 +1229,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
if (components.size() == 1) if (components.size() == 1)
_tuple.annotation().type = type(*components[0]); _tuple.annotation().type = type(*components[0]);
else else
_tuple.annotation().type = TypeProvider::tupleType(move(types)); _tuple.annotation().type = TypeProvider::tuple(move(types));
// If some of the components are not LValues, the error is reported above. // If some of the components are not LValues, the error is reported above.
_tuple.annotation().isLValue = true; _tuple.annotation().isLValue = true;
} }
@ -1286,14 +1286,14 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
else if (!inlineArrayType->canLiveOutsideStorage()) else if (!inlineArrayType->canLiveOutsideStorage())
m_errorReporter.fatalTypeError(_tuple.location(), "Type " + inlineArrayType->toString() + " is only valid in storage."); m_errorReporter.fatalTypeError(_tuple.location(), "Type " + inlineArrayType->toString() + " is only valid in storage.");
_tuple.annotation().type = TypeProvider::arrayType(DataLocation::Memory, inlineArrayType, types.size()); _tuple.annotation().type = TypeProvider::array(DataLocation::Memory, inlineArrayType, types.size());
} }
else else
{ {
if (components.size() == 1) if (components.size() == 1)
_tuple.annotation().type = type(*components[0]); _tuple.annotation().type = type(*components[0]);
else else
_tuple.annotation().type = TypeProvider::tupleType(move(types)); _tuple.annotation().type = TypeProvider::tuple(move(types));
} }
} }
@ -1350,7 +1350,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
_operation.annotation().commonType = commonType; _operation.annotation().commonType = commonType;
_operation.annotation().type = _operation.annotation().type =
TokenTraits::isCompareOp(_operation.getOperator()) ? TokenTraits::isCompareOp(_operation.getOperator()) ?
TypeProvider::boolType() : TypeProvider::boolean() :
commonType; commonType;
_operation.annotation().isPure = _operation.annotation().isPure =
_operation.leftExpression().annotation().isPure && _operation.leftExpression().annotation().isPure &&
@ -1475,8 +1475,8 @@ TypePointer TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
} }
if (resultType->category() == Type::Category::Address) if (resultType->category() == Type::Category::Address)
{ {
bool const payable = argType->isExplicitlyConvertibleTo(*TypeProvider::payableAddressType()); bool const payable = argType->isExplicitlyConvertibleTo(*TypeProvider::payableAddress());
resultType = payable ? TypeProvider::payableAddressType() : TypeProvider::addressType(); resultType = payable ? TypeProvider::payableAddress() : TypeProvider::address();
} }
} }
return resultType; return resultType;
@ -1925,7 +1925,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
funcCallAnno.type = returnTypes.size() == 1 ? funcCallAnno.type = returnTypes.size() == 1 ?
move(returnTypes.front()) : move(returnTypes.front()) :
TypeProvider::tupleType(move(returnTypes)); TypeProvider::tuple(move(returnTypes));
break; break;
} }
@ -1935,7 +1935,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
// for non-callables, ensure error reported and annotate node to void function // for non-callables, ensure error reported and annotate node to void function
solAssert(m_errorReporter.hasErrors(), ""); solAssert(m_errorReporter.hasErrors(), "");
funcCallAnno.kind = FunctionCallKind::FunctionCall; funcCallAnno.kind = FunctionCallKind::FunctionCall;
funcCallAnno.type = TypeProvider::emptyTupleType(); funcCallAnno.type = TypeProvider::emptyTuple();
break; break;
} }
@ -1997,8 +1997,8 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
_newExpression.typeName().location(), _newExpression.typeName().location(),
"Length has to be placed in parentheses after the array type for new expression." "Length has to be placed in parentheses after the array type for new expression."
); );
type = ReferenceType::copyForLocationIfReference(DataLocation::Memory, type); type = TypeProvider::withLocationIfReference(DataLocation::Memory, type);
_newExpression.annotation().type = TypeProvider::functionType( _newExpression.annotation().type = TypeProvider::function(
TypePointers{TypeProvider::uint256()}, TypePointers{TypeProvider::uint256()},
TypePointers{type}, TypePointers{type},
strings(1, ""), strings(1, ""),
@ -2043,7 +2043,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
if (initialMemberCount == 0) if (initialMemberCount == 0)
{ {
// Try to see if the member was removed because it is only available for storage types. // Try to see if the member was removed because it is only available for storage types.
auto storageType = ReferenceType::copyForLocationIfReference( auto storageType = TypeProvider::withLocationIfReference(
DataLocation::Storage, DataLocation::Storage,
exprType exprType
); );
@ -2078,7 +2078,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
} }
else if (exprType->category() == Type::Category::Contract) else if (exprType->category() == Type::Category::Contract)
{ {
for (auto const& addressMember: TypeProvider::payableAddressType()->nativeMembers(nullptr)) for (auto const& addressMember: TypeProvider::payableAddress()->nativeMembers(nullptr))
if (addressMember.name == memberName) if (addressMember.name == memberName)
{ {
Identifier const* var = dynamic_cast<Identifier const*>(&_memberAccess.expression()); Identifier const* var = dynamic_cast<Identifier const*>(&_memberAccess.expression());
@ -2225,7 +2225,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
if (dynamic_cast<ContractType const*>(typeType.actualType())) if (dynamic_cast<ContractType const*>(typeType.actualType()))
m_errorReporter.typeError(_access.location(), "Index access for contracts or libraries is not possible."); m_errorReporter.typeError(_access.location(), "Index access for contracts or libraries is not possible.");
if (!index) if (!index)
resultType = TypeProvider::typeType(TypeProvider::arrayType(DataLocation::Memory, typeType.actualType())); resultType = TypeProvider::typeType(TypeProvider::array(DataLocation::Memory, typeType.actualType()));
else else
{ {
u256 length = 1; u256 length = 1;
@ -2239,7 +2239,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
else else
solAssert(m_errorReporter.hasErrors(), "Expected errors as expectType returned false"); solAssert(m_errorReporter.hasErrors(), "Expected errors as expectType returned false");
resultType = TypeProvider::typeType(TypeProvider::arrayType( resultType = TypeProvider::typeType(TypeProvider::array(
DataLocation::Memory, DataLocation::Memory,
typeType.actualType(), typeType.actualType(),
length length
@ -2260,7 +2260,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
if (bytesType.numBytes() <= integerType->literalValue(nullptr)) if (bytesType.numBytes() <= integerType->literalValue(nullptr))
m_errorReporter.typeError(_access.location(), "Out of bounds array access."); m_errorReporter.typeError(_access.location(), "Out of bounds array access.");
} }
resultType = TypeProvider::fixedBytesType(1); resultType = TypeProvider::fixedBytes(1);
isLValue = false; // @todo this heavily depends on how it is embedded isLValue = false; // @todo this heavily depends on how it is embedded
break; break;
} }
@ -2373,7 +2373,7 @@ void TypeChecker::endVisit(Literal const& _literal)
if (_literal.looksLikeAddress()) if (_literal.looksLikeAddress())
{ {
// Assign type here if it even looks like an address. This prevents double errors for invalid addresses // Assign type here if it even looks like an address. This prevents double errors for invalid addresses
_literal.annotation().type = TypeProvider::payableAddressType(); _literal.annotation().type = TypeProvider::payableAddress();
string msg; string msg;
if (_literal.valueWithoutUnderscores().length() != 42) // "0x" + 40 hex digits if (_literal.valueWithoutUnderscores().length() != 42) // "0x" + 40 hex digits

View File

@ -106,7 +106,7 @@ ImportAnnotation& ImportDirective::annotation() const
TypePointer ImportDirective::type() const TypePointer ImportDirective::type() const
{ {
solAssert(!!annotation().sourceUnit, ""); solAssert(!!annotation().sourceUnit, "");
return TypeProvider::moduleType(*annotation().sourceUnit); return TypeProvider::module(*annotation().sourceUnit);
} }
map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const
@ -189,10 +189,10 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::inter
vector<FunctionTypePointer> functions; vector<FunctionTypePointer> functions;
for (FunctionDefinition const* f: contract->definedFunctions()) for (FunctionDefinition const* f: contract->definedFunctions())
if (f->isPartOfExternalInterface()) if (f->isPartOfExternalInterface())
functions.push_back(TypeProvider::functionType(*f, false)); functions.push_back(TypeProvider::function(*f, false));
for (VariableDeclaration const* v: contract->stateVariables()) for (VariableDeclaration const* v: contract->stateVariables())
if (v->isPartOfExternalInterface()) if (v->isPartOfExternalInterface())
functions.push_back(TypeProvider::functionType(*v)); functions.push_back(TypeProvider::function(*v));
for (FunctionTypePointer const& fun: functions) for (FunctionTypePointer const& fun: functions)
{ {
if (!fun->interfaceFunctionType()) if (!fun->interfaceFunctionType())
@ -247,7 +247,7 @@ vector<Declaration const*> const& ContractDefinition::inheritableMembers() const
TypePointer ContractDefinition::type() const TypePointer ContractDefinition::type() const
{ {
return TypeProvider::typeType(TypeProvider::contractType(*this)); return TypeProvider::typeType(TypeProvider::contract(*this));
} }
ContractDefinitionAnnotation& ContractDefinition::annotation() const ContractDefinitionAnnotation& ContractDefinition::annotation() const
@ -313,7 +313,7 @@ FunctionTypePointer FunctionDefinition::functionType(bool _internal) const
case Declaration::Visibility::Private: case Declaration::Visibility::Private:
case Declaration::Visibility::Internal: case Declaration::Visibility::Internal:
case Declaration::Visibility::Public: case Declaration::Visibility::Public:
return TypeProvider::functionType(*this, _internal); return TypeProvider::function(*this, _internal);
case Declaration::Visibility::External: case Declaration::Visibility::External:
return {}; return {};
} }
@ -329,7 +329,7 @@ FunctionTypePointer FunctionDefinition::functionType(bool _internal) const
return {}; return {};
case Declaration::Visibility::Public: case Declaration::Visibility::Public:
case Declaration::Visibility::External: case Declaration::Visibility::External:
return TypeProvider::functionType(*this, _internal); return TypeProvider::function(*this, _internal);
} }
} }
@ -340,12 +340,12 @@ FunctionTypePointer FunctionDefinition::functionType(bool _internal) const
TypePointer FunctionDefinition::type() const TypePointer FunctionDefinition::type() const
{ {
solAssert(visibility() != Declaration::Visibility::External, ""); solAssert(visibility() != Declaration::Visibility::External, "");
return TypeProvider::functionType(*this); return TypeProvider::function(*this);
} }
string FunctionDefinition::externalSignature() const string FunctionDefinition::externalSignature() const
{ {
return TypeProvider::functionType(*this)->externalSignature(); return TypeProvider::function(*this)->externalSignature();
} }
FunctionDefinitionAnnotation& FunctionDefinition::annotation() const FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
@ -357,7 +357,7 @@ FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
TypePointer ModifierDefinition::type() const TypePointer ModifierDefinition::type() const
{ {
return TypeProvider::modifierType(*this); return TypeProvider::modifier(*this);
} }
ModifierDefinitionAnnotation& ModifierDefinition::annotation() const ModifierDefinitionAnnotation& ModifierDefinition::annotation() const
@ -369,13 +369,13 @@ ModifierDefinitionAnnotation& ModifierDefinition::annotation() const
TypePointer EventDefinition::type() const TypePointer EventDefinition::type() const
{ {
return TypeProvider::functionType(*this); return TypeProvider::function(*this);
} }
FunctionTypePointer EventDefinition::functionType(bool _internal) const FunctionTypePointer EventDefinition::functionType(bool _internal) const
{ {
if (_internal) if (_internal)
return TypeProvider::functionType(*this); return TypeProvider::function(*this);
else else
return nullptr; return nullptr;
} }
@ -568,7 +568,7 @@ FunctionTypePointer VariableDeclaration::functionType(bool _internal) const
return nullptr; return nullptr;
case Declaration::Visibility::Public: case Declaration::Visibility::Public:
case Declaration::Visibility::External: case Declaration::Visibility::External:
return TypeProvider::functionType(*this); return TypeProvider::function(*this);
} }
// To make the compiler happy // To make the compiler happy

View File

@ -24,19 +24,19 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace solidity; using namespace solidity;
BoolType const TypeProvider::m_boolType{}; BoolType const TypeProvider::m_boolean{};
InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamicType{}; InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamic{};
/// The string and bytes unique_ptrs are initialized when they are first used because /// The string and bytes unique_ptrs are initialized when they are first used because
/// they rely on `byte` being available which we cannot guarantee in the static init context. /// they rely on `byte` being available which we cannot guarantee in the static init context.
std::unique_ptr<ArrayType> TypeProvider::m_bytesStorageType; unique_ptr<ArrayType> TypeProvider::m_bytesStorage;
std::unique_ptr<ArrayType> TypeProvider::m_bytesMemoryType; unique_ptr<ArrayType> TypeProvider::m_bytesMemory;
std::unique_ptr<ArrayType> TypeProvider::m_stringStorageType; unique_ptr<ArrayType> TypeProvider::m_stringStorage;
std::unique_ptr<ArrayType> TypeProvider::m_stringMemoryType; unique_ptr<ArrayType> TypeProvider::m_stringMemory;
TupleType const TypeProvider::m_emptyTupleType{}; TupleType const TypeProvider::m_emptyTuple{};
AddressType const TypeProvider::m_payableAddressType{StateMutability::Payable}; AddressType const TypeProvider::m_payableAddress{StateMutability::Payable};
AddressType const TypeProvider::m_addressType{StateMutability::NonPayable}; AddressType const TypeProvider::m_address{StateMutability::NonPayable};
array<unique_ptr<IntegerType>, 32> const TypeProvider::m_intM{{ array<unique_ptr<IntegerType>, 32> const TypeProvider::m_intM{{
{make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Signed)}, {make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Signed)},
@ -143,7 +143,7 @@ array<unique_ptr<FixedBytesType>, 32> const TypeProvider::m_bytesM{{
{make_unique<FixedBytesType>(32)} {make_unique<FixedBytesType>(32)}
}}; }};
array<unique_ptr<MagicType>, 4> const TypeProvider::m_magicTypes{{ array<unique_ptr<MagicType>, 4> const TypeProvider::m_magics{{
{make_unique<MagicType>(MagicType::Kind::Block)}, {make_unique<MagicType>(MagicType::Kind::Block)},
{make_unique<MagicType>(MagicType::Kind::Message)}, {make_unique<MagicType>(MagicType::Kind::Message)},
{make_unique<MagicType>(MagicType::Kind::Transaction)}, {make_unique<MagicType>(MagicType::Kind::Transaction)},
@ -173,19 +173,19 @@ inline void clearCaches(Container& container)
void TypeProvider::reset() void TypeProvider::reset()
{ {
clearCache(m_boolType); clearCache(m_boolean);
clearCache(m_inaccessibleDynamicType); clearCache(m_inaccessibleDynamic);
clearCache(m_bytesStorageType); clearCache(m_bytesStorage);
clearCache(m_bytesMemoryType); clearCache(m_bytesMemory);
clearCache(m_stringStorageType); clearCache(m_stringStorage);
clearCache(m_stringMemoryType); clearCache(m_stringMemory);
clearCache(m_emptyTupleType); clearCache(m_emptyTuple);
clearCache(m_payableAddressType); clearCache(m_payableAddress);
clearCache(m_addressType); clearCache(m_address);
clearCaches(instance().m_intM); clearCaches(instance().m_intM);
clearCaches(instance().m_uintM); clearCaches(instance().m_uintM);
clearCaches(instance().m_bytesM); clearCaches(instance().m_bytesM);
clearCaches(instance().m_magicTypes); clearCaches(instance().m_magics);
instance().m_generalTypes.clear(); instance().m_generalTypes.clear();
instance().m_stringLiteralTypes.clear(); instance().m_stringLiteralTypes.clear();
@ -213,33 +213,33 @@ Type const* TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken const&
switch (_type.token()) switch (_type.token())
{ {
case Token::IntM: case Token::IntM:
return integerType(m, IntegerType::Modifier::Signed); return integer(m, IntegerType::Modifier::Signed);
case Token::UIntM: case Token::UIntM:
return integerType(m, IntegerType::Modifier::Unsigned); return integer(m, IntegerType::Modifier::Unsigned);
case Token::Byte: case Token::Byte:
return byteType(); return byte();
case Token::BytesM: case Token::BytesM:
return fixedBytesType(m); return fixedBytes(m);
case Token::FixedMxN: case Token::FixedMxN:
return fixedPointType(m, n, FixedPointType::Modifier::Signed); return fixedPoint(m, n, FixedPointType::Modifier::Signed);
case Token::UFixedMxN: case Token::UFixedMxN:
return fixedPointType(m, n, FixedPointType::Modifier::Unsigned); return fixedPoint(m, n, FixedPointType::Modifier::Unsigned);
case Token::Int: case Token::Int:
return integerType(256, IntegerType::Modifier::Signed); return integer(256, IntegerType::Modifier::Signed);
case Token::UInt: case Token::UInt:
return integerType(256, IntegerType::Modifier::Unsigned); return integer(256, IntegerType::Modifier::Unsigned);
case Token::Fixed: case Token::Fixed:
return fixedPointType(128, 18, FixedPointType::Modifier::Signed); return fixedPoint(128, 18, FixedPointType::Modifier::Signed);
case Token::UFixed: case Token::UFixed:
return fixedPointType(128, 18, FixedPointType::Modifier::Unsigned); return fixedPoint(128, 18, FixedPointType::Modifier::Unsigned);
case Token::Address: case Token::Address:
return addressType(); return address();
case Token::Bool: case Token::Bool:
return boolType(); return boolean();
case Token::Bytes: case Token::Bytes:
return bytesStorageType(); return bytesStorage();
case Token::String: case Token::String:
return stringStorageType(); return stringStorage();
default: default:
solAssert( solAssert(
false, false,
@ -280,11 +280,11 @@ TypePointer TypeProvider::fromElementaryTypeName(string const& _name)
if (nameParts.size() == 2) if (nameParts.size() == 2)
{ {
if (nameParts[1] == "payable") if (nameParts[1] == "payable")
return payableAddressType(); return payableAddress();
else else
solAssert(false, "Invalid state mutability for address type: " + nameParts[1]); solAssert(false, "Invalid state mutability for address type: " + nameParts[1]);
} }
return addressType(); return address();
} }
else else
{ {
@ -293,32 +293,32 @@ TypePointer TypeProvider::fromElementaryTypeName(string const& _name)
} }
} }
ArrayType const* TypeProvider::bytesStorageType() ArrayType const* TypeProvider::bytesStorage()
{ {
if (!m_bytesStorageType) if (!m_bytesStorage)
m_bytesStorageType = make_unique<ArrayType>(DataLocation::Storage, false); m_bytesStorage = make_unique<ArrayType>(DataLocation::Storage, false);
return m_bytesStorageType.get(); return m_bytesStorage.get();
} }
ArrayType const* TypeProvider::bytesMemoryType() ArrayType const* TypeProvider::bytesMemory()
{ {
if (!m_bytesMemoryType) if (!m_bytesMemory)
m_bytesMemoryType = make_unique<ArrayType>(DataLocation::Memory, false); m_bytesMemory = make_unique<ArrayType>(DataLocation::Memory, false);
return m_bytesMemoryType.get(); return m_bytesMemory.get();
} }
ArrayType const* TypeProvider::stringStorageType() ArrayType const* TypeProvider::stringStorage()
{ {
if (!m_stringStorageType) if (!m_stringStorage)
m_stringStorageType = make_unique<ArrayType>(DataLocation::Storage, true); m_stringStorage = make_unique<ArrayType>(DataLocation::Storage, true);
return m_stringStorageType.get(); return m_stringStorage.get();
} }
ArrayType const* TypeProvider::stringMemoryType() ArrayType const* TypeProvider::stringMemory()
{ {
if (!m_stringMemoryType) if (!m_stringMemory)
m_stringMemoryType = make_unique<ArrayType>(DataLocation::Memory, true); m_stringMemory = make_unique<ArrayType>(DataLocation::Memory, true);
return m_stringMemoryType.get(); return m_stringMemory.get();
} }
TypePointer TypeProvider::forLiteral(Literal const& _literal) TypePointer TypeProvider::forLiteral(Literal const& _literal)
@ -327,17 +327,17 @@ TypePointer TypeProvider::forLiteral(Literal const& _literal)
{ {
case Token::TrueLiteral: case Token::TrueLiteral:
case Token::FalseLiteral: case Token::FalseLiteral:
return boolType(); return boolean();
case Token::Number: case Token::Number:
return rationalNumberType(_literal); return rationalNumber(_literal);
case Token::StringLiteral: case Token::StringLiteral:
return stringLiteralType(_literal.value()); return stringLiteral(_literal.value());
default: default:
return nullptr; return nullptr;
} }
} }
RationalNumberType const* TypeProvider::rationalNumberType(Literal const& _literal) RationalNumberType const* TypeProvider::rationalNumber(Literal const& _literal)
{ {
solAssert(_literal.token() == Token::Number, ""); solAssert(_literal.token() == Token::Number, "");
std::tuple<bool, rational> validLiteral = RationalNumberType::isValidLiteral(_literal); std::tuple<bool, rational> validLiteral = RationalNumberType::isValidLiteral(_literal);
@ -348,15 +348,15 @@ RationalNumberType const* TypeProvider::rationalNumberType(Literal const& _liter
{ {
size_t const digitCount = _literal.valueWithoutUnderscores().length() - 2; size_t const digitCount = _literal.valueWithoutUnderscores().length() - 2;
if (digitCount % 2 == 0 && (digitCount / 2) <= 32) if (digitCount % 2 == 0 && (digitCount / 2) <= 32)
compatibleBytesType = fixedBytesType(digitCount / 2); compatibleBytesType = fixedBytes(digitCount / 2);
} }
return rationalNumberType(std::get<1>(validLiteral), compatibleBytesType); return rationalNumber(std::get<1>(validLiteral), compatibleBytesType);
} }
return nullptr; return nullptr;
} }
StringLiteralType const* TypeProvider::stringLiteralType(string const& literal) StringLiteralType const* TypeProvider::stringLiteral(string const& literal)
{ {
auto i = instance().m_stringLiteralTypes.find(literal); auto i = instance().m_stringLiteralTypes.find(literal);
if (i != instance().m_stringLiteralTypes.end()) if (i != instance().m_stringLiteralTypes.end())
@ -365,7 +365,7 @@ StringLiteralType const* TypeProvider::stringLiteralType(string const& literal)
return instance().m_stringLiteralTypes.emplace(literal, make_unique<StringLiteralType>(literal)).first->second.get(); return instance().m_stringLiteralTypes.emplace(literal, make_unique<StringLiteralType>(literal)).first->second.get();
} }
FixedPointType const* TypeProvider::fixedPointType(unsigned m, unsigned n, FixedPointType::Modifier _modifier) FixedPointType const* TypeProvider::fixedPoint(unsigned m, unsigned n, FixedPointType::Modifier _modifier)
{ {
auto& map = _modifier == FixedPointType::Modifier::Unsigned ? instance().m_ufixedMxN : instance().m_fixedMxN; auto& map = _modifier == FixedPointType::Modifier::Unsigned ? instance().m_ufixedMxN : instance().m_fixedMxN;
@ -379,10 +379,10 @@ FixedPointType const* TypeProvider::fixedPointType(unsigned m, unsigned n, Fixed
).first->second.get(); ).first->second.get();
} }
TupleType const* TypeProvider::tupleType(vector<Type const*> members) TupleType const* TypeProvider::tuple(vector<Type const*> members)
{ {
if (members.empty()) if (members.empty())
return &m_emptyTupleType; return &m_emptyTuple;
return createAndGet<TupleType>(move(members)); return createAndGet<TupleType>(move(members));
} }
@ -396,27 +396,27 @@ ReferenceType const* TypeProvider::withLocation(ReferenceType const* _type, Data
return static_cast<ReferenceType const*>(instance().m_generalTypes.back().get()); return static_cast<ReferenceType const*>(instance().m_generalTypes.back().get());
} }
FunctionType const* TypeProvider::functionType(FunctionDefinition const& _function, bool _isInternal) FunctionType const* TypeProvider::function(FunctionDefinition const& _function, bool _isInternal)
{ {
return createAndGet<FunctionType>(_function, _isInternal); return createAndGet<FunctionType>(_function, _isInternal);
} }
FunctionType const* TypeProvider::functionType(VariableDeclaration const& _varDecl) FunctionType const* TypeProvider::function(VariableDeclaration const& _varDecl)
{ {
return createAndGet<FunctionType>(_varDecl); return createAndGet<FunctionType>(_varDecl);
} }
FunctionType const* TypeProvider::functionType(EventDefinition const& _def) FunctionType const* TypeProvider::function(EventDefinition const& _def)
{ {
return createAndGet<FunctionType>(_def); return createAndGet<FunctionType>(_def);
} }
FunctionType const* TypeProvider::functionType(FunctionTypeName const& _typeName) FunctionType const* TypeProvider::function(FunctionTypeName const& _typeName)
{ {
return createAndGet<FunctionType>(_typeName); return createAndGet<FunctionType>(_typeName);
} }
FunctionType const* TypeProvider::functionType( FunctionType const* TypeProvider::function(
strings const& _parameterTypes, strings const& _parameterTypes,
strings const& _returnParameterTypes, strings const& _returnParameterTypes,
FunctionType::Kind _kind, FunctionType::Kind _kind,
@ -430,7 +430,7 @@ FunctionType const* TypeProvider::functionType(
); );
} }
FunctionType const* TypeProvider::functionType( FunctionType const* TypeProvider::function(
TypePointers const& _parameterTypes, TypePointers const& _parameterTypes,
TypePointers const& _returnParameterTypes, TypePointers const& _returnParameterTypes,
strings _parameterNames, strings _parameterNames,
@ -459,41 +459,41 @@ FunctionType const* TypeProvider::functionType(
); );
} }
RationalNumberType const* TypeProvider::rationalNumberType(rational const& _value, Type const* _compatibleBytesType) RationalNumberType const* TypeProvider::rationalNumber(rational const& _value, Type const* _compatibleBytesType)
{ {
return createAndGet<RationalNumberType>(_value, _compatibleBytesType); return createAndGet<RationalNumberType>(_value, _compatibleBytesType);
} }
ArrayType const* TypeProvider::arrayType(DataLocation _location, bool _isString) ArrayType const* TypeProvider::array(DataLocation _location, bool _isString)
{ {
if (_isString) if (_isString)
{ {
if (_location == DataLocation::Storage) if (_location == DataLocation::Storage)
return stringStorageType(); return stringStorage();
if (_location == DataLocation::Memory) if (_location == DataLocation::Memory)
return stringMemoryType(); return stringMemory();
} }
else else
{ {
if (_location == DataLocation::Storage) if (_location == DataLocation::Storage)
return bytesStorageType(); return bytesStorage();
if (_location == DataLocation::Memory) if (_location == DataLocation::Memory)
return bytesMemoryType(); return bytesMemory();
} }
return createAndGet<ArrayType>(_location, _isString); return createAndGet<ArrayType>(_location, _isString);
} }
ArrayType const* TypeProvider::arrayType(DataLocation _location, Type const* _baseType) ArrayType const* TypeProvider::array(DataLocation _location, Type const* _baseType)
{ {
return createAndGet<ArrayType>(_location, _baseType); return createAndGet<ArrayType>(_location, _baseType);
} }
ArrayType const* TypeProvider::arrayType(DataLocation _location, Type const* _baseType, u256 const& _length) ArrayType const* TypeProvider::array(DataLocation _location, Type const* _baseType, u256 const& _length)
{ {
return createAndGet<ArrayType>(_location, _baseType, _length); return createAndGet<ArrayType>(_location, _baseType, _length);
} }
ContractType const* TypeProvider::contractType(ContractDefinition const& _contractDef, bool _isSuper) ContractType const* TypeProvider::contract(ContractDefinition const& _contractDef, bool _isSuper)
{ {
return createAndGet<ContractType>(_contractDef, _isSuper); return createAndGet<ContractType>(_contractDef, _isSuper);
} }
@ -503,7 +503,7 @@ EnumType const* TypeProvider::enumType(EnumDefinition const& _enumDef)
return createAndGet<EnumType>(_enumDef); return createAndGet<EnumType>(_enumDef);
} }
ModuleType const* TypeProvider::moduleType(SourceUnit const& _source) ModuleType const* TypeProvider::module(SourceUnit const& _source)
{ {
return createAndGet<ModuleType>(_source); return createAndGet<ModuleType>(_source);
} }
@ -518,24 +518,24 @@ StructType const* TypeProvider::structType(StructDefinition const& _struct, Data
return createAndGet<StructType>(_struct, _location); return createAndGet<StructType>(_struct, _location);
} }
ModifierType const* TypeProvider::modifierType(ModifierDefinition const& _def) ModifierType const* TypeProvider::modifier(ModifierDefinition const& _def)
{ {
return createAndGet<ModifierType>(_def); return createAndGet<ModifierType>(_def);
} }
MagicType const* TypeProvider::magicType(MagicType::Kind _kind) MagicType const* TypeProvider::magic(MagicType::Kind _kind)
{ {
solAssert(_kind != MagicType::Kind::MetaType, "MetaType is handled separately"); solAssert(_kind != MagicType::Kind::MetaType, "MetaType is handled separately");
return m_magicTypes.at(static_cast<size_t>(_kind)).get(); return m_magics.at(static_cast<size_t>(_kind)).get();
} }
MagicType const* TypeProvider::metaType(Type const* _type) MagicType const* TypeProvider::meta(Type const* _type)
{ {
solAssert(_type && _type->category() == Type::Category::Contract, "Only contracts supported for now."); solAssert(_type && _type->category() == Type::Category::Contract, "Only contracts supported for now.");
return createAndGet<MagicType>(_type); return createAndGet<MagicType>(_type);
} }
MappingType const* TypeProvider::mappingType(Type const* _keyType, Type const* _valueType) MappingType const* TypeProvider::mapping(Type const* _keyType, Type const* _valueType)
{ {
return createAndGet<MappingType>(_keyType, _valueType); return createAndGet<MappingType>(_keyType, _valueType);
} }

View File

@ -61,29 +61,29 @@ public:
static TypePointer fromElementaryTypeName(std::string const& _name); static TypePointer fromElementaryTypeName(std::string const& _name);
/// @returns boolean type. /// @returns boolean type.
static BoolType const* boolType() noexcept { return &m_boolType; } static BoolType const* boolean() noexcept { return &m_boolean; }
static FixedBytesType const* byteType() { return fixedBytesType(1); } static FixedBytesType const* byte() { return fixedBytes(1); }
static FixedBytesType const* fixedBytesType(unsigned m) { return m_bytesM.at(m - 1).get(); } static FixedBytesType const* fixedBytes(unsigned m) { return m_bytesM.at(m - 1).get(); }
static ArrayType const* bytesStorageType(); static ArrayType const* bytesStorage();
static ArrayType const* bytesMemoryType(); static ArrayType const* bytesMemory();
static ArrayType const* stringStorageType(); static ArrayType const* stringStorage();
static ArrayType const* stringMemoryType(); static ArrayType const* stringMemory();
/// Constructor for a byte array ("bytes") and string. /// Constructor for a byte array ("bytes") and string.
static ArrayType const* arrayType(DataLocation _location, bool _isString = false); static ArrayType const* array(DataLocation _location, bool _isString = false);
/// Constructor for a dynamically sized array type ("type[]") /// Constructor for a dynamically sized array type ("type[]")
static ArrayType const* arrayType(DataLocation _location, Type const* _baseType); static ArrayType const* array(DataLocation _location, Type const* _baseType);
/// Constructor for a fixed-size array type ("type[20]") /// Constructor for a fixed-size array type ("type[20]")
static ArrayType const* arrayType(DataLocation _location, Type const* _baseType, u256 const& _length); static ArrayType const* array(DataLocation _location, Type const* _baseType, u256 const& _length);
static AddressType const* payableAddressType() noexcept { return &m_payableAddressType; } static AddressType const* payableAddress() noexcept { return &m_payableAddress; }
static AddressType const* addressType() noexcept { return &m_addressType; } static AddressType const* address() noexcept { return &m_address; }
static IntegerType const* integerType(unsigned _bits, IntegerType::Modifier _modifier) static IntegerType const* integer(unsigned _bits, IntegerType::Modifier _modifier)
{ {
solAssert((_bits % 8) == 0, ""); solAssert((_bits % 8) == 0, "");
if (_modifier == IntegerType::Modifier::Unsigned) if (_modifier == IntegerType::Modifier::Unsigned)
@ -91,19 +91,19 @@ public:
else else
return m_intM.at(_bits / 8 - 1).get(); return m_intM.at(_bits / 8 - 1).get();
} }
static IntegerType const* uint(unsigned _bits) { return integerType(_bits, IntegerType::Modifier::Unsigned); } static IntegerType const* uint(unsigned _bits) { return integer(_bits, IntegerType::Modifier::Unsigned); }
static IntegerType const* uint256() { return uint(256); } static IntegerType const* uint256() { return uint(256); }
static FixedPointType const* fixedPointType(unsigned m, unsigned n, FixedPointType::Modifier _modifier); static FixedPointType const* fixedPoint(unsigned m, unsigned n, FixedPointType::Modifier _modifier);
static StringLiteralType const* stringLiteralType(std::string const& literal); static StringLiteralType const* stringLiteral(std::string const& literal);
/// @param members the member types the tuple type must contain. This is passed by value on purspose. /// @param members the member types the tuple type must contain. This is passed by value on purspose.
/// @returns a tuple type with the given members. /// @returns a tuple type with the given members.
static TupleType const* tupleType(std::vector<Type const*> members); static TupleType const* tuple(std::vector<Type const*> members);
static TupleType const* emptyTupleType() noexcept { return &m_emptyTupleType; } static TupleType const* emptyTuple() noexcept { return &m_emptyTuple; }
static ReferenceType const* withLocation(ReferenceType const* _type, DataLocation _location, bool _isPointer); static ReferenceType const* withLocation(ReferenceType const* _type, DataLocation _location, bool _isPointer);
@ -119,19 +119,19 @@ public:
} }
/// @returns the internally-facing or externally-facing type of a function. /// @returns the internally-facing or externally-facing type of a function.
static FunctionType const* functionType(FunctionDefinition const& _function, bool _isInternal = true); static FunctionType const* function(FunctionDefinition const& _function, bool _isInternal = true);
/// @returns the accessor function type of a state variable. /// @returns the accessor function type of a state variable.
static FunctionType const* functionType(VariableDeclaration const& _varDecl); static FunctionType const* function(VariableDeclaration const& _varDecl);
/// @returns the function type of an event. /// @returns the function type of an event.
static FunctionType const* functionType(EventDefinition const& _event); static FunctionType const* function(EventDefinition const& _event);
/// @returns the type of a function type name. /// @returns the type of a function type name.
static FunctionType const* functionType(FunctionTypeName const& _typeName); static FunctionType const* function(FunctionTypeName const& _typeName);
/// @returns the function type to be used for a plain type (not derived from a declaration). /// @returns the function type to be used for a plain type (not derived from a declaration).
static FunctionType const* functionType( static FunctionType const* function(
strings const& _parameterTypes, strings const& _parameterTypes,
strings const& _returnParameterTypes, strings const& _returnParameterTypes,
FunctionType::Kind _kind = FunctionType::Kind::Internal, FunctionType::Kind _kind = FunctionType::Kind::Internal,
@ -140,7 +140,7 @@ public:
); );
/// @returns a highly customized FunctionType, use with care. /// @returns a highly customized FunctionType, use with care.
static FunctionType const* functionType( static FunctionType const* function(
TypePointers const& _parameterTypes, TypePointers const& _parameterTypes,
TypePointers const& _returnParameterTypes, TypePointers const& _returnParameterTypes,
strings _parameterNames = strings{}, strings _parameterNames = strings{},
@ -157,34 +157,34 @@ public:
/// Auto-detect the proper type for a literal. @returns an empty pointer if the literal does /// Auto-detect the proper type for a literal. @returns an empty pointer if the literal does
/// not fit any type. /// not fit any type.
static TypePointer forLiteral(Literal const& _literal); static TypePointer forLiteral(Literal const& _literal);
static RationalNumberType const* rationalNumberType(Literal const& _literal); static RationalNumberType const* rationalNumber(Literal const& _literal);
static RationalNumberType const* rationalNumberType( static RationalNumberType const* rationalNumber(
rational const& _value, rational const& _value,
Type const* _compatibleBytesType = nullptr Type const* _compatibleBytesType = nullptr
); );
static ContractType const* contractType(ContractDefinition const& _contract, bool _isSuper = false); static ContractType const* contract(ContractDefinition const& _contract, bool _isSuper = false);
static InaccessibleDynamicType const* inaccessibleDynamicType() noexcept { return &m_inaccessibleDynamicType; } static InaccessibleDynamicType const* inaccessibleDynamic() noexcept { return &m_inaccessibleDynamic; }
/// @returns the type of an enum instance for given definition, there is one distinct type per enum definition. /// @returns the type of an enum instance for given definition, there is one distinct type per enum definition.
static EnumType const* enumType(EnumDefinition const& _enum); static EnumType const* enumType(EnumDefinition const& _enum);
/// @returns special type for imported modules. These mainly give access to their scope via members. /// @returns special type for imported modules. These mainly give access to their scope via members.
static ModuleType const* moduleType(SourceUnit const& _source); static ModuleType const* module(SourceUnit const& _source);
static TypeType const* typeType(Type const* _actualType); static TypeType const* typeType(Type const* _actualType);
static StructType const* structType(StructDefinition const& _struct, DataLocation _location); static StructType const* structType(StructDefinition const& _struct, DataLocation _location);
static ModifierType const* modifierType(ModifierDefinition const& _modifierDef); static ModifierType const* modifier(ModifierDefinition const& _modifierDef);
static MagicType const* magicType(MagicType::Kind _kind); static MagicType const* magic(MagicType::Kind _kind);
static MagicType const* metaType(Type const* _type); static MagicType const* meta(Type const* _type);
static MappingType const* mappingType(Type const* _keyType, Type const* _valueType); static MappingType const* mapping(Type const* _keyType, Type const* _valueType);
private: private:
/// Global TypeProvider instance. /// Global TypeProvider instance.
@ -197,22 +197,22 @@ private:
template <typename T, typename... Args> template <typename T, typename... Args>
static inline T const* createAndGet(Args&& ... _args); static inline T const* createAndGet(Args&& ... _args);
static BoolType const m_boolType; static BoolType const m_boolean;
static InaccessibleDynamicType const m_inaccessibleDynamicType; static InaccessibleDynamicType const m_inaccessibleDynamic;
/// These are lazy-initialized because they depend on `byte` being available. /// These are lazy-initialized because they depend on `byte` being available.
static std::unique_ptr<ArrayType> m_bytesStorageType; static std::unique_ptr<ArrayType> m_bytesStorage;
static std::unique_ptr<ArrayType> m_bytesMemoryType; static std::unique_ptr<ArrayType> m_bytesMemory;
static std::unique_ptr<ArrayType> m_stringStorageType; static std::unique_ptr<ArrayType> m_stringStorage;
static std::unique_ptr<ArrayType> m_stringMemoryType; static std::unique_ptr<ArrayType> m_stringMemory;
static TupleType const m_emptyTupleType; static TupleType const m_emptyTuple;
static AddressType const m_payableAddressType; static AddressType const m_payableAddress;
static AddressType const m_addressType; static AddressType const m_address;
static std::array<std::unique_ptr<IntegerType>, 32> const m_intM; static std::array<std::unique_ptr<IntegerType>, 32> const m_intM;
static std::array<std::unique_ptr<IntegerType>, 32> const m_uintM; static std::array<std::unique_ptr<IntegerType>, 32> const m_uintM;
static std::array<std::unique_ptr<FixedBytesType>, 32> const m_bytesM; static std::array<std::unique_ptr<FixedBytesType>, 32> const m_bytesM;
static std::array<std::unique_ptr<MagicType>, 4> const m_magicTypes; ///< MagicType's except MetaType static std::array<std::unique_ptr<MagicType>, 4> const m_magics; ///< MagicType's except MetaType
std::map<std::pair<unsigned, unsigned>, std::unique_ptr<FixedPointType>> m_ufixedMxN{}; std::map<std::pair<unsigned, unsigned>, std::unique_ptr<FixedPointType>> m_ufixedMxN{};
std::map<std::pair<unsigned, unsigned>, std::unique_ptr<FixedPointType>> m_fixedMxN{}; std::map<std::pair<unsigned, unsigned>, std::unique_ptr<FixedPointType>> m_fixedMxN{};

View File

@ -142,7 +142,7 @@ BoolResult fitsIntegerType(bigint const& _value, IntegerType const& _type)
/// if _signed is true. /// if _signed is true.
bool fitsIntoBits(bigint const& _value, unsigned _bits, bool _signed) bool fitsIntoBits(bigint const& _value, unsigned _bits, bool _signed)
{ {
return fitsIntegerType(_value, *TypeProvider::integerType( return fitsIntegerType(_value, *TypeProvider::integer(
_bits, _bits,
_signed ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned _signed ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned
)); ));
@ -343,13 +343,13 @@ TypePointer Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool) c
MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition const& _scope) MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition const& _scope)
{ {
// Normalise data location of type. // Normalise data location of type.
TypePointer type = ReferenceType::copyForLocationIfReference(DataLocation::Storage, &_type); TypePointer type = TypeProvider::withLocationIfReference(DataLocation::Storage, &_type);
set<Declaration const*> seenFunctions; set<Declaration const*> seenFunctions;
MemberList::MemberMap members; MemberList::MemberMap members;
for (ContractDefinition const* contract: _scope.annotation().linearizedBaseContracts) for (ContractDefinition const* contract: _scope.annotation().linearizedBaseContracts)
for (UsingForDirective const* ufd: contract->usingForDirectives()) for (UsingForDirective const* ufd: contract->usingForDirectives())
{ {
if (ufd->typeName() && *type != *ReferenceType::copyForLocationIfReference( if (ufd->typeName() && *type != *TypeProvider::withLocationIfReference(
DataLocation::Storage, DataLocation::Storage,
ufd->typeName()->annotation().type ufd->typeName()->annotation().type
)) ))
@ -426,7 +426,7 @@ u256 AddressType::literalValue(Literal const* _literal) const
TypeResult AddressType::unaryOperatorResult(Token _operator) const TypeResult AddressType::unaryOperatorResult(Token _operator) const
{ {
return _operator == Token::Delete ? TypeProvider::emptyTupleType() : nullptr; return _operator == Token::Delete ? TypeProvider::emptyTuple() : nullptr;
} }
@ -450,15 +450,15 @@ MemberList::MemberMap AddressType::nativeMembers(ContractDefinition const*) cons
{ {
MemberList::MemberMap members = { MemberList::MemberMap members = {
{"balance", TypeProvider::uint256()}, {"balance", TypeProvider::uint256()},
{"call", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCall, false, StateMutability::Payable)}, {"call", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCall, false, StateMutability::Payable)},
{"callcode", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCallCode, false, StateMutability::Payable)}, {"callcode", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCallCode, false, StateMutability::Payable)},
{"delegatecall", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareDelegateCall, false, StateMutability::NonPayable)}, {"delegatecall", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareDelegateCall, false, StateMutability::NonPayable)},
{"staticcall", TypeProvider::functionType(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareStaticCall, false, StateMutability::View)} {"staticcall", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareStaticCall, false, StateMutability::View)}
}; };
if (m_stateMutability == StateMutability::Payable) if (m_stateMutability == StateMutability::Payable)
{ {
members.emplace_back(MemberList::Member{"send", TypeProvider::functionType(strings{"uint"}, strings{"bool"}, FunctionType::Kind::Send, false, StateMutability::NonPayable)}); members.emplace_back(MemberList::Member{"send", TypeProvider::function(strings{"uint"}, strings{"bool"}, FunctionType::Kind::Send, false, StateMutability::NonPayable)});
members.emplace_back(MemberList::Member{"transfer", TypeProvider::functionType(strings{"uint"}, strings(), FunctionType::Kind::Transfer, false, StateMutability::NonPayable)}); members.emplace_back(MemberList::Member{"transfer", TypeProvider::function(strings{"uint"}, strings(), FunctionType::Kind::Transfer, false, StateMutability::NonPayable)});
} }
return members; return members;
} }
@ -530,7 +530,7 @@ TypeResult IntegerType::unaryOperatorResult(Token _operator) const
{ {
// "delete" is ok for all integer types // "delete" is ok for all integer types
if (_operator == Token::Delete) if (_operator == Token::Delete)
return TypeResult{TypeProvider::emptyTupleType()}; return TypeResult{TypeProvider::emptyTuple()};
// we allow -, ++ and -- // we allow -, ++ and --
else if (_operator == Token::Sub || _operator == Token::Inc || else if (_operator == Token::Sub || _operator == Token::Inc ||
_operator == Token::Dec || _operator == Token::BitNot) _operator == Token::Dec || _operator == Token::BitNot)
@ -647,7 +647,7 @@ TypeResult FixedPointType::unaryOperatorResult(Token _operator) const
{ {
case Token::Delete: case Token::Delete:
// "delete" is ok for all fixed types // "delete" is ok for all fixed types
return TypeResult{TypeProvider::emptyTupleType()}; return TypeResult{TypeProvider::emptyTuple()};
case Token::Add: case Token::Add:
case Token::Sub: case Token::Sub:
case Token::Inc: case Token::Inc:
@ -707,7 +707,7 @@ TypeResult FixedPointType::binaryOperatorResult(Token _operator, Type const* _ot
IntegerType const* FixedPointType::asIntegerType() const IntegerType const* FixedPointType::asIntegerType() const
{ {
return TypeProvider::integerType(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned); return TypeProvider::integer(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned);
} }
tuple<bool, rational> RationalNumberType::parseRational(string const& _value) tuple<bool, rational> RationalNumberType::parseRational(string const& _value)
@ -923,7 +923,7 @@ TypeResult RationalNumberType::unaryOperatorResult(Token _operator) const
default: default:
return nullptr; return nullptr;
} }
return TypeResult{TypeProvider::rationalNumberType(value)}; return TypeResult{TypeProvider::rationalNumber(value)};
} }
TypeResult RationalNumberType::binaryOperatorResult(Token _operator, Type const* _other) const TypeResult RationalNumberType::binaryOperatorResult(Token _operator, Type const* _other) const
@ -1107,7 +1107,7 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, Type const*
if (value.numerator() != 0 && max(mostSignificantBit(abs(value.numerator())), mostSignificantBit(abs(value.denominator()))) > 4096) if (value.numerator() != 0 && max(mostSignificantBit(abs(value.numerator())), mostSignificantBit(abs(value.denominator()))) > 4096)
return TypeResult::err("Precision of rational constants is limited to 4096 bits."); return TypeResult::err("Precision of rational constants is limited to 4096 bits.");
return TypeResult{TypeProvider::rationalNumberType(value)}; return TypeResult{TypeProvider::rationalNumber(value)};
} }
} }
@ -1199,7 +1199,7 @@ IntegerType const* RationalNumberType::integerType() const
if (value > u256(-1)) if (value > u256(-1))
return nullptr; return nullptr;
else else
return TypeProvider::integerType( return TypeProvider::integer(
max(bytesRequired(value), 1u) * 8, max(bytesRequired(value), 1u) * 8,
negative ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned negative ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned
); );
@ -1237,7 +1237,7 @@ FixedPointType const* RationalNumberType::fixedPointType() const
unsigned totalBits = max(bytesRequired(v), 1u) * 8; unsigned totalBits = max(bytesRequired(v), 1u) * 8;
solAssert(totalBits <= 256, ""); solAssert(totalBits <= 256, "");
return TypeProvider::fixedPointType( return TypeProvider::fixedPoint(
totalBits, fractionalDigits, totalBits, fractionalDigits,
negative ? FixedPointType::Modifier::Signed : FixedPointType::Modifier::Unsigned negative ? FixedPointType::Modifier::Signed : FixedPointType::Modifier::Unsigned
); );
@ -1292,7 +1292,7 @@ std::string StringLiteralType::toString(bool) const
TypePointer StringLiteralType::mobileType() const TypePointer StringLiteralType::mobileType() const
{ {
return TypeProvider::stringMemoryType(); return TypeProvider::stringMemory();
} }
bool StringLiteralType::isValidUTF8() const bool StringLiteralType::isValidUTF8() const
@ -1328,7 +1328,7 @@ TypeResult FixedBytesType::unaryOperatorResult(Token _operator) const
{ {
// "delete" and "~" is okay for FixedBytesType // "delete" and "~" is okay for FixedBytesType
if (_operator == Token::Delete) if (_operator == Token::Delete)
return TypeResult{TypeProvider::emptyTupleType()}; return TypeResult{TypeProvider::emptyTuple()};
else if (_operator == Token::BitNot) else if (_operator == Token::BitNot)
return this; return this;
@ -1388,7 +1388,7 @@ u256 BoolType::literalValue(Literal const* _literal) const
TypeResult BoolType::unaryOperatorResult(Token _operator) const TypeResult BoolType::unaryOperatorResult(Token _operator) const
{ {
if (_operator == Token::Delete) if (_operator == Token::Delete)
return TypeProvider::emptyTupleType(); // TODO: Lag of understanding. return TypeProvider::emptyTuple();
else if (_operator == Token::Not) else if (_operator == Token::Not)
return this; return this;
else else
@ -1411,9 +1411,9 @@ Type const* ContractType::encodingType() const
return nullptr; return nullptr;
if (isPayable()) if (isPayable())
return TypeProvider::payableAddressType(); return TypeProvider::payableAddress();
else else
return TypeProvider::addressType(); return TypeProvider::address();
} }
BoolResult ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const BoolResult ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const
@ -1451,7 +1451,7 @@ TypeResult ContractType::unaryOperatorResult(Token _operator) const
if (isSuper()) if (isSuper())
return nullptr; return nullptr;
else if (_operator == Token::Delete) else if (_operator == Token::Delete)
return TypeProvider::emptyTupleType(); // TODO: Lag of understanding. return TypeProvider::emptyTuple();
else else
return nullptr; return nullptr;
} }
@ -1472,23 +1472,16 @@ TypeResult ReferenceType::unaryOperatorResult(Token _operator) const
case DataLocation::CallData: case DataLocation::CallData:
return nullptr; return nullptr;
case DataLocation::Memory: case DataLocation::Memory:
return TypeProvider::emptyTupleType(); return TypeProvider::emptyTuple();
case DataLocation::Storage: case DataLocation::Storage:
return m_isPointer ? nullptr : TypeProvider::emptyTupleType(); return m_isPointer ? nullptr : TypeProvider::emptyTuple();
} }
return nullptr; return nullptr;
} }
TypePointer ReferenceType::copyForLocationIfReference(DataLocation _location, Type const* _type)
{
if (auto type = dynamic_cast<ReferenceType const*>(_type))
return TypeProvider::withLocation(type, _location, false);
return _type;
}
TypePointer ReferenceType::copyForLocationIfReference(Type const* _type) const TypePointer ReferenceType::copyForLocationIfReference(Type const* _type) const
{ {
return copyForLocationIfReference(m_location, _type); return TypeProvider::withLocationIfReference(m_location, _type);
} }
string ReferenceType::stringForReferencePart() const string ReferenceType::stringForReferencePart() const
@ -1529,7 +1522,7 @@ string ReferenceType::identifierLocationSuffix() const
ArrayType::ArrayType(DataLocation _location, bool _isString): ArrayType::ArrayType(DataLocation _location, bool _isString):
ReferenceType(_location), ReferenceType(_location),
m_arrayKind(_isString ? ArrayKind::String : ArrayKind::Bytes), m_arrayKind(_isString ? ArrayKind::String : ArrayKind::Bytes),
m_baseType{TypeProvider::byteType()} m_baseType{TypeProvider::byte()}
{ {
} }
@ -1756,14 +1749,14 @@ MemberList::MemberMap ArrayType::nativeMembers(ContractDefinition const*) const
members.emplace_back("length", TypeProvider::uint256()); members.emplace_back("length", TypeProvider::uint256());
if (isDynamicallySized() && location() == DataLocation::Storage) if (isDynamicallySized() && location() == DataLocation::Storage)
{ {
members.emplace_back("push", TypeProvider::functionType( members.emplace_back("push", TypeProvider::function(
TypePointers{baseType()}, TypePointers{baseType()},
TypePointers{TypeProvider::uint256()}, TypePointers{TypeProvider::uint256()},
strings{string()}, strings{string()},
strings{string()}, strings{string()},
isByteArray() ? FunctionType::Kind::ByteArrayPush : FunctionType::Kind::ArrayPush isByteArray() ? FunctionType::Kind::ByteArrayPush : FunctionType::Kind::ArrayPush
)); ));
members.emplace_back("pop", TypeProvider::functionType( members.emplace_back("pop", TypeProvider::function(
TypePointers{}, TypePointers{},
TypePointers{}, TypePointers{},
strings{}, strings{},
@ -1812,9 +1805,9 @@ TypeResult ArrayType::interfaceType(bool _inLibrary) const
else if (m_arrayKind != ArrayKind::Ordinary) else if (m_arrayKind != ArrayKind::Ordinary)
result = TypeProvider::withLocation(this, DataLocation::Memory, true); result = TypeProvider::withLocation(this, DataLocation::Memory, true);
else if (isDynamicallySized()) else if (isDynamicallySized())
result = TypeProvider::arrayType(DataLocation::Memory, baseInterfaceType); result = TypeProvider::array(DataLocation::Memory, baseInterfaceType);
else else
result = TypeProvider::arrayType(DataLocation::Memory, baseInterfaceType, m_length); result = TypeProvider::array(DataLocation::Memory, baseInterfaceType, m_length);
if (_inLibrary) if (_inLibrary)
m_interfaceType_library = result; m_interfaceType_library = result;
@ -1886,7 +1879,7 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const* _con
if (!function->isVisibleInDerivedContracts() || !function->isImplemented()) if (!function->isVisibleInDerivedContracts() || !function->isImplemented())
continue; continue;
auto functionType = TypeProvider::functionType(*function, true); auto functionType = TypeProvider::function(*function, true);
bool functionWithEqualArgumentsFound = false; bool functionWithEqualArgumentsFound = false;
for (auto const& member: members) for (auto const& member: members)
{ {
@ -2202,9 +2195,9 @@ FunctionTypePointer StructType::constructorType() const
if (!member.type->canLiveOutsideStorage()) if (!member.type->canLiveOutsideStorage())
continue; continue;
paramNames.push_back(member.name); paramNames.push_back(member.name);
paramTypes.push_back(copyForLocationIfReference(DataLocation::Memory, member.type)); paramTypes.push_back(TypeProvider::withLocationIfReference(DataLocation::Memory, member.type));
} }
return TypeProvider::functionType( return TypeProvider::function(
paramTypes, paramTypes,
TypePointers{TypeProvider::withLocation(this, DataLocation::Memory, false)}, TypePointers{TypeProvider::withLocation(this, DataLocation::Memory, false)},
paramNames, paramNames,
@ -2257,7 +2250,7 @@ TypePointer EnumType::encodingType() const
TypeResult EnumType::unaryOperatorResult(Token _operator) const TypeResult EnumType::unaryOperatorResult(Token _operator) const
{ {
return _operator == Token::Delete ? TypeProvider::emptyTupleType() : nullptr; return _operator == Token::Delete ? TypeProvider::emptyTuple() : nullptr;
} }
string EnumType::richIdentifier() const string EnumType::richIdentifier() const
@ -2386,7 +2379,7 @@ TypePointer TupleType::mobileType() const
else else
mobiles.push_back(nullptr); mobiles.push_back(nullptr);
} }
return TypeProvider::tupleType(move(mobiles)); return TypeProvider::tuple(move(mobiles));
} }
TypePointer TupleType::closestTemporaryType(Type const* _targetType) const TypePointer TupleType::closestTemporaryType(Type const* _targetType) const
@ -2403,7 +2396,7 @@ TypePointer TupleType::closestTemporaryType(Type const* _targetType) const
solAssert(tempComponents[i], ""); solAssert(tempComponents[i], "");
} }
} }
return TypeProvider::tupleType(move(tempComponents)); return TypeProvider::tuple(move(tempComponents));
} }
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal): FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
@ -2581,9 +2574,9 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
stateMutability = StateMutability::Payable; stateMutability = StateMutability::Payable;
} }
return TypeProvider::functionType( return TypeProvider::function(
parameters, parameters,
TypePointers{TypeProvider::contractType(_contract)}, TypePointers{TypeProvider::contract(_contract)},
parameterNames, parameterNames,
strings{""}, strings{""},
Kind::Creation, Kind::Creation,
@ -2613,7 +2606,7 @@ TypePointers FunctionType::returnParameterTypesWithoutDynamicTypes() const
) )
for (auto& param: returnParameterTypes) for (auto& param: returnParameterTypes)
if (param->isDynamicallySized() && !param->dataStoredIn(DataLocation::Storage)) if (param->isDynamicallySized() && !param->dataStoredIn(DataLocation::Storage))
param = TypeProvider::inaccessibleDynamicType(); param = TypeProvider::inaccessibleDynamic();
return returnParameterTypes; return returnParameterTypes;
} }
@ -2696,7 +2689,7 @@ bool FunctionType::operator==(Type const& _other) const
BoolResult FunctionType::isExplicitlyConvertibleTo(Type const& _convertTo) const BoolResult FunctionType::isExplicitlyConvertibleTo(Type const& _convertTo) const
{ {
if (m_kind == Kind::External && _convertTo == *TypeProvider::addressType()) if (m_kind == Kind::External && _convertTo == *TypeProvider::address())
return true; return true;
return _convertTo.category() == category(); return _convertTo.category() == category();
} }
@ -2729,7 +2722,7 @@ BoolResult FunctionType::isImplicitlyConvertibleTo(Type const& _convertTo) const
TypeResult FunctionType::unaryOperatorResult(Token _operator) const TypeResult FunctionType::unaryOperatorResult(Token _operator) const
{ {
if (_operator == Token::Delete) if (_operator == Token::Delete)
return TypeResult(TypeProvider::emptyTupleType()); return TypeResult(TypeProvider::emptyTuple());
return nullptr; return nullptr;
} }
@ -2870,7 +2863,7 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
if (variable && retParamTypes.empty()) if (variable && retParamTypes.empty())
return FunctionTypePointer(); return FunctionTypePointer();
return TypeProvider::functionType( return TypeProvider::function(
paramTypes, paramTypes,
retParamTypes, retParamTypes,
m_parameterNames, m_parameterNames,
@ -2895,13 +2888,13 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
{ {
MemberList::MemberMap members; MemberList::MemberMap members;
if (m_kind == Kind::External) if (m_kind == Kind::External)
members.emplace_back("selector", TypeProvider::fixedBytesType(4)); members.emplace_back("selector", TypeProvider::fixedBytes(4));
if (m_kind != Kind::BareDelegateCall) if (m_kind != Kind::BareDelegateCall)
{ {
if (isPayable()) if (isPayable())
members.emplace_back( members.emplace_back(
"value", "value",
TypeProvider::functionType( TypeProvider::function(
parseElementaryTypeVector({"uint"}), parseElementaryTypeVector({"uint"}),
TypePointers{copyAndSetGasOrValue(false, true)}, TypePointers{copyAndSetGasOrValue(false, true)},
strings(1, ""), strings(1, ""),
@ -2918,7 +2911,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
if (m_kind != Kind::Creation) if (m_kind != Kind::Creation)
members.emplace_back( members.emplace_back(
"gas", "gas",
TypeProvider::functionType( TypeProvider::function(
parseElementaryTypeVector({"uint"}), parseElementaryTypeVector({"uint"}),
TypePointers{copyAndSetGasOrValue(true, false)}, TypePointers{copyAndSetGasOrValue(true, false)},
strings(1, ""), strings(1, ""),
@ -3132,7 +3125,7 @@ TypePointers FunctionType::parseElementaryTypeVector(strings const& _types)
TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) const TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) const
{ {
return TypeProvider::functionType( return TypeProvider::function(
m_parameterTypes, m_parameterTypes,
m_returnParameterTypes, m_returnParameterTypes,
m_parameterNames, m_parameterNames,
@ -3172,7 +3165,7 @@ FunctionTypePointer FunctionType::asCallableFunction(bool _inLibrary, bool _boun
kind = Kind::DelegateCall; kind = Kind::DelegateCall;
} }
return TypeProvider::functionType( return TypeProvider::function(
parameterTypes, parameterTypes,
m_returnParameterTypes, m_returnParameterTypes,
m_parameterNames, m_parameterNames,
@ -3225,7 +3218,7 @@ bool FunctionType::padArguments() const
Type const* MappingType::encodingType() const Type const* MappingType::encodingType() const
{ {
return TypeProvider::integerType(256, IntegerType::Modifier::Unsigned); return TypeProvider::integer(256, IntegerType::Modifier::Unsigned);
} }
string MappingType::richIdentifier() const string MappingType::richIdentifier() const
@ -3415,11 +3408,6 @@ string ModuleType::toString(bool) const
return string("module \"") + m_sourceUnit.annotation().path + string("\""); return string("module \"") + m_sourceUnit.annotation().path + string("\"");
} }
MagicType const* MagicType::metaType(TypePointer _type)
{
return TypeProvider::metaType(_type);
}
string MagicType::richIdentifier() const string MagicType::richIdentifier() const
{ {
switch (m_kind) switch (m_kind)
@ -3453,65 +3441,65 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
{ {
case Kind::Block: case Kind::Block:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"coinbase", TypeProvider::payableAddressType()}, {"coinbase", TypeProvider::payableAddress()},
{"timestamp", TypeProvider::uint256()}, {"timestamp", TypeProvider::uint256()},
{"blockhash", TypeProvider::functionType(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)}, {"blockhash", TypeProvider::function(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
{"difficulty", TypeProvider::uint256()}, {"difficulty", TypeProvider::uint256()},
{"number", TypeProvider::uint256()}, {"number", TypeProvider::uint256()},
{"gaslimit", TypeProvider::uint256()} {"gaslimit", TypeProvider::uint256()}
}); });
case Kind::Message: case Kind::Message:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"sender", TypeProvider::payableAddressType()}, {"sender", TypeProvider::payableAddress()},
{"gas", TypeProvider::uint256()}, {"gas", TypeProvider::uint256()},
{"value", TypeProvider::uint256()}, {"value", TypeProvider::uint256()},
{"data", TypeProvider::arrayType(DataLocation::CallData)}, {"data", TypeProvider::array(DataLocation::CallData)},
{"sig", TypeProvider::fixedBytesType(4)} {"sig", TypeProvider::fixedBytes(4)}
}); });
case Kind::Transaction: case Kind::Transaction:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"origin", TypeProvider::payableAddressType()}, {"origin", TypeProvider::payableAddress()},
{"gasprice", TypeProvider::uint256()} {"gasprice", TypeProvider::uint256()}
}); });
case Kind::ABI: case Kind::ABI:
return MemberList::MemberMap({ return MemberList::MemberMap({
{"encode", TypeProvider::functionType( {"encode", TypeProvider::function(
TypePointers{}, TypePointers{},
TypePointers{TypeProvider::arrayType(DataLocation::Memory)}, TypePointers{TypeProvider::array(DataLocation::Memory)},
strings{}, strings{},
strings{1, ""}, strings{1, ""},
FunctionType::Kind::ABIEncode, FunctionType::Kind::ABIEncode,
true, true,
StateMutability::Pure StateMutability::Pure
)}, )},
{"encodePacked", TypeProvider::functionType( {"encodePacked", TypeProvider::function(
TypePointers{}, TypePointers{},
TypePointers{TypeProvider::arrayType(DataLocation::Memory)}, TypePointers{TypeProvider::array(DataLocation::Memory)},
strings{}, strings{},
strings{1, ""}, strings{1, ""},
FunctionType::Kind::ABIEncodePacked, FunctionType::Kind::ABIEncodePacked,
true, true,
StateMutability::Pure StateMutability::Pure
)}, )},
{"encodeWithSelector", TypeProvider::functionType( {"encodeWithSelector", TypeProvider::function(
TypePointers{TypeProvider::fixedBytesType(4)}, TypePointers{TypeProvider::fixedBytes(4)},
TypePointers{TypeProvider::arrayType(DataLocation::Memory)}, TypePointers{TypeProvider::array(DataLocation::Memory)},
strings{1, ""}, strings{1, ""},
strings{1, ""}, strings{1, ""},
FunctionType::Kind::ABIEncodeWithSelector, FunctionType::Kind::ABIEncodeWithSelector,
true, true,
StateMutability::Pure StateMutability::Pure
)}, )},
{"encodeWithSignature", TypeProvider::functionType( {"encodeWithSignature", TypeProvider::function(
TypePointers{TypeProvider::arrayType(DataLocation::Memory, true)}, TypePointers{TypeProvider::array(DataLocation::Memory, true)},
TypePointers{TypeProvider::arrayType(DataLocation::Memory)}, TypePointers{TypeProvider::array(DataLocation::Memory)},
strings{1, ""}, strings{1, ""},
strings{1, ""}, strings{1, ""},
FunctionType::Kind::ABIEncodeWithSignature, FunctionType::Kind::ABIEncodeWithSignature,
true, true,
StateMutability::Pure StateMutability::Pure
)}, )},
{"decode", TypeProvider::functionType( {"decode", TypeProvider::function(
TypePointers(), TypePointers(),
TypePointers(), TypePointers(),
strings{}, strings{},
@ -3530,9 +3518,9 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*m_typeArgument).contractDefinition(); ContractDefinition const& contract = dynamic_cast<ContractType const&>(*m_typeArgument).contractDefinition();
if (contract.canBeDeployed()) if (contract.canBeDeployed())
return MemberList::MemberMap({ return MemberList::MemberMap({
{"creationCode", TypeProvider::arrayType(DataLocation::Memory)}, {"creationCode", TypeProvider::array(DataLocation::Memory)},
{"runtimeCode", TypeProvider::arrayType(DataLocation::Memory)}, {"runtimeCode", TypeProvider::array(DataLocation::Memory)},
{"name", TypeProvider::stringMemoryType()}, {"name", TypeProvider::stringMemory()},
}); });
else else
return {}; return {};
@ -3571,5 +3559,5 @@ TypePointer MagicType::typeArgument() const
TypePointer InaccessibleDynamicType::decodingType() const TypePointer InaccessibleDynamicType::decodingType() const
{ {
return TypeProvider::integerType(256, IntegerType::Modifier::Unsigned); return TypeProvider::integer(256, IntegerType::Modifier::Unsigned);
} }

View File

@ -654,11 +654,6 @@ public:
return location() == _other.location() && isPointer() == _other.isPointer(); return location() == _other.location() && isPointer() == _other.isPointer();
} }
/// @returns a copy of @a _type having the same location as this (and is not a pointer type)
/// if _type is a reference type and an unmodified copy of _type otherwise.
/// This function is mostly useful to modify inner types appropriately.
static Type const* copyForLocationIfReference(DataLocation _location, Type const* _type);
Type const* withLocation(DataLocation _location, bool _isPointer) const; Type const* withLocation(DataLocation _location, bool _isPointer) const;
protected: protected:
@ -1346,9 +1341,6 @@ public:
Category category() const override { return Category::Magic; } Category category() const override { return Category::Magic; }
/// Factory function for meta type
static MagicType const* metaType(TypePointer _type);
TypeResult binaryOperatorResult(Token, Type const*) const override TypeResult binaryOperatorResult(Token, Type const*) const override
{ {
return nullptr; return nullptr;

View File

@ -90,7 +90,7 @@ void CompilerUtils::revertWithStringData(Type const& _argumentType)
m_context << Instruction::DUP2 << Instruction::MSTORE; m_context << Instruction::DUP2 << Instruction::MSTORE;
m_context << u256(4) << Instruction::ADD; m_context << u256(4) << Instruction::ADD;
// Stack: <string data> <mem pos of encoding start> // Stack: <string data> <mem pos of encoding start>
abiEncode({&_argumentType}, {TypeProvider::arrayType(DataLocation::Memory, true)}); abiEncode({&_argumentType}, {TypeProvider::array(DataLocation::Memory, true)});
toSizeAfterFreeMemoryPointer(); toSizeAfterFreeMemoryPointer();
m_context << Instruction::REVERT; m_context << Instruction::REVERT;
} }

View File

@ -872,7 +872,7 @@ bool ContractCompiler::visit(Return const& _return)
TypePointer expectedType; TypePointer expectedType;
if (expression->annotation().type->category() == Type::Category::Tuple || types.size() != 1) if (expression->annotation().type->category() == Type::Category::Tuple || types.size() != 1)
expectedType = TypeProvider::tupleType(move(types)); expectedType = TypeProvider::tuple(move(types));
else else
expectedType = types.front(); expectedType = types.front();
compileExpression(*expression, expectedType); compileExpression(*expression, expectedType);

View File

@ -732,9 +732,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
arguments.front()->accept(*this); arguments.front()->accept(*this);
// Optimization: If type is bytes or string, then do not encode, // Optimization: If type is bytes or string, then do not encode,
// but directly compute keccak256 on memory. // but directly compute keccak256 on memory.
if (*argType == *TypeProvider::bytesMemoryType() || *argType == *TypeProvider::stringMemoryType()) if (*argType == *TypeProvider::bytesMemory() || *argType == *TypeProvider::stringMemory())
{ {
ArrayUtils(m_context).retrieveLength(*TypeProvider::bytesMemoryType()); ArrayUtils(m_context).retrieveLength(*TypeProvider::bytesMemory());
m_context << Instruction::SWAP1 << u256(0x20) << Instruction::ADD; m_context << Instruction::SWAP1 << u256(0x20) << Instruction::ADD;
} }
else else
@ -875,8 +875,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
TypePointer paramType = function.parameterTypes()[0]; TypePointer paramType = function.parameterTypes()[0];
ArrayType const* arrayType = ArrayType const* arrayType =
function.kind() == FunctionType::Kind::ArrayPush ? function.kind() == FunctionType::Kind::ArrayPush ?
TypeProvider::arrayType(DataLocation::Storage, paramType) : TypeProvider::array(DataLocation::Storage, paramType) :
TypeProvider::arrayType(DataLocation::Storage); TypeProvider::array(DataLocation::Storage);
// stack: ArrayReference // stack: ArrayReference
arguments[0]->accept(*this); arguments[0]->accept(*this);
@ -1062,7 +1062,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
{ {
FixedHash<4> hash(dev::keccak256(stringType->value())); FixedHash<4> hash(dev::keccak256(stringType->value()));
m_context << (u256(FixedHash<4>::Arith(hash)) << (256 - 32)); m_context << (u256(FixedHash<4>::Arith(hash)) << (256 - 32));
dataOnStack = TypeProvider::fixedBytesType(4); dataOnStack = TypeProvider::fixedBytes(4);
} }
else else
{ {
@ -1073,7 +1073,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
m_context << Instruction::KECCAK256; m_context << Instruction::KECCAK256;
// stack: <memory pointer> <hash> // stack: <memory pointer> <hash>
dataOnStack = TypeProvider::fixedBytesType(32); dataOnStack = TypeProvider::fixedBytes(32);
} }
} }
else else
@ -1115,7 +1115,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
utils().abiDecode(targetTypes, false); utils().abiDecode(targetTypes, false);
else else
{ {
utils().convertType(*firstArgType, *TypeProvider::bytesMemoryType()); utils().convertType(*firstArgType, *TypeProvider::bytesMemory());
m_context << Instruction::DUP1 << u256(32) << Instruction::ADD; m_context << Instruction::DUP1 << u256(32) << Instruction::ADD;
m_context << Instruction::SWAP1 << Instruction::MLOAD; m_context << Instruction::SWAP1 << Instruction::MLOAD;
// stack now: <mem_pos> <length> // stack now: <mem_pos> <length>
@ -1289,7 +1289,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
identifier = FunctionType(*function).externalIdentifier(); identifier = FunctionType(*function).externalIdentifier();
else else
solAssert(false, "Contract member is neither variable nor function."); solAssert(false, "Contract member is neither variable nor function.");
utils().convertType(type, type.isPayable() ? *TypeProvider::payableAddressType() : *TypeProvider::addressType(), true); utils().convertType(type, type.isPayable() ? *TypeProvider::payableAddress() : *TypeProvider::address(), true);
m_context << identifier; m_context << identifier;
} }
else else
@ -1307,7 +1307,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
{ {
utils().convertType( utils().convertType(
*_memberAccess.expression().annotation().type, *_memberAccess.expression().annotation().type,
*TypeProvider::addressType(), *TypeProvider::address(),
true true
); );
m_context << Instruction::BALANCE; m_context << Instruction::BALANCE;
@ -1324,7 +1324,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
else if ((set<string>{"call", "callcode", "delegatecall", "staticcall"}).count(member)) else if ((set<string>{"call", "callcode", "delegatecall", "staticcall"}).count(member))
utils().convertType( utils().convertType(
*_memberAccess.expression().annotation().type, *_memberAccess.expression().annotation().type,
*TypeProvider::addressType(), *TypeProvider::address(),
true true
); );
else else

View File

@ -419,11 +419,8 @@ void StorageItem::setToZero(SourceLocation const&, bool _removeReference) const
} }
} }
/// Used in StorageByteArrayElement
static FixedBytesType byteType(1);
StorageByteArrayElement::StorageByteArrayElement(CompilerContext& _compilerContext): StorageByteArrayElement::StorageByteArrayElement(CompilerContext& _compilerContext):
LValue(_compilerContext, &byteType) LValue(_compilerContext, TypeProvider::byte())
{ {
} }

View File

@ -145,7 +145,7 @@ string YulUtilFunctions::leftAlignFunction(Type const& _type)
templ("body", "aligned := value"); templ("body", "aligned := value");
break; break;
case Type::Category::Contract: case Type::Category::Contract:
templ("body", "aligned := " + leftAlignFunction(*TypeProvider::addressType()) + "(value)"); templ("body", "aligned := " + leftAlignFunction(*TypeProvider::address()) + "(value)");
break; break;
case Type::Category::Enum: case Type::Category::Enum:
{ {

View File

@ -804,7 +804,7 @@ void SMTChecker::endVisit(Literal const& _literal)
{ {
if (type.category() == Type::Category::StringLiteral) if (type.category() == Type::Category::StringLiteral)
{ {
auto stringType = TypeProvider::stringMemoryType(); auto stringType = TypeProvider::stringMemory();
auto stringLit = dynamic_cast<StringLiteralType const*>(_literal.annotation().type); auto stringLit = dynamic_cast<StringLiteralType const*>(_literal.annotation().type);
solAssert(stringLit, ""); solAssert(stringLit, "");
auto result = newSymbolicVariable(*stringType, stringLit->richIdentifier(), *m_interface); auto result = newSymbolicVariable(*stringType, stringLit->richIdentifier(), *m_interface);
@ -1524,7 +1524,7 @@ void SMTChecker::resetVariables(function<bool(VariableDeclaration const&)> const
TypePointer SMTChecker::typeWithoutPointer(TypePointer const& _type) TypePointer SMTChecker::typeWithoutPointer(TypePointer const& _type)
{ {
if (auto refType = dynamic_cast<ReferenceType const*>(_type)) if (auto refType = dynamic_cast<ReferenceType const*>(_type))
return ReferenceType::copyForLocationIfReference(refType->location(), _type); return TypeProvider::withLocationIfReference(refType->location(), _type);
return _type; return _type;
} }

View File

@ -598,7 +598,7 @@ BOOST_AUTO_TEST_CASE(blockhash)
} }
)"; )";
auto blockhashFun = TypeProvider::functionType(strings{"uint256"}, strings{"bytes32"}, auto blockhashFun = TypeProvider::function(strings{"uint256"}, strings{"bytes32"},
FunctionType::Kind::BlockHash, false, StateMutability::View); FunctionType::Kind::BlockHash, false, StateMutability::View);
bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("blockhash", blockhashFun)}); bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("blockhash", blockhashFun)});
@ -619,7 +619,7 @@ BOOST_AUTO_TEST_CASE(gas_left)
)"; )";
bytes code = compileFirstExpression( bytes code = compileFirstExpression(
sourceCode, {}, {}, sourceCode, {}, {},
{make_shared<MagicVariableDeclaration>("gasleft", TypeProvider::functionType(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft))} {make_shared<MagicVariableDeclaration>("gasleft", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft))}
); );
bytes expectation = bytes({uint8_t(Instruction::GAS)}); bytes expectation = bytes({uint8_t(Instruction::GAS)});

View File

@ -40,42 +40,42 @@ BOOST_AUTO_TEST_SUITE(SolidityTypes)
BOOST_AUTO_TEST_CASE(int_types) BOOST_AUTO_TEST_CASE(int_types)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::Int, 0, 0)) == *TypeProvider::integerType(256, IntegerType::Modifier::Signed)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::Int, 0, 0)) == *TypeProvider::integer(256, IntegerType::Modifier::Signed));
for (unsigned i = 8; i <= 256; i += 8) for (unsigned i = 8; i <= 256; i += 8)
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, i, 0)) == *TypeProvider::integerType(i, IntegerType::Modifier::Signed)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, i, 0)) == *TypeProvider::integer(i, IntegerType::Modifier::Signed));
} }
BOOST_AUTO_TEST_CASE(uint_types) BOOST_AUTO_TEST_CASE(uint_types)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UInt, 0, 0)) == *TypeProvider::integerType(256, IntegerType::Modifier::Unsigned)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UInt, 0, 0)) == *TypeProvider::integer(256, IntegerType::Modifier::Unsigned));
for (unsigned i = 8; i <= 256; i += 8) for (unsigned i = 8; i <= 256; i += 8)
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, i, 0)) == *TypeProvider::integerType(i, IntegerType::Modifier::Unsigned)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, i, 0)) == *TypeProvider::integer(i, IntegerType::Modifier::Unsigned));
} }
BOOST_AUTO_TEST_CASE(byte_types) BOOST_AUTO_TEST_CASE(byte_types)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::Byte, 0, 0)) == *TypeProvider::fixedBytesType(1)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::Byte, 0, 0)) == *TypeProvider::fixedBytes(1));
for (unsigned i = 1; i <= 32; i++) for (unsigned i = 1; i <= 32; i++)
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, i, 0)) == *TypeProvider::fixedBytesType(i)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, i, 0)) == *TypeProvider::fixedBytes(i));
} }
BOOST_AUTO_TEST_CASE(fixed_types) BOOST_AUTO_TEST_CASE(fixed_types)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *TypeProvider::fixedPointType(128, 18, FixedPointType::Modifier::Signed)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *TypeProvider::fixedPoint(128, 18, FixedPointType::Modifier::Signed));
for (unsigned i = 8; i <= 256; i += 8) for (unsigned i = 8; i <= 256; i += 8)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 0)) == *TypeProvider::fixedPointType(i, 0, FixedPointType::Modifier::Signed)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 0)) == *TypeProvider::fixedPoint(i, 0, FixedPointType::Modifier::Signed));
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 2)) == *TypeProvider::fixedPointType(i, 2, FixedPointType::Modifier::Signed)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 2)) == *TypeProvider::fixedPoint(i, 2, FixedPointType::Modifier::Signed));
} }
} }
BOOST_AUTO_TEST_CASE(ufixed_types) BOOST_AUTO_TEST_CASE(ufixed_types)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *TypeProvider::fixedPointType(128, 18, FixedPointType::Modifier::Unsigned)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *TypeProvider::fixedPoint(128, 18, FixedPointType::Modifier::Unsigned));
for (unsigned i = 8; i <= 256; i += 8) for (unsigned i = 8; i <= 256; i += 8)
{ {
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 0)) == *TypeProvider::fixedPointType(i, 0, FixedPointType::Modifier::Unsigned)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 0)) == *TypeProvider::fixedPoint(i, 0, FixedPointType::Modifier::Unsigned));
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 2)) == *TypeProvider::fixedPointType(i, 2, FixedPointType::Modifier::Unsigned)); BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 2)) == *TypeProvider::fixedPoint(i, 2, FixedPointType::Modifier::Unsigned));
} }
} }
@ -99,12 +99,12 @@ BOOST_AUTO_TEST_CASE(storage_layout_mapping)
{ {
MemberList members(MemberList::MemberMap({ MemberList members(MemberList::MemberMap({
{string("first"), TypeProvider::fromElementaryTypeName("uint128")}, {string("first"), TypeProvider::fromElementaryTypeName("uint128")},
{string("second"), TypeProvider::mappingType( {string("second"), TypeProvider::mapping(
TypeProvider::fromElementaryTypeName("uint8"), TypeProvider::fromElementaryTypeName("uint8"),
TypeProvider::fromElementaryTypeName("uint8") TypeProvider::fromElementaryTypeName("uint8")
)}, )},
{string("third"), TypeProvider::fromElementaryTypeName("uint16")}, {string("third"), TypeProvider::fromElementaryTypeName("uint16")},
{string("final"), TypeProvider::mappingType( {string("final"), TypeProvider::mapping(
TypeProvider::fromElementaryTypeName("uint8"), TypeProvider::fromElementaryTypeName("uint8"),
TypeProvider::fromElementaryTypeName("uint8") TypeProvider::fromElementaryTypeName("uint8")
)}, )},
@ -122,13 +122,13 @@ BOOST_AUTO_TEST_CASE(storage_layout_mapping)
BOOST_AUTO_TEST_CASE(storage_layout_arrays) BOOST_AUTO_TEST_CASE(storage_layout_arrays)
{ {
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(1), 32).storageSize() == 1); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(1), 32).storageSize() == 1);
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(1), 33).storageSize() == 2); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(1), 33).storageSize() == 2);
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(2), 31).storageSize() == 2); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(2), 31).storageSize() == 2);
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(7), 8).storageSize() == 2); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(7), 8).storageSize() == 2);
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(7), 9).storageSize() == 3); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(7), 9).storageSize() == 3);
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(31), 9).storageSize() == 9); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(31), 9).storageSize() == 9);
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(32), 9).storageSize() == 9); BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(32), 9).storageSize() == 9);
} }
BOOST_AUTO_TEST_CASE(type_identifier_escaping) BOOST_AUTO_TEST_CASE(type_identifier_escaping)
@ -178,8 +178,8 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
BOOST_CHECK_EQUAL(TypeProvider::fromElementaryTypeName("string calldata")->identifier(), "t_string_calldata_ptr"); BOOST_CHECK_EQUAL(TypeProvider::fromElementaryTypeName("string calldata")->identifier(), "t_string_calldata_ptr");
ArrayType largeintArray(DataLocation::Memory, TypeProvider::fromElementaryTypeName("int128"), u256("2535301200456458802993406410752")); ArrayType largeintArray(DataLocation::Memory, TypeProvider::fromElementaryTypeName("int128"), u256("2535301200456458802993406410752"));
BOOST_CHECK_EQUAL(largeintArray.identifier(), "t_array$_t_int128_$2535301200456458802993406410752_memory_ptr"); BOOST_CHECK_EQUAL(largeintArray.identifier(), "t_array$_t_int128_$2535301200456458802993406410752_memory_ptr");
TypePointer stringArray = TypeProvider::arrayType(DataLocation::Storage, TypeProvider::fromElementaryTypeName("string"), u256("20")); TypePointer stringArray = TypeProvider::array(DataLocation::Storage, TypeProvider::fromElementaryTypeName("string"), u256("20"));
TypePointer multiArray = TypeProvider::arrayType(DataLocation::Storage, stringArray); TypePointer multiArray = TypeProvider::array(DataLocation::Storage, stringArray);
BOOST_CHECK_EQUAL(multiArray->identifier(), "t_array$_t_array$_t_string_storage_$20_storage_$dyn_storage_ptr"); BOOST_CHECK_EQUAL(multiArray->identifier(), "t_array$_t_array$_t_string_storage_$20_storage_$dyn_storage_ptr");
ContractDefinition c(SourceLocation{}, make_shared<string>("MyContract$"), {}, {}, {}, ContractDefinition::ContractKind::Contract); ContractDefinition c(SourceLocation{}, make_shared<string>("MyContract$"), {}, {}, {}, ContractDefinition::ContractKind::Contract);
@ -195,13 +195,13 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
TupleType t({e.type(), s.type(), stringArray, nullptr}); TupleType t({e.type(), s.type(), stringArray, nullptr});
BOOST_CHECK_EQUAL(t.identifier(), "t_tuple$_t_type$_t_enum$_Enum_$4_$_$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$_t_array$_t_string_storage_$20_storage_ptr_$__$"); BOOST_CHECK_EQUAL(t.identifier(), "t_tuple$_t_type$_t_enum$_Enum_$4_$_$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$_t_array$_t_string_storage_$20_storage_ptr_$__$");
TypePointer keccak256fun = TypeProvider::functionType(strings{}, strings{}, FunctionType::Kind::KECCAK256); TypePointer keccak256fun = TypeProvider::function(strings{}, strings{}, FunctionType::Kind::KECCAK256);
BOOST_CHECK_EQUAL(keccak256fun->identifier(), "t_function_keccak256_nonpayable$__$returns$__$"); BOOST_CHECK_EQUAL(keccak256fun->identifier(), "t_function_keccak256_nonpayable$__$returns$__$");
FunctionType metaFun(TypePointers{keccak256fun}, TypePointers{s.type()}, strings{""}, strings{""}); FunctionType metaFun(TypePointers{keccak256fun}, TypePointers{s.type()}, strings{""}, strings{""});
BOOST_CHECK_EQUAL(metaFun.identifier(), "t_function_internal_nonpayable$_t_function_keccak256_nonpayable$__$returns$__$_$returns$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$"); BOOST_CHECK_EQUAL(metaFun.identifier(), "t_function_internal_nonpayable$_t_function_keccak256_nonpayable$__$returns$__$_$returns$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$");
TypePointer m = TypeProvider::mappingType(TypeProvider::fromElementaryTypeName("bytes32"), s.type()); TypePointer m = TypeProvider::mapping(TypeProvider::fromElementaryTypeName("bytes32"), s.type());
MappingType m2(TypeProvider::fromElementaryTypeName("uint64"), m); MappingType m2(TypeProvider::fromElementaryTypeName("uint64"), m);
BOOST_CHECK_EQUAL(m2.identifier(), "t_mapping$_t_uint64_$_t_mapping$_t_bytes32_$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$_$"); BOOST_CHECK_EQUAL(m2.identifier(), "t_mapping$_t_uint64_$_t_mapping$_t_bytes32_$_t_type$_t_struct$_Struct_$3_storage_ptr_$_$_$");
@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(encoded_sizes)
BOOST_CHECK_EQUAL(BoolType().calldataEncodedSize(true), 32); BOOST_CHECK_EQUAL(BoolType().calldataEncodedSize(true), 32);
BOOST_CHECK_EQUAL(BoolType().calldataEncodedSize(false), 1); BOOST_CHECK_EQUAL(BoolType().calldataEncodedSize(false), 1);
ArrayType const* uint24Array = TypeProvider::arrayType( ArrayType const* uint24Array = TypeProvider::array(
DataLocation::Memory, DataLocation::Memory,
TypeProvider::uint(24), TypeProvider::uint(24),
9 9