forked from qt-creator/qt-creator
CppTools: Auto-include pre-compiled headers
So far the pre-compiled headers were processed (thus defines from those headers were visible), but the actual includes for the documents were not added, which is necessary for lookup/completion. Note that this will be only done if pre-compiled headers are not ignored (Options > C++ > Code Model > [] Ignore pre-compiled headers). Change-Id: I54a8e6b00597af164d958e3e9f2a1075ea187788 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -873,7 +875,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
|
||||
}
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
|
||||
void CppToolsPlugin::test_modelmanager_precompiled_headers()
|
||||
{
|
||||
ModelManagerTestHelper helper;
|
||||
|
||||
@@ -922,14 +924,16 @@ void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
|
||||
|
||||
struct Data {
|
||||
QString firstDeclarationName;
|
||||
QString firstClassInPchFile;
|
||||
QString fileName;
|
||||
} d[] = {
|
||||
{ _("one"), main1File },
|
||||
{ _("two"), main2File }
|
||||
{ _("one"), _("ClassInPch1"), main1File },
|
||||
{ _("two"), _("ClassInPch2"), main2File }
|
||||
};
|
||||
const int size = sizeof(d) / sizeof(d[0]);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
const QString firstDeclarationName = d[i].firstDeclarationName;
|
||||
const QByteArray firstClassInPchFile = d[i].firstClassInPchFile.toUtf8();
|
||||
const QString fileName = d[i].fileName;
|
||||
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
|
||||
@@ -943,11 +947,22 @@ void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
|
||||
while (sup->lastSemanticInfoDocument().isNull())
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
sup->snapshotUpdater()->setUsePrecompiledHeaders(true);
|
||||
sup->snapshotUpdater()->update(mm->workingCopy());
|
||||
const QSharedPointer<SnapshotUpdater> updater = sup->snapshotUpdater();
|
||||
updater->setUsePrecompiledHeaders(true);
|
||||
updater->update(mm->workingCopy());
|
||||
|
||||
Document::Ptr doc = mm->document(fileName);
|
||||
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
|
||||
// Check if defines from pch are considered
|
||||
Document::Ptr document = mm->document(fileName);
|
||||
QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName);
|
||||
|
||||
// Check if declarations from pch are considered
|
||||
CPlusPlus::LookupContext context(document, updater->snapshot());
|
||||
const CPlusPlus::Identifier *identifier
|
||||
= document->control()->identifier(firstClassInPchFile.data());
|
||||
const QList<CPlusPlus::LookupItem> results = context.lookup(identifier,
|
||||
document->globalNamespace());
|
||||
QVERIFY(!results.isEmpty());
|
||||
QVERIFY(results.first().declaration()->type()->asClassType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,8 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
|
||||
}
|
||||
if (!m_editorDefines.isEmpty())
|
||||
sourceProcessor.run(editorDefinesFileName);
|
||||
sourceProcessor.run(m_fileInEditor);
|
||||
sourceProcessor.run(m_fileInEditor, m_usePrecompiledHeaders ? m_precompiledHeaders
|
||||
: QStringList());
|
||||
|
||||
m_snapshot = sourceProcessor.snapshot();
|
||||
Snapshot newSnapshot = m_snapshot.simplified(document());
|
||||
|
||||
@@ -148,9 +148,10 @@ void CppSourceProcessor::addFrameworkPath(const ProjectPart::HeaderPath &framewo
|
||||
void CppSourceProcessor::setTodo(const QStringList &files)
|
||||
{ m_todo = QSet<QString>::fromList(files); }
|
||||
|
||||
void CppSourceProcessor::run(const QString &fileName)
|
||||
void CppSourceProcessor::run(const QString &fileName,
|
||||
const QStringList &initialIncludes)
|
||||
{
|
||||
sourceNeeded(0, fileName, IncludeGlobal);
|
||||
sourceNeeded(0, fileName, IncludeGlobal, initialIncludes);
|
||||
}
|
||||
|
||||
void CppSourceProcessor::removeFromCache(const QString &fileName)
|
||||
@@ -377,7 +378,8 @@ void CppSourceProcessor::stopSkippingBlocks(unsigned utf16charsOffset)
|
||||
m_currentDoc->stopSkippingBlocks(utf16charsOffset);
|
||||
}
|
||||
|
||||
void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, IncludeType type)
|
||||
void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, IncludeType type,
|
||||
const QStringList &initialIncludes)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
@@ -417,6 +419,11 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
|
||||
Document::Ptr document = Document::create(absoluteFileName);
|
||||
document->setRevision(m_revision);
|
||||
document->setEditorRevision(editorRevision);
|
||||
foreach (const QString &include, initialIncludes) {
|
||||
m_included.insert(include);
|
||||
Document::Include inc(include, include, 0, IncludeLocal);
|
||||
document->addIncludeFile(inc);
|
||||
}
|
||||
const QFileInfo info(absoluteFileName);
|
||||
if (info.exists())
|
||||
document->setLastModified(info.lastModified());
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths);
|
||||
void setTodo(const QStringList &files);
|
||||
|
||||
void run(const QString &fileName);
|
||||
void run(const QString &fileName, const QStringList &initialIncludes = QStringList());
|
||||
void removeFromCache(const QString &fileName);
|
||||
void resetEnvironment();
|
||||
|
||||
@@ -80,7 +80,8 @@ private:
|
||||
void markAsIncludeGuard(const QByteArray ¯oName) QTC_OVERRIDE;
|
||||
void startSkippingBlocks(unsigned utf16charsOffset) QTC_OVERRIDE;
|
||||
void stopSkippingBlocks(unsigned utf16charsOffset) QTC_OVERRIDE;
|
||||
void sourceNeeded(unsigned line, const QString &fileName, IncludeType type) QTC_OVERRIDE;
|
||||
void sourceNeeded(unsigned line, const QString &fileName, IncludeType type,
|
||||
const QStringList &initialIncludes) QTC_OVERRIDE;
|
||||
|
||||
private:
|
||||
CPlusPlus::Snapshot m_snapshot;
|
||||
|
||||
@@ -146,8 +146,8 @@ private slots:
|
||||
void test_modelmanager_gc_if_last_cppeditor_closed();
|
||||
void test_modelmanager_dont_gc_opened_files();
|
||||
void test_modelmanager_defines_per_project();
|
||||
void test_modelmanager_defines_per_project_pch();
|
||||
void test_modelmanager_defines_per_editor();
|
||||
void test_modelmanager_precompiled_headers();
|
||||
|
||||
void test_cpplocatorfilters_CppLocatorFilter();
|
||||
void test_cpplocatorfilters_CppLocatorFilter_data();
|
||||
|
||||
Reference in New Issue
Block a user