diff options
-rw-r--r-- | src/qml/parser/qqmljslexer.cpp | 64 | ||||
-rw-r--r-- | src/qml/parser/qqmljslexer_p.h | 6 | ||||
-rw-r--r-- | tests/auto/qml/linebylinelex/tst_linebylinelex.cpp | 18 |
3 files changed, 88 insertions, 0 deletions
diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp index cc552996ea..4fbc5b106f 100644 --- a/src/qml/parser/qqmljslexer.cpp +++ b/src/qml/parser/qqmljslexer.cpp @@ -17,6 +17,7 @@ #include <optional> +QT_BEGIN_NAMESPACE using namespace QQmlJS; static inline int regExpFlagFromChar(const QChar &ch) @@ -437,6 +438,40 @@ QChar Lexer::decodeHexEscapeCharacter(bool *ok) return QChar(); } +namespace QQmlJS { +QDebug operator<<(QDebug dbg, const Lexer &l) +{ + dbg << "{\n" + << " engine:" << qsizetype(l._engine) << ",\n" + << " lexMode:" << int(l._lexMode) << ",\n" + << " code.size:" << qsizetype(l._code.unicode()) << "+" << l._code.size() << ",\n" + << " endPtr: codePtr + " << (l._endPtr - l._codePtr) << ",\n" + << " qmlMode:" << l._qmlMode << ",\n" + << " staticIsKeyword:" << l._staticIsKeyword << ",\n" + << " currentLineNumber:" << l._currentLineNumber << ",\n" + << " currentColumnNumber:" << l._currentColumnNumber << ",\n" + << " currentOffset:" << l._currentOffset << ",\n" + << " tokenLength:" << l._tokenLength << ",\n" + << " tokenLine:" << l._tokenLine << ",\n" + << " tokenColumn:" << l._tokenColumn << ",\n" + << " tokenText:" << l._tokenText << ",\n" + << " skipLinefeed:" << l._skipLinefeed << ",\n" + << " errorMessage:" << l._errorMessage << ",\n" + << " tokenSpell:" << l._tokenSpell << ",\n" + << " rawString:" << l._rawString << ",\n"; + if (l._codePtr) + dbg << " codePtr: code.unicode()+" << (l._codePtr - l._code.unicode()) << ",\n"; + else + dbg << " codePtr: *null*,\n"; + if (l._tokenStartPtr) + dbg << " tokenStartPtr: codePtr " << (l._tokenStartPtr - l._codePtr) << ",\n"; + else + dbg << " tokenStartPtr: *null*,\n"; + dbg << " state:" << l._state << "\n}"; + return dbg; +} +} + static inline bool isIdentifierStart(uint ch) { // fast path for ascii @@ -1766,3 +1801,32 @@ void Lexer::setState(const Lexer::State &state) { _state = state; } + +namespace QQmlJS { +QDebug operator<<(QDebug dbg, const Lexer::State &s) +{ + dbg << "{\n" + << " errorCode:" << int(s.errorCode) << ",\n" + << " currentChar:" << s.currentChar << ",\n" + << " tokenValue:" << s.tokenValue << ",\n" + << " parenthesesState:" << s.parenthesesState << ",\n" + << " parenthesesCount:" << s.parenthesesCount << ",\n" + << " outerTemplateBraceCount:" << s.outerTemplateBraceCount << ",\n" + << " bracesCount:" << s.bracesCount << ",\n" + << " stackToken:" << s.stackToken << ",\n" + << " patternFlags:" << s.patternFlags << ",\n" + << " tokenKind:" << s.tokenKind << ",\n" + << " importState:" << int(s.importState) << ",\n" + << " validTokenText:" << s.validTokenText << ",\n" + << " prohibitAutomaticSemicolon:" << s.prohibitAutomaticSemicolon << ",\n" + << " restrictedKeyword:" << s.restrictedKeyword << ",\n" + << " terminator:" << s.terminator << ",\n" + << " followsClosingBrace:" << s.followsClosingBrace << ",\n" + << " delimited:" << s.delimited << ",\n" + << " handlingDirectives:" << s.handlingDirectives << ",\n" + << " generatorLevel:" << s.generatorLevel << "\n}"; + return dbg; +} +} + +QT_END_NAMESPACE diff --git a/src/qml/parser/qqmljslexer_p.h b/src/qml/parser/qqmljslexer_p.h index a49c1a8f76..242a6ec095 100644 --- a/src/qml/parser/qqmljslexer_p.h +++ b/src/qml/parser/qqmljslexer_p.h @@ -23,6 +23,8 @@ QT_BEGIN_NAMESPACE +class QDebug; + namespace QQmlJS { class Engine; @@ -232,6 +234,8 @@ public: } friend bool operator!=(State const &s1, State const &s2) { return !(s1 == s2); } + + friend QML_PARSER_EXPORT QDebug operator<<(QDebug dbg, State const &s); }; const State &state() const; @@ -265,6 +269,8 @@ private: uint decodeUnicodeEscapeCharacter(bool *ok); QChar decodeHexEscapeCharacter(bool *ok); + friend QML_PARSER_EXPORT QDebug operator<<(QDebug dbg, const Lexer &l); + private: Engine *_engine; diff --git a/tests/auto/qml/linebylinelex/tst_linebylinelex.cpp b/tests/auto/qml/linebylinelex/tst_linebylinelex.cpp index 0d1ad180b9..64dcc9a4ed 100644 --- a/tests/auto/qml/linebylinelex/tst_linebylinelex.cpp +++ b/tests/auto/qml/linebylinelex/tst_linebylinelex.cpp @@ -5,6 +5,9 @@ #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtCore/qplugin.h> #include <QtQml/private/qqmljslexer_p.h> +#include <QtCore/qloggingcategory.h> + +Q_LOGGING_CATEGORY(lexLog, "qt.qml.lex"); QT_USE_NAMESPACE using namespace Qt::StringLiterals; @@ -91,7 +94,9 @@ void TestLineByLineLex::runLex(const QString &fileToLex) QQmlJS::Lexer::State oldState = llLexer.state(); llLexer.setCode(line, 1, isQml, QQmlJS::Lexer::CodeContinuation::Reset); int iLine = 0; + qCDebug(lexLog) << "pre lex" << lexer; int tokenKind = lexer.lex(); + qCDebug(lexLog) << tokenKind << "post lex" << lexer; QList<int> extraTokens({ QQmlJSGrammar::T_COMMENT, QQmlJSGrammar::T_PARTIAL_COMMENT, QQmlJSGrammar::T_PARTIAL_DOUBLE_QUOTE_STRING_LITERAL, QQmlJSGrammar::T_PARTIAL_SINGLE_QUOTE_STRING_LITERAL, @@ -104,18 +109,31 @@ void TestLineByLineLex::runLex(const QString &fileToLex) llLexer2.setCode(line, iLine, isQml, ((iLine == 1) ? QQmlJS::Lexer::CodeContinuation::Reset : QQmlJS::Lexer::CodeContinuation::Continue)); + qCDebug(lexLog) << "line:" << iLine << line; + qCDebug(lexLog) << "llpre lex" << llLexer; int llTokenKind = llLexer.lex(); + qCDebug(lexLog) << llTokenKind << "llpost lex" << llLexer; + qCDebug(lexLog) << "ll2pre lex" << llLexer2; int ll2TokenKind = llLexer2.lex(); + qCDebug(lexLog) << ll2TokenKind << "ll2post lex" << llLexer2; + qCDebug(lexLog) << "token" << llTokenKind << ll2TokenKind; QCOMPARE(llTokenKind, ll2TokenKind); QCOMPARE(llLexer.state(), llLexer2.state()); while (llTokenKind != QQmlJSGrammar::T_EOL) { if (!extraTokens.contains(llTokenKind)) { + qCDebug(lexLog) << "comparing with global lexer" << llTokenKind << tokenKind; QCOMPARE(llTokenKind, tokenKind); QCOMPARE(llLexer.state(), lexer.state()); + qCDebug(lexLog) << "pre lex" << lexer; tokenKind = lexer.lex(); + qCDebug(lexLog) << tokenKind << "post lex" << lexer; } + qCDebug(lexLog) << "llpre lex" << llLexer; llTokenKind = llLexer.lex(); + qCDebug(lexLog) << llTokenKind << "llpost lex" << llLexer; + qCDebug(lexLog) << "ll2pre lex" << llLexer2; ll2TokenKind = llLexer2.lex(); + qCDebug(lexLog) << ll2TokenKind << "ll2post lex" << llLexer2; QCOMPARE(llTokenKind, ll2TokenKind); QCOMPARE(llLexer.state(), llLexer2.state()); } |