aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/AST.h4
-rw-r--r--libsolidity/ast/ASTVisitor.h2
-rw-r--r--libsolidity/ast/Types.cpp41
-rw-r--r--libsolidity/ast/Types.h8
4 files changed, 23 insertions, 32 deletions
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index a53987bf..fa0d6921 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -146,6 +146,7 @@ private:
class Scopable
{
public:
+ virtual ~Scopable() = default;
/// @returns the scope this declaration resides in. Can be nullptr if it is the global scope.
/// Available only after name and type resolution step.
ASTNode const* scope() const { return m_scope; }
@@ -307,6 +308,7 @@ private:
class VariableScope
{
public:
+ virtual ~VariableScope() = default;
void addLocalVariable(VariableDeclaration const& _localVariable) { m_localVariables.push_back(&_localVariable); }
std::vector<VariableDeclaration const*> const& localVariables() const { return m_localVariables; }
@@ -320,6 +322,7 @@ private:
class Documented
{
public:
+ virtual ~Documented() = default;
explicit Documented(ASTPointer<ASTString> const& _documentation): m_documentation(_documentation) {}
/// @return A shared pointer of an ASTString.
@@ -336,6 +339,7 @@ protected:
class ImplementationOptional
{
public:
+ virtual ~ImplementationOptional() = default;
explicit ImplementationOptional(bool _implemented): m_implemented(_implemented) {}
/// @return whether this node is fully implemented or not
diff --git a/libsolidity/ast/ASTVisitor.h b/libsolidity/ast/ASTVisitor.h
index b1389f0f..6c0ce6f8 100644
--- a/libsolidity/ast/ASTVisitor.h
+++ b/libsolidity/ast/ASTVisitor.h
@@ -43,6 +43,7 @@ namespace solidity
class ASTVisitor
{
public:
+ virtual ~ASTVisitor() = default;
virtual bool visit(SourceUnit& _node) { return visitNode(_node); }
virtual bool visit(PragmaDirective& _node) { return visitNode(_node); }
virtual bool visit(ImportDirective& _node) { return visitNode(_node); }
@@ -147,6 +148,7 @@ protected:
class ASTConstVisitor
{
public:
+ virtual ~ASTConstVisitor() = default;
virtual bool visit(SourceUnit const& _node) { return visitNode(_node); }
virtual bool visit(PragmaDirective const& _node) { return visitNode(_node); }
virtual bool visit(ImportDirective const& _node) { return visitNode(_node); }
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index a8d9a1d3..f4198016 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -627,8 +627,7 @@ bool FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const
bool FixedPointType::isExplicitlyConvertibleTo(Type const& _convertTo) const
{
return _convertTo.category() == category() ||
- _convertTo.category() == Category::Integer ||
- _convertTo.category() == Category::FixedBytes;
+ (_convertTo.category() == Category::Integer && !dynamic_cast<IntegerType const&>(_convertTo).isAddress());
}
TypePointer FixedPointType::unaryOperatorResult(Token::Value _operator) const
@@ -682,13 +681,7 @@ bigint FixedPointType::minIntegerValue() const
TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const
{
- if (
- _other->category() != Category::RationalNumber &&
- _other->category() != category() &&
- _other->category() != Category::Integer
- )
- return TypePointer();
- auto commonType = Type::commonType(shared_from_this(), _other); //might be fixed point or integer
+ auto commonType = Type::commonType(shared_from_this(), _other);
if (!commonType)
return TypePointer();
@@ -696,19 +689,16 @@ TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePoi
// All fixed types can be compared
if (Token::isCompareOp(_operator))
return commonType;
- if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator))
+ if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator) || _operator == Token::Exp)
return TypePointer();
- if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType))
- {
- if (Token::Exp == _operator)
- return TypePointer();
- }
- else if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
- if (intType->isAddress())
- return TypePointer();
return commonType;
}
+std::shared_ptr<IntegerType> FixedPointType::asIntegerType() const
+{
+ return std::make_shared<IntegerType>(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned);
+}
+
tuple<bool, rational> RationalNumberType::parseRational(string const& _value)
{
rational value;
@@ -1148,7 +1138,7 @@ u256 RationalNumberType::literalValue(Literal const*) const
auto fixed = fixedPointType();
solAssert(fixed, "");
int fractionalDigits = fixed->fractionalDigits();
- shiftedValue = (m_value.numerator() / m_value.denominator()) * pow(bigint(10), fractionalDigits);
+ shiftedValue = m_value.numerator() * pow(bigint(10), fractionalDigits) / m_value.denominator();
}
// we ignore the literal and hope that the type was correctly determined
@@ -1274,17 +1264,12 @@ bool StringLiteralType::isValidUTF8() const
return dev::validateUTF8(m_value);
}
-shared_ptr<FixedBytesType> FixedBytesType::smallestTypeForLiteral(string const& _literal)
-{
- if (_literal.length() <= 32)
- return make_shared<FixedBytesType>(_literal.length());
- return shared_ptr<FixedBytesType>();
-}
-
FixedBytesType::FixedBytesType(int _bytes): m_bytes(_bytes)
{
- solAssert(m_bytes >= 0 && m_bytes <= 32,
- "Invalid byte number for fixed bytes type: " + dev::toString(m_bytes));
+ solAssert(
+ m_bytes > 0 && m_bytes <= 32,
+ "Invalid byte number for fixed bytes type: " + dev::toString(m_bytes)
+ );
}
bool FixedBytesType::isImplicitlyConvertibleTo(Type const& _convertTo) const
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 345f84a1..ca6822c9 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -138,6 +138,7 @@ private:
class Type: private boost::noncopyable, public std::enable_shared_from_this<Type>
{
public:
+ virtual ~Type() = default;
enum class Category
{
Integer, RationalNumber, StringLiteral, Bool, FixedPoint, Array,
@@ -396,6 +397,9 @@ public:
/// smallest value in general.
bigint minIntegerValue() const;
+ /// @returns the smallest integer type that can hold this type with fractional parts shifted to integers.
+ std::shared_ptr<IntegerType> asIntegerType() const;
+
private:
int m_totalBits;
int m_fractionalDigits;
@@ -502,10 +506,6 @@ class FixedBytesType: public Type
public:
virtual Category category() const override { return Category::FixedBytes; }
- /// @returns the smallest bytes type for the given literal or an empty pointer
- /// if no type fits.
- static std::shared_ptr<FixedBytesType> smallestTypeForLiteral(std::string const& _literal);
-
explicit FixedBytesType(int _bytes);
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;