summaryrefslogtreecommitdiff
path: root/src/qdoc/clangcodeparser.cpp
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2023-03-17 14:00:02 +0100
committerLuca Di Sera <luca.disera@qt.io>2023-03-19 15:04:37 +0000
commit105791ef458d50f84387efbd8526671a8d8fd9a6 (patch)
treef5126af09a5fc4e2b13b6454e1f25757d551917c /src/qdoc/clangcodeparser.cpp
parent8adba40d7c780c7ad2b75b6fdc8105568094907b (diff)
downloadqttools-105791ef458d50f84387efbd8526671a8d8fd9a6.tar.gz
QDoc: Remove `CppCodeParser::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 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 `topicCommands`, to list the available "topic commands" in a commnet-block. `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 public static, `topic_commands`, that is initialized in-place, to simplify the related code. All usages of `topicCommands` were modified to refer to `CppCodeParser::topic_commands`, keeping an equivalent semantic, as a consequence of the change. Change-Id: I9de2332bf557254e7ffd33290e6af678c2b121aa Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r--src/qdoc/clangcodeparser.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp
index 5bf7a7521..b9aa27fbe 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 = topicCommands() + metaCommands();
+ const QSet<QString> &commands = CppCodeParser::topic_commands + metaCommands();
clang_tokenize(tu, clang_getCursorExtent(tuCur), &tokens, &numTokens);
for (unsigned int i = 0; i < numTokens; ++i) {
@@ -1579,7 +1579,7 @@ void ClangCodeParser::parseSourceFile(const Location & /*location*/, const QStri
Doc::trimCStyleComment(loc, comment);
// Doc constructor parses the comment.
- Doc doc(loc, end_loc, comment, commands, topicCommands());
+ Doc doc(loc, end_loc, comment, commands, CppCodeParser::topic_commands);
if (hasTooManyTopics(doc))
continue;