diff options
-rw-r--r-- | AST.cpp | 11 | ||||
-rwxr-xr-x | AST.h | 3 | ||||
-rw-r--r-- | Parser.cpp | 16 | ||||
-rw-r--r-- | Types.cpp | 44 | ||||
-rw-r--r-- | Types.h | 3 |
5 files changed, 34 insertions, 43 deletions
@@ -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); @@ -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; @@ -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(); @@ -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; } @@ -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; |