Commit e3bc84c4 authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

C++: Record also unresolved paths for includes

Change-Id: Id107b6c1f34f594c5a01502c156963c964235ed7
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 35a790fb
......@@ -341,15 +341,15 @@ QStringList Document::includedFiles() const
{
QStringList files;
foreach (const Include &i, _includes)
files.append(i.fileName());
files.append(i.resolvedFileName());
files.removeDuplicates();
return files;
}
// This assumes to be called with a QDir::cleanPath cleaned fileName.
void Document::addIncludeFile(const QString &fileName, unsigned line)
void Document::addIncludeFile(const Document::Include &include)
{
_includes.append(Include(fileName, line));
_includes.append(include);
}
void Document::appendMacro(const Macro &macro)
......
......@@ -33,6 +33,7 @@
#include "Macro.h"
#include <cplusplus/CPlusPlusForwardDeclarations.h>
#include <cplusplus/PreprocessorClient.h>
#include <QSharedPointer>
#include <QDateTime>
......@@ -75,9 +76,6 @@ public:
QString fileName() const;
QStringList includedFiles() const;
void addIncludeFile(const QString &fileName, unsigned line);
void appendMacro(const Macro &macro);
void addMacroUse(const Macro &macro, unsigned offset, unsigned length,
unsigned beginLine,
......@@ -233,22 +231,31 @@ public:
};
class Include {
QString _fileName;
QString _resolvedFileName;
QString _unresolvedFileName;
unsigned _line;
Client::IncludeType _type;
public:
Include(const QString &fileName, unsigned line)
: _fileName(fileName), _line(line)
Include(const QString &unresolvedFileName, const QString &resolvedFileName, unsigned line,
Client::IncludeType type)
: _resolvedFileName(resolvedFileName)
, _unresolvedFileName(unresolvedFileName)
, _line(line)
, _type(type)
{ }
QString fileName() const
{ return _fileName; }
QString resolvedFileName() const
{ return _resolvedFileName; }
QString unresolvedFileName() const
{ return _unresolvedFileName; }
unsigned line() const
{ return _line; }
bool resolved() const
{ return QFileInfo(_fileName).isAbsolute(); }
Client::IncludeType type() const
{ return _type; }
};
class MacroUse: public Block {
......@@ -302,6 +309,9 @@ public:
}
};
QStringList includedFiles() const;
void addIncludeFile(const Include &include);
QList<Include> includes() const
{ return _includes; }
......
......@@ -53,7 +53,7 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source)
mergeEnvironment(Preprocessor::configurationFileName);
foreach (const Document::Include &i, doc->includes())
mergeEnvironment(i.fileName());
mergeEnvironment(i.resolvedFileName());
}
const QByteArray preprocessed = _preproc.run(fileName, source);
......@@ -62,13 +62,13 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source)
return preprocessed;
}
void FastPreprocessor::sourceNeeded(unsigned line, const QString &fileName, IncludeType)
void FastPreprocessor::sourceNeeded(unsigned line, const QString &fileName,
IncludeType mode)
{
Q_ASSERT(_currentDoc);
// CHECKME: Is that cleanName needed?
QString cleanName = QDir::cleanPath(fileName);
_currentDoc->addIncludeFile(cleanName, line);
_currentDoc->addIncludeFile(Document::Include(fileName, cleanName, line, mode));
mergeEnvironment(fileName);
}
......@@ -79,7 +79,7 @@ void FastPreprocessor::mergeEnvironment(const QString &fileName)
if (Document::Ptr doc = _snapshot.document(fileName)) {
foreach (const Document::Include &i, doc->includes())
mergeEnvironment(i.fileName());
mergeEnvironment(i.resolvedFileName());
_env.addMacros(doc->definedMacros());
}
......
......@@ -57,7 +57,7 @@ public:
QByteArray run(Document::Ptr newDoc, const QString &source);
// CPlusPlus::Client
virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType);
virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType mode);
virtual void macroAdded(const Macro &);
......
......@@ -1364,7 +1364,7 @@ void CreateBindings::process(Document::Ptr doc)
_processed.insert(globalNamespace);
foreach (const Document::Include &i, doc->includes()) {
if (Document::Ptr incl = _snapshot.document(i.fileName()))
if (Document::Ptr incl = _snapshot.document(i.resolvedFileName()))
process(incl);
}
......
......@@ -50,7 +50,7 @@ void SnapshotSymbolVisitor::accept(Document::Ptr doc, QSet<QString> *processed)
processed->insert(doc->fileName());
foreach (const Document::Include &i, doc->includes()) {
if (Document::Ptr incl = _snapshot.document(i.fileName()))
if (Document::Ptr incl = _snapshot.document(i.resolvedFileName()))
accept(incl, processed);
}
......
......@@ -176,7 +176,7 @@ void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env,
processed->insert(doc->fileName());
foreach (const Document::Include &incl, doc->includes())
processEnvironment(m_snapshot.document(incl.fileName()), env, processed);
processEnvironment(m_snapshot.document(incl.resolvedFileName()), env, processed);
foreach (const Macro &macro, doc->definedMacros())
env->bind(macro);
......
......@@ -1398,7 +1398,8 @@ CPPEditorWidget::Link CPPEditorWidget::findMacroLink(const QByteArray &name,
const QList<Document::Include> includes = doc->includes();
for (int index = includes.size() - 1; index != -1; --index) {
const Document::Include &i = includes.at(index);
Link link = findMacroLink(name, snapshot.document(i.fileName()), snapshot, processed);
Link link = findMacroLink(name, snapshot.document(i.resolvedFileName()), snapshot,
processed);
if (link.hasValidTarget())
return link;
}
......@@ -1528,8 +1529,8 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, boo
if (tk.is(T_STRING_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL)) {
const unsigned lineno = cursor.blockNumber() + 1;
foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineno && incl.resolved()) {
link.targetFileName = incl.fileName();
if (incl.line() == lineno) {
link.targetFileName = incl.resolvedFileName();
link.linkTextStart = beginOfToken + 1;
link.linkTextEnd = endOfToken - 1;
return link;
......
......@@ -243,8 +243,8 @@ Unknown::Unknown(const QString &type) : type(type)
// CppInclude
CppInclude::CppInclude(const Document::Include &includeFile) :
path(QDir::toNativeSeparators(includeFile.fileName())),
fileName(QFileInfo(includeFile.fileName()).fileName())
path(QDir::toNativeSeparators(includeFile.resolvedFileName())),
fileName(QFileInfo(includeFile.resolvedFileName()).fileName())
{
helpCategory = TextEditor::HelpItem::Brief;
helpIdCandidates = QStringList(fileName);
......
......@@ -1754,9 +1754,10 @@ public:
if (!includes.isEmpty()) {
QHash<QString, unsigned> includePositions;
foreach (const Document::Include &include, includes) {
if (include.fileName().endsWith(QLatin1String(".moc")))
const QString fileName = include.unresolvedFileName();
if (fileName.endsWith(QLatin1String(".moc")))
continue;
includePositions.insert(include.fileName(), include.line());
includePositions.insert(fileName, include.line());
}
if (!includePositions.isEmpty()) {
......
......@@ -100,7 +100,7 @@ protected:
processed->insert(doc->globalNamespace());
foreach (const Document::Include &i, doc->includes())
process(_snapshot.document(i.fileName()), processed);
process(_snapshot.document(i.resolvedFileName()), processed);
_mainDocument = (doc == _doc); // ### improve
accept(doc->globalNamespace());
......
......@@ -439,7 +439,8 @@ void CppToolsPlugin::test_codegen_definition_first_member()
QCOMPARE(src->globalSymbolCount(), 1U);
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(src->fileName(), 1);
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
......@@ -508,7 +509,8 @@ void CppToolsPlugin::test_codegen_definition_last_member()
QCOMPARE(src->globalSymbolCount(), 1U);
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(src->fileName(), 1);
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
......@@ -583,7 +585,8 @@ void CppToolsPlugin::test_codegen_definition_middle_member()
QCOMPARE(src->globalSymbolCount(), 1U);
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(src->fileName(), 1);
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
......
......@@ -1692,7 +1692,7 @@ void CppCompletionAssistProcessor::addMacros_helper(const CPlusPlus::Snapshot &s
processed->insert(doc->fileName());
foreach (const Document::Include &i, doc->includes()) {
addMacros_helper(snapshot, i.fileName(), processed, definedMacros);
addMacros_helper(snapshot, i.resolvedFileName(), processed, definedMacros);
}
foreach (const Macro &macro, doc->definedMacros()) {
......
......@@ -331,7 +331,7 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc)
m_processed.insert(fn);
foreach (const Document::Include &incl, doc->includes()) {
QString includedFile = incl.fileName();
QString includedFile = incl.resolvedFileName();
if (Document::Ptr includedDoc = m_snapshot.document(includedFile))
mergeEnvironment(includedDoc);
......@@ -364,7 +364,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu
QString absoluteFileName = resolveFile(fileName, type);
absoluteFileName = QDir::cleanPath(absoluteFileName);
if (m_currentDoc && !absoluteFileName.isEmpty())
m_currentDoc->addIncludeFile(absoluteFileName, line);
m_currentDoc->addIncludeFile(Document::Include(fileName, absoluteFileName, line, type));
if (m_included.contains(absoluteFileName))
return; // we've already seen this file.
if (absoluteFileName != modelManager()->configurationFileName())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment