diff options
author | Martin Smith <martin.smith@qt.io> | 2016-08-29 14:41:46 +0200 |
---|---|---|
committer | Martin Smith <martin.smith@qt.io> | 2017-08-10 07:32:32 +0000 |
commit | 5b090261774ca0b18b0149a960d658ed3d06c3bc (patch) | |
tree | 42beda2b5d826474c197978ae5acb1af21970579 /src/qdoc/clangcodeparser.cpp | |
parent | c9cc240cdc67d816aef5e65ffacf152d9313dd1b (diff) | |
download | qttools-5b090261774ca0b18b0149a960d658ed3d06c3bc.tar.gz |
qdoc: Add "clangdefines" to Config class
The qdoc 'defines' config variable lists values
that contain '*' to represent wildcards, but clang
doesn't accept them. This change adds a new config
variable called 'clangdefines' which explicitly
lists all the defines that match the wildcards.
It also lists several Qt defines for C++11 stuff,
because when clangqdoc comes into use, all the
supported compilers for Qt will support C++11
constructs.
There might be a few defines listed in clangdefines
that are unnecessary and maybe a few that we really
should not include, but we can adjust the list as
needed.
Also included in this change: Tell clang never to fail
(i.e. keep parsing no matter how many errors are found),
and tell clang not to print parsing errors, because they
obscure the qdoc errors in the output. clangqdoc should
assume that the source files are correct, but some of the
include files, especially system level stuff, will not be
present. clangqdoc doesn't care about these missing files,
because they aren't part of the documentation.
Change-Id: I84e1cae24d961a82d16ee705333d6f36955d35de
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 3e76a9ff8..ee7897060 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -721,7 +721,9 @@ ClangCodeParser::~ClangCodeParser() } /*! - + Get the include paths from the qdoc configuration database + \a config. Call the initializeParser() in the base class. + Get the defines list from the qdocconf database. */ void ClangCodeParser::initializeParser(const Config &config) { @@ -733,6 +735,30 @@ void ClangCodeParser::initializeParser(const Config &config) pchFileDir_.reset(nullptr); allHeaders_.clear(); pchName_.clear(); + defines_.clear(); + QSet<QString> accepted; + { + const QStringList tmpDefines = config.getStringList(CONFIG_CLANGDEFINES); + for (const QString &def : tmpDefines) { + if (!accepted.contains(def)) { + QByteArray tmp("-D"); + tmp.append(def.toUtf8()); + defines_.append(tmp.constData()); + accepted.insert(def); + } + } + } + { + const QStringList tmpDefines = config.getStringList(CONFIG_DEFINES); + for (const QString &def : tmpDefines) { + if (!accepted.contains(def) && !def.contains(QChar('*'))) { + QByteArray tmp("-D"); + tmp.append(def.toUtf8()); + defines_.append(tmp.constData()); + accepted.insert(def); + } + } + } } /*! @@ -803,6 +829,9 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin "-I" CLANG_RESOURCE_DIR }; std::vector<const char *> args(std::begin(defaultArgs), std::end(defaultArgs)); + // Add the defines from the qdocconf file. + for (const auto &p : qAsConst(defines_)) + args.push_back(p.constData()); auto moreArgs = includePaths_; if (moreArgs.isEmpty()) { @@ -824,8 +853,9 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin for (const auto &p : qAsConst(moreArgs)) args.push_back(p.constData()); - auto flags = CXTranslationUnit_Incomplete | CXTranslationUnit_SkipFunctionBodies; - CXIndex index = clang_createIndex(1, 1); + auto flags = CXTranslationUnit_Incomplete | CXTranslationUnit_SkipFunctionBodies | + CXTranslationUnit_KeepGoing; + CXIndex index = clang_createIndex(1, 0); if (!pchFileDir_) { pchFileDir_.reset(new QTemporaryDir(QDir::tempPath() + QLatin1String("/qdoc_pch"))); @@ -930,10 +960,18 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin } } } + args.clear(); + args.insert(args.begin(), std::begin(defaultArgs), std::end(defaultArgs)); + // Add the defines from the qdocconf file. + for (const auto &p : qAsConst(defines_)) + args.push_back(p.constData()); if (!pchName_.isEmpty() && !filePath.endsWith(".mm")) { + args.push_back("-w"); args.push_back("-include-pch"); args.push_back(pchName_.constData()); } + for (const auto &p : qAsConst(moreArgs)) + args.push_back(p.constData()); CXTranslationUnit tu; CXErrorCode err = clang_parseTranslationUnit2(index, filePath.toLocal8Bit(), args.data(), |