2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cppmodelmanager.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
#include "abstracteditorsupport.h"
|
2013-03-12 12:06:41 +01:00
|
|
|
#include "builtinindexingsupport.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
#include "cppcodemodelsettings.h"
|
2013-07-11 11:13:07 +02:00
|
|
|
#include "cppfindreferences.h"
|
2012-02-20 12:39:08 +01:00
|
|
|
#include "cpphighlightingsupport.h"
|
2012-10-16 16:02:40 +02:00
|
|
|
#include "cppindexingsupport.h"
|
2013-09-04 18:15:08 +02:00
|
|
|
#include "cppmodelmanagersupportinternal.h"
|
2013-07-11 11:13:07 +02:00
|
|
|
#include "cpppreprocessor.h"
|
|
|
|
#include "cpptoolsconstants.h"
|
2012-09-07 10:51:50 +02:00
|
|
|
#include "cpptoolseditorsupport.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
#include "cpptoolsplugin.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2012-09-07 10:51:50 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/session.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QTextBlock>
|
2013-07-11 11:13:07 +02:00
|
|
|
#include <QTimer>
|
2010-04-26 14:02:09 +02:00
|
|
|
|
2013-04-23 15:04:36 +02:00
|
|
|
#if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU)
|
|
|
|
#define WITH_AST_DUMP
|
2009-02-18 16:01:28 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2013-04-23 15:04:36 +02:00
|
|
|
#endif
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2013-04-02 11:28:11 +02:00
|
|
|
namespace CppTools {
|
2012-11-23 16:29:00 +01:00
|
|
|
|
2013-03-04 01:30:46 +04:00
|
|
|
uint qHash(const ProjectPart &p)
|
2012-02-16 15:09:56 +01:00
|
|
|
{
|
2013-03-04 01:30:46 +04:00
|
|
|
uint h = qHash(p.defines) ^ p.cVersion ^ p.cxxVersion ^ p.cxxExtensions ^ p.qtVersion;
|
2012-02-16 15:09:56 +01:00
|
|
|
|
|
|
|
foreach (const QString &i, p.includePaths)
|
|
|
|
h ^= qHash(i);
|
|
|
|
|
|
|
|
foreach (const QString &f, p.frameworkPaths)
|
|
|
|
h ^= qHash(f);
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
2012-11-23 16:29:00 +01:00
|
|
|
|
2013-03-04 01:30:46 +04:00
|
|
|
bool operator==(const ProjectPart &p1,
|
|
|
|
const ProjectPart &p2)
|
2012-02-16 15:09:56 +01:00
|
|
|
{
|
|
|
|
if (p1.defines != p2.defines)
|
|
|
|
return false;
|
2013-03-04 01:30:46 +04:00
|
|
|
if (p1.cVersion != p2.cVersion)
|
|
|
|
return false;
|
|
|
|
if (p1.cxxVersion != p2.cxxVersion)
|
|
|
|
return false;
|
|
|
|
if (p1.cxxExtensions != p2.cxxExtensions)
|
2012-02-16 15:09:56 +01:00
|
|
|
return false;
|
2012-11-23 16:29:00 +01:00
|
|
|
if (p1.qtVersion!= p2.qtVersion)
|
2012-02-16 15:09:56 +01:00
|
|
|
return false;
|
|
|
|
if (p1.includePaths != p2.includePaths)
|
|
|
|
return false;
|
|
|
|
return p1.frameworkPaths == p2.frameworkPaths;
|
|
|
|
}
|
2012-11-23 16:29:00 +01:00
|
|
|
|
2013-04-02 11:28:11 +02:00
|
|
|
} // namespace CppTools
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2008-12-08 11:08:48 +01:00
|
|
|
using namespace CppTools;
|
|
|
|
using namespace CppTools::Internal;
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
#ifdef QTCREATOR_WITH_DUMP_AST
|
2009-02-18 16:01:28 +01:00
|
|
|
|
|
|
|
#include <cxxabi.h>
|
|
|
|
|
|
|
|
class DumpAST: protected ASTVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int depth;
|
|
|
|
|
|
|
|
DumpAST(Control *control)
|
|
|
|
: ASTVisitor(control), depth(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void operator()(AST *ast)
|
|
|
|
{ accept(ast); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool preVisit(AST *ast)
|
|
|
|
{
|
|
|
|
std::ostringstream s;
|
|
|
|
PrettyPrinter pp(control(), s);
|
|
|
|
pp(ast);
|
|
|
|
QString code = QString::fromStdString(s.str());
|
|
|
|
code.replace('\n', ' ');
|
|
|
|
code.replace(QRegExp("\\s+"), " ");
|
|
|
|
|
|
|
|
const char *name = abi::__cxa_demangle(typeid(*ast).name(), 0, 0, 0) + 11;
|
|
|
|
|
|
|
|
QByteArray ind(depth, ' ');
|
|
|
|
ind += name;
|
|
|
|
|
|
|
|
printf("%-40s %s\n", ind.constData(), qPrintable(code));
|
|
|
|
++depth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void postVisit(AST *)
|
|
|
|
{ --depth; }
|
|
|
|
};
|
|
|
|
|
2009-03-05 09:46:54 +01:00
|
|
|
#endif // QTCREATOR_WITH_DUMP_AST
|
2009-02-18 16:01:28 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
static const char pp_configuration[] =
|
|
|
|
"# 1 \"<configuration>\"\n"
|
2013-05-27 11:37:50 +02:00
|
|
|
"#define Q_CREATOR_RUN 1\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
"#define __cplusplus 1\n"
|
|
|
|
"#define __extension__\n"
|
|
|
|
"#define __context__\n"
|
|
|
|
"#define __range__\n"
|
|
|
|
"#define restrict\n"
|
|
|
|
"#define __restrict\n"
|
2009-07-17 10:54:08 +02:00
|
|
|
"#define __restrict__\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-02-23 09:53:26 +01:00
|
|
|
"#define __complex__\n"
|
|
|
|
"#define __imag__\n"
|
|
|
|
"#define __real__\n"
|
|
|
|
|
2009-06-18 17:48:55 +02:00
|
|
|
"#define __builtin_va_arg(a,b) ((b)0)\n"
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ### add macros for win32
|
|
|
|
"#define __cdecl\n"
|
2009-12-10 16:20:34 +01:00
|
|
|
"#define __stdcall\n"
|
2008-12-02 12:01:29 +01:00
|
|
|
"#define QT_WA(x) x\n"
|
|
|
|
"#define CALLBACK\n"
|
|
|
|
"#define STDMETHODCALLTYPE\n"
|
|
|
|
"#define __RPC_FAR\n"
|
|
|
|
"#define __declspec(a)\n"
|
2011-09-06 16:45:47 +02:00
|
|
|
"#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method\n"
|
|
|
|
"#define __try try\n"
|
|
|
|
"#define __except catch\n"
|
2011-09-08 11:30:48 +02:00
|
|
|
"#define __finally\n"
|
|
|
|
"#define __inline inline\n"
|
|
|
|
"#define __forceinline inline\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
QStringList CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr> documentsToCheck)
|
2009-11-05 12:34:02 +01:00
|
|
|
{
|
|
|
|
QStringList sourceFiles;
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
foreach (const Document::Ptr doc, documentsToCheck) {
|
2009-11-05 12:34:02 +01:00
|
|
|
const QDateTime lastModified = doc->lastModified();
|
|
|
|
|
2013-07-24 11:59:39 +02:00
|
|
|
if (!lastModified.isNull()) {
|
2009-11-05 12:34:02 +01:00
|
|
|
QFileInfo fileInfo(doc->fileName());
|
|
|
|
|
|
|
|
if (fileInfo.exists() && fileInfo.lastModified() != lastModified)
|
|
|
|
sourceFiles.append(doc->fileName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
return sourceFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppModelManager::updateModifiedSourceFiles()
|
|
|
|
{
|
|
|
|
const Snapshot snapshot = this->snapshot();
|
|
|
|
QList<Document::Ptr> documentsToCheck;
|
|
|
|
foreach (const Document::Ptr document, snapshot)
|
|
|
|
documentsToCheck << document;
|
|
|
|
|
|
|
|
const QStringList filesToUpdate = timeStampModifiedFiles(documentsToCheck);
|
|
|
|
updateSourceFiles(filesToUpdate);
|
2009-11-05 12:34:02 +01:00
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
\class CppTools::CppModelManager
|
2013-07-11 11:13:07 +02:00
|
|
|
\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.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
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
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
QMutex CppModelManager::m_instanceMutex;
|
|
|
|
CppModelManager *CppModelManager::m_instance = 0;
|
2012-10-15 16:38:56 +02:00
|
|
|
|
|
|
|
CppModelManager *CppModelManager::instance()
|
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
if (m_instance)
|
|
|
|
return m_instance;
|
|
|
|
|
|
|
|
QMutexLocker locker(&m_instanceMutex);
|
|
|
|
if (!m_instance)
|
|
|
|
m_instance = new CppModelManager;
|
|
|
|
|
|
|
|
return m_instance;
|
2012-10-15 16:38:56 +02:00
|
|
|
}
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
CppModelManager::CppModelManager(QObject *parent)
|
2009-11-10 18:02:42 +01:00
|
|
|
: CppModelManagerInterface(parent)
|
2012-11-23 11:47:39 +01:00
|
|
|
, m_indexingSupporter(0)
|
2013-07-11 11:13:07 +02:00
|
|
|
, m_enableGC(true)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-08-07 13:02:36 +02:00
|
|
|
m_findReferences = new CppFindReferences(this);
|
2009-12-07 12:03:31 +01:00
|
|
|
m_indexerEnabled = qgetenv("QTCREATOR_NO_CODE_INDEXER").isNull();
|
2009-03-11 12:00:07 +01:00
|
|
|
|
2008-12-04 17:07:43 +01:00
|
|
|
m_dirty = true;
|
|
|
|
|
2013-07-18 10:57:19 +02:00
|
|
|
m_delayedGcTimer = new QTimer(this);
|
|
|
|
m_delayedGcTimer->setSingleShot(true);
|
|
|
|
connect(m_delayedGcTimer, SIGNAL(timeout()), this, SLOT(GC()));
|
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
QObject *sessionManager = ProjectExplorer::SessionManager::instance();
|
|
|
|
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
2008-12-04 17:07:43 +01:00
|
|
|
this, SLOT(onProjectAdded(ProjectExplorer::Project*)));
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
|
2012-03-05 22:30:59 +01:00
|
|
|
this, SLOT(onAboutToRemoveProject(ProjectExplorer::Project*)));
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(sessionManager, SIGNAL(aboutToLoadSession(QString)),
|
2013-07-18 10:57:19 +02:00
|
|
|
this, SLOT(onAboutToLoadSession()));
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(sessionManager, SIGNAL(aboutToUnloadSession(QString)),
|
2009-08-13 17:10:53 +02:00
|
|
|
this, SLOT(onAboutToUnloadSession()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-04-19 16:56:12 +02:00
|
|
|
connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()),
|
|
|
|
this, SLOT(onCoreAboutToClose()));
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr");
|
|
|
|
|
2013-09-04 18:15:08 +02:00
|
|
|
m_modelManagerSupportFallback.reset(new ModelManagerSupportInternal);
|
2013-09-06 13:14:15 +02:00
|
|
|
CppToolsPlugin::instance()->codeModelSettings()->setDefaultId(
|
|
|
|
m_modelManagerSupportFallback->id());
|
2013-09-04 18:15:08 +02:00
|
|
|
addModelManagerSupport(m_modelManagerSupportFallback.data());
|
|
|
|
|
2012-11-28 09:52:19 +01:00
|
|
|
m_internalIndexingSupport = new BuiltinIndexingSupport;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CppModelManager::~CppModelManager()
|
2012-02-20 12:39:08 +01:00
|
|
|
{
|
2012-10-16 16:02:40 +02:00
|
|
|
delete m_internalIndexingSupport;
|
2012-02-20 12:39:08 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-12 10:07:58 +01:00
|
|
|
Snapshot CppModelManager::snapshot() const
|
2009-03-04 09:38:01 +01:00
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_snapshotMutex);
|
2009-03-04 09:38:01 +01:00
|
|
|
return m_snapshot;
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-02-19 12:48:42 +01:00
|
|
|
Document::Ptr CppModelManager::document(const QString &fileName) const
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_snapshotMutex);
|
2013-02-19 12:48:42 +01:00
|
|
|
return m_snapshot.document(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Replace the document in the snapshot.
|
|
|
|
///
|
|
|
|
/// \returns true if successful, false if the new document is out-dated.
|
|
|
|
bool CppModelManager::replaceDocument(Document::Ptr newDoc)
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_snapshotMutex);
|
2013-02-19 12:48:42 +01:00
|
|
|
|
|
|
|
Document::Ptr previous = m_snapshot.document(newDoc->fileName());
|
|
|
|
if (previous && (newDoc->revision() != 0 && newDoc->revision() < previous->revision()))
|
|
|
|
// the new document is outdated
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_snapshot.insert(newDoc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-08 10:44:56 +01:00
|
|
|
void CppModelManager::ensureUpdated()
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2013-07-24 11:59:39 +02:00
|
|
|
if (!m_dirty)
|
2008-12-08 10:44:56 +01:00
|
|
|
return;
|
|
|
|
|
2008-12-08 14:48:51 +01:00
|
|
|
m_projectFiles = internalProjectFiles();
|
|
|
|
m_includePaths = internalIncludePaths();
|
|
|
|
m_frameworkPaths = internalFrameworkPaths();
|
|
|
|
m_definedMacros = internalDefinedMacros();
|
2008-12-08 10:44:56 +01:00
|
|
|
m_dirty = false;
|
|
|
|
}
|
|
|
|
|
2008-12-08 14:48:51 +01:00
|
|
|
QStringList CppModelManager::internalProjectFiles() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
QStringList files;
|
2013-07-11 11:13:07 +02:00
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projectToProjectsInfo);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2013-07-11 11:13:07 +02:00
|
|
|
const ProjectInfo pinfo = it.value();
|
2012-11-23 16:29:00 +01:00
|
|
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
|
2013-03-04 01:30:46 +04:00
|
|
|
foreach (const ProjectFile &file, part->files)
|
|
|
|
files += file.path;
|
2012-11-23 16:29:00 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-08 14:48:51 +01:00
|
|
|
files.removeDuplicates();
|
2008-12-02 12:01:29 +01:00
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2008-12-08 14:48:51 +01:00
|
|
|
QStringList CppModelManager::internalIncludePaths() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
QStringList includePaths;
|
2013-07-11 11:13:07 +02:00
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projectToProjectsInfo);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2013-07-11 11:13:07 +02:00
|
|
|
const ProjectInfo pinfo = it.value();
|
2012-02-16 15:09:56 +01:00
|
|
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
|
2012-12-19 16:24:06 +01:00
|
|
|
foreach (const QString &path, part->includePaths)
|
|
|
|
includePaths.append(CppPreprocessor::cleanPath(path));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-08 14:48:51 +01:00
|
|
|
includePaths.removeDuplicates();
|
2008-12-02 12:01:29 +01:00
|
|
|
return includePaths;
|
|
|
|
}
|
|
|
|
|
2008-12-08 14:48:51 +01:00
|
|
|
QStringList CppModelManager::internalFrameworkPaths() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
QStringList frameworkPaths;
|
2013-07-11 11:13:07 +02:00
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projectToProjectsInfo);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2013-07-11 11:13:07 +02:00
|
|
|
const ProjectInfo pinfo = it.value();
|
2012-02-16 15:09:56 +01:00
|
|
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
|
2012-12-19 16:24:06 +01:00
|
|
|
foreach (const QString &path, part->frameworkPaths)
|
|
|
|
frameworkPaths.append(CppPreprocessor::cleanPath(path));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-08 14:48:51 +01:00
|
|
|
frameworkPaths.removeDuplicates();
|
2008-12-02 12:01:29 +01:00
|
|
|
return frameworkPaths;
|
|
|
|
}
|
|
|
|
|
2008-12-08 14:48:51 +01:00
|
|
|
QByteArray CppModelManager::internalDefinedMacros() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
QByteArray macros;
|
2012-03-27 15:29:12 +02:00
|
|
|
QSet<QByteArray> alreadyIn;
|
2013-07-11 11:13:07 +02:00
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projectToProjectsInfo);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2013-07-11 11:13:07 +02:00
|
|
|
const ProjectInfo pinfo = it.value();
|
2012-03-27 15:29:12 +02:00
|
|
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
|
|
|
|
const QList<QByteArray> defs = part->defines.split('\n');
|
|
|
|
foreach (const QByteArray &def, defs) {
|
|
|
|
if (!alreadyIn.contains(def)) {
|
|
|
|
macros += def;
|
|
|
|
macros.append('\n');
|
|
|
|
alreadyIn.insert(def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
return macros;
|
|
|
|
}
|
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
/// This function will aquire the mutex!
|
2012-11-06 10:48:16 +01:00
|
|
|
void CppModelManager::dumpModelManagerConfiguration()
|
|
|
|
{
|
|
|
|
// Tons of debug output...
|
2013-07-11 11:13:07 +02:00
|
|
|
qDebug() << "========= CppModelManager::dumpModelManagerConfiguration ======";
|
|
|
|
foreach (const ProjectInfo &pinfo, m_projectToProjectsInfo) {
|
2013-07-23 12:30:17 +02:00
|
|
|
qDebug() << " for project:"<< pinfo.project().data()->projectFilePath();
|
2012-11-06 10:48:16 +01:00
|
|
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
|
|
|
|
qDebug() << "=== part ===";
|
2013-03-04 01:30:46 +04:00
|
|
|
const char* cVersion;
|
|
|
|
switch (part->cVersion) {
|
|
|
|
case ProjectPart::C89: cVersion = "C89"; break;
|
|
|
|
case ProjectPart::C99: cVersion = "C99"; break;
|
|
|
|
case ProjectPart::C11: cVersion = "C11"; break;
|
|
|
|
default: cVersion = "INVALID";
|
|
|
|
}
|
2013-03-27 10:08:56 +04:00
|
|
|
const char* cxxVersion;
|
2013-03-04 01:30:46 +04:00
|
|
|
switch (part->cxxVersion) {
|
2013-03-27 10:08:56 +04:00
|
|
|
case ProjectPart::CXX98: cxxVersion = "CXX98"; break;
|
|
|
|
case ProjectPart::CXX11: cxxVersion = "CXX11"; break;
|
2013-03-04 01:30:46 +04:00
|
|
|
default: cxxVersion = "INVALID";
|
|
|
|
}
|
2013-03-27 10:08:56 +04:00
|
|
|
QStringList cxxExtensions;
|
|
|
|
if (part->cxxExtensions & ProjectPart::GnuExtensions)
|
|
|
|
cxxExtensions << QLatin1String("GnuExtensions");
|
|
|
|
if (part->cxxExtensions & ProjectPart::MicrosoftExtensions)
|
|
|
|
cxxExtensions << QLatin1String("MicrosoftExtensions");
|
|
|
|
if (part->cxxExtensions & ProjectPart::BorlandExtensions)
|
|
|
|
cxxExtensions << QLatin1String("BorlandExtensions");
|
2013-08-19 18:20:49 +02:00
|
|
|
if (part->cxxExtensions & ProjectPart::OpenMPExtensions)
|
2013-03-27 10:08:56 +04:00
|
|
|
cxxExtensions << QLatin1String("OpenMP");
|
2012-11-23 16:29:00 +01:00
|
|
|
|
2013-03-04 01:30:46 +04:00
|
|
|
qDebug() << "cVersion:" << cVersion;
|
|
|
|
qDebug() << "cxxVersion:" << cxxVersion;
|
|
|
|
qDebug() << "cxxExtensions:" << cxxExtensions;
|
2012-11-06 10:48:16 +01:00
|
|
|
qDebug() << "Qt version:" << part->qtVersion;
|
|
|
|
qDebug() << "precompiled header:" << part->precompiledHeaders;
|
|
|
|
qDebug() << "defines:" << part->defines;
|
|
|
|
qDebug() << "includes:" << part->includePaths;
|
|
|
|
qDebug() << "frameworkPaths:" << part->frameworkPaths;
|
2013-03-04 01:30:46 +04:00
|
|
|
qDebug() << "files:" << part->files;
|
2012-11-06 10:48:16 +01:00
|
|
|
qDebug() << "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureUpdated();
|
|
|
|
qDebug() << "=== Merged include paths ===";
|
|
|
|
foreach (const QString &inc, m_includePaths)
|
|
|
|
qDebug() << inc;
|
|
|
|
qDebug() << "=== Merged framework paths ===";
|
|
|
|
foreach (const QString &inc, m_frameworkPaths)
|
|
|
|
qDebug() << inc;
|
|
|
|
qDebug() << "=== Merged defined macros ===";
|
|
|
|
qDebug() << m_definedMacros;
|
2013-07-11 11:13:07 +02:00
|
|
|
qDebug() << "========= End of dump ======";
|
2012-11-06 10:48:16 +01:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
void CppModelManager::addExtraEditorSupport(AbstractEditorSupport *editorSupport)
|
2009-05-12 13:45:24 +02:00
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
m_extraEditorSupports.insert(editorSupport);
|
2009-05-12 13:45:24 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupport)
|
2009-05-12 13:45:24 +02:00
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
m_extraEditorSupports.remove(editorSupport);
|
2009-05-12 13:45:24 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 10:58:20 +02:00
|
|
|
/// \brief Returns the \c CppEditorSupport for the given text editor. It will
|
|
|
|
/// create one when none exists yet.
|
2013-07-11 11:13:07 +02:00
|
|
|
CppEditorSupport *CppModelManager::cppEditorSupport(TextEditor::BaseTextEditor *textEditor)
|
2013-04-17 10:58:20 +02:00
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
Q_ASSERT(textEditor);
|
2013-04-17 10:58:20 +02:00
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
QMutexLocker locker(&m_cppEditorSupportsMutex);
|
2013-04-17 10:58:20 +02:00
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
CppEditorSupport *editorSupport = m_cppEditorSupports.value(textEditor, 0);
|
2013-04-17 10:58:20 +02:00
|
|
|
if (!editorSupport) {
|
2013-07-11 11:13:07 +02:00
|
|
|
editorSupport = new CppEditorSupport(this, textEditor);
|
|
|
|
m_cppEditorSupports.insert(textEditor, editorSupport);
|
2013-04-17 10:58:20 +02:00
|
|
|
}
|
|
|
|
return editorSupport;
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
/// \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;
|
2013-07-18 10:57:19 +02:00
|
|
|
delayedGC();
|
2013-07-11 11:13:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-31 12:09:28 +02:00
|
|
|
QList<int> CppModelManager::references(CPlusPlus::Symbol *symbol, const LookupContext &context)
|
2009-09-30 13:25:40 +02:00
|
|
|
{
|
2010-05-31 12:09:28 +02:00
|
|
|
return m_findReferences->references(symbol, context);
|
2009-09-30 13:25:40 +02:00
|
|
|
}
|
|
|
|
|
2010-05-31 12:09:28 +02:00
|
|
|
void CppModelManager::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context)
|
2009-08-07 13:02:36 +02:00
|
|
|
{
|
2009-09-24 16:51:40 +02:00
|
|
|
if (symbol->identifier())
|
2010-05-31 12:09:28 +02:00
|
|
|
m_findReferences->findUsages(symbol, context);
|
2009-10-05 15:17:25 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
void CppModelManager::renameUsages(CPlusPlus::Symbol *symbol,
|
|
|
|
const CPlusPlus::LookupContext &context,
|
2010-07-20 11:02:37 +02:00
|
|
|
const QString &replacement)
|
2009-10-05 15:17:25 +02:00
|
|
|
{
|
|
|
|
if (symbol->identifier())
|
2010-07-20 11:02:37 +02:00
|
|
|
m_findReferences->renameUsages(symbol, context, replacement);
|
2009-08-07 13:02:36 +02:00
|
|
|
}
|
|
|
|
|
2009-12-21 14:54:10 +01:00
|
|
|
void CppModelManager::findMacroUsages(const CPlusPlus::Macro ¯o)
|
|
|
|
{
|
|
|
|
m_findReferences->findMacroUses(macro);
|
|
|
|
}
|
|
|
|
|
2012-03-17 13:26:27 +01:00
|
|
|
void CppModelManager::renameMacroUsages(const CPlusPlus::Macro ¯o, const QString &replacement)
|
|
|
|
{
|
|
|
|
m_findReferences->renameMacroUses(macro, replacement);
|
|
|
|
}
|
|
|
|
|
2013-02-19 12:48:42 +01:00
|
|
|
void CppModelManager::replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot)
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker snapshotLocker(&m_snapshotMutex);
|
2013-02-19 12:48:42 +01:00
|
|
|
m_snapshot = newSnapshot;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:16:46 +01:00
|
|
|
CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
QList<CppEditorSupport *> cppEditorSupports;
|
2013-04-17 10:58:20 +02:00
|
|
|
|
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
QMutexLocker locker(&m_cppEditorSupportsMutex);
|
|
|
|
cppEditorSupports = m_cppEditorSupports.values();
|
2013-04-17 10:58:20 +02:00
|
|
|
}
|
|
|
|
|
2009-12-15 15:16:46 +01:00
|
|
|
WorkingCopy workingCopy;
|
2013-07-11 11:13:07 +02:00
|
|
|
foreach (const CppEditorSupport *editorSupport, cppEditorSupports) {
|
2013-04-17 10:58:20 +02:00
|
|
|
workingCopy.insert(editorSupport->fileName(), editorSupport->contents(),
|
|
|
|
editorSupport->editorRevision());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
QSetIterator<AbstractEditorSupport *> it(m_extraEditorSupports);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
AbstractEditorSupport *es = it.next();
|
2013-08-19 15:47:51 +02:00
|
|
|
workingCopy.insert(es->fileName(), es->contents());
|
2009-05-12 13:45:24 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
// Add the project configuration file
|
2013-08-19 16:05:29 +02:00
|
|
|
QByteArray conf = codeModelConfiguration();
|
2008-12-02 12:01:29 +01:00
|
|
|
conf += definedMacros();
|
2013-08-19 15:47:51 +02:00
|
|
|
workingCopy.insert(configurationFileName(), conf);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
return workingCopy;
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:16:46 +01:00
|
|
|
CppModelManager::WorkingCopy CppModelManager::workingCopy() const
|
2009-10-12 10:38:00 +02:00
|
|
|
{
|
|
|
|
return const_cast<CppModelManager *>(this)->buildWorkingCopyList();
|
|
|
|
}
|
|
|
|
|
2013-08-19 16:05:29 +02:00
|
|
|
QByteArray CppModelManager::codeModelConfiguration() const
|
|
|
|
{
|
|
|
|
return QByteArray::fromRawData(pp_configuration, qstrlen(pp_configuration));
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:42:27 +02:00
|
|
|
QFuture<void> CppModelManager::updateSourceFiles(const QStringList &sourceFiles,
|
|
|
|
ProgressNotificationMode mode)
|
2012-10-16 16:02:40 +02:00
|
|
|
{
|
|
|
|
if (sourceFiles.isEmpty() || !m_indexerEnabled)
|
|
|
|
return QFuture<void>();
|
|
|
|
|
2012-11-23 11:47:39 +01:00
|
|
|
if (m_indexingSupporter)
|
2013-06-21 08:42:27 +02:00
|
|
|
m_indexingSupporter->refreshSourceFiles(sourceFiles, mode);
|
|
|
|
return m_internalIndexingSupport->refreshSourceFiles(sourceFiles, mode);
|
2012-10-16 16:02:40 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-08 10:44:56 +01:00
|
|
|
QList<CppModelManager::ProjectInfo> CppModelManager::projectInfos() const
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2013-07-11 11:13:07 +02:00
|
|
|
return m_projectToProjectsInfo.values();
|
2008-12-08 10:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CppModelManager::ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2013-07-11 11:13:07 +02:00
|
|
|
return m_projectToProjectsInfo.value(project, ProjectInfo(project));
|
2008-12-08 10:44:56 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
/// \brief Remove all files and their includes (recursively) of given ProjectInfo from the snapshot.
|
|
|
|
void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo)
|
|
|
|
{
|
|
|
|
if (!projectInfo.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QMutexLocker snapshotLocker(&m_snapshotMutex);
|
|
|
|
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
|
|
|
|
foreach (const ProjectFile &cxxFile, projectPart->files) {
|
|
|
|
foreach (const QString &fileName, m_snapshot.allIncludesForDocument(cxxFile.path))
|
|
|
|
m_snapshot.remove(fileName);
|
|
|
|
m_snapshot.remove(cxxFile.path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Remove all given files from the snapshot.
|
|
|
|
void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove)
|
|
|
|
{
|
|
|
|
QMutexLocker snapshotLocker(&m_snapshotMutex);
|
|
|
|
QSetIterator<QString> i(filesToRemove);
|
|
|
|
while (i.hasNext())
|
|
|
|
m_snapshot.remove(i.next());
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProjectInfoComparer
|
2008-12-08 10:44:56 +01:00
|
|
|
{
|
2013-07-10 14:46:08 +02:00
|
|
|
public:
|
|
|
|
ProjectInfoComparer(const CppModelManager::ProjectInfo &oldProjectInfo,
|
|
|
|
const CppModelManager::ProjectInfo &newProjectInfo)
|
|
|
|
: m_old(oldProjectInfo)
|
|
|
|
, m_oldSourceFiles(oldProjectInfo.sourceFiles().toSet())
|
|
|
|
, m_new(newProjectInfo)
|
|
|
|
, m_newSourceFiles(newProjectInfo.sourceFiles().toSet())
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool definesChanged() const
|
|
|
|
{
|
|
|
|
return m_new.defines() != m_old.defines();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool configurationChanged() const
|
|
|
|
{
|
|
|
|
return definesChanged()
|
|
|
|
|| m_new.includePaths() != m_old.includePaths()
|
|
|
|
|| m_new.frameworkPaths() != m_old.frameworkPaths();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nothingChanged() const
|
|
|
|
{
|
|
|
|
return !configurationChanged() && m_new.sourceFiles() == m_old.sourceFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<QString> addedFiles() const
|
|
|
|
{
|
|
|
|
QSet<QString> addedFilesSet = m_newSourceFiles;
|
|
|
|
addedFilesSet.subtract(m_oldSourceFiles);
|
|
|
|
return addedFilesSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<QString> removedFiles() const
|
|
|
|
{
|
|
|
|
QSet<QString> removedFilesSet = m_oldSourceFiles;
|
|
|
|
removedFilesSet.subtract(m_newSourceFiles);
|
|
|
|
return removedFilesSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a list of common files that have a changed timestamp.
|
|
|
|
QSet<QString> timeStampModifiedFiles(const Snapshot &snapshot) const
|
|
|
|
{
|
|
|
|
QSet<QString> commonSourceFiles = m_newSourceFiles;
|
|
|
|
commonSourceFiles.intersect(m_oldSourceFiles);
|
|
|
|
|
|
|
|
QList<Document::Ptr> documentsToCheck;
|
|
|
|
QSetIterator<QString> i(commonSourceFiles);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
const QString file = i.next();
|
|
|
|
if (Document::Ptr document = snapshot.document(file))
|
|
|
|
documentsToCheck << document;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CppModelManager::timeStampModifiedFiles(documentsToCheck).toSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const CppModelManager::ProjectInfo &m_old;
|
|
|
|
const QSet<QString> m_oldSourceFiles;
|
|
|
|
|
|
|
|
const CppModelManager::ProjectInfo &m_new;
|
|
|
|
const QSet<QString> m_newSourceFiles;
|
|
|
|
};
|
|
|
|
|
2013-10-04 12:25:26 +02:00
|
|
|
/// Make sure that m_projectMutex is locked when calling this.
|
|
|
|
void CppModelManager::recalculateFileToProjectParts()
|
|
|
|
{
|
|
|
|
m_fileToProjectParts.clear();
|
|
|
|
foreach (const ProjectInfo &projectInfo, m_projectToProjectsInfo) {
|
|
|
|
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
|
|
|
|
foreach (const ProjectFile &cxxFile, projectPart->files) {
|
|
|
|
m_fileToProjectParts[cxxFile.path].append(projectPart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectInfo)
|
|
|
|
{
|
|
|
|
if (!newProjectInfo.isValid())
|
2013-07-11 11:13:07 +02:00
|
|
|
return QFuture<void>();
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
QStringList filesToReindex;
|
|
|
|
bool filesRemoved = false;
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
{ // Only hold the mutex for a limited scope, so the dumping afterwards does not deadlock.
|
2013-07-10 14:46:08 +02:00
|
|
|
QMutexLocker projectLocker(&m_projectMutex);
|
|
|
|
|
|
|
|
ProjectExplorer::Project *project = newProjectInfo.project().data();
|
|
|
|
const QStringList newSourceFiles = newProjectInfo.sourceFiles();
|
2008-12-08 10:44:56 +01:00
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
// Check if we can avoid a full reindexing
|
2013-07-11 11:13:07 +02:00
|
|
|
ProjectInfo oldProjectInfo = m_projectToProjectsInfo.value(project);
|
2013-06-28 11:26:02 +02:00
|
|
|
if (oldProjectInfo.isValid()) {
|
2013-07-10 14:46:08 +02:00
|
|
|
ProjectInfoComparer comparer(oldProjectInfo, newProjectInfo);
|
|
|
|
if (comparer.nothingChanged())
|
2013-07-16 12:08:39 +02:00
|
|
|
return QFuture<void>();
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
// If the project configuration changed, do a full reindexing
|
|
|
|
if (comparer.configurationChanged()) {
|
|
|
|
removeProjectInfoFilesAndIncludesFromSnapshot(oldProjectInfo);
|
|
|
|
filesToReindex << newSourceFiles;
|
|
|
|
|
|
|
|
// The "configuration file" includes all defines and therefore should be updated
|
|
|
|
if (comparer.definesChanged()) {
|
|
|
|
QMutexLocker snapshotLocker(&m_snapshotMutex);
|
|
|
|
m_snapshot.remove(configurationFileName());
|
2013-06-28 11:26:02 +02:00
|
|
|
}
|
2013-07-10 14:46:08 +02:00
|
|
|
|
|
|
|
// Otherwise check for added and modified files
|
|
|
|
} else {
|
|
|
|
const QSet<QString> addedFiles = comparer.addedFiles();
|
|
|
|
filesToReindex << addedFiles.toList();
|
|
|
|
|
|
|
|
const QSet<QString> modifiedFiles = comparer.timeStampModifiedFiles(snapshot());
|
|
|
|
filesToReindex << modifiedFiles.toList();
|
2013-06-28 11:26:02 +02:00
|
|
|
}
|
2013-07-10 14:46:08 +02:00
|
|
|
|
|
|
|
// Announce and purge the removed files from the snapshot
|
|
|
|
const QSet<QString> removedFiles = comparer.removedFiles();
|
|
|
|
if (!removedFiles.isEmpty()) {
|
|
|
|
filesRemoved = true;
|
|
|
|
emit aboutToRemoveFiles(removedFiles.toList());
|
|
|
|
removeFilesFromSnapshot(removedFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
// A new project was opened/created, do a full indexing
|
|
|
|
} else {
|
|
|
|
filesToReindex << newSourceFiles;
|
2013-06-28 11:26:02 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
// Update Project/ProjectInfo and File/ProjectPart table
|
2012-11-06 10:48:16 +01:00
|
|
|
m_dirty = true;
|
2013-07-10 14:46:08 +02:00
|
|
|
m_projectToProjectsInfo.insert(project, newProjectInfo);
|
2013-10-04 12:25:26 +02:00
|
|
|
recalculateFileToProjectParts();
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
} // Mutex scope
|
|
|
|
|
|
|
|
// If requested, dump everything we got
|
2012-11-06 10:48:16 +01:00
|
|
|
if (!qgetenv("QTCREATOR_DUMP_PROJECT_INFO").isEmpty())
|
|
|
|
dumpModelManagerConfiguration();
|
2013-01-01 10:34:42 +01:00
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
// Remove files from snapshot that are not reachable any more
|
|
|
|
if (filesRemoved)
|
|
|
|
GC();
|
|
|
|
|
|
|
|
emit projectPartsUpdated(newProjectInfo.project().data());
|
2013-07-16 12:08:39 +02:00
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
// Trigger reindexing
|
|
|
|
return updateSourceFiles(filesToReindex, ForcedProgressNotification);
|
2012-02-16 15:09:56 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 01:30:46 +04:00
|
|
|
QList<ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
|
2012-02-16 15:09:56 +01:00
|
|
|
{
|
2013-08-19 16:05:29 +02:00
|
|
|
return m_fileToProjectParts.value(fileName);
|
|
|
|
}
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2013-08-19 16:05:29 +02:00
|
|
|
QList<ProjectPart::Ptr> CppModelManager::projectPartFromDependencies(const QString &fileName) const
|
|
|
|
{
|
|
|
|
QSet<ProjectPart::Ptr> parts;
|
2012-02-16 15:09:56 +01:00
|
|
|
DependencyTable table;
|
|
|
|
table.build(snapshot());
|
2013-07-11 11:13:07 +02:00
|
|
|
const QStringList deps = table.filesDependingOn(fileName);
|
2013-08-19 16:05:29 +02:00
|
|
|
foreach (const QString &dep, deps)
|
|
|
|
parts.unite(QSet<ProjectPart::Ptr>::fromList(m_fileToProjectParts.value(dep)));
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2013-08-19 16:05:29 +02:00
|
|
|
return parts.values();
|
2008-12-08 10:44:56 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-08-19 18:20:49 +02:00
|
|
|
ProjectPart::Ptr CppModelManager::fallbackProjectPart() const
|
|
|
|
{
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
|
|
|
part->defines = m_definedMacros;
|
|
|
|
part->includePaths = m_includePaths;
|
|
|
|
part->frameworkPaths = m_frameworkPaths;
|
|
|
|
part->cVersion = ProjectPart::C11;
|
|
|
|
part->cxxVersion = ProjectPart::CXX11;
|
|
|
|
part->cxxExtensions = ProjectPart::AllExtensions;
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool CppModelManager::isCppEditor(Core::IEditor *editor) const
|
|
|
|
{
|
2010-06-25 17:37:59 +02:00
|
|
|
return editor->context().contains(ProjectExplorer::Constants::LANG_CXX);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CppModelManager::emitDocumentUpdated(Document::Ptr doc)
|
|
|
|
{
|
2013-02-19 12:48:42 +01:00
|
|
|
if (replaceDocument(doc))
|
2013-04-17 10:58:20 +02:00
|
|
|
emit documentUpdated(doc);
|
2009-02-10 22:56:04 +01:00
|
|
|
}
|
|
|
|
|
2008-12-04 17:07:43 +01:00
|
|
|
void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2008-12-04 17:07:43 +01:00
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
2013-07-18 10:57:19 +02:00
|
|
|
void CppModelManager::delayedGC()
|
|
|
|
{
|
|
|
|
m_delayedGcTimer->start(500);
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
|
|
|
|
{
|
2008-12-08 10:44:56 +01:00
|
|
|
do {
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2008-12-08 10:44:56 +01:00
|
|
|
m_dirty = true;
|
2013-07-11 11:13:07 +02:00
|
|
|
m_projectToProjectsInfo.remove(project);
|
2013-10-04 12:25:26 +02:00
|
|
|
recalculateFileToProjectParts();
|
2008-12-08 10:44:56 +01:00
|
|
|
} while (0);
|
|
|
|
|
2013-07-18 10:57:19 +02:00
|
|
|
delayedGC();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppModelManager::onAboutToLoadSession()
|
|
|
|
{
|
|
|
|
if (m_delayedGcTimer->isActive())
|
|
|
|
m_delayedGcTimer->stop();
|
2008-12-02 12:01:29 +01:00
|
|
|
GC();
|
|
|
|
}
|
|
|
|
|
2009-08-13 17:10:53 +02:00
|
|
|
void CppModelManager::onAboutToUnloadSession()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-09-03 15:18:37 +02:00
|
|
|
Core::ProgressManager::cancelTasks(CppTools::Constants::TASK_INDEX);
|
2008-12-08 10:44:56 +01:00
|
|
|
do {
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2013-07-11 11:13:07 +02:00
|
|
|
m_projectToProjectsInfo.clear();
|
2013-10-04 12:25:26 +02:00
|
|
|
recalculateFileToProjectParts();
|
2008-12-08 10:44:56 +01:00
|
|
|
m_dirty = true;
|
|
|
|
} while (0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2013-04-19 16:56:12 +02:00
|
|
|
void CppModelManager::onCoreAboutToClose()
|
|
|
|
{
|
|
|
|
m_enableGC = false;
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CppModelManager::GC()
|
|
|
|
{
|
2013-04-19 16:56:12 +02:00
|
|
|
if (!m_enableGC)
|
|
|
|
return;
|
|
|
|
|
2013-07-17 13:50:38 +02:00
|
|
|
// Collect files of CppEditorSupport and AbstractEditorSupport.
|
|
|
|
QStringList filesInEditorSupports;
|
|
|
|
QList<CppEditorSupport *> cppEditorSupports;
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_cppEditorSupportsMutex);
|
|
|
|
cppEditorSupports = m_cppEditorSupports.values();
|
|
|
|
}
|
|
|
|
foreach (const CppEditorSupport *cppEditorSupport, cppEditorSupports)
|
|
|
|
filesInEditorSupports << cppEditorSupport->fileName();
|
|
|
|
|
|
|
|
QSetIterator<AbstractEditorSupport *> jt(m_extraEditorSupports);
|
|
|
|
while (jt.hasNext()) {
|
|
|
|
AbstractEditorSupport *abstractEditorSupport = jt.next();
|
|
|
|
filesInEditorSupports << abstractEditorSupport->fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
Snapshot currentSnapshot = snapshot();
|
2013-07-11 11:13:07 +02:00
|
|
|
QSet<QString> reachableFiles;
|
2013-07-17 13:50:38 +02:00
|
|
|
// The configuration file is part of the project files, which is just fine.
|
|
|
|
// If single files are open, without any project, then there is no need to
|
|
|
|
// keep the configuration file around.
|
|
|
|
QStringList todo = filesInEditorSupports + projectFiles();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
// Collect all files that are reachable from the project files
|
2013-07-24 11:59:39 +02:00
|
|
|
while (!todo.isEmpty()) {
|
2013-07-11 11:13:07 +02:00
|
|
|
const QString file = todo.last();
|
2008-12-02 12:01:29 +01:00
|
|
|
todo.removeLast();
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
if (reachableFiles.contains(file))
|
2008-12-02 12:01:29 +01:00
|
|
|
continue;
|
2013-07-11 11:13:07 +02:00
|
|
|
reachableFiles.insert(file);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
if (Document::Ptr doc = currentSnapshot.document(file))
|
2008-12-02 12:01:29 +01:00
|
|
|
todo += doc->includedFiles();
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
// Find out the files in the current snapshot that are not reachable from the project files
|
|
|
|
QStringList notReachableFiles;
|
2009-12-07 10:54:27 +01:00
|
|
|
Snapshot newSnapshot;
|
|
|
|
for (Snapshot::const_iterator it = currentSnapshot.begin(); it != currentSnapshot.end(); ++it) {
|
|
|
|
const QString fileName = it.key();
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
if (reachableFiles.contains(fileName))
|
2009-12-07 10:54:27 +01:00
|
|
|
newSnapshot.insert(it.value());
|
|
|
|
else
|
2013-07-11 11:13:07 +02:00
|
|
|
notReachableFiles.append(fileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
// Announce removing files and replace the snapshot
|
|
|
|
emit aboutToRemoveFiles(notReachableFiles);
|
2013-02-19 12:48:42 +01:00
|
|
|
replaceSnapshot(newSnapshot);
|
2013-07-18 10:57:19 +02:00
|
|
|
emit gcFinished();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-12-03 13:49:35 +01:00
|
|
|
|
2011-07-05 10:46:46 +02:00
|
|
|
void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files)
|
|
|
|
{
|
|
|
|
emit sourceFilesRefreshed(files);
|
|
|
|
}
|
|
|
|
|
2013-09-04 18:15:08 +02:00
|
|
|
void CppModelManager::addModelManagerSupport(ModelManagerSupport *modelManagerSupport)
|
2013-08-30 12:55:06 +02:00
|
|
|
{
|
2013-09-06 13:14:15 +02:00
|
|
|
Q_ASSERT(modelManagerSupport);
|
|
|
|
m_idTocodeModelSupporter[modelManagerSupport->id()] = modelManagerSupport;
|
|
|
|
QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings();
|
|
|
|
cms->setModelManagerSupports(m_idTocodeModelSupporter.values());
|
2013-09-04 18:15:08 +02:00
|
|
|
}
|
2013-08-30 12:55:06 +02:00
|
|
|
|
2013-09-04 18:15:08 +02:00
|
|
|
ModelManagerSupport *CppModelManager::modelManagerSupportForMimeType(const QString &mimeType) const
|
|
|
|
{
|
2013-09-06 13:14:15 +02:00
|
|
|
QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings();
|
|
|
|
const QString &id = cms->modelManagerSupportId(mimeType);
|
|
|
|
return m_idTocodeModelSupporter.value(id, m_modelManagerSupportFallback.data());
|
2013-08-30 12:55:06 +02:00
|
|
|
}
|
|
|
|
|
2013-09-04 18:15:08 +02:00
|
|
|
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
|
2012-02-20 12:39:08 +01:00
|
|
|
{
|
2013-09-04 18:15:08 +02:00
|
|
|
ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType());
|
|
|
|
|
|
|
|
return cms->completionAssistProvider();
|
2012-02-20 12:39:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 15:09:08 +01:00
|
|
|
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
|
|
|
|
{
|
2013-09-04 18:15:08 +02:00
|
|
|
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor);
|
|
|
|
if (!textEditor)
|
2012-02-07 15:09:08 +01:00
|
|
|
return 0;
|
2011-08-24 10:55:48 +02:00
|
|
|
|
2013-09-04 18:15:08 +02:00
|
|
|
ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType());
|
|
|
|
|
|
|
|
return cms->highlightingSupport(textEditor);
|
2012-02-20 12:39:08 +01:00
|
|
|
}
|
|
|
|
|
2012-11-23 11:47:39 +01:00
|
|
|
void CppModelManager::setIndexingSupport(CppIndexingSupport *indexingSupport)
|
2012-10-16 16:02:40 +02:00
|
|
|
{
|
|
|
|
if (indexingSupport)
|
2012-11-23 11:47:39 +01:00
|
|
|
m_indexingSupporter = indexingSupport;
|
|
|
|
}
|
|
|
|
|
|
|
|
CppIndexingSupport *CppModelManager::indexingSupport()
|
|
|
|
{
|
|
|
|
return m_indexingSupporter ? m_indexingSupporter : m_internalIndexingSupport;
|
2012-10-16 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
void CppModelManager::setExtraDiagnostics(const QString &fileName,
|
|
|
|
const QString &kind,
|
2011-08-24 10:55:48 +02:00
|
|
|
const QList<Document::DiagnosticMessage> &diagnostics)
|
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
QList<CppEditorSupport *> cppEditorSupports;
|
2013-04-17 10:58:20 +02:00
|
|
|
|
2011-08-24 10:55:48 +02:00
|
|
|
{
|
2013-07-11 11:13:07 +02:00
|
|
|
QMutexLocker locker(&m_cppEditorSupportsMutex);
|
|
|
|
cppEditorSupports = m_cppEditorSupports.values();
|
2011-08-24 10:55:48 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:13:07 +02:00
|
|
|
foreach (CppEditorSupport *editorSupport, cppEditorSupports) {
|
|
|
|
if (editorSupport->fileName() == fileName) {
|
|
|
|
editorSupport->setExtraDiagnostics(kind, diagnostics);
|
2013-04-17 10:58:20 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-08-24 10:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-09 11:43:20 +02:00
|
|
|
|
|
|
|
void CppModelManager::setIfdefedOutBlocks(const QString &fileName,
|
|
|
|
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks)
|
|
|
|
{
|
|
|
|
QList<CppEditorSupport *> cppEditorSupports;
|
|
|
|
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_cppEditorSupportsMutex);
|
|
|
|
cppEditorSupports = m_cppEditorSupports.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (CppEditorSupport *editorSupport, cppEditorSupports) {
|
|
|
|
if (editorSupport->fileName() == fileName) {
|
|
|
|
editorSupport->setIfdefedOutBlocks(ifdeffedOutBlocks);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|