summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2023-03-17 14:20:38 +0100
committerLuca Di Sera <luca.disera@qt.io>2023-03-19 16:04:41 +0100
commitbf03e5a11f4052e74da260bfedcf23f4761113af (patch)
tree2cf3b809db36a7eb56994de5d559319d95e75285
parent105791ef458d50f84387efbd8526671a8d8fd9a6 (diff)
downloadqttools-bf03e5a11f4052e74da260bfedcf23f4761113af.tar.gz
QDoc: Remove `CppCodeParser::metaCommands`
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 some of the `CodeParser` child classes provides series of methods to retrieve the required commands for each parser. `CppCodeParser`, the parser that provides the semantic for QDoc's comment-blocks, for example, provides `metaCommands`, to list the available "meta commands" in a comment-block. `metaCommands` returns a static member, `metaComamnds_`. This static member is initialized during the construction of an `CppCodeParser` instance, and the initialization is made so that it doesn't run more than once, albeit this is done in a non-thread-safe way. The initialization is based on `CppCodeParser::common_meta_commands`, as a base, plus some other commands that are not in `common_meta_commands`. Generally, this process could be better expressed by the use of a static with in-place initialization. There are two probable reasons why this has not been the way it was written in the past. Supposedly, when this code was written, there was no suitable way to initialize a `QSet<QString>`, the type of `metaCommands_`, 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 `metaCommands_`, 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 `metaCommands()` method is removed, along with `metaCommands_`, in favor of a public static, `meta_commands`, that is initialized in-place, to simplify the related code. All usages of `meta_commands` were modified to refer to `CppCodeParser::meta_commands`, keeping an equivalent semantic, as a consequence of the change. As the initialization of `metaCommands_` was the only thing that was being done in the constructor for `CppCodeParser`, the constructor was removed in favor of a default one. Change-Id: I6e54b95a50d07a394d727c0af8c409599a088d4c Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r--src/qdoc/clangcodeparser.cpp2
-rw-r--r--src/qdoc/cppcodeparser.cpp25
-rw-r--r--src/qdoc/cppcodeparser.h9
-rw-r--r--src/qdoc/puredocparser.cpp2
4 files changed, 9 insertions, 29 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp
index b9aa27fbe..4589df9ed 100644
--- a/src/qdoc/clangcodeparser.cpp
+++ b/src/qdoc/clangcodeparser.cpp
@@ -1563,7 +1563,7 @@ void ClangCodeParser::parseSourceFile(const Location & /*location*/, const QStri
CXToken *tokens;
unsigned int numTokens = 0;
- const QSet<QString> &commands = CppCodeParser::topic_commands + metaCommands();
+ const QSet<QString> &commands = CppCodeParser::topic_commands + CppCodeParser::meta_commands;
clang_tokenize(tu, clang_getCursorExtent(tuCur), &tokens, &numTokens);
for (unsigned int i = 0; i < numTokens; ++i) {
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp
index 7c0cee764..341acb6b3 100644
--- a/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/cppcodeparser.cpp
@@ -33,8 +33,6 @@ QT_BEGIN_NAMESPACE
QSet<QString> CppCodeParser::m_excludeDirs;
QSet<QString> CppCodeParser::m_excludeFiles;
-static QSet<QString> metaCommands_;
-
/*
All these can appear in a C++ namespace. Don't add
anything that can't be in a C++ namespace.
@@ -57,20 +55,6 @@ static const QMap<QString, NodeTypeTestFunc> s_nodeTypeTestFuncMap{
};
/*!
- The constructor initializes some regular expressions
- and initializes the tokenizer variables.
- */
-CppCodeParser::CppCodeParser()
-{
- if (metaCommands_.isEmpty()) {
- metaCommands_ = CodeParser::common_meta_commands;
- metaCommands_ << COMMAND_INHEADERFILE << COMMAND_NEXTPAGE
- << COMMAND_OVERLOAD << COMMAND_PREVIOUSPAGE << COMMAND_QMLINSTANTIATES
- << COMMAND_REIMP << COMMAND_RELATES;
- }
-}
-
-/*!
The constructor initializes a map of special node types
for identifying important nodes. And it initializes
some filters for identifying and excluding certain kinds of files.
@@ -377,15 +361,6 @@ void CppCodeParser::processQmlProperties(const Doc &doc, NodeList &nodes, DocLis
}
/*!
- Returns the set of strings representing the common metacommands
- plus some other metacommands.
- */
-const QSet<QString> &CppCodeParser::metaCommands()
-{
- return metaCommands_;
-}
-
-/*!
Process the metacommand \a command in the context of the
\a node associated with the topic command and the \a doc.
\a arg is the argument to the metacommand.
diff --git a/src/qdoc/cppcodeparser.h b/src/qdoc/cppcodeparser.h
index 7854850db..6cf63f740 100644
--- a/src/qdoc/cppcodeparser.h
+++ b/src/qdoc/cppcodeparser.h
@@ -27,8 +27,14 @@ public:
COMMAND_QMLMODULE, COMMAND_STRUCT, COMMAND_UNION,
};
+ static inline const QSet<QString> meta_commands = QSet<QString>(CodeParser::common_meta_commands)
+ << COMMAND_INHEADERFILE << COMMAND_NEXTPAGE
+ << COMMAND_OVERLOAD << COMMAND_PREVIOUSPAGE
+ << COMMAND_QMLINSTANTIATES << COMMAND_REIMP
+ << COMMAND_RELATES;
+
public:
- CppCodeParser();
+ CppCodeParser() = default;
void initializeParser() override;
void terminateParser() override;
@@ -41,7 +47,6 @@ public:
static bool isQMLPropertyTopic(const QString &t);
protected:
- static const QSet<QString> &metaCommands();
virtual Node *processTopicCommand(const Doc &doc, const QString &command,
const ArgPair &arg);
void processQmlProperties(const Doc &doc, NodeList &nodes, DocList &docs);
diff --git a/src/qdoc/puredocparser.cpp b/src/qdoc/puredocparser.cpp
index 86b9bdaa2..931ca253c 100644
--- a/src/qdoc/puredocparser.cpp
+++ b/src/qdoc/puredocparser.cpp
@@ -56,7 +56,7 @@ void PureDocParser::processQdocComments(QFile& input_file)
{
Tokenizer tokenizer(Location{input_file.fileName()}, input_file);
- const QSet<QString> &commands = CppCodeParser::topic_commands + metaCommands();
+ const QSet<QString> &commands = CppCodeParser::topic_commands + CppCodeParser::meta_commands;
int token = tokenizer.getToken();
while (token != Tok_Eoi) {