Commit 6b5298fa authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

CppTools: Move Project{Part,Info} to new cppprojects.{h,cpp}

Change-Id: Ieff216017b9da1e6a12121688ea9572bdd81fd9b
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent b8a6a4dd
......@@ -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;
......
......@@ -441,7 +441,7 @@ void PchManager::updateActivePchFiles()
QSet<ProjectPart::Ptr> 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<ProjectPart::Ptr>::fromList(pi.projectParts()));
QList<ProjectPart::Ptr> partsWithPCHFiles = m_activePchFiles.keys();
foreach (ProjectPart::Ptr pPart, partsWithPCHFiles)
......
......@@ -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) {
......
......@@ -949,7 +949,7 @@ class ProjectPartsModel : public QAbstractListModel
public:
ProjectPartsModel(QObject *parent);
void configure(const QList<CppModelManagerInterface::ProjectInfo> &projectInfos,
void configure(const QList<ProjectInfo> &projectInfos,
const ProjectPart::Ptr &currentEditorsProjectPart);
QModelIndex indexForCurrentEditorsProjectPart() const;
......@@ -972,12 +972,12 @@ ProjectPartsModel::ProjectPartsModel(QObject *parent)
{
}
void ProjectPartsModel::configure(const QList<CppModelManagerInterface::ProjectInfo> &projectInfos,
void ProjectPartsModel::configure(const QList<ProjectInfo> &projectInfos,
const ProjectPart::Ptr &currentEditorsProjectPart)
{
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<CppModelManagerInterface::ProjectInfo> projectInfos = cmmi->projectInfos();
const QList<ProjectInfo> projectInfos = cmmi->projectInfos();
dumper.dumpProjectInfos(projectInfos);
m_projectPartsModel->configure(projectInfos, editorsProjectPart);
m_projectPartsView->resizeColumns(ProjectPartsModel::ColumnCount);
......
......@@ -1903,9 +1903,9 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
// find the include paths
ProjectPart::HeaderPaths headerPaths;
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
QList<CppModelManagerInterface::ProjectInfo> projectInfos = modelManager->projectInfos();
QList<ProjectInfo> 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()) {
......
......@@ -150,12 +150,12 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
// Collect files to process
QStringList filesToOpen;
QList<QPointer<ProjectExplorer::Project> > projects;
const QList<CppModelManagerInterface::ProjectInfo> projectInfos
const QList<ProjectInfo> 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<ProjectExplorer::Project> project = info.project();
if (!projects.contains(project))
projects << project;
......
......@@ -472,7 +472,7 @@ Dumper::~Dumper()
m_out << "*** END Code Model Inspection Report\n";
}
void Dumper::dumpProjectInfos( const QList<CppModelManagerInterface::ProjectInfo> &projectInfos)
void Dumper::dumpProjectInfos( const QList<ProjectInfo> &projectInfos)
{
const QByteArray i1 = indent(1);
const QByteArray i2 = indent(2);
......@@ -480,7 +480,7 @@ void Dumper::dumpProjectInfos( const QList<CppModelManagerInterface::ProjectInfo
const QByteArray i4 = indent(4);
m_out << "Projects loaded: " << projectInfos.size() << "{{{1\n";
foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) {
foreach (const ProjectInfo &info, projectInfos) {
const QPointer<ProjectExplorer::Project> project = info.project();
m_out << i1 << "Project " << project->displayName()
<< " (" << project->projectFilePath().toUserOutput() << "){{{2\n";
......
......@@ -69,7 +69,7 @@ public:
const QString &logFileId = QString());
~Dumper();
void dumpProjectInfos(const QList<CppTools::CppModelManagerInterface::ProjectInfo> &projectInfos);
void dumpProjectInfos(const QList<CppTools::ProjectInfo> &projectInfos);
void dumpSnapshot(const CPlusPlus::Snapshot &snapshot,
const QString &title,
bool isGlobalSnapshot = false);
......
......@@ -368,7 +368,7 @@ QByteArray CppModelManager::internalDefinedMacros() const
addUnique(part->toolchainDefines.split('\n'), &macros, &alreadyIn);
addUnique(part->projectDefines.split('\n'), &macros, &alreadyIn);
if (!part->projectConfigFile.isEmpty())
macros += readProjectConfigFile(part);
macros += ProjectPart::readProjectConfigFile(part);
}
}
return macros;
......@@ -523,13 +523,13 @@ QFuture<void> CppModelManager::updateSourceFiles(const QStringList &sourceFiles,
return m_internalIndexingSupport->refreshSourceFiles(sourceFiles, mode);
}
QList<CppModelManager::ProjectInfo> CppModelManager::projectInfos() const
QList<ProjectInfo> 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<QString> &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<QString> m_oldSourceFiles;
const CppModelManager::ProjectInfo &m_new;
const ProjectInfo &m_new;
const QSet<QString> m_newSourceFiles;
};
......
......@@ -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;
......
......@@ -34,8 +34,6 @@
#include <projectexplorer/headerpath.h>
#include <projectexplorer/toolchain.h>
#include <QSet>
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<ProjectExplorer::HeaderPath> 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<CppModelManagerInterface *>(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<HeaderPath> incs = QSet<HeaderPath>::fromList(m_headerPaths);
foreach (const HeaderPath &hp, part->headerPaths) {
if (!incs.contains(hp)) {
incs.insert(hp);
m_headerPaths += hp;
}
}
// Update source files
QSet<QString> srcs = QSet<QString>::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;
}
......@@ -32,11 +32,10 @@
#include "cpptools_global.h"
#include "cppprojectfile.h"
#include "cppprojects.h"
#include <cplusplus/CppDocument.h>
#include <cplusplus/cppmodelmanagerbase.h>
#include <projectexplorer/toolchain.h>
#include <QFuture>
#include <QHash>
......@@ -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<ProjectPart> 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<HeaderPath> HeaderPaths;
public:
QString displayName;
QString projectFile;
ProjectExplorer::Project *project;
QList<ProjectFile> files;
QString projectConfigFile; // currently only used by the Generic Project Manager
QByteArray projectDefines;
QByteArray toolchainDefines;
QList<HeaderPath> 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<ProjectExplorer::Project> 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<ProjectExplorer::Project> project() const
{ return m_project; }
const QList<ProjectPart::Ptr> 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<ProjectExplorer::Project> m_project;
QList<ProjectPart::Ptr> 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
......
/****************************************************************************
**
** 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 <projectexplorer/headerpath.h>
#include <QSet>
#include <QTextStream>
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<ProjectExplorer::HeaderPath> 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<ProjectExplorer::Project> 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<ProjectExplorer::Project> ProjectInfo::project() const
{
return m_project;
}
const QList<ProjectPart::Ptr> 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<HeaderPath> incs = QSet<HeaderPath>::fromList(m_headerPaths);
foreach (const HeaderPath &hp, part->headerPaths) {
if (!incs.contains(hp)) {
incs.insert(hp);
m_headerPaths += hp;
}
}
// Update source files
QSet<QString> srcs = QSet<QString>::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
{