diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index 1cac04e8837..a44e22650e9 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -157,15 +157,10 @@ void Lexer::scan(Token *tok) void Lexer::scan_helper(Token *tok) { _Lagain: - _tokenStart = _currentChar; - tok->offset = _currentChar - _firstChar; - while (_yychar && std::isspace(_yychar)) { if (_yychar == '\n') { tok->f.joined = false; tok->f.newline = true; - if (_state == State_MultiLineComment || _state == State_MultiLineDoxyComment) - break; } else { tok->f.whitespace = true; } @@ -175,10 +170,12 @@ void Lexer::scan_helper(Token *tok) if (! _translationUnit) tok->lineno = _currentLine; + _tokenStart = _currentChar; + tok->offset = _currentChar - _firstChar; + if (_state == State_MultiLineComment || _state == State_MultiLineDoxyComment) { const int originalState = _state; - if (! _yychar) { tok->f.kind = T_EOF_SYMBOL; return; @@ -207,9 +204,6 @@ void Lexer::scan_helper(Token *tok) return; // done } - _tokenStart = _currentChar; - tok->offset = _currentChar - _firstChar; - if (! _yychar) { tok->f.kind = T_EOF_SYMBOL; return; diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index c8559f50174..b4a6c63b60c 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -162,15 +162,15 @@ void CppHighlighter::highlightBlock(const QString &text) else if (tk.is(T_STRING_LITERAL) || tk.is(T_CHAR_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL) || tk.is(T_AT_STRING_LITERAL)) - setFormat(tk.begin(), tk.length(), m_formats[CppStringFormat]); + highlightLine(text, tk.begin(), tk.length(), m_formats[CppStringFormat]); else if (tk.is(T_WIDE_STRING_LITERAL) || tk.is(T_WIDE_CHAR_LITERAL)) - setFormat(tk.begin(), tk.length(), m_formats[CppStringFormat]); + highlightLine(text, tk.begin(), tk.length(), m_formats[CppStringFormat]); else if (tk.isComment()) { if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)) - setFormat(tk.begin(), tk.length(), m_formats[CppCommentFormat]); + highlightLine(text, tk.begin(), tk.length(), m_formats[CppCommentFormat]); else // a doxygen comment highlightDoxygenComment(text, tk.begin(), tk.length()); @@ -212,7 +212,7 @@ void CppHighlighter::highlightBlock(const QString &text) const Token tk = tokens.last(); const int lastTokenEnd = tk.begin() + tk.length(); if (text.length() > lastTokenEnd) - setFormat(lastTokenEnd, text.length() - lastTokenEnd, QTextCharFormat()); + highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, QTextCharFormat()); } if (! initialState && state && ! tokens.isEmpty()) { @@ -439,7 +439,7 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position, int k = CppTools::classifyDoxygenTag(start, it - start); if (k != CppTools::T_DOXY_IDENTIFIER) { - setFormat(initial, start - uc - initial, format); + highlightLine(text, initial, start - uc - initial, format); setFormat(start - uc - 1, it - start + 1, kwFormat); initial = it - uc; } @@ -447,6 +447,6 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position, ++it; } - setFormat(initial, it - uc - initial, format); + highlightLine(text, initial, it - uc - initial, format); } diff --git a/tests/auto/cplusplus/misc/tst_misc.cpp b/tests/auto/cplusplus/misc/tst_misc.cpp index 514a333a0af..68d3a4d7b6f 100644 --- a/tests/auto/cplusplus/misc/tst_misc.cpp +++ b/tests/auto/cplusplus/misc/tst_misc.cpp @@ -34,8 +34,6 @@ #include #include -#include -#include #include @@ -52,14 +50,6 @@ private slots: void findBreakpoints(); void findBreakpoints2(); - - void testLexerComment(); - void testLexerComment2(); - void testLexerComment3(); - void testLexerMultiLineComment(); - void testLexerMultiLineComment2(); - void testLexerMultiLineComment3(); - void testLexerMultiLineComment4(); }; void tst_Misc::diagnosticClient_error() @@ -187,107 +177,5 @@ void tst_Misc::findBreakpoints2() QCOMPARE(findBreakpoint(7), 7U); } -void tst_Misc::testLexerComment() { - const QByteArray src("// int a = 42 "); - - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - const QList tokens = tokenize(src); - - QCOMPARE(tokenize.state(), 0); - QCOMPARE(tokens.size(), 1); - QCOMPARE(tokens[0].f.kind, 2U); - QCOMPARE(tokens[0].f.length, 17U); -} - -void tst_Misc::testLexerComment2() { - const QByteArray src(" // int a = 42 "); - - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - const QList tokens = tokenize(src); - - QCOMPARE(tokenize.state(), 0); - QCOMPARE(tokens.size(), 1); - QCOMPARE(tokens[0].f.kind, 2U); - QCOMPARE(tokens[0].f.length, 17U); -} - -void tst_Misc::testLexerComment3() { - const QByteArray src(" int main( int argc, char** argv) { // Foo m_foo = 42 /n"); - - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - const QList tokens = tokenize(src); - - QCOMPARE(tokenize.state(), 0); - QCOMPARE(tokens.size(), 13); - QCOMPARE(tokens.last().f.kind, 2U); - QCOMPARE(tokens.last().f.length, 21U); -} - -void tst_Misc::testLexerMultiLineComment() { - const QByteArray src("/* multi /n" - " * line /n"); - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - const QList tokens = tokenize(src); - - QCOMPARE(tokenize.state(), 1); - QCOMPARE(tokens.size(), 1); - QCOMPARE(tokens[0].f.kind, 4U); - QCOMPARE(tokens.last().f.length, 22U); -} - -void tst_Misc::testLexerMultiLineComment2() { - const QByteArray src(""); - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - QList tokens = tokenize(src,1); - - QCOMPARE(tokenize.state(), 1); - QCOMPARE(tokens.size(), 1); - QCOMPARE(tokens[0].f.kind, 4U); - QCOMPARE(tokens[0].f.length, 1U); -} - -void tst_Misc::testLexerMultiLineComment3() { - const QByteArray src(" "); - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - const QList tokens = tokenize(src,1); - - QCOMPARE(tokenize.state(), 1); - QCOMPARE(tokens.size(), 1); - QCOMPARE(tokens[0].f.kind, 4U); - QCOMPARE(tokens[0].f.length, 5U); -} - -void tst_Misc::testLexerMultiLineComment4() { - const QByteArray src("int /* integer */ i"); - SimpleLexer tokenize; - tokenize.setQtMocRunEnabled(false); - tokenize.setObjCEnabled(false); - tokenize.setCxx0xEnabled(true); - const QList tokens = tokenize(src,0); - - QCOMPARE(tokenize.state(), 0); - QCOMPARE(tokens.size(), 3); - QCOMPARE(tokens[1].f.kind, 4U); - QCOMPARE(tokens[1].f.length, 13U); -} - QTEST_MAIN(tst_Misc) #include "tst_misc.moc"