aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/Types.cpp32
-rw-r--r--libsolidity/ast/Types.h44
2 files changed, 41 insertions, 35 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index bf5745a6..97e7a922 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -354,7 +354,7 @@ IntegerType::IntegerType(int _bits, IntegerType::Modifier _modifier):
);
}
-string IntegerType::identifier() const
+string IntegerType::richIdentifier() const
{
if (isAddress())
return "t_address";
@@ -524,7 +524,7 @@ FixedPointType::FixedPointType(int _totalBits, int _fractionalDigits, FixedPoint
);
}
-string FixedPointType::identifier() const
+string FixedPointType::richIdentifier() const
{
return "t_" + string(isSigned() ? "" : "u") + "fixed" + std::to_string(m_totalBits) + "x" + std::to_string(m_fractionalDigits);
}
@@ -956,7 +956,7 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ
}
}
-string RationalNumberType::identifier() const
+string RationalNumberType::richIdentifier() const
{
return "t_rational_" + m_value.numerator().str() + "_by_" + m_value.denominator().str();
}
@@ -1097,7 +1097,7 @@ bool StringLiteralType::isImplicitlyConvertibleTo(Type const& _convertTo) const
return false;
}
-string StringLiteralType::identifier() const
+string StringLiteralType::richIdentifier() const
{
// Since we have to return a valid identifier and the string itself may contain
// anything, we hash it.
@@ -1197,7 +1197,7 @@ MemberList::MemberMap FixedBytesType::nativeMembers(const ContractDefinition*) c
return MemberList::MemberMap{MemberList::Member{"length", make_shared<IntegerType>(8)}};
}
-string FixedBytesType::identifier() const
+string FixedBytesType::richIdentifier() const
{
return "t_bytes" + std::to_string(m_bytes);
}
@@ -1390,7 +1390,7 @@ bool ArrayType::isExplicitlyConvertibleTo(const Type& _convertTo) const
return true;
}
-string ArrayType::identifier() const
+string ArrayType::richIdentifier() const
{
string id;
if (isString())
@@ -1624,7 +1624,7 @@ TypePointer ArrayType::copyForLocation(DataLocation _location, bool _isPointer)
return copy;
}
-string ContractType::identifier() const
+string ContractType::richIdentifier() const
{
return (m_super ? "t_super" : "t_contract") + parenthesizeUserIdentifier(m_contract.name()) + std::to_string(m_contract.id());
}
@@ -1776,7 +1776,7 @@ bool StructType::isImplicitlyConvertibleTo(const Type& _convertTo) const
return this->m_struct == convertTo.m_struct;
}
-string StructType::identifier() const
+string StructType::richIdentifier() const
{
return "t_struct" + parenthesizeUserIdentifier(m_struct.name()) + std::to_string(m_struct.id()) + identifierLocationSuffix();
}
@@ -2008,7 +2008,7 @@ TypePointer EnumType::unaryOperatorResult(Token::Value _operator) const
return _operator == Token::Delete ? make_shared<TupleType>() : TypePointer();
}
-string EnumType::identifier() const
+string EnumType::richIdentifier() const
{
return "t_enum" + parenthesizeUserIdentifier(m_enum.name()) + std::to_string(m_enum.id());
}
@@ -2094,7 +2094,7 @@ bool TupleType::isImplicitlyConvertibleTo(Type const& _other) const
return false;
}
-string TupleType::identifier() const
+string TupleType::richIdentifier() const
{
return "t_tuple" + identifierList(components());
}
@@ -2354,7 +2354,7 @@ TypePointers FunctionType::parameterTypes() const
return TypePointers(m_parameterTypes.cbegin() + 1, m_parameterTypes.cend());
}
-string FunctionType::identifier() const
+string FunctionType::richIdentifier() const
{
string id = "t_function_";
switch (m_kind)
@@ -2847,7 +2847,7 @@ ASTPointer<ASTString> FunctionType::documentation() const
return ASTPointer<ASTString>();
}
-string MappingType::identifier() const
+string MappingType::richIdentifier() const
{
return "t_mapping" + identifierList(m_keyType, m_valueType);
}
@@ -2870,7 +2870,7 @@ string MappingType::canonicalName() const
return "mapping(" + keyType()->canonicalName() + " => " + valueType()->canonicalName() + ")";
}
-string TypeType::identifier() const
+string TypeType::richIdentifier() const
{
return "t_type" + identifierList(actualType());
}
@@ -2955,7 +2955,7 @@ u256 ModifierType::storageSize() const
solAssert(false, "Storage size of non-storable type type requested.");
}
-string ModifierType::identifier() const
+string ModifierType::richIdentifier() const
{
return "t_modifier" + identifierList(m_parameterTypes);
}
@@ -2984,7 +2984,7 @@ string ModifierType::toString(bool _short) const
return name + ")";
}
-string ModuleType::identifier() const
+string ModuleType::richIdentifier() const
{
return "t_module_" + std::to_string(m_sourceUnit.id());
}
@@ -3010,7 +3010,7 @@ string ModuleType::toString(bool) const
return string("module \"") + m_sourceUnit.annotation().path + string("\"");
}
-string MagicType::identifier() const
+string MagicType::richIdentifier() const
{
switch (m_kind)
{
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index ef898f37..a12b7063 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -163,7 +163,13 @@ public:
/// @returns a valid solidity identifier such that two types should compare equal if and
/// only if they have the same identifier.
/// The identifier should start with "t_".
- virtual std::string identifier() const = 0;
+ /// Can contain characters which are invalid in identifiers.
+ virtual std::string richIdentifier() const = 0;
+ /// @returns a valid solidity identifier such that two types should compare equal if and
+ /// only if they have the same identifier.
+ /// The identifier should start with "t_".
+ /// Will not contain any character which would be invalid as an identifier.
+ std::string identifier() const { return escapeIdentifier(richIdentifier()); }
/// More complex identifier strings use "parentheses", where $_ is interpreted as as
/// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that
@@ -312,7 +318,7 @@ public:
explicit IntegerType(int _bits, Modifier _modifier = Modifier::Unsigned);
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
@@ -359,7 +365,7 @@ public:
explicit FixedPointType(int _totalBits, int _fractionalDigits, Modifier _modifier = Modifier::Unsigned);
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
@@ -416,7 +422,7 @@ public:
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
virtual TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual bool canBeStored() const override { return false; }
@@ -465,7 +471,7 @@ public:
return TypePointer();
}
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual bool canBeStored() const override { return false; }
@@ -499,7 +505,7 @@ public:
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
virtual TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const override;
@@ -527,7 +533,7 @@ class BoolType: public Type
public:
BoolType() {}
virtual Category category() const override { return Category::Bool; }
- virtual std::string identifier() const override { return "t_bool"; }
+ virtual std::string richIdentifier() const override { return "t_bool"; }
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
virtual TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const override;
@@ -627,7 +633,7 @@ public:
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(const Type& _other) const override;
virtual unsigned calldataEncodedSize(bool _padded) const override;
virtual bool isDynamicallySized() const override { return m_hasDynamicLength; }
@@ -684,7 +690,7 @@ public:
/// Contracts can be converted to themselves and to integers.
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual unsigned calldataEncodedSize(bool _padded ) const override
{
@@ -742,7 +748,7 @@ public:
explicit StructType(StructDefinition const& _struct, DataLocation _location = DataLocation::Storage):
ReferenceType(_location), m_struct(_struct) {}
virtual bool isImplicitlyConvertibleTo(const Type& _convertTo) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual unsigned calldataEncodedSize(bool _padded) const override;
virtual bool isDynamicallyEncoded() const override;
@@ -797,7 +803,7 @@ public:
virtual Category category() const override { return Category::Enum; }
explicit EnumType(EnumDefinition const& _enum): m_enum(_enum) {}
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual unsigned calldataEncodedSize(bool _padded) const override
{
@@ -838,7 +844,7 @@ public:
virtual Category category() const override { return Category::Tuple; }
explicit TupleType(std::vector<TypePointer> const& _types = std::vector<TypePointer>()): m_components(_types) {}
virtual bool isImplicitlyConvertibleTo(Type const& _other) const override;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual TypePointer binaryOperatorResult(Token::Value, TypePointer const&) const override { return TypePointer(); }
virtual std::string toString(bool) const override;
@@ -972,7 +978,7 @@ public:
/// @returns the "self" parameter type for a bound function
TypePointer const& selfType() const;
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
@@ -1076,7 +1082,7 @@ public:
MappingType(TypePointer const& _keyType, TypePointer const& _valueType):
m_keyType(_keyType), m_valueType(_valueType) {}
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual std::string toString(bool _short) const override;
virtual std::string canonicalName() const override;
@@ -1113,7 +1119,7 @@ public:
TypePointer const& actualType() const { return m_actualType; }
virtual TypePointer binaryOperatorResult(Token::Value, TypePointer const&) const override { return TypePointer(); }
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual bool canBeStored() const override { return false; }
virtual u256 storageSize() const override;
@@ -1141,7 +1147,7 @@ public:
virtual u256 storageSize() const override;
virtual bool canLiveOutsideStorage() const override { return false; }
virtual unsigned sizeOnStack() const override { return 0; }
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual std::string toString(bool _short) const override;
@@ -1162,7 +1168,7 @@ public:
explicit ModuleType(SourceUnit const& _source): m_sourceUnit(_source) {}
virtual TypePointer binaryOperatorResult(Token::Value, TypePointer const&) const override { return TypePointer(); }
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual bool canBeStored() const override { return false; }
virtual bool canLiveOutsideStorage() const override { return true; }
@@ -1192,7 +1198,7 @@ public:
return TypePointer();
}
- virtual std::string identifier() const override;
+ virtual std::string richIdentifier() const override;
virtual bool operator==(Type const& _other) const override;
virtual bool canBeStored() const override { return false; }
virtual bool canLiveOutsideStorage() const override { return true; }
@@ -1216,7 +1222,7 @@ class InaccessibleDynamicType: public Type
public:
virtual Category category() const override { return Category::InaccessibleDynamic; }
- virtual std::string identifier() const override { return "t_inaccessible"; }
+ virtual std::string richIdentifier() const override { return "t_inaccessible"; }
virtual bool isImplicitlyConvertibleTo(Type const&) const override { return false; }
virtual bool isExplicitlyConvertibleTo(Type const&) const override { return false; }
virtual TypePointer binaryOperatorResult(Token::Value, TypePointer const&) const override { return TypePointer(); }