forked from qt-creator/qt-creator
CPlusPlus: Use FilePath for resolved include paths
... and fix fallout. Change-Id: I66886e91ff476eff15db51cc024a8021e952d44d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -299,11 +299,11 @@ void Document::setLastModified(const QDateTime &lastModified)
|
||||
|
||||
FilePaths Document::includedFiles() const
|
||||
{
|
||||
QStringList files;
|
||||
FilePaths files;
|
||||
for (const Include &i : std::as_const(_resolvedIncludes))
|
||||
files.append(i.resolvedFileName());
|
||||
files.removeDuplicates();
|
||||
return transform(files, &FilePath::fromString);
|
||||
FilePath::removeDuplicates(files);
|
||||
return files;
|
||||
}
|
||||
|
||||
// This assumes to be called with a QDir::cleanPath cleaned fileName.
|
||||
@@ -786,13 +786,13 @@ QSet<FilePath> Snapshot::allIncludesForDocument(const FilePath &filePath) const
|
||||
}
|
||||
|
||||
QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument(
|
||||
const QString &fileNameOrPath) const
|
||||
const FilePath &fileNameOrPath) const
|
||||
{
|
||||
const bool matchFullPath = FilePath::fromString(fileNameOrPath).isAbsolutePath();
|
||||
const bool matchFullPath = fileNameOrPath.isAbsolutePath();
|
||||
const auto isMatch = [&](const Document::Include &include) {
|
||||
if (matchFullPath)
|
||||
return include.resolvedFileName() == fileNameOrPath;
|
||||
return FilePath::fromString(include.resolvedFileName()).fileName() == fileNameOrPath;
|
||||
return include.resolvedFileName().fileName() == fileNameOrPath.fileName();
|
||||
};
|
||||
QList<IncludeLocation> result;
|
||||
for (const_iterator cit = begin(), citEnd = end(); cit != citEnd; ++cit) {
|
||||
@@ -807,7 +807,7 @@ QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument(
|
||||
}
|
||||
if (!matchFullPath && !foundMatch) {
|
||||
for (const auto &includeFile : cit.value()->unresolvedIncludes()) {
|
||||
if (includeFile.unresolvedFileName() == fileNameOrPath)
|
||||
if (includeFile.unresolvedFileName() == fileNameOrPath.path())
|
||||
result.push_back({doc, includeFile.line()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,13 +218,13 @@ public:
|
||||
};
|
||||
|
||||
class Include {
|
||||
QString _resolvedFileName;
|
||||
Utils::FilePath _resolvedFileName;
|
||||
QString _unresolvedFileName;
|
||||
int _line;
|
||||
Client::IncludeType _type;
|
||||
|
||||
public:
|
||||
Include(const QString &unresolvedFileName, const QString &resolvedFileName, int line,
|
||||
Include(const QString &unresolvedFileName, const Utils::FilePath &resolvedFileName, int line,
|
||||
Client::IncludeType type)
|
||||
: _resolvedFileName(resolvedFileName)
|
||||
, _unresolvedFileName(unresolvedFileName)
|
||||
@@ -232,7 +232,7 @@ public:
|
||||
, _type(type)
|
||||
{ }
|
||||
|
||||
const QString &resolvedFileName() const
|
||||
const Utils::FilePath &resolvedFileName() const
|
||||
{ return _resolvedFileName; }
|
||||
|
||||
const QString &unresolvedFileName() const
|
||||
@@ -404,7 +404,7 @@ public:
|
||||
|
||||
QSet<Utils::FilePath> allIncludesForDocument(const Utils::FilePath &filePath) const;
|
||||
|
||||
QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const;
|
||||
QList<IncludeLocation> includeLocationsOfDocument(const Utils::FilePath &fileNameOrPath) const;
|
||||
|
||||
Utils::FilePaths filesDependingOn(const Utils::FilePath &filePath) const;
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc,
|
||||
_preproc.setKeepComments(true);
|
||||
|
||||
if (Document::Ptr doc = _snapshot.document(filePath)) {
|
||||
_merged.insert(filePath.toString());
|
||||
_merged.insert(filePath);
|
||||
|
||||
for (Snapshot::const_iterator i = _snapshot.begin(), ei = _snapshot.end(); i != ei; ++i) {
|
||||
if (isInjectedFile(i.key().toString()))
|
||||
mergeEnvironment(i.key().toString());
|
||||
mergeEnvironment(i.key());
|
||||
}
|
||||
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
@@ -55,20 +55,21 @@ void FastPreprocessor::sourceNeeded(int line, const QString &fileName, IncludeTy
|
||||
{
|
||||
Q_UNUSED(initialIncludes)
|
||||
Q_ASSERT(_currentDoc);
|
||||
FilePath filePath = FilePath::fromString(fileName);
|
||||
if (_addIncludesToCurrentDoc) {
|
||||
// CHECKME: Is that cleanName needed?
|
||||
const QString cleanName = QDir::cleanPath(fileName);
|
||||
_currentDoc->addIncludeFile(Document::Include(fileName, cleanName, line, mode));
|
||||
// CHECKME: Is that cleanPath needed?
|
||||
const FilePath cleanPath = filePath.cleanPath();
|
||||
_currentDoc->addIncludeFile(Document::Include(fileName, cleanPath, line, mode));
|
||||
}
|
||||
mergeEnvironment(fileName);
|
||||
mergeEnvironment(filePath);
|
||||
}
|
||||
|
||||
void FastPreprocessor::mergeEnvironment(const QString &fileName)
|
||||
void FastPreprocessor::mergeEnvironment(const FilePath &filePath)
|
||||
{
|
||||
if (! _merged.contains(fileName)) {
|
||||
_merged.insert(fileName);
|
||||
if (! _merged.contains(filePath)) {
|
||||
_merged.insert(filePath);
|
||||
|
||||
if (Document::Ptr doc = _snapshot.document(fileName)) {
|
||||
if (Document::Ptr doc = _snapshot.document(filePath)) {
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &i : includes)
|
||||
mergeEnvironment(i.resolvedFileName());
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PreprocessorClient.h"
|
||||
#include "CppDocument.h"
|
||||
#include "pp.h"
|
||||
#include "PreprocessorClient.h"
|
||||
#include "PreprocessorEnvironment.h"
|
||||
#include "pp-engine.h"
|
||||
|
||||
#include <cplusplus/Control.h>
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
@@ -19,11 +22,11 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client
|
||||
Environment _env;
|
||||
Snapshot _snapshot;
|
||||
Preprocessor _preproc;
|
||||
QSet<QString> _merged;
|
||||
QSet<Utils::FilePath> _merged;
|
||||
Document::Ptr _currentDoc;
|
||||
bool _addIncludesToCurrentDoc;
|
||||
|
||||
void mergeEnvironment(const QString &fileName);
|
||||
void mergeEnvironment(const Utils::FilePath &filePath);
|
||||
|
||||
public:
|
||||
FastPreprocessor(const Snapshot &snapshot);
|
||||
|
||||
Reference in New Issue
Block a user