From ddd16d76552d4080ffb82c433ebdd846bfc867ef Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Tue, 29 Mar 2016 11:55:06 -0500 Subject: Fix for Token::name and token::toString --- libsolidity/parsing/Token.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 3812a83f..df60aa4b 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -155,16 +155,15 @@ tuple Token::fromIdentifierOrKeyword(s ) { int n = parseSize(positionX + 1, _literal.end()); if ( - 0 < m && m < 256 && - 0 < n && n < 256 && + m + n > 0 && m + n <= 256 && m % 8 == 0 && n % 8 == 0 ) { if (keyword == Token::UFixed) - return make_tuple(Token::UFixed, m, n); + return make_tuple(Token::UFixedMxN, m, n); else - return make_tuple(Token::Fixed, m, n); + return make_tuple(Token::FixedMxN, m, n); } } } -- cgit v1.2.3 From 63951683717004449eb85dd41157ee586953b55d Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Tue, 29 Mar 2016 20:29:48 -0500 Subject: change lexical cast to unsigned int --- libsolidity/parsing/Token.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index df60aa4b..24877c70 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -113,7 +113,7 @@ int Token::parseSize(string::const_iterator _begin, string::const_iterator _end) { try { - unsigned int m = boost::lexical_cast(boost::make_iterator_range(_begin, _end)); + unsigned int m = boost::lexical_cast(boost::make_iterator_range(_begin, _end)); return m; } catch(boost::bad_lexical_cast const&) -- cgit v1.2.3 From 6c61e28dc22894a8b035ba25ed727db664a4b163 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Tue, 29 Mar 2016 22:32:40 -0500 Subject: Got it working exactly like you wanted ;) --- libsolidity/parsing/ParserBase.cpp | 87 +++++++++++++++++++++++++++++--------- libsolidity/parsing/Token.h | 14 +++--- 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp index 64e42841..9148946c 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/libsolidity/parsing/ParserBase.cpp @@ -44,14 +44,32 @@ int ParserBase::endPosition() const void ParserBase::expectToken(Token::Value _value) { - if (m_scanner->currentToken() != _value) - fatalParserError( - string("Expected token ") + - string(Token::name(_value)) + - string(" got '") + - string(Token::name(m_scanner->currentToken())) + - string("'") - ); + Token::Value tok = m_scanner->currentToken(); + if (tok != _value) + { + if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting + { + unsigned firstSize; + unsigned secondSize; + tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); + ElementaryTypeNameToken elemTypeName(tok, firstSize, secondSize); + fatalParserError( + string("Expected token ") + + string(Token::name(_value)) + + string(" got '") + + elemTypeName.toString() + + string("'") + ); + } + else + fatalParserError( + string("Expected token ") + + string(Token::name(_value)) + + string(" got '") + + string(Token::name(m_scanner->currentToken())) + + string("'") + ); + } m_scanner->next(); } @@ -59,23 +77,54 @@ Token::Value ParserBase::expectAssignmentOperator() { Token::Value op = m_scanner->currentToken(); if (!Token::isAssignmentOp(op)) - fatalParserError( - string("Expected assignment operator, got '") + - string(Token::name(m_scanner->currentToken())) + - string("'") - ); + { + if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting + { + unsigned firstSize; + unsigned secondSize; + tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); + ElementaryTypeNameToken elemTypeName(op, firstSize, secondSize); + fatalParserError( + string("Expected assignment operator, got '") + + elemTypeName.toString() + + string("'") + ); + } + else + fatalParserError( + string("Expected assignment operator, got '") + + string(Token::name(m_scanner->currentToken())) + + string("'") + ); + } m_scanner->next(); return op; } ASTPointer ParserBase::expectIdentifierToken() { - if (m_scanner->currentToken() != Token::Identifier) - fatalParserError( - string("Expected identifier, got '") + - string(Token::name(m_scanner->currentToken())) + - string("'") - ); + Token::Value id = m_scanner->currentToken(); + if (id != Token::Identifier) + { + if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting + { + unsigned firstSize; + unsigned secondSize; + tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); + ElementaryTypeNameToken elemTypeName(id, firstSize, secondSize); + fatalParserError( + string("Expected identifier, got '") + + elemTypeName.toString() + + string("'") + ); + } + else + fatalParserError( + string("Expected identifier, got '") + + string(Token::name(id)) + + string("'") + ); + } return getLiteralAndAdvance(); } diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 31646f8d..e7a7e24c 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -190,18 +190,18 @@ namespace solidity K(After, "after", 0) \ /* type keywords*/ \ K(Int, "int", 0) \ - T(IntM, "intM", 0) \ K(UInt, "uint", 0) \ - T(UIntM, "uintM", 0) \ K(Bytes, "bytes", 0) \ - T(BytesM, "bytesM", 0) \ K(Byte, "byte", 0) \ K(String, "string", 0) \ K(Address, "address", 0) \ K(Bool, "bool", 0) \ K(Fixed, "fixed", 0) \ - T(FixedMxN, "fixedMxN", 0) \ K(UFixed, "ufixed", 0) \ + T(IntM, "intM", 0) \ + T(UIntM, "uintM", 0) \ + T(BytesM, "bytesM", 0) \ + T(FixedMxN, "fixedMxN", 0) \ T(UFixedMxN, "ufixedMxN", 0) \ T(TypesEnd, NULL, 0) /* used as type enum end marker */ \ \ @@ -334,8 +334,10 @@ public: std::string name = Token::toString(m_token); if (tokenValue || (firstNumber() == 0 && secondNumber() == 0)) return name; - //need to set it up this way for fixed types construction in future - return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber); + else if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN) + return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber); + else + return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber); } private: -- cgit v1.2.3 From 427b9557d688fe901814350099540ce333a59acd Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Wed, 30 Mar 2016 09:52:33 -0500 Subject: added solidity invalid fixed type test --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 3d0cc2cd..684731e8 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -3258,6 +3258,18 @@ BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value) BOOST_CHECK(!success(text)); } +BOOST_AUTO_TEST_CASE(invalid_fixed_type_long) +{ + char const* text = R"( + contract test { + function f() { + fixed8x888888888888888888888888888888888888888888888888888 b; + } + } + )"; + BOOST_CHECK(!success(text)); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 9404600b3f99acb633f6400baa0b53db42a8a626 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Wed, 30 Mar 2016 13:09:38 -0500 Subject: helper function in scanner and corresponding edits to parserBase --- libsolidity/parsing/ParserBase.cpp | 15 +++------------ libsolidity/parsing/Scanner.h | 7 +++++++ libsolidity/parsing/Token.cpp | 3 +++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp index 9148946c..71085a4d 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/libsolidity/parsing/ParserBase.cpp @@ -49,10 +49,7 @@ void ParserBase::expectToken(Token::Value _value) { if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting { - unsigned firstSize; - unsigned secondSize; - tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); - ElementaryTypeNameToken elemTypeName(tok, firstSize, secondSize); + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); fatalParserError( string("Expected token ") + string(Token::name(_value)) + @@ -80,10 +77,7 @@ Token::Value ParserBase::expectAssignmentOperator() { if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting { - unsigned firstSize; - unsigned secondSize; - tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); - ElementaryTypeNameToken elemTypeName(op, firstSize, secondSize); + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); fatalParserError( string("Expected assignment operator, got '") + elemTypeName.toString() + @@ -108,10 +102,7 @@ ASTPointer ParserBase::expectIdentifierToken() { if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting { - unsigned firstSize; - unsigned secondSize; - tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); - ElementaryTypeNameToken elemTypeName(id, firstSize, secondSize); + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); fatalParserError( string("Expected identifier, got '") + elemTypeName.toString() + diff --git a/libsolidity/parsing/Scanner.h b/libsolidity/parsing/Scanner.h index cffcec8e..ac9f18e8 100644 --- a/libsolidity/parsing/Scanner.h +++ b/libsolidity/parsing/Scanner.h @@ -119,6 +119,13 @@ public: { return m_currentToken.token; } + ElementaryTypeNameToken currentElementaryTypeNameToken() + { + unsigned firstSize; + unsigned secondSize; + std::tie(firstSize, secondSize) = m_currentToken.extendedTokenInfo; + return ElementaryTypeNameToken(m_currentToken.token, firstSize, secondSize); + } SourceLocation currentLocation() const { return m_currentToken.location; } std::string const& currentLiteral() const { return m_currentToken.literal; } diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 24877c70..097a6f54 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -132,6 +132,7 @@ tuple Token::fromIdentifierOrKeyword(s Token::Value keyword = keywordByName(baseType); if (keyword == Token::Bytes) { + solAssert(m != -1, "Invalid type M in fixed command. Should not reach here."); if (0 < m && m <= 32 && positionX == _literal.end()) return make_tuple(Token::BytesM, m, 0); } @@ -139,6 +140,7 @@ tuple Token::fromIdentifierOrKeyword(s { if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end()) { + solAssert(m != -1, "Invalid type M in fixed command. Should not reach here."); if (keyword == Token::UInt) return make_tuple(Token::UIntM, m, 0); else @@ -160,6 +162,7 @@ tuple Token::fromIdentifierOrKeyword(s m % 8 == 0 && n % 8 == 0 ) { + solAssert(n != -1, "Invalid type N in fixed command. Should not reach here."); if (keyword == Token::UFixed) return make_tuple(Token::UFixedMxN, m, n); else -- cgit v1.2.3 From 1b39d3b5d479aead729b765a67dfeaba0031c1ca Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Wed, 30 Mar 2016 13:15:54 -0500 Subject: solAsserts added and some changes rolled back. --- libsolidity/parsing/Token.cpp | 2 +- libsolidity/parsing/Token.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 097a6f54..2fbc3886 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -113,7 +113,7 @@ int Token::parseSize(string::const_iterator _begin, string::const_iterator _end) { try { - unsigned int m = boost::lexical_cast(boost::make_iterator_range(_begin, _end)); + unsigned int m = boost::lexical_cast(boost::make_iterator_range(_begin, _end)); return m; } catch(boost::bad_lexical_cast const&) diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index e7a7e24c..76c274bb 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -334,7 +334,8 @@ public: std::string name = Token::toString(m_token); if (tokenValue || (firstNumber() == 0 && secondNumber() == 0)) return name; - else if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN) + solAssert(name.size() >= 3, "Token name size should be greater than 3. Should not reach here."); + if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN) return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber); else return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber); -- cgit v1.2.3 From 3fc67245bf065837a3565fb89b5ee3061c3a2291 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Thu, 31 Mar 2016 12:15:49 -0500 Subject: readding conditionals but with slight changes --- libsolidity/parsing/Token.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 2fbc3886..c73368e5 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -132,7 +132,6 @@ tuple Token::fromIdentifierOrKeyword(s Token::Value keyword = keywordByName(baseType); if (keyword == Token::Bytes) { - solAssert(m != -1, "Invalid type M in fixed command. Should not reach here."); if (0 < m && m <= 32 && positionX == _literal.end()) return make_tuple(Token::BytesM, m, 0); } @@ -140,7 +139,6 @@ tuple Token::fromIdentifierOrKeyword(s { if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end()) { - solAssert(m != -1, "Invalid type M in fixed command. Should not reach here."); if (keyword == Token::UInt) return make_tuple(Token::UIntM, m, 0); else @@ -157,12 +155,13 @@ tuple Token::fromIdentifierOrKeyword(s ) { int n = parseSize(positionX + 1, _literal.end()); if ( + 0 <= m && m <= 256 && + 0 <= n && n <= 256 && m + n > 0 && m + n <= 256 && m % 8 == 0 && n % 8 == 0 ) { - solAssert(n != -1, "Invalid type N in fixed command. Should not reach here."); if (keyword == Token::UFixed) return make_tuple(Token::UFixedMxN, m, n); else -- cgit v1.2.3