diff options
author | Luca Di Sera <luca.disera@qt.io> | 2023-03-24 13:15:22 +0100 |
---|---|---|
committer | Luca Di Sera <luca.disera@qt.io> | 2023-03-27 11:44:51 +0100 |
commit | 23f0761d22bd972b046614fa173b29555b2d2047 (patch) | |
tree | 2ece4ed6b93db6f4134225a968cdcbd2671af971 | |
parent | 2a3f531028e8c59a745d3fb90aecbed18cd759dd (diff) | |
download | qttools-23f0761d22bd972b046614fa173b29555b2d2047.tar.gz |
QDoc: Remove `QmlCodeParser::m_lexer`
As part of producing a documentation set, QDoc parses a series of
user-defined input source files in various languages to extract the
user-provided documentation and certain source-code level elements.
For QML source files, the `QmlCodeParser` class is used, taking care of
reading the QML code and build an internal representation for some of
its elements.
`QmlCodeParser` uses the `QQmlJs` parsing api to do so.
As part of using the `QQmlJs` parsing api, `QmlCodeParser` has to build
a `QQmlJs::Engine`, `QQmlJs::Lexer` and `QQmlJsEngine::Parser`.
Currently, `QmlCodeParser` stores all those elements as instance
members. For example, for the `QQmlJs::Lexer` instance, a member
variable `m_lexer` is used as storage.
Supposedly, this is intended as a way to avoid building the three
elements more than once.
Building a `QQmlJs::Lexer` more than once does not provide any
meaningful overhead, moreover not in the code path where it is used.
Furthermore, `m_lexer` is used only once, in
`QmlCodeParser::parseSourceFile`, the entry point for parsing a QML
source file.
Hence, to reduce the scope of `m_lexer` and avoid requiring an
out-of-scope initialization for it, `m_lexer` is now removed in favor of
an local instance in `QmlCodeParser::parseSourceFile`.
The initialization and deletion of `m_lexer` in
`QmlCodeParser::initializeParser` and `QmlCodeParser::terminateParser`
was removed as a consequence of the removal of the member.
Some comments that mentioned the initialization or deletion of the lexer
were modified to represent the modified code.
Change-Id: I32d38e7883273ab83745eb1f34d183fd5ecca19a
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r-- | src/qdoc/qmlcodeparser.cpp | 11 | ||||
-rw-r--r-- | src/qdoc/qmlcodeparser.h | 1 |
2 files changed, 5 insertions, 7 deletions
diff --git a/src/qdoc/qmlcodeparser.cpp b/src/qdoc/qmlcodeparser.cpp index 902000954..3d8cd5483 100644 --- a/src/qdoc/qmlcodeparser.cpp +++ b/src/qdoc/qmlcodeparser.cpp @@ -16,25 +16,23 @@ QT_BEGIN_NAMESPACE /*! Constructs the QML code parser. */ -QmlCodeParser::QmlCodeParser() : m_lexer(nullptr), m_parser(nullptr) { } +QmlCodeParser::QmlCodeParser() : m_parser(nullptr) { } /*! Initializes the code parser base class. - Also creates a lexer and parser from QQmlJS. + Also creates a parser from QQmlJS. */ void QmlCodeParser::initializeParser() { - m_lexer = new QQmlJS::Lexer(&m_engine); m_parser = new QQmlJS::Parser(&m_engine); } /*! - Terminates the QML code parser. Deletes the lexer and parser + Terminates the QML code parser. Deletes the parser created by the constructor. */ void QmlCodeParser::terminateParser() { - delete m_lexer; delete m_parser; } @@ -82,7 +80,8 @@ void QmlCodeParser::parseSourceFile(const Location &location, const QString &fil QString newCode = document; extractPragmas(newCode); - m_lexer->setCode(newCode, 1); + QQmlJS::Lexer lexer{&m_engine}; + lexer.setCode(newCode, 1); if (m_parser->parse()) { QQmlJS::AST::UiProgram *ast = m_parser->ast(); diff --git a/src/qdoc/qmlcodeparser.h b/src/qdoc/qmlcodeparser.h index 91ee64858..bbf2a1545 100644 --- a/src/qdoc/qmlcodeparser.h +++ b/src/qdoc/qmlcodeparser.h @@ -34,7 +34,6 @@ public: private: QQmlJS::Engine m_engine {}; - QQmlJS::Lexer *m_lexer { nullptr }; QQmlJS::Parser *m_parser { nullptr }; }; |