Clang: fix indexing to at least compile

Change-Id: Ife43b0850f61e17af5f2c2e4397c7db6bb12e598
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Erik Verbruggen
2014-09-05 11:22:02 +02:00
committed by Nikolai Kosjar
parent 580b5d1239
commit e29324118a
9 changed files with 52 additions and 278 deletions

View File

@@ -75,14 +75,12 @@ SOURCES += clangutils.cpp \
contains(DEFINES, CLANG_INDEXING) { contains(DEFINES, CLANG_INDEXING) {
HEADERS += \ HEADERS += \
$$PWD/clangindexer.h \ $$PWD/clangindexer.h \
$$PWD/clangsymbolsearcher.h \
$$PWD/index.h \ $$PWD/index.h \
$$PWD/indexer.h $$PWD/indexer.h
# $$PWD/dependencygraph.h \ # $$PWD/dependencygraph.h \
SOURCES += \ SOURCES += \
$$PWD/clangindexer.cpp \ $$PWD/clangindexer.cpp \
$$PWD/clangsymbolsearcher.cpp \
$$PWD/index.cpp \ $$PWD/index.cpp \
$$PWD/indexer.cpp $$PWD/indexer.cpp
# $$PWD/dependencygraph.cpp \ # $$PWD/dependencygraph.cpp \

View File

@@ -105,8 +105,6 @@ QtcPlugin {
files: [ files: [
"clangindexer.cpp", "clangindexer.cpp",
"clangindexer.h", "clangindexer.h",
"clangsymbolsearcher.cpp",
"clangsymbolsearcher.h",
"index.cpp", "index.cpp",
"index.h", "index.h",
"indexer.cpp", "indexer.cpp",

View File

@@ -28,10 +28,8 @@
****************************************************************************/ ****************************************************************************/
#include "clangindexer.h" #include "clangindexer.h"
#include "clangsymbolsearcher.h"
#include "clangutils.h" #include "clangutils.h"
#include "indexer.h" #include "indexer.h"
#include "liveunitsmanager.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -52,14 +50,21 @@ ClangIndexingSupport::~ClangIndexingSupport()
{ {
} }
QFuture<void> ClangIndexingSupport::refreshSourceFiles(const QStringList &sourceFiles) QFuture<void> ClangIndexingSupport::refreshSourceFiles(
const QSet<QString> &sourceFiles,
CppTools::CppModelManager::ProgressNotificationMode mode)
{ {
Q_UNUSED(mode);
return m_indexer->refreshSourceFiles(sourceFiles); return m_indexer->refreshSourceFiles(sourceFiles);
} }
CppTools::SymbolSearcher *ClangIndexingSupport::createSymbolSearcher(CppTools::SymbolSearcher::Parameters parameters, QSet<QString> fileNames) CppTools::SymbolSearcher *ClangIndexingSupport::createSymbolSearcher(CppTools::SymbolSearcher::Parameters parameters, QSet<QString> fileNames)
{ {
return new ClangSymbolSearcher(m_indexer, parameters, fileNames); Q_UNUSED(parameters);
Q_UNUSED(fileNames)
// return new ClangSymbolSearcher(m_indexer, parameters, fileNames);
return 0;
} }
ClangIndexer::ClangIndexer() ClangIndexer::ClangIndexer()
@@ -68,8 +73,8 @@ ClangIndexer::ClangIndexer()
, m_isLoadingSession(false) , m_isLoadingSession(false)
, m_clangIndexer(new Indexer(this)) , m_clangIndexer(new Indexer(this))
{ {
connect(m_clangIndexer, SIGNAL(indexingStarted(QFuture<void>)), connect(m_clangIndexer, SIGNAL(indexingStarted(QFuture<void>, Internal::ProgressNotificationMode)),
this, SLOT(onIndexingStarted(QFuture<void>))); this, SLOT(onIndexingStarted(QFuture<void>, Internal::ProgressNotificationMode)));
QObject *session = ProjectExplorer::SessionManager::instance(); QObject *session = ProjectExplorer::SessionManager::instance();
@@ -91,19 +96,18 @@ CppTools::CppIndexingSupport *ClangIndexer::indexingSupport()
return m_indexingSupport.data(); return m_indexingSupport.data();
} }
QFuture<void> ClangIndexer::refreshSourceFiles(const QStringList &sourceFiles) QFuture<void> ClangIndexer::refreshSourceFiles(const QSet<QString> &sourceFiles)
{ {
typedef CppTools::ProjectPart ProjectPart; typedef CppTools::ProjectPart ProjectPart;
CppTools::CppModelManager *mmi = CppTools::CppModelManager::instance(); CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
LiveUnitsManager *lum = LiveUnitsManager::instance();
if (m_clangIndexer->isBusy()) if (m_clangIndexer->isBusy())
m_clangIndexer->cancel(true); m_clangIndexer->cancel(true);
foreach (const QString &file, sourceFiles) { foreach (const QString &file, sourceFiles) {
if (lum->isTracking(file)) if (m_clangIndexer->isTracking(file))
continue; // we get notified separately about open files. continue; // we get notified separately about open files.
const QList<ProjectPart::Ptr> &parts = mmi->projectPart(file); const QList<ProjectPart::Ptr> &parts = modelManager->projectPart(file);
if (!parts.isEmpty()) if (!parts.isEmpty())
m_clangIndexer->addFile(file, parts.at(0)); m_clangIndexer->addFile(file, parts.at(0));
else else
@@ -160,7 +164,8 @@ void ClangIndexer::indexNow(Unit::Ptr unit)
void ClangIndexer::onIndexingStarted(QFuture<void> indexingFuture) void ClangIndexer::onIndexingStarted(QFuture<void> indexingFuture)
{ {
Core::ICore::instance()->progressManager()->addTask(indexingFuture, Core::ProgressManager::addTask(indexingFuture, QCoreApplication::translate(
tr("C++ Indexing"), "ClangCodeModel::Internal::ClangIndexer",
QLatin1String("Key.Temp.Indexing")); "Parsing C/C++/ObjC Files"),
"ClangCodeMode.Task.Indexing");
} }

View File

@@ -42,6 +42,7 @@ class Indexer;
namespace Internal { namespace Internal {
typedef CppTools::CppModelManager::ProgressNotificationMode ProgressNotificationMode;
class ClangIndexer; class ClangIndexer;
class ClangSymbolSearcher; class ClangSymbolSearcher;
@@ -51,8 +52,11 @@ public:
ClangIndexingSupport(ClangIndexer *indexer); ClangIndexingSupport(ClangIndexer *indexer);
virtual ~ClangIndexingSupport(); virtual ~ClangIndexingSupport();
virtual QFuture<void> refreshSourceFiles(const QStringList &sourceFiles); virtual QFuture<void> refreshSourceFiles(
virtual CppTools::SymbolSearcher *createSymbolSearcher(CppTools::SymbolSearcher::Parameters parameters, QSet<QString> fileNames); const QSet<QString> &sourceFiles,
ProgressNotificationMode mode);
virtual CppTools::SymbolSearcher *createSymbolSearcher(
CppTools::SymbolSearcher::Parameters parameters, QSet<QString> fileNames);
private: private:
ClangIndexer *m_indexer; ClangIndexer *m_indexer;
@@ -68,7 +72,7 @@ public:
CppTools::CppIndexingSupport *indexingSupport(); CppTools::CppIndexingSupport *indexingSupport();
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles); QFuture<void> refreshSourceFiles(const QSet<QString> &sourceFiles);
void match(ClangSymbolSearcher *searcher) const; void match(ClangSymbolSearcher *searcher) const;

View File

@@ -1,155 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clangsymbolsearcher.h"
#include "symbol.h"
#include <cpptools/searchsymbols.h>
#include <cassert>
using namespace ClangCodeModel;
using namespace ClangCodeModel::Internal;
ClangSymbolSearcher::ClangSymbolSearcher(ClangIndexer *indexer, const Parameters &parameters, QSet<QString> fileNames, QObject *parent)
: CppTools::SymbolSearcher(parent)
, m_indexer(indexer)
, m_parameters(parameters)
, m_fileNames(fileNames)
, m_future(0)
{
assert(indexer);
}
ClangSymbolSearcher::~ClangSymbolSearcher()
{
}
void ClangSymbolSearcher::runSearch(QFutureInterface<SearchResultItem> &future)
{
m_future = &future;
m_indexer->match(this);
m_future = 0;
}
void ClangSymbolSearcher::search(const QLinkedList<Symbol> &allSymbols)
{
QString findString = (m_parameters.flags & Find::FindRegularExpression
? m_parameters.text : QRegExp::escape(m_parameters.text));
if (m_parameters.flags & Find::FindWholeWords)
findString = QString::fromLatin1("\\b%1\\b").arg(findString);
QRegExp matcher(findString, (m_parameters.flags & Find::FindCaseSensitively
? Qt::CaseSensitive : Qt::CaseInsensitive));
const int chunkSize = 10;
QVector<Core::SearchResultItem> resultItems;
resultItems.reserve(100);
m_future->setProgressRange(0, allSymbols.size() % chunkSize);
m_future->setProgressValue(0);
int symbolNr = 0;
foreach (const Symbol &s, allSymbols) {
if (symbolNr % chunkSize == 0) {
m_future->setProgressValue(symbolNr / chunkSize);
m_future->reportResults(resultItems);
resultItems.clear();
if (m_future->isPaused())
m_future->waitForResume();
if (m_future->isCanceled())
return;
}
++symbolNr;
CppTools::IndexItem info;
switch (s.m_kind) {
case Symbol::Enum:
if (m_parameters.types & SymbolSearcher::Enums) {
info.type = CppTools::IndexItem::Enum;
info.symbolType = QLatin1String("enum");
break;
} else {
continue;
}
case Symbol::Class:
if (m_parameters.types & SymbolSearcher::Classes) {
info.type = CppTools::IndexItem::Class;
info.symbolType = QLatin1String("class");
break;
} else {
continue;
}
case Symbol::Method:
case Symbol::Function:
case Symbol::Constructor:
case Symbol::Destructor:
if (m_parameters.types & SymbolSearcher::Functions) {
info.type = CppTools::IndexItem::Function;
break;
} else {
continue;
}
case Symbol::Declaration:
if (m_parameters.types & SymbolSearcher::Declarations) {
info.type = CppTools::IndexItem::Declaration;
break;
} else {
continue;
}
default: continue;
}
if (matcher.indexIn(s.m_name) == -1)
continue;
info.symbolName = s.m_name;
info.fullyQualifiedName = s.m_qualification.split(QLatin1String("::")) << s.m_name;
info.fileName = s.m_location.fileName();
info.icon = s.iconForSymbol();
info.line = s.m_location.line();
info.column = s.m_location.column() - 1;
Core::SearchResultItem item;
item.path << s.m_qualification;
item.text = s.m_name;
item.icon = info.icon;
item.textMarkPos = -1;
item.textMarkLength = 0;
item.lineNumber = -1;
item.userData = qVariantFromValue(info);
resultItems << item;
}
if (!resultItems.isEmpty())
m_future->reportResults(resultItems);
}

View File

@@ -1,69 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGSYMBOLSEARCHER_H
#define CLANGSYMBOLSEARCHER_H
#include "clangindexer.h"
#include <cpptools/cppindexingsupport.h>
#include <QLinkedList>
namespace ClangCodeModel {
class Symbol;
namespace Internal {
class ClangSymbolSearcher: public CppTools::SymbolSearcher
{
Q_OBJECT
typedef CppTools::SymbolSearcher::Parameters Parameters;
typedef Core::SearchResultItem SearchResultItem;
public:
ClangSymbolSearcher(ClangIndexer *indexer, const Parameters &parameters, QSet<QString> fileNames, QObject *parent = 0);
virtual ~ClangSymbolSearcher();
virtual void runSearch(QFutureInterface<SearchResultItem> &future);
void search(const QLinkedList<Symbol> &allSymbols);
private:
ClangIndexer *m_indexer;
const Parameters m_parameters;
const QSet<QString> m_fileNames;
QFutureInterface<SearchResultItem> *m_future;
};
} // namespace Internal
} // namespace ClangCodeModel
#endif // CLANGSYMBOLSEARCHER_H

View File

@@ -27,7 +27,6 @@
** **
****************************************************************************/ ****************************************************************************/
#include "clangsymbolsearcher.h"
#include "index.h" #include "index.h"
#include <QStringList> #include <QStringList>
@@ -257,8 +256,8 @@ QList<Symbol> IndexPrivate::symbols(Symbol::Kind kind) const
void IndexPrivate::match(ClangSymbolSearcher *searcher) const void IndexPrivate::match(ClangSymbolSearcher *searcher) const
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
Q_UNUSED(searcher);
searcher->search(m_container); // searcher->search(m_container);
} }
QList<Symbol> IndexPrivate::symbolsFromIterators(const QList<SymbolIt> &symbolList) QList<Symbol> IndexPrivate::symbolsFromIterators(const QList<SymbolIt> &symbolList)

View File

@@ -32,9 +32,7 @@
#include "index.h" #include "index.h"
#include "cxraii.h" #include "cxraii.h"
#include "sourcelocation.h" #include "sourcelocation.h"
#include "liveunitsmanager.h"
#include "utils_p.h" #include "utils_p.h"
#include "clangsymbolsearcher.h"
#include "pchmanager.h" #include "pchmanager.h"
#include "raii/scopedclangoptions.h" #include "raii/scopedclangoptions.h"
@@ -61,19 +59,6 @@
#include <QDateTime> #include <QDateTime>
#include <QStringBuilder> #include <QStringBuilder>
#include <cassert>
//#define DEBUG
//#define DEBUG_DIAGNOSTICS
#ifdef DEBUG
#define BEGIN_PROFILE_SCOPE(ID) { ScopepTimer t(ID);
#define END_PROFILE_SCOPE }
#else
#define BEGIN_PROFILE_SCOPE(ID)
#define END_PROFILE_SCOPE
#endif
using namespace Utils; using namespace Utils;
using namespace ClangCodeModel; using namespace ClangCodeModel;
using namespace Internal; using namespace Internal;
@@ -172,7 +157,7 @@ public:
void computeDependencyGraph(); void computeDependencyGraph();
void analyzeRestoredSymbols(); void analyzeRestoredSymbols();
void runQuickIndexing(const Unit &unit, const ProjectPart::Ptr &part); void runQuickIndexing(const Unit::Ptr &unit, const ProjectPart::Ptr &part);
void run(); void run();
void run(const QStringList &fileNames); void run(const QStringList &fileNames);
void runCore(const QHash<QString, FileData> &headers, void runCore(const QHash<QString, FileData> &headers,
@@ -389,7 +374,7 @@ protected:
void addInclude(File *f) void addInclude(File *f)
{ {
assert(f); // assert(f);
m_includes.insert(f->name(), f); m_includes.insert(f->name(), f);
} }
@@ -407,7 +392,7 @@ protected:
void addSymbol(Symbol *symbol) void addSymbol(Symbol *symbol)
{ {
assert(symbol); // assert(symbol);
m_symbols.append(symbol); m_symbols.append(symbol);
} }
@@ -656,7 +641,7 @@ private:
class QuickIndexer: public LibClangIndexer class QuickIndexer: public LibClangIndexer
{ {
public: public:
QuickIndexer(IndexerPrivate *indexer, const Unit &unit, const ProjectPart::Ptr &projectPart) QuickIndexer(IndexerPrivate *indexer, const Unit::Ptr &unit, const ProjectPart::Ptr&projectPart)
: LibClangIndexer(indexer) : LibClangIndexer(indexer)
, m_unit(unit) , m_unit(unit)
, m_projectPart(projectPart) , m_projectPart(projectPart)
@@ -664,19 +649,19 @@ public:
void run() void run()
{ {
if (isCanceled() || !m_unit.isLoaded()) { if (isCanceled() || !m_unit->isLoaded()) {
finish(); finish();
return; return;
} }
CXIndexAction idxAction = clang_IndexAction_create(m_unit.clangIndex()); CXIndexAction idxAction = clang_IndexAction_create(m_unit->clangIndex());
const unsigned index_opts = CXIndexOpt_SuppressWarnings; const unsigned index_opts = CXIndexOpt_SuppressWarnings;
// qDebug() << "Indexing TU" << m_unit.fileName() << "..."; // qDebug() << "Indexing TU" << m_unit.fileName() << "...";
/*int result =*/ clang_indexTranslationUnit(idxAction, this, /*int result =*/ clang_indexTranslationUnit(idxAction, this,
&IndexCB, sizeof(IndexCB), &IndexCB, sizeof(IndexCB),
index_opts, index_opts,
m_unit.clangTranslationUnit()); m_unit->clangTranslationUnit());
propagateResults(m_projectPart); propagateResults(m_projectPart);
@@ -685,7 +670,7 @@ public:
} }
private: private:
Unit m_unit; Unit::Ptr m_unit;
ProjectPart::Ptr m_projectPart; ProjectPart::Ptr m_projectPart;
}; };
@@ -839,23 +824,23 @@ void IndexerPrivate::reset()
void IndexerPrivate::synchronize(const QVector<IndexingResult> &results) void IndexerPrivate::synchronize(const QVector<IndexingResult> &results)
{ {
foreach (IndexingResult result, results) { Q_UNUSED(results);
#if 0
foreach (const IndexingResult &result, results) {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
result.m_unit.makeUnique();
foreach (const Symbol &symbol, result.m_symbolsInfo) { foreach (const Symbol &symbol, result.m_symbolsInfo) {
addOrUpdateFileData(symbol.m_location.fileName(), addOrUpdateFileData(symbol.m_location.fileName(),
result.m_projectPart, result.m_projectPart,
true); true);
// Make the symbol available in the database. // Make the symbol available in the database.
m_index.insertSymbol(symbol, result.m_unit.timeStamp()); m_index.insertSymbol(symbol, result.m_unit->timeStamp());
} }
// There might be files which were processed but did not "generate" any indexable symbol, // There might be files which were processed but did not "generate" any indexable symbol,
// but we still need to make the index aware of them. // but we still need to make the index aware of them.
result.m_processedFiles.insert(result.m_unit.fileName()); result.m_processedFiles.insert(result.m_unit->fileName());
foreach (const QString &fileName, result.m_processedFiles) { foreach (const QString &fileName, result.m_processedFiles) {
if (!m_index.containsFile(fileName)) if (!m_index.containsFile(fileName))
m_index.insertFile(fileName, result.m_unit.timeStamp()); m_index.insertFile(fileName, result.m_unit.timeStamp());
@@ -865,6 +850,7 @@ void IndexerPrivate::synchronize(const QVector<IndexingResult> &results)
if (LiveUnitsManager::instance()->isTracking(result.m_unit.fileName())) if (LiveUnitsManager::instance()->isTracking(result.m_unit.fileName()))
LiveUnitsManager::instance()->updateUnit(result.m_unit.fileName(), result.m_unit); LiveUnitsManager::instance()->updateUnit(result.m_unit.fileName(), result.m_unit);
} }
#endif
} }
void IndexerPrivate::finished(LibClangIndexer *indexer) void IndexerPrivate::finished(LibClangIndexer *indexer)
@@ -1089,11 +1075,11 @@ void IndexerPrivate::analyzeRestoredSymbols()
} }
} }
void IndexerPrivate::runQuickIndexing(const Unit &unit, const CppTools::ProjectPart::Ptr &part) void IndexerPrivate::runQuickIndexing(const Unit::Ptr &unit, const CppTools::ProjectPart::Ptr &part)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
addOrUpdateFileData(unit.fileName(), part, false); addOrUpdateFileData(unit->fileName(), part, false);
QuickIndexer indexer(this, unit, part); QuickIndexer indexer(this, unit, part);
indexer.run(); indexer.run();
@@ -1288,4 +1274,10 @@ void Indexer::runQuickIndexing(Unit::Ptr unit, const CppTools::ProjectPart::Ptr
m_d->runQuickIndexing(unit, part); m_d->runQuickIndexing(unit, part);
} }
bool Indexer::isTracking(const QString &fileName) const
{
return m_d->isTrackingFile(fileName, IndexerPrivate::ImplementationFile)
|| m_d->isTrackingFile(fileName, IndexerPrivate::HeaderFile);
}
#include "indexer.moc" #include "indexer.moc"

View File

@@ -87,6 +87,8 @@ public:
void runQuickIndexing(Internal::Unit::Ptr unit, const ProjectPart::Ptr &part); void runQuickIndexing(Internal::Unit::Ptr unit, const ProjectPart::Ptr &part);
bool isTracking(const QString &fileName) const;
signals: signals:
void indexingStarted(QFuture<void> future); void indexingStarted(QFuture<void> future);
void indexingFinished(); void indexingFinished();