mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[libsolidity] TypeProvider: eliminate redundant "Type" suffix in provider function signatures.
This commit is contained in:
parent
862b65d6e3
commit
721bf367a3
@ -57,7 +57,7 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
|
||||
setType(
|
||||
_operation,
|
||||
TokenTraits::isCompareOp(_operation.getOperator()) ?
|
||||
TypeProvider::boolType() :
|
||||
TypeProvider::boolean() :
|
||||
commonType
|
||||
);
|
||||
}
|
||||
|
@ -245,13 +245,13 @@ void ContractLevelChecker::checkAbstractFunctions(ContractDefinition const& _con
|
||||
{
|
||||
for (VariableDeclaration const* v: contract->stateVariables())
|
||||
if (v->isPartOfExternalInterface())
|
||||
registerFunction(*v, TypeProvider::functionType(*v), true);
|
||||
registerFunction(*v, TypeProvider::function(*v), true);
|
||||
|
||||
for (FunctionDefinition const* function: contract->definedFunctions())
|
||||
if (!function->isConstructor())
|
||||
registerFunction(
|
||||
*function,
|
||||
TypeProvider::functionType(*function)->asCallableFunction(false),
|
||||
TypeProvider::function(*function)->asCallableFunction(false),
|
||||
function->isImplemented()
|
||||
);
|
||||
}
|
||||
@ -408,7 +408,7 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
|
||||
for (FunctionDefinition const* f: contract->definedFunctions())
|
||||
if (f->isPartOfExternalInterface())
|
||||
{
|
||||
auto functionType = TypeProvider::functionType(*f);
|
||||
auto functionType = TypeProvider::function(*f);
|
||||
// under non error circumstances this should be true
|
||||
if (functionType->interfaceFunctionType())
|
||||
externalDeclarations[functionType->externalSignature()].emplace_back(
|
||||
@ -418,7 +418,7 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
|
||||
for (VariableDeclaration const* v: contract->stateVariables())
|
||||
if (v->isPartOfExternalInterface())
|
||||
{
|
||||
auto functionType = TypeProvider::functionType(*v);
|
||||
auto functionType = TypeProvider::function(*v);
|
||||
// under non error circumstances this should be true
|
||||
if (functionType->interfaceFunctionType())
|
||||
externalDeclarations[functionType->externalSignature()].emplace_back(
|
||||
|
@ -42,33 +42,33 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
|
||||
};
|
||||
|
||||
return {
|
||||
magicVarDecl("abi", TypeProvider::magicType(MagicType::Kind::ABI)),
|
||||
magicVarDecl("addmod", TypeProvider::functionType(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("block", TypeProvider::magicType(MagicType::Kind::Block)),
|
||||
magicVarDecl("blockhash", TypeProvider::functionType(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("gasleft", TypeProvider::functionType(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("log0", TypeProvider::functionType(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
|
||||
magicVarDecl("log1", TypeProvider::functionType(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log1)),
|
||||
magicVarDecl("log2", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log2)),
|
||||
magicVarDecl("log3", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log3)),
|
||||
magicVarDecl("log4", TypeProvider::functionType(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
|
||||
magicVarDecl("msg", TypeProvider::magicType(MagicType::Kind::Message)),
|
||||
magicVarDecl("mulmod", TypeProvider::functionType(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)),
|
||||
magicVarDecl("abi", TypeProvider::magic(MagicType::Kind::ABI)),
|
||||
magicVarDecl("addmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)),
|
||||
magicVarDecl("assert", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)),
|
||||
magicVarDecl("block", TypeProvider::magic(MagicType::Kind::Block)),
|
||||
magicVarDecl("blockhash", TypeProvider::function(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)),
|
||||
magicVarDecl("ecrecover", TypeProvider::function(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)),
|
||||
magicVarDecl("gasleft", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, false, StateMutability::View)),
|
||||
magicVarDecl("keccak256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)),
|
||||
magicVarDecl("log0", TypeProvider::function(strings{"bytes32"}, strings{}, FunctionType::Kind::Log0)),
|
||||
magicVarDecl("log1", TypeProvider::function(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log1)),
|
||||
magicVarDecl("log2", TypeProvider::function(strings{"bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log2)),
|
||||
magicVarDecl("log3", TypeProvider::function(strings{"bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log3)),
|
||||
magicVarDecl("log4", TypeProvider::function(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Kind::Log4)),
|
||||
magicVarDecl("msg", TypeProvider::magic(MagicType::Kind::Message)),
|
||||
magicVarDecl("mulmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, false, StateMutability::Pure)),
|
||||
magicVarDecl("now", TypeProvider::uint256()),
|
||||
magicVarDecl("require", TypeProvider::functionType(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("revert", TypeProvider::functionType(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)),
|
||||
magicVarDecl("revert", TypeProvider::functionType(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("selfdestruct", TypeProvider::functionType(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||
magicVarDecl("sha256", TypeProvider::functionType(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("suicide", TypeProvider::functionType(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||
magicVarDecl("tx", TypeProvider::magicType(MagicType::Kind::Transaction)),
|
||||
magicVarDecl("type", TypeProvider::functionType(
|
||||
magicVarDecl("require", TypeProvider::function(strings{"bool"}, 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::function(strings(), strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)),
|
||||
magicVarDecl("revert", TypeProvider::function(strings{"string memory"}, strings(), FunctionType::Kind::Revert, false, StateMutability::Pure)),
|
||||
magicVarDecl("ripemd160", TypeProvider::function(strings{"bytes memory"}, strings{"bytes20"}, FunctionType::Kind::RIPEMD160, false, StateMutability::Pure)),
|
||||
magicVarDecl("selfdestruct", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||
magicVarDecl("sha256", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::SHA256, false, StateMutability::Pure)),
|
||||
magicVarDecl("sha3", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::KECCAK256, false, StateMutability::Pure)),
|
||||
magicVarDecl("suicide", TypeProvider::function(strings{"address payable"}, strings{}, FunctionType::Kind::Selfdestruct)),
|
||||
magicVarDecl("tx", TypeProvider::magic(MagicType::Kind::Transaction)),
|
||||
magicVarDecl("type", TypeProvider::function(
|
||||
strings{"address"} /* accepts any contract type, handled by the type checker */,
|
||||
strings{} /* returns a MagicType, handled by the type checker */,
|
||||
FunctionType::Kind::MetaType,
|
||||
@ -99,7 +99,7 @@ vector<Declaration const*> GlobalContext::declarations() const
|
||||
MagicVariableDeclaration const* GlobalContext::currentThis() const
|
||||
{
|
||||
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();
|
||||
|
||||
}
|
||||
@ -107,7 +107,7 @@ MagicVariableDeclaration const* GlobalContext::currentThis() const
|
||||
MagicVariableDeclaration const* GlobalContext::currentSuper() const
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -129,10 +129,10 @@ bool ReferencesResolver::visit(ElementaryTypeName const& _typeName)
|
||||
switch(*_typeName.stateMutability())
|
||||
{
|
||||
case StateMutability::Payable:
|
||||
_typeName.annotation().type = TypeProvider::payableAddressType();
|
||||
_typeName.annotation().type = TypeProvider::payableAddress();
|
||||
break;
|
||||
case StateMutability::NonPayable:
|
||||
_typeName.annotation().type = TypeProvider::addressType();
|
||||
_typeName.annotation().type = TypeProvider::address();
|
||||
break;
|
||||
default:
|
||||
m_errorReporter.typeError(
|
||||
@ -186,10 +186,10 @@ void ReferencesResolver::endVisit(UserDefinedTypeName const& _typeName)
|
||||
else if (EnumDefinition const* enumDef = dynamic_cast<EnumDefinition const*>(declaration))
|
||||
_typeName.annotation().type = TypeProvider::enumType(*enumDef);
|
||||
else if (ContractDefinition const* contract = dynamic_cast<ContractDefinition const*>(declaration))
|
||||
_typeName.annotation().type = TypeProvider::contractType(*contract);
|
||||
_typeName.annotation().type = TypeProvider::contract(*contract);
|
||||
else
|
||||
{
|
||||
_typeName.annotation().type = TypeProvider::emptyTupleType();
|
||||
_typeName.annotation().type = TypeProvider::emptyTuple();
|
||||
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)
|
||||
@ -234,7 +234,7 @@ void ReferencesResolver::endVisit(Mapping const& _typeName)
|
||||
keyType = TypeProvider::withLocationIfReference(DataLocation::Memory, keyType);
|
||||
// Convert value type to storage reference.
|
||||
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)
|
||||
@ -262,10 +262,10 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
|
||||
else if (lengthType->isNegative())
|
||||
fatalTypeError(length->location(), "Array with negative length specified.");
|
||||
else
|
||||
_typeName.annotation().type = TypeProvider::arrayType(DataLocation::Storage, baseType, lengthType->literalValue(nullptr));
|
||||
_typeName.annotation().type = TypeProvider::array(DataLocation::Storage, baseType, lengthType->literalValue(nullptr));
|
||||
}
|
||||
else
|
||||
_typeName.annotation().type = TypeProvider::arrayType(DataLocation::Storage, baseType);
|
||||
_typeName.annotation().type = TypeProvider::array(DataLocation::Storage, baseType);
|
||||
}
|
||||
|
||||
bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
|
||||
|
@ -138,7 +138,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
|
||||
|
||||
if (arguments.size() >= 1)
|
||||
{
|
||||
BoolResult result = type(*arguments.front())->isImplicitlyConvertibleTo(*TypeProvider::bytesMemoryType());
|
||||
BoolResult result = type(*arguments.front())->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory());
|
||||
|
||||
if (!result)
|
||||
m_errorReporter.typeErrorConcatenateDescriptions(
|
||||
@ -180,7 +180,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
|
||||
actualType = TypeProvider::withLocationIfReference(DataLocation::Memory, actualType);
|
||||
// We force address payable for address types.
|
||||
if (actualType->category() == Type::Category::Address)
|
||||
actualType = TypeProvider::payableAddressType();
|
||||
actualType = TypeProvider::payableAddress();
|
||||
solAssert(
|
||||
!actualType->dataStoredIn(DataLocation::CallData) &&
|
||||
!actualType->dataStoredIn(DataLocation::Storage),
|
||||
@ -196,7 +196,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
|
||||
else
|
||||
{
|
||||
m_errorReporter.typeError(typeArgument->location(), "Argument has to be a type name.");
|
||||
components.push_back(TypeProvider::emptyTupleType());
|
||||
components.push_back(TypeProvider::emptyTuple());
|
||||
}
|
||||
}
|
||||
return components;
|
||||
@ -231,7 +231,7 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
|
||||
return {};
|
||||
}
|
||||
|
||||
return {TypeProvider::metaType(dynamic_cast<TypeType const&>(*firstArgType).actualType())};
|
||||
return {TypeProvider::meta(dynamic_cast<TypeType const&>(*firstArgType).actualType())};
|
||||
}
|
||||
|
||||
void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
|
||||
@ -717,7 +717,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
|
||||
|
||||
bool TypeChecker::visit(IfStatement const& _ifStatement)
|
||||
{
|
||||
expectType(_ifStatement.condition(), *TypeProvider::boolType());
|
||||
expectType(_ifStatement.condition(), *TypeProvider::boolean());
|
||||
_ifStatement.trueStatement().accept(*this);
|
||||
if (_ifStatement.falseStatement())
|
||||
_ifStatement.falseStatement()->accept(*this);
|
||||
@ -726,7 +726,7 @@ bool TypeChecker::visit(IfStatement const& _ifStatement)
|
||||
|
||||
bool TypeChecker::visit(WhileStatement const& _whileStatement)
|
||||
{
|
||||
expectType(_whileStatement.condition(), *TypeProvider::boolType());
|
||||
expectType(_whileStatement.condition(), *TypeProvider::boolean());
|
||||
_whileStatement.body().accept(*this);
|
||||
return false;
|
||||
}
|
||||
@ -736,7 +736,7 @@ bool TypeChecker::visit(ForStatement const& _forStatement)
|
||||
if (_forStatement.initializationExpression())
|
||||
_forStatement.initializationExpression()->accept(*this);
|
||||
if (_forStatement.condition())
|
||||
expectType(*_forStatement.condition(), *TypeProvider::boolType());
|
||||
expectType(*_forStatement.condition(), *TypeProvider::boolean());
|
||||
if (_forStatement.loopExpression())
|
||||
_forStatement.loopExpression()->accept(*this);
|
||||
_forStatement.body().accept(*this);
|
||||
@ -951,7 +951,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
||||
else
|
||||
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.");
|
||||
else if (valueComponentType->category() == Type::Category::RationalNumber)
|
||||
{
|
||||
@ -1073,7 +1073,7 @@ void TypeChecker::endVisit(ExpressionStatement const& _statement)
|
||||
|
||||
bool TypeChecker::visit(Conditional const& _conditional)
|
||||
{
|
||||
expectType(_conditional.condition(), *TypeProvider::boolType());
|
||||
expectType(_conditional.condition(), *TypeProvider::boolean());
|
||||
|
||||
_conditional.trueExpression().accept(*this);
|
||||
_conditional.falseExpression().accept(*this);
|
||||
@ -1177,7 +1177,7 @@ bool TypeChecker::visit(Assignment const& _assignment)
|
||||
"Compound assignment is not allowed for tuple types."
|
||||
);
|
||||
// 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);
|
||||
|
||||
@ -1229,7 +1229,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
|
||||
if (components.size() == 1)
|
||||
_tuple.annotation().type = type(*components[0]);
|
||||
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.
|
||||
_tuple.annotation().isLValue = true;
|
||||
}
|
||||
@ -1286,14 +1286,14 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
|
||||
else if (!inlineArrayType->canLiveOutsideStorage())
|
||||
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
|
||||
{
|
||||
if (components.size() == 1)
|
||||
_tuple.annotation().type = type(*components[0]);
|
||||
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().type =
|
||||
TokenTraits::isCompareOp(_operation.getOperator()) ?
|
||||
TypeProvider::boolType() :
|
||||
TypeProvider::boolean() :
|
||||
commonType;
|
||||
_operation.annotation().isPure =
|
||||
_operation.leftExpression().annotation().isPure &&
|
||||
@ -1475,8 +1475,8 @@ TypePointer TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
|
||||
}
|
||||
if (resultType->category() == Type::Category::Address)
|
||||
{
|
||||
bool const payable = argType->isExplicitlyConvertibleTo(*TypeProvider::payableAddressType());
|
||||
resultType = payable ? TypeProvider::payableAddressType() : TypeProvider::addressType();
|
||||
bool const payable = argType->isExplicitlyConvertibleTo(*TypeProvider::payableAddress());
|
||||
resultType = payable ? TypeProvider::payableAddress() : TypeProvider::address();
|
||||
}
|
||||
}
|
||||
return resultType;
|
||||
@ -1925,7 +1925,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
||||
|
||||
funcCallAnno.type = returnTypes.size() == 1 ?
|
||||
move(returnTypes.front()) :
|
||||
TypeProvider::tupleType(move(returnTypes));
|
||||
TypeProvider::tuple(move(returnTypes));
|
||||
|
||||
break;
|
||||
}
|
||||
@ -1935,7 +1935,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
||||
// for non-callables, ensure error reported and annotate node to void function
|
||||
solAssert(m_errorReporter.hasErrors(), "");
|
||||
funcCallAnno.kind = FunctionCallKind::FunctionCall;
|
||||
funcCallAnno.type = TypeProvider::emptyTupleType();
|
||||
funcCallAnno.type = TypeProvider::emptyTuple();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1998,7 +1998,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
|
||||
"Length has to be placed in parentheses after the array type for new expression."
|
||||
);
|
||||
type = TypeProvider::withLocationIfReference(DataLocation::Memory, type);
|
||||
_newExpression.annotation().type = TypeProvider::functionType(
|
||||
_newExpression.annotation().type = TypeProvider::function(
|
||||
TypePointers{TypeProvider::uint256()},
|
||||
TypePointers{type},
|
||||
strings(1, ""),
|
||||
@ -2078,7 +2078,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
|
||||
}
|
||||
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)
|
||||
{
|
||||
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()))
|
||||
m_errorReporter.typeError(_access.location(), "Index access for contracts or libraries is not possible.");
|
||||
if (!index)
|
||||
resultType = TypeProvider::typeType(TypeProvider::arrayType(DataLocation::Memory, typeType.actualType()));
|
||||
resultType = TypeProvider::typeType(TypeProvider::array(DataLocation::Memory, typeType.actualType()));
|
||||
else
|
||||
{
|
||||
u256 length = 1;
|
||||
@ -2239,7 +2239,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
|
||||
else
|
||||
solAssert(m_errorReporter.hasErrors(), "Expected errors as expectType returned false");
|
||||
|
||||
resultType = TypeProvider::typeType(TypeProvider::arrayType(
|
||||
resultType = TypeProvider::typeType(TypeProvider::array(
|
||||
DataLocation::Memory,
|
||||
typeType.actualType(),
|
||||
length
|
||||
@ -2260,7 +2260,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
|
||||
if (bytesType.numBytes() <= integerType->literalValue(nullptr))
|
||||
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
|
||||
break;
|
||||
}
|
||||
@ -2373,7 +2373,7 @@ void TypeChecker::endVisit(Literal const& _literal)
|
||||
if (_literal.looksLikeAddress())
|
||||
{
|
||||
// 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;
|
||||
if (_literal.valueWithoutUnderscores().length() != 42) // "0x" + 40 hex digits
|
||||
|
@ -106,7 +106,7 @@ ImportAnnotation& ImportDirective::annotation() const
|
||||
TypePointer ImportDirective::type() const
|
||||
{
|
||||
solAssert(!!annotation().sourceUnit, "");
|
||||
return TypeProvider::moduleType(*annotation().sourceUnit);
|
||||
return TypeProvider::module(*annotation().sourceUnit);
|
||||
}
|
||||
|
||||
map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const
|
||||
@ -189,10 +189,10 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::inter
|
||||
vector<FunctionTypePointer> functions;
|
||||
for (FunctionDefinition const* f: contract->definedFunctions())
|
||||
if (f->isPartOfExternalInterface())
|
||||
functions.push_back(TypeProvider::functionType(*f, false));
|
||||
functions.push_back(TypeProvider::function(*f, false));
|
||||
for (VariableDeclaration const* v: contract->stateVariables())
|
||||
if (v->isPartOfExternalInterface())
|
||||
functions.push_back(TypeProvider::functionType(*v));
|
||||
functions.push_back(TypeProvider::function(*v));
|
||||
for (FunctionTypePointer const& fun: functions)
|
||||
{
|
||||
if (!fun->interfaceFunctionType())
|
||||
@ -247,7 +247,7 @@ vector<Declaration const*> const& ContractDefinition::inheritableMembers() const
|
||||
|
||||
TypePointer ContractDefinition::type() const
|
||||
{
|
||||
return TypeProvider::typeType(TypeProvider::contractType(*this));
|
||||
return TypeProvider::typeType(TypeProvider::contract(*this));
|
||||
}
|
||||
|
||||
ContractDefinitionAnnotation& ContractDefinition::annotation() const
|
||||
@ -313,7 +313,7 @@ FunctionTypePointer FunctionDefinition::functionType(bool _internal) const
|
||||
case Declaration::Visibility::Private:
|
||||
case Declaration::Visibility::Internal:
|
||||
case Declaration::Visibility::Public:
|
||||
return TypeProvider::functionType(*this, _internal);
|
||||
return TypeProvider::function(*this, _internal);
|
||||
case Declaration::Visibility::External:
|
||||
return {};
|
||||
}
|
||||
@ -329,7 +329,7 @@ FunctionTypePointer FunctionDefinition::functionType(bool _internal) const
|
||||
return {};
|
||||
case Declaration::Visibility::Public:
|
||||
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
|
||||
{
|
||||
solAssert(visibility() != Declaration::Visibility::External, "");
|
||||
return TypeProvider::functionType(*this);
|
||||
return TypeProvider::function(*this);
|
||||
}
|
||||
|
||||
string FunctionDefinition::externalSignature() const
|
||||
{
|
||||
return TypeProvider::functionType(*this)->externalSignature();
|
||||
return TypeProvider::function(*this)->externalSignature();
|
||||
}
|
||||
|
||||
FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
|
||||
@ -357,7 +357,7 @@ FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
|
||||
|
||||
TypePointer ModifierDefinition::type() const
|
||||
{
|
||||
return TypeProvider::modifierType(*this);
|
||||
return TypeProvider::modifier(*this);
|
||||
}
|
||||
|
||||
ModifierDefinitionAnnotation& ModifierDefinition::annotation() const
|
||||
@ -369,13 +369,13 @@ ModifierDefinitionAnnotation& ModifierDefinition::annotation() const
|
||||
|
||||
TypePointer EventDefinition::type() const
|
||||
{
|
||||
return TypeProvider::functionType(*this);
|
||||
return TypeProvider::function(*this);
|
||||
}
|
||||
|
||||
FunctionTypePointer EventDefinition::functionType(bool _internal) const
|
||||
{
|
||||
if (_internal)
|
||||
return TypeProvider::functionType(*this);
|
||||
return TypeProvider::function(*this);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
@ -568,7 +568,7 @@ FunctionTypePointer VariableDeclaration::functionType(bool _internal) const
|
||||
return nullptr;
|
||||
case Declaration::Visibility::Public:
|
||||
case Declaration::Visibility::External:
|
||||
return TypeProvider::functionType(*this);
|
||||
return TypeProvider::function(*this);
|
||||
}
|
||||
|
||||
// To make the compiler happy
|
||||
|
@ -24,19 +24,19 @@ using namespace std;
|
||||
using namespace dev;
|
||||
using namespace solidity;
|
||||
|
||||
BoolType const TypeProvider::m_boolType{};
|
||||
InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamicType{};
|
||||
BoolType const TypeProvider::m_boolean{};
|
||||
InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamic{};
|
||||
|
||||
/// 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.
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_bytesStorageType;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_bytesMemoryType;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_stringStorageType;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_stringMemoryType;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_bytesStorage;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_bytesMemory;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_stringStorage;
|
||||
std::unique_ptr<ArrayType> TypeProvider::m_stringMemory;
|
||||
|
||||
TupleType const TypeProvider::m_emptyTupleType{};
|
||||
AddressType const TypeProvider::m_payableAddressType{StateMutability::Payable};
|
||||
AddressType const TypeProvider::m_addressType{StateMutability::NonPayable};
|
||||
TupleType const TypeProvider::m_emptyTuple{};
|
||||
AddressType const TypeProvider::m_payableAddress{StateMutability::Payable};
|
||||
AddressType const TypeProvider::m_address{StateMutability::NonPayable};
|
||||
|
||||
array<unique_ptr<IntegerType>, 32> const TypeProvider::m_intM{{
|
||||
{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)}
|
||||
}};
|
||||
|
||||
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::Message)},
|
||||
{make_unique<MagicType>(MagicType::Kind::Transaction)},
|
||||
@ -173,19 +173,19 @@ inline void clearCaches(Container& container)
|
||||
|
||||
void TypeProvider::reset()
|
||||
{
|
||||
clearCache(m_boolType);
|
||||
clearCache(m_inaccessibleDynamicType);
|
||||
clearCache(m_bytesStorageType);
|
||||
clearCache(m_bytesMemoryType);
|
||||
clearCache(m_stringStorageType);
|
||||
clearCache(m_stringMemoryType);
|
||||
clearCache(m_emptyTupleType);
|
||||
clearCache(m_payableAddressType);
|
||||
clearCache(m_addressType);
|
||||
clearCache(m_boolean);
|
||||
clearCache(m_inaccessibleDynamic);
|
||||
clearCache(m_bytesStorage);
|
||||
clearCache(m_bytesMemory);
|
||||
clearCache(m_stringStorage);
|
||||
clearCache(m_stringMemory);
|
||||
clearCache(m_emptyTuple);
|
||||
clearCache(m_payableAddress);
|
||||
clearCache(m_address);
|
||||
clearCaches(instance().m_intM);
|
||||
clearCaches(instance().m_uintM);
|
||||
clearCaches(instance().m_bytesM);
|
||||
clearCaches(instance().m_magicTypes);
|
||||
clearCaches(instance().m_magics);
|
||||
|
||||
instance().m_generalTypes.clear();
|
||||
instance().m_stringLiteralTypes.clear();
|
||||
@ -213,33 +213,33 @@ Type const* TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken const&
|
||||
switch (_type.token())
|
||||
{
|
||||
case Token::IntM:
|
||||
return integerType(m, IntegerType::Modifier::Signed);
|
||||
return integer(m, IntegerType::Modifier::Signed);
|
||||
case Token::UIntM:
|
||||
return integerType(m, IntegerType::Modifier::Unsigned);
|
||||
return integer(m, IntegerType::Modifier::Unsigned);
|
||||
case Token::Byte:
|
||||
return byteType();
|
||||
return byte();
|
||||
case Token::BytesM:
|
||||
return fixedBytesType(m);
|
||||
return fixedBytes(m);
|
||||
case Token::FixedMxN:
|
||||
return fixedPointType(m, n, FixedPointType::Modifier::Signed);
|
||||
return fixedPoint(m, n, FixedPointType::Modifier::Signed);
|
||||
case Token::UFixedMxN:
|
||||
return fixedPointType(m, n, FixedPointType::Modifier::Unsigned);
|
||||
return fixedPoint(m, n, FixedPointType::Modifier::Unsigned);
|
||||
case Token::Int:
|
||||
return integerType(256, IntegerType::Modifier::Signed);
|
||||
return integer(256, IntegerType::Modifier::Signed);
|
||||
case Token::UInt:
|
||||
return integerType(256, IntegerType::Modifier::Unsigned);
|
||||
return integer(256, IntegerType::Modifier::Unsigned);
|
||||
case Token::Fixed:
|
||||
return fixedPointType(128, 18, FixedPointType::Modifier::Signed);
|
||||
return fixedPoint(128, 18, FixedPointType::Modifier::Signed);
|
||||
case Token::UFixed:
|
||||
return fixedPointType(128, 18, FixedPointType::Modifier::Unsigned);
|
||||
return fixedPoint(128, 18, FixedPointType::Modifier::Unsigned);
|
||||
case Token::Address:
|
||||
return addressType();
|
||||
return address();
|
||||
case Token::Bool:
|
||||
return boolType();
|
||||
return boolean();
|
||||
case Token::Bytes:
|
||||
return bytesStorageType();
|
||||
return bytesStorage();
|
||||
case Token::String:
|
||||
return stringStorageType();
|
||||
return stringStorage();
|
||||
default:
|
||||
solAssert(
|
||||
false,
|
||||
@ -280,11 +280,11 @@ TypePointer TypeProvider::fromElementaryTypeName(string const& _name)
|
||||
if (nameParts.size() == 2)
|
||||
{
|
||||
if (nameParts[1] == "payable")
|
||||
return payableAddressType();
|
||||
return payableAddress();
|
||||
else
|
||||
solAssert(false, "Invalid state mutability for address type: " + nameParts[1]);
|
||||
}
|
||||
return addressType();
|
||||
return address();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -293,32 +293,32 @@ TypePointer TypeProvider::fromElementaryTypeName(string const& _name)
|
||||
}
|
||||
}
|
||||
|
||||
ArrayType const* TypeProvider::bytesStorageType()
|
||||
ArrayType const* TypeProvider::bytesStorage()
|
||||
{
|
||||
if (!m_bytesStorageType)
|
||||
m_bytesStorageType = make_unique<ArrayType>(DataLocation::Storage, false);
|
||||
return m_bytesStorageType.get();
|
||||
if (!m_bytesStorage)
|
||||
m_bytesStorage = make_unique<ArrayType>(DataLocation::Storage, false);
|
||||
return m_bytesStorage.get();
|
||||
}
|
||||
|
||||
ArrayType const* TypeProvider::bytesMemoryType()
|
||||
ArrayType const* TypeProvider::bytesMemory()
|
||||
{
|
||||
if (!m_bytesMemoryType)
|
||||
m_bytesMemoryType = make_unique<ArrayType>(DataLocation::Memory, false);
|
||||
return m_bytesMemoryType.get();
|
||||
if (!m_bytesMemory)
|
||||
m_bytesMemory = make_unique<ArrayType>(DataLocation::Memory, false);
|
||||
return m_bytesMemory.get();
|
||||
}
|
||||
|
||||
ArrayType const* TypeProvider::stringStorageType()
|
||||
ArrayType const* TypeProvider::stringStorage()
|
||||
{
|
||||
if (!m_stringStorageType)
|
||||
m_stringStorageType = make_unique<ArrayType>(DataLocation::Storage, true);
|
||||
return m_stringStorageType.get();
|
||||
if (!m_stringStorage)
|
||||
m_stringStorage = make_unique<ArrayType>(DataLocation::Storage, true);
|
||||
return m_stringStorage.get();
|
||||
}
|
||||
|
||||
ArrayType const* TypeProvider::stringMemoryType()
|
||||
ArrayType const* TypeProvider::stringMemory()
|
||||
{
|
||||
if (!m_stringMemoryType)
|
||||
m_stringMemoryType = make_unique<ArrayType>(DataLocation::Memory, true);
|
||||
return m_stringMemoryType.get();
|
||||
if (!m_stringMemory)
|
||||
m_stringMemory = make_unique<ArrayType>(DataLocation::Memory, true);
|
||||
return m_stringMemory.get();
|
||||
}
|
||||
|
||||
TypePointer TypeProvider::forLiteral(Literal const& _literal)
|
||||
@ -327,17 +327,17 @@ TypePointer TypeProvider::forLiteral(Literal const& _literal)
|
||||
{
|
||||
case Token::TrueLiteral:
|
||||
case Token::FalseLiteral:
|
||||
return boolType();
|
||||
return boolean();
|
||||
case Token::Number:
|
||||
return rationalNumberType(_literal);
|
||||
return rationalNumber(_literal);
|
||||
case Token::StringLiteral:
|
||||
return stringLiteralType(_literal.value());
|
||||
return stringLiteral(_literal.value());
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RationalNumberType const* TypeProvider::rationalNumberType(Literal const& _literal)
|
||||
RationalNumberType const* TypeProvider::rationalNumber(Literal const& _literal)
|
||||
{
|
||||
solAssert(_literal.token() == Token::Number, "");
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
StringLiteralType const* TypeProvider::stringLiteralType(string const& literal)
|
||||
StringLiteralType const* TypeProvider::stringLiteral(string const& literal)
|
||||
{
|
||||
auto i = instance().m_stringLiteralTypes.find(literal);
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -379,10 +379,10 @@ FixedPointType const* TypeProvider::fixedPointType(unsigned m, unsigned n, Fixed
|
||||
).first->second.get();
|
||||
}
|
||||
|
||||
TupleType const* TypeProvider::tupleType(vector<Type const*> members)
|
||||
TupleType const* TypeProvider::tuple(vector<Type const*> members)
|
||||
{
|
||||
if (members.empty())
|
||||
return &m_emptyTupleType;
|
||||
return &m_emptyTuple;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
FunctionType const* TypeProvider::functionType(FunctionDefinition const& _function, bool _isInternal)
|
||||
FunctionType const* TypeProvider::function(FunctionDefinition const& _function, bool _isInternal)
|
||||
{
|
||||
return createAndGet<FunctionType>(_function, _isInternal);
|
||||
}
|
||||
|
||||
FunctionType const* TypeProvider::functionType(VariableDeclaration const& _varDecl)
|
||||
FunctionType const* TypeProvider::function(VariableDeclaration const& _varDecl)
|
||||
{
|
||||
return createAndGet<FunctionType>(_varDecl);
|
||||
}
|
||||
|
||||
FunctionType const* TypeProvider::functionType(EventDefinition const& _def)
|
||||
FunctionType const* TypeProvider::function(EventDefinition const& _def)
|
||||
{
|
||||
return createAndGet<FunctionType>(_def);
|
||||
}
|
||||
|
||||
FunctionType const* TypeProvider::functionType(FunctionTypeName const& _typeName)
|
||||
FunctionType const* TypeProvider::function(FunctionTypeName const& _typeName)
|
||||
{
|
||||
return createAndGet<FunctionType>(_typeName);
|
||||
}
|
||||
|
||||
FunctionType const* TypeProvider::functionType(
|
||||
FunctionType const* TypeProvider::function(
|
||||
strings const& _parameterTypes,
|
||||
strings const& _returnParameterTypes,
|
||||
FunctionType::Kind _kind,
|
||||
@ -430,7 +430,7 @@ FunctionType const* TypeProvider::functionType(
|
||||
);
|
||||
}
|
||||
|
||||
FunctionType const* TypeProvider::functionType(
|
||||
FunctionType const* TypeProvider::function(
|
||||
TypePointers const& _parameterTypes,
|
||||
TypePointers const& _returnParameterTypes,
|
||||
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);
|
||||
}
|
||||
|
||||
ArrayType const* TypeProvider::arrayType(DataLocation _location, bool _isString)
|
||||
ArrayType const* TypeProvider::array(DataLocation _location, bool _isString)
|
||||
{
|
||||
if (_isString)
|
||||
{
|
||||
if (_location == DataLocation::Storage)
|
||||
return stringStorageType();
|
||||
return stringStorage();
|
||||
if (_location == DataLocation::Memory)
|
||||
return stringMemoryType();
|
||||
return stringMemory();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_location == DataLocation::Storage)
|
||||
return bytesStorageType();
|
||||
return bytesStorage();
|
||||
if (_location == DataLocation::Memory)
|
||||
return bytesMemoryType();
|
||||
return bytesMemory();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ContractType const* TypeProvider::contractType(ContractDefinition const& _contractDef, bool _isSuper)
|
||||
ContractType const* TypeProvider::contract(ContractDefinition const& _contractDef, bool _isSuper)
|
||||
{
|
||||
return createAndGet<ContractType>(_contractDef, _isSuper);
|
||||
}
|
||||
@ -503,7 +503,7 @@ EnumType const* TypeProvider::enumType(EnumDefinition const& _enumDef)
|
||||
return createAndGet<EnumType>(_enumDef);
|
||||
}
|
||||
|
||||
ModuleType const* TypeProvider::moduleType(SourceUnit const& _source)
|
||||
ModuleType const* TypeProvider::module(SourceUnit const& _source)
|
||||
{
|
||||
return createAndGet<ModuleType>(_source);
|
||||
}
|
||||
@ -518,24 +518,24 @@ StructType const* TypeProvider::structType(StructDefinition const& _struct, Data
|
||||
return createAndGet<StructType>(_struct, _location);
|
||||
}
|
||||
|
||||
ModifierType const* TypeProvider::modifierType(ModifierDefinition const& _def)
|
||||
ModifierType const* TypeProvider::modifier(ModifierDefinition const& _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");
|
||||
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.");
|
||||
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);
|
||||
}
|
||||
|
@ -61,29 +61,29 @@ public:
|
||||
static TypePointer fromElementaryTypeName(std::string const& _name);
|
||||
|
||||
/// @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* fixedBytesType(unsigned m) { return m_bytesM.at(m - 1).get(); }
|
||||
static FixedBytesType const* byte() { return fixedBytes(1); }
|
||||
static FixedBytesType const* fixedBytes(unsigned m) { return m_bytesM.at(m - 1).get(); }
|
||||
|
||||
static ArrayType const* bytesStorageType();
|
||||
static ArrayType const* bytesMemoryType();
|
||||
static ArrayType const* stringStorageType();
|
||||
static ArrayType const* stringMemoryType();
|
||||
static ArrayType const* bytesStorage();
|
||||
static ArrayType const* bytesMemory();
|
||||
static ArrayType const* stringStorage();
|
||||
static ArrayType const* stringMemory();
|
||||
|
||||
/// 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[]")
|
||||
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]")
|
||||
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* addressType() noexcept { return &m_addressType; }
|
||||
static AddressType const* payableAddress() noexcept { return &m_payableAddress; }
|
||||
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, "");
|
||||
if (_modifier == IntegerType::Modifier::Unsigned)
|
||||
@ -91,19 +91,19 @@ public:
|
||||
else
|
||||
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 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.
|
||||
/// @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);
|
||||
|
||||
@ -119,19 +119,19 @@ public:
|
||||
}
|
||||
|
||||
/// @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.
|
||||
static FunctionType const* functionType(VariableDeclaration const& _varDecl);
|
||||
static FunctionType const* function(VariableDeclaration const& _varDecl);
|
||||
|
||||
/// @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.
|
||||
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).
|
||||
static FunctionType const* functionType(
|
||||
static FunctionType const* function(
|
||||
strings const& _parameterTypes,
|
||||
strings const& _returnParameterTypes,
|
||||
FunctionType::Kind _kind = FunctionType::Kind::Internal,
|
||||
@ -140,7 +140,7 @@ public:
|
||||
);
|
||||
|
||||
/// @returns a highly customized FunctionType, use with care.
|
||||
static FunctionType const* functionType(
|
||||
static FunctionType const* function(
|
||||
TypePointers const& _parameterTypes,
|
||||
TypePointers const& _returnParameterTypes,
|
||||
strings _parameterNames = strings{},
|
||||
@ -157,34 +157,34 @@ public:
|
||||
/// Auto-detect the proper type for a literal. @returns an empty pointer if the literal does
|
||||
/// not fit any type.
|
||||
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,
|
||||
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.
|
||||
static EnumType const* enumType(EnumDefinition const& _enum);
|
||||
|
||||
/// @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 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:
|
||||
/// Global TypeProvider instance.
|
||||
@ -197,22 +197,22 @@ private:
|
||||
template <typename T, typename... Args>
|
||||
static inline T const* createAndGet(Args&& ... _args);
|
||||
|
||||
static BoolType const m_boolType;
|
||||
static InaccessibleDynamicType const m_inaccessibleDynamicType;
|
||||
static BoolType const m_boolean;
|
||||
static InaccessibleDynamicType const m_inaccessibleDynamic;
|
||||
|
||||
/// These are lazy-initialized because they depend on `byte` being available.
|
||||
static std::unique_ptr<ArrayType> m_bytesStorageType;
|
||||
static std::unique_ptr<ArrayType> m_bytesMemoryType;
|
||||
static std::unique_ptr<ArrayType> m_stringStorageType;
|
||||
static std::unique_ptr<ArrayType> m_stringMemoryType;
|
||||
static std::unique_ptr<ArrayType> m_bytesStorage;
|
||||
static std::unique_ptr<ArrayType> m_bytesMemory;
|
||||
static std::unique_ptr<ArrayType> m_stringStorage;
|
||||
static std::unique_ptr<ArrayType> m_stringMemory;
|
||||
|
||||
static TupleType const m_emptyTupleType;
|
||||
static AddressType const m_payableAddressType;
|
||||
static AddressType const m_addressType;
|
||||
static TupleType const m_emptyTuple;
|
||||
static AddressType const m_payableAddress;
|
||||
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_uintM;
|
||||
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_fixedMxN{};
|
||||
|
@ -142,7 +142,7 @@ BoolResult fitsIntegerType(bigint const& _value, IntegerType const& _type)
|
||||
/// if _signed is true.
|
||||
bool fitsIntoBits(bigint const& _value, unsigned _bits, bool _signed)
|
||||
{
|
||||
return fitsIntegerType(_value, *TypeProvider::integerType(
|
||||
return fitsIntegerType(_value, *TypeProvider::integer(
|
||||
_bits,
|
||||
_signed ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned
|
||||
));
|
||||
@ -426,7 +426,7 @@ u256 AddressType::literalValue(Literal const* _literal) 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 = {
|
||||
{"balance", TypeProvider::uint256()},
|
||||
{"call", TypeProvider::functionType(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)},
|
||||
{"delegatecall", TypeProvider::functionType(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)}
|
||||
{"call", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCall, false, StateMutability::Payable)},
|
||||
{"callcode", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareCallCode, false, StateMutability::Payable)},
|
||||
{"delegatecall", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareDelegateCall, false, StateMutability::NonPayable)},
|
||||
{"staticcall", TypeProvider::function(strings{"bytes memory"}, strings{"bool", "bytes memory"}, FunctionType::Kind::BareStaticCall, false, StateMutability::View)}
|
||||
};
|
||||
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{"transfer", TypeProvider::functionType(strings{"uint"}, strings(), FunctionType::Kind::Transfer, 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::function(strings{"uint"}, strings(), FunctionType::Kind::Transfer, false, StateMutability::NonPayable)});
|
||||
}
|
||||
return members;
|
||||
}
|
||||
@ -530,7 +530,7 @@ TypeResult IntegerType::unaryOperatorResult(Token _operator) const
|
||||
{
|
||||
// "delete" is ok for all integer types
|
||||
if (_operator == Token::Delete)
|
||||
return TypeResult{TypeProvider::emptyTupleType()};
|
||||
return TypeResult{TypeProvider::emptyTuple()};
|
||||
// we allow -, ++ and --
|
||||
else if (_operator == Token::Sub || _operator == Token::Inc ||
|
||||
_operator == Token::Dec || _operator == Token::BitNot)
|
||||
@ -647,7 +647,7 @@ TypeResult FixedPointType::unaryOperatorResult(Token _operator) const
|
||||
{
|
||||
case Token::Delete:
|
||||
// "delete" is ok for all fixed types
|
||||
return TypeResult{TypeProvider::emptyTupleType()};
|
||||
return TypeResult{TypeProvider::emptyTuple()};
|
||||
case Token::Add:
|
||||
case Token::Sub:
|
||||
case Token::Inc:
|
||||
@ -707,7 +707,7 @@ TypeResult FixedPointType::binaryOperatorResult(Token _operator, Type const* _ot
|
||||
|
||||
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)
|
||||
@ -923,7 +923,7 @@ TypeResult RationalNumberType::unaryOperatorResult(Token _operator) const
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return TypeResult{TypeProvider::rationalNumberType(value)};
|
||||
return TypeResult{TypeProvider::rationalNumber(value)};
|
||||
}
|
||||
|
||||
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)
|
||||
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))
|
||||
return nullptr;
|
||||
else
|
||||
return TypeProvider::integerType(
|
||||
return TypeProvider::integer(
|
||||
max(bytesRequired(value), 1u) * 8,
|
||||
negative ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned
|
||||
);
|
||||
@ -1237,7 +1237,7 @@ FixedPointType const* RationalNumberType::fixedPointType() const
|
||||
unsigned totalBits = max(bytesRequired(v), 1u) * 8;
|
||||
solAssert(totalBits <= 256, "");
|
||||
|
||||
return TypeProvider::fixedPointType(
|
||||
return TypeProvider::fixedPoint(
|
||||
totalBits, fractionalDigits,
|
||||
negative ? FixedPointType::Modifier::Signed : FixedPointType::Modifier::Unsigned
|
||||
);
|
||||
@ -1292,7 +1292,7 @@ std::string StringLiteralType::toString(bool) const
|
||||
|
||||
TypePointer StringLiteralType::mobileType() const
|
||||
{
|
||||
return TypeProvider::stringMemoryType();
|
||||
return TypeProvider::stringMemory();
|
||||
}
|
||||
|
||||
bool StringLiteralType::isValidUTF8() const
|
||||
@ -1328,7 +1328,7 @@ TypeResult FixedBytesType::unaryOperatorResult(Token _operator) const
|
||||
{
|
||||
// "delete" and "~" is okay for FixedBytesType
|
||||
if (_operator == Token::Delete)
|
||||
return TypeResult{TypeProvider::emptyTupleType()};
|
||||
return TypeResult{TypeProvider::emptyTuple()};
|
||||
else if (_operator == Token::BitNot)
|
||||
return this;
|
||||
|
||||
@ -1388,7 +1388,7 @@ u256 BoolType::literalValue(Literal const* _literal) const
|
||||
TypeResult BoolType::unaryOperatorResult(Token _operator) const
|
||||
{
|
||||
if (_operator == Token::Delete)
|
||||
return TypeProvider::emptyTupleType();
|
||||
return TypeProvider::emptyTuple();
|
||||
else if (_operator == Token::Not)
|
||||
return this;
|
||||
else
|
||||
@ -1411,9 +1411,9 @@ Type const* ContractType::encodingType() const
|
||||
return nullptr;
|
||||
|
||||
if (isPayable())
|
||||
return TypeProvider::payableAddressType();
|
||||
return TypeProvider::payableAddress();
|
||||
else
|
||||
return TypeProvider::addressType();
|
||||
return TypeProvider::address();
|
||||
}
|
||||
|
||||
BoolResult ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
@ -1451,7 +1451,7 @@ TypeResult ContractType::unaryOperatorResult(Token _operator) const
|
||||
if (isSuper())
|
||||
return nullptr;
|
||||
else if (_operator == Token::Delete)
|
||||
return TypeProvider::emptyTupleType();
|
||||
return TypeProvider::emptyTuple();
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
@ -1472,9 +1472,9 @@ TypeResult ReferenceType::unaryOperatorResult(Token _operator) const
|
||||
case DataLocation::CallData:
|
||||
return nullptr;
|
||||
case DataLocation::Memory:
|
||||
return TypeProvider::emptyTupleType();
|
||||
return TypeProvider::emptyTuple();
|
||||
case DataLocation::Storage:
|
||||
return m_isPointer ? nullptr : TypeProvider::emptyTupleType();
|
||||
return m_isPointer ? nullptr : TypeProvider::emptyTuple();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -1522,7 +1522,7 @@ string ReferenceType::identifierLocationSuffix() const
|
||||
ArrayType::ArrayType(DataLocation _location, bool _isString):
|
||||
ReferenceType(_location),
|
||||
m_arrayKind(_isString ? ArrayKind::String : ArrayKind::Bytes),
|
||||
m_baseType{TypeProvider::byteType()}
|
||||
m_baseType{TypeProvider::byte()}
|
||||
{
|
||||
}
|
||||
|
||||
@ -1749,14 +1749,14 @@ MemberList::MemberMap ArrayType::nativeMembers(ContractDefinition const*) const
|
||||
members.emplace_back("length", TypeProvider::uint256());
|
||||
if (isDynamicallySized() && location() == DataLocation::Storage)
|
||||
{
|
||||
members.emplace_back("push", TypeProvider::functionType(
|
||||
members.emplace_back("push", TypeProvider::function(
|
||||
TypePointers{baseType()},
|
||||
TypePointers{TypeProvider::uint256()},
|
||||
strings{string()},
|
||||
strings{string()},
|
||||
isByteArray() ? FunctionType::Kind::ByteArrayPush : FunctionType::Kind::ArrayPush
|
||||
));
|
||||
members.emplace_back("pop", TypeProvider::functionType(
|
||||
members.emplace_back("pop", TypeProvider::function(
|
||||
TypePointers{},
|
||||
TypePointers{},
|
||||
strings{},
|
||||
@ -1805,9 +1805,9 @@ TypeResult ArrayType::interfaceType(bool _inLibrary) const
|
||||
else if (m_arrayKind != ArrayKind::Ordinary)
|
||||
result = TypeProvider::withLocation(this, DataLocation::Memory, true);
|
||||
else if (isDynamicallySized())
|
||||
result = TypeProvider::arrayType(DataLocation::Memory, baseInterfaceType);
|
||||
result = TypeProvider::array(DataLocation::Memory, baseInterfaceType);
|
||||
else
|
||||
result = TypeProvider::arrayType(DataLocation::Memory, baseInterfaceType, m_length);
|
||||
result = TypeProvider::array(DataLocation::Memory, baseInterfaceType, m_length);
|
||||
|
||||
if (_inLibrary)
|
||||
m_interfaceType_library = result;
|
||||
@ -1879,7 +1879,7 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const* _con
|
||||
if (!function->isVisibleInDerivedContracts() || !function->isImplemented())
|
||||
continue;
|
||||
|
||||
auto functionType = TypeProvider::functionType(*function, true);
|
||||
auto functionType = TypeProvider::function(*function, true);
|
||||
bool functionWithEqualArgumentsFound = false;
|
||||
for (auto const& member: members)
|
||||
{
|
||||
@ -2197,7 +2197,7 @@ FunctionTypePointer StructType::constructorType() const
|
||||
paramNames.push_back(member.name);
|
||||
paramTypes.push_back(TypeProvider::withLocationIfReference(DataLocation::Memory, member.type));
|
||||
}
|
||||
return TypeProvider::functionType(
|
||||
return TypeProvider::function(
|
||||
paramTypes,
|
||||
TypePointers{TypeProvider::withLocation(this, DataLocation::Memory, false)},
|
||||
paramNames,
|
||||
@ -2250,7 +2250,7 @@ TypePointer EnumType::encodingType() 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
|
||||
@ -2379,7 +2379,7 @@ TypePointer TupleType::mobileType() const
|
||||
else
|
||||
mobiles.push_back(nullptr);
|
||||
}
|
||||
return TypeProvider::tupleType(move(mobiles));
|
||||
return TypeProvider::tuple(move(mobiles));
|
||||
}
|
||||
|
||||
TypePointer TupleType::closestTemporaryType(Type const* _targetType) const
|
||||
@ -2396,7 +2396,7 @@ TypePointer TupleType::closestTemporaryType(Type const* _targetType) const
|
||||
solAssert(tempComponents[i], "");
|
||||
}
|
||||
}
|
||||
return TypeProvider::tupleType(move(tempComponents));
|
||||
return TypeProvider::tuple(move(tempComponents));
|
||||
}
|
||||
|
||||
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
|
||||
@ -2574,9 +2574,9 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
|
||||
stateMutability = StateMutability::Payable;
|
||||
}
|
||||
|
||||
return TypeProvider::functionType(
|
||||
return TypeProvider::function(
|
||||
parameters,
|
||||
TypePointers{TypeProvider::contractType(_contract)},
|
||||
TypePointers{TypeProvider::contract(_contract)},
|
||||
parameterNames,
|
||||
strings{""},
|
||||
Kind::Creation,
|
||||
@ -2606,7 +2606,7 @@ TypePointers FunctionType::returnParameterTypesWithoutDynamicTypes() const
|
||||
)
|
||||
for (auto& param: returnParameterTypes)
|
||||
if (param->isDynamicallySized() && !param->dataStoredIn(DataLocation::Storage))
|
||||
param = TypeProvider::inaccessibleDynamicType();
|
||||
param = TypeProvider::inaccessibleDynamic();
|
||||
|
||||
return returnParameterTypes;
|
||||
}
|
||||
@ -2689,7 +2689,7 @@ bool FunctionType::operator==(Type const& _other) 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 _convertTo.category() == category();
|
||||
}
|
||||
@ -2722,7 +2722,7 @@ BoolResult FunctionType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
TypeResult FunctionType::unaryOperatorResult(Token _operator) const
|
||||
{
|
||||
if (_operator == Token::Delete)
|
||||
return TypeResult(TypeProvider::emptyTupleType());
|
||||
return TypeResult(TypeProvider::emptyTuple());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -2863,7 +2863,7 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
|
||||
if (variable && retParamTypes.empty())
|
||||
return FunctionTypePointer();
|
||||
|
||||
return TypeProvider::functionType(
|
||||
return TypeProvider::function(
|
||||
paramTypes,
|
||||
retParamTypes,
|
||||
m_parameterNames,
|
||||
@ -2888,13 +2888,13 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
|
||||
{
|
||||
MemberList::MemberMap members;
|
||||
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 (isPayable())
|
||||
members.emplace_back(
|
||||
"value",
|
||||
TypeProvider::functionType(
|
||||
TypeProvider::function(
|
||||
parseElementaryTypeVector({"uint"}),
|
||||
TypePointers{copyAndSetGasOrValue(false, true)},
|
||||
strings(1, ""),
|
||||
@ -2911,7 +2911,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
|
||||
if (m_kind != Kind::Creation)
|
||||
members.emplace_back(
|
||||
"gas",
|
||||
TypeProvider::functionType(
|
||||
TypeProvider::function(
|
||||
parseElementaryTypeVector({"uint"}),
|
||||
TypePointers{copyAndSetGasOrValue(true, false)},
|
||||
strings(1, ""),
|
||||
@ -3125,7 +3125,7 @@ TypePointers FunctionType::parseElementaryTypeVector(strings const& _types)
|
||||
|
||||
TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) const
|
||||
{
|
||||
return TypeProvider::functionType(
|
||||
return TypeProvider::function(
|
||||
m_parameterTypes,
|
||||
m_returnParameterTypes,
|
||||
m_parameterNames,
|
||||
@ -3165,7 +3165,7 @@ FunctionTypePointer FunctionType::asCallableFunction(bool _inLibrary, bool _boun
|
||||
kind = Kind::DelegateCall;
|
||||
}
|
||||
|
||||
return TypeProvider::functionType(
|
||||
return TypeProvider::function(
|
||||
parameterTypes,
|
||||
m_returnParameterTypes,
|
||||
m_parameterNames,
|
||||
@ -3218,7 +3218,7 @@ bool FunctionType::padArguments() const
|
||||
|
||||
Type const* MappingType::encodingType() const
|
||||
{
|
||||
return TypeProvider::integerType(256, IntegerType::Modifier::Unsigned);
|
||||
return TypeProvider::integer(256, IntegerType::Modifier::Unsigned);
|
||||
}
|
||||
|
||||
string MappingType::richIdentifier() const
|
||||
@ -3441,65 +3441,65 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
|
||||
{
|
||||
case Kind::Block:
|
||||
return MemberList::MemberMap({
|
||||
{"coinbase", TypeProvider::payableAddressType()},
|
||||
{"coinbase", TypeProvider::payableAddress()},
|
||||
{"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()},
|
||||
{"number", TypeProvider::uint256()},
|
||||
{"gaslimit", TypeProvider::uint256()}
|
||||
});
|
||||
case Kind::Message:
|
||||
return MemberList::MemberMap({
|
||||
{"sender", TypeProvider::payableAddressType()},
|
||||
{"sender", TypeProvider::payableAddress()},
|
||||
{"gas", TypeProvider::uint256()},
|
||||
{"value", TypeProvider::uint256()},
|
||||
{"data", TypeProvider::arrayType(DataLocation::CallData)},
|
||||
{"sig", TypeProvider::fixedBytesType(4)}
|
||||
{"data", TypeProvider::array(DataLocation::CallData)},
|
||||
{"sig", TypeProvider::fixedBytes(4)}
|
||||
});
|
||||
case Kind::Transaction:
|
||||
return MemberList::MemberMap({
|
||||
{"origin", TypeProvider::payableAddressType()},
|
||||
{"origin", TypeProvider::payableAddress()},
|
||||
{"gasprice", TypeProvider::uint256()}
|
||||
});
|
||||
case Kind::ABI:
|
||||
return MemberList::MemberMap({
|
||||
{"encode", TypeProvider::functionType(
|
||||
{"encode", TypeProvider::function(
|
||||
TypePointers{},
|
||||
TypePointers{TypeProvider::arrayType(DataLocation::Memory)},
|
||||
TypePointers{TypeProvider::array(DataLocation::Memory)},
|
||||
strings{},
|
||||
strings{1, ""},
|
||||
FunctionType::Kind::ABIEncode,
|
||||
true,
|
||||
StateMutability::Pure
|
||||
)},
|
||||
{"encodePacked", TypeProvider::functionType(
|
||||
{"encodePacked", TypeProvider::function(
|
||||
TypePointers{},
|
||||
TypePointers{TypeProvider::arrayType(DataLocation::Memory)},
|
||||
TypePointers{TypeProvider::array(DataLocation::Memory)},
|
||||
strings{},
|
||||
strings{1, ""},
|
||||
FunctionType::Kind::ABIEncodePacked,
|
||||
true,
|
||||
StateMutability::Pure
|
||||
)},
|
||||
{"encodeWithSelector", TypeProvider::functionType(
|
||||
TypePointers{TypeProvider::fixedBytesType(4)},
|
||||
TypePointers{TypeProvider::arrayType(DataLocation::Memory)},
|
||||
{"encodeWithSelector", TypeProvider::function(
|
||||
TypePointers{TypeProvider::fixedBytes(4)},
|
||||
TypePointers{TypeProvider::array(DataLocation::Memory)},
|
||||
strings{1, ""},
|
||||
strings{1, ""},
|
||||
FunctionType::Kind::ABIEncodeWithSelector,
|
||||
true,
|
||||
StateMutability::Pure
|
||||
)},
|
||||
{"encodeWithSignature", TypeProvider::functionType(
|
||||
TypePointers{TypeProvider::arrayType(DataLocation::Memory, true)},
|
||||
TypePointers{TypeProvider::arrayType(DataLocation::Memory)},
|
||||
{"encodeWithSignature", TypeProvider::function(
|
||||
TypePointers{TypeProvider::array(DataLocation::Memory, true)},
|
||||
TypePointers{TypeProvider::array(DataLocation::Memory)},
|
||||
strings{1, ""},
|
||||
strings{1, ""},
|
||||
FunctionType::Kind::ABIEncodeWithSignature,
|
||||
true,
|
||||
StateMutability::Pure
|
||||
)},
|
||||
{"decode", TypeProvider::functionType(
|
||||
{"decode", TypeProvider::function(
|
||||
TypePointers(),
|
||||
TypePointers(),
|
||||
strings{},
|
||||
@ -3518,9 +3518,9 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
|
||||
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*m_typeArgument).contractDefinition();
|
||||
if (contract.canBeDeployed())
|
||||
return MemberList::MemberMap({
|
||||
{"creationCode", TypeProvider::arrayType(DataLocation::Memory)},
|
||||
{"runtimeCode", TypeProvider::arrayType(DataLocation::Memory)},
|
||||
{"name", TypeProvider::stringMemoryType()},
|
||||
{"creationCode", TypeProvider::array(DataLocation::Memory)},
|
||||
{"runtimeCode", TypeProvider::array(DataLocation::Memory)},
|
||||
{"name", TypeProvider::stringMemory()},
|
||||
});
|
||||
else
|
||||
return {};
|
||||
@ -3559,5 +3559,5 @@ TypePointer MagicType::typeArgument() const
|
||||
|
||||
TypePointer InaccessibleDynamicType::decodingType() const
|
||||
{
|
||||
return TypeProvider::integerType(256, IntegerType::Modifier::Unsigned);
|
||||
return TypeProvider::integer(256, IntegerType::Modifier::Unsigned);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void CompilerUtils::revertWithStringData(Type const& _argumentType)
|
||||
m_context << Instruction::DUP2 << Instruction::MSTORE;
|
||||
m_context << u256(4) << Instruction::ADD;
|
||||
// Stack: <string data> <mem pos of encoding start>
|
||||
abiEncode({&_argumentType}, {TypeProvider::arrayType(DataLocation::Memory, true)});
|
||||
abiEncode({&_argumentType}, {TypeProvider::array(DataLocation::Memory, true)});
|
||||
toSizeAfterFreeMemoryPointer();
|
||||
m_context << Instruction::REVERT;
|
||||
}
|
||||
|
@ -872,7 +872,7 @@ bool ContractCompiler::visit(Return const& _return)
|
||||
|
||||
TypePointer expectedType;
|
||||
if (expression->annotation().type->category() == Type::Category::Tuple || types.size() != 1)
|
||||
expectedType = TypeProvider::tupleType(move(types));
|
||||
expectedType = TypeProvider::tuple(move(types));
|
||||
else
|
||||
expectedType = types.front();
|
||||
compileExpression(*expression, expectedType);
|
||||
|
@ -732,9 +732,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
arguments.front()->accept(*this);
|
||||
// Optimization: If type is bytes or string, then do not encode,
|
||||
// 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;
|
||||
}
|
||||
else
|
||||
@ -875,8 +875,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
TypePointer paramType = function.parameterTypes()[0];
|
||||
ArrayType const* arrayType =
|
||||
function.kind() == FunctionType::Kind::ArrayPush ?
|
||||
TypeProvider::arrayType(DataLocation::Storage, paramType) :
|
||||
TypeProvider::arrayType(DataLocation::Storage);
|
||||
TypeProvider::array(DataLocation::Storage, paramType) :
|
||||
TypeProvider::array(DataLocation::Storage);
|
||||
|
||||
// stack: ArrayReference
|
||||
arguments[0]->accept(*this);
|
||||
@ -1062,7 +1062,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
{
|
||||
FixedHash<4> hash(dev::keccak256(stringType->value()));
|
||||
m_context << (u256(FixedHash<4>::Arith(hash)) << (256 - 32));
|
||||
dataOnStack = TypeProvider::fixedBytesType(4);
|
||||
dataOnStack = TypeProvider::fixedBytes(4);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1073,7 +1073,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
m_context << Instruction::KECCAK256;
|
||||
// stack: <memory pointer> <hash>
|
||||
|
||||
dataOnStack = TypeProvider::fixedBytesType(32);
|
||||
dataOnStack = TypeProvider::fixedBytes(32);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1115,7 +1115,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
utils().abiDecode(targetTypes, false);
|
||||
else
|
||||
{
|
||||
utils().convertType(*firstArgType, *TypeProvider::bytesMemoryType());
|
||||
utils().convertType(*firstArgType, *TypeProvider::bytesMemory());
|
||||
m_context << Instruction::DUP1 << u256(32) << Instruction::ADD;
|
||||
m_context << Instruction::SWAP1 << Instruction::MLOAD;
|
||||
// stack now: <mem_pos> <length>
|
||||
@ -1289,7 +1289,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
identifier = FunctionType(*function).externalIdentifier();
|
||||
else
|
||||
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;
|
||||
}
|
||||
else
|
||||
@ -1307,7 +1307,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
{
|
||||
utils().convertType(
|
||||
*_memberAccess.expression().annotation().type,
|
||||
*TypeProvider::addressType(),
|
||||
*TypeProvider::address(),
|
||||
true
|
||||
);
|
||||
m_context << Instruction::BALANCE;
|
||||
@ -1324,7 +1324,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
else if ((set<string>{"call", "callcode", "delegatecall", "staticcall"}).count(member))
|
||||
utils().convertType(
|
||||
*_memberAccess.expression().annotation().type,
|
||||
*TypeProvider::addressType(),
|
||||
*TypeProvider::address(),
|
||||
true
|
||||
);
|
||||
else
|
||||
|
@ -419,11 +419,8 @@ void StorageItem::setToZero(SourceLocation const&, bool _removeReference) const
|
||||
}
|
||||
}
|
||||
|
||||
/// Used in StorageByteArrayElement
|
||||
static FixedBytesType byteType(1);
|
||||
|
||||
StorageByteArrayElement::StorageByteArrayElement(CompilerContext& _compilerContext):
|
||||
LValue(_compilerContext, &byteType)
|
||||
LValue(_compilerContext, TypeProvider::byte())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ string YulUtilFunctions::leftAlignFunction(Type const& _type)
|
||||
templ("body", "aligned := value");
|
||||
break;
|
||||
case Type::Category::Contract:
|
||||
templ("body", "aligned := " + leftAlignFunction(*TypeProvider::addressType()) + "(value)");
|
||||
templ("body", "aligned := " + leftAlignFunction(*TypeProvider::address()) + "(value)");
|
||||
break;
|
||||
case Type::Category::Enum:
|
||||
{
|
||||
|
@ -804,7 +804,7 @@ void SMTChecker::endVisit(Literal const& _literal)
|
||||
{
|
||||
if (type.category() == Type::Category::StringLiteral)
|
||||
{
|
||||
auto stringType = TypeProvider::stringMemoryType();
|
||||
auto stringType = TypeProvider::stringMemory();
|
||||
auto stringLit = dynamic_cast<StringLiteralType const*>(_literal.annotation().type);
|
||||
solAssert(stringLit, "");
|
||||
auto result = newSymbolicVariable(*stringType, stringLit->richIdentifier(), *m_interface);
|
||||
|
@ -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);
|
||||
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("blockhash", blockhashFun)});
|
||||
@ -619,7 +619,7 @@ BOOST_AUTO_TEST_CASE(gas_left)
|
||||
)";
|
||||
bytes code = compileFirstExpression(
|
||||
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)});
|
||||
|
@ -40,42 +40,42 @@ BOOST_AUTO_TEST_SUITE(SolidityTypes)
|
||||
|
||||
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)
|
||||
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_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)
|
||||
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_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++)
|
||||
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_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)
|
||||
{
|
||||
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::FixedMxN, i, 0)) == *TypeProvider::fixedPointType(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, 0)) == *TypeProvider::fixedPoint(i, 0, 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_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)
|
||||
{
|
||||
BOOST_CHECK(*TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixedMxN, i, 0)) == *TypeProvider::fixedPointType(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, 0)) == *TypeProvider::fixedPoint(i, 0, 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({
|
||||
{string("first"), TypeProvider::fromElementaryTypeName("uint128")},
|
||||
{string("second"), TypeProvider::mappingType(
|
||||
{string("second"), TypeProvider::mapping(
|
||||
TypeProvider::fromElementaryTypeName("uint8"),
|
||||
TypeProvider::fromElementaryTypeName("uint8")
|
||||
)},
|
||||
{string("third"), TypeProvider::fromElementaryTypeName("uint16")},
|
||||
{string("final"), TypeProvider::mappingType(
|
||||
{string("final"), TypeProvider::mapping(
|
||||
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_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(1), 32).storageSize() == 1);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(1), 33).storageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(2), 31).storageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(7), 8).storageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(7), 9).storageSize() == 3);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(31), 9).storageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytesType(32), 9).storageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(1), 32).storageSize() == 1);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(1), 33).storageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(2), 31).storageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(7), 8).storageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(7), 9).storageSize() == 3);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(31), 9).storageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, TypeProvider::fixedBytes(32), 9).storageSize() == 9);
|
||||
}
|
||||
|
||||
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");
|
||||
ArrayType largeintArray(DataLocation::Memory, TypeProvider::fromElementaryTypeName("int128"), u256("2535301200456458802993406410752"));
|
||||
BOOST_CHECK_EQUAL(largeintArray.identifier(), "t_array$_t_int128_$2535301200456458802993406410752_memory_ptr");
|
||||
TypePointer stringArray = TypeProvider::arrayType(DataLocation::Storage, TypeProvider::fromElementaryTypeName("string"), u256("20"));
|
||||
TypePointer multiArray = TypeProvider::arrayType(DataLocation::Storage, stringArray);
|
||||
TypePointer stringArray = TypeProvider::array(DataLocation::Storage, TypeProvider::fromElementaryTypeName("string"), u256("20"));
|
||||
TypePointer multiArray = TypeProvider::array(DataLocation::Storage, stringArray);
|
||||
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);
|
||||
@ -195,13 +195,13 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
|
||||
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_$__$");
|
||||
|
||||
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$__$");
|
||||
|
||||
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_$_$");
|
||||
|
||||
TypePointer m = TypeProvider::mappingType(TypeProvider::fromElementaryTypeName("bytes32"), s.type());
|
||||
TypePointer m = TypeProvider::mapping(TypeProvider::fromElementaryTypeName("bytes32"), s.type());
|
||||
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_$_$_$");
|
||||
|
||||
@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(encoded_sizes)
|
||||
BOOST_CHECK_EQUAL(BoolType().calldataEncodedSize(true), 32);
|
||||
BOOST_CHECK_EQUAL(BoolType().calldataEncodedSize(false), 1);
|
||||
|
||||
ArrayType const* uint24Array = TypeProvider::arrayType(
|
||||
ArrayType const* uint24Array = TypeProvider::array(
|
||||
DataLocation::Memory,
|
||||
TypeProvider::uint(24),
|
||||
9
|
||||
|
Loading…
Reference in New Issue
Block a user