[libsolidity] TypeProvider: eliminate redundant "Type" suffix in provider function signatures.

This commit is contained in:
Christian Parpart
2019-04-17 14:42:07 +02:00
parent 862b65d6e3
commit 721bf367a3
17 changed files with 312 additions and 315 deletions
+12 -12
View File
@@ -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
+83 -83
View File
@@ -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);
}
+43 -43
View File
@@ -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{};
+66 -66
View File
@@ -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);
}