diff options
author | Luca Di Sera <luca.disera@qt.io> | 2023-03-17 12:40:56 +0100 |
---|---|---|
committer | Luca Di Sera <luca.disera@qt.io> | 2023-03-19 15:04:32 +0000 |
commit | 8adba40d7c780c7ad2b75b6fdc8105568094907b (patch) | |
tree | 85c03375475b7a68fabac172126c06bebfb2eb6c | |
parent | a45b2106549e8b0eb665651b053fba3743d50324 (diff) | |
download | qttools-8adba40d7c780c7ad2b75b6fdc8105568094907b.tar.gz |
QDoc: Remove `QmlCodeParser::topicCommands`
As part of extracting user-provided documentation, QDoc has to parse a
variety of source files in a variety of languages.
`CodeParser` is the base class of objects that take care of performing
this parsing process in QDoc.
When extracting the documentation in one of the `CodeParser`s QDoc
generally tries to parse the extracted documentation in-place.
The documentation has a series of available commands that might depend
on the currently used parser.
To support this process various `CodeParser` child classes provides a
way to access the available commands.
In particular, `QmlCodeParser`, the class that processes QML files,
provides `topicCommands`, a method to retrieve the available topic
commands for documentation extracted by QML files.
`topicCommands` initializes a static member, `topicCommands_`
and then returns it, avoiding initialization if the method is called
more than once.
While this process can be better expressed by the simple use of a
`static` there are two probable reason for why it wasn't done in this
way.
Supposedly, when this code was written, there was no suitable way to
initialize a `QSet<QString>`, the type of `topicCommands_`,
in-place, as similar patterns can be found in other legacy parts of QDoc
that are confirmed to have had this issue due to their age.
Additionally, the expansion of the `COMMAND_*` macros, which form the
content for `topicCommands_`, were, until recently, dependent on
certain data being available in another part of the system, so that
expanding them in a static context that would be processed before this
data was available would incur into a series of errors.
This dependency was removed in a recent patch, so that the issue is no
more.
Hence, the `topicCommands()` method is removed, along with
`topicCommands_`, in favor of a static,
`topic_commands`, that is initialized in-place, to simplify the
related code.
`topicCommands()` only uses were in `QmlCodeParser::parseSourceFile`,
the entry point for the extraction of documentation from a specific QML
file.
Thus, `topic_commands` is now scoped as a static in `parseSourceFile`,
the smaller scope where it is required.
All usages of `topicCommands()` were modified to refer to
`topic_commands`, keeping an equivalent semantic.
Change-Id: Ic97166a9a563f4e8d5ac840999231d92045a6f0d
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r-- | src/qdoc/qmlcodeparser.cpp | 27 | ||||
-rw-r--r-- | src/qdoc/qmlcodeparser.h | 3 |
2 files changed, 9 insertions, 21 deletions
diff --git a/src/qdoc/qmlcodeparser.cpp b/src/qdoc/qmlcodeparser.cpp index ce8ddce72..65f107154 100644 --- a/src/qdoc/qmlcodeparser.cpp +++ b/src/qdoc/qmlcodeparser.cpp @@ -64,6 +64,13 @@ QStringList QmlCodeParser::sourceFileNameFilter() */ void QmlCodeParser::parseSourceFile(const Location &location, const QString &filePath) { + static const QSet<QString> topic_commands{ + COMMAND_VARIABLE, COMMAND_QMLCLASS, COMMAND_QMLTYPE, COMMAND_QMLPROPERTY, + COMMAND_QMLPROPERTYGROUP, COMMAND_QMLATTACHEDPROPERTY, COMMAND_QMLSIGNAL, + COMMAND_QMLATTACHEDSIGNAL, COMMAND_QMLMETHOD, COMMAND_QMLATTACHEDMETHOD, + COMMAND_QMLVALUETYPE, COMMAND_QMLBASICTYPE, + }; + QFile in(filePath); if (!in.open(QIODevice::ReadOnly)) { location.error(QStringLiteral("Cannot open QML file '%1'").arg(filePath)); @@ -79,8 +86,8 @@ void QmlCodeParser::parseSourceFile(const Location &location, const QString &fil if (m_parser->parse()) { QQmlJS::AST::UiProgram *ast = m_parser->ast(); - QmlDocVisitor visitor(filePath, newCode, &m_engine, topicCommands() + CodeParser::common_meta_commands, - topicCommands()); + QmlDocVisitor visitor(filePath, newCode, &m_engine, topic_commands + CodeParser::common_meta_commands, + topic_commands); QQmlJS::AST::Node::accept(ast, &visitor); if (visitor.hasError()) Location(filePath).warning("Could not analyze QML file, output is incomplete."); @@ -92,22 +99,6 @@ void QmlCodeParser::parseSourceFile(const Location &location, const QString &fil } } -static QSet<QString> topicCommands_; -/*! - Returns the set of strings representing the topic commands. - */ -const QSet<QString> &QmlCodeParser::topicCommands() -{ - if (topicCommands_.isEmpty()) { - topicCommands_ << COMMAND_VARIABLE << COMMAND_QMLCLASS << COMMAND_QMLTYPE - << COMMAND_QMLPROPERTY << COMMAND_QMLPROPERTYGROUP // mws 13/03/2019 - << COMMAND_QMLATTACHEDPROPERTY << COMMAND_QMLSIGNAL - << COMMAND_QMLATTACHEDSIGNAL << COMMAND_QMLMETHOD - << COMMAND_QMLATTACHEDMETHOD << COMMAND_QMLVALUETYPE << COMMAND_QMLBASICTYPE; - } - return topicCommands_; -} - /*! Copy and paste from src/declarative/qml/qdeclarativescriptparser.cpp. This function blanks out the section of the \a str beginning at \a idx diff --git a/src/qdoc/qmlcodeparser.h b/src/qdoc/qmlcodeparser.h index 243c552fb..61e9d6c6d 100644 --- a/src/qdoc/qmlcodeparser.h +++ b/src/qdoc/qmlcodeparser.h @@ -32,9 +32,6 @@ public: /* Copied from src/declarative/qml/qdeclarativescriptparser.cpp */ void extractPragmas(QString &script); -protected: - const QSet<QString> &topicCommands(); - private: QQmlJS::Engine m_engine {}; QQmlJS::Lexer *m_lexer { nullptr }; |