aboutsummaryrefslogtreecommitdiffstats
path: root/Types.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-25 21:43:23 +0800
committerChristian <c@ethdev.com>2014-11-26 22:35:25 +0800
commita2715c5f34cfa4050ba64b4a1467b9ca5821472b (patch)
tree699b649087db7c9b5c9eb000fb452d404af7c755 /Types.h
parent6e6b85b58a478a7e2bc0f8bee976df97f9861b91 (diff)
downloaddexon-solidity-a2715c5f34cfa4050ba64b4a1467b9ca5821472b.tar.gz
dexon-solidity-a2715c5f34cfa4050ba64b4a1467b9ca5821472b.tar.zst
dexon-solidity-a2715c5f34cfa4050ba64b4a1467b9ca5821472b.zip
More general function types and references.
Diffstat (limited to 'Types.h')
-rw-r--r--Types.h38
1 files changed, 23 insertions, 15 deletions
diff --git a/Types.h b/Types.h
index 2dd4af64..17d9053b 100644
--- a/Types.h
+++ b/Types.h
@@ -39,6 +39,8 @@ namespace solidity
// @todo realMxN, string<N>
class Type; // forward
+using TypePointer = std::shared_ptr<Type const>;
+using TypePointers = std::vector<TypePointer>;
/**
* List of members of a type.
@@ -46,7 +48,6 @@ class Type; // forward
class MemberList
{
public:
- using TypePointer = std::shared_ptr<Type const>;
using MemberMap = std::map<std::string, TypePointer>;
MemberList() {}
@@ -54,7 +55,7 @@ public:
TypePointer getMemberType(std::string const& _name) const
{
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(); }
@@ -82,6 +83,7 @@ public:
static std::shared_ptr<Type> fromElementaryTypeName(Token::Value _typeToken);
static std::shared_ptr<Type> fromUserDefinedTypeName(UserDefinedTypeName 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
@@ -117,7 +119,7 @@ public:
/// Returns the list of all members of this type. Default implementation: no members.
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.
- 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 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
{
public:
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 std::string toString() const override;
@@ -263,7 +270,8 @@ public:
virtual bool canLiveOutsideStorage() const override { return false; }
private:
- FunctionDefinition const& m_function;
+ TypePointers m_parameterTypes;
+ TypePointers m_returnParameterTypes;
};
/**
@@ -273,19 +281,19 @@ class MappingType: public Type
{
public:
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) {}
virtual bool operator==(Type const& _other) const override;
virtual std::string toString() const override;
virtual bool canLiveOutsideStorage() const override { return false; }
- std::shared_ptr<Type const> getKeyType() const { return m_keyType; }
- std::shared_ptr<Type const> getValueType() const { return m_valueType; }
+ TypePointer getKeyType() const { return m_keyType; }
+ TypePointer getValueType() const { return m_valueType; }
private:
- std::shared_ptr<Type const> m_keyType;
- std::shared_ptr<Type const> m_valueType;
+ TypePointer m_keyType;
+ TypePointer m_valueType;
};
/**
@@ -312,9 +320,9 @@ class TypeType: public Type
{
public:
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 canBeStored() const override { return false; }
@@ -323,7 +331,7 @@ public:
virtual std::string toString() const override { return "type(" + m_actualType->toString() + ")"; }
private:
- std::shared_ptr<Type const> m_actualType;
+ TypePointer m_actualType;
};