diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 00:43:38 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 00:43:38 +0800 |
commit | a7b661d3be53b4c6a05401782ab8f90202a4f776 (patch) | |
tree | a2fdb25e88821def4962e1eacf303ec8f89cdfc3 /Types.h | |
parent | 184ddca5a108c5f3d026aa372a2af2f63b2694f9 (diff) | |
parent | d18fa27b6a48540298e835ad324152566586c65c (diff) | |
download | dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.tar.gz dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.tar.zst dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.zip |
merging develop
Diffstat (limited to 'Types.h')
-rw-r--r-- | Types.h | 62 |
1 files changed, 51 insertions, 11 deletions
@@ -81,15 +81,23 @@ public: ///@{ ///@name Factory functions /// Factory functions that convert an AST @ref TypeName to a Type. - static std::shared_ptr<Type const> fromElementaryTypeName(Token::Value _typeToken); - static std::shared_ptr<Type const> fromUserDefinedTypeName(UserDefinedTypeName const& _typeName); - static std::shared_ptr<Type const> fromMapping(Mapping const& _typeName); - static std::shared_ptr<Type const> fromFunction(FunctionDefinition const& _function); + static TypePointer fromElementaryTypeName(Token::Value _typeToken); + static TypePointer fromUserDefinedTypeName(UserDefinedTypeName const& _typeName); + static TypePointer fromMapping(Mapping const& _typeName); + static TypePointer fromFunction(FunctionDefinition const& _function); /// @} /// Auto-detect the proper type for a literal. @returns an empty pointer if the literal does /// not fit any type. - static std::shared_ptr<Type const> forLiteral(Literal const& _literal); + static TypePointer forLiteral(Literal const& _literal); + /// @returns a pointer to _a or _b if the other is implicitly convertible to it or nullptr otherwise + static TypePointer commonType(TypePointer const& _a, TypePointer const& _b); + /// @returns the resulting type of applying the given operator or an empty pointer if this is not possible. + /// The default implementation allows comparison operators if a common type exists + static TypePointer binaryOperatorResult(Token::Value _operator, TypePointer const& _a, TypePointer const& _b) + { + return _a->binaryOperatorResultImpl(_operator, _a, _b); + } virtual Category getCategory() const = 0; virtual bool isImplicitlyConvertibleTo(Type const& _other) const { return *this == _other; } @@ -97,7 +105,6 @@ public: { return isImplicitlyConvertibleTo(_convertTo); } - virtual bool acceptsBinaryOperator(Token::Value) const { return false; } virtual bool acceptsUnaryOperator(Token::Value) const { return false; } virtual bool operator==(Type const& _other) const { return getCategory() == _other.getCategory(); } @@ -131,6 +138,11 @@ public: } protected: + virtual TypePointer binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _a, TypePointer const& _b) const + { + return Token::isCompareOp(_operator) ? commonType(_a, _b) : TypePointer(); + } + /// Convenience object used when returning an empty member list. static const MemberList EmptyMemberList; }; @@ -155,7 +167,6 @@ public: virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; - virtual bool acceptsBinaryOperator(Token::Value _operator) const override; virtual bool acceptsUnaryOperator(Token::Value _operator) const override; virtual bool operator==(Type const& _other) const override; @@ -173,6 +184,9 @@ public: bool isAddress() const { return m_modifier == Modifier::ADDRESS; } int isSigned() const { return m_modifier == Modifier::SIGNED; } +protected: + virtual TypePointer binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const override; + private: int m_bits; Modifier m_modifier; @@ -217,10 +231,6 @@ public: BoolType() {} virtual Category getCategory() const { return Category::BOOL; } virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; - virtual bool acceptsBinaryOperator(Token::Value _operator) const override - { - return _operator == Token::AND || _operator == Token::OR; - } virtual bool acceptsUnaryOperator(Token::Value _operator) const override { return _operator == Token::NOT || _operator == Token::DELETE; @@ -231,6 +241,9 @@ public: virtual std::string toString() const override { return "bool"; } virtual u256 literalValue(Literal const& _literal) const override; + +protected: + virtual TypePointer binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const override; }; /** @@ -370,6 +383,15 @@ public: virtual u256 getStorageSize() const override { BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Storage size of non-storable void type requested.")); } virtual bool canLiveOutsideStorage() const override { return false; } virtual unsigned getSizeOnStack() const override { return 0; } + +protected: + virtual TypePointer binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const override + { + (void)_operator; + (void)_this; + (void)_other; + return TypePointer(); + } }; /** @@ -390,6 +412,15 @@ public: virtual bool canLiveOutsideStorage() const override { return false; } virtual std::string toString() const override { return "type(" + m_actualType->toString() + ")"; } +protected: + virtual TypePointer binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const override + { + (void)_operator; + (void)_this; + (void)_other; + return TypePointer(); + } + private: TypePointer m_actualType; }; @@ -414,6 +445,15 @@ public: virtual std::string toString() const override; +protected: + virtual TypePointer binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const override + { + (void)_operator; + (void)_this; + (void)_other; + return TypePointer(); + } + private: Kind m_kind; |