summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2023-03-17 11:13:34 +0100
committerLuca Di Sera <luca.disera@qt.io>2023-03-19 15:04:28 +0000
commita45b2106549e8b0eb665651b053fba3743d50324 (patch)
treead47fe375ae24b86e4565423e4cf4ad122cd7650
parentb3630c567cf2ed22a4b200b4aa72eeb23ba08dfb (diff)
downloadqttools-a45b2106549e8b0eb665651b053fba3743d50324.tar.gz
QDoc: Remove `CodeParser::commonMetaCommands`
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 `CodeParser` provides as part of its interface a series of methods to retrieve the required commands for each parser. One of those methods, `commonMetaCommands`, provides the commands that are common to all parser. `commonMetaCommands` initializes a static member, `commonMetaCommands_` 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 `commonMetaCommands_`, 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 `commonMetaCommands_`, 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 `commonMetaCommands()` method is removed, along with `commonMetaCommands_`, in favor of a public static, `common_meta_commands`, that is initialized in-place, to simplify the related code. `common_meta_commands` is initialized inline under `CodeParser` in "codeparser.h". Its initialization depends on the `COMMAND_*` macros being available. Previously, those macros were defined under `Codeparser` in "codeparser.h" so that they would not be available at the point of initialization. Hence, all definition of the `COMMAND_*` macros were moved higher up in "codeparser.h", to ensure that they would be available when required by `common_meta_commands`. All usages of `commonMetaCommands()` were modified to refer to `CodeParser::common_meta_commands`, keeping an equivalent semantic. Change-Id: If4987e5c1b53e80585e7556e62701690d98954c3 Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r--src/qdoc/codeparser.cpp21
-rw-r--r--src/qdoc/codeparser.h86
-rw-r--r--src/qdoc/cppcodeparser.cpp2
-rw-r--r--src/qdoc/qmlcodeparser.cpp2
4 files changed, 50 insertions, 61 deletions
diff --git a/src/qdoc/codeparser.cpp b/src/qdoc/codeparser.cpp
index 65ee08353..77c7d0f24 100644
--- a/src/qdoc/codeparser.cpp
+++ b/src/qdoc/codeparser.cpp
@@ -84,27 +84,6 @@ CodeParser *CodeParser::parserForSourceFile(const QString &filePath)
return nullptr;
}
-static QSet<QString> commonMetaCommands_;
-/*!
- Returns the set of strings representing the common metacommands.
- */
-const QSet<QString> &CodeParser::commonMetaCommands()
-{
- if (commonMetaCommands_.isEmpty()) {
- commonMetaCommands_ << COMMAND_ABSTRACT << COMMAND_DEFAULT << COMMAND_DEPRECATED
- << COMMAND_INGROUP << COMMAND_INMODULE << COMMAND_INPUBLICGROUP
- << COMMAND_INQMLMODULE << COMMAND_INTERNAL << COMMAND_MODULESTATE
- << COMMAND_NOAUTOLIST << COMMAND_NONREENTRANT << COMMAND_OBSOLETE
- << COMMAND_PRELIMINARY << COMMAND_QMLABSTRACT << COMMAND_QMLDEFAULT
- << COMMAND_QMLINHERITS << COMMAND_QMLREADONLY << COMMAND_QMLREQUIRED
- << COMMAND_QTCMAKEPACKAGE << COMMAND_QTVARIABLE << COMMAND_REENTRANT
- << COMMAND_SINCE << COMMAND_STARTPAGE << COMMAND_SUBTITLE
- << COMMAND_THREADSAFE << COMMAND_TITLE << COMMAND_WRAPPER
- << COMMAND_ATTRIBUTION;
- }
- return commonMetaCommands_;
-}
-
/*!
\internal
*/
diff --git a/src/qdoc/codeparser.h b/src/qdoc/codeparser.h
index 08e06449d..304e83993 100644
--- a/src/qdoc/codeparser.h
+++ b/src/qdoc/codeparser.h
@@ -10,44 +10,6 @@
QT_BEGIN_NAMESPACE
-class Location;
-class QString;
-class QDocDatabase;
-
-class CodeParser
-{
-public:
- CodeParser();
- virtual ~CodeParser();
-
- virtual void initializeParser() = 0;
- virtual void terminateParser();
- virtual QString language() = 0;
- virtual QStringList sourceFileNameFilter() = 0;
- virtual void parseSourceFile(const Location &location, const QString &filePath) = 0;
- virtual Node *parseFnArg(const Location &, const QString &, const QString & = QString())
- {
- return nullptr;
- }
-
- void checkModuleInclusion(Node *n);
-
- static void initialize();
- static void terminate();
- static CodeParser *parserForLanguage(const QString &language);
- static CodeParser *parserForSourceFile(const QString &filePath);
- static void setLink(Node *node, Node::LinkType linkType, const QString &arg);
- static bool isWorthWarningAbout(const Doc &doc);
-
-protected:
- const QSet<QString> &commonMetaCommands();
- static void extractPageLinkAndDesc(QStringView arg, QString *link, QString *desc);
- QDocDatabase *m_qdb {};
-
-private:
- static QList<CodeParser *> s_parsers;
-};
-
#define COMMAND_ABSTRACT QLatin1String("abstract")
#define COMMAND_CLASS QLatin1String("class")
#define COMMAND_DEFAULT QLatin1String("default")
@@ -117,6 +79,54 @@ private:
// deprecated alias of qmlvaluetype
#define COMMAND_QMLBASICTYPE QLatin1String("qmlbasictype")
+class Location;
+class QString;
+class QDocDatabase;
+
+class CodeParser
+{
+public:
+ static inline const QSet<QString> common_meta_commands{
+ COMMAND_ABSTRACT, COMMAND_DEFAULT, COMMAND_DEPRECATED, COMMAND_INGROUP,
+ COMMAND_INMODULE, COMMAND_INPUBLICGROUP, COMMAND_INQMLMODULE, COMMAND_INTERNAL,
+ COMMAND_MODULESTATE, COMMAND_NOAUTOLIST, COMMAND_NONREENTRANT, COMMAND_OBSOLETE,
+ COMMAND_PRELIMINARY, COMMAND_QMLABSTRACT, COMMAND_QMLDEFAULT, COMMAND_QMLINHERITS,
+ COMMAND_QMLREADONLY, COMMAND_QMLREQUIRED, COMMAND_QTCMAKEPACKAGE, COMMAND_QTVARIABLE,
+ COMMAND_REENTRANT, COMMAND_SINCE, COMMAND_STARTPAGE, COMMAND_SUBTITLE, COMMAND_THREADSAFE,
+ COMMAND_TITLE, COMMAND_WRAPPER, COMMAND_ATTRIBUTION,
+ };
+
+public:
+ CodeParser();
+ virtual ~CodeParser();
+
+ virtual void initializeParser() = 0;
+ virtual void terminateParser();
+ virtual QString language() = 0;
+ virtual QStringList sourceFileNameFilter() = 0;
+ virtual void parseSourceFile(const Location &location, const QString &filePath) = 0;
+ virtual Node *parseFnArg(const Location &, const QString &, const QString & = QString())
+ {
+ return nullptr;
+ }
+
+ void checkModuleInclusion(Node *n);
+
+ static void initialize();
+ static void terminate();
+ static CodeParser *parserForLanguage(const QString &language);
+ static CodeParser *parserForSourceFile(const QString &filePath);
+ static void setLink(Node *node, Node::LinkType linkType, const QString &arg);
+ static bool isWorthWarningAbout(const Doc &doc);
+
+protected:
+ static void extractPageLinkAndDesc(QStringView arg, QString *link, QString *desc);
+ QDocDatabase *m_qdb {};
+
+private:
+ static QList<CodeParser *> s_parsers;
+};
+
QT_END_NAMESPACE
#endif
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp
index 0f0cfe1cf..01434f352 100644
--- a/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/cppcodeparser.cpp
@@ -77,7 +77,7 @@ CppCodeParser::CppCodeParser()
<< COMMAND_STRUCT << COMMAND_UNION;
}
if (metaCommands_.isEmpty()) {
- metaCommands_ = commonMetaCommands();
+ metaCommands_ = CodeParser::common_meta_commands;
metaCommands_ << COMMAND_INHEADERFILE << COMMAND_NEXTPAGE
<< COMMAND_OVERLOAD << COMMAND_PREVIOUSPAGE << COMMAND_QMLINSTANTIATES
<< COMMAND_REIMP << COMMAND_RELATES;
diff --git a/src/qdoc/qmlcodeparser.cpp b/src/qdoc/qmlcodeparser.cpp
index e851a2ebd..ce8ddce72 100644
--- a/src/qdoc/qmlcodeparser.cpp
+++ b/src/qdoc/qmlcodeparser.cpp
@@ -79,7 +79,7 @@ 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() + commonMetaCommands(),
+ QmlDocVisitor visitor(filePath, newCode, &m_engine, topicCommands() + CodeParser::common_meta_commands,
topicCommands());
QQmlJS::AST::Node::accept(ast, &visitor);
if (visitor.hasError())