mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Introduced byte array type.
This commit is contained in:
parent
2119a758b3
commit
1369337808
6
Token.h
6
Token.h
@ -176,8 +176,7 @@ namespace solidity
|
|||||||
K(SubFinney, "finney", 0) \
|
K(SubFinney, "finney", 0) \
|
||||||
K(SubEther, "ether", 0) \
|
K(SubEther, "ether", 0) \
|
||||||
/* type keywords, keep them in this order, keep int as first keyword
|
/* type keywords, keep them in this order, keep int as first keyword
|
||||||
* the implementation in Types.cpp has to be synced to this here
|
* the implementation in Types.cpp has to be synced to this here */\
|
||||||
* TODO more to be added */ \
|
|
||||||
K(Int, "int", 0) \
|
K(Int, "int", 0) \
|
||||||
K(Int8, "int8", 0) \
|
K(Int8, "int8", 0) \
|
||||||
K(Int16, "int16", 0) \
|
K(Int16, "int16", 0) \
|
||||||
@ -279,7 +278,8 @@ namespace solidity
|
|||||||
K(Hash256, "hash256", 0) \
|
K(Hash256, "hash256", 0) \
|
||||||
K(Address, "address", 0) \
|
K(Address, "address", 0) \
|
||||||
K(Bool, "bool", 0) \
|
K(Bool, "bool", 0) \
|
||||||
K(StringType, "string", 0) \
|
K(Bytes, "bytes", 0) \
|
||||||
|
K(StringType, "string", 0) \
|
||||||
K(String0, "string0", 0) \
|
K(String0, "string0", 0) \
|
||||||
K(String1, "string1", 0) \
|
K(String1, "string1", 0) \
|
||||||
K(String2, "string2", 0) \
|
K(String2, "string2", 0) \
|
||||||
|
11
Types.cpp
11
Types.cpp
@ -57,6 +57,8 @@ shared_ptr<Type const> Type::fromElementaryTypeName(Token::Value _typeToken)
|
|||||||
return make_shared<BoolType>();
|
return make_shared<BoolType>();
|
||||||
else if (Token::String0 <= _typeToken && _typeToken <= Token::String32)
|
else if (Token::String0 <= _typeToken && _typeToken <= Token::String32)
|
||||||
return make_shared<StaticStringType>(int(_typeToken) - int(Token::String0));
|
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
|
else
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to convert elementary typename " +
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to convert elementary typename " +
|
||||||
std::string(Token::toString(_typeToken)) + " to type."));
|
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();
|
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
|
bool ContractType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
|
32
Types.h
32
Types.h
@ -76,9 +76,10 @@ class Type: private boost::noncopyable, public std::enable_shared_from_this<Type
|
|||||||
public:
|
public:
|
||||||
enum class Category
|
enum class Category
|
||||||
{
|
{
|
||||||
Integer, IntegerConstant, Bool, Real,
|
Integer, IntegerConstant, Bool, Real, String,
|
||||||
String, Contract, Struct, Function,
|
ByteArray, Mapping,
|
||||||
Mapping, Void, TypeType, Modifier, Magic
|
Contract, Struct, Function,
|
||||||
|
Void, TypeType, Modifier, Magic
|
||||||
};
|
};
|
||||||
|
|
||||||
///@{
|
///@{
|
||||||
@ -263,7 +264,7 @@ class BoolType: public Type
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoolType() {}
|
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 bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
|
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
|
||||||
virtual TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const override;
|
virtual TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const override;
|
||||||
@ -275,6 +276,29 @@ public:
|
|||||||
virtual u256 literalValue(Literal const* _literal) const override;
|
virtual u256 literalValue(Literal const* _literal) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* The type of a contract instance, there is one distinct type for each contract definition.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user