summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/ModelManagerInterface.cpp10
-rw-r--r--src/plugins/cpptools/ModelManagerInterface.h91
-rw-r--r--src/plugins/cpptools/cppmodelmanager.cpp66
-rw-r--r--src/plugins/cpptools/cppmodelmanager.h4
-rw-r--r--src/plugins/cpptools/cppmodelmanager_test.cpp16
-rw-r--r--src/plugins/cpptools/cppprojectfile.cpp101
-rw-r--r--src/plugins/cpptools/cppprojectfile.h86
-rw-r--r--src/plugins/cpptools/cpptools.pro6
8 files changed, 299 insertions, 81 deletions
diff --git a/src/plugins/cpptools/ModelManagerInterface.cpp b/src/plugins/cpptools/ModelManagerInterface.cpp
index c7d52785da..8f877f0cbe 100644
--- a/src/plugins/cpptools/ModelManagerInterface.cpp
+++ b/src/plugins/cpptools/ModelManagerInterface.cpp
@@ -82,7 +82,7 @@ void CppModelManagerInterface::ProjectInfo::clearProjectParts()
}
void CppModelManagerInterface::ProjectInfo::appendProjectPart(
- const CppModelManagerInterface::ProjectPart::Ptr &part)
+ const ProjectPart::Ptr &part)
{
if (!part)
return;
@@ -103,12 +103,8 @@ void CppModelManagerInterface::ProjectInfo::appendProjectPart(
// update source files
QSet<QString> srcs = QSet<QString>::fromList(m_sourceFiles);
- foreach (const QString &src, part->headerFiles)
- srcs.insert(src);
- foreach (const QString &src, part->sourceFiles)
- srcs.insert(src);
- foreach (const QString &src, part->objcSourceFiles)
- srcs.insert(src);
+ foreach (const ProjectFile &file, part->files)
+ srcs.insert(file.path);
m_sourceFiles = srcs.toList();
// update defines
diff --git a/src/plugins/cpptools/ModelManagerInterface.h b/src/plugins/cpptools/ModelManagerInterface.h
index f57b038778..5376daad25 100644
--- a/src/plugins/cpptools/ModelManagerInterface.h
+++ b/src/plugins/cpptools/ModelManagerInterface.h
@@ -33,6 +33,7 @@
#include <cplusplus/CppDocument.h>
#include <languageutils/fakemetaobject.h>
#include "cpptools_global.h"
+#include "cppprojectfile.h"
#include <QObject>
#include <QHash>
@@ -63,48 +64,64 @@ namespace CppTools {
namespace CPlusPlus {
-class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
+class CPPTOOLS_EXPORT ProjectPart
{
- Q_OBJECT
+public:
+ ProjectPart()
+ : cVersion(C89)
+ , cxxVersion(CXX11)
+ , cxxExtensions(NoExtensions)
+ , qtVersion(UnknownQt)
+ {}
public:
+ enum CVersion {
+ C89,
+ C99,
+ C11
+ };
- class CPPTOOLS_EXPORT ProjectPart
- {
- public:
- ProjectPart()
- : language(CXX11)
- , qtVersion(UnknownQt)
- {}
-
- public: // enums and types
- enum Language {
- C89 = 1,
- C99 = 2,
- CXX = 3,
- CXX11 = 4
- };
- enum QtVersion {
- UnknownQt = -1,
- NoQt = 0,
- Qt4 = 1,
- Qt5 = 2
- };
-
- typedef QSharedPointer<ProjectPart> Ptr;
-
- public: //attributes
- QStringList headerFiles;
- QStringList sourceFiles;
- QStringList objcSourceFiles;
- QByteArray defines;
- QStringList includePaths;
- QStringList frameworkPaths;
- QStringList precompiledHeaders;
- Language language;
- QtVersion qtVersion;
+ enum CXXVersion {
+ CXX98,
+ CXX11
+ };
+
+ enum CXXExtension {
+ NoExtensions = 0x0,
+ GnuExtensions = 0x1,
+ MicrosoftExtensions = 0x2,
+ BorlandExtensions = 0x4,
+ OpenMP = 0x8
+ };
+ Q_DECLARE_FLAGS(CXXExtensions, CXXExtension)
+
+ enum QtVersion {
+ UnknownQt = -1,
+ NoQt = 0,
+ Qt4 = 1,
+ Qt5 = 2
};
+ typedef QSharedPointer<ProjectPart> Ptr;
+
+public: //attributes
+ QList<ProjectFile> files;
+ QByteArray defines;
+ QStringList includePaths;
+ QStringList frameworkPaths;
+ QStringList precompiledHeaders;
+ CVersion cVersion;
+ CXXVersion cxxVersion;
+ CXXExtensions cxxExtensions;
+ QtVersion qtVersion;
+};
+
+class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
+{
+ Q_OBJECT
+
+public:
+
class CPPTOOLS_EXPORT ProjectInfo
{
public:
@@ -252,4 +269,6 @@ public Q_SLOTS:
} // namespace CPlusPlus
+QDebug operator <<(QDebug stream, const CPlusPlus::ProjectFile &cxxFile);
+
#endif // CPPMODELMANAGERINTERFACE_H
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index ce615d5c6b..7dd4c79a2b 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -89,9 +89,9 @@
namespace CPlusPlus {
-uint qHash(const CppModelManagerInterface::ProjectPart &p)
+uint qHash(const ProjectPart &p)
{
- uint h = qHash(p.defines) ^ p.language ^ p.qtVersion;
+ uint h = qHash(p.defines) ^ p.cVersion ^ p.cxxVersion ^ p.cxxExtensions ^ p.qtVersion;
foreach (const QString &i, p.includePaths)
h ^= qHash(i);
@@ -102,12 +102,16 @@ uint qHash(const CppModelManagerInterface::ProjectPart &p)
return h;
}
-bool operator==(const CppModelManagerInterface::ProjectPart &p1,
- const CppModelManagerInterface::ProjectPart &p2)
+bool operator==(const ProjectPart &p1,
+ const ProjectPart &p2)
{
if (p1.defines != p2.defines)
return false;
- if (p1.language != p2.language)
+ if (p1.cVersion != p2.cVersion)
+ return false;
+ if (p1.cxxVersion != p2.cxxVersion)
+ return false;
+ if (p1.cxxExtensions != p2.cxxExtensions)
return false;
if (p1.qtVersion!= p2.qtVersion)
return false;
@@ -769,9 +773,8 @@ QStringList CppModelManager::internalProjectFiles() const
it.next();
ProjectInfo pinfo = it.value();
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
- files += part->headerFiles;
- files += part->sourceFiles;
- files += part->objcSourceFiles;
+ foreach (const ProjectFile &file, part->files)
+ files += file.path;
}
}
files.removeDuplicates();
@@ -839,24 +842,37 @@ void CppModelManager::dumpModelManagerConfiguration()
qDebug()<<" for project:"<< pinfo.project().data()->document()->fileName();
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
qDebug() << "=== part ===";
- const char* lang;
- switch (part->language) {
- case ProjectPart::CXX: lang = "C++"; break;
- case ProjectPart::CXX11: lang = "C++11"; break;
- case ProjectPart::C89: lang = "C89"; break;
- case ProjectPart::C99: lang = "C99"; break;
- default: lang = "INVALID";
+ const char* cVersion;
+ const char* cxxVersion;
+ const char* cxxExtensions;
+ switch (part->cVersion) {
+ case ProjectPart::C89: cVersion = "C89"; break;
+ case ProjectPart::C99: cVersion = "C99"; break;
+ case ProjectPart::C11: cVersion = "C11"; break;
+ default: cVersion = "INVALID";
+ }
+ switch (part->cxxVersion) {
+ case ProjectPart::CXX98: cVersion = "CXX98"; break;
+ case ProjectPart::CXX11: cVersion = "CXX11"; break;
+ default: cxxVersion = "INVALID";
+ }
+ switch (part->cxxExtensions) {
+ case ProjectPart::NoExtensions: cVersion = "NoExtensions"; break;
+ case ProjectPart::GnuExtensions: cVersion = "GnuExtensions"; break;
+ case ProjectPart::MicrosoftExtensions: cVersion = "MicrosoftExtensions"; break;
+ case ProjectPart::BorlandExtensions: cVersion = "BorlandExtensions"; break;
+ default: cxxExtensions = "INVALID";
}
- qDebug() << "language:" << lang;
+ qDebug() << "cVersion:" << cVersion;
+ qDebug() << "cxxVersion:" << cxxVersion;
+ qDebug() << "cxxExtensions:" << cxxExtensions;
qDebug() << "Qt version:" << part->qtVersion;
qDebug() << "precompiled header:" << part->precompiledHeaders;
qDebug() << "defines:" << part->defines;
qDebug() << "includes:" << part->includePaths;
qDebug() << "frameworkPaths:" << part->frameworkPaths;
- qDebug() << "headers:" << part->headerFiles;
- qDebug() << "sources:" << part->sourceFiles;
- qDebug() << "objc sources:" << part->objcSourceFiles;
+ qDebug() << "files:" << part->files;
qDebug() << "";
}
}
@@ -988,12 +1004,8 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
foreach (const ProjectInfo &projectInfo, m_projects) {
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
- foreach (const QString &sourceFile, projectPart->sourceFiles)
- m_srcToProjectPart[sourceFile].append(projectPart);
- foreach (const QString &objcSourceFile, projectPart->objcSourceFiles)
- m_srcToProjectPart[objcSourceFile].append(projectPart);
- foreach (const QString &headerFile, projectPart->headerFiles)
- m_srcToProjectPart[headerFile].append(projectPart);
+ foreach (const ProjectFile &cxxFile, projectPart->files)
+ m_srcToProjectPart[cxxFile.path].append(projectPart);
}
}
}
@@ -1004,9 +1016,9 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
emit projectPartsUpdated(pinfo.project().data());
}
-QList<CppModelManager::ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
+QList<ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
{
- QList<CppModelManager::ProjectPart::Ptr> parts = m_srcToProjectPart.value(fileName);
+ QList<ProjectPart::Ptr> parts = m_srcToProjectPart.value(fileName);
if (!parts.isEmpty())
return parts;
diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h
index c882a0ec4f..503c3c5258 100644
--- a/src/plugins/cpptools/cppmodelmanager.h
+++ b/src/plugins/cpptools/cppmodelmanager.h
@@ -94,7 +94,7 @@ public:
virtual QList<ProjectInfo> projectInfos() const;
virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
virtual void updateProjectInfo(const ProjectInfo &pinfo);
- virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const;
+ virtual QList<CPlusPlus::ProjectPart::Ptr> projectPart(const QString &fileName) const;
virtual CPlusPlus::Snapshot snapshot() const;
virtual Document::Ptr document(const QString &fileName) const;
@@ -244,7 +244,7 @@ private:
mutable QMutex m_protectExtraDiagnostics;
QHash<QString, QHash<int, QList<Document::DiagnosticMessage> > > m_extraDiagnostics;
- QMap<QString, QList<ProjectPart::Ptr> > m_srcToProjectPart;
+ QMap<QString, QList<CPlusPlus::ProjectPart::Ptr> > m_srcToProjectPart;
CppCompletionAssistProvider *m_completionAssistProvider;
CppCompletionAssistProvider *m_completionFallback;
diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp
index 338aa01d79..a5eb79914b 100644
--- a/src/plugins/cpptools/cppmodelmanager_test.cpp
+++ b/src/plugins/cpptools/cppmodelmanager_test.cpp
@@ -39,7 +39,8 @@ using namespace CppTools::Internal;
typedef CPlusPlus::Document Document;
typedef CPlusPlus::CppModelManagerInterface::ProjectInfo ProjectInfo;
-typedef CPlusPlus::CppModelManagerInterface::ProjectPart ProjectPart;
+typedef CPlusPlus::ProjectPart ProjectPart;
+typedef CPlusPlus::ProjectFile ProjectFile;
typedef ProjectExplorer::Project Project;
namespace {
@@ -81,7 +82,7 @@ void CppToolsPlugin::test_modelmanager_paths()
ProjectPart::Ptr part(new ProjectPart);
pi.appendProjectPart(part);
- part->language = ProjectPart::CXX;
+ part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths = QStringList() << testIncludeDir(false);
@@ -109,19 +110,20 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
ProjectPart::Ptr part(new ProjectPart);
pi.appendProjectPart(part);
- part->language = ProjectPart::CXX;
+ part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths << testIncludeDir();
part->frameworkPaths << testFrameworksDir();
- part->sourceFiles << testSource(QLatin1String("test_modelmanager_framework_headers.cpp"));
+ const QString &source = testSource(QLatin1String("test_modelmanager_framework_headers.cpp"));
+ part->files << ProjectFile(source, ProjectFile::CXXSource);
mm->updateProjectInfo(pi);
- mm->updateSourceFiles(part->sourceFiles).waitForFinished();
+ mm->updateSourceFiles(QStringList(source)).waitForFinished();
QCoreApplication::processEvents();
- QVERIFY(mm->snapshot().contains(part->sourceFiles.first()));
- Document::Ptr doc = mm->snapshot().document(part->sourceFiles.first());
+ QVERIFY(mm->snapshot().contains(source));
+ Document::Ptr doc = mm->snapshot().document(source);
QVERIFY(!doc.isNull());
CPlusPlus::Namespace *ns = doc->globalNamespace();
QVERIFY(ns);
diff --git a/src/plugins/cpptools/cppprojectfile.cpp b/src/plugins/cpptools/cppprojectfile.cpp
new file mode 100644
index 0000000000..20e58a60ae
--- /dev/null
+++ b/src/plugins/cpptools/cppprojectfile.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 "cppprojectfile.h"
+#include <coreplugin/icore.h>
+#include "cpptoolsconstants.h"
+#include <QDebug>
+
+namespace CPlusPlus {
+
+ProjectFile::ProjectFile()
+ : kind(CHeader)
+{
+}
+
+ProjectFile::ProjectFile(const QString &file, Kind kind)
+ : path(file)
+ , kind(kind)
+{
+}
+
+ProjectFileAdder::ProjectFileAdder(QList<ProjectFile> &files)
+ : m_files(files)
+{
+ addMapping(CppTools::Constants::C_SOURCE_MIMETYPE, ProjectFile::CSource);
+ addMapping(CppTools::Constants::C_HEADER_MIMETYPE, ProjectFile::CHeader);
+ addMapping(CppTools::Constants::CPP_SOURCE_MIMETYPE, ProjectFile::CSource);
+ addMapping(CppTools::Constants::CPP_HEADER_MIMETYPE, ProjectFile::CHeader);
+ addMapping(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE, ProjectFile::ObjCXXSource);
+}
+
+ProjectFileAdder::~ProjectFileAdder()
+{
+}
+
+bool ProjectFileAdder::maybeAdd(const QString &path)
+{
+ m_fileInfo.setFile(path);
+ foreach (const Pair &pair, m_mapping)
+ if (pair.first.matchesFile(path)) {
+ m_files << ProjectFile(path, pair.second);
+ return true;
+ }
+ return false;
+}
+
+void ProjectFileAdder::addMapping(const char *mimeName, ProjectFile::Kind kind)
+{
+ const Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
+ Core::MimeType mimeType = mimeDatabase->findByType(QLatin1String(mimeName));
+ if (!mimeType.isNull())
+ m_mapping.append(Pair(mimeType, kind));
+}
+
+} // namespace CPlusPlus
+
+QDebug operator <<(QDebug stream, const CPlusPlus::ProjectFile &cxxFile)
+{
+ const char *kind;
+ switch (cxxFile.kind) {
+ case CPlusPlus::ProjectFile::CHeader: kind = "CHeader"; break;
+ case CPlusPlus::ProjectFile::CSource: kind = "CSource"; break;
+ case CPlusPlus::ProjectFile::CXXHeader: kind = "CXXHeader"; break;
+ case CPlusPlus::ProjectFile::CXXSource: kind = "CXXSource"; break;
+ case CPlusPlus::ProjectFile::ObjCHeader: kind = "ObjCHeader"; break;
+ case CPlusPlus::ProjectFile::ObjCSource: kind = "ObjCSource"; break;
+ case CPlusPlus::ProjectFile::ObjCXXHeader: kind = "ObjCXXHeader"; break;
+ case CPlusPlus::ProjectFile::ObjCXXSource: kind = "ObjCXXSource"; break;
+ case CPlusPlus::ProjectFile::CudaSource: kind = "CudaSource"; break;
+ case CPlusPlus::ProjectFile::OpenCLSource: kind = "OpenCLSource"; break;
+ default: kind = "INVALID"; break;
+ }
+ stream << cxxFile.path << QLatin1String(", ") << kind;
+ return stream;
+}
diff --git a/src/plugins/cpptools/cppprojectfile.h b/src/plugins/cpptools/cppprojectfile.h
new file mode 100644
index 0000000000..ffe4e9c1c0
--- /dev/null
+++ b/src/plugins/cpptools/cppprojectfile.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 CPLUSPLUS_CPPPROJECTFILE_H
+#define CPLUSPLUS_CPPPROJECTFILE_H
+
+#include <QString>
+#include <QMap>
+#include <coreplugin/mimedatabase.h>
+#include "cpptools_global.h"
+
+namespace CPlusPlus {
+
+class CPPTOOLS_EXPORT ProjectFile
+{
+public:
+ // enums and types
+ enum Kind {
+ CHeader = 1,
+ CSource = 2,
+ CXXHeader = 3,
+ CXXSource = 4,
+ ObjCHeader = 5,
+ ObjCSource = 6,
+ ObjCXXHeader = 7,
+ ObjCXXSource = 8,
+ CudaSource = 9,
+ OpenCLSource = 10
+ };
+
+ ProjectFile();
+ ProjectFile(const QString &file, Kind kind);
+
+ QString path;
+ Kind kind;
+};
+
+class CPPTOOLS_EXPORT ProjectFileAdder
+{
+public:
+ ProjectFileAdder(QList<ProjectFile> &files);
+ ~ProjectFileAdder();
+
+ bool maybeAdd(const QString &path);
+
+private:
+ typedef QPair<Core::MimeType, ProjectFile::Kind> Pair;
+
+ void addMapping(const char *mimeName, ProjectFile::Kind kind);
+
+ QList<ProjectFile> &m_files;
+ QList<Pair> m_mapping;
+ QFileInfo m_fileInfo;
+};
+
+} // namespace CPlusPlus
+
+QDebug operator <<(QDebug stream, const CPlusPlus::ProjectFile &cxxFile);
+
+#endif // CPLUSPLUS_CPPPROJECTFILE_H
diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro
index 50ffa5d562..a6f329db4e 100644
--- a/src/plugins/cpptools/cpptools.pro
+++ b/src/plugins/cpptools/cpptools.pro
@@ -48,7 +48,8 @@ HEADERS += completionsettingspage.h \
TypeHierarchyBuilder.h \
cppindexingsupport.h \
builtinindexingsupport.h \
- cpppointerdeclarationformatter.h
+ cpppointerdeclarationformatter.h \
+ cppprojectfile.h
SOURCES += completionsettingspage.cpp \
cppclassesfilter.cpp \
@@ -90,7 +91,8 @@ SOURCES += completionsettingspage.cpp \
TypeHierarchyBuilder.cpp \
cppindexingsupport.cpp \
builtinindexingsupport.cpp \
- cpppointerdeclarationformatter.cpp
+ cpppointerdeclarationformatter.cpp \
+ cppprojectfile.cpp
FORMS += completionsettingspage.ui \
cppfilesettingspage.ui \