diff options
author | Christian <c@ethdev.com> | 2014-12-19 18:31:17 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-01-09 22:16:09 +0800 |
commit | be623273f329b841bfda2a0aef91f091aa81b216 (patch) | |
tree | 6467f6a373d9f7156b78e44685aa08fafa7d8e3e /Types.h | |
parent | be1e89da42e0ed9828dd2fb5939fd7bd48140be7 (diff) | |
download | dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.tar dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.tar.gz dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.tar.bz2 dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.tar.lz dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.tar.xz dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.tar.zst dexon-solidity-be623273f329b841bfda2a0aef91f091aa81b216.zip |
Arbitrary precision integer constants.
Diffstat (limited to 'Types.h')
-rw-r--r-- | Types.h | 47 |
1 files changed, 38 insertions, 9 deletions
@@ -75,7 +75,7 @@ class Type: private boost::noncopyable, public std::enable_shared_from_this<Type public: enum class Category { - INTEGER, BOOL, REAL, STRING, CONTRACT, STRUCT, FUNCTION, MAPPING, VOID, TYPE, MAGIC + INTEGER, INTEGER_CONSTANT, BOOL, REAL, STRING, CONTRACT, STRUCT, FUNCTION, MAPPING, VOID, TYPE, MAGIC }; ///@{ @@ -135,7 +135,7 @@ public: TypePointer getMemberType(std::string const& _name) const { return getMembers().getMemberType(_name); } virtual std::string toString() const = 0; - virtual u256 literalValue(Literal const&) const + virtual u256 literalValue(Literal const*) const { BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Literal value requested " "for type without literals.")); @@ -158,10 +158,6 @@ public: }; virtual Category getCategory() const override { return Category::INTEGER; } - /// @returns the smallest integer type for the given literal or an empty pointer - /// if no type fits. - static std::shared_ptr<IntegerType const> smallestTypeForLiteral(std::string const& _literal); - explicit IntegerType(int _bits, Modifier _modifier = Modifier::UNSIGNED); virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; @@ -177,7 +173,6 @@ public: virtual MemberList const& getMembers() const { return isAddress() ? AddressMemberList : EmptyMemberList; } virtual std::string toString() const override; - virtual u256 literalValue(Literal const& _literal) const override; int getNumBits() const { return m_bits; } bool isHash() const { return m_modifier == Modifier::HASH || m_modifier == Modifier::ADDRESS; } @@ -191,6 +186,40 @@ private: }; /** + * Integer constants either literals or computed. Example expressions: 2, 2+10, ~10. + * There is one distinct type per value. + */ +class IntegerConstantType: public Type +{ +public: + virtual Category getCategory() const override { return Category::INTEGER_CONSTANT; } + + static std::shared_ptr<IntegerConstantType const> fromLiteral(std::string const& _literal); + + explicit IntegerConstantType(bigint _value): m_value(_value) {} + + virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; + 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; + + virtual bool operator==(Type const& _other) const override; + + virtual bool canBeStored() const override { return false; } + virtual bool canLiveOutsideStorage() const override { return false; } + virtual unsigned getSizeOnStack() const override { return 1; } + + virtual std::string toString() const override; + virtual u256 literalValue(Literal const* _literal) const override; + + /// @returns the smallest integer type that can hold the value or an empty pointer if not possible. + std::shared_ptr<IntegerType const> getIntegerType() const; + +private: + bigint m_value; +}; + +/** * String type with fixed length, up to 32 bytes. */ class StaticStringType: public Type @@ -211,7 +240,7 @@ public: virtual bool isValueType() const override { return true; } virtual std::string toString() const override { return "string" + dev::toString(m_bytes); } - virtual u256 literalValue(Literal const& _literal) const override; + virtual u256 literalValue(Literal const* _literal) const override; int getNumBytes() const { return m_bytes; } @@ -238,7 +267,7 @@ public: virtual bool isValueType() const override { return true; } virtual std::string toString() const override { return "bool"; } - virtual u256 literalValue(Literal const& _literal) const override; + virtual u256 literalValue(Literal const* _literal) const override; }; /** |