diff options
-rw-r--r-- | Token.h | 6 | ||||
-rw-r--r-- | Types.cpp | 11 | ||||
-rw-r--r-- | Types.h | 32 |
3 files changed, 42 insertions, 7 deletions
@@ -176,8 +176,7 @@ namespace solidity K(SubFinney, "finney", 0) \ K(SubEther, "ether", 0) \ /* type keywords, keep them in this order, keep int as first keyword - * the implementation in Types.cpp has to be synced to this here - * TODO more to be added */ \ + * the implementation in Types.cpp has to be synced to this here */\ K(Int, "int", 0) \ K(Int8, "int8", 0) \ K(Int16, "int16", 0) \ @@ -279,7 +278,8 @@ namespace solidity K(Hash256, "hash256", 0) \ K(Address, "address", 0) \ K(Bool, "bool", 0) \ - K(StringType, "string", 0) \ + K(Bytes, "bytes", 0) \ + K(StringType, "string", 0) \ K(String0, "string0", 0) \ K(String1, "string1", 0) \ K(String2, "string2", 0) \ @@ -57,6 +57,8 @@ shared_ptr<Type const> Type::fromElementaryTypeName(Token::Value _typeToken) return make_shared<BoolType>(); else if (Token::String0 <= _typeToken && _typeToken <= Token::String32) return make_shared<StaticStringType>(int(_typeToken) - int(Token::String0)); + else if (_typeToken == Token::Bytes) + return make_shared<ByteArrayType>(ByteArrayType::Location::Storage, 0, 0, true); else BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to convert elementary typename " + std::string(Token::toString(_typeToken)) + " to type.")); @@ -506,6 +508,15 @@ TypePointer ContractType::unaryOperatorResult(Token::Value _operator) const return _operator == Token::Delete ? make_shared<VoidType>() : TypePointer(); } +bool ByteArrayType::operator==(Type const& _other) const +{ + if (_other.getCategory() != getCategory()) + return false; + ByteArrayType const& other = dynamic_cast<ByteArrayType const&>(_other); + return other.m_location == m_location && other.m_dynamicLength == m_dynamicLength + && other.m_length == m_length && other.m_offset == m_offset; +} + bool ContractType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) @@ -76,9 +76,10 @@ class Type: private boost::noncopyable, public std::enable_shared_from_this<Type public: enum class Category { - Integer, IntegerConstant, Bool, Real, - String, Contract, Struct, Function, - Mapping, Void, TypeType, Modifier, Magic + Integer, IntegerConstant, Bool, Real, String, + ByteArray, Mapping, + Contract, Struct, Function, + Void, TypeType, Modifier, Magic }; ///@{ @@ -263,7 +264,7 @@ class BoolType: public Type { public: BoolType() {} - virtual Category getCategory() const { return Category::Bool; } + virtual Category getCategory() const override { return Category::Bool; } virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; virtual TypePointer unaryOperatorResult(Token::Value _operator) const override; virtual TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const override; @@ -276,6 +277,29 @@ public: }; /** + * The type of a byte array, prototype for a general array. + */ +class ByteArrayType: public Type +{ +public: + enum class Location { Storage, CallData, Memory }; + + virtual Category getCategory() const override { return Category::ByteArray; } + ByteArrayType(Location _location, u256 const& _offset, u256 const& _length, bool _dynamicLength): + m_location(_location), m_offset(_offset), m_length(_length), m_dynamicLength(_dynamicLength) {} + virtual bool operator==(const Type& _other) const override; + virtual unsigned getSizeOnStack() const override { return 1; /* TODO */ } + virtual std::string toString() const override { return "bytes"; } + + +private: + Location m_location; + u256 m_offset; + u256 m_length; + bool m_dynamicLength; +}; + +/** * The type of a contract instance, there is one distinct type for each contract definition. */ class ContractType: public Type |