From 5e3208317922d20a5b3b760df872a589d87bf94d Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 20 Feb 2015 15:52:30 +0100 Subject: Parsing of array types and basic implementation. --- Types.h | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'Types.h') diff --git a/Types.h b/Types.h index af64f1cb..b13f3517 100644 --- a/Types.h +++ b/Types.h @@ -36,8 +36,6 @@ namespace dev namespace solidity { -// @todo realMxN, dynamic strings, text, arrays - class Type; // forward class FunctionType; // forward using TypePointer = std::shared_ptr; @@ -78,7 +76,7 @@ class Type: private boost::noncopyable, public std::enable_shared_from_this(8)) {} + /// Constructor for a dynamically sized array type ("type[]") + ArrayType(Location _location, const TypePointer &_baseType): + m_location(_location), m_baseType(_baseType) {} + /// Constructor for a fixed-size array type ("type[20]") + ArrayType(Location _location, const TypePointer &_baseType, u256 const& _length): + m_location(_location), m_baseType(_baseType), m_hasDynamicLength(false), m_length(_length) {} + virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; virtual TypePointer unaryOperatorResult(Token::Value _operator) const override; virtual bool operator==(const Type& _other) const override; - virtual bool isDynamicallySized() const { return true; } + virtual bool isDynamicallySized() const { return m_hasDynamicLength; } virtual unsigned getSizeOnStack() const override; - virtual std::string toString() const override { return "bytes"; } - virtual MemberList const& getMembers() const override { return s_byteArrayMemberList; } + virtual std::string toString() const override; + virtual MemberList const& getMembers() const override { return s_arrayTypeMemberList; } Location getLocation() const { return m_location; } + bool isByteArray() const { return m_isByteArray; } + TypePointer const& getBaseType() const { solAssert(!!m_baseType, ""); return m_baseType;} + u256 const& getLength() const { return m_length; } /// @returns a copy of this type with location changed to @a _location /// @todo this might move as far up as Type later - std::shared_ptr copyForLocation(Location _location) const; + std::shared_ptr copyForLocation(Location _location) const; private: Location m_location; - static const MemberList s_byteArrayMemberList; + bool m_isByteArray = false; ///< Byte arrays ("bytes") have different semantics from ordinary arrays. + TypePointer m_baseType; + bool m_hasDynamicLength = true; + u256 m_length; + static const MemberList s_arrayTypeMemberList; }; /** -- cgit