summaryrefslogtreecommitdiff
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
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>
-rw-r--r--src/qdoc/clangcodeparser.cpp4
-rw-r--r--src/qdoc/cppcodeparser.cpp24
-rw-r--r--src/qdoc/cppcodeparser.h12
-rw-r--r--src/qdoc/puredocparser.cpp4
4 files changed, 16 insertions, 28 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;
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp
index 01434f352..7c0cee764 100644
--- a/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/cppcodeparser.cpp
@@ -33,7 +33,6 @@ QT_BEGIN_NAMESPACE
QSet<QString> CppCodeParser::m_excludeDirs;
QSet<QString> CppCodeParser::m_excludeFiles;
-static QSet<QString> topicCommands_;
static QSet<QString> metaCommands_;
/*
@@ -63,19 +62,6 @@ static const QMap<QString, NodeTypeTestFunc> s_nodeTypeTestFuncMap{
*/
CppCodeParser::CppCodeParser()
{
- if (topicCommands_.isEmpty()) {
- topicCommands_ << COMMAND_CLASS << COMMAND_DONTDOCUMENT << COMMAND_ENUM << COMMAND_EXAMPLE
- << COMMAND_EXTERNALPAGE << COMMAND_FN << COMMAND_GROUP << COMMAND_HEADERFILE
- << COMMAND_MACRO << COMMAND_MODULE << COMMAND_NAMESPACE << COMMAND_PAGE
- << COMMAND_PROPERTY << COMMAND_TYPEALIAS << COMMAND_TYPEDEF
- << COMMAND_VARIABLE << COMMAND_QMLTYPE << COMMAND_QMLPROPERTY
- << COMMAND_QMLPROPERTYGROUP // mws 13/03/2019
- << COMMAND_QMLATTACHEDPROPERTY << COMMAND_QMLSIGNAL
- << COMMAND_QMLATTACHEDSIGNAL << COMMAND_QMLMETHOD
- << COMMAND_QMLATTACHEDMETHOD << COMMAND_QMLVALUETYPE << COMMAND_QMLBASICTYPE
- << COMMAND_QMLMODULE
- << COMMAND_STRUCT << COMMAND_UNION;
- }
if (metaCommands_.isEmpty()) {
metaCommands_ = CodeParser::common_meta_commands;
metaCommands_ << COMMAND_INHEADERFILE << COMMAND_NEXTPAGE
@@ -138,14 +124,6 @@ QStringList CppCodeParser::sourceFileNameFilter()
}
/*!
- Returns the set of strings representing the topic commands.
- */
-const QSet<QString> &CppCodeParser::topicCommands()
-{
- return topicCommands_;
-}
-
-/*!
Process the topic \a command found in the \a doc with argument \a arg.
*/
Node *CppCodeParser::processTopicCommand(const Doc &doc, const QString &command,
@@ -971,7 +949,7 @@ void CppCodeParser::processMetaCommands(NodeList &nodes, DocList &docs)
*/
bool CppCodeParser::hasTooManyTopics(const Doc &doc) const
{
- const QSet<QString> topicCommandsUsed = topicCommands() & doc.metaCommandsUsed();
+ const QSet<QString> topicCommandsUsed = CppCodeParser::topic_commands & doc.metaCommandsUsed();
if (topicCommandsUsed.empty() || topicCommandsUsed.size() == 1)
return false;
diff --git a/src/qdoc/cppcodeparser.h b/src/qdoc/cppcodeparser.h
index 7869f97c5..7854850db 100644
--- a/src/qdoc/cppcodeparser.h
+++ b/src/qdoc/cppcodeparser.h
@@ -15,6 +15,17 @@ class Aggregate;
class CppCodeParser : public CodeParser
{
+public:
+ static inline const QSet<QString> topic_commands{
+ COMMAND_CLASS, COMMAND_DONTDOCUMENT, COMMAND_ENUM, COMMAND_EXAMPLE,
+ COMMAND_EXTERNALPAGE, COMMAND_FN, COMMAND_GROUP, COMMAND_HEADERFILE,
+ COMMAND_MACRO, COMMAND_MODULE, COMMAND_NAMESPACE, COMMAND_PAGE,
+ COMMAND_PROPERTY, COMMAND_TYPEALIAS, COMMAND_TYPEDEF, COMMAND_VARIABLE,
+ COMMAND_QMLTYPE, COMMAND_QMLPROPERTY, COMMAND_QMLPROPERTYGROUP,
+ COMMAND_QMLATTACHEDPROPERTY, COMMAND_QMLSIGNAL, COMMAND_QMLATTACHEDSIGNAL,
+ COMMAND_QMLMETHOD, COMMAND_QMLATTACHEDMETHOD, COMMAND_QMLVALUETYPE, COMMAND_QMLBASICTYPE,
+ COMMAND_QMLMODULE, COMMAND_STRUCT, COMMAND_UNION,
+ };
public:
CppCodeParser();
@@ -30,7 +41,6 @@ public:
static bool isQMLPropertyTopic(const QString &t);
protected:
- static const QSet<QString> &topicCommands();
static const QSet<QString> &metaCommands();
virtual Node *processTopicCommand(const Doc &doc, const QString &command,
const ArgPair &arg);
diff --git a/src/qdoc/puredocparser.cpp b/src/qdoc/puredocparser.cpp
index 7bbc17b73..86b9bdaa2 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 = topicCommands() + metaCommands();
+ const QSet<QString> &commands = CppCodeParser::topic_commands + metaCommands();
int token = tokenizer.getToken();
while (token != Tok_Eoi) {
@@ -72,7 +72,7 @@ void PureDocParser::processQdocComments(QFile& input_file)
Location end_loc(tokenizer.location());
// Doc constructor parses the comment.
- Doc doc(start_loc, end_loc, comment, commands, topicCommands());
+ Doc doc(start_loc, end_loc, comment, commands, CppCodeParser::topic_commands);
const TopicList &topics = doc.topicsUsed();
if (topics.isEmpty()) {
doc.location().warning(QStringLiteral("This qdoc comment contains no topic command "