From 28e99bbd7d5b482a68c86984731158f55a323dce Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 4 Feb 2015 16:37:54 +0100 Subject: [PATCH 1/5] Adding ether subdenominations after constan literals --- libsolidity/AST.cpp | 11 +++++++++++ libsolidity/AST.h | 16 +++++++++++++--- libsolidity/Parser.cpp | 6 ++++-- libsolidity/Token.h | 5 +++++ libsolidity/Types.cpp | 27 ++++++++++++++++++++++++--- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 6028c07cf..f0c60e05d 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -594,6 +594,17 @@ void ElementaryTypeNameExpression::checkTypeRequirements() m_type = make_shared(Type::fromElementaryTypeName(m_typeToken)); } +Literal::Literal(Location const& _location, Token::Value _token, + ASTPointer const& _value, + Token::Value _sub): + PrimaryExpression(_location), m_token(_token), m_value(_value) +{ + solAssert(_sub == Token::ILLEGAL || _sub == Token::ETH_SUB_WEI || + _sub == Token::ETH_SUB_SZABO || _sub == Token::ETH_SUB_FINNEY || + _sub == Token::ETH_SUB_ETHER, "Illegal Token::Value given to Literal ctor"); + m_subDenomination =static_cast(_sub); +} + void Literal::checkTypeRequirements() { m_type = Type::forLiteral(*this); diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 525907bf4..ecf91c059 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -1112,13 +1112,20 @@ private: }; /** - * A literal string or number. @see Type::literalToBigEndian is used to actually parse its value. + * A literal string or number. @see ExpressionCompiler::endVisit() is used to actually parse its value. */ class Literal: public PrimaryExpression { public: - Literal(Location const& _location, Token::Value _token, ASTPointer const& _value): - PrimaryExpression(_location), m_token(_token), m_value(_value) {} + enum class ethSubDenomination { + NONE = Token::ILLEGAL, + WEI = Token::ETH_SUB_WEI, + SZABO = Token::ETH_SUB_SZABO, + FINNEY = Token::ETH_SUB_FINNEY, + ETHER = Token::ETH_SUB_ETHER}; + Literal(Location const& _location, Token::Value _token, + ASTPointer const& _value, + Token::Value _sub = Token::ILLEGAL); virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; virtual void checkTypeRequirements() override; @@ -1127,9 +1134,12 @@ public: /// @returns the non-parsed value of the literal ASTString const& getValue() const { return *m_value; } + ethSubDenomination getSubDenomination() const { return m_subDenomination; } + private: Token::Value m_token; ASTPointer m_value; + ethSubDenomination m_subDenomination; }; /// @} diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 0ad7bd7ca..739bbdd61 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -180,7 +180,7 @@ ASTPointer Parser::parseInheritanceSpecifier() Declaration::Visibility Parser::parseVisibilitySpecifier(Token::Value _token) { - Declaration::Visibility visibility; + Declaration::Visibility visibility = Declaration::Visibility::DEFAULT; if (_token == Token::PUBLIC) visibility = Declaration::Visibility::PUBLIC; else if (_token == Token::PROTECTED) @@ -684,6 +684,7 @@ ASTPointer Parser::parsePrimaryExpression() ASTNodeFactory nodeFactory(*this); Token::Value token = m_scanner->getCurrentToken(); ASTPointer expression; + Token::Value nextToken = Token::ILLEGAL; switch (token) { case Token::TRUE_LITERAL: @@ -691,9 +692,10 @@ ASTPointer Parser::parsePrimaryExpression() expression = nodeFactory.createNode(token, getLiteralAndAdvance()); break; case Token::NUMBER: + nextToken = m_scanner->peekNextToken(); case Token::STRING_LITERAL: nodeFactory.markEndPosition(); - expression = nodeFactory.createNode(token, getLiteralAndAdvance()); + expression = nodeFactory.createNode(token, getLiteralAndAdvance(), nextToken); break; case Token::IDENTIFIER: nodeFactory.markEndPosition(); diff --git a/libsolidity/Token.h b/libsolidity/Token.h index 76e504499..7b9608254 100644 --- a/libsolidity/Token.h +++ b/libsolidity/Token.h @@ -174,6 +174,11 @@ namespace solidity K(WHILE, "while", 0) \ \ \ + /* Ether subdenominations */ \ + K(ETH_SUB_WEI, "wei", 0) \ + K(ETH_SUB_SZABO, "szabo", 0) \ + K(ETH_SUB_FINNEY, "finney", 0) \ + K(ETH_SUB_ETHER, "ether", 0) \ /* type keywords, keep them in this order, keep int as first keyword * the implementation in Types.cpp has to be synced to this here * TODO more to be added */ \ diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 54e701c10..98c648025 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -326,15 +326,36 @@ string IntegerConstantType::toString() const return "int_const " + m_value.str(); } -u256 IntegerConstantType::literalValue(Literal const*) const +u256 IntegerConstantType::literalValue(Literal const* _literal) const { + Literal::ethSubDenomination sub =_literal->getSubDenomination(); + u256 value; // we ignore the literal and hope that the type was correctly determined solAssert(m_value <= u256(-1), "Integer constant too large."); solAssert(m_value >= -(bigint(1) << 255), "Integer constant too small."); + + if (m_value >= 0) - return u256(m_value); + value = u256(m_value); else - return s2u(s256(m_value)); + value = s2u(s256(m_value)); + + switch(sub) { + case Literal::ethSubDenomination::WEI: + case Literal::ethSubDenomination::NONE: + break; + case Literal::ethSubDenomination::SZABO: + value *= u256(1000000000000); + break; + case Literal::ethSubDenomination::FINNEY: + value *= u256(1000000000000000); + break; + case Literal::ethSubDenomination::ETHER: + value *= u256(1000000000000000000); + break; + } + + return value; } shared_ptr IntegerConstantType::getIntegerType() const From 13d9cbf5abe8edb79e0de51205a3db3665863b07 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 4 Feb 2015 22:02:35 +0100 Subject: [PATCH 2/5] Tests for ether subdenominations. Work in progress --- libsolidity/AST.cpp | 8 +++---- libsolidity/Parser.cpp | 2 ++ libsolidity/Token.h | 1 + test/SolidityExpressionCompiler.cpp | 33 ++++++++++++++++++++++++++++- test/SolidityParser.cpp | 19 +++++++++++++++++ test/SolidityScanner.cpp | 9 ++++++++ 6 files changed, 67 insertions(+), 5 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index f0c60e05d..307168ed1 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -599,10 +599,10 @@ Literal::Literal(Location const& _location, Token::Value _token, Token::Value _sub): PrimaryExpression(_location), m_token(_token), m_value(_value) { - solAssert(_sub == Token::ILLEGAL || _sub == Token::ETH_SUB_WEI || - _sub == Token::ETH_SUB_SZABO || _sub == Token::ETH_SUB_FINNEY || - _sub == Token::ETH_SUB_ETHER, "Illegal Token::Value given to Literal ctor"); - m_subDenomination =static_cast(_sub); + if(Token::isEtherSubdenomination(_sub)) + m_subDenomination = static_cast(_sub); + else + m_subDenomination = Literal::ethSubDenomination::NONE; } void Literal::checkTypeRequirements() diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 739bbdd61..6449ba93d 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -694,6 +694,8 @@ ASTPointer Parser::parsePrimaryExpression() case Token::NUMBER: nextToken = m_scanner->peekNextToken(); case Token::STRING_LITERAL: + if (Token::isEtherSubdenomination(nextToken)) + m_scanner->next(); nodeFactory.markEndPosition(); expression = nodeFactory.createNode(token, getLiteralAndAdvance(), nextToken); break; diff --git a/libsolidity/Token.h b/libsolidity/Token.h index 7b9608254..f2beefd9a 100644 --- a/libsolidity/Token.h +++ b/libsolidity/Token.h @@ -383,6 +383,7 @@ public: static bool isCountOp(Value op) { return op == INC || op == DEC; } static bool isShiftOp(Value op) { return (SHL <= op) && (op <= SHR); } static bool isVisibilitySpecifier(Value op) { return op == PUBLIC || op == PRIVATE || op == PROTECTED; } + static bool isEtherSubdenomination(Value op) { return op == ETH_SUB_WEI || op == ETH_SUB_SZABO || op == ETH_SUB_FINNEY || op == Token::ETH_SUB_ETHER; } // Returns a string corresponding to the JS token string // (.e., "<" for the token LT) or NULL if the token doesn't diff --git a/test/SolidityExpressionCompiler.cpp b/test/SolidityExpressionCompiler.cpp index a0cca3a3a..71f40bd25 100644 --- a/test/SolidityExpressionCompiler.cpp +++ b/test/SolidityExpressionCompiler.cpp @@ -91,7 +91,16 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ { Parser parser; ASTPointer sourceUnit; - BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); + try + { + sourceUnit = parser.parse(make_shared(CharStream(_sourceCode))); + } + catch(boost::exception const& _e) + { + auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); + BOOST_FAIL(msg); + } + // BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); vector declarations; declarations.reserve(_globalDeclarations.size() + 1); @@ -177,6 +186,28 @@ BOOST_AUTO_TEST_CASE(int_literal) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } +BOOST_AUTO_TEST_CASE(int_literals_with_ether_subdenominations) +{ + char const* sourceCode = R"( + contract c { + function c () + { + a = 1 wei; + // b = 2 szabo; + // c = 3 finney; +// b = 4 ether; + } + uint256 a; + uint256 b; + uint256 c; + uint256 d; + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH5), 0x38, 0xd4, 0xa5, 0x10, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + BOOST_AUTO_TEST_CASE(comparison) { char const* sourceCode = "contract test {\n" diff --git a/test/SolidityParser.cpp b/test/SolidityParser.cpp index 9ba38a4a1..b6837866c 100644 --- a/test/SolidityParser.cpp +++ b/test/SolidityParser.cpp @@ -660,6 +660,25 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) BOOST_CHECK_THROW(parseText(text), ParserError); } +BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) +{ + char const* text = R"( + contract c { + function c () + { + a = 1 wei; + b = 2 szabo; + c = 3 finney; + b = 4 ether; + } + uint256 a; + uint256 b; + uint256 c; + uint256 d; + })"; + BOOST_CHECK_NO_THROW(parseTextExplainError(text)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/SolidityScanner.cpp b/test/SolidityScanner.cpp index 7dc9ef482..5bd897ab4 100644 --- a/test/SolidityScanner.cpp +++ b/test/SolidityScanner.cpp @@ -255,6 +255,15 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence) BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "documentation comment "); } +BOOST_AUTO_TEST_CASE(ether_subdenominations) +{ + Scanner scanner(CharStream("wei szabo finney ether")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI); + BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO); + BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY); + BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER); +} + BOOST_AUTO_TEST_SUITE_END() } From c11c26c09453af1e4bf0692f3beaf9ec332abbfe Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 5 Feb 2015 13:48:02 +0100 Subject: [PATCH 3/5] Tests and fixes for ether subdenominations --- libsolidity/Parser.cpp | 4 +- libsolidity/Types.cpp | 31 +++++++------- test/SolidityExpressionCompiler.cpp | 63 +++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 6449ba93d..741b9aba7 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -694,10 +694,10 @@ ASTPointer Parser::parsePrimaryExpression() case Token::NUMBER: nextToken = m_scanner->peekNextToken(); case Token::STRING_LITERAL: - if (Token::isEtherSubdenomination(nextToken)) - m_scanner->next(); nodeFactory.markEndPosition(); expression = nodeFactory.createNode(token, getLiteralAndAdvance(), nextToken); + if (Token::isEtherSubdenomination(nextToken)) + m_scanner->next(); break; case Token::IDENTIFIER: nodeFactory.markEndPosition(); diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 98c648025..c554f3551 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -328,31 +328,32 @@ string IntegerConstantType::toString() const u256 IntegerConstantType::literalValue(Literal const* _literal) const { - Literal::ethSubDenomination sub =_literal->getSubDenomination(); u256 value; // we ignore the literal and hope that the type was correctly determined solAssert(m_value <= u256(-1), "Integer constant too large."); solAssert(m_value >= -(bigint(1) << 255), "Integer constant too small."); - if (m_value >= 0) value = u256(m_value); else value = s2u(s256(m_value)); - switch(sub) { - case Literal::ethSubDenomination::WEI: - case Literal::ethSubDenomination::NONE: - break; - case Literal::ethSubDenomination::SZABO: - value *= u256(1000000000000); - break; - case Literal::ethSubDenomination::FINNEY: - value *= u256(1000000000000000); - break; - case Literal::ethSubDenomination::ETHER: - value *= u256(1000000000000000000); - break; + if (_literal) { + Literal::ethSubDenomination sub =_literal->getSubDenomination(); + switch(sub) { + case Literal::ethSubDenomination::WEI: + case Literal::ethSubDenomination::NONE: + break; + case Literal::ethSubDenomination::SZABO: + value *= u256(1000000000000); + break; + case Literal::ethSubDenomination::FINNEY: + value *= u256(1000000000000000); + break; + case Literal::ethSubDenomination::ETHER: + value *= u256(1000000000000000000); + break; + } } return value; diff --git a/test/SolidityExpressionCompiler.cpp b/test/SolidityExpressionCompiler.cpp index 71f40bd25..3c3ea1baa 100644 --- a/test/SolidityExpressionCompiler.cpp +++ b/test/SolidityExpressionCompiler.cpp @@ -100,7 +100,6 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); BOOST_FAIL(msg); } - // BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); vector declarations; declarations.reserve(_globalDeclarations.size() + 1); @@ -186,25 +185,63 @@ BOOST_AUTO_TEST_CASE(int_literal) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } -BOOST_AUTO_TEST_CASE(int_literals_with_ether_subdenominations) +BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination) { char const* sourceCode = R"( - contract c { - function c () + contract test { + function test () { - a = 1 wei; - // b = 2 szabo; - // c = 3 finney; -// b = 4 ether; + var x = 1 wei; } - uint256 a; - uint256 b; - uint256 c; - uint256 d; })"; bytes code = compileFirstExpression(sourceCode); - bytes expectation({byte(eth::Instruction::PUSH5), 0x38, 0xd4, 0xa5, 0x10, 0x00}); + bytes expectation({byte(eth::Instruction::PUSH1), 0x1}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination) +{ + char const* sourceCode = R"( + contract test { + function test () + { + var x = 1 szabo; + } + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination) +{ + char const* sourceCode = R"( + contract test { + function test () + { + var x = 1 finney; + } + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination) +{ + char const* sourceCode = R"( + contract test { + function test () + { + var x = 1 ether; + } + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } From c0151476adf493c2a9fbd747cf00eda07941e121 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 5 Feb 2015 22:38:07 +0100 Subject: [PATCH 4/5] Minor Style fixes --- libsolidity/AST.cpp | 6 +++--- libsolidity/AST.h | 16 +++++++++------- libsolidity/Token.h | 12 ++++++------ libsolidity/Types.cpp | 18 ++++++++++-------- test/SolidityScanner.cpp | 8 ++++---- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 307168ed1..455dc44aa 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -599,10 +599,10 @@ Literal::Literal(Location const& _location, Token::Value _token, Token::Value _sub): PrimaryExpression(_location), m_token(_token), m_value(_value) { - if(Token::isEtherSubdenomination(_sub)) - m_subDenomination = static_cast(_sub); + if (Token::isEtherSubdenomination(_sub)) + m_subDenomination = static_cast(_sub); else - m_subDenomination = Literal::ethSubDenomination::NONE; + m_subDenomination = Literal::SubDenomination::NONE; } void Literal::checkTypeRequirements() diff --git a/libsolidity/AST.h b/libsolidity/AST.h index ecf91c059..193e7310a 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -1117,12 +1117,14 @@ private: class Literal: public PrimaryExpression { public: - enum class ethSubDenomination { + enum class SubDenomination + { NONE = Token::ILLEGAL, - WEI = Token::ETH_SUB_WEI, - SZABO = Token::ETH_SUB_SZABO, - FINNEY = Token::ETH_SUB_FINNEY, - ETHER = Token::ETH_SUB_ETHER}; + WEI = Token::SubWei, + SZABO = Token::SubSzabo, + FINNEY = Token::SubFinney, + ETHER = Token::SubEther + }; Literal(Location const& _location, Token::Value _token, ASTPointer const& _value, Token::Value _sub = Token::ILLEGAL); @@ -1134,12 +1136,12 @@ public: /// @returns the non-parsed value of the literal ASTString const& getValue() const { return *m_value; } - ethSubDenomination getSubDenomination() const { return m_subDenomination; } + SubDenomination getSubDenomination() const { return m_subDenomination; } private: Token::Value m_token; ASTPointer m_value; - ethSubDenomination m_subDenomination; + SubDenomination m_subDenomination; }; /// @} diff --git a/libsolidity/Token.h b/libsolidity/Token.h index f2beefd9a..b07fc46c6 100644 --- a/libsolidity/Token.h +++ b/libsolidity/Token.h @@ -174,11 +174,11 @@ namespace solidity K(WHILE, "while", 0) \ \ \ - /* Ether subdenominations */ \ - K(ETH_SUB_WEI, "wei", 0) \ - K(ETH_SUB_SZABO, "szabo", 0) \ - K(ETH_SUB_FINNEY, "finney", 0) \ - K(ETH_SUB_ETHER, "ether", 0) \ + /* Ether subdenominations */ \ + K(SubWei, "wei", 0) \ + K(SubSzabo, "szabo", 0) \ + K(SubFinney, "finney", 0) \ + K(SubEther, "ether", 0) \ /* type keywords, keep them in this order, keep int as first keyword * the implementation in Types.cpp has to be synced to this here * TODO more to be added */ \ @@ -383,7 +383,7 @@ public: static bool isCountOp(Value op) { return op == INC || op == DEC; } static bool isShiftOp(Value op) { return (SHL <= op) && (op <= SHR); } static bool isVisibilitySpecifier(Value op) { return op == PUBLIC || op == PRIVATE || op == PROTECTED; } - static bool isEtherSubdenomination(Value op) { return op == ETH_SUB_WEI || op == ETH_SUB_SZABO || op == ETH_SUB_FINNEY || op == Token::ETH_SUB_ETHER; } + static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == Token::SubEther; } // Returns a string corresponding to the JS token string // (.e., "<" for the token LT) or NULL if the token doesn't diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index c554f3551..a8b3add48 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -338,19 +338,21 @@ u256 IntegerConstantType::literalValue(Literal const* _literal) const else value = s2u(s256(m_value)); - if (_literal) { - Literal::ethSubDenomination sub =_literal->getSubDenomination(); - switch(sub) { - case Literal::ethSubDenomination::WEI: - case Literal::ethSubDenomination::NONE: + if (_literal) + { + Literal::SubDenomination sub =_literal->getSubDenomination(); + switch(sub) + { + case Literal::SubDenomination::WEI: + case Literal::SubDenomination::NONE: break; - case Literal::ethSubDenomination::SZABO: + case Literal::SubDenomination::SZABO: value *= u256(1000000000000); break; - case Literal::ethSubDenomination::FINNEY: + case Literal::SubDenomination::FINNEY: value *= u256(1000000000000000); break; - case Literal::ethSubDenomination::ETHER: + case Literal::SubDenomination::ETHER: value *= u256(1000000000000000000); break; } diff --git a/test/SolidityScanner.cpp b/test/SolidityScanner.cpp index 5bd897ab4..8088b4d4b 100644 --- a/test/SolidityScanner.cpp +++ b/test/SolidityScanner.cpp @@ -258,10 +258,10 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence) BOOST_AUTO_TEST_CASE(ether_subdenominations) { Scanner scanner(CharStream("wei szabo finney ether")); - BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI); - BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO); - BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY); - BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::SubWei); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther); } BOOST_AUTO_TEST_SUITE_END() From e296d86cc6df7bc637b0175a43cdae9ad60e89c5 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 5 Feb 2015 23:03:24 +0100 Subject: [PATCH 5/5] More style changes in enums --- libsolidity/AST.cpp | 2 +- libsolidity/AST.h | 10 +++++----- libsolidity/Types.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 455dc44aa..50a67a8db 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -602,7 +602,7 @@ Literal::Literal(Location const& _location, Token::Value _token, if (Token::isEtherSubdenomination(_sub)) m_subDenomination = static_cast(_sub); else - m_subDenomination = Literal::SubDenomination::NONE; + m_subDenomination = Literal::SubDenomination::None; } void Literal::checkTypeRequirements() diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 193e7310a..bced99f9a 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -1119,11 +1119,11 @@ class Literal: public PrimaryExpression public: enum class SubDenomination { - NONE = Token::ILLEGAL, - WEI = Token::SubWei, - SZABO = Token::SubSzabo, - FINNEY = Token::SubFinney, - ETHER = Token::SubEther + None = Token::ILLEGAL, + Wei = Token::SubWei, + Szabo = Token::SubSzabo, + Finney = Token::SubFinney, + Ether = Token::SubEther }; Literal(Location const& _location, Token::Value _token, ASTPointer const& _value, diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index a8b3add48..648cf9cb2 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -343,16 +343,16 @@ u256 IntegerConstantType::literalValue(Literal const* _literal) const Literal::SubDenomination sub =_literal->getSubDenomination(); switch(sub) { - case Literal::SubDenomination::WEI: - case Literal::SubDenomination::NONE: + case Literal::SubDenomination::Wei: + case Literal::SubDenomination::None: break; - case Literal::SubDenomination::SZABO: + case Literal::SubDenomination::Szabo: value *= u256(1000000000000); break; - case Literal::SubDenomination::FINNEY: + case Literal::SubDenomination::Finney: value *= u256(1000000000000000); break; - case Literal::SubDenomination::ETHER: + case Literal::SubDenomination::Ether: value *= u256(1000000000000000000); break; }