diff --git a/plugins/clang/duchain/duchainutils.cpp b/plugins/clang/duchain/duchainutils.cpp index 4ffa51955a..61314d2580 100644 --- a/plugins/clang/duchain/duchainutils.cpp +++ b/plugins/clang/duchain/duchainutils.cpp @@ -1,112 +1,119 @@ /* * Copyright 2014 Kevin Funk * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "duchainutils.h" #include "util/clangdebug.h" #include #include #include #include #include #include "macrodefinition.h" #include "clangducontext.h" #include "clangparsingenvironmentfile.h" #include "types/classspecializationtype.h" #include "libclang_include_path.h" using namespace KDevelop; namespace ClangIntegration { KTextEditor::Range DUChainUtils::functionSignatureRange(const Declaration* decl) { if (!decl->isFunctionDeclaration()) { qCWarning(KDEV_CLANG) << "Invalid declaration:" << decl; return {}; } auto functionContext = decl->internalContext(); Q_ASSERT(functionContext); auto childContexts = functionContext->childContexts(); if (childContexts.isEmpty()) { return functionContext->rangeInCurrentRevision(); } const auto start = functionContext->rangeInCurrentRevision().start(); const auto end = childContexts[0]->rangeInCurrentRevision().start(); return {start, end}; } void DUChainUtils::registerDUChainItems() { duchainRegisterType(); duchainRegisterType(); duchainRegisterType(); duchainRegisterType(); TypeSystem::self().registerTypeClass(); } void DUChainUtils::unregisterDUChainItems() { TypeSystem::self().unregisterTypeClass(); /// FIXME: this is currently not supported by the DUChain code... /// When the items are unregistered on plugin destruction, we'll get hit by /// assertions later on when the DUChain is finalized. There, when the data is getting cleaned up, /// we try to load all kinds of items again which would fail to find our items if we unregister. /// So let's not do it... /* duchainUnregisterType(); duchainUnregisterType(); duchainUnregisterType(); duchainUnregisterType(); */ } ParseSessionData::Ptr DUChainUtils::findParseSessionData(const IndexedString &file, const IndexedString &tufile) { DUChainReadLocker lock; auto context = KDevelop::DUChainUtils::standardContextForUrl(file.toUrl()); if (!context || !context->ast()) { // no cached data found for the current file, but maybe // we are lucky and can grab it from the TU context // this happens e.g. when originally a .cpp file is open and then one // of its included files is opened in the editor. context = KDevelop::DUChainUtils::standardContextForUrl(tufile.toUrl()); } if (context) { return ParseSessionData::Ptr(dynamic_cast(context->ast().data())); } return {}; } QString DUChainUtils::clangBuiltinIncludePath() { - return qEnvironmentVariable("KDEV_CLANG_BUILTIN_DIR", QStringLiteral(KDEV_CLANG_BUILTIN_DIR)); + static const auto dir = []() -> QString { + auto dir = qgetenv("KDEV_CLANG_BUILTIN_DIR"); + if (dir.isEmpty()) { + dir = KDEV_CLANG_BUILTIN_DIR; + } + return QString::fromUtf8(dir); + }(); + return dir; } }