From fdaddec7d1f2706302ca6c2fe754ab7c925d6d66 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 11 Jul 2013 11:13:07 +0200 Subject: [PATCH] CppTools: Clean up CppModelManager(Interface) * Const correctness * Better variable names * Sort order of includes and forward declarations * Comment fixes * Cosmetic/Whitespace changes Change-Id: Ieb137266ac7eddedb00c37f8b2cc8677d67e4bdd Reviewed-by: David Schulz --- .../cmakeprojectmanager/cmakeproject.cpp | 6 +- src/plugins/cppeditor/cppeditor.cpp | 2 +- src/plugins/cpptools/cppmodelmanager.cpp | 244 +++++++++--------- src/plugins/cpptools/cppmodelmanager.h | 64 ++--- .../cpptools/cppmodelmanagerinterface.cpp | 46 ++-- .../cpptools/cppmodelmanagerinterface.h | 34 +-- src/plugins/qt4projectmanager/qt4nodes.cpp | 6 +- 7 files changed, 204 insertions(+), 198 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 701f769b06..5c649e85cb 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -128,7 +128,7 @@ CMakeProject::~CMakeProject() it = m_uiCodeModelSupport.constBegin(); end = m_uiCodeModelSupport.constEnd(); for (; it!=end; ++it) { - modelManager->removeEditorSupport(it.value()); + modelManager->removeExtraEditorSupport(it.value()); delete it.value(); } @@ -794,7 +794,7 @@ void CMakeProject::createUiCodeModelSupport() // qDebug()<<"adding new codemodelsupport"; QtSupport::UiCodeModelSupport *cms = new QtSupport::UiCodeModelSupport(modelManager, this, uiFile, uiHeaderFilePath); m_uiCodeModelSupport.insert(uiFile, cms); - modelManager->addEditorSupport(cms); + modelManager->addExtraEditorSupport(cms); } } } @@ -803,7 +803,7 @@ void CMakeProject::createUiCodeModelSupport() QMap::const_iterator it, end; end = oldCodeModelSupport.constEnd(); for (it = oldCodeModelSupport.constBegin(); it!=end; ++it) { - modelManager->removeEditorSupport(it.value()); + modelManager->removeExtraEditorSupport(it.value()); delete it.value(); } } diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 21756ba8fa..e8cb40e6da 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -561,7 +561,7 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent) CPPEditorWidget::~CPPEditorWidget() { if (m_modelManager) - m_modelManager->deleteEditorSupport(editor()); + m_modelManager->deleteCppEditorSupport(editor()); delete m_completionSupport; } diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 82616e7be4..fde83d8fea 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -28,31 +28,30 @@ ****************************************************************************/ #include "cppmodelmanager.h" -#include "cpppreprocessor.h" -#include "cpptoolsconstants.h" +#include "abstracteditorsupport.h" #include "builtinindexingsupport.h" #include "cppcompletionassist.h" +#include "cppfindreferences.h" #include "cpphighlightingsupport.h" #include "cpphighlightingsupportinternal.h" #include "cppindexingsupport.h" -#include "abstracteditorsupport.h" +#include "cpppreprocessor.h" +#include "cpptoolsconstants.h" #include "cpptoolseditorsupport.h" -#include "cppfindreferences.h" #include #include #include #include - #include #include #include #include #include -#include #include +#include #if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU) #define WITH_AST_DUMP @@ -99,7 +98,7 @@ using namespace CppTools; using namespace CppTools::Internal; using namespace CPlusPlus; -#ifdef WITH_AST_DUMP +#ifdef QTCREATOR_WITH_DUMP_AST #include @@ -194,41 +193,44 @@ void CppModelManager::updateModifiedSourceFiles() /*! \class CppTools::CppModelManager - \brief The CppModelManager class keeps track of one CppCodeModel instance - for each project and all the related CppCodeModelPart instances. + \brief The CppModelManager keeps tracks of the source files the code model is aware of. + + The CppModelManager manages the source files in a Snapshot object. - It also takes care of updating the code models when C++ files are - modified within Qt Creator. + The snapshot is updated in case e.g. + * New files are opened/edited (Editor integration) + * A project manager pushes updated project information (Project integration) + * Files are garbage collected */ -QMutex CppModelManager::m_modelManagerMutex; -CppModelManager *CppModelManager::m_modelManagerInstance = 0; +QMutex CppModelManager::m_instanceMutex; +CppModelManager *CppModelManager::m_instance = 0; CppModelManager *CppModelManager::instance() { - if (m_modelManagerInstance) - return m_modelManagerInstance; - QMutexLocker locker(&m_modelManagerMutex); - if (!m_modelManagerInstance) - m_modelManagerInstance = new CppModelManager; - return m_modelManagerInstance; + if (m_instance) + return m_instance; + + QMutexLocker locker(&m_instanceMutex); + if (!m_instance) + m_instance = new CppModelManager; + + return m_instance; } CppModelManager::CppModelManager(QObject *parent) : CppModelManagerInterface(parent) - , m_enableGC(true) , m_completionAssistProvider(0) , m_highlightingFactory(0) , m_indexingSupporter(0) + , m_enableGC(true) { m_findReferences = new CppFindReferences(this); m_indexerEnabled = qgetenv("QTCREATOR_NO_CODE_INDEXER").isNull(); m_dirty = true; - ProjectExplorer::ProjectExplorerPlugin *pe = - ProjectExplorer::ProjectExplorerPlugin::instance(); - + ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance(); QTC_ASSERT(pe, return); ProjectExplorer::SessionManager *session = pe->session(); @@ -306,10 +308,10 @@ void CppModelManager::ensureUpdated() QStringList CppModelManager::internalProjectFiles() const { QStringList files; - QMapIterator it(m_projects); + QMapIterator it(m_projectToProjectsInfo); while (it.hasNext()) { it.next(); - ProjectInfo pinfo = it.value(); + const ProjectInfo pinfo = it.value(); foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) { foreach (const ProjectFile &file, part->files) files += file.path; @@ -322,10 +324,10 @@ QStringList CppModelManager::internalProjectFiles() const QStringList CppModelManager::internalIncludePaths() const { QStringList includePaths; - QMapIterator it(m_projects); + QMapIterator it(m_projectToProjectsInfo); while (it.hasNext()) { it.next(); - ProjectInfo pinfo = it.value(); + const ProjectInfo pinfo = it.value(); foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) foreach (const QString &path, part->includePaths) includePaths.append(CppPreprocessor::cleanPath(path)); @@ -337,10 +339,10 @@ QStringList CppModelManager::internalIncludePaths() const QStringList CppModelManager::internalFrameworkPaths() const { QStringList frameworkPaths; - QMapIterator it(m_projects); + QMapIterator it(m_projectToProjectsInfo); while (it.hasNext()) { it.next(); - ProjectInfo pinfo = it.value(); + const ProjectInfo pinfo = it.value(); foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) foreach (const QString &path, part->frameworkPaths) frameworkPaths.append(CppPreprocessor::cleanPath(path)); @@ -353,10 +355,10 @@ QByteArray CppModelManager::internalDefinedMacros() const { QByteArray macros; QSet alreadyIn; - QMapIterator it(m_projects); + QMapIterator it(m_projectToProjectsInfo); while (it.hasNext()) { it.next(); - ProjectInfo pinfo = it.value(); + const ProjectInfo pinfo = it.value(); foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) { const QList defs = part->defines.split('\n'); foreach (const QByteArray &def, defs) { @@ -375,9 +377,9 @@ QByteArray CppModelManager::internalDefinedMacros() const void CppModelManager::dumpModelManagerConfiguration() { // Tons of debug output... - qDebug()<<"========= CppModelManager::dumpModelManagerConfiguration ======"; - foreach (const ProjectInfo &pinfo, m_projects) { - qDebug()<<" for project:"<< pinfo.project().data()->document()->filePath(); + qDebug() << "========= CppModelManager::dumpModelManagerConfiguration ======"; + foreach (const ProjectInfo &pinfo, m_projectToProjectsInfo) { + qDebug() << " for project:"<< pinfo.project().data()->document()->filePath(); foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) { qDebug() << "=== part ==="; const char* cVersion; @@ -425,35 +427,64 @@ void CppModelManager::dumpModelManagerConfiguration() qDebug() << inc; qDebug() << "=== Merged defined macros ==="; qDebug() << m_definedMacros; - qDebug()<<"========= End of dump ======"; + qDebug() << "========= End of dump ======"; } -void CppModelManager::addEditorSupport(AbstractEditorSupport *editorSupport) +void CppModelManager::addExtraEditorSupport(AbstractEditorSupport *editorSupport) { - m_addtionalEditorSupport.insert(editorSupport); + m_extraEditorSupports.insert(editorSupport); } -void CppModelManager::removeEditorSupport(AbstractEditorSupport *editorSupport) +void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupport) { - m_addtionalEditorSupport.remove(editorSupport); + m_extraEditorSupports.remove(editorSupport); } /// \brief Returns the \c CppEditorSupport for the given text editor. It will /// create one when none exists yet. -CppEditorSupport *CppModelManager::cppEditorSupport(TextEditor::BaseTextEditor *editor) +CppEditorSupport *CppModelManager::cppEditorSupport(TextEditor::BaseTextEditor *textEditor) { - Q_ASSERT(editor); + Q_ASSERT(textEditor); - QMutexLocker locker(&m_editorSupportMutex); + QMutexLocker locker(&m_cppEditorSupportsMutex); - CppEditorSupport *editorSupport = m_editorSupport.value(editor, 0); + CppEditorSupport *editorSupport = m_cppEditorSupports.value(textEditor, 0); if (!editorSupport) { - editorSupport = new CppEditorSupport(this, editor); - m_editorSupport.insert(editor, editorSupport); + editorSupport = new CppEditorSupport(this, textEditor); + m_cppEditorSupports.insert(textEditor, editorSupport); } return editorSupport; } +/// \brief Removes the CppEditorSupport for the closed editor. +void CppModelManager::deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor) +{ + static short numberOfClosedEditors = 0; + + QTC_ASSERT(textEditor, return); + + if (!isCppEditor(textEditor)) + return; + + CppEditorSupport *editorSupport; + int numberOfOpenEditors = 0; + + { // Only lock the operations on m_cppEditorSupport + QMutexLocker locker(&m_cppEditorSupportsMutex); + editorSupport = m_cppEditorSupports.value(textEditor, 0); + m_cppEditorSupports.remove(textEditor); + numberOfOpenEditors = m_cppEditorSupports.size(); + } + + delete editorSupport; + + ++numberOfClosedEditors; + if (numberOfOpenEditors == 0 || numberOfClosedEditors == 5) { + numberOfClosedEditors = 0; + GC(); + } +} + QList CppModelManager::references(CPlusPlus::Symbol *symbol, const LookupContext &context) { return m_findReferences->references(symbol, context); @@ -465,7 +496,8 @@ void CppModelManager::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::Loo m_findReferences->findUsages(symbol, context); } -void CppModelManager::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context, +void CppModelManager::renameUsages(CPlusPlus::Symbol *symbol, + const CPlusPlus::LookupContext &context, const QString &replacement) { if (symbol->identifier()) @@ -490,26 +522,26 @@ void CppModelManager::replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot) CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList() { - QList supporters; + QList cppEditorSupports; { - QMutexLocker locker(&m_editorSupportMutex); - supporters = m_editorSupport.values(); + QMutexLocker locker(&m_cppEditorSupportsMutex); + cppEditorSupports = m_cppEditorSupports.values(); } WorkingCopy workingCopy; - foreach (const CppEditorSupport *editorSupport, supporters) { + foreach (const CppEditorSupport *editorSupport, cppEditorSupports) { workingCopy.insert(editorSupport->fileName(), editorSupport->contents(), editorSupport->editorRevision()); } - QSetIterator jt(m_addtionalEditorSupport); - while (jt.hasNext()) { - AbstractEditorSupport *es = jt.next(); + QSetIterator it(m_extraEditorSupports); + while (it.hasNext()) { + AbstractEditorSupport *es = it.next(); workingCopy.insert(es->fileName(), QString::fromUtf8(es->contents())); } - // add the project configuration file + // Add the project configuration file QByteArray conf(pp_configuration); conf += definedMacros(); workingCopy.insert(configurationFileName(), QString::fromLocal8Bit(conf)); @@ -536,27 +568,25 @@ QFuture CppModelManager::updateSourceFiles(const QStringList &sourceFiles, QList CppModelManager::projectInfos() const { QMutexLocker locker(&m_projectMutex); - - return m_projects.values(); + return m_projectToProjectsInfo.values(); } CppModelManager::ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const { QMutexLocker locker(&m_projectMutex); - - return m_projects.value(project, ProjectInfo(project)); + return m_projectToProjectsInfo.value(project, ProjectInfo(project)); } QFuture CppModelManager::updateProjectInfo(const ProjectInfo &pinfo) { - { // only hold the mutex for a limited scope, so the dumping afterwards can aquire it without deadlocking. - QMutexLocker locker(&m_projectMutex); + if (!pinfo.isValid()) + return QFuture(); - if (!pinfo.isValid()) - return QFuture(); + { // Only hold the mutex for a limited scope, so the dumping afterwards does not deadlock. + QMutexLocker locker(&m_projectMutex); ProjectExplorer::Project *project = pinfo.project().data(); - ProjectInfo oldProjectInfo = m_projects.value(project); + ProjectInfo oldProjectInfo = m_projectToProjectsInfo.value(project); if (oldProjectInfo.isValid()) { if (pinfo.defines() == oldProjectInfo.defines() && pinfo.includePaths() == oldProjectInfo.includePaths() @@ -577,14 +607,14 @@ QFuture CppModelManager::updateProjectInfo(const ProjectInfo &pinfo) } m_snapshot.remove(configurationFileName()); - m_projects.insert(project, pinfo); + m_projectToProjectsInfo.insert(project, pinfo); m_dirty = true; - m_srcToProjectPart.clear(); - foreach (const ProjectInfo &projectInfo, m_projects) { + m_fileToProjectParts.clear(); + foreach (const ProjectInfo &projectInfo, m_projectToProjectsInfo) { foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) { foreach (const ProjectFile &cxxFile, projectPart->files) { - m_srcToProjectPart[cxxFile.path].append(projectPart); + m_fileToProjectParts[cxxFile.path].append(projectPart); } } } @@ -600,15 +630,15 @@ QFuture CppModelManager::updateProjectInfo(const ProjectInfo &pinfo) QList CppModelManager::projectPart(const QString &fileName) const { - QList parts = m_srcToProjectPart.value(fileName); + QList parts = m_fileToProjectParts.value(fileName); if (!parts.isEmpty()) return parts; DependencyTable table; table.build(snapshot()); - QStringList deps = table.filesDependingOn(fileName); + const QStringList deps = table.filesDependingOn(fileName); foreach (const QString &dep, deps) { - parts = m_srcToProjectPart.value(dep); + parts = m_fileToProjectParts.value(dep); if (!parts.isEmpty()) return parts; } @@ -616,35 +646,6 @@ QList CppModelManager::projectPart(const QString &fileName) co return parts; } -/// \brief Removes the CppEditorSupport for the closed editor. -void CppModelManager::deleteEditorSupport(TextEditor::BaseTextEditor *textEditor) -{ - static short numberOfClosedEditors = 0; - - QTC_ASSERT(textEditor, return); - - if (!isCppEditor(textEditor)) - return; - - CppEditorSupport *editorSupport; - int numberOfOpenEditors = 0; - - { // only lock the operations on m_editorSupport - QMutexLocker locker(&m_editorSupportMutex); - editorSupport = m_editorSupport.value(textEditor, 0); - m_editorSupport.remove(textEditor); - numberOfOpenEditors = m_editorSupport.size(); - } - - delete editorSupport; - - ++numberOfClosedEditors; - if (numberOfOpenEditors == 0 || numberOfClosedEditors == 5) { - numberOfClosedEditors = 0; - GC(); - } -} - bool CppModelManager::isCppEditor(Core::IEditor *editor) const { return editor->context().contains(ProjectExplorer::Constants::LANG_CXX); @@ -667,7 +668,7 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project) do { QMutexLocker locker(&m_projectMutex); m_dirty = true; - m_projects.remove(project); + m_projectToProjectsInfo.remove(project); } while (0); GC(); @@ -679,7 +680,7 @@ void CppModelManager::onAboutToUnloadSession() pm->cancelTasks(QLatin1String(CppTools::Constants::TASK_INDEX)); do { QMutexLocker locker(&m_projectMutex); - m_projects.clear(); + m_projectToProjectsInfo.clear(); m_dirty = true; } while (0); @@ -696,37 +697,37 @@ void CppModelManager::GC() if (!m_enableGC) return; - Snapshot currentSnapshot = snapshot(); - QSet processed; + const Snapshot currentSnapshot = snapshot(); + QSet reachableFiles; QStringList todo = projectFiles(); + // Collect all files that are reachable from the project files while (!todo.isEmpty()) { - QString fn = todo.last(); + const QString file = todo.last(); todo.removeLast(); - if (processed.contains(fn)) + if (reachableFiles.contains(file)) continue; + reachableFiles.insert(file); - processed.insert(fn); - - if (Document::Ptr doc = currentSnapshot.document(fn)) + if (Document::Ptr doc = currentSnapshot.document(file)) todo += doc->includedFiles(); } - QStringList removedFiles; - + // Find out the files in the current snapshot that are not reachable from the project files + QStringList notReachableFiles; Snapshot newSnapshot; for (Snapshot::const_iterator it = currentSnapshot.begin(); it != currentSnapshot.end(); ++it) { const QString fileName = it.key(); - if (processed.contains(fileName)) + if (reachableFiles.contains(fileName)) newSnapshot.insert(it.value()); else - removedFiles.append(fileName); + notReachableFiles.append(fileName); } - emit aboutToRemoveFiles(removedFiles); - + // Announce removing files and replace the snapshot + emit aboutToRemoveFiles(notReachableFiles); replaceSnapshot(newSnapshot); } @@ -780,19 +781,20 @@ CppIndexingSupport *CppModelManager::indexingSupport() return m_indexingSupporter ? m_indexingSupporter : m_internalIndexingSupport; } -void CppModelManager::setExtraDiagnostics(const QString &fileName, const QString &kind, +void CppModelManager::setExtraDiagnostics(const QString &fileName, + const QString &kind, const QList &diagnostics) { - QList supporters; + QList cppEditorSupports; { - QMutexLocker locker(&m_editorSupportMutex); - supporters = m_editorSupport.values(); + QMutexLocker locker(&m_cppEditorSupportsMutex); + cppEditorSupports = m_cppEditorSupports.values(); } - foreach (CppEditorSupport *supporter, supporters) { - if (supporter->fileName() == fileName) { - supporter->setExtraDiagnostics(kind, diagnostics); + foreach (CppEditorSupport *editorSupport, cppEditorSupports) { + if (editorSupport->fileName() == fileName) { + editorSupport->setExtraDiagnostics(kind, diagnostics); break; } } diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 5758cdb4b3..7024ae1780 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -31,6 +31,7 @@ #define CPPMODELMANAGER_H #include "cpptools_global.h" + #include "cppmodelmanagerinterface.h" #include @@ -40,10 +41,7 @@ #include namespace Core { class IEditor; } - -namespace TextEditor { -class BaseTextEditorWidget; -} // namespace TextEditor +namespace TextEditor { class BaseTextEditorWidget; } namespace CppTools { @@ -81,14 +79,14 @@ public: bool replaceDocument(Document::Ptr newDoc); virtual void GC(); - virtual bool isCppEditor(Core::IEditor *editor) const; - void emitDocumentUpdated(CPlusPlus::Document::Ptr doc); - virtual void addEditorSupport(AbstractEditorSupport *editorSupport); - virtual void removeEditorSupport(AbstractEditorSupport *editorSupport); - virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *editor); - virtual void deleteEditorSupport(TextEditor::BaseTextEditor *textEditor); + virtual bool isCppEditor(Core::IEditor *editor) const; + + virtual void addExtraEditorSupport(AbstractEditorSupport *editorSupport); + virtual void removeExtraEditorSupport(AbstractEditorSupport *editorSupport); + virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor); + virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor); virtual QList references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); @@ -143,14 +141,14 @@ public: return m_definedMacros; } -Q_SIGNALS: +signals: void aboutToRemoveFiles(const QStringList &files); -public Q_SLOTS: +public slots: virtual void updateModifiedSourceFiles(); -private Q_SLOTS: - // this should be executed in the GUI thread. +private slots: + // This should be executed in the GUI thread. void onAboutToRemoveProject(ProjectExplorer::Project *project); void onAboutToUnloadSession(); void onCoreAboutToClose(); @@ -169,42 +167,46 @@ private: void dumpModelManagerConfiguration(); private: - static QMutex m_modelManagerMutex; - static CppModelManager *m_modelManagerInstance; + static QMutex m_instanceMutex; + static CppModelManager *m_instance; private: - // snapshot + // Snapshot mutable QMutex m_snapshotMutex; CPlusPlus::Snapshot m_snapshot; - bool m_enableGC; - - // project integration + // Project integration mutable QMutex m_projectMutex; - QMap m_projects; - QMap > m_srcToProjectPart; - // cached/calculated from the projects and/or their project-parts + QMap m_projectToProjectsInfo; + QMap > m_fileToProjectParts; + // The members below are cached/(re)calculated from the projects and/or their project parts bool m_dirty; QStringList m_projectFiles; QStringList m_includePaths; QStringList m_frameworkPaths; QByteArray m_definedMacros; - // editor integration - mutable QMutex m_editorSupportMutex; - QMap m_editorSupport; - - QSet m_addtionalEditorSupport; - - CppFindReferences *m_findReferences; - bool m_indexerEnabled; + // Editor integration + mutable QMutex m_cppEditorSupportsMutex; + QMap m_cppEditorSupports; + QSet m_extraEditorSupports; + // Completion CppCompletionAssistProvider *m_completionAssistProvider; CppCompletionAssistProvider *m_completionFallback; + + // Highlighting CppHighlightingSupportFactory *m_highlightingFactory; CppHighlightingSupportFactory *m_highlightingFallback; + + // Indexing CppIndexingSupport *m_indexingSupporter; CppIndexingSupport *m_internalIndexingSupport; + bool m_indexerEnabled; + + CppFindReferences *m_findReferences; + + bool m_enableGC; }; } // namespace Internal diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.cpp b/src/plugins/cpptools/cppmodelmanagerinterface.cpp index cbdb28caad..1338c214a1 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.cpp +++ b/src/plugins/cpptools/cppmodelmanagerinterface.cpp @@ -29,11 +29,15 @@ #include "cppmodelmanagerinterface.h" -#include -#include #include -#include +#include +#include + +#include + +using namespace CppTools; +using namespace ProjectExplorer; /*! \enum CppTools::CppModelManagerInterface::ProgressNotificationMode @@ -44,15 +48,16 @@ \value ForcedProgressNotification Notify regardless of the number of files requested for update. - \value ReservedProgressNotification Notify only if more than one file is requested for update. */ /*! \enum CppTools::CppModelManagerInterface::QtVersion + Allows C++ parser engine to inject headers or change inner settings as needed to parse Qt language extensions for concrete major Qt version + \value UnknownQt Parser may choose any policy \value NoQt @@ -63,9 +68,6 @@ Parser may enable tricks for Qt v5.x */ -using namespace CppTools; -using namespace ProjectExplorer; - ProjectPart::ProjectPart() : cVersion(C89) , cxxVersion(CXX11) @@ -76,12 +78,13 @@ ProjectPart::ProjectPart() { } -/** - * @brief Retrieves info from concrete compiler using it's flags. - * @param tc Either nullptr or toolchain for project's active target. - * @param cxxflags C++ or Objective-C++ flags. - * @param cflags C or ObjectiveC flags if possible, \a cxxflags otherwise. - */ +/*! + \brief Retrieves info from concrete compiler using it's flags. + + \param tc Either nullptr or toolchain for project's active target. + \param cxxflags C++ or Objective-C++ flags. + \param cflags C or ObjectiveC flags if possible, \a cxxflags otherwise. +*/ void ProjectPart::evaluateToolchain(const ToolChain *tc, const QStringList &cxxflags, const QStringList &cflags, @@ -89,6 +92,7 @@ void ProjectPart::evaluateToolchain(const ToolChain *tc, { if (!tc) return; + ToolChain::CompilerFlags cxx = tc->compilerFlags(cxxflags); ToolChain::CompilerFlags c = (cxxflags == cflags) ? cxx : tc->compilerFlags(cflags); @@ -117,14 +121,14 @@ void ProjectPart::evaluateToolchain(const ToolChain *tc, cWarningFlags = tc->warningFlags(cflags); cxxWarningFlags = tc->warningFlags(cxxflags); - QList headers = tc->systemHeaderPaths(cxxflags, sysRoot); + const QList headers = tc->systemHeaderPaths(cxxflags, sysRoot); foreach (const HeaderPath &header, headers) if (header.kind() == HeaderPath::FrameworkHeaderPath) frameworkPaths << header.path(); else includePaths << header.path(); - QByteArray macros = tc->predefinedMacros(cxxflags); + const QByteArray macros = tc->predefinedMacros(cxxflags); if (!macros.isEmpty()) { if (!defines.isEmpty()) defines += '\n'; @@ -156,7 +160,6 @@ CppModelManagerInterface *CppModelManagerInterface::instance() return g_instance; } - void CppModelManagerInterface::ProjectInfo::clearProjectParts() { m_projectParts.clear(); @@ -166,33 +169,32 @@ void CppModelManagerInterface::ProjectInfo::clearProjectParts() m_defines.clear(); } -void CppModelManagerInterface::ProjectInfo::appendProjectPart( - const ProjectPart::Ptr &part) +void CppModelManagerInterface::ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part) { if (!part) return; m_projectParts.append(part); - // update include paths + // Update include paths QSet incs = QSet::fromList(m_includePaths); foreach (const QString &ins, part->includePaths) incs.insert(ins); m_includePaths = incs.toList(); - // update framework paths + // Update framework paths QSet frms = QSet::fromList(m_frameworkPaths); foreach (const QString &frm, part->frameworkPaths) frms.insert(frm); m_frameworkPaths = frms.toList(); - // update source files + // Update source files QSet srcs = QSet::fromList(m_sourceFiles); foreach (const ProjectFile &file, part->files) srcs.insert(file.path); m_sourceFiles = srcs.toList(); - // update defines + // Update defines if (!m_defines.isEmpty()) m_defines.append('\n'); m_defines.append(part->defines); diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index cf33a7aaba..e4885ea578 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -31,16 +31,17 @@ #define CPPMODELMANAGERINTERFACE_H #include "cpptools_global.h" + #include "cppprojectfile.h" #include #include -#include +#include #include +#include #include #include -#include namespace Core { class IEditor; } namespace CPlusPlus { class LookupContext; } @@ -49,9 +50,10 @@ namespace TextEditor { class BaseTextEditor; } namespace Utils { class FileName; } namespace CppTools { + class AbstractEditorSupport; -class CppCompletionSupport; class CppCompletionAssistProvider; +class CppCompletionSupport; class CppEditorSupport; class CppHighlightingSupport; class CppHighlightingSupportFactory; @@ -97,7 +99,7 @@ public: typedef QSharedPointer Ptr; -public: //attributes +public: QList files; QByteArray defines; QStringList includePaths; @@ -116,8 +118,7 @@ class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject Q_OBJECT public: - - // Documented in source file. + // Documented in source file. enum ProgressNotificationMode { ForcedProgressNotification, ReservedProgressNotification @@ -127,11 +128,11 @@ public: { public: ProjectInfo() - { } + {} ProjectInfo(QPointer project) : m_project(project) - { } + {} operator bool() const { return !m_project.isNull(); } @@ -163,10 +164,10 @@ public: const QByteArray defines() const { return m_defines; } - private: // attributes + private: QPointer m_project; QList m_projectParts; - // the attributes below are calculated from the project parts. + // The members below are (re)calculated from the project parts once a part is appended. QStringList m_includePaths; QStringList m_frameworkPaths; QStringList m_sourceFiles; @@ -220,10 +221,10 @@ public: virtual QStringList includePaths() = 0; - virtual void addEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0; - virtual void removeEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0; - virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *editor) = 0; - virtual void deleteEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0; + virtual void addExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0; + virtual void removeExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0; + virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0; + virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0; virtual QList references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) = 0; @@ -247,7 +248,7 @@ public: virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0; virtual CppTools::CppIndexingSupport *indexingSupport() = 0; -Q_SIGNALS: +signals: void documentUpdated(CPlusPlus::Document::Ptr doc); void sourceFilesRefreshed(const QStringList &files); @@ -256,8 +257,7 @@ Q_SIGNALS: /// Other classes can use this to get notified when the \c ProjectExplorer has updated the parts. void projectPartsUpdated(ProjectExplorer::Project *project); -public Q_SLOTS: - +public slots: virtual void updateModifiedSourceFiles() = 0; virtual QFuture updateSourceFiles(const QStringList &sourceFiles, ProgressNotificationMode mode = ReservedProgressNotification) = 0; diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index 8899e2948a..d4a1088e42 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -1466,7 +1466,7 @@ Qt4ProFileNode::~Qt4ProFileNode() QMap::const_iterator it, end; end = m_uiCodeModelSupport.constEnd(); for (it = m_uiCodeModelSupport.constBegin(); it != end; ++it) { - modelManager->removeEditorSupport(it.value()); + modelManager->removeExtraEditorSupport(it.value()); delete it.value(); } m_parseFutureWatcher.waitForFinished(); @@ -2318,7 +2318,7 @@ void Qt4ProFileNode::createUiCodeModelSupport() // qDebug()<<"adding new codemodelsupport"; QtSupport::UiCodeModelSupport *cms = new QtSupport::UiCodeModelSupport(modelManager, m_project, uiFile->path(), uiHeaderFilePath); m_uiCodeModelSupport.insert(uiFile->path(), cms); - modelManager->addEditorSupport(cms); + modelManager->addExtraEditorSupport(cms); } } } @@ -2326,7 +2326,7 @@ void Qt4ProFileNode::createUiCodeModelSupport() QMap::const_iterator it, end; end = oldCodeModelSupport.constEnd(); for (it = oldCodeModelSupport.constBegin(); it!=end; ++it) { - modelManager->removeEditorSupport(it.value()); + modelManager->removeExtraEditorSupport(it.value()); delete it.value(); } } -- GitLab