|
@ -39,6 +39,8 @@ namespace solidity |
|
|
// @todo realMxN, string<N>
|
|
|
// @todo realMxN, string<N>
|
|
|
|
|
|
|
|
|
class Type; // forward
|
|
|
class Type; // forward
|
|
|
|
|
|
using TypePointer = std::shared_ptr<Type const>; |
|
|
|
|
|
using TypePointers = std::vector<TypePointer>; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* List of members of a type. |
|
|
* List of members of a type. |
|
@ -46,7 +48,6 @@ class Type; // forward |
|
|
class MemberList |
|
|
class MemberList |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
using TypePointer = std::shared_ptr<Type const>; |
|
|
|
|
|
using MemberMap = std::map<std::string, TypePointer>; |
|
|
using MemberMap = std::map<std::string, TypePointer>; |
|
|
|
|
|
|
|
|
MemberList() {} |
|
|
MemberList() {} |
|
@ -54,7 +55,7 @@ public: |
|
|
TypePointer getMemberType(std::string const& _name) const |
|
|
TypePointer getMemberType(std::string const& _name) const |
|
|
{ |
|
|
{ |
|
|
auto it = m_memberTypes.find(_name); |
|
|
auto it = m_memberTypes.find(_name); |
|
|
return it != m_memberTypes.end() ? it->second : std::shared_ptr<Type const>(); |
|
|
return it != m_memberTypes.end() ? it->second : TypePointer(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MemberMap::const_iterator begin() const { return m_memberTypes.begin(); } |
|
|
MemberMap::const_iterator begin() const { return m_memberTypes.begin(); } |
|
@ -82,6 +83,7 @@ public: |
|
|
static std::shared_ptr<Type> fromElementaryTypeName(Token::Value _typeToken); |
|
|
static std::shared_ptr<Type> fromElementaryTypeName(Token::Value _typeToken); |
|
|
static std::shared_ptr<Type> fromUserDefinedTypeName(UserDefinedTypeName const& _typeName); |
|
|
static std::shared_ptr<Type> fromUserDefinedTypeName(UserDefinedTypeName const& _typeName); |
|
|
static std::shared_ptr<Type> fromMapping(Mapping const& _typeName); |
|
|
static std::shared_ptr<Type> fromMapping(Mapping const& _typeName); |
|
|
|
|
|
static std::shared_ptr<Type> fromFunction(FunctionDefinition const& _function); |
|
|
/// @}
|
|
|
/// @}
|
|
|
|
|
|
|
|
|
/// Auto-detect the proper type for a literal. @returns an empty pointer if the literal does
|
|
|
/// Auto-detect the proper type for a literal. @returns an empty pointer if the literal does
|
|
@ -117,7 +119,7 @@ public: |
|
|
/// Returns the list of all members of this type. Default implementation: no members.
|
|
|
/// Returns the list of all members of this type. Default implementation: no members.
|
|
|
virtual MemberList const& getMembers() const { return EmptyMemberList; } |
|
|
virtual MemberList const& getMembers() const { return EmptyMemberList; } |
|
|
/// Convenience method, returns the type of the given named member or an empty pointer if no such member exists.
|
|
|
/// Convenience method, returns the type of the given named member or an empty pointer if no such member exists.
|
|
|
std::shared_ptr<Type const> getMemberType(std::string const& _name) const { return getMembers().getMemberType(_name); } |
|
|
TypePointer getMemberType(std::string const& _name) const { return getMembers().getMemberType(_name); } |
|
|
|
|
|
|
|
|
virtual std::string toString() const = 0; |
|
|
virtual std::string toString() const = 0; |
|
|
virtual u256 literalValue(Literal const&) const |
|
|
virtual u256 literalValue(Literal const&) const |
|
@ -246,15 +248,20 @@ private: |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* The type of a function, there is one distinct type per function definition. |
|
|
* The type of a function, identified by its (return) parameter types. |
|
|
|
|
|
* @todo the return parameters should also have names, i.e. return parameters should be a struct |
|
|
|
|
|
* type. |
|
|
*/ |
|
|
*/ |
|
|
class FunctionType: public Type |
|
|
class FunctionType: public Type |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
virtual Category getCategory() const override { return Category::FUNCTION; } |
|
|
virtual Category getCategory() const override { return Category::FUNCTION; } |
|
|
FunctionType(FunctionDefinition const& _function): m_function(_function) {} |
|
|
explicit FunctionType(FunctionDefinition const& _function); |
|
|
|
|
|
FunctionType(TypePointers const& _parameterTypes, TypePointers const& _returnParameterTypes): |
|
|
|
|
|
m_parameterTypes(_parameterTypes), m_returnParameterTypes(_returnParameterTypes) {} |
|
|
|
|
|
|
|
|
FunctionDefinition const& getFunction() const { return m_function; } |
|
|
TypePointers const& getParameterTypes() const { return m_parameterTypes; } |
|
|
|
|
|
TypePointers const& getReturnParameterTypes() const { return m_returnParameterTypes; } |
|
|
|
|
|
|
|
|
virtual bool operator==(Type const& _other) const override; |
|
|
virtual bool operator==(Type const& _other) const override; |
|
|
virtual std::string toString() const override; |
|
|
virtual std::string toString() const override; |
|
@ -263,7 +270,8 @@ public: |
|
|
virtual bool canLiveOutsideStorage() const override { return false; } |
|
|
virtual bool canLiveOutsideStorage() const override { return false; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
FunctionDefinition const& m_function; |
|
|
TypePointers m_parameterTypes; |
|
|
|
|
|
TypePointers m_returnParameterTypes; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -273,19 +281,19 @@ class MappingType: public Type |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
virtual Category getCategory() const override { return Category::MAPPING; } |
|
|
virtual Category getCategory() const override { return Category::MAPPING; } |
|
|
MappingType(std::shared_ptr<Type const> _keyType, std::shared_ptr<Type const> _valueType): |
|
|
MappingType(TypePointer const& _keyType, TypePointer const& _valueType): |
|
|
m_keyType(_keyType), m_valueType(_valueType) {} |
|
|
m_keyType(_keyType), m_valueType(_valueType) {} |
|
|
|
|
|
|
|
|
virtual bool operator==(Type const& _other) const override; |
|
|
virtual bool operator==(Type const& _other) const override; |
|
|
virtual std::string toString() const override; |
|
|
virtual std::string toString() const override; |
|
|
virtual bool canLiveOutsideStorage() const override { return false; } |
|
|
virtual bool canLiveOutsideStorage() const override { return false; } |
|
|
|
|
|
|
|
|
std::shared_ptr<Type const> getKeyType() const { return m_keyType; } |
|
|
TypePointer getKeyType() const { return m_keyType; } |
|
|
std::shared_ptr<Type const> getValueType() const { return m_valueType; } |
|
|
TypePointer getValueType() const { return m_valueType; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
std::shared_ptr<Type const> m_keyType; |
|
|
TypePointer m_keyType; |
|
|
std::shared_ptr<Type const> m_valueType; |
|
|
TypePointer m_valueType; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -312,9 +320,9 @@ class TypeType: public Type |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
virtual Category getCategory() const override { return Category::TYPE; } |
|
|
virtual Category getCategory() const override { return Category::TYPE; } |
|
|
TypeType(std::shared_ptr<Type const> const& _actualType): m_actualType(_actualType) {} |
|
|
TypeType(TypePointer const& _actualType): m_actualType(_actualType) {} |
|
|
|
|
|
|
|
|
std::shared_ptr<Type const> const& getActualType() const { return m_actualType; } |
|
|
TypePointer const& getActualType() const { return m_actualType; } |
|
|
|
|
|
|
|
|
virtual bool operator==(Type const& _other) const override; |
|
|
virtual bool operator==(Type const& _other) const override; |
|
|
virtual bool canBeStored() const override { return false; } |
|
|
virtual bool canBeStored() const override { return false; } |
|
@ -323,7 +331,7 @@ public: |
|
|
virtual std::string toString() const override { return "type(" + m_actualType->toString() + ")"; } |
|
|
virtual std::string toString() const override { return "type(" + m_actualType->toString() + ")"; } |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
std::shared_ptr<Type const> m_actualType; |
|
|
TypePointer m_actualType; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|