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-04-23 15:04:36 +02:00
|
|
|
#include "cpppreprocessor.h"
|
|
|
|
#include "cpptoolsconstants.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2013-03-12 12:06:41 +01:00
|
|
|
#include "builtinindexingsupport.h"
|
2012-02-21 10:00:32 +01:00
|
|
|
#include "cppcompletionassist.h"
|
2012-02-20 12:39:08 +01:00
|
|
|
#include "cpphighlightingsupport.h"
|
|
|
|
#include "cpphighlightingsupportinternal.h"
|
2012-10-16 16:02:40 +02:00
|
|
|
#include "cppindexingsupport.h"
|
2010-12-03 13:49:35 +01:00
|
|
|
#include "abstracteditorsupport.h"
|
2012-09-07 10:51:50 +02:00
|
|
|
#include "cpptoolseditorsupport.h"
|
|
|
|
#include "cppfindreferences.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>
|
2009-10-05 13:43:05 +02:00
|
|
|
|
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 <QTimer>
|
|
|
|
#include <QTextBlock>
|
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-04-23 15:04:36 +02:00
|
|
|
#ifdef WITH_AST_DUMP
|
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
|
|
|
|
2010-12-03 13:49:35 +01:00
|
|
|
void CppModelManager::updateModifiedSourceFiles()
|
2009-11-05 12:34:02 +01:00
|
|
|
{
|
|
|
|
const Snapshot snapshot = this->snapshot();
|
|
|
|
QStringList sourceFiles;
|
|
|
|
|
|
|
|
foreach (const Document::Ptr doc, snapshot) {
|
|
|
|
const QDateTime lastModified = doc->lastModified();
|
|
|
|
|
|
|
|
if (! lastModified.isNull()) {
|
|
|
|
QFileInfo fileInfo(doc->fileName());
|
|
|
|
|
|
|
|
if (fileInfo.exists() && fileInfo.lastModified() != lastModified)
|
|
|
|
sourceFiles.append(doc->fileName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSourceFiles(sourceFiles);
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
\class CppTools::CppModelManager
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The CppModelManager class keeps track of one CppCodeModel instance
|
|
|
|
for each project and all the related CppCodeModelPart instances.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
It also takes care of updating the code models when C++ files are
|
2009-05-08 13:01:32 +02:00
|
|
|
modified within Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
2012-10-15 16:38:56 +02:00
|
|
|
QMutex CppModelManager::m_modelManagerMutex;
|
|
|
|
CppModelManager *CppModelManager::m_modelManagerInstance = 0;
|
|
|
|
|
|
|
|
CppModelManager *CppModelManager::instance()
|
|
|
|
{
|
|
|
|
if (m_modelManagerInstance)
|
|
|
|
return m_modelManagerInstance;
|
|
|
|
QMutexLocker locker(&m_modelManagerMutex);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!m_modelManagerInstance)
|
2012-10-15 16:38:56 +02:00
|
|
|
m_modelManagerInstance = new CppModelManager;
|
|
|
|
return m_modelManagerInstance;
|
|
|
|
}
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
CppModelManager::CppModelManager(QObject *parent)
|
2009-11-10 18:02:42 +01:00
|
|
|
: CppModelManagerInterface(parent)
|
2013-04-19 16:56:12 +02:00
|
|
|
, m_enableGC(true)
|
2012-11-23 11:47:39 +01:00
|
|
|
, m_completionAssistProvider(0)
|
|
|
|
, m_highlightingFactory(0)
|
|
|
|
, m_indexingSupporter(0)
|
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;
|
|
|
|
|
2009-03-04 11:47:30 +01:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin *pe =
|
2009-03-04 09:38:01 +01:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-04 09:38:01 +01:00
|
|
|
QTC_ASSERT(pe, return);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-04 09:38:01 +01:00
|
|
|
ProjectExplorer::SessionManager *session = pe->session();
|
2008-12-04 17:07:43 +01:00
|
|
|
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
|
|
|
this, SLOT(onProjectAdded(ProjectExplorer::Project*)));
|
|
|
|
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
|
|
|
|
this, SLOT(onAboutToRemoveProject(ProjectExplorer::Project*)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-10 12:46:33 +01:00
|
|
|
connect(session, 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");
|
|
|
|
|
2012-02-21 10:00:32 +01:00
|
|
|
m_completionFallback = new InternalCompletionAssistProvider;
|
|
|
|
m_completionAssistProvider = m_completionFallback;
|
2012-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
|
2012-02-20 12:39:08 +01:00
|
|
|
m_highlightingFallback = new CppHighlightingSupportInternalFactory;
|
|
|
|
m_highlightingFactory = m_highlightingFallback;
|
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-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
|
2012-02-20 12:39:08 +01:00
|
|
|
delete m_completionFallback;
|
|
|
|
delete m_highlightingFallback;
|
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);
|
2008-12-08 10:44:56 +01:00
|
|
|
if (! m_dirty)
|
|
|
|
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;
|
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projects);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
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;
|
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projects);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
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;
|
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projects);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
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;
|
2008-12-02 12:01:29 +01:00
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projects);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-06 10:48:16 +01:00
|
|
|
/// This method will aquire the mutex!
|
|
|
|
void CppModelManager::dumpModelManagerConfiguration()
|
|
|
|
{
|
|
|
|
// Tons of debug output...
|
|
|
|
qDebug()<<"========= CppModelManager::dumpModelManagerConfiguration ======";
|
2013-03-08 09:58:01 +01:00
|
|
|
foreach (const ProjectInfo &pinfo, m_projects) {
|
2012-11-06 10:48:16 +01:00
|
|
|
qDebug()<<" for project:"<< pinfo.project().data()->document()->fileName();
|
|
|
|
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");
|
|
|
|
if (part->cxxExtensions & ProjectPart::OpenMP)
|
|
|
|
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;
|
|
|
|
qDebug()<<"========= End of dump ======";
|
|
|
|
}
|
|
|
|
|
2009-05-12 13:45:24 +02:00
|
|
|
void CppModelManager::addEditorSupport(AbstractEditorSupport *editorSupport)
|
|
|
|
{
|
|
|
|
m_addtionalEditorSupport.insert(editorSupport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppModelManager::removeEditorSupport(AbstractEditorSupport *editorSupport)
|
|
|
|
{
|
|
|
|
m_addtionalEditorSupport.remove(editorSupport);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
CppEditorSupport *CppModelManager::cppEditorSupport(TextEditor::BaseTextEditor *editor)
|
|
|
|
{
|
|
|
|
Q_ASSERT(editor);
|
|
|
|
|
|
|
|
QMutexLocker locker(&m_editorSupportMutex);
|
|
|
|
|
|
|
|
CppEditorSupport *editorSupport = m_editorSupport.value(editor, 0);
|
|
|
|
if (!editorSupport) {
|
|
|
|
editorSupport = new CppEditorSupport(this, editor);
|
|
|
|
m_editorSupport.insert(editor, editorSupport);
|
|
|
|
}
|
|
|
|
return editorSupport;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-20 11:02:37 +02:00
|
|
|
void CppModelManager::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
|
|
|
|
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-04-17 10:58:20 +02:00
|
|
|
QList<CppEditorSupport *> supporters;
|
|
|
|
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_editorSupportMutex);
|
|
|
|
supporters = m_editorSupport.values();
|
|
|
|
}
|
|
|
|
|
2009-12-15 15:16:46 +01:00
|
|
|
WorkingCopy workingCopy;
|
2013-04-17 10:58:20 +02:00
|
|
|
foreach (const CppEditorSupport *editorSupport, supporters) {
|
|
|
|
workingCopy.insert(editorSupport->fileName(), editorSupport->contents(),
|
|
|
|
editorSupport->editorRevision());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2009-05-12 13:45:24 +02:00
|
|
|
QSetIterator<AbstractEditorSupport *> jt(m_addtionalEditorSupport);
|
|
|
|
while (jt.hasNext()) {
|
|
|
|
AbstractEditorSupport *es = jt.next();
|
2012-11-21 22:36:47 +02:00
|
|
|
workingCopy.insert(es->fileName(), QString::fromUtf8(es->contents()));
|
2009-05-12 13:45:24 +02:00
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// add the project configuration file
|
|
|
|
QByteArray conf(pp_configuration);
|
|
|
|
conf += definedMacros();
|
2013-06-13 12:17:33 +02:00
|
|
|
workingCopy.insert(configurationFileName(), QString::fromLocal8Bit(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-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);
|
2008-12-08 10:44:56 +01:00
|
|
|
|
|
|
|
return m_projects.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
CppModelManager::ProjectInfo CppModelManager::projectInfo(ProjectExplorer::Project *project) const
|
|
|
|
{
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2008-12-08 10:44:56 +01:00
|
|
|
|
|
|
|
return m_projects.value(project, ProjectInfo(project));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
|
|
|
|
{
|
2012-11-06 10:48:16 +01:00
|
|
|
{ // only hold the mutex for a limited scope, so the dumping afterwards can aquire it without deadlocking.
|
2013-04-23 14:46:44 +02:00
|
|
|
QMutexLocker locker(&m_projectMutex);
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2012-11-06 10:48:16 +01:00
|
|
|
if (! pinfo.isValid())
|
|
|
|
return;
|
2008-12-08 10:44:56 +01:00
|
|
|
|
2012-11-06 10:48:16 +01:00
|
|
|
ProjectExplorer::Project *project = pinfo.project().data();
|
|
|
|
m_projects.insert(project, pinfo);
|
|
|
|
m_dirty = true;
|
2008-12-08 10:44:56 +01:00
|
|
|
|
2012-11-06 10:48:16 +01:00
|
|
|
m_srcToProjectPart.clear();
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2013-03-08 09:58:01 +01:00
|
|
|
foreach (const ProjectInfo &projectInfo, m_projects) {
|
2012-11-23 16:29:00 +01:00
|
|
|
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
|
2013-04-11 12:51:06 +02:00
|
|
|
foreach (const ProjectFile &cxxFile, projectPart->files) {
|
2013-03-04 01:30:46 +04:00
|
|
|
m_srcToProjectPart[cxxFile.path].append(projectPart);
|
2013-04-11 12:51:06 +02:00
|
|
|
foreach (const QString &fileName, m_snapshot.allIncludesForDocument(cxxFile.path))
|
|
|
|
m_snapshot.remove(fileName);
|
|
|
|
m_snapshot.remove(cxxFile.path);
|
|
|
|
}
|
2012-11-23 16:29:00 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-11 12:51:06 +02:00
|
|
|
|
|
|
|
m_snapshot.remove(configurationFileName());
|
2012-11-06 10:48:16 +01:00
|
|
|
}
|
2012-02-16 15:09:56 +01:00
|
|
|
|
2012-11-06 10:48:16 +01:00
|
|
|
if (!qgetenv("QTCREATOR_DUMP_PROJECT_INFO").isEmpty())
|
|
|
|
dumpModelManagerConfiguration();
|
2013-01-01 10:34:42 +01:00
|
|
|
|
|
|
|
emit projectPartsUpdated(pinfo.project().data());
|
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-03-04 01:30:46 +04:00
|
|
|
QList<ProjectPart::Ptr> parts = m_srcToProjectPart.value(fileName);
|
2012-02-16 15:09:56 +01:00
|
|
|
if (!parts.isEmpty())
|
|
|
|
return parts;
|
|
|
|
|
|
|
|
DependencyTable table;
|
|
|
|
table.build(snapshot());
|
|
|
|
QStringList deps = table.filesDependingOn(fileName);
|
|
|
|
foreach (const QString &dep, deps) {
|
|
|
|
parts = m_srcToProjectPart.value(dep);
|
|
|
|
if (!parts.isEmpty())
|
|
|
|
return parts;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parts;
|
2008-12-08 10:44:56 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-04-17 10:58:20 +02:00
|
|
|
/// \brief Removes the CppEditorSupport for the closed editor.
|
2013-05-24 13:04:40 +02:00
|
|
|
void CppModelManager::deleteEditorSupport(TextEditor::BaseTextEditor *textEditor)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-04-17 10:58:20 +02:00
|
|
|
QTC_ASSERT(textEditor, return);
|
|
|
|
|
2013-05-24 13:04:40 +02:00
|
|
|
if (!isCppEditor(textEditor))
|
|
|
|
return;
|
|
|
|
|
2013-04-17 10:58:20 +02:00
|
|
|
QMutexLocker locker(&m_editorSupportMutex);
|
|
|
|
CppEditorSupport *editorSupport = m_editorSupport.value(textEditor, 0);
|
|
|
|
m_editorSupport.remove(textEditor);
|
|
|
|
delete editorSupport;
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
m_projects.remove(project);
|
|
|
|
} while (0);
|
|
|
|
|
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
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (Core::ProgressManager *pm = Core::ICore::progressManager())
|
2012-11-21 22:36:47 +02:00
|
|
|
pm->cancelTasks(QLatin1String(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);
|
2008-12-08 10:44:56 +01:00
|
|
|
m_projects.clear();
|
|
|
|
m_dirty = true;
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
GC();
|
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-02-19 12:48:42 +01:00
|
|
|
Snapshot currentSnapshot = snapshot();
|
2008-12-02 12:01:29 +01:00
|
|
|
QSet<QString> processed;
|
2008-12-04 17:07:43 +01:00
|
|
|
QStringList todo = projectFiles();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
while (! todo.isEmpty()) {
|
|
|
|
QString fn = todo.last();
|
|
|
|
todo.removeLast();
|
|
|
|
|
|
|
|
if (processed.contains(fn))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
processed.insert(fn);
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (Document::Ptr doc = currentSnapshot.document(fn))
|
2008-12-02 12:01:29 +01:00
|
|
|
todo += doc->includedFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList removedFiles;
|
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();
|
|
|
|
|
|
|
|
if (processed.contains(fileName))
|
|
|
|
newSnapshot.insert(it.value());
|
|
|
|
else
|
|
|
|
removedFiles.append(fileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
emit aboutToRemoveFiles(removedFiles);
|
2009-06-02 15:27:13 +02:00
|
|
|
|
2013-02-19 12:48:42 +01:00
|
|
|
replaceSnapshot(newSnapshot);
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-07 15:09:08 +01:00
|
|
|
CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor) const
|
|
|
|
{
|
2012-02-20 12:39:08 +01:00
|
|
|
if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor))
|
2012-02-21 10:00:32 +01:00
|
|
|
return m_completionAssistProvider->completionSupport(textEditor);
|
2012-02-07 15:09:08 +01:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 10:00:32 +01:00
|
|
|
void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider)
|
2012-02-20 12:39:08 +01:00
|
|
|
{
|
2012-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
|
2012-02-21 10:00:32 +01:00
|
|
|
if (completionAssistProvider)
|
|
|
|
m_completionAssistProvider = completionAssistProvider;
|
2012-02-20 12:39:08 +01:00
|
|
|
else
|
2012-02-21 10:00:32 +01:00
|
|
|
m_completionAssistProvider = m_completionFallback;
|
2012-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
|
2012-02-20 12:39:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 15:09:08 +01:00
|
|
|
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
|
|
|
|
{
|
2012-02-20 12:39:08 +01:00
|
|
|
if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor))
|
|
|
|
return m_highlightingFactory->highlightingSupport(textEditor);
|
2012-02-07 15:09:08 +01:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-24 10:55:48 +02:00
|
|
|
|
2012-02-20 12:39:08 +01:00
|
|
|
void CppModelManager::setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory)
|
|
|
|
{
|
|
|
|
if (highlightingFactory)
|
|
|
|
m_highlightingFactory = highlightingFactory;
|
|
|
|
else
|
|
|
|
m_highlightingFactory = m_highlightingFallback;
|
|
|
|
}
|
|
|
|
|
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-04-17 10:58:20 +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-04-17 10:58:20 +02:00
|
|
|
QList<CppEditorSupport *> supporters;
|
|
|
|
|
2011-08-24 10:55:48 +02:00
|
|
|
{
|
2013-04-17 10:58:20 +02:00
|
|
|
QMutexLocker locker(&m_editorSupportMutex);
|
|
|
|
supporters = m_editorSupport.values();
|
2011-08-24 10:55:48 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 10:58:20 +02:00
|
|
|
foreach (CppEditorSupport *supporter, supporters) {
|
|
|
|
if (supporter->fileName() == fileName) {
|
|
|
|
supporter->setExtraDiagnostics(kind, diagnostics);
|
|
|
|
break;
|
|
|
|
}
|
2011-08-24 10:55:48 +02:00
|
|
|
}
|
|
|
|
}
|