forked from qt-creator/qt-creator
Introduced a parallel indexer. It is ifdef-out atm.
This commit is contained in:
@@ -230,7 +230,8 @@ Document::Ptr Document::create(const QString &fileName)
|
|||||||
|
|
||||||
void Document::setSource(const QByteArray &source)
|
void Document::setSource(const QByteArray &source)
|
||||||
{
|
{
|
||||||
_translationUnit->setSource(source.constBegin(), source.size());
|
_source = source;
|
||||||
|
_translationUnit->setSource(_source.constBegin(), _source.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::startSkippingBlocks(unsigned start)
|
void Document::startSkippingBlocks(unsigned start)
|
||||||
@@ -250,6 +251,21 @@ void Document::stopSkippingBlocks(unsigned stop)
|
|||||||
_skippedBlocks.back() = Block(start, stop);
|
_skippedBlocks.back() = Block(start, stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Document::isTokenized() const
|
||||||
|
{
|
||||||
|
return _translationUnit->isTokenized();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Document::tokenize()
|
||||||
|
{
|
||||||
|
_translationUnit->tokenize();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::isParsed() const
|
||||||
|
{
|
||||||
|
return _translationUnit->isParsed();
|
||||||
|
}
|
||||||
|
|
||||||
bool Document::parse(ParseMode mode)
|
bool Document::parse(ParseMode mode)
|
||||||
{
|
{
|
||||||
TranslationUnit::ParseMode m = TranslationUnit::ParseTranlationUnit;
|
TranslationUnit::ParseMode m = TranslationUnit::ParseTranlationUnit;
|
||||||
@@ -295,6 +311,11 @@ void Document::check()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Document::releaseSource()
|
||||||
|
{
|
||||||
|
_source.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void Document::releaseTranslationUnit()
|
void Document::releaseTranslationUnit()
|
||||||
{
|
{
|
||||||
_translationUnit->release();
|
_translationUnit->release();
|
||||||
|
@@ -96,8 +96,15 @@ public:
|
|||||||
ParseStatement
|
ParseStatement
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool isTokenized() const;
|
||||||
|
void tokenize();
|
||||||
|
|
||||||
|
bool isParsed() const;
|
||||||
bool parse(ParseMode mode = ParseTranlationUnit);
|
bool parse(ParseMode mode = ParseTranlationUnit);
|
||||||
|
|
||||||
void check();
|
void check();
|
||||||
|
|
||||||
|
void releaseSource();
|
||||||
void releaseTranslationUnit();
|
void releaseTranslationUnit();
|
||||||
|
|
||||||
static Ptr create(const QString &fileName);
|
static Ptr create(const QString &fileName);
|
||||||
@@ -233,6 +240,7 @@ private:
|
|||||||
QList<Macro> _definedMacros;
|
QList<Macro> _definedMacros;
|
||||||
QList<Block> _skippedBlocks;
|
QList<Block> _skippedBlocks;
|
||||||
QList<MacroUse> _macroUses;
|
QList<MacroUse> _macroUses;
|
||||||
|
QByteArray _source;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT Snapshot: public QMap<QString, Document::Ptr>
|
class CPLUSPLUS_EXPORT Snapshot: public QMap<QString, Document::Ptr>
|
||||||
|
@@ -73,6 +73,7 @@
|
|||||||
#include <QtCore/QMutexLocker>
|
#include <QtCore/QMutexLocker>
|
||||||
#include <QtCore/QTime>
|
#include <QtCore/QTime>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
|
#include <QtConcurrentMap>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -171,8 +172,8 @@ public:
|
|||||||
void setProjectFiles(const QStringList &files);
|
void setProjectFiles(const QStringList &files);
|
||||||
void setTodo(const QStringList &files);
|
void setTodo(const QStringList &files);
|
||||||
|
|
||||||
void run(QString &fileName);
|
void run(const QString &fileName);
|
||||||
void operator()(QString &fileName);
|
void run_helper(const QString &fileName, QList<Document::Ptr> *documents);
|
||||||
|
|
||||||
void resetEnvironment();
|
void resetEnvironment();
|
||||||
|
|
||||||
@@ -211,8 +212,9 @@ private:
|
|||||||
QStringList m_projectFiles;
|
QStringList m_projectFiles;
|
||||||
QStringList m_frameworkPaths;
|
QStringList m_frameworkPaths;
|
||||||
QSet<QString> m_included;
|
QSet<QString> m_included;
|
||||||
CPlusPlus::Document::Ptr m_currentDoc;
|
Document::Ptr m_currentDoc;
|
||||||
QSet<QString> m_todo;
|
QSet<QString> m_todo;
|
||||||
|
QList<Document::Ptr> *m_documents;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -221,7 +223,8 @@ private:
|
|||||||
CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager)
|
CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager)
|
||||||
: snapshot(modelManager->snapshot()),
|
: snapshot(modelManager->snapshot()),
|
||||||
m_modelManager(modelManager),
|
m_modelManager(modelManager),
|
||||||
m_proc(this, env)
|
m_proc(this, env),
|
||||||
|
m_documents(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void CppPreprocessor::setWorkingCopy(const QMap<QString, QByteArray> &workingCopy)
|
void CppPreprocessor::setWorkingCopy(const QMap<QString, QByteArray> &workingCopy)
|
||||||
@@ -239,15 +242,70 @@ void CppPreprocessor::setProjectFiles(const QStringList &files)
|
|||||||
void CppPreprocessor::setTodo(const QStringList &files)
|
void CppPreprocessor::setTodo(const QStringList &files)
|
||||||
{ m_todo = QSet<QString>::fromList(files); }
|
{ m_todo = QSet<QString>::fromList(files); }
|
||||||
|
|
||||||
void CppPreprocessor::run(QString &fileName)
|
|
||||||
{ sourceNeeded(fileName, IncludeGlobal, /*line = */ 0); }
|
namespace {
|
||||||
|
|
||||||
|
class Process
|
||||||
|
{
|
||||||
|
QPointer<CppModelManager> _modelManager;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Process(QPointer<CppModelManager> modelManager)
|
||||||
|
: _modelManager(modelManager)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void operator()(Document::Ptr doc)
|
||||||
|
{
|
||||||
|
doc->parse();
|
||||||
|
doc->check();
|
||||||
|
doc->releaseTranslationUnit();
|
||||||
|
|
||||||
|
if (_modelManager)
|
||||||
|
_modelManager->emitDocumentUpdated(doc); // ### TODO: compress
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of anonymous namespace
|
||||||
|
|
||||||
|
// #define QTCREATOR_WITH_PARALLEL_INDEXER
|
||||||
|
|
||||||
|
void CppPreprocessor::run(const QString &fileName)
|
||||||
|
{
|
||||||
|
QList<Document::Ptr> documents;
|
||||||
|
run_helper(fileName, &documents);
|
||||||
|
|
||||||
|
#ifdef QTCREATOR_WITH_PARALLEL_INDEXER
|
||||||
|
QFuture<void> future = QtConcurrent::map(documents, Process(m_modelManager));
|
||||||
|
future.waitForFinished();
|
||||||
|
|
||||||
|
#else
|
||||||
|
foreach (Document::Ptr doc, documents) {
|
||||||
|
doc->parse();
|
||||||
|
doc->check();
|
||||||
|
|
||||||
|
doc->releaseTranslationUnit();
|
||||||
|
|
||||||
|
if (m_modelManager)
|
||||||
|
m_modelManager->emitDocumentUpdated(doc); // ### TODO: compress
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppPreprocessor::run_helper(const QString &fileName,
|
||||||
|
QList<Document::Ptr> *documents)
|
||||||
|
{
|
||||||
|
QList<Document::Ptr> *previousDocuments = m_documents;
|
||||||
|
m_documents = documents;
|
||||||
|
|
||||||
|
QString absoluteFilePath = fileName;
|
||||||
|
sourceNeeded(absoluteFilePath, IncludeGlobal, /*line = */ 0);
|
||||||
|
|
||||||
|
m_documents = previousDocuments;
|
||||||
|
}
|
||||||
|
|
||||||
void CppPreprocessor::resetEnvironment()
|
void CppPreprocessor::resetEnvironment()
|
||||||
{ env.reset(); }
|
{ env.reset(); }
|
||||||
|
|
||||||
void CppPreprocessor::operator()(QString &fileName)
|
|
||||||
{ run(fileName); }
|
|
||||||
|
|
||||||
bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QByteArray *result)
|
bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QByteArray *result)
|
||||||
{
|
{
|
||||||
if (absoluteFilePath.isEmpty() || m_included.contains(absoluteFilePath)) {
|
if (absoluteFilePath.isEmpty() || m_included.contains(absoluteFilePath)) {
|
||||||
@@ -475,23 +533,15 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
|
|||||||
m_proc(fileName.toUtf8(), contents, &preprocessedCode);
|
m_proc(fileName.toUtf8(), contents, &preprocessedCode);
|
||||||
|
|
||||||
doc->setSource(preprocessedCode);
|
doc->setSource(preprocessedCode);
|
||||||
|
doc->tokenize();
|
||||||
|
doc->releaseSource();
|
||||||
|
|
||||||
doc->parse();
|
snapshot.insert(doc->fileName(), doc);
|
||||||
doc->check();
|
|
||||||
|
|
||||||
#if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU)
|
m_documents->append(doc);
|
||||||
DumpAST dump(m_currentDoc->control());
|
|
||||||
dump(m_currentDoc->translationUnit()->ast());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
doc->releaseTranslationUnit();
|
|
||||||
|
|
||||||
snapshot[fileName] = doc;
|
|
||||||
|
|
||||||
if (m_modelManager)
|
|
||||||
m_modelManager->emitDocumentUpdated(m_currentDoc); // ### TODO: compress
|
|
||||||
|
|
||||||
(void) switchDocument(previousDoc);
|
(void) switchDocument(previousDoc);
|
||||||
|
|
||||||
m_todo.remove(fileName);
|
m_todo.remove(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user