diff options
author | chriseth <chris@ethereum.org> | 2018-12-01 06:45:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-01 06:45:31 +0800 |
commit | aaeb74f59283486ee95d71f896cf2dd6cbe503f7 (patch) | |
tree | 062fbcc8d84ce2bfa5bb0bb2ef200ba402bb3e8b /liblangutil/Scanner.cpp | |
parent | cc00d8172b6cd7f9fc032e4a21857455ace2f290 (diff) | |
parent | 757623e381aba24b81a2365cf19037d3d96bf945 (diff) | |
download | dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.gz dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.bz2 dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.lz dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.xz dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.tar.zst dexon-solidity-aaeb74f59283486ee95d71f896cf2dd6cbe503f7.zip |
Merge pull request #5537 from ethereum/cp-SourceLocation-related-refactoring
[1/3] SourceLocation related refactoring.
Diffstat (limited to 'liblangutil/Scanner.cpp')
-rw-r--r-- | liblangutil/Scanner.cpp | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/liblangutil/Scanner.cpp b/liblangutil/Scanner.cpp index 215171b3..ac298bd5 100644 --- a/liblangutil/Scanner.cpp +++ b/liblangutil/Scanner.cpp @@ -167,17 +167,23 @@ private: }; // end of LiteralScope class -void Scanner::reset(CharStream _source, string _sourceName) +void Scanner::reset(CharStream _source) { - m_source = std::move(_source); - m_sourceName = make_shared<string const>(std::move(_sourceName)); + m_source = make_shared<CharStream>(std::move(_source)); + reset(); +} + +void Scanner::reset(std::shared_ptr<CharStream> _source) +{ + solAssert(_source.get() != nullptr, "You MUST provide a CharStream when resetting."); + m_source = _source; reset(); } void Scanner::reset() { - m_source.reset(); - m_char = m_source.get(); + m_source->reset(); + m_char = m_source->get(); skipWhitespace(); scanToken(); next(); @@ -296,13 +302,13 @@ Token Scanner::scanSingleLineDocComment() { // check if next line is also a documentation comment skipWhitespace(); - if (!m_source.isPastEndOfInput(3) && - m_source.get(0) == '/' && - m_source.get(1) == '/' && - m_source.get(2) == '/') + if (!m_source->isPastEndOfInput(3) && + m_source->get(0) == '/' && + m_source->get(1) == '/' && + m_source->get(2) == '/') { addCommentLiteralChar('\n'); - m_char = m_source.advanceAndGet(3); + m_char = m_source->advanceAndGet(3); } else break; // next line is not a documentation comment, we are done @@ -355,20 +361,20 @@ Token Scanner::scanMultiLineDocComment() if (isLineTerminator(m_char)) { skipWhitespace(); - if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '*') + if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) == '*') { // it is unknown if this leads to the end of the comment addCommentLiteralChar('*'); advance(); } - else if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) != '/') + else if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) != '/') { // skip first '*' in subsequent lines if (charsAdded) addCommentLiteralChar('\n'); - m_char = m_source.advanceAndGet(2); + m_char = m_source->advanceAndGet(2); } - else if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '/') + else if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) == '/') { // if after newline the comment ends, don't insert the newline - m_char = m_source.advanceAndGet(2); + m_char = m_source->advanceAndGet(2); endFound = true; break; } @@ -376,9 +382,9 @@ Token Scanner::scanMultiLineDocComment() addCommentLiteralChar('\n'); } - if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '/') + if (!m_source->isPastEndOfInput(1) && m_source->get(0) == '*' && m_source->get(1) == '/') { - m_char = m_source.advanceAndGet(2); + m_char = m_source->advanceAndGet(2); endFound = true; break; } @@ -715,11 +721,11 @@ bool Scanner::isUnicodeLinebreak() if (0x0a <= m_char && m_char <= 0x0d) // line feed, vertical tab, form feed, carriage return return true; - else if (!m_source.isPastEndOfInput(1) && uint8_t(m_source.get(0)) == 0xc2 && uint8_t(m_source.get(1)) == 0x85) + else if (!m_source->isPastEndOfInput(1) && uint8_t(m_source->get(0)) == 0xc2 && uint8_t(m_source->get(1)) == 0x85) // NEL - U+0085, C2 85 in utf8 return true; - else if (!m_source.isPastEndOfInput(2) && uint8_t(m_source.get(0)) == 0xe2 && uint8_t(m_source.get(1)) == 0x80 && ( - uint8_t(m_source.get(2)) == 0xa8 || uint8_t(m_source.get(2)) == 0xa9 + else if (!m_source->isPastEndOfInput(2) && uint8_t(m_source->get(0)) == 0xe2 && uint8_t(m_source->get(1)) == 0x80 && ( + uint8_t(m_source->get(2)) == 0xa8 || uint8_t(m_source->get(2)) == 0xa9 )) // LS - U+2028, E2 80 A8 in utf8 // PS - U+2029, E2 80 A9 in utf8 @@ -783,7 +789,7 @@ void Scanner::scanDecimalDigits() // May continue with decimal digit or underscore for grouping. do addLiteralCharAndAdvance(); - while (!m_source.isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_')); + while (!m_source->isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_')); // Defer further validation of underscore to SyntaxChecker. } @@ -829,7 +835,7 @@ Token Scanner::scanNumber(char _charSeen) scanDecimalDigits(); // optional if (m_char == '.') { - if (!m_source.isPastEndOfInput(1) && m_source.get(1) == '_') + if (!m_source->isPastEndOfInput(1) && m_source->get(1) == '_') { // Assume the input may be a floating point number with leading '_' in fraction part. // Recover by consuming it all but returning `Illegal` right away. @@ -837,7 +843,7 @@ Token Scanner::scanNumber(char _charSeen) addLiteralCharAndAdvance(); // '_' scanDecimalDigits(); } - if (m_source.isPastEndOfInput() || !isDecimalDigit(m_source.get(1))) + if (m_source->isPastEndOfInput() || !isDecimalDigit(m_source->get(1))) { // A '.' has to be followed by a number. literal.complete(); @@ -854,7 +860,7 @@ Token Scanner::scanNumber(char _charSeen) solAssert(kind != HEX, "'e'/'E' must be scanned as part of the hex number"); if (kind != DECIMAL) return setError(ScannerError::IllegalExponent); - else if (!m_source.isPastEndOfInput(1) && m_source.get(1) == '_') + else if (!m_source->isPastEndOfInput(1) && m_source->get(1) == '_') { // Recover from wrongly placed underscore as delimiter in literal with scientific // notation by consuming until the end. |