2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 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"
|
2014-03-17 08:44:46 -03:00
|
|
|
#include "cppcodemodelinspectordumper.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
#include "cppcodemodelsettings.h"
|
2013-07-11 11:13:07 +02:00
|
|
|
#include "cppfindreferences.h"
|
2012-10-16 16:02:40 +02:00
|
|
|
#include "cppindexingsupport.h"
|
2013-09-04 18:15:08 +02:00
|
|
|
#include "cppmodelmanagersupportinternal.h"
|
2014-05-16 15:51:04 -04:00
|
|
|
#include "cppsourceprocessor.h"
|
2013-07-11 11:13:07 +02:00
|
|
|
#include "cpptoolsconstants.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
#include "cpptoolsplugin.h"
|
2014-08-19 15:59:29 +02:00
|
|
|
#include "editordocumenthandle.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
|
|
|
|
2014-03-06 14:42:01 -03:00
|
|
|
static const bool DumpProjectInfo = qgetenv("QTC_DUMP_PROJECT_INFO") == "1";
|
|
|
|
|
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"
|
2014-06-11 08:05:08 +03:00
|
|
|
"#define __thiscall\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
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
QSet<QString> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck)
|
2009-11-05 12:34:02 +01:00
|
|
|
{
|
2014-09-04 14:59:50 +02:00
|
|
|
QSet<QString> sourceFiles;
|
2009-11-05 12:34:02 +01:00
|
|
|
|
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)
|
2014-09-04 14:59:50 +02:00
|
|
|
sourceFiles.insert(doc->fileName());
|
2009-11-05 12:34:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
return sourceFiles;
|
|
|
|
}
|
|
|
|
|
2014-06-06 14:41:19 +02:00
|
|
|
/*!
|
|
|
|
* \brief createSourceProcessor Create a new source processor, which will signal the
|
|
|
|
* model manager when a document has been processed.
|
|
|
|
*
|
|
|
|
* Indexed file is truncated version of fully parsed document: copy of source
|
|
|
|
* code and full AST will be dropped when indexing is done.
|
|
|
|
*
|
|
|
|
* \return a new source processor object, which the caller needs to delete when finished.
|
|
|
|
*/
|
|
|
|
CppSourceProcessor *CppModelManager::createSourceProcessor()
|
|
|
|
{
|
|
|
|
CppModelManager *that = instance();
|
2014-06-25 09:29:33 +03:00
|
|
|
return new CppSourceProcessor(that->snapshot(), [that](const Document::Ptr &doc) {
|
2014-06-06 14:41:19 +02:00
|
|
|
that->emitDocumentUpdated(doc);
|
|
|
|
doc->releaseSourceAndAST();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
void CppModelManager::updateModifiedSourceFiles()
|
|
|
|
{
|
|
|
|
const Snapshot snapshot = this->snapshot();
|
|
|
|
QList<Document::Ptr> documentsToCheck;
|
|
|
|
foreach (const Document::Ptr document, snapshot)
|
|
|
|
documentsToCheck << document;
|
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
updateSourceFiles(timeStampModifiedFiles(documentsToCheck));
|
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
|
|
|
{
|
2013-10-10 10:26:39 +02:00
|
|
|
connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
|
|
|
|
this, SIGNAL(globalSnapshotChanged()));
|
|
|
|
connect(this, SIGNAL(aboutToRemoveFiles(QStringList)),
|
|
|
|
this, SIGNAL(globalSnapshotChanged()));
|
2014-09-04 14:59:50 +02:00
|
|
|
connect(this, SIGNAL(sourceFilesRefreshed(QSet<QString>)),
|
2014-08-05 11:34:52 +02:00
|
|
|
this, SLOT(onSourceFilesRefreshed()));
|
2013-10-10 10:26:39 +02:00
|
|
|
|
2009-08-07 13:02:36 +02:00
|
|
|
m_findReferences = new CppFindReferences(this);
|
2014-03-06 14:42:01 -03:00
|
|
|
m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1";
|
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);
|
2014-08-27 11:50:53 +02:00
|
|
|
m_delayedGcTimer->setObjectName(QLatin1String("CppModelManager::m_delayedGcTimer"));
|
2013-07-18 10:57:19 +02:00
|
|
|
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();
|
2014-06-25 17:23:19 +02:00
|
|
|
m_headerPaths = internalHeaderPaths();
|
2008-12-08 14:48:51 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-25 17:23:19 +02:00
|
|
|
ProjectPart::HeaderPaths CppModelManager::internalHeaderPaths() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-06-25 17:23:19 +02:00
|
|
|
ProjectPart::HeaderPaths headerPaths;
|
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();
|
2014-06-25 17:23:19 +02:00
|
|
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
|
|
|
|
foreach (const ProjectPart::HeaderPath &path, part->headerPaths) {
|
|
|
|
const ProjectPart::HeaderPath hp(CppSourceProcessor::cleanPath(path.path),
|
|
|
|
path.type);
|
|
|
|
if (!headerPaths.contains(hp))
|
|
|
|
headerPaths += hp;
|
|
|
|
}
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2014-06-25 17:23:19 +02:00
|
|
|
return headerPaths;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:17:51 +01:00
|
|
|
static void addUnique(const QList<QByteArray> &defs, QByteArray *macros, QSet<QByteArray> *alreadyIn)
|
|
|
|
{
|
|
|
|
Q_ASSERT(macros);
|
|
|
|
Q_ASSERT(alreadyIn);
|
|
|
|
|
|
|
|
foreach (const QByteArray &def, defs) {
|
|
|
|
if (def.trimmed().isEmpty())
|
|
|
|
continue;
|
|
|
|
if (!alreadyIn->contains(def)) {
|
|
|
|
macros->append(def);
|
|
|
|
macros->append('\n');
|
|
|
|
alreadyIn->insert(def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()) {
|
2013-11-27 15:17:51 +01:00
|
|
|
addUnique(part->toolchainDefines.split('\n'), ¯os, &alreadyIn);
|
|
|
|
addUnique(part->projectDefines.split('\n'), ¯os, &alreadyIn);
|
2014-02-05 16:44:35 +01:00
|
|
|
if (!part->projectConfigFile.isEmpty())
|
2014-07-30 17:13:45 +02:00
|
|
|
macros += ProjectPart::readProjectConfigFile(part);
|
2012-03-27 15:29:12 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
return macros;
|
|
|
|
}
|
|
|
|
|
2014-03-17 08:44:46 -03:00
|
|
|
/// This function will acquire mutexes!
|
2014-03-17 09:45:07 -03:00
|
|
|
void CppModelManager::dumpModelManagerConfiguration(const QString &logFileId)
|
2012-11-06 10:48:16 +01:00
|
|
|
{
|
2014-03-17 08:44:46 -03:00
|
|
|
const Snapshot globalSnapshot = snapshot();
|
|
|
|
const QString globalSnapshotTitle
|
|
|
|
= QString::fromLatin1("Global/Indexing Snapshot (%1 Documents)").arg(globalSnapshot.size());
|
|
|
|
|
2014-03-17 09:45:07 -03:00
|
|
|
CppCodeModelInspector::Dumper dumper(globalSnapshot, logFileId);
|
2014-03-17 08:44:46 -03:00
|
|
|
dumper.dumpProjectInfos(projectInfos());
|
|
|
|
dumper.dumpSnapshot(globalSnapshot, globalSnapshotTitle, /*isGlobalSnapshot=*/ true);
|
|
|
|
dumper.dumpWorkingCopy(workingCopy());
|
2012-11-06 10:48:16 +01:00
|
|
|
ensureUpdated();
|
2014-06-25 17:23:19 +02:00
|
|
|
dumper.dumpMergedEntities(m_headerPaths, m_definedMacros);
|
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
|
|
|
}
|
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
EditorDocumentHandle *CppModelManager::editorDocument(const QString &filePath)
|
2013-04-17 10:58:20 +02:00
|
|
|
{
|
2014-08-19 15:59:29 +02:00
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return 0);
|
2013-04-17 10:58:20 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
QMutexLocker locker(&m_cppEditorsMutex);
|
|
|
|
return m_cppEditors.value(filePath, 0);
|
2013-04-17 10:58:20 +02:00
|
|
|
}
|
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
void CppModelManager::registerEditorDocument(EditorDocumentHandle *editorDocument)
|
2013-07-11 11:13:07 +02:00
|
|
|
{
|
2014-08-19 15:59:29 +02:00
|
|
|
QTC_ASSERT(editorDocument, return);
|
|
|
|
const QString filePath = editorDocument->filePath();
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return);
|
2013-07-11 11:13:07 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
QMutexLocker locker(&m_cppEditorsMutex);
|
|
|
|
QTC_ASSERT(m_cppEditors.value(filePath, 0) == 0, return);
|
|
|
|
m_cppEditors.insert(filePath, editorDocument);
|
|
|
|
}
|
2013-07-11 11:13:07 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
void CppModelManager::unregisterEditorDocument(const QString &filePath)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return);
|
2013-07-11 11:13:07 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
static short closedCppDocuments = 0;
|
|
|
|
int openCppDocuments = 0;
|
2013-07-11 11:13:07 +02:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_cppEditorsMutex);
|
|
|
|
QTC_ASSERT(m_cppEditors.value(filePath, 0), return);
|
|
|
|
QTC_CHECK(m_cppEditors.remove(filePath) == 1);
|
|
|
|
openCppDocuments = m_cppEditors.size();
|
2013-07-11 11:13:07 +02:00
|
|
|
}
|
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
++closedCppDocuments;
|
|
|
|
if (openCppDocuments == 0 || closedCppDocuments == 5) {
|
|
|
|
closedCppDocuments = 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;
|
|
|
|
}
|
|
|
|
|
2014-07-30 16:29:02 +02:00
|
|
|
WorkingCopy CppModelManager::buildWorkingCopyList()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-12-15 15:16:46 +01:00
|
|
|
WorkingCopy workingCopy;
|
2014-03-20 17:03:27 -03:00
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
foreach (const EditorDocumentHandle *cppEditor, cppEditors())
|
|
|
|
workingCopy.insert(cppEditor->filePath(), cppEditor->contents(), cppEditor->revision());
|
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-11-25 15:22:58 +01:00
|
|
|
workingCopy.insert(es->fileName(), es->contents(), es->revision());
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-30 16:29:02 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
QFuture<void> CppModelManager::updateSourceFiles(const QSet<QString> &sourceFiles,
|
2013-06-21 08:42:27 +02:00
|
|
|
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
|
|
|
|
2014-07-30 17:13:45 +02:00
|
|
|
QList<ProjectInfo> CppModelManager::projectInfos() const
|
2008-12-08 10:44:56 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2014-07-30 17:13:45 +02:00
|
|
|
ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const
|
2008-12-08 10:44:56 +01:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
QList<EditorDocumentHandle *> CppModelManager::cppEditors() const
|
2014-03-20 17:03:27 -03:00
|
|
|
{
|
2014-08-19 15:59:29 +02:00
|
|
|
QMutexLocker locker(&m_cppEditorsMutex);
|
|
|
|
return m_cppEditors.values();
|
2014-03-20 17:03:27 -03:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:46:08 +02:00
|
|
|
/// \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:
|
2014-07-30 17:13:45 +02:00
|
|
|
ProjectInfoComparer(const ProjectInfo &oldProjectInfo,
|
|
|
|
const ProjectInfo &newProjectInfo)
|
2013-07-10 14:46:08 +02:00
|
|
|
: m_old(oldProjectInfo)
|
2014-09-04 14:59:50 +02:00
|
|
|
, m_oldSourceFiles(oldProjectInfo.sourceFiles())
|
2013-07-10 14:46:08 +02:00
|
|
|
, m_new(newProjectInfo)
|
2014-09-04 14:59:50 +02:00
|
|
|
, m_newSourceFiles(newProjectInfo.sourceFiles())
|
2013-07-10 14:46:08 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool definesChanged() const
|
|
|
|
{
|
|
|
|
return m_new.defines() != m_old.defines();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool configurationChanged() const
|
|
|
|
{
|
|
|
|
return definesChanged()
|
2014-06-25 17:23:19 +02:00
|
|
|
|| m_new.headerPaths() != m_old.headerPaths();
|
2013-07-10 14:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
return CppModelManager::timeStampModifiedFiles(documentsToCheck);
|
2013-07-10 14:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-07-30 17:13:45 +02:00
|
|
|
const ProjectInfo &m_old;
|
2013-07-10 14:46:08 +02:00
|
|
|
const QSet<QString> m_oldSourceFiles;
|
|
|
|
|
2014-07-30 17:13:45 +02:00
|
|
|
const ProjectInfo &m_new;
|
2013-07-10 14:46:08 +02:00
|
|
|
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()
|
|
|
|
{
|
2013-12-02 15:23:13 +01:00
|
|
|
m_projectFileToProjectPart.clear();
|
2013-10-04 12:25:26 +02:00
|
|
|
m_fileToProjectParts.clear();
|
|
|
|
foreach (const ProjectInfo &projectInfo, m_projectToProjectsInfo) {
|
|
|
|
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
|
2013-12-02 15:23:13 +01:00
|
|
|
m_projectFileToProjectPart[projectPart->projectFile] = projectPart;
|
|
|
|
foreach (const ProjectFile &cxxFile, projectPart->files)
|
2013-10-04 12:25:26 +02:00
|
|
|
m_fileToProjectParts[cxxFile.path].append(projectPart);
|
2013-12-02 15:23:13 +01:00
|
|
|
|
2013-10-04 12:25:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
QSet<QString> filesToReindex;
|
2013-07-10 14:46:08 +02:00
|
|
|
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();
|
2014-09-04 14:59:50 +02:00
|
|
|
const QSet<QString> 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);
|
2014-09-04 14:59:50 +02:00
|
|
|
filesToReindex.unite(newSourceFiles);
|
2013-07-10 14:46:08 +02:00
|
|
|
|
|
|
|
// 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();
|
2014-09-04 14:59:50 +02:00
|
|
|
filesToReindex.unite(addedFiles);
|
2013-07-10 14:46:08 +02:00
|
|
|
|
|
|
|
const QSet<QString> modifiedFiles = comparer.timeStampModifiedFiles(snapshot());
|
2014-09-04 14:59:50 +02:00
|
|
|
filesToReindex.unite(modifiedFiles);
|
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 {
|
2014-09-04 14:59:50 +02:00
|
|
|
filesToReindex.unite(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
|
2014-03-06 14:42:01 -03:00
|
|
|
if (DumpProjectInfo)
|
2014-03-17 09:45:07 -03:00
|
|
|
dumpModelManagerConfiguration(QLatin1String("updateProjectInfo"));
|
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-12-02 15:23:13 +01:00
|
|
|
ProjectPart::Ptr CppModelManager::projectPartForProjectFile(const QString &projectFile) const
|
|
|
|
{
|
|
|
|
return m_projectFileToProjectPart.value(projectFile);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-03-10 15:22:46 -03:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
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);
|
|
|
|
|
2013-11-27 15:17:51 +01:00
|
|
|
part->projectDefines = m_definedMacros;
|
2014-06-25 17:23:19 +02:00
|
|
|
part->headerPaths = m_headerPaths;
|
2013-08-19 18:20:49 +02:00
|
|
|
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()
|
|
|
|
{
|
2013-12-17 13:54:52 +01:00
|
|
|
if (m_enableGC)
|
|
|
|
m_delayedGcTimer->start(500);
|
2013-07-18 10:57:19 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-08-05 11:34:52 +02:00
|
|
|
void CppModelManager::onSourceFilesRefreshed() const
|
|
|
|
{
|
|
|
|
if (BuiltinIndexingSupport::isFindErrorsIndexingActive()) {
|
|
|
|
QTimer::singleShot(1, QCoreApplication::instance(), SLOT(quit()));
|
|
|
|
qDebug("FindErrorsIndexing: Done, requesting Qt Creator to quit.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 10:57:19 +02:00
|
|
|
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;
|
2014-08-19 15:59:29 +02:00
|
|
|
foreach (const EditorDocumentHandle *cppEditor, cppEditors())
|
|
|
|
filesInEditorSupports << cppEditor->filePath();
|
2013-07-17 13:50:38 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
void CppModelManager::finishedRefreshingSourceFiles(const QSet<QString> &files)
|
2011-07-05 10:46:46 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-06-06 10:55:09 -04:00
|
|
|
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(const QString &mimeType) const
|
2012-02-20 12:39:08 +01:00
|
|
|
{
|
2014-06-06 10:55:09 -04:00
|
|
|
if (mimeType.isEmpty())
|
|
|
|
return 0;
|
2013-09-04 18:15:08 +02:00
|
|
|
|
2014-06-06 10:55:09 -04:00
|
|
|
ModelManagerSupport *cms = modelManagerSupportForMimeType(mimeType);
|
|
|
|
QTC_ASSERT(cms, return 0);
|
2013-09-04 18:15:08 +02:00
|
|
|
return cms->completionAssistProvider();
|
2012-02-20 12:39:08 +01:00
|
|
|
}
|
|
|
|
|
2014-08-19 15:59:29 +02:00
|
|
|
BaseEditorDocumentProcessor *CppModelManager::editorDocumentProcessor(
|
2014-06-06 11:52:09 -04:00
|
|
|
TextEditor::BaseTextDocument *baseTextDocument) const
|
2012-02-07 15:09:08 +01:00
|
|
|
{
|
2014-06-06 11:52:09 -04:00
|
|
|
QTC_ASSERT(baseTextDocument, return 0);
|
|
|
|
ModelManagerSupport *cms = modelManagerSupportForMimeType(baseTextDocument->mimeType());
|
|
|
|
QTC_ASSERT(cms, return 0);
|
2014-08-19 15:59:29 +02:00
|
|
|
return cms->editorDocumentProcessor(baseTextDocument);
|
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-12-17 13:54:52 +01:00
|
|
|
void CppModelManager::enableGarbageCollector(bool enable)
|
|
|
|
{
|
|
|
|
m_delayedGcTimer->stop();
|
|
|
|
m_enableGC = enable;
|
|
|
|
}
|