Supply c++11 flags and per-project info to c++ code model.

A manual squash/merge of the changes below, plus a couple of subsequent
code fixes.

59085aa5fbb99e2d786cd2c1a06c24a111ccb49f:
    Modify CppModel::ProjectInfo

    Adding per project node information, to pass on the correct
    defines/includes for each file, instead of aggregating them incorrectly.

    Also split up SOURCES and OBJECTIVE_SOURCES.

    Also ask the toolchain to convert the compilerflags to flags the
    codemodel understands, for now only gcc and only c++11.

    Also make the toolchain aware of the flags used to compile, so that it
    can emit the correct defines.

    Note: No header files are passed on.

74028802314cd4e75b41b46407433e07090a304d:
    GCC: Evaluate cxxflags when checking for predefined macros

ebaaa4957e4c02cc9637a998eddae1d0acd74f83:
    MSVC: Take cxxflags into account when checking for predefined macros

9bfce7e889bcf7bcc47bf880e3ea25945ca7d0d7:
    Compile fixes

Change-Id: I9de94ad038dfc5dc1987732e84b13fb4419c96f5
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
This commit is contained in:
Erik Verbruggen
2012-02-16 15:09:56 +01:00
parent 89e64b5aed
commit 3aab8beaf4
31 changed files with 519 additions and 195 deletions

View File

@@ -90,6 +90,34 @@
#include <iostream>
#include <sstream>
namespace CPlusPlus {
uint qHash(const CppModelManagerInterface::ProjectPart &p)
{
uint h = qHash(p.defines) ^ p.language ^ p.flags;
foreach (const QString &i, p.includePaths)
h ^= qHash(i);
foreach (const QString &f, p.frameworkPaths)
h ^= qHash(f);
return h;
}
bool operator==(const CppModelManagerInterface::ProjectPart &p1,
const CppModelManagerInterface::ProjectPart &p2)
{
if (p1.defines != p2.defines)
return false;
if (p1.language != p2.language)
return false;
if (p1.flags != p2.flags)
return false;
if (p1.includePaths != p2.includePaths)
return false;
return p1.frameworkPaths == p2.frameworkPaths;
}
} // namespace CPlusPlus
using namespace CppTools;
using namespace CppTools::Internal;
using namespace CPlusPlus;
@@ -733,7 +761,8 @@ QStringList CppModelManager::internalProjectFiles() const
while (it.hasNext()) {
it.next();
ProjectInfo pinfo = it.value();
files += pinfo.sourceFiles;
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
files += part->sourceFiles;
}
files.removeDuplicates();
return files;
@@ -746,7 +775,8 @@ QStringList CppModelManager::internalIncludePaths() const
while (it.hasNext()) {
it.next();
ProjectInfo pinfo = it.value();
includePaths += pinfo.includePaths;
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
includePaths += part->includePaths;
}
includePaths.removeDuplicates();
return includePaths;
@@ -759,7 +789,8 @@ QStringList CppModelManager::internalFrameworkPaths() const
while (it.hasNext()) {
it.next();
ProjectInfo pinfo = it.value();
frameworkPaths += pinfo.frameworkPaths;
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
frameworkPaths += part->frameworkPaths;
}
frameworkPaths.removeDuplicates();
return frameworkPaths;
@@ -772,7 +803,8 @@ QByteArray CppModelManager::internalDefinedMacros() const
while (it.hasNext()) {
it.next();
ProjectInfo pinfo = it.value();
macros += pinfo.defines;
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
macros += part->defines;
}
return macros;
}
@@ -860,13 +892,66 @@ CppModelManager::ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Proje
void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
{
#if 0
// Tons of debug output...
qDebug()<<"========= CppModelManager::updateProjectInfo ======";
qDebug()<<" for project:"<< pinfo.project.data()->file()->fileName();
foreach (const ProjectPart::Ptr &part, pinfo.projectParts) {
qDebug() << "=== part ===";
qDebug() << "language:" << (part->language == CXX ? "C++" : "ObjC++");
qDebug() << "compilerflags:" << part->flags;
qDebug() << "precompiled header:" << part->precompiledHeaders;
qDebug() << "defines:" << part->defines;
qDebug() << "includes:" << part->includePaths;
qDebug() << "frameworkPaths:" << part->frameworkPaths;
qDebug() << "sources:" << part->sourceFiles;
qDebug() << "";
}
qDebug() << "";
#endif
QMutexLocker locker(&mutex);
if (! pinfo.isValid())
return;
m_projects.insert(pinfo.project, pinfo);
ProjectExplorer::Project *project = pinfo.project().data();
m_projects.insert(project, pinfo);
m_dirty = true;
m_srcToProjectPart.clear();
foreach (const ProjectPart::Ptr &projectPart, pinfo.projectParts()) {
foreach (const QString &sourceFile, projectPart->sourceFiles) {
m_srcToProjectPart[sourceFile].append(projectPart);
}
}
}
QList<CppModelManager::ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
{
QList<CppModelManager::ProjectPart::Ptr> parts = m_srcToProjectPart.value(fileName);
if (!parts.isEmpty())
return parts;
//### FIXME: This is a DIRTY hack!
if (fileName.endsWith(".h")) {
QString cppFile = fileName.mid(0, fileName.length() - 2) + QLatin1String(".cpp");
parts = m_srcToProjectPart.value(cppFile);
if (!parts.isEmpty())
return parts;
}
DependencyTable table;
table.build(snapshot());
QStringList deps = table.filesDependingOn(fileName);
foreach (const QString &dep, deps) {
parts = m_srcToProjectPart.value(dep);
if (!parts.isEmpty())
return parts;
}
return parts;
}
QFuture<void> CppModelManager::refreshSourceFiles(const QStringList &sourceFiles)