aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AST.cpp11
-rwxr-xr-xAST.h3
-rw-r--r--Parser.cpp16
-rw-r--r--Types.cpp44
-rw-r--r--Types.h3
5 files changed, 34 insertions, 43 deletions
diff --git a/AST.cpp b/AST.cpp
index 156d51f2..0ec0eb0c 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -596,17 +596,6 @@ void ElementaryTypeNameExpression::checkTypeRequirements()
m_type = make_shared<TypeType>(Type::fromElementaryTypeName(m_typeToken));
}
-Literal::Literal(Location const& _location, Token::Value _token,
- ASTPointer<ASTString> const& _value,
- Token::Value _sub):
- PrimaryExpression(_location), m_token(_token), m_value(_value)
-{
- if (Token::isEtherSubdenomination(_sub))
- m_subDenomination = static_cast<Literal::SubDenomination>(_sub);
- else
- m_subDenomination = Literal::SubDenomination::None;
-}
-
void Literal::checkTypeRequirements()
{
m_type = Type::forLiteral(*this);
diff --git a/AST.h b/AST.h
index bced99f9..47f2a40c 100755
--- a/AST.h
+++ b/AST.h
@@ -1127,7 +1127,8 @@ public:
};
Literal(Location const& _location, Token::Value _token,
ASTPointer<ASTString> const& _value,
- Token::Value _sub = Token::ILLEGAL);
+ SubDenomination _sub = SubDenomination::None):
+ PrimaryExpression(_location), m_token(_token), m_value(_value), m_subDenomination(_sub) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
diff --git a/Parser.cpp b/Parser.cpp
index 741b9aba..d8c15c36 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -684,7 +684,6 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
ASTNodeFactory nodeFactory(*this);
Token::Value token = m_scanner->getCurrentToken();
ASTPointer<Expression> expression;
- Token::Value nextToken = Token::ILLEGAL;
switch (token)
{
case Token::TRUE_LITERAL:
@@ -692,12 +691,19 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
expression = nodeFactory.createNode<Literal>(token, getLiteralAndAdvance());
break;
case Token::NUMBER:
- nextToken = m_scanner->peekNextToken();
+ if (Token::isEtherSubdenomination(m_scanner->peekNextToken()))
+ {
+ ASTPointer<ASTString> literal = getLiteralAndAdvance();
+ nodeFactory.markEndPosition();
+ Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(m_scanner->getCurrentToken());
+ m_scanner->next();
+ expression = nodeFactory.createNode<Literal>(token, literal, subdenomination);
+ break;
+ }
+ // fall-through
case Token::STRING_LITERAL:
nodeFactory.markEndPosition();
- expression = nodeFactory.createNode<Literal>(token, getLiteralAndAdvance(), nextToken);
- if (Token::isEtherSubdenomination(nextToken))
- m_scanner->next();
+ expression = nodeFactory.createNode<Literal>(token, getLiteralAndAdvance());
break;
case Token::IDENTIFIER:
nodeFactory.markEndPosition();
diff --git a/Types.cpp b/Types.cpp
index 648cf9cb..38549594 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -91,7 +91,7 @@ shared_ptr<Type const> Type::forLiteral(Literal const& _literal)
case Token::FALSE_LITERAL:
return make_shared<BoolType>();
case Token::NUMBER:
- return IntegerConstantType::fromLiteral(_literal.getValue());
+ return make_shared<IntegerConstantType>(_literal);
case Token::STRING_LITERAL:
//@todo put larger strings into dynamic strings
return StaticStringType::smallestTypeForLiteral(_literal.getValue());
@@ -216,9 +216,25 @@ const MemberList IntegerType::AddressMemberList =
strings{}, FunctionType::Location::BARE)},
{"send", make_shared<FunctionType>(strings{"uint"}, strings{}, FunctionType::Location::SEND)}});
-shared_ptr<IntegerConstantType const> IntegerConstantType::fromLiteral(string const& _literal)
+IntegerConstantType::IntegerConstantType(Literal const& _literal)
{
- return make_shared<IntegerConstantType>(bigint(_literal));
+ m_value = bigint(_literal.getValue());
+
+ switch (_literal.getSubDenomination())
+ {
+ case Literal::SubDenomination::Wei:
+ case Literal::SubDenomination::None:
+ break;
+ case Literal::SubDenomination::Szabo:
+ m_value *= bigint("1000000000000");
+ break;
+ case Literal::SubDenomination::Finney:
+ m_value *= bigint("1000000000000000");
+ break;
+ case Literal::SubDenomination::Ether:
+ m_value *= bigint("1000000000000000000");
+ break;
+ }
}
bool IntegerConstantType::isImplicitlyConvertibleTo(Type const& _convertTo) const
@@ -326,7 +342,7 @@ string IntegerConstantType::toString() const
return "int_const " + m_value.str();
}
-u256 IntegerConstantType::literalValue(Literal const* _literal) const
+u256 IntegerConstantType::literalValue(Literal const*) const
{
u256 value;
// we ignore the literal and hope that the type was correctly determined
@@ -338,26 +354,6 @@ u256 IntegerConstantType::literalValue(Literal const* _literal) const
else
value = s2u(s256(m_value));
- if (_literal)
- {
- Literal::SubDenomination sub =_literal->getSubDenomination();
- switch(sub)
- {
- case Literal::SubDenomination::Wei:
- case Literal::SubDenomination::None:
- break;
- case Literal::SubDenomination::Szabo:
- value *= u256(1000000000000);
- break;
- case Literal::SubDenomination::Finney:
- value *= u256(1000000000000000);
- break;
- case Literal::SubDenomination::Ether:
- value *= u256(1000000000000000000);
- break;
- }
- }
-
return value;
}
diff --git a/Types.h b/Types.h
index 1f4d27a2..fcc77fea 100644
--- a/Types.h
+++ b/Types.h
@@ -197,8 +197,7 @@ 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(Literal const& _literal);
explicit IntegerConstantType(bigint _value): m_value(_value) {}
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;