diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp index e9c5642868e..51c6f748d97 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp @@ -410,7 +410,7 @@ void AutotoolsProject::updateCppCodeModel() if (cxxflags.isEmpty()) cxxflags = cflags; - CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelManager->projectInfo(this); + CppTools::ProjectInfo pinfo = modelManager->projectInfo(this); pinfo.clearProjectParts(); CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart); part->project = this; diff --git a/src/plugins/clangcodemodel/pchmanager.cpp b/src/plugins/clangcodemodel/pchmanager.cpp index 55a23f6a402..1b384c3ac3b 100644 --- a/src/plugins/clangcodemodel/pchmanager.cpp +++ b/src/plugins/clangcodemodel/pchmanager.cpp @@ -441,7 +441,7 @@ void PchManager::updateActivePchFiles() QSet activeParts; CppTools::CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance(); - foreach (const CppTools::CppModelManagerInterface::ProjectInfo &pi, mmi->projectInfos()) + foreach (const CppTools::ProjectInfo &pi, mmi->projectInfos()) activeParts.unite(QSet::fromList(pi.projectParts())); QList partsWithPCHFiles = m_activePchFiles.keys(); foreach (ProjectPart::Ptr pPart, partsWithPCHFiles) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 8e859e73f0b..d6df383bd15 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -329,7 +329,7 @@ bool CMakeProject::parseCMakeLists() CppTools::CppModelManagerInterface *modelmanager = CppTools::CppModelManagerInterface::instance(); if (modelmanager) { - CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this); + CppTools::ProjectInfo pinfo = modelmanager->projectInfo(this); pinfo.clearProjectParts(); foreach (const CMakeBuildTarget &cbt, m_buildTargets) { diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 1a65bec3ecf..c60e8839328 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -949,7 +949,7 @@ class ProjectPartsModel : public QAbstractListModel public: ProjectPartsModel(QObject *parent); - void configure(const QList &projectInfos, + void configure(const QList &projectInfos, const ProjectPart::Ptr ¤tEditorsProjectPart); QModelIndex indexForCurrentEditorsProjectPart() const; @@ -972,12 +972,12 @@ ProjectPartsModel::ProjectPartsModel(QObject *parent) { } -void ProjectPartsModel::configure(const QList &projectInfos, +void ProjectPartsModel::configure(const QList &projectInfos, const ProjectPart::Ptr ¤tEditorsProjectPart) { emit layoutAboutToBeChanged(); m_projectPartsList.clear(); - foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) { + foreach (const ProjectInfo &info, projectInfos) { foreach (const ProjectPart::Ptr &projectPart, info.projectParts()) { if (!m_projectPartsList.contains(projectPart)) { m_projectPartsList << projectPart; @@ -1416,7 +1416,7 @@ void CppCodeModelInspectorDialog::refresh() ? editorSupport->snapshotUpdater()->currentProjectPart() : ProjectPart::Ptr(); - const QList projectInfos = cmmi->projectInfos(); + const QList projectInfos = cmmi->projectInfos(); dumper.dumpProjectInfos(projectInfos); m_projectPartsModel->configure(projectInfos, editorsProjectPart); m_projectPartsView->resizeColumns(ProjectPartsModel::ColumnCount); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index f88a4490649..f00a5afd4b0 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -1903,9 +1903,9 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa // find the include paths ProjectPart::HeaderPaths headerPaths; CppModelManagerInterface *modelManager = CppModelManagerInterface::instance(); - QList projectInfos = modelManager->projectInfos(); + QList projectInfos = modelManager->projectInfos(); bool inProject = false; - foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) { + foreach (const ProjectInfo &info, projectInfos) { foreach (ProjectPart::Ptr part, info.projectParts()) { foreach (const ProjectFile &file, part->files) { if (file.path == doc->fileName()) { diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 10ce9f99b3b..a765141b86e 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -150,12 +150,12 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti // Collect files to process QStringList filesToOpen; QList > projects; - const QList projectInfos + const QList projectInfos = m_modelManager->projectInfos(); if (projectInfos.isEmpty()) MSKIP_SINGLE("No project(s) loaded. Test operates only on loaded projects."); - foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) { + foreach (const ProjectInfo &info, projectInfos) { QPointer project = info.project(); if (!projects.contains(project)) projects << project; diff --git a/src/plugins/cpptools/cppcodemodelinspectordumper.cpp b/src/plugins/cpptools/cppcodemodelinspectordumper.cpp index 9c27db8fe53..2600b7f16a9 100644 --- a/src/plugins/cpptools/cppcodemodelinspectordumper.cpp +++ b/src/plugins/cpptools/cppcodemodelinspectordumper.cpp @@ -472,7 +472,7 @@ Dumper::~Dumper() m_out << "*** END Code Model Inspection Report\n"; } -void Dumper::dumpProjectInfos( const QList &projectInfos) +void Dumper::dumpProjectInfos( const QList &projectInfos) { const QByteArray i1 = indent(1); const QByteArray i2 = indent(2); @@ -480,7 +480,7 @@ void Dumper::dumpProjectInfos( const QList project = info.project(); m_out << i1 << "Project " << project->displayName() << " (" << project->projectFilePath().toUserOutput() << "){{{2\n"; diff --git a/src/plugins/cpptools/cppcodemodelinspectordumper.h b/src/plugins/cpptools/cppcodemodelinspectordumper.h index 313229e4861..5f4c4620d07 100644 --- a/src/plugins/cpptools/cppcodemodelinspectordumper.h +++ b/src/plugins/cpptools/cppcodemodelinspectordumper.h @@ -69,7 +69,7 @@ public: const QString &logFileId = QString()); ~Dumper(); - void dumpProjectInfos(const QList &projectInfos); + void dumpProjectInfos(const QList &projectInfos); void dumpSnapshot(const CPlusPlus::Snapshot &snapshot, const QString &title, bool isGlobalSnapshot = false); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 81824c56bdd..83c642b5b9e 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -368,7 +368,7 @@ QByteArray CppModelManager::internalDefinedMacros() const addUnique(part->toolchainDefines.split('\n'), ¯os, &alreadyIn); addUnique(part->projectDefines.split('\n'), ¯os, &alreadyIn); if (!part->projectConfigFile.isEmpty()) - macros += readProjectConfigFile(part); + macros += ProjectPart::readProjectConfigFile(part); } } return macros; @@ -523,13 +523,13 @@ QFuture CppModelManager::updateSourceFiles(const QStringList &sourceFiles, return m_internalIndexingSupport->refreshSourceFiles(sourceFiles, mode); } -QList CppModelManager::projectInfos() const +QList CppModelManager::projectInfos() const { QMutexLocker locker(&m_projectMutex); return m_projectToProjectsInfo.values(); } -CppModelManager::ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const +ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const { QMutexLocker locker(&m_projectMutex); return m_projectToProjectsInfo.value(project, ProjectInfo(project)); @@ -569,8 +569,8 @@ void CppModelManager::removeFilesFromSnapshot(const QSet &filesToRemove class ProjectInfoComparer { public: - ProjectInfoComparer(const CppModelManager::ProjectInfo &oldProjectInfo, - const CppModelManager::ProjectInfo &newProjectInfo) + ProjectInfoComparer(const ProjectInfo &oldProjectInfo, + const ProjectInfo &newProjectInfo) : m_old(oldProjectInfo) , m_oldSourceFiles(oldProjectInfo.sourceFiles().toSet()) , m_new(newProjectInfo) @@ -625,10 +625,10 @@ public: } private: - const CppModelManager::ProjectInfo &m_old; + const ProjectInfo &m_old; const QSet m_oldSourceFiles; - const CppModelManager::ProjectInfo &m_new; + const ProjectInfo &m_new; const QSet m_newSourceFiles; }; diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index 2af2cc2c233..b8fbe7b926c 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -55,7 +55,7 @@ using namespace CppTools::Internal; using namespace ProjectExplorer; typedef CPlusPlus::Document Document; -typedef CppTools::CppModelManagerInterface::ProjectInfo ProjectInfo; +typedef CppTools::ProjectInfo ProjectInfo; typedef CppTools::ProjectPart ProjectPart; typedef CppTools::ProjectFile ProjectFile; diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.cpp b/src/plugins/cpptools/cppmodelmanagerinterface.cpp index 8c79e3d0dab..d6a4158b0c6 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.cpp +++ b/src/plugins/cpptools/cppmodelmanagerinterface.cpp @@ -34,8 +34,6 @@ #include #include -#include - using namespace CppTools; using namespace ProjectExplorer; @@ -99,71 +97,6 @@ using namespace ProjectExplorer; \sa CppTools::CppModelManagerInterface::updateProjectInfo() */ -ProjectPart::ProjectPart() - : project(0) - , cVersion(C89) - , cxxVersion(CXX11) - , cxxExtensions(NoExtensions) - , qtVersion(UnknownQt) - , cWarningFlags(ProjectExplorer::ToolChain::WarningsDefault) - , cxxWarningFlags(ProjectExplorer::ToolChain::WarningsDefault) - -{ -} - -/*! - \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, - const Utils::FileName &sysRoot) -{ - if (!tc) - return; - - ToolChain::CompilerFlags cxx = tc->compilerFlags(cxxflags); - ToolChain::CompilerFlags c = (cxxflags == cflags) - ? cxx : tc->compilerFlags(cflags); - - if (c & ToolChain::StandardC11) - cVersion = C11; - else if (c & ToolChain::StandardC99) - cVersion = C99; - else - cVersion = C89; - - if (cxx & ToolChain::StandardCxx11) - cxxVersion = CXX11; - else - cxxVersion = CXX98; - - if (cxx & ToolChain::BorlandExtensions) - cxxExtensions |= BorlandExtensions; - if (cxx & ToolChain::GnuExtensions) - cxxExtensions |= GnuExtensions; - if (cxx & ToolChain::MicrosoftExtensions) - cxxExtensions |= MicrosoftExtensions; - if (cxx & ToolChain::OpenMP) - cxxExtensions |= OpenMPExtensions; - - cWarningFlags = tc->warningFlags(cflags); - cxxWarningFlags = tc->warningFlags(cxxflags); - - const QList headers = tc->systemHeaderPaths(cxxflags, sysRoot); - foreach (const ProjectExplorer::HeaderPath &header, headers) { - headerPaths << HeaderPath(header.path(), - header.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath - ? HeaderPath::FrameworkPath : HeaderPath::IncludePath); - } - - toolchainDefines = tc->predefinedMacros(cxxflags); -} - const QString CppModelManagerInterface::configurationFileName() { return CPlusPlus::Preprocessor::configurationFileName; } @@ -183,62 +116,3 @@ CppModelManagerInterface *CppModelManagerInterface::instance() { return qobject_cast(CPlusPlus::CppModelManagerBase::instance()); } - -void CppModelManagerInterface::ProjectInfo::clearProjectParts() -{ - m_projectParts.clear(); - m_headerPaths.clear(); - m_sourceFiles.clear(); - m_defines.clear(); -} - -void CppModelManagerInterface::ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part) -{ - if (!part) - return; - - m_projectParts.append(part); - - typedef ProjectPart::HeaderPath HeaderPath; - - // Update header paths - QSet incs = QSet::fromList(m_headerPaths); - foreach (const HeaderPath &hp, part->headerPaths) { - if (!incs.contains(hp)) { - incs.insert(hp); - m_headerPaths += hp; - } - } - - // 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 - if (!m_defines.isEmpty()) - m_defines.append('\n'); - m_defines.append(part->toolchainDefines); - m_defines.append(part->projectDefines); - if (!part->projectConfigFile.isEmpty()) { - m_defines.append('\n'); - m_defines += readProjectConfigFile(part); - m_defines.append('\n'); - } -} - -QByteArray CppModelManagerInterface::readProjectConfigFile(const ProjectPart::Ptr &part) -{ - QByteArray result; - - QFile f(part->projectConfigFile); - if (f.open(QIODevice::ReadOnly)) { - QTextStream is(&f); - result = is.readAll().toUtf8(); - f.close(); - } - - return result; -} - diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index 27eaa6b2276..53120715fd3 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -32,11 +32,10 @@ #include "cpptools_global.h" -#include "cppprojectfile.h" +#include "cppprojects.h" #include #include -#include #include #include @@ -53,97 +52,13 @@ namespace Utils { class FileName; } namespace CppTools { class AbstractEditorSupport; -class ModelManagerSupport; class CppCompletionAssistProvider; class CppEditorSupport; class CppHighlightingSupport; class CppIndexingSupport; +class ModelManagerSupport; class WorkingCopy; -class CPPTOOLS_EXPORT ProjectPart -{ -public: - ProjectPart(); - - void evaluateToolchain(const ProjectExplorer::ToolChain *tc, - const QStringList &cxxflags, - const QStringList &cflags, - const Utils::FileName &sysRoot); - -public: - enum CVersion { - C89, - C99, - C11 - }; - - enum CXXVersion { - CXX98, - CXX11 - }; - - enum CXXExtension { - NoExtensions = 0x0, - GnuExtensions = 0x1, - MicrosoftExtensions = 0x2, - BorlandExtensions = 0x4, - OpenMPExtensions = 0x8, - - AllExtensions = GnuExtensions | MicrosoftExtensions | BorlandExtensions | OpenMPExtensions - }; - Q_DECLARE_FLAGS(CXXExtensions, CXXExtension) - - enum QtVersion { - UnknownQt = -1, - NoQt = 0, - Qt4 = 1, - Qt5 = 2 - }; - - typedef QSharedPointer Ptr; - - struct HeaderPath { - enum Type { InvalidPath, IncludePath, FrameworkPath }; - - public: - QString path; - Type type; - - HeaderPath(): type(InvalidPath) {} - HeaderPath(const QString &path, Type type): path(path), type(type) {} - - bool isValid() const { return type != InvalidPath; } - bool isFrameworkPath() const { return type == FrameworkPath; } - - bool operator==(const HeaderPath &other) const - { return path == other.path && type == other.type; } - - bool operator!=(const HeaderPath &other) const - { return !(*this == other); } - }; - typedef QList HeaderPaths; - -public: - QString displayName; - QString projectFile; - ProjectExplorer::Project *project; - QList files; - QString projectConfigFile; // currently only used by the Generic Project Manager - QByteArray projectDefines; - QByteArray toolchainDefines; - QList headerPaths; - QStringList precompiledHeaders; - CVersion cVersion; - CXXVersion cxxVersion; - CXXExtensions cxxExtensions; - QtVersion qtVersion; - ProjectExplorer::ToolChain::WarningFlags cWarningFlags; - ProjectExplorer::ToolChain::WarningFlags cxxWarningFlags; -}; - -inline uint qHash(const ProjectPart::HeaderPath &key, uint seed = 0) -{ return ((qHash(key.path) << 2) | key.type) ^ seed; } - class CPPTOOLS_EXPORT CppModelManagerInterface : public CPlusPlus::CppModelManagerBase { Q_OBJECT @@ -155,52 +70,6 @@ public: ReservedProgressNotification }; - class CPPTOOLS_EXPORT ProjectInfo - { - public: - ProjectInfo() - {} - - ProjectInfo(QPointer project) - : m_project(project) - {} - - operator bool() const - { return !m_project.isNull(); } - - bool isValid() const - { return !m_project.isNull(); } - - bool isNull() const - { return m_project.isNull(); } - - QPointer project() const - { return m_project; } - - const QList projectParts() const - { return m_projectParts; } - - void clearProjectParts(); - void appendProjectPart(const ProjectPart::Ptr &part); - - const ProjectPart::HeaderPaths headerPaths() const - { return m_headerPaths; } - - const QStringList sourceFiles() const - { return m_sourceFiles; } - - const QByteArray defines() const - { return m_defines; } - - private: - QPointer m_project; - QList m_projectParts; - // The members below are (re)calculated from the project parts once a part is appended. - ProjectPart::HeaderPaths m_headerPaths; - QStringList m_sourceFiles; - QByteArray m_defines; - }; - public: static const QString configurationFileName(); static const QString editorConfigurationFileName(); @@ -278,9 +147,6 @@ public slots: virtual void updateModifiedSourceFiles() = 0; virtual void GC() = 0; - -protected: - static QByteArray readProjectConfigFile(const ProjectPart::Ptr &part); }; } // namespace CppTools diff --git a/src/plugins/cpptools/cppprojects.cpp b/src/plugins/cpptools/cppprojects.cpp new file mode 100644 index 00000000000..058bf27e633 --- /dev/null +++ b/src/plugins/cpptools/cppprojects.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cppprojects.h" + +#include + +#include +#include + +namespace CppTools { + +ProjectPart::ProjectPart() + : project(0) + , cVersion(C89) + , cxxVersion(CXX11) + , cxxExtensions(NoExtensions) + , qtVersion(UnknownQt) + , cWarningFlags(ProjectExplorer::ToolChain::WarningsDefault) + , cxxWarningFlags(ProjectExplorer::ToolChain::WarningsDefault) + +{ +} + +/*! + \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 ProjectExplorer::ToolChain *tc, + const QStringList &cxxflags, + const QStringList &cflags, + const Utils::FileName &sysRoot) +{ + if (!tc) + return; + + using namespace ProjectExplorer; + ToolChain::CompilerFlags cxx = tc->compilerFlags(cxxflags); + ToolChain::CompilerFlags c = (cxxflags == cflags) + ? cxx : tc->compilerFlags(cflags); + + if (c & ToolChain::StandardC11) + cVersion = C11; + else if (c & ToolChain::StandardC99) + cVersion = C99; + else + cVersion = C89; + + if (cxx & ToolChain::StandardCxx11) + cxxVersion = CXX11; + else + cxxVersion = CXX98; + + if (cxx & ToolChain::BorlandExtensions) + cxxExtensions |= BorlandExtensions; + if (cxx & ToolChain::GnuExtensions) + cxxExtensions |= GnuExtensions; + if (cxx & ToolChain::MicrosoftExtensions) + cxxExtensions |= MicrosoftExtensions; + if (cxx & ToolChain::OpenMP) + cxxExtensions |= OpenMPExtensions; + + cWarningFlags = tc->warningFlags(cflags); + cxxWarningFlags = tc->warningFlags(cxxflags); + + const QList headers = tc->systemHeaderPaths(cxxflags, sysRoot); + foreach (const ProjectExplorer::HeaderPath &header, headers) { + headerPaths << ProjectPart::HeaderPath(header.path(), + header.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath + ? ProjectPart::HeaderPath::FrameworkPath + : ProjectPart::HeaderPath::IncludePath); + } + + toolchainDefines = tc->predefinedMacros(cxxflags); +} + +QByteArray ProjectPart::readProjectConfigFile(const ProjectPart::Ptr &part) +{ + QByteArray result; + + QFile f(part->projectConfigFile); + if (f.open(QIODevice::ReadOnly)) { + QTextStream is(&f); + result = is.readAll().toUtf8(); + f.close(); + } + + return result; +} + +ProjectInfo::ProjectInfo() +{} + +ProjectInfo::ProjectInfo(QPointer project) + : m_project(project) +{} + +ProjectInfo::operator bool() const +{ + return !m_project.isNull(); +} + +bool ProjectInfo::isValid() const +{ + return !m_project.isNull(); +} + +bool ProjectInfo::isNull() const +{ + return m_project.isNull(); +} + +QPointer ProjectInfo::project() const +{ + return m_project; +} + +const QList ProjectInfo::projectParts() const +{ + return m_projectParts; +} + +void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part) +{ + if (!part) + return; + + m_projectParts.append(part); + + typedef ProjectPart::HeaderPath HeaderPath; + + // Update header paths + QSet incs = QSet::fromList(m_headerPaths); + foreach (const HeaderPath &hp, part->headerPaths) { + if (!incs.contains(hp)) { + incs.insert(hp); + m_headerPaths += hp; + } + } + + // 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 + if (!m_defines.isEmpty()) + m_defines.append('\n'); + m_defines.append(part->toolchainDefines); + m_defines.append(part->projectDefines); + if (!part->projectConfigFile.isEmpty()) { + m_defines.append('\n'); + m_defines += ProjectPart::readProjectConfigFile(part); + m_defines.append('\n'); + } +} + +void ProjectInfo::clearProjectParts() +{ + m_projectParts.clear(); + m_headerPaths.clear(); + m_sourceFiles.clear(); + m_defines.clear(); +} + +const ProjectPart::HeaderPaths ProjectInfo::headerPaths() const +{ + return m_headerPaths; +} + +const QStringList ProjectInfo::sourceFiles() const +{ + return m_sourceFiles; +} + +const QByteArray ProjectInfo::defines() const +{ + return m_defines; +} + +} // namespace CppTools diff --git a/src/plugins/cpptools/cppprojects.h b/src/plugins/cpptools/cppprojects.h new file mode 100644 index 00000000000..da11f695ab1 --- /dev/null +++ b/src/plugins/cpptools/cppprojects.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CPPPROJECTPART_H +#define CPPPROJECTPART_H + +#include "cpptools_global.h" + +#include "cppprojectfile.h" + +#include +#include + +#include + +namespace CppTools { + +class CPPTOOLS_EXPORT ProjectPart +{ +public: + typedef QSharedPointer Ptr; + +public: + ProjectPart(); + + void evaluateToolchain(const ProjectExplorer::ToolChain *tc, + const QStringList &cxxflags, + const QStringList &cflags, + const Utils::FileName &sysRoot); + +public: + enum CVersion { + C89, + C99, + C11 + }; + + enum CXXVersion { + CXX98, + CXX11 + }; + + enum CXXExtension { + NoExtensions = 0x0, + GnuExtensions = 0x1, + MicrosoftExtensions = 0x2, + BorlandExtensions = 0x4, + OpenMPExtensions = 0x8, + + AllExtensions = GnuExtensions | MicrosoftExtensions | BorlandExtensions | OpenMPExtensions + }; + Q_DECLARE_FLAGS(CXXExtensions, CXXExtension) + + enum QtVersion { + UnknownQt = -1, + NoQt = 0, + Qt4 = 1, + Qt5 = 2 + }; + + class HeaderPath + { + public: + enum Type { InvalidPath, IncludePath, FrameworkPath }; + + QString path; + Type type; + + HeaderPath(): type(InvalidPath) {} + HeaderPath(const QString &path, Type type): path(path), type(type) {} + + bool isValid() const { return type != InvalidPath; } + bool isFrameworkPath() const { return type == FrameworkPath; } + + bool operator==(const HeaderPath &other) const + { return path == other.path && type == other.type; } + + bool operator!=(const HeaderPath &other) const + { return !(*this == other); } + }; + typedef QList HeaderPaths; + +public: + static QByteArray readProjectConfigFile(const ProjectPart::Ptr &part); + +public: + QString displayName; + QString projectFile; + ProjectExplorer::Project *project; + QList files; + QString projectConfigFile; // currently only used by the Generic Project Manager + QByteArray projectDefines; + QByteArray toolchainDefines; + QList headerPaths; + QStringList precompiledHeaders; + CVersion cVersion; + CXXVersion cxxVersion; + CXXExtensions cxxExtensions; + QtVersion qtVersion; + ProjectExplorer::ToolChain::WarningFlags cWarningFlags; + ProjectExplorer::ToolChain::WarningFlags cxxWarningFlags; +}; + +inline uint qHash(const ProjectPart::HeaderPath &key, uint seed = 0) +{ return ((qHash(key.path) << 2) | key.type) ^ seed; } + +class CPPTOOLS_EXPORT ProjectInfo +{ +public: + ProjectInfo(); + ProjectInfo(QPointer project); + + operator bool() const; + bool isValid() const; + bool isNull() const; + + QPointer project() const; + const QList projectParts() const; + + void appendProjectPart(const ProjectPart::Ptr &part); + void clearProjectParts(); + + const ProjectPart::HeaderPaths headerPaths() const; + const QStringList sourceFiles() const; + const QByteArray defines() const; + +private: + QPointer m_project; + QList m_projectParts; + // The members below are (re)calculated from the project parts once a part is appended. + ProjectPart::HeaderPaths m_headerPaths; + QStringList m_sourceFiles; + QByteArray m_defines; +}; + +} // namespace CppTools + +#endif // CPPPROJECTPART_H diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 8c0cecb096a..cb34c770838 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -36,6 +36,7 @@ HEADERS += \ cppmodelmanagersupportinternal.h \ cpppointerdeclarationformatter.h \ cppprojectfile.h \ + cppprojects.h \ cppqtstyleindenter.h \ cpprefactoringchanges.h \ cppsemanticinfo.h \ @@ -93,6 +94,7 @@ SOURCES += \ cppmodelmanagersupportinternal.cpp \ cpppointerdeclarationformatter.cpp \ cppprojectfile.cpp \ + cppprojects.cpp \ cppqtstyleindenter.cpp \ cpprefactoringchanges.cpp \ cppsemanticinfo.cpp \ diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index 0aed824106d..5635be318ad 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -56,6 +56,7 @@ QtcPlugin { "cppmodelmanagersupportinternal.cpp", "cppmodelmanagersupportinternal.h", "cpppointerdeclarationformatter.cpp", "cpppointerdeclarationformatter.h", "cppprojectfile.cpp", "cppprojectfile.h", + "cppprojects.cpp", "cppprojects.h", "cppqtstyleindenter.cpp", "cppqtstyleindenter.h", "cpprefactoringchanges.cpp", "cpprefactoringchanges.h", "cppsemanticinfo.cpp", "cppsemanticinfo.h", diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index f2c8e455c4c..d214c6055fd 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -433,8 +433,8 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader) // Find files in other projects } else { CppModelManager *modelManager = CppModelManager::instance(); - QList projectInfos = modelManager->projectInfos(); - foreach (const CppModelManagerInterface::ProjectInfo &projectInfo, projectInfos) { + QList projectInfos = modelManager->projectInfos(); + foreach (const ProjectInfo &projectInfo, projectInfos) { const ProjectExplorer::Project *project = projectInfo.project().data(); if (project == currentProject) continue; // We have already checked the current project. diff --git a/src/plugins/cpptools/modelmanagertesthelper.h b/src/plugins/cpptools/modelmanagertesthelper.h index 3292e1950ed..fdc1e449ee4 100644 --- a/src/plugins/cpptools/modelmanagertesthelper.h +++ b/src/plugins/cpptools/modelmanagertesthelper.h @@ -69,7 +69,6 @@ class ModelManagerTestHelper: public QObject Q_OBJECT public: - typedef CppModelManagerInterface::ProjectInfo ProjectInfo; typedef ProjectExplorer::Project Project; explicit ModelManagerTestHelper(QObject *parent = 0); diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index c3b82136e67..a460e8537f5 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -270,7 +270,7 @@ void GenericProject::refresh(RefreshOptions options) CppTools::CppModelManagerInterface::instance(); if (modelManager) { - CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelManager->projectInfo(this); + CppTools::ProjectInfo pinfo = modelManager->projectInfo(this); pinfo.clearProjectParts(); CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart); part->project = this; diff --git a/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp b/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp index 2f21b67364d..32a9c656df6 100644 --- a/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp +++ b/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp @@ -98,7 +98,7 @@ void GenericProjectPlugin::test_simple() cppHelper.waitForSourceFilesRefreshed(mainFile); CppModelManagerInterface *mm = cppHelper.cppModelManager(); - CppModelManagerInterface::ProjectInfo pInfo = mm->projectInfo(project); + ProjectInfo pInfo = mm->projectInfo(project); QCOMPARE(pInfo.projectParts().size(), 1); diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp index 5a63f82cf1a..a763cf081ce 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.cpp +++ b/src/plugins/qbsprojectmanager/qbsproject.cpp @@ -627,7 +627,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj) if (!modelmanager) return; - CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this); + CppTools::ProjectInfo pinfo = modelmanager->projectInfo(this); pinfo.clearProjectParts(); CppTools::ProjectPart::QtVersion qtVersionForPart = CppTools::ProjectPart::NoQt; diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 83ac0be0f4c..3dbc7b6d045 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -495,7 +495,7 @@ void QmakeProject::updateCppCodeModel() FindQmakeProFiles findQmakeProFiles; QList proFiles = findQmakeProFiles(rootProjectNode()); - CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this); + CppTools::ProjectInfo pinfo = modelmanager->projectInfo(this); pinfo.clearProjectParts(); ProjectPart::QtVersion qtVersionForPart = ProjectPart::NoQt; if (qtVersion) { diff --git a/src/plugins/todo/cpptodoitemsscanner.cpp b/src/plugins/todo/cpptodoitemsscanner.cpp index 5ff7d14907f..b001edc5ff5 100644 --- a/src/plugins/todo/cpptodoitemsscanner.cpp +++ b/src/plugins/todo/cpptodoitemsscanner.cpp @@ -53,7 +53,7 @@ void CppTodoItemsScanner::keywordListChanged() CppTools::CppModelManagerInterface *modelManager = CppTools::CppModelManagerInterface::instance(); QStringList filesToBeUpdated; - foreach (const CppTools::CppModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) + foreach (const CppTools::ProjectInfo &info, modelManager->projectInfos()) filesToBeUpdated << info.project().data()->files(ProjectExplorer::Project::ExcludeGeneratedFiles); modelManager->updateSourceFiles(filesToBeUpdated);