diff --git a/languages/clang/CMakeLists.txt b/languages/clang/CMakeLists.txt index 26fa8b885e..671c4dec0e 100644 --- a/languages/clang/CMakeLists.txt +++ b/languages/clang/CMakeLists.txt @@ -1,51 +1,135 @@ add_definitions(${LLVM_CFLAGS}) include_directories(${CLANG_INCLUDE_DIRS}) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libs ${KDevelop_SOURCE_DIR}/languages/plugin ) add_subdirectory(tests) add_definitions( -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_BYTEARRAY ) -add_subdirectory(clangsettings) -add_subdirectory(duchain) -add_subdirectory(codecompletion) -add_subdirectory(codegen) -add_subdirectory(util) +# TODO: Move to kdevplatform +function(add_private_library target) + set(options) + set(oneValueArgs) + set(multiValueArgs SOURCES) + cmake_parse_arguments(KDEV_ADD_PRIVATE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + string(REPLACE "KDev" "" shortTargetName ${target}) + if (${shortTargetName} STREQUAL ${target}) + message(FATAL_ERROR "Target passed to add_private_library needs to start with \"KDev\", was \"${target}\"") + endif() + + string(TOLOWER ${shortTargetName} shortTargetNameToLower) + + add_library(${target} SHARED ${KDEV_ADD_PRIVATE_SOURCES}) + generate_export_header(${target} EXPORT_FILE_NAME ${shortTargetNameToLower}export.h) + set_target_properties(${target} PROPERTIES + VERSION ${KDEV_PLUGIN_VERSION} + SOVERSION ${KDEV_PLUGIN_VERSION} + ) + install(TARGETS ${target} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP) +endfunction() + +set(kdevclangprivate_SRCS + clangsettings/clangsettingsmanager.cpp + clangsettings/sessionsettings/sessionsettings.cpp + + codecompletion/completionhelper.cpp + codecompletion/context.cpp + codecompletion/includepathcompletioncontext.cpp + codecompletion/model.cpp + + codegen/adaptsignatureaction.cpp + codegen/adaptsignatureassistant.cpp + codegen/codegenhelper.cpp + + duchain/builder.cpp + duchain/clangdiagnosticevaluator.cpp + duchain/clangducontext.cpp + duchain/clanghelpers.cpp + duchain/clangindex.cpp + duchain/clangparsingenvironment.cpp + duchain/clangparsingenvironmentfile.cpp + duchain/clangpch.cpp + duchain/clangproblem.cpp + duchain/debugvisitor.cpp + duchain/documentfinderhelpers.cpp + duchain/duchainutils.cpp + duchain/macrodefinition.cpp + duchain/macronavigationcontext.cpp + duchain/missingincludepathproblem.cpp + duchain/navigationwidget.cpp + duchain/parsesession.cpp + duchain/todoextractor.cpp + duchain/types/classspecializationtype.cpp + duchain/unknowndeclarationproblem.cpp + duchain/unsavedfile.cpp + + util/clangdebug.cpp + util/clangtypes.cpp + util/clangutils.cpp +) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} +) + +ki18n_wrap_ui(kdevclangprivate_SRCS + clangsettings/sessionsettings/sessionsettings.ui +) + +kconfig_add_kcfg_files(kdevclangprivate_SRCS clangsettings/sessionsettings/sessionconfig.kcfgc) + +add_private_library(KDevClangPrivate SOURCES ${kdevclangprivate_SRCS}) +target_link_libraries(KDevClangPrivate +LINK_PRIVATE + Qt5::Core + KF5::TextEditor + KF5::ThreadWeaver + KDev::Util +LINK_PUBLIC + KDev::Language + KDev::Project + KDev::Util + ${CLANG_LIBCLANG_LIB} +) + +install(FILES duchain/gcc_compat.h DESTINATION ${DATA_INSTALL_DIR}/kdevclangsupport PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) +install(DIRECTORY duchain/wrappedQtHeaders DESTINATION ${DATA_INSTALL_DIR}/kdevclangsupport + DIRECTORY_PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_WRITE GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE + FILE_PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) set(kdevclangsupport_SRCS clangparsejob.cpp clangsupport.cpp clanghighlighting.cpp ) qt5_add_resources(kdevclangsupport_SRCS kdevclangsupport.qrc) kdevplatform_add_plugin(kdevclangsupport JSON kdevclangsupport.json SOURCES ${kdevclangsupport_SRCS}) - target_link_libraries(kdevclangsupport - kdevclangduchain - kdevclangcodecompletion - kdevclangcodegen - kdevclangutil - sessionsettings + KDevClangPrivate KF5::ThreadWeaver KF5::TextEditor KDev::Util KDev::Project ) diff --git a/languages/clang/clangparsejob.cpp b/languages/clang/clangparsejob.cpp index 8e65a7c970..f31750b178 100644 --- a/languages/clang/clangparsejob.cpp +++ b/languages/clang/clangparsejob.cpp @@ -1,369 +1,369 @@ /* This file is part of KDevelop Copyright 2013 Olivier de Gaalon Copyright 2013 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "clangparsejob.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "clangsettings/clangsettingsmanager.h" #include "duchain/clanghelpers.h" #include "duchain/clangpch.h" #include "duchain/duchainutils.h" #include "duchain/parsesession.h" #include "duchain/clangindex.h" #include "duchain/clangparsingenvironmentfile.h" #include "util/clangdebug.h" #include "util/clangtypes.h" #include "clangsupport.h" -#include "documentfinderhelpers.h" +#include "duchain/documentfinderhelpers.h" #include #include #include #include #include #include using namespace KDevelop; namespace { QString findConfigFile(const QString& forFile, const QString& configFileName) { QDir dir = QFileInfo(forFile).dir(); while (dir.exists()) { const QFileInfo customIncludePaths(dir, configFileName); if (customIncludePaths.exists()) { return customIncludePaths.absoluteFilePath(); } if (!dir.cdUp()) { break; } } return {}; } Path::List readPathListFile(const QString& filepath) { if (filepath.isEmpty()) { return {}; } QFile f(filepath); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { return {}; } const QString text = QString::fromLocal8Bit(f.readAll()); const QStringList lines = text.split(QLatin1Char('\n'), QString::SkipEmptyParts); Path::List paths(lines.length()); std::transform(lines.begin(), lines.end(), paths.begin(), [] (const QString& line) { return Path(line); }); return paths; } /** * File should contain the header to precompile and use while parsing * @returns the first path in the file */ Path userDefinedPchIncludeForFile(const QString& sourcefile) { static const QString pchIncludeFilename = QStringLiteral(".kdev_pch_include"); const auto paths = readPathListFile(findConfigFile(sourcefile, pchIncludeFilename)); return paths.isEmpty() ? Path() : paths.first(); } ProjectFileItem* findProjectFileItem(const IndexedString& url, bool* hasBuildSystemInfo) { ProjectFileItem* file = nullptr; *hasBuildSystemInfo = false; for (auto project: ICore::self()->projectController()->projects()) { auto files = project->filesForPath(url); if (files.isEmpty()) { continue; } file = files.last(); // A file might be defined in different targets. // Prefer file items defined inside a target with non-empty includes. for (auto f: files) { if (!dynamic_cast(f->parent())) { continue; } file = f; if (!IDefinesAndIncludesManager::manager()->includes(f, IDefinesAndIncludesManager::ProjectSpecific).isEmpty()) { break; } } } if (file && file->project()) { if (auto bsm = file->project()->buildSystemManager()) { *hasBuildSystemInfo = bsm->hasIncludesOrDefines(file); } } return file; } ClangParsingEnvironmentFile* parsingEnvironmentFile(const TopDUContext* context) { return dynamic_cast(context->parsingEnvironmentFile().data()); } DocumentChangeTracker* trackerForUrl(const IndexedString& url) { return ICore::self()->languageController()->backgroundParser()->trackerForUrl(url); } } ClangParseJob::ClangParseJob(const IndexedString& url, ILanguageSupport* languageSupport) : ParseJob(url, languageSupport) { const auto tuUrl = clang()->index()->translationUnitForUrl(url); bool hasBuildSystemInfo; if (auto file = findProjectFileItem(tuUrl, &hasBuildSystemInfo)) { m_environment.addIncludes(IDefinesAndIncludesManager::manager()->includes(file)); m_environment.addDefines(IDefinesAndIncludesManager::manager()->defines(file)); m_environment.setParserSettings(ClangSettingsManager::self()->parserSettings(file)); } else { m_environment.addIncludes(IDefinesAndIncludesManager::manager()->includes(tuUrl.str())); m_environment.addDefines(IDefinesAndIncludesManager::manager()->defines(tuUrl.str())); m_environment.setParserSettings(ClangSettingsManager::self()->parserSettings(nullptr)); } const bool isSource = ClangHelpers::isSource(tuUrl.str()); m_environment.setQuality( isSource ? (hasBuildSystemInfo ? ClangParsingEnvironment::BuildSystem : ClangParsingEnvironment::Source) : ClangParsingEnvironment::Unknown ); m_environment.setTranslationUnitUrl(tuUrl); Path::List projectPaths; const auto& projects = ICore::self()->projectController()->projects(); projectPaths.reserve(projects.size()); foreach (auto project, projects) { projectPaths.append(project->path()); } m_environment.setProjectPaths(projectPaths); foreach(auto document, ICore::self()->documentController()->openDocuments()) { auto textDocument = document->textDocument(); if (!textDocument || !textDocument->isModified() || !textDocument->url().isLocalFile() || !DocumentFinderHelpers::mimeTypesList().contains(textDocument->mimeType())) { continue; } m_unsavedFiles << UnsavedFile(textDocument->url().toLocalFile(), textDocument->textLines(textDocument->documentRange())); const IndexedString indexedUrl(textDocument->url()); m_unsavedRevisions.insert(indexedUrl, ModificationRevision::revisionForFile(indexedUrl)); } if (auto tracker = trackerForUrl(url)) { tracker->reset(); } } ClangSupport* ClangParseJob::clang() const { return static_cast(languageSupport()); } void ClangParseJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/) { QReadLocker parseLock(languageSupport()->parseLock()); if (abortRequested()) { return; } { const auto tuUrlStr = m_environment.translationUnitUrl().str(); m_environment.addIncludes(IDefinesAndIncludesManager::manager()->includesInBackground(tuUrlStr)); m_environment.addDefines(IDefinesAndIncludesManager::manager()->definesInBackground(tuUrlStr)); m_environment.setPchInclude(userDefinedPchIncludeForFile(tuUrlStr)); } if (abortRequested()) { return; } // NOTE: we must have all declarations, contexts and uses available for files that are opened in the editor // it is very hard to check this for all included files of this TU, and previously lead to problems // when we tried to skip function bodies as an optimization for files that where not open in the editor. // now, we always build everything, which is correct but a tad bit slower. we can try to optimize later. setMinimumFeatures(static_cast(minimumFeatures() | TopDUContext::AllDeclarationsContextsAndUses)); if (minimumFeatures() & AttachASTWithoutUpdating) { // The context doesn't need to be updated, but has no AST attached (restored from disk), // so attach AST to it, without updating DUChain ParseSession session(createSessionData()); DUChainWriteLocker lock; auto ctx = DUChainUtils::standardContextForUrl(document().toUrl()); if (!ctx) { clangDebug() << "Lost context while attaching AST"; return; } ctx->setAst(IAstContainer::Ptr(session.data())); if (minimumFeatures() & UpdateHighlighting) { lock.unlock(); languageSupport()->codeHighlighting()->highlightDUChain(ctx); } return; } { UrlParseLock urlLock(document()); if (abortRequested() || !isUpdateRequired(ParseSession::languageString())) { return; } } ParseSession session(ClangIntegration::DUChainUtils::findParseSessionData(document(), m_environment.translationUnitUrl())); if (abortRequested()) { return; } if (!session.data() || !session.reparse(m_unsavedFiles, m_environment)) { session.setData(createSessionData()); } if (!session.unit()) { // failed to parse file, unpin and don't try again clang()->index()->unpinTranslationUnitForUrl(document()); return; } if (!clang_getFile(session.unit(), document().byteArray().constData())) { // this parse job's document does not exist in the pinned translation unit // so we need to unpin and re-add this document // Ideally we'd reset m_environment and session, but this is much simpler // and shouldn't be a common case clang()->index()->unpinTranslationUnitForUrl(document()); if (!(minimumFeatures() & Rescheduled)) { auto features = static_cast(minimumFeatures() | Rescheduled); ICore::self()->languageController()->backgroundParser()->addDocument(document(), features, priority()); } return; } Imports imports = ClangHelpers::tuImports(session.unit()); IncludeFileContexts includedFiles; if (auto pch = clang()->index()->pch(m_environment)) { auto pchFile = pch->mapFile(session.unit()); includedFiles = pch->mapIncludes(session.unit()); includedFiles.insert(pchFile, pch->context()); auto tuFile = clang_getFile(session.unit(), m_environment.translationUnitUrl().byteArray().constData()); imports.insert(tuFile, { pchFile, CursorInRevision(0, 0) } ); } if (abortRequested()) { return; } auto context = ClangHelpers::buildDUChain(session.mainFile(), imports, session, minimumFeatures(), includedFiles, clang()->index()); setDuChain(context); if (abortRequested()) { return; } if (context) { if (minimumFeatures() & TopDUContext::AST) { DUChainWriteLocker lock; context->setAst(IAstContainer::Ptr(session.data())); } #ifdef QT_DEBUG DUChainReadLocker lock; auto file = parsingEnvironmentFile(context); Q_ASSERT(file); // verify that features and environment where properly set in ClangHelpers::buildDUChain Q_ASSERT(file->featuresSatisfied(TopDUContext::Features(minimumFeatures() & ~TopDUContext::ForceUpdateRecursive))); if (trackerForUrl(context->url())) { Q_ASSERT(file->featuresSatisfied(TopDUContext::AllDeclarationsContextsAndUses)); } #endif } foreach(const auto& context, includedFiles) { if (!context) { continue; } { // prefer the editor modification revision, instead of the on-disk revision auto it = m_unsavedRevisions.find(context->url()); if (it != m_unsavedRevisions.end()) { DUChainWriteLocker lock; auto file = parsingEnvironmentFile(context); Q_ASSERT(file); file->setModificationRevision(it.value()); } } if (trackerForUrl(context->url())) { if (clang()->index()->translationUnitForUrl(context->url()) == m_environment.translationUnitUrl()) { // cache the parse session and the contained translation unit for this chain // this then allows us to quickly reparse the document if it is changed by // the user // otherwise no editor component is open for this document and we can dispose // the TU to save memory // share the session data with all contexts that are pinned to this TU DUChainWriteLocker lock; context->setAst(IAstContainer::Ptr(session.data())); } languageSupport()->codeHighlighting()->highlightDUChain(context); } } } ParseSessionData::Ptr ClangParseJob::createSessionData() const { return ParseSessionData::Ptr(new ParseSessionData(m_unsavedFiles, clang()->index(), m_environment, ParseSessionData::NoOption)); } const ParsingEnvironment* ClangParseJob::environment() const { return &m_environment; } diff --git a/languages/clang/clangsettings/CMakeLists.txt b/languages/clang/clangsettings/CMakeLists.txt deleted file mode 100644 index e840a50c23..0000000000 --- a/languages/clang/clangsettings/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ - -add_library(settingsmanager -STATIC - clangsettingsmanager.cpp -) - -target_link_libraries(settingsmanager -LINK_PUBLIC - KDev::Project - KDev::Util -) - -set(sessionsettings_SRCS - sessionsettings/sessionsettings.cpp -) - -ki18n_wrap_ui(sessionsettings_SRCS - sessionsettings/sessionsettings.ui -) - -kconfig_add_kcfg_files(sessionsettings_SRCS sessionsettings/sessionconfig.kcfgc) - -add_library(sessionsettings -STATIC - ${sessionsettings_SRCS} -) - -target_link_libraries(sessionsettings -LINK_PUBLIC - KDev::Project - KDev::Util -) diff --git a/languages/clang/clangsettings/clangsettingsmanager.h b/languages/clang/clangsettings/clangsettingsmanager.h index 379b747d15..a819ddfd6c 100644 --- a/languages/clang/clangsettings/clangsettingsmanager.h +++ b/languages/clang/clangsettings/clangsettingsmanager.h @@ -1,76 +1,78 @@ /* * This file is part of KDevelop * * Copyright 2015 Sergey Kalinichev * * 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 . * */ #ifndef CLANGSETTINGSMANAGER_H #define CLANGSETTINGSMANAGER_H #include #include +#include "clangprivateexport.h" + class KConfig; namespace KDevelop { class ProjectBaseItem; class IProject; } struct ParserSettings { QString parserOptions; bool isCpp() const; QVector toClangAPI() const; bool operator==(const ParserSettings& rhs) const; }; Q_DECLARE_METATYPE(ParserSettings); struct CodeCompletionSettings { bool macros = true; bool lookAhead = false; }; struct AssistantsSettings { bool forwardDeclare = true; }; -class ClangSettingsManager +class KDEVCLANGPRIVATE_EXPORT ClangSettingsManager { public: static ClangSettingsManager* self(); AssistantsSettings assistantsSettings() const; CodeCompletionSettings codeCompletionSettings() const; ParserSettings parserSettings(KDevelop::ProjectBaseItem* item) const; private: ClangSettingsManager(); bool m_enableTesting = false; friend class CodeCompletionTestBase; }; #endif // CLANGSETTINGSMANAGER_H diff --git a/languages/clang/clangsettings/sessionsettings/sessionconfig.kcfgc b/languages/clang/clangsettings/sessionsettings/sessionconfig.kcfgc index 34e126c758..fa5f046e25 100644 --- a/languages/clang/clangsettings/sessionsettings/sessionconfig.kcfgc +++ b/languages/clang/clangsettings/sessionsettings/sessionconfig.kcfgc @@ -1,5 +1,6 @@ File=sessionconfig.kcfg ClassName=SessionConfig Singleton=true Inherits=SessionConfigSkeleton -IncludeFiles="sessionsettings/sessionconfigskeleton.h" +IncludeFiles=clangsettings/sessionsettings/sessionconfigskeleton.h,clangprivateexport.h +Visibility=KDEVCLANGPRIVATE_EXPORT diff --git a/languages/clang/clangsettings/sessionsettings/sessionsettings.h b/languages/clang/clangsettings/sessionsettings/sessionsettings.h index 1e1168dd54..1973c97c1a 100644 --- a/languages/clang/clangsettings/sessionsettings/sessionsettings.h +++ b/languages/clang/clangsettings/sessionsettings/sessionsettings.h @@ -1,57 +1,58 @@ /* * This file is part of KDevelop * * Copyright 2015 Sergey Kalinichev * * 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 . * */ #ifndef SESSIONSETTINGS_H #define SESSIONSETTINGS_H #include +#include "clangprivateexport.h" #include namespace Ui { class SessionSettings; } -class SessionSettings: public KDevelop::ConfigPage +class KDEVCLANGPRIVATE_EXPORT SessionSettings: public KDevelop::ConfigPage { Q_OBJECT public: explicit SessionSettings(QWidget* parent); ~SessionSettings() override; QString name() const override; QString fullName() const override; QIcon icon() const override; KDevelop::ConfigPage::ConfigPageType configPageType() const override; void apply() override; void reset() override; private: QScopedPointer m_settings; }; #endif // SESSIONSETTINGS_H diff --git a/languages/clang/codecompletion/CMakeLists.txt b/languages/clang/codecompletion/CMakeLists.txt deleted file mode 100644 index 8f7fb7bdce..0000000000 --- a/languages/clang/codecompletion/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_library(kdevclangcodecompletion STATIC - model.cpp - context.cpp - includepathcompletioncontext.cpp - completionhelper.cpp -) -target_link_libraries(kdevclangcodecompletion -LINK_PRIVATE - KF5::TextEditor - KDev::Language - kdevclangduchain -) -set_target_properties(kdevclangcodecompletion PROPERTIES - POSITION_INDEPENDENT_CODE TRUE) diff --git a/languages/clang/codecompletion/context.h b/languages/clang/codecompletion/context.h index de17f7771e..d4e47574a9 100644 --- a/languages/clang/codecompletion/context.h +++ b/languages/clang/codecompletion/context.h @@ -1,80 +1,81 @@ /* * This file is part of KDevelop * Copyright 2014 Milian Wolff * * 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 . */ #ifndef CLANGCODECOMPLETIONCONTEXT_H #define CLANGCODECOMPLETIONCONTEXT_H #include "duchain/parsesession.h" #include #include #include #include "completionhelper.h" +#include "clangprivateexport.h" -class ClangCodeCompletionContext : public KDevelop::CodeCompletionContext +class KDEVCLANGPRIVATE_EXPORT ClangCodeCompletionContext : public KDevelop::CodeCompletionContext { public: enum ContextFilter { NoFilter = 0, ///< Show everything NoBuiltins = 1 << 0, ///< Hide builtin completion items NoMacros = 1 << 1, ///< Hide macro completion items NoDeclarations = 1 << 2, ///< Hide declaration completion items NoClangCompletion = NoBuiltins | NoMacros | NoDeclarations }; Q_DECLARE_FLAGS(ContextFilters, ContextFilter) ClangCodeCompletionContext(const KDevelop::DUContextPointer& context, const ParseSessionData::Ptr& sessionData, const QUrl& url, const KTextEditor::Cursor& position, const QString& text, const QString& followingText = {}); ~ClangCodeCompletionContext(); virtual QList completionItems(bool& abort, bool fullCompletion = true) override; QList ungroupedElements() override; ContextFilters filters() const; void setFilters(const ContextFilters& filters); private: void addOverwritableItems(); void addImplementationHelperItems(); /// Creates the group named @p name and adds it to m_ungrouped if items @p items is not empty void eventuallyAddGroup(const QString& name, int priority, const QList& items); /// Returns whether the we are at a valid completion-position bool isValidPosition(CXTranslationUnit unit, CXFile file) const; std::unique_ptr m_results; QList m_ungrouped; CompletionHelper m_completionHelper; ParseSessionData::Ptr m_parseSessionData; ContextFilters m_filters = NoFilter; }; #endif // CLANGCODECOMPLETIONCONTEXT_H diff --git a/languages/clang/codecompletion/includepathcompletioncontext.h b/languages/clang/codecompletion/includepathcompletioncontext.h index d96ab39598..2f781eaab9 100644 --- a/languages/clang/codecompletion/includepathcompletioncontext.h +++ b/languages/clang/codecompletion/includepathcompletioncontext.h @@ -1,48 +1,49 @@ /* * This file is part of KDevelop * Copyright 2014 Sergey Kalinichev * * 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 . */ #ifndef INCLUDEPATHCOMPLETIONCONTEXT_H #define INCLUDEPATHCOMPLETIONCONTEXT_H #include "duchain/parsesession.h" +#include "clangprivateexport.h" #include #include -class IncludePathCompletionContext : public KDevelop::CodeCompletionContext +class KDEVCLANGPRIVATE_EXPORT IncludePathCompletionContext : public KDevelop::CodeCompletionContext { public: IncludePathCompletionContext(const KDevelop::DUContextPointer& context, const ParseSessionData::Ptr& sessionData, const QUrl& url, const KTextEditor::Cursor& position, const QString& text); virtual QList completionItems(bool& abort, bool fullCompletion = true) override; virtual ~IncludePathCompletionContext() = default; private: QList m_includeItems; }; #endif // INCLUDEPATHCOMPLETIONCONTEXT_H diff --git a/languages/clang/codecompletion/model.h b/languages/clang/codecompletion/model.h index e3162be087..363e7b77b3 100644 --- a/languages/clang/codecompletion/model.h +++ b/languages/clang/codecompletion/model.h @@ -1,60 +1,62 @@ /* * This file is part of KDevelop * Copyright 2014 Milian Wolff * * 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 . */ #ifndef CLANGCODECOMPLETIONMODEL_H #define CLANGCODECOMPLETIONMODEL_H #include #include +#include "clangprivateexport.h" + #include #if KTEXTEDITOR_VERSION < QT_VERSION_CHECK(5, 10, 0) Q_DECLARE_METATYPE(KTextEditor::Cursor) #endif class ClangIndex; -class ClangCodeCompletionModel : public KDevelop::CodeCompletionModel +class KDEVCLANGPRIVATE_EXPORT ClangCodeCompletionModel : public KDevelop::CodeCompletionModel { Q_OBJECT public: explicit ClangCodeCompletionModel(ClangIndex* index, QObject* parent); ~ClangCodeCompletionModel() override; bool shouldStartCompletion(KTextEditor::View* view, const QString& inserted, bool userInsertion, const KTextEditor::Cursor& position) override; signals: void requestCompletion(const QUrl &url, const KTextEditor::Cursor& cursor, const QString& text, const QString& followingText); protected: KDevelop::CodeCompletionWorker* createCompletionWorker() override; void completionInvokedInternal(KTextEditor::View* view, const KTextEditor::Range& range, InvocationType invocationType, const QUrl &url) override; private: ClangIndex* m_index; }; #endif // CLANGCODECOMPLETIONMODEL_H diff --git a/languages/clang/codegen/CMakeLists.txt b/languages/clang/codegen/CMakeLists.txt deleted file mode 100644 index d4a48c53f2..0000000000 --- a/languages/clang/codegen/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_library(kdevclangcodegen STATIC - adaptsignatureaction.cpp - adaptsignatureassistant.cpp - codegenhelper.cpp -) -target_link_libraries(kdevclangcodegen -LINK_PRIVATE - KF5::TextEditor - KF5::ThreadWeaver - KDev::Language - kdevclangduchain -) -set_target_properties(kdevclangcodegen PROPERTIES - POSITION_INDEPENDENT_CODE TRUE) diff --git a/languages/clang/codegen/adaptsignatureassistant.h b/languages/clang/codegen/adaptsignatureassistant.h index d2a5abf6f5..876e64d4d6 100644 --- a/languages/clang/codegen/adaptsignatureassistant.h +++ b/languages/clang/codegen/adaptsignatureassistant.h @@ -1,73 +1,74 @@ /* Copyright 2009 David Nolden Copyright 2014 Kevin Funk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SIGNATUREASSISTANT_H #define SIGNATUREASSISTANT_H #include "adaptsignatureaction.h" +#include "clangprivateexport.h" #include #include #include #include #include namespace KTextEditor { class View; } -class AdaptSignatureAssistant : public KDevelop::StaticAssistant +class KDEVCLANGPRIVATE_EXPORT AdaptSignatureAssistant : public KDevelop::StaticAssistant { Q_OBJECT public: AdaptSignatureAssistant(KDevelop::ILanguageSupport* supportedLanguage); QString title() const override; void textChanged(KTextEditor::View* view, const KTextEditor::Range& invocationRange, const QString& removedText = QString()) override; bool isUseful() const override; private: ///Compare @param newSignature to m_oldSignature and put differences in oldPositions ///@returns whether or not there are any differences bool getSignatureChanges(const Signature &newSignature, QList &oldPositions) const; ///Set default params in @param newSignature based on m_oldSignature's defaults and @param oldPositions void setDefaultParams(Signature &newSignature, const QList &oldPositions) const; ///@returns RenameActions for each parameter in newSignature that has been renamed QList getRenameActions(const Signature &newSignature, const QList &oldPositions) const; // If this is true, the user is editing on the definition side, // and the declaration should be updated bool m_editingDefinition = false; KDevelop::Identifier m_declarationName; KDevelop::DeclarationId m_otherSideId; KDevelop::ReferencedTopDUContext m_otherSideTopContext; KDevelop::DUContextPointer m_otherSideContext; //old signature of the _other_side Signature m_oldSignature; QUrl m_document; QPointer m_view; private slots: void updateReady(const KDevelop::IndexedString& document, const KDevelop::ReferencedTopDUContext& context); void reset(); }; #endif // SIGNATUREASSISTANT_H diff --git a/languages/clang/duchain/CMakeLists.txt b/languages/clang/duchain/CMakeLists.txt deleted file mode 100644 index c13fe178cd..0000000000 --- a/languages/clang/duchain/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -add_library(kdevclangduchain STATIC - parsesession.cpp - clangdiagnosticevaluator.cpp - clangducontext.cpp - clangindex.cpp - clangparsingenvironmentfile.cpp - clangparsingenvironment.cpp - clangproblem.cpp - debugvisitor.cpp - duchainutils.cpp - builder.cpp - clangpch.cpp - clanghelpers.cpp - unknowndeclarationproblem.cpp - macrodefinition.cpp - missingincludepathproblem.cpp - macronavigationcontext.cpp - navigationwidget.cpp - todoextractor.cpp - types/classspecializationtype.cpp - unsavedfile.cpp - documentfinderhelpers.cpp -) - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} -) - -generate_export_header(kdevclangduchain EXPORT_FILE_NAME clangduchainexport.h) -target_link_libraries(kdevclangduchain -LINK_PRIVATE - Qt5::Core - kdevclangcodegen - kdevclangcodecompletion - kdevclangutil - settingsmanager -LINK_PUBLIC - KDev::Language - KDev::Project - KDev::Util - ${CLANG_LIBCLANG_LIB} -) - -install(FILES gcc_compat.h DESTINATION ${DATA_INSTALL_DIR}/kdevclangsupport PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) -install(DIRECTORY wrappedQtHeaders DESTINATION ${DATA_INSTALL_DIR}/kdevclangsupport - DIRECTORY_PERMISSIONS - OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_WRITE GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE - FILE_PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) diff --git a/languages/clang/duchain/builder.h b/languages/clang/duchain/builder.h index 84ddddd67a..3fd9d668b9 100644 --- a/languages/clang/duchain/builder.h +++ b/languages/clang/duchain/builder.h @@ -1,42 +1,42 @@ /* * This file is part of KDevelop * * Copyright 2013 Olivier de Gaalon * Copyright 2015 Milian Wolff +#include "clangprivateexport.h" #include "clanghelpers.h" namespace Builder { /** * Visit the AST in @p tu and build declarations for cursors belonging to @p file. * * @param update Set to true when an existing DUChain cache is getting updated. */ -KDEVCLANGDUCHAIN_EXPORT void visit(CXTranslationUnit tu, CXFile file, +KDEVCLANGPRIVATE_EXPORT void visit(CXTranslationUnit tu, CXFile file, const IncludeFileContexts& includes, const bool update); } #endif //BUILDER_H diff --git a/languages/clang/duchain/clangdiagnosticevaluator.h b/languages/clang/duchain/clangdiagnosticevaluator.h index 8840049faf..cf342cfeab 100644 --- a/languages/clang/duchain/clangdiagnosticevaluator.h +++ b/languages/clang/duchain/clangdiagnosticevaluator.h @@ -1,49 +1,49 @@ /* * 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 . * */ #ifndef CLANGDIAGNOSTICEVALUATOR_H #define CLANGDIAGNOSTICEVALUATOR_H -#include +#include "clangprivateexport.h" #include class ClangProblem; namespace ClangDiagnosticEvaluator { -KDEVCLANGDUCHAIN_EXPORT ClangProblem* createProblem(CXDiagnostic diagnostic, CXTranslationUnit unit); +KDEVCLANGPRIVATE_EXPORT ClangProblem* createProblem(CXDiagnostic diagnostic, CXTranslationUnit unit); enum DiagnosticType { Unknown, UnknownDeclarationProblem, IncludeFileNotFoundProblem, ReplaceWithDotProblem, ReplaceWithArrowProblem }; /** * @return Type of @p diagnostic * @sa DiagnosticType */ -KDEVCLANGDUCHAIN_EXPORT DiagnosticType diagnosticType(CXDiagnostic diagnostic); +KDEVCLANGPRIVATE_EXPORT DiagnosticType diagnosticType(CXDiagnostic diagnostic); } #endif // CLANGDIAGNOSTICEVALUATOR_H diff --git a/languages/clang/duchain/clanghelpers.h b/languages/clang/duchain/clanghelpers.h index 86cbdc683f..9b32128a71 100644 --- a/languages/clang/duchain/clanghelpers.h +++ b/languages/clang/duchain/clanghelpers.h @@ -1,100 +1,100 @@ /* * Copyright 2014 Olivier de Gaalon * Copyright 2014 Milian Wolff * * 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 . */ #ifndef CLANGHELPERS_H #define CLANGHELPERS_H #include #include #include -#include +#include "clangprivateexport.h" class ParseSession; class ClangIndex; struct Import { CXFile file; KDevelop::CursorInRevision location; }; using Imports = QMultiHash; using IncludeFileContexts = QHash; namespace ClangHelpers { KDevelop::DeclarationPointer findDeclaration(CXSourceLocation cursor, const KDevelop::ReferencedTopDUContext& top); KDevelop::DeclarationPointer findDeclaration(CXCursor cursor, const IncludeFileContexts& includes); KDevelop::DeclarationPointer findDeclaration(CXType type, const IncludeFileContexts& includes); /** * Try to look up the first reachable forward declaration for type @p type * * @param context The context where this search is happening * @param cursor The location from which we're searching */ KDevelop::DeclarationPointer findForwardDeclaration(CXType type, KDevelop::DUContext* context, CXCursor cursor); /** * Wrapper for @ref clang_Cursor_getSpellingNameRange which sometimes reports invalid ranges */ KDevelop::RangeInRevision cursorSpellingNameRange(CXCursor cursor, const KDevelop::Identifier& id); /** * @returns all the Imports for each file in the @param tu */ -KDEVCLANGDUCHAIN_EXPORT Imports tuImports(CXTranslationUnit tu); +KDEVCLANGPRIVATE_EXPORT Imports tuImports(CXTranslationUnit tu); /** * Recursively builds a duchain with the specified @param features for the * @param file and each of its @param imports using the TU from @param session. * The resulting contexts are placed in @param includedFiles. * @returns the context created for @param file */ -KDEVCLANGDUCHAIN_EXPORT KDevelop::ReferencedTopDUContext buildDUChain( +KDEVCLANGPRIVATE_EXPORT KDevelop::ReferencedTopDUContext buildDUChain( CXFile file, const Imports& imports, const ParseSession& session, KDevelop::TopDUContext::Features features, IncludeFileContexts& includedFiles, ClangIndex* index = nullptr); /** * @return List of possible header extensions used for definition/declaration fallback switching */ QStringList headerExtensions(); /** * @return List of possible source extensions used for definition/declaration fallback switching */ QStringList sourceExtensions(); /** * @return True if the given file @p path has the extension of a C++ source file */ -bool isSource(const QString& path); +KDEVCLANGPRIVATE_EXPORT bool isSource(const QString& path); /** * @return True if the given file @p path has the extension of a C++ header file */ -bool isHeader(const QString& path); +KDEVCLANGPRIVATE_EXPORT bool isHeader(const QString& path); } #endif //CLANGHELPERS_H diff --git a/languages/clang/duchain/clangindex.h b/languages/clang/duchain/clangindex.h index e5a15c3736..d4a34aad08 100644 --- a/languages/clang/duchain/clangindex.h +++ b/languages/clang/duchain/clangindex.h @@ -1,82 +1,82 @@ /* * This file is part of KDevelop * * Copyright 2013 Olivier de Gaalon * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef CLANGINDEX_H #define CLANGINDEX_H #include "clanghelpers.h" -#include +#include "clangprivateexport.h" #include #include #include #include #include class ClangParsingEnvironment; class ClangPCH; -class KDEVCLANGDUCHAIN_EXPORT ClangIndex +class KDEVCLANGPRIVATE_EXPORT ClangIndex { public: ClangIndex(); ~ClangIndex(); CXIndex index() const; /** * @returns the existing ClangPCH for the @param pchInclude * The PCH is created using @param includePaths and @param defines if it doesn't exist * This function is thread safe. */ QSharedPointer pch(const ClangParsingEnvironment& defines); /** * Gets the currently pinned TU for @p url * * If the currently pinned TU does not import @p url, @p url is returned */ KDevelop::IndexedString translationUnitForUrl(const KDevelop::IndexedString& url); /** * Pin @p tu as the translation unit to use when parsing @p url */ void pinTranslationUnitForUrl(const KDevelop::IndexedString& tu, const KDevelop::IndexedString& url); /** * Unpin any translation unit currently pinned for @p url */ void unpinTranslationUnitForUrl(const KDevelop::IndexedString& url); private: CXIndex m_index; QReadWriteLock m_pchLock; QHash> m_pch; QMutex m_mappingMutex; QHash m_tuForUrl; }; #endif //CLANGINDEX_H diff --git a/languages/clang/duchain/clangparsingenvironment.h b/languages/clang/duchain/clangparsingenvironment.h index 66a2d73d19..c689132504 100644 --- a/languages/clang/duchain/clangparsingenvironment.h +++ b/languages/clang/duchain/clangparsingenvironment.h @@ -1,112 +1,112 @@ /* * This file is part of KDevelop * * Copyright 2014 Milian Wolff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * 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, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CLANGPARSINGENVIRONMENT_H #define CLANGPARSINGENVIRONMENT_H #include #include -#include +#include "clangprivateexport.h" #include "clangsettings/clangsettingsmanager.h" -class KDEVCLANGDUCHAIN_EXPORT ClangParsingEnvironment : public KDevelop::ParsingEnvironment +class KDEVCLANGPRIVATE_EXPORT ClangParsingEnvironment : public KDevelop::ParsingEnvironment { public: virtual ~ClangParsingEnvironment() = default; virtual int type() const override; /** * Sets the list of project paths. * * Any include path outside these project paths is considered * to be a system include. */ void setProjectPaths(const KDevelop::Path::List& projectPaths); KDevelop::Path::List projectPaths() const; /** * Add the given list of @p include paths to this environment. */ void addIncludes(const KDevelop::Path::List& includes); struct IncludePaths { /// This list contains all include paths outside the known projects paths. KDevelop::Path::List system; /// This list contains all include paths inside the known projects paths. KDevelop::Path::List project; }; /** * Returns the list of includes, split into a list of system includes and project includes. */ IncludePaths includes() const; void addDefines(const QHash& defines); QMap defines() const; void setPchInclude(const KDevelop::Path& path); KDevelop::Path pchInclude() const; void setTranslationUnitUrl(const KDevelop::IndexedString& url); KDevelop::IndexedString translationUnitUrl() const; enum Quality { Unknown, Source, BuildSystem }; void setQuality(Quality quality); Quality quality() const; void setParserSettings(const ParserSettings& arguments); ParserSettings parserSettings() const; /** * Hash all contents of this environment and return the result. * * This is useful for a quick comparison, and enough to store on-disk * to figure out if the environment changed or not. */ uint hash() const; bool operator==(const ClangParsingEnvironment& other) const; bool operator!=(const ClangParsingEnvironment& other) const { return !(*this == other); } private: KDevelop::Path::List m_projectPaths; KDevelop::Path::List m_includes; // NOTE: As elements in QHash stored in an unordered sequence, we're using QMap instead QMap m_defines; KDevelop::Path m_pchInclude; KDevelop::IndexedString m_tuUrl; Quality m_quality = Unknown; ParserSettings m_parserSettings; }; #endif // CLANGPARSINGENVIRONMENT_H diff --git a/languages/clang/duchain/clangparsingenvironmentfile.h b/languages/clang/duchain/clangparsingenvironmentfile.h index 1b255281da..08f6d6009f 100644 --- a/languages/clang/duchain/clangparsingenvironmentfile.h +++ b/languages/clang/duchain/clangparsingenvironmentfile.h @@ -1,63 +1,63 @@ /* * * Copyright 2014 Milian Wolff * * 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 . * */ #ifndef CLANGPARSINGENVIRONMENTFILE_H #define CLANGPARSINGENVIRONMENTFILE_H #include "clangparsingenvironment.h" #include -#include +#include "clangprivateexport.h" class ClangParsingEnvironmentFileData; -class KDEVCLANGDUCHAIN_EXPORT ClangParsingEnvironmentFile : public KDevelop::ParsingEnvironmentFile +class KDEVCLANGPRIVATE_EXPORT ClangParsingEnvironmentFile : public KDevelop::ParsingEnvironmentFile { public: using Ptr = QExplicitlySharedDataPointer; ClangParsingEnvironmentFile(const KDevelop::IndexedString& url, const ClangParsingEnvironment& environment); ClangParsingEnvironmentFile(ClangParsingEnvironmentFileData& data); ~ClangParsingEnvironmentFile(); virtual bool needsUpdate(const KDevelop::ParsingEnvironment* environment = 0) const override; virtual int type() const override; virtual bool matchEnvironment(const KDevelop::ParsingEnvironment* environment) const override; void setEnvironment(const ClangParsingEnvironment& environment); ClangParsingEnvironment::Quality environmentQuality() const; uint environmentHash() const; enum { Identity = 142 }; private: DUCHAIN_DECLARE_DATA(ClangParsingEnvironmentFile) }; DUCHAIN_DECLARE_TYPE(ClangParsingEnvironmentFile) #endif // CLANGPARSINGENVIRONMENTFILE_H diff --git a/languages/clang/duchain/clangpch.h b/languages/clang/duchain/clangpch.h index d703f7c57f..1d8cee841e 100644 --- a/languages/clang/duchain/clangpch.h +++ b/languages/clang/duchain/clangpch.h @@ -1,51 +1,51 @@ /* * Copyright 2014 Olivier de Gaalon * * 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 . */ #ifndef CLANGPCH_H #define CLANGPCH_H #include #include #include "parsesession.h" #include "clanghelpers.h" class ClangParsingEnvironment; -class KDEVCLANGDUCHAIN_EXPORT ClangPCH +class KDEVCLANGPRIVATE_EXPORT ClangPCH { public: ClangPCH(const ClangParsingEnvironment& environment, ClangIndex* index); IncludeFileContexts mapIncludes(CXTranslationUnit tu) const; CXFile mapFile(CXTranslationUnit tu) const; KDevelop::ReferencedTopDUContext context() const; private: Q_DISABLE_COPY(ClangPCH); IncludeFileContexts m_includes; KDevelop::ReferencedTopDUContext m_context; ParseSession m_session; }; #endif //CLANGPCH_H diff --git a/languages/clang/duchain/clangproblem.h b/languages/clang/duchain/clangproblem.h index cfebc065e6..840ca9e198 100644 --- a/languages/clang/duchain/clangproblem.h +++ b/languages/clang/duchain/clangproblem.h @@ -1,116 +1,116 @@ /* * 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 . * */ #ifndef CLANGPROBLEM_H #define CLANGPROBLEM_H -#include +#include "clangprivateexport.h" #include #include #include -struct KDEVCLANGDUCHAIN_EXPORT ClangFixit +struct KDEVCLANGPRIVATE_EXPORT ClangFixit { QString replacementText; KDevelop::DocumentRange range; QString description; bool operator==(const ClangFixit& other) const { return replacementText == other.replacementText && range == other.range && description == other.description; } }; -QDebug KDEVCLANGDUCHAIN_EXPORT operator<<(QDebug debug, const ClangFixit& fixit); +QDebug KDEVCLANGPRIVATE_EXPORT operator<<(QDebug debug, const ClangFixit& fixit); using ClangFixits = QVector; -class KDEVCLANGDUCHAIN_EXPORT ClangProblem : public KDevelop::Problem +class KDEVCLANGPRIVATE_EXPORT ClangProblem : public KDevelop::Problem { public: using Ptr = QExplicitlySharedDataPointer; using ConstPtr = QExplicitlySharedDataPointer; /** * Import @p diagnostic into a ClangProblem object * * @param[in] diagnostic To-be-imported clang diagnostic */ ClangProblem(CXDiagnostic diagnostic, CXTranslationUnit unit); KDevelop::IAssistant::Ptr solutionAssistant() const override; ClangFixits fixits() const; void setFixits(const ClangFixits& fixits); /** * Retrieve all fixits of this problem and its child diagnostics * * @return A mapping of problem pointers to the list of associated fixits */ ClangFixits allFixits() const; private: ClangFixits m_fixits; }; -class KDEVCLANGDUCHAIN_EXPORT ClangFixitAssistant : public KDevelop::IAssistant +class KDEVCLANGPRIVATE_EXPORT ClangFixitAssistant : public KDevelop::IAssistant { Q_OBJECT public: ClangFixitAssistant(const ClangFixits& fixits); ClangFixitAssistant(const QString& title, const ClangFixits& fixits); QString title() const override; void createActions() override; ClangFixits fixits() const; private: QString m_title; ClangFixits m_fixits; }; -class KDEVCLANGDUCHAIN_EXPORT ClangFixitAction : public KDevelop::IAssistantAction +class KDEVCLANGPRIVATE_EXPORT ClangFixitAction : public KDevelop::IAssistantAction { Q_OBJECT public: ClangFixitAction(const ClangFixit& fixit); QString description() const override; public Q_SLOTS: void execute() override; private: ClangFixit m_fixit; }; #endif // CLANGPROBLEM_H diff --git a/languages/clang/duchain/debugvisitor.h b/languages/clang/duchain/debugvisitor.h index eaeb6509fe..39ca4520b9 100644 --- a/languages/clang/duchain/debugvisitor.h +++ b/languages/clang/duchain/debugvisitor.h @@ -1,39 +1,39 @@ /* This file is part of KDevelop Copyright 2013 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DEBUGVISITOR_H #define DEBUGVISITOR_H #include "parsesession.h" -#include +#include "clangprivateexport.h" -class KDEVCLANGDUCHAIN_EXPORT DebugVisitor +class KDEVCLANGPRIVATE_EXPORT DebugVisitor { public: DebugVisitor(ParseSession* session); void visit(CXTranslationUnit unit, CXFile file); private: ParseSession* m_session; }; #endif // DEBUGVISITOR_H diff --git a/languages/clang/duchain/documentfinderhelpers.h b/languages/clang/duchain/documentfinderhelpers.h index 7a4014f6ed..52c26516c9 100644 --- a/languages/clang/duchain/documentfinderhelpers.h +++ b/languages/clang/duchain/documentfinderhelpers.h @@ -1,50 +1,52 @@ /* * This file is part of KDevelop * * Copyright 2014 Sergey Kalinichev * * 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) any later version. * * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #ifndef DOCUMENTFINDERHELPERS_H #define DOCUMENTFINDERHELPERS_H #include #include #include +#include "clangprivateexport.h" + /// Helper class for handling @see IBuddyDocumentFinder features. namespace DocumentFinderHelpers { /// @return All supported mime types -QStringList mimeTypesList(); +KDEVCLANGPRIVATE_EXPORT QStringList mimeTypesList(); /** * Considers the URLs as buddy documents if the base path (without extension) * is the same, and one extension starts with h/H and the other one with c/C. * For example, foo.hpp and foo.C are buddies. */ -bool areBuddies(const QUrl &url1, const QUrl& url2); +KDEVCLANGPRIVATE_EXPORT bool areBuddies(const QUrl &url1, const QUrl& url2); /// @see KDevelop::IBuddyDocumentFinder -bool buddyOrder(const QUrl &url1, const QUrl& url2); +KDEVCLANGPRIVATE_EXPORT bool buddyOrder(const QUrl &url1, const QUrl& url2); /// @see KDevelop::IBuddyDocumentFinder -QVector< QUrl > getPotentialBuddies(const QUrl &url, bool checkDUChain = true); +KDEVCLANGPRIVATE_EXPORT QVector< QUrl > getPotentialBuddies(const QUrl &url, bool checkDUChain = true); }; #endif // DOCUMENTFINDERHELPERS_H diff --git a/languages/clang/duchain/duchainutils.h b/languages/clang/duchain/duchainutils.h index 9632c4f932..83e9381dea 100644 --- a/languages/clang/duchain/duchainutils.h +++ b/languages/clang/duchain/duchainutils.h @@ -1,56 +1,56 @@ /* * 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 . */ #ifndef DUCHAINUTILS_H #define DUCHAINUTILS_H -#include +#include "clangprivateexport.h" #include "duchain/parsesession.h" namespace KTextEditor { class Range; } namespace KDevelop { class Declaration; } namespace ClangIntegration { namespace DUChainUtils { -KDEVCLANGDUCHAIN_EXPORT KTextEditor::Range functionSignatureRange(const KDevelop::Declaration* decl); +KDEVCLANGPRIVATE_EXPORT KTextEditor::Range functionSignatureRange(const KDevelop::Declaration* decl); -KDEVCLANGDUCHAIN_EXPORT void registerDUChainItems(); -KDEVCLANGDUCHAIN_EXPORT void unregisterDUChainItems(); +KDEVCLANGPRIVATE_EXPORT void registerDUChainItems(); +KDEVCLANGPRIVATE_EXPORT void unregisterDUChainItems(); /** * Finds attached parse session data (aka AST) to the @p file * * If no session data found, then @p tuFile asked for the attached session data */ -ParseSessionData::Ptr findParseSessionData(const KDevelop::IndexedString &file, const KDevelop::IndexedString &tufile); +KDEVCLANGPRIVATE_EXPORT ParseSessionData::Ptr findParseSessionData(const KDevelop::IndexedString &file, const KDevelop::IndexedString &tufile); }; } #endif // DUCHAINUTILS_H diff --git a/languages/clang/duchain/macrodefinition.h b/languages/clang/duchain/macrodefinition.h index cf5719bf53..ea222e23c2 100644 --- a/languages/clang/duchain/macrodefinition.h +++ b/languages/clang/duchain/macrodefinition.h @@ -1,94 +1,94 @@ /* * 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 . */ #ifndef MACRODEFINITION_H #define MACRODEFINITION_H -#include +#include "clangprivateexport.h" #include #include #include class MacroDefinitionData; /** * @brief Represents a single C/C++ macro definition in the DUCHain * * This declaration represents a single macro definition, such as: * @code * #define FOO_BAR(x) do_something_with(x) * @endcode * * In this example, the identifer is 'FOO_BAR', and the macro is function-like * * @note API designed after of http://clang.llvm.org/doxygen/classclang_1_1MacroInfo.html */ -class KDEVCLANGDUCHAIN_EXPORT MacroDefinition : public KDevelop::Declaration +class KDEVCLANGPRIVATE_EXPORT MacroDefinition : public KDevelop::Declaration { public: using Ptr = KDevelop::DUChainPointer; MacroDefinition(const KDevelop::RangeInRevision& range, KDevelop::DUContext* context); MacroDefinition(MacroDefinitionData& data); MacroDefinition(const MacroDefinition& rhs); virtual ~MacroDefinition(); /** * The definition text of this macro * * Example: * @code * #define FOO_BAR(x) do_something_with(x) * @endcode * * Here, "do_something_with(x)" is the definition text */ KDevelop::IndexedString definition() const; void setDefinition(const KDevelop::IndexedString& definition); /** * Whether this macro is a function or not * * Example: * @code * #define FOO_BAR(x) x // function-like * #define FOO_BAR x // not function-like * @endcode */ bool isFunctionLike() const; void setFunctionLike(bool isFunctionLike); const KDevelop::IndexedString* parameters() const; unsigned int parametersSize() const; void addParameter(const KDevelop::IndexedString& str); void clearParameters(); enum { Identity = 143 }; private: DUCHAIN_DECLARE_DATA(MacroDefinition); }; DUCHAIN_DECLARE_TYPE(MacroDefinition) #endif // MACRODEFINITION_H diff --git a/languages/clang/duchain/macronavigationcontext.h b/languages/clang/duchain/macronavigationcontext.h index c703d487ac..3f924b1341 100644 --- a/languages/clang/duchain/macronavigationcontext.h +++ b/languages/clang/duchain/macronavigationcontext.h @@ -1,53 +1,53 @@ /* Copyright 2007 David Nolden Copyright 2014 Kevin Funk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MACRONAVIGATIONCONTEXT_H #define MACRONAVIGATIONCONTEXT_H -#include +#include "clangprivateexport.h" #include "macrodefinition.h" #include #include #include -class KDEVCLANGDUCHAIN_EXPORT MacroNavigationContext : public KDevelop::AbstractNavigationContext +class KDEVCLANGPRIVATE_EXPORT MacroNavigationContext : public KDevelop::AbstractNavigationContext { public: MacroNavigationContext(const MacroDefinition::Ptr& macro, const KDevelop::DocumentCursor& expansionLocation = KDevelop::DocumentCursor::invalid()); ~MacroNavigationContext(); virtual QWidget* widget() const override; virtual QString html(bool shorten) override; virtual QString name() const override; private: QString retrievePreprocessedBody(const KDevelop::DocumentCursor& expansionLocation) const; const MacroDefinition::Ptr m_macro; QString m_body; KTextEditor::Document* m_preprocessed; KTextEditor::Document* m_definition; QPointer m_widget; }; #endif diff --git a/languages/clang/duchain/navigationwidget.h b/languages/clang/duchain/navigationwidget.h index 8eed105534..a607cdaff2 100644 --- a/languages/clang/duchain/navigationwidget.h +++ b/languages/clang/duchain/navigationwidget.h @@ -1,51 +1,51 @@ /* * This file is part of KDevelop * Copyright 2014 Milian Wolff * 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 . */ #ifndef NAVIGATIONWIDGET_H #define NAVIGATIONWIDGET_H -#include +#include "clangprivateexport.h" #include "macrodefinition.h" #include namespace KDevelop { class DocumentCursor; class IncludeItem; } -class KDEVCLANGDUCHAIN_EXPORT ClangNavigationWidget : public KDevelop::AbstractNavigationWidget +class KDEVCLANGPRIVATE_EXPORT ClangNavigationWidget : public KDevelop::AbstractNavigationWidget { public: ClangNavigationWidget(const KDevelop::DeclarationPointer& declaration); ClangNavigationWidget(const MacroDefinition::Ptr& macro, const KDevelop::DocumentCursor& expansionLocation); ClangNavigationWidget(const KDevelop::IncludeItem& includeItem, KDevelop::TopDUContextPointer topContext, const QString& htmlPrefix = QString(), const QString& htmlSuffix = QString()); virtual ~ClangNavigationWidget() = default; /// Used by @see AbstractIncludeFileCompletionItem static QString shortDescription(const KDevelop::IncludeItem& includeItem); }; #endif // NAVIGATIONWIDGET_H diff --git a/languages/clang/duchain/parsesession.h b/languages/clang/duchain/parsesession.h index e9ce84dc01..38ccd35e1d 100644 --- a/languages/clang/duchain/parsesession.h +++ b/languages/clang/duchain/parsesession.h @@ -1,139 +1,139 @@ /* This file is part of KDevelop Copyright 2013 Olivier de Gaalon Copyright 2013 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PARSESESSION_H #define PARSESESSION_H #include #include #include #include #include #include #include #include -#include +#include "clangprivateexport.h" #include "clangparsingenvironment.h" #include "unsavedfile.h" class ClangIndex; -class KDEVCLANGDUCHAIN_EXPORT ParseSessionData : public KDevelop::IAstContainer +class KDEVCLANGPRIVATE_EXPORT ParseSessionData : public KDevelop::IAstContainer { public: using Ptr = QExplicitlySharedDataPointer; enum Option { NoOption, ///< No special options SkipFunctionBodies, ///< Pass CXTranslationUnit_SkipFunctionBodies (likely unwanted) PrecompiledHeader ///< Pass CXTranslationUnit_PrecompiledPreamble and others to cache precompiled headers }; Q_DECLARE_FLAGS(Options, Option) /** * Parse the given @p contents. * * @param unsavedFiles Optional unsaved document contents from the editor. */ ParseSessionData(const QVector& unsavedFiles, ClangIndex* index, const ClangParsingEnvironment& environment, Options options = Options()); ~ParseSessionData(); ClangParsingEnvironment environment() const; private: friend class ParseSession; void setUnit(CXTranslationUnit unit); QMutex m_mutex; CXFile m_file = nullptr; CXTranslationUnit m_unit = nullptr; ClangParsingEnvironment m_environment; /// TODO: share this file for all TUs that use the same defines (probably most in a project) /// best would be a PCH, if possible QTemporaryFile m_definesFile; }; /** * Thread-safe utility class around a CXTranslationUnit. * * It will lock the mutex of the currently set ParseSessionData and thereby ensure * only one ParseSession can operate on a given CXTranslationUnit stored therein. */ -class KDEVCLANGDUCHAIN_EXPORT ParseSession +class KDEVCLANGPRIVATE_EXPORT ParseSession { public: /** * @return a unique identifier for Clang documents. */ static KDevelop::IndexedString languageString(); /** * Initialize a parse session with the given data and, if that data is valid, lock its mutex. */ ParseSession(const ParseSessionData::Ptr& data); /** * Unlocks the mutex of the currently set ParseSessionData. */ ~ParseSession(); /** * Unlocks the mutex of the currently set ParseSessionData, and instead acquire the lock in @p data. */ void setData(const ParseSessionData::Ptr& data); ParseSessionData::Ptr data() const; /** * @return find the CXFile for the given path. */ CXFile file(const QByteArray& path) const; /** * @return the CXFile for the first file in this translation unit. */ CXFile mainFile() const; QList problemsForFile(CXFile file) const; CXTranslationUnit unit() const; bool reparse(const QVector& unsavedFiles, const ClangParsingEnvironment& environment); ClangParsingEnvironment environment() const; private: Q_DISABLE_COPY(ParseSession); ParseSessionData::Ptr d; }; #endif // PARSESESSION_H diff --git a/languages/clang/duchain/todoextractor.h b/languages/clang/duchain/todoextractor.h index cc92d8a86d..83e718aee9 100644 --- a/languages/clang/duchain/todoextractor.h +++ b/languages/clang/duchain/todoextractor.h @@ -1,51 +1,51 @@ /* * 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 . * */ #ifndef TODOEXTRACTOR_H #define TODOEXTRACTOR_H -#include +#include "clangprivateexport.h" #include #include -class KDEVCLANGDUCHAIN_EXPORT TodoExtractor +class KDEVCLANGPRIVATE_EXPORT TodoExtractor { public: TodoExtractor(CXTranslationUnit unit, CXFile file); /** * Retrieve the list of to-do problems this instance found */ QList problems() const; private: void extractTodos(); CXTranslationUnit m_unit; CXFile m_file; QStringList m_todoMarkerWords; QList m_problems; }; #endif // TODOEXTRACTOR_H diff --git a/languages/clang/duchain/unknowndeclarationproblem.h b/languages/clang/duchain/unknowndeclarationproblem.h index 9213ccc042..8d3bc83dd9 100644 --- a/languages/clang/duchain/unknowndeclarationproblem.h +++ b/languages/clang/duchain/unknowndeclarationproblem.h @@ -1,48 +1,48 @@ /* * Copyright 2014 Jørgen Kvalsvik * 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 . * */ #ifndef UNKNOWNDECLARATION_H #define UNKNOWNDECLARATION_H -#include +#include "clangprivateexport.h" #include "clangproblem.h" #include -class KDEVCLANGDUCHAIN_EXPORT UnknownDeclarationProblem : public ClangProblem +class KDEVCLANGPRIVATE_EXPORT UnknownDeclarationProblem : public ClangProblem { public: using Ptr = QExplicitlySharedDataPointer; using ConstPtr = QExplicitlySharedDataPointer; UnknownDeclarationProblem(CXDiagnostic diagnostic, CXTranslationUnit unit); void setSymbol(const KDevelop::QualifiedIdentifier& identifier); virtual KDevelop::IAssistant::Ptr solutionAssistant() const override; private: KDevelop::QualifiedIdentifier m_identifier; }; #endif // UNKNOWNDECLARATION_H diff --git a/languages/clang/duchain/unsavedfile.h b/languages/clang/duchain/unsavedfile.h index b61f79e597..a3442c7304 100644 --- a/languages/clang/duchain/unsavedfile.h +++ b/languages/clang/duchain/unsavedfile.h @@ -1,50 +1,52 @@ /* This file is part of KDevelop Copyright 2015 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef UNSAVEDFILE_H #define UNSAVEDFILE_H #include +#include "clangprivateexport.h" + struct CXUnsavedFile; /** * Wrapper API to map unsaved editor contents to the CXUnsavedFile API for clang. */ -class UnsavedFile +class KDEVCLANGPRIVATE_EXPORT UnsavedFile { public: UnsavedFile(const QString& fileName = {}, const QStringList& contents = {}); CXUnsavedFile toClangApi() const; private: QString m_fileName; QStringList m_contents; // lazy-loaded byte arrays for usage in clang API void convertToUtf8(); QByteArray m_fileNameUtf8; QByteArray m_contentsUtf8; }; Q_DECLARE_TYPEINFO(UnsavedFile, Q_MOVABLE_TYPE); #endif // UNSAVEDFILE_H diff --git a/languages/clang/tests/CMakeLists.txt b/languages/clang/tests/CMakeLists.txt index c47744e4f5..3205095217 100644 --- a/languages/clang/tests/CMakeLists.txt +++ b/languages/clang/tests/CMakeLists.txt @@ -1,99 +1,96 @@ add_executable(clang-parser clang-parser.cpp ) target_link_libraries(clang-parser KDev::Tests - kdevclangduchain + KDevClangPrivate ) add_library(codecompletiontestbase STATIC codecompletiontestbase.cpp) target_link_libraries(codecompletiontestbase PUBLIC KDev::Tests Qt5::Test - kdevclangcodecompletion - kdevclangduchain + KDevClangPrivate ) add_executable(clang-minimal-visitor WIN32 minimal_visitor.cpp ) ecm_mark_nongui_executable(clang-minimal-visitor) target_link_libraries(clang-minimal-visitor ${CLANG_LIBCLANG_LIB} ) ecm_add_test(test_buddies.cpp TEST_NAME test_buddies-clang LINK_LIBRARIES KDev::Tests Qt5::Test ) ecm_add_test(test_codecompletion.cpp TEST_NAME test_codecompletion LINK_LIBRARIES codecompletiontestbase ) ecm_add_test(test_assistants.cpp TEST_NAME test_assistants LINK_LIBRARIES KDev::Tests Qt5::Test - kdevclangduchain - kdevclangutil + KDevClangPrivate ) ecm_add_test(test_clangutils.cpp TEST_NAME test_clangutils LINK_LIBRARIES KDev::Tests Qt5::Test ${CLANG_LIBCLANG_LIB} - kdevclangduchain + KDevClangPrivate ) ecm_add_test(test_duchain.cpp TEST_NAME test_duchain-clang LINK_LIBRARIES KDev::Tests Qt5::Test - kdevclangduchain + KDevClangPrivate ) ecm_add_test(test_duchainutils.cpp TEST_NAME test_duchainutils LINK_LIBRARIES KDev::Tests Qt5::Test - kdevclangcodecompletion - kdevclangduchain + KDevClangPrivate ) ecm_add_test(test_problems.cpp TEST_NAME test_problems LINK_LIBRARIES KDev::Tests Qt5::Test - kdevclangduchain + KDevClangPrivate ) configure_file("testfilepaths.h.cmake" "testfilepaths.h" ESCAPE_QUOTES) ecm_add_test(test_files.cpp TEST_NAME test_files-clang LINK_LIBRARIES Qt5::Test Qt5::Core KDev::Language KDev::Tests ) if(NOT COMPILER_OPTIMIZATIONS_DISABLED) ecm_add_test(bench_codecompletion.cpp TEST_NAME bench_codecompletion LINK_LIBRARIES codecompletiontestbase ) set_tests_properties(bench_codecompletion PROPERTIES TIMEOUT 30) endif() diff --git a/languages/clang/util/CMakeLists.txt b/languages/clang/util/CMakeLists.txt deleted file mode 100644 index 1e182c4550..0000000000 --- a/languages/clang/util/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -add_library(kdevclangutil STATIC - clangdebug.cpp - clangutils.cpp - clangtypes.cpp -) -target_link_libraries(kdevclangutil -LINK_PRIVATE - KDev::Util - KF5::TextEditor) -set_target_properties(kdevclangutil PROPERTIES POSITION_INDEPENDENT_CODE TRUE) diff --git a/languages/clang/util/clangdebug.h b/languages/clang/util/clangdebug.h index 93c386ef9b..8b2ec7fc47 100644 --- a/languages/clang/util/clangdebug.h +++ b/languages/clang/util/clangdebug.h @@ -1,36 +1,40 @@ /* * 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 . * */ #ifndef CLANGDEBUG_H #define CLANGDEBUG_H #include #include -Q_DECLARE_LOGGING_CATEGORY(KDEV_CLANG) +#include "clangprivateexport.h" + +//TODO: FIXME +//Q_DECLARE_LOGGING_CATEGORY(KDEV_CLANG) +extern KDEVCLANGPRIVATE_EXPORT const QLoggingCategory &KDEV_CLANG(); #define clangDebug() qCDebug(KDEV_CLANG) -QDebug operator<<(QDebug dbg, CXString string); -QDebug operator<<(QDebug dbg, CXSourceLocation location); -QDebug operator<<(QDebug dbg, CXSourceRange range); +KDEVCLANGPRIVATE_EXPORT QDebug operator<<(QDebug dbg, CXString string); +KDEVCLANGPRIVATE_EXPORT QDebug operator<<(QDebug dbg, CXSourceLocation location); +KDEVCLANGPRIVATE_EXPORT QDebug operator<<(QDebug dbg, CXSourceRange range); #endif // CLANGDEBUG_H diff --git a/languages/clang/util/clangtypes.h b/languages/clang/util/clangtypes.h index feb9f050b7..1afb4cd90e 100644 --- a/languages/clang/util/clangtypes.h +++ b/languages/clang/util/clangtypes.h @@ -1,142 +1,144 @@ /* This file is part of KDevelop Copyright 2013 Olivier de Gaalon Copyright 2013 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CLANGTYPES_H #define CLANGTYPES_H #include #include +#include "clangprivateexport.h" + #include class QTextStream; namespace KTextEditor { class Cursor; class Range; } namespace KDevelop { class DocumentCursor; class DocumentRange; class CursorInRevision; class RangeInRevision; class IndexedString; } inline uint qHash(const CXCursor& cursor) noexcept { return clang_hashCursor(cursor); } inline bool operator==(const CXCursor& lhs, const CXCursor& rhs) noexcept { return clang_equalCursors(lhs, rhs); } class ClangString { public: ClangString(CXString string); ~ClangString(); ClangString(const ClangString&) = delete; ClangString& operator=(const ClangString&) = delete; /** * Might return nullptr for invalid strings */ const char* c_str() const; bool isEmpty() const; QString toString() const; QByteArray toByteArray() const; KDevelop::IndexedString toIndexed() const; private: CXString string; }; QTextStream& operator<<(QTextStream& stream, const ClangString& str); class ClangLocation { public: ClangLocation(CXSourceLocation cursor); ~ClangLocation(); operator KDevelop::DocumentCursor() const; operator KTextEditor::Cursor() const; operator KDevelop::CursorInRevision() const; operator CXSourceLocation() const; private: CXSourceLocation location; }; -class ClangRange +class KDEVCLANGPRIVATE_EXPORT ClangRange { public: ClangRange(CXSourceRange range); ~ClangRange(); ClangLocation start() const; ClangLocation end() const; CXSourceRange range() const; KDevelop::DocumentRange toDocumentRange() const; KTextEditor::Range toRange() const; KDevelop::RangeInRevision toRangeInRevision() const; private: CXSourceRange m_range; }; -class ClangTokens +class KDEVCLANGPRIVATE_EXPORT ClangTokens { public: ClangTokens(CXTranslationUnit unit, CXSourceRange range); ClangTokens(const ClangTokens&) = delete; ClangTokens& operator=(const ClangTokens&) = delete; ~ClangTokens(); CXToken* begin() const; CXToken* end() const; std::reverse_iterator rbegin() const; std::reverse_iterator rend() const; uint size() const; CXToken at(uint index) const; private: CXTranslationUnit m_unit; CXToken* m_tokens; uint m_numTokens; }; #endif // CLANGTYPES_H diff --git a/languages/clang/util/clangutils.h b/languages/clang/util/clangutils.h index 2d7329ceaa..46e57515f7 100644 --- a/languages/clang/util/clangutils.h +++ b/languages/clang/util/clangutils.h @@ -1,168 +1,170 @@ /* * 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 . * */ #ifndef CLANGUTILS_H #define CLANGUTILS_H #include #include #include +#include "clangprivateexport.h" + namespace KDevelop { class IndexedString; } namespace ClangUtils { /** * Finds the most specific CXCursor which applies to the the specified line and column * in the given translation unit and file. * * @param line The 0-indexed line number at which to search. * @param column The 0-indexed column number at which to search. * @param unit The translation unit to examine. * @param file The file in the translation unit to examine. * * @return The cursor at the specified location */ CXCursor getCXCursor(int line, int column, const CXTranslationUnit& unit, const CXFile& file); enum DefaultArgumentsMode { FixedSize, ///< The vector will have length equal to the number of arguments to the function /// and any arguments without a default parameter will be represented with an empty string. MinimumSize ///< The vector will have a length equal to the number of default values }; /** * Given a cursor representing a function, returns a vector containing the string * representations of the default arguments of the function which are defined at * the occurance of the cursor. Note that this is not necessarily all of the default * arguments of the function. * * @param cursor The cursor to examine * @return a vector of QStrings representing the default arguments, or an empty * vector if cursor does not represent a function */ QVector getDefaultArguments(CXCursor cursor, DefaultArgumentsMode mode = FixedSize); /** * @return true when the cursor kind references a named scope. */ bool isScopeKind(CXCursorKind kind); /** * Given a cursor and destination context, returns the string representing the * cursor's scope at its current location. * * @param cursor The cursor to examine * @param context The destination context from which the cursor should be referenced. * By default this will be set to the cursors lexical parent. * @return the cursor's scope as a string */ - QString getScope(CXCursor cursor, CXCursor context = clang_getNullCursor()); + KDEVCLANGPRIVATE_EXPORT QString getScope(CXCursor cursor, CXCursor context = clang_getNullCursor()); /** * Given a cursor representing some sort of function, returns its signature. The * effect of this function when passed a non-function cursor is undefined. * * @param cursor The cursor to work with * @param scope The scope of the cursor (e.g. "SomeNS::SomeClass") * @return A QString of the function's signature */ QString getCursorSignature(CXCursor cursor, const QString& scope, const QVector& defaultArgs = QVector()); /** * Given a cursor representing the template argument list, return a * list of the argument types. * * @param cursor The cursor to work with * @return A QStringList of the template's arguments */ - QStringList templateArgumentTypes(CXCursor cursor); + KDEVCLANGPRIVATE_EXPORT QStringList templateArgumentTypes(CXCursor cursor); /** * Extract the raw contents of the range @p range * * @note This will return the exact textual representation of the code, * no whitespace stripped, etc. * * TODO: It would better if we'd be able to just memcpy parts of the file buffer * that's stored inside Clang (cf. llvm::MemoryBuffer for files), but libclang * doesn't offer API for that. This implementation here is a lot more expensive. * * @param unit Translation unit this range is part of */ - QByteArray getRawContents(CXTranslationUnit unit, CXSourceRange range); + KDEVCLANGPRIVATE_EXPORT QByteArray getRawContents(CXTranslationUnit unit, CXSourceRange range); /** * @brief Return true if file @p file1 and file @p file2 are equal * * @see clang_File_isEqual */ inline bool isFileEqual(CXFile file1, CXFile file2) { #if CINDEX_VERSION_MINOR >= 28 return clang_File_isEqual(file1, file2); #else // note: according to the implementation of clang_File_isEqual, file1 and file2 can still be equal, // regardless of whether file1 == file2 is true or not // however, we didn't see any problems with pure pointer comparisions until now, so fall back to that return file1 == file2; #endif } /** * @brief Return true if the cursor @p cursor refers to an explicitly deleted/defaulted function * such as the default constructor in "struct Foo { Foo() = delete; }" * * TODO: do we need isExplicitlyDefaulted() + isExplicitlyDeleted()? * Currently this is only used by the implements completion to hide deleted+defaulted functions so * we don't need to know the difference. We need to tokenize the source code because there is no * such API in libclang so having one function to check both cases is more efficient (only tokenize once) */ bool isExplicitlyDefaultedOrDeleted(CXCursor cursor); /** * Extract the range of the path-spec inside the include-directive in line @p line * * Example: line = "#include " => returns {0, 10, 0, 16} * * @param originalRange This is the range that the resulting range will be based on * * @return Range pointing to the path-spec of the include or invalid range if there is no #include directive on the line. */ - KTextEditor::Range rangeForIncludePathSpec(const QString& line, const KTextEditor::Range& originalRange = KTextEditor::Range()); + KDEVCLANGPRIVATE_EXPORT KTextEditor::Range rangeForIncludePathSpec(const QString& line, const KTextEditor::Range& originalRange = KTextEditor::Range()); enum SpecialQtAttributes { NoQtAttribute, QtSignalAttribute, QtSlotAttribute }; /** * Given a cursor representing a CXXmethod */ SpecialQtAttributes specialQtAttributes(CXCursor cursor); }; #endif // CLANGUTILS_H