diff options
author | Luca Di Sera <luca.disera@qt.io> | 2023-03-24 14:09:46 +0100 |
---|---|---|
committer | Luca Di Sera <luca.disera@qt.io> | 2023-03-27 11:45:05 +0100 |
commit | dbd68d439b17f8d3daa253256b3b79e053b01131 (patch) | |
tree | d04b5a1485f91896b110a77539d26d7819928b0f | |
parent | f6291e2163c96e9c6d15c0ac52a8313c4580cb8d (diff) | |
download | qttools-dbd68d439b17f8d3daa253256b3b79e053b01131.tar.gz |
QDoc: Remove `QmlCodeParser::m_engine`
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 the engine element as
an instance member, `m_engine`.
Supposedly, this is intended as a way to avoid building the element more
than once.
Building a `QQmlJs::Engine` more than once does not provide any
meaningful overhead, moreover not in the code path where it is used.
Furthermore, `m_engine` is used only a few times, in
`QmlCodeParser::parseSourceFile`, the entry point for parsing a QML
source file.
Hence, to reduce the scope of `m_engine` and avoid requiring an
out-of-scope initialization for it, `m_engine` is now removed in favor
of a local instance in `QmlCodeParser::parseSourceFile`.
Change-Id: I73f23ec06c1fa3ba3fe50ff4dffc9ff9229c114d
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r-- | src/qdoc/qmlcodeparser.cpp | 8 | ||||
-rw-r--r-- | src/qdoc/qmlcodeparser.h | 3 |
2 files changed, 5 insertions, 6 deletions
diff --git a/src/qdoc/qmlcodeparser.cpp b/src/qdoc/qmlcodeparser.cpp index f2fcea5d3..fadd7c307 100644 --- a/src/qdoc/qmlcodeparser.cpp +++ b/src/qdoc/qmlcodeparser.cpp @@ -57,14 +57,16 @@ void QmlCodeParser::parseSourceFile(const Location &location, const QString &fil QString newCode = document; extractPragmas(newCode); - QQmlJS::Lexer lexer{&m_engine}; + + QQmlJS::Engine engine{}; + QQmlJS::Lexer lexer{&engine}; lexer.setCode(newCode, 1); - QQmlJS::Parser parser{&m_engine}; + QQmlJS::Parser parser{&engine}; if (parser.parse()) { QQmlJS::AST::UiProgram *ast = parser.ast(); - QmlDocVisitor visitor(filePath, newCode, &m_engine, topic_commands + CodeParser::common_meta_commands, + QmlDocVisitor visitor(filePath, newCode, &engine, topic_commands + CodeParser::common_meta_commands, topic_commands); QQmlJS::AST::Node::accept(ast, &visitor); if (visitor.hasError()) diff --git a/src/qdoc/qmlcodeparser.h b/src/qdoc/qmlcodeparser.h index 239e89473..dff493be4 100644 --- a/src/qdoc/qmlcodeparser.h +++ b/src/qdoc/qmlcodeparser.h @@ -31,9 +31,6 @@ public: /* Copied from src/declarative/qml/qdeclarativescriptparser.cpp */ void extractPragmas(QString &script); - -private: - QQmlJS::Engine m_engine {}; }; QT_END_NAMESPACE |