summaryrefslogtreecommitdiff
path: root/src/qdoc/clangcodeparser.cpp
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2023-03-13 11:07:28 +0100
committerLuca Di Sera <luca.disera@qt.io>2023-03-16 12:34:26 +0100
commit80463cbf8d2a7c8fe3068825be8329aa4908b35f (patch)
tree345d81805e4e9d10898dd6d4b1bd15c88532d00b /src/qdoc/clangcodeparser.cpp
parent51204ad805d81ca82775f0afb49380447aa190c5 (diff)
downloadqttools-80463cbf8d2a7c8fe3068825be8329aa4908b35f.tar.gz
QDoc: Remove `CodeParser::m_moduleHeader`
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::setModuleHeader` and `CodeParser::moduleHeader` which are used to provide an PCH-able header file for the C++ headers that will be parsed for a project. Those methods are implemented in the `CodeParser` base-class, along as setter and getter for the instance-state `m_moduleHeader`. Nonetheless, they are only meaningful when running through the `ClangCodeParser` `ClangCodeParser` child class, which actually implements the processing of C++ source files. Those, `m_moduleHeader`, `setModuleHeader` and `getModuleHeader` are now removed from `CodeParser`. `ClangCodeParser` only requires knowledge of the module header in its private method `CLangCodeParser::buildPCH`, where the module header is used to actually produce a precompiled header that will later be used by further call to Clang when parsing C++ source files. Hence, instead of moving the `m_moduleHeader` instance state to `ClangCodeParser`, `buildPCH` and its public entry point `ClangCodeParser::precompileHeaders` were modified to require a `QString` parameter that is equivalent to the original value set through `setModuleHeader`, so as to reduce the of the state to its current lowest. The value of a "module header" is generally given through the configuration for the currently built project and was previously extracted in "main.cpp" and set through `setModuleHeader`. As a consequence of the above changes, the code that took care of setting the module header was modified to pass the relevant value directly to the single call of `ClangCodeParser::precompileHeaders`. Furthermore, the above code was moved directly adjacent to the call to `precompileHeaders` so that it appears nearer to its usage site. Change-Id: I1d4db2fba2807b69e23e182197a78796a2a4675f Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r--src/qdoc/clangcodeparser.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp
index 4e918c2e7..3bcc68af9 100644
--- a/src/qdoc/clangcodeparser.cpp
+++ b/src/qdoc/clangcodeparser.cpp
@@ -1360,15 +1360,15 @@ void ClangCodeParser::getMoreArgs()
files, so it is moved here to its own member function, and
it is called after the list of header files is complete.
*/
-void ClangCodeParser::buildPCH()
+void ClangCodeParser::buildPCH(QString module_header)
{
- if (!m_pchFileDir && !moduleHeader().isEmpty()) {
+ if (!m_pchFileDir && !module_header.isEmpty()) {
m_pchFileDir.reset(new QTemporaryDir(QDir::tempPath() + QLatin1String("/qdoc_pch")));
if (m_pchFileDir->isValid()) {
- const QByteArray module = moduleHeader().toUtf8();
+ const QByteArray module = module_header.toUtf8();
QByteArray header;
QByteArray privateHeaderDir;
- qCDebug(lcQdoc) << "Build and visit PCH for" << moduleHeader();
+ qCDebug(lcQdoc) << "Build and visit PCH for" << module_header;
// A predicate for std::find_if() to locate a path to the module's header
// (e.g. QtGui/QtGui) to be used as pre-compiled header
struct FindPredicate
@@ -1466,7 +1466,7 @@ void ClangCodeParser::buildPCH()
auto error = clang_saveTranslationUnit(tu, m_pchName.constData(),
clang_defaultSaveOptions(tu));
if (error) {
- qCCritical(lcQdoc) << "Could not save PCH file for" << moduleHeader();
+ qCCritical(lcQdoc) << "Could not save PCH file for" << module_header;
m_pchName.clear();
} else {
// Visit the header now, as token from pre-compiled header won't be visited
@@ -1474,11 +1474,11 @@ void ClangCodeParser::buildPCH()
CXCursor cur = clang_getTranslationUnitCursor(tu);
ClangVisitor visitor(m_qdb, m_allHeaders);
visitor.visitChildren(cur);
- qCDebug(lcQdoc) << "PCH built and visited for" << moduleHeader();
+ qCDebug(lcQdoc) << "PCH built and visited for" << module_header;
}
} else {
m_pchFileDir->remove();
- qCCritical(lcQdoc) << "Could not create PCH file for " << moduleHeader();
+ qCCritical(lcQdoc) << "Could not create PCH file for " << module_header;
}
clang_disposeTranslationUnit(tu);
m_args.pop_back(); // remove the "-xc++";
@@ -1489,7 +1489,7 @@ void ClangCodeParser::buildPCH()
/*!
Precompile the header files for the current module.
*/
-void ClangCodeParser::precompileHeaders()
+void ClangCodeParser::precompileHeaders(QString module_header)
{
getDefaultArgs();
getMoreArgs();
@@ -1502,7 +1502,7 @@ void ClangCodeParser::precompileHeaders()
index_ = clang_createIndex(1, kClangDontDisplayDiagnostics);
- buildPCH();
+ buildPCH(module_header);
clang_disposeIndex(index_);
}