summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2023-03-08 15:58:53 +0100
committerLuca Di Sera <luca.disera@qt.io>2023-03-10 11:15:00 +0100
commit9668522b2c702ee04abccc5417636f94dec9811a (patch)
tree843bcadeff745081032a5857d190dd039971155c
parente8f777ffa6117b21a2aaa58bcd22ceb294003f6d (diff)
downloadqttools-9668522b2c702ee04abccc5417636f94dec9811a.tar.gz
QDoc: Move `CodeParser::parseHeaderFile` to `ClangCodeParser`
QDoc parses a series of source file in different languages and formats to find the user-provided documentation. The base parsing interface for elements that perform this process is given by the `CodeParser` class, with the concrete implementation of the process for different languages/formats give by its child classes. `CodeParser`, as part of its interface, provides certain methods that are only meaningful when processing specific programming languages source. For example, it exposes `CodeParser::parseHeaderFile` whose purpose it to provide an entry point for parsing C++ header files. The method is only meaningfully implemented and used in the `ClangCodeParser` child class, the class that actually implements the processing of C++ source files. Hence, the method is now removed from `CodeParser`'s interface and directly exposed as part of the interface of `ClangCodeParser`, to reduce the surface of the method and to reduce the dependencies between `ClangCodeParser` and the `CodeParser` interface, which is generally expected to be removed in the future. `CodeParser` are, currently and temporarily, mostly initialized statically and then retrieved through certain methods of the `CodeParser` interface. `CodeParser::parserForHeaderFile` is one such method that would retrieve a `CodeParser` or child class instance that is able to parse an header file. Due to the removal of `parseHeaderFile` from `CodeParser` interface and the fact that only one specific parser is able, and should be able, to parse header files, `CodeParser::parserForHeaderFile` was removed. Its only usage in "main.cpp", where it was called to retrieve the already available `ClangCodeParser`, was modified to make use of `ClangCodeParser` directly. An auxiliary method, `CodeParser::headerFileNameFilter`, previously used only by `CodeParser::parserForHeaderFile`, which provided a list of extensions to identify what files could be accepted by a certain parser as header files, is now removed as dead code. A non-meaningful reimplementation of the `headerFileNameFilter` method in `CppCodeParser`, a child class of `CodeParser`, was removed as of consequence. Similarly, the same method implementation in `ClangCodeParser` was removed. The filtering functionality that the method indirectly provided when used by `CodeParser::parserForHeaderFile`, which is to be retained for backward compatibility reasons, was moved to `processQdocconfFile` in "main.cpp", where the header files that should be parsed are gathered. Instead of using the `headerFileNameFilter` method, the data that was provided by it is now exposed as a static member of `ClangCodeParser` and accessed directly when filtering is necessary. Change-Id: Iff9a204627675aa7b34232c114945afceb8313ff Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r--src/qdoc/clangcodeparser.cpp17
-rw-r--r--src/qdoc/clangcodeparser.h7
-rw-r--r--src/qdoc/codeparser.cpp25
-rw-r--r--src/qdoc/codeparser.h2
-rw-r--r--src/qdoc/cppcodeparser.cpp8
-rw-r--r--src/qdoc/cppcodeparser.h1
-rw-r--r--src/qdoc/main.cpp12
7 files changed, 16 insertions, 56 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp
index d2338ee32..e3984e502 100644
--- a/src/qdoc/clangcodeparser.cpp
+++ b/src/qdoc/clangcodeparser.cpp
@@ -41,6 +41,10 @@
QT_BEGIN_NAMESPACE
+const QStringList ClangCodeParser::accepted_header_file_extensions{
+ "ch", "h", "h++", "hh", "hpp", "hxx"
+};
+
// We're printing diagnostics in ClangCodeParser::printDiagnostics,
// so avoid clang itself printing them.
static const auto kClangDontDisplayDiagnostics = 0;
@@ -1240,19 +1244,6 @@ QString ClangCodeParser::language()
}
/*!
- Returns a list of extensions for header files.
- */
-QStringList ClangCodeParser::headerFileNameFilter()
-{
- return QStringList() << "*.ch"
- << "*.h"
- << "*.h++"
- << "*.hh"
- << "*.hpp"
- << "*.hxx";
-}
-
-/*!
Returns a list of extensions for source files, i.e. not
header files.
*/
diff --git a/src/qdoc/clangcodeparser.h b/src/qdoc/clangcodeparser.h
index 30d639f9f..24c793714 100644
--- a/src/qdoc/clangcodeparser.h
+++ b/src/qdoc/clangcodeparser.h
@@ -7,6 +7,7 @@
#include "cppcodeparser.h"
#include <QtCore/qtemporarydir.h>
+#include <QtCore/QStringList>
typedef struct CXTranslationUnitImpl *CXTranslationUnit;
@@ -15,14 +16,16 @@ QT_BEGIN_NAMESPACE
class ClangCodeParser : public CppCodeParser
{
public:
+ static const QStringList accepted_header_file_extensions;
+
+public:
~ClangCodeParser() override = default;
void initializeParser() override;
void terminateParser() override;
QString language() override;
- QStringList headerFileNameFilter() override;
QStringList sourceFileNameFilter() override;
- void parseHeaderFile(const Location &location, const QString &filePath) override;
+ void parseHeaderFile(const Location &location, const QString &filePath);
void parseSourceFile(const Location &location, const QString &filePath) override;
void precompileHeaders();
Node *parseFnArg(const Location &location, const QString &fnSignature, const QString &idTag) override;
diff --git a/src/qdoc/codeparser.cpp b/src/qdoc/codeparser.cpp
index 72d1139e4..3c1ceabd1 100644
--- a/src/qdoc/codeparser.cpp
+++ b/src/qdoc/codeparser.cpp
@@ -50,16 +50,6 @@ void CodeParser::terminateParser()
// nothing.
}
-QStringList CodeParser::headerFileNameFilter()
-{
- return sourceFileNameFilter();
-}
-
-void CodeParser::parseHeaderFile(const Location &location, const QString &filePath)
-{
- parseSourceFile(location, filePath);
-}
-
/*!
All the code parsers in the static list are initialized here,
after the qdoc configuration variables have been set.
@@ -88,21 +78,6 @@ CodeParser *CodeParser::parserForLanguage(const QString &language)
return nullptr;
}
-CodeParser *CodeParser::parserForHeaderFile(const QString &filePath)
-{
- QString fileName = QFileInfo(filePath).fileName();
-
- for (const auto &parser : std::as_const(s_parsers)) {
- const QStringList headerPatterns = parser->headerFileNameFilter();
- for (const auto &pattern : headerPatterns) {
- auto re = QRegularExpression::fromWildcard(pattern, Qt::CaseInsensitive);
- if (re.match(fileName).hasMatch())
- return parser;
- }
- }
- return nullptr;
-}
-
CodeParser *CodeParser::parserForSourceFile(const QString &filePath)
{
QString fileName = QFileInfo(filePath).fileName();
diff --git a/src/qdoc/codeparser.h b/src/qdoc/codeparser.h
index ebd433dae..17fd43574 100644
--- a/src/qdoc/codeparser.h
+++ b/src/qdoc/codeparser.h
@@ -23,9 +23,7 @@ public:
virtual void initializeParser();
virtual void terminateParser();
virtual QString language() = 0;
- virtual QStringList headerFileNameFilter();
virtual QStringList sourceFileNameFilter() = 0;
- virtual void parseHeaderFile(const Location &location, const QString &filePath);
virtual void parseSourceFile(const Location &location, const QString &filePath) = 0;
virtual Node *parseFnArg(const Location &, const QString &, const QString & = QString())
{
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp
index 3e16626fc..82753cb61 100644
--- a/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/cppcodeparser.cpp
@@ -136,14 +136,6 @@ void CppCodeParser::terminateParser()
}
/*!
- Returns a list of extensions for header files.
- */
-QStringList CppCodeParser::headerFileNameFilter()
-{
- return QStringList();
-}
-
-/*!
Returns a list of extensions for source files, i.e. not
header files.
*/
diff --git a/src/qdoc/cppcodeparser.h b/src/qdoc/cppcodeparser.h
index b6d718eb9..14ab48661 100644
--- a/src/qdoc/cppcodeparser.h
+++ b/src/qdoc/cppcodeparser.h
@@ -30,7 +30,6 @@ public:
void initializeParser() override;
void terminateParser() override;
QString language() override { return QStringLiteral("Cpp"); }
- QStringList headerFileNameFilter() override;
QStringList sourceFileNameFilter() override;
FunctionNode *parseMacroArg(const Location &location, const QString &macroArg);
FunctionNode *parseOtherFuncArg(const QString &topic, const Location &location,
diff --git a/src/qdoc/main.cpp b/src/qdoc/main.cpp
index d2e0b2625..1d0af6078 100644
--- a/src/qdoc/main.cpp
+++ b/src/qdoc/main.cpp
@@ -480,8 +480,13 @@ static void processQdocconfFile(const QString &fileName)
for (const auto &header : headerList) {
if (header.contains(QLatin1String("doc/snippets")))
continue;
+
if (headers.contains(header))
continue;
+
+ if (!ClangCodeParser::accepted_header_file_extensions.contains(QFileInfo{header}.suffix()))
+ continue;
+
headers.insert(header, header);
QString t = header.mid(header.lastIndexOf('/') + 1);
headerFileNames.insert(t, t);
@@ -521,11 +526,8 @@ static void processQdocconfFile(const QString &fileName)
qCDebug(lcQdoc, "Parsing header files");
for (auto it = headers.constBegin(); it != headers.constEnd(); ++it) {
- CodeParser *codeParser = CodeParser::parserForHeaderFile(it.key());
- if (codeParser) {
- qCDebug(lcQdoc, "Parsing %s", qPrintable(it.key()));
- codeParser->parseHeaderFile(config.location(), it.key());
- }
+ qCDebug(lcQdoc, "Parsing %s", qPrintable(it.key()));
+ clangParser_->parseHeaderFile(config.location(), it.key());
}
clangParser_->precompileHeaders();