Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/duchain/parsesession.cpp
Show All 26 Lines | |||||
27 | #include "clangdiagnosticevaluator.h" | 27 | #include "clangdiagnosticevaluator.h" | ||
28 | #include "todoextractor.h" | 28 | #include "todoextractor.h" | ||
29 | #include "clanghelpers.h" | 29 | #include "clanghelpers.h" | ||
30 | #include "clangindex.h" | 30 | #include "clangindex.h" | ||
31 | #include "clangparsingenvironment.h" | 31 | #include "clangparsingenvironment.h" | ||
32 | #include "util/clangdebug.h" | 32 | #include "util/clangdebug.h" | ||
33 | #include "util/clangtypes.h" | 33 | #include "util/clangtypes.h" | ||
34 | #include "util/clangutils.h" | 34 | #include "util/clangutils.h" | ||
35 | #include "libclang_include_path.h" | ||||
35 | 36 | | |||
36 | #include <language/duchain/duchainlock.h> | 37 | #include <language/duchain/duchainlock.h> | ||
37 | #include <language/duchain/duchain.h> | 38 | #include <language/duchain/duchain.h> | ||
38 | 39 | | |||
39 | #include <KShell> | 40 | #include <KShell> | ||
40 | 41 | | |||
41 | #include <QDir> | 42 | #include <QDir> | ||
42 | #include <QFileInfo> | 43 | #include <QFileInfo> | ||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 185 | { | |||
185 | QVector<CXUnsavedFile> unsaved; | 186 | QVector<CXUnsavedFile> unsaved; | ||
186 | unsaved.reserve(unsavedFiles.size()); | 187 | unsaved.reserve(unsavedFiles.size()); | ||
187 | std::transform(unsavedFiles.begin(), unsavedFiles.end(), | 188 | std::transform(unsavedFiles.begin(), unsavedFiles.end(), | ||
188 | std::back_inserter(unsaved), | 189 | std::back_inserter(unsaved), | ||
189 | [] (const UnsavedFile& file) { return file.toClangApi(); }); | 190 | [] (const UnsavedFile& file) { return file.toClangApi(); }); | ||
190 | return unsaved; | 191 | return unsaved; | ||
191 | } | 192 | } | ||
192 | 193 | | |||
193 | bool needGccCompatibility(const ClangParsingEnvironment& environment) | | |||
194 | { | | |||
195 | const auto& defines = environment.defines(); | | |||
196 | // TODO: potentially do the same for the intel compiler? | | |||
197 | return defines.contains(QStringLiteral("__GNUC__")) | | |||
198 | && !environment.defines().contains(QStringLiteral("__clang__")); | | |||
199 | } | | |||
200 | | ||||
201 | bool hasQtIncludes(const Path::List& includePaths) | 194 | bool hasQtIncludes(const Path::List& includePaths) | ||
202 | { | 195 | { | ||
203 | return std::find_if(includePaths.begin(), includePaths.end(), [] (const Path& path) { | 196 | return std::find_if(includePaths.begin(), includePaths.end(), [] (const Path& path) { | ||
204 | return path.lastPathSegment() == QLatin1String("QtCore"); | 197 | return path.lastPathSegment() == QLatin1String("QtCore"); | ||
205 | }) != includePaths.end(); | 198 | }) != includePaths.end(); | ||
206 | } | 199 | } | ||
207 | 200 | | |||
208 | } | 201 | } | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 222 | #endif | |||
255 | // NOTE: the PCH include must come before all other includes! | 248 | // NOTE: the PCH include must come before all other includes! | ||
256 | if (pchInclude.isValid()) { | 249 | if (pchInclude.isValid()) { | ||
257 | clangArguments << "-include"; | 250 | clangArguments << "-include"; | ||
258 | QByteArray pchFile = pchInclude.toLocalFile().toUtf8(); | 251 | QByteArray pchFile = pchInclude.toLocalFile().toUtf8(); | ||
259 | smartArgs << pchFile; | 252 | smartArgs << pchFile; | ||
260 | clangArguments << pchFile.constData(); | 253 | clangArguments << pchFile.constData(); | ||
261 | } | 254 | } | ||
262 | 255 | | |||
263 | if (needGccCompatibility(environment)) { | | |||
264 | const auto compatFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kdevclangsupport/gcc_compat.h")).toUtf8(); | | |||
265 | if (!compatFile.isEmpty()) { | | |||
266 | smartArgs << compatFile; | | |||
267 | clangArguments << "-include" << compatFile.constData(); | | |||
268 | } | | |||
269 | } | | |||
270 | | ||||
271 | if (hasQtIncludes(includes.system)) { | 256 | if (hasQtIncludes(includes.system)) { | ||
272 | const auto wrappedQtHeaders = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | 257 | const auto wrappedQtHeaders = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||
273 | QStringLiteral("kdevclangsupport/wrappedQtHeaders"), | 258 | QStringLiteral("kdevclangsupport/wrappedQtHeaders"), | ||
274 | QStandardPaths::LocateDirectory).toUtf8(); | 259 | QStandardPaths::LocateDirectory).toUtf8(); | ||
275 | if (!wrappedQtHeaders.isEmpty()) { | 260 | if (!wrappedQtHeaders.isEmpty()) { | ||
276 | smartArgs << wrappedQtHeaders; | 261 | smartArgs << wrappedQtHeaders; | ||
277 | clangArguments << "-isystem" << wrappedQtHeaders.constData(); | 262 | clangArguments << "-isystem" << wrappedQtHeaders.constData(); | ||
278 | const QByteArray qtCore = wrappedQtHeaders + "/QtCore"; | 263 | const QByteArray qtCore = wrappedQtHeaders + "/QtCore"; | ||
279 | smartArgs << qtCore; | 264 | smartArgs << qtCore; | ||
280 | clangArguments << "-isystem" << qtCore.constData(); | 265 | clangArguments << "-isystem" << qtCore.constData(); | ||
281 | } | 266 | } | ||
282 | } | 267 | } | ||
283 | 268 | | |||
284 | addIncludes(&clangArguments, &smartArgs, includes.system, "-isystem"); | 269 | addIncludes(&clangArguments, &smartArgs, includes.system, "-isystem"); | ||
285 | addIncludes(&clangArguments, &smartArgs, includes.project, "-I"); | 270 | addIncludes(&clangArguments, &smartArgs, includes.project, "-I"); | ||
286 | 271 | | |||
287 | const auto& frameworkDirectories = environment.frameworkDirectories(); | 272 | const auto& frameworkDirectories = environment.frameworkDirectories(); | ||
288 | addFrameworkDirectories(&clangArguments, &smartArgs, frameworkDirectories.system, "-iframework"); | 273 | addFrameworkDirectories(&clangArguments, &smartArgs, frameworkDirectories.system, "-iframework"); | ||
289 | addFrameworkDirectories(&clangArguments, &smartArgs, frameworkDirectories.project, "-F"); | 274 | addFrameworkDirectories(&clangArguments, &smartArgs, frameworkDirectories.project, "-F"); | ||
290 | 275 | | |||
276 | // libclang cannot find it's builtin dir automatically, we have to specify it manually | ||||
277 | clangArguments << "-isystem" << KDEV_CLANG_BUILTIN_DIR; | ||||
278 | | ||||
291 | smartArgs << writeDefinesFile(environment.defines()); | 279 | smartArgs << writeDefinesFile(environment.defines()); | ||
292 | clangArguments << "-imacros" << smartArgs.last().constData(); | 280 | clangArguments << "-imacros" << smartArgs.last().constData(); | ||
293 | 281 | | |||
294 | // append extra args from environment variable | 282 | // append extra args from environment variable | ||
295 | static const auto extraArgs = ::extraArgs(); | 283 | static const auto extraArgs = ::extraArgs(); | ||
296 | foreach (const QByteArray& arg, extraArgs) { | 284 | foreach (const QByteArray& arg, extraArgs) { | ||
297 | clangArguments << arg.constData(); | 285 | clangArguments << arg.constData(); | ||
298 | } | 286 | } | ||
▲ Show 20 Lines • Show All 248 Lines • Show Last 20 Lines |