@ -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 ;
} ;
/**
@ -369,6 +382,12 @@ 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
{
return TypePointer ( ) ;
}
} ;
/**
@ -389,6 +408,12 @@ 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
{
return TypePointer ( ) ;
}
private :
TypePointer m_actualType ;
} ;
@ -413,6 +438,12 @@ public:
virtual std : : string toString ( ) const override ;
protected :
virtual TypePointer binaryOperatorResultImpl ( Token : : Value _operator , TypePointer const & _this , TypePointer const & _other ) const override
{
return TypePointer ( ) ;
}
private :
Kind m_kind ;