CPlusPlus: Proliferate FilePath use

The starts with CppDocument::filePath(), plus a bit of the fallout

This is one patch of potentially many. It is hard to draw the
line where to stop this kind of chunk, this here converts a few
additional functions for which including it in the patch looked
like less churn than without.

Converting is mostly fromString/toString, with a few exceptions
for "already seem" like caches, that use cheaper "path()" to
avoid likely performance regressions (on Windows FilePath
comparison is currently case-insenstive, and more expensive).

There should be no difference for local operation with this patch.

Change-Id: I7b35f98a0a6f0bfed4ea0f8f987faf586f7a8f2b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-21 16:48:50 +01:00
parent 822e2a224a
commit fa1adf4d40
69 changed files with 351 additions and 313 deletions

View File

@@ -205,7 +205,7 @@ public:
const QString fileName = QString::fromUtf8(fileId->chars(), fileId->size());
if (fileName != doc->fileName())
if (fileName != doc->filePath().pathView())
return;
const QString message = QString::vasprintf(format, ap);
@@ -220,7 +220,7 @@ public:
}
#endif // DO_NOT_DUMP_ALL_PARSER_ERRORS
Document::DiagnosticMessage m(convertLevel(level), doc->fileName(),
Document::DiagnosticMessage m(convertLevel(level), doc->filePath(),
line, column, message);
messages->append(m);
}
@@ -244,7 +244,7 @@ private:
Document::Document(const QString &fileName)
: _fileName(QDir::cleanPath(fileName)),
: _filePath(Utils::FilePath::fromUserInput(QDir::cleanPath(fileName))),
_globalNamespace(nullptr),
_revision(0),
_editorRevision(0),
@@ -652,7 +652,7 @@ bool Document::DiagnosticMessage::operator==(const Document::DiagnosticMessage &
_column == other._column &&
_length == other._length &&
_level == other._level &&
_fileName == other._fileName &&
_filePath == other._filePath &&
_text == other._text;
}
@@ -697,7 +697,7 @@ bool Snapshot::contains(const Utils::FilePath &fileName) const
void Snapshot::insert(Document::Ptr doc)
{
if (doc) {
_documents.insert(Utils::FilePath::fromString(doc->fileName()), doc);
_documents.insert(doc->filePath(), doc);
m_deps.files.clear(); // Will trigger re-build when accessed.
}
}
@@ -848,7 +848,7 @@ Snapshot Snapshot::simplified(Document::Ptr doc) const
if (doc) {
snapshot.insert(doc);
const QSet<QString> fileNames = allIncludesForDocument(doc->fileName());
const QSet<QString> fileNames = allIncludesForDocument(doc->filePath().toString());
for (const QString &fileName : fileNames)
if (Document::Ptr inc = document(fileName))
snapshot.insert(inc);

View File

@@ -49,7 +49,7 @@ public:
const QDateTime &lastModified() const { return _lastModified; }
void setLastModified(const QDateTime &lastModified);
const QString &fileName() const { return _fileName; }
const Utils::FilePath &filePath() const { return _filePath; }
void appendMacro(const Macro &macro);
void addMacroUse(const Macro &macro,
@@ -125,13 +125,13 @@ public:
};
public:
DiagnosticMessage(int level, const QString &fileName,
DiagnosticMessage(int level, const Utils::FilePath &filePath,
int line, int column,
const QString &text,
int length = 0)
: _level(level),
_line(line),
_fileName(fileName),
_filePath(filePath),
_column(column),
_length(length),
_text(text)
@@ -149,8 +149,8 @@ public:
bool isFatal() const
{ return _level == Fatal; }
const QString &fileName() const
{ return _fileName; }
const Utils::FilePath &filePath() const
{ return _filePath; }
int line() const
{ return _line; }
@@ -170,7 +170,7 @@ public:
private:
int _level;
int _line;
QString _fileName;
Utils::FilePath _filePath;
int _column;
int _length;
QString _text;
@@ -334,7 +334,7 @@ public:
{ return static_cast<CheckMode>(_checkMode); }
private:
QString _fileName;
Utils::FilePath _filePath;
Control *_control;
TranslationUnit *_translationUnit;
Namespace *_globalNamespace;

View File

@@ -8,6 +8,7 @@
#include <QDir>
using namespace Utils;
using namespace CPlusPlus;
FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
@@ -23,12 +24,12 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc,
std::swap(newDoc, _currentDoc);
_addIncludesToCurrentDoc = _currentDoc->resolvedIncludes().isEmpty()
&& _currentDoc->unresolvedIncludes().isEmpty();
const QString fileName = _currentDoc->fileName();
const FilePath filePath = _currentDoc->filePath();
_preproc.setExpandFunctionlikeMacros(false);
_preproc.setKeepComments(true);
if (Document::Ptr doc = _snapshot.document(fileName)) {
_merged.insert(fileName);
if (Document::Ptr doc = _snapshot.document(filePath)) {
_merged.insert(filePath.toString());
for (Snapshot::const_iterator i = _snapshot.begin(), ei = _snapshot.end(); i != ei; ++i) {
if (isInjectedFile(i.key().toString()))
@@ -43,7 +44,7 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc,
_env.addMacros(_currentDoc->definedMacros());
}
const QByteArray preprocessed = _preproc.run(fileName, source);
const QByteArray preprocessed = _preproc.run(filePath, source);
// qDebug("FastPreprocessor::run for %s produced [[%s]]", fileName.toUtf8().constData(), preprocessed.constData());
std::swap(newDoc, _currentDoc);
return preprocessed;

View File

@@ -118,7 +118,7 @@ void FindUsages::reportResult(unsigned tokenIndex, const QList<LookupItem> &cand
lineText = matchingLine(tk);
const int len = tk.utf16chars();
const Usage u(Utils::FilePath::fromString(_doc->fileName()), lineText,
const Usage u(_doc->filePath(), lineText,
getContainingFunction(line, col), getTags(line, col, tokenIndex),
line, col - 1, len);
_usages.append(u);

View File

@@ -20,8 +20,8 @@ void SnapshotSymbolVisitor::accept(Document::Ptr doc)
void SnapshotSymbolVisitor::accept(Document::Ptr doc, QSet<QString> *processed)
{
if (doc && doc->globalNamespace() && ! processed->contains(doc->fileName())) {
processed->insert(doc->fileName());
if (doc && doc->globalNamespace() && ! processed->contains(doc->filePath().path())) {
processed->insert(doc->filePath().path());
const QList<Document::Include> includes = doc->resolvedIncludes();
for (const Document::Include &i : includes) {

View File

@@ -13,7 +13,7 @@
#include <QSet>
using namespace CPlusPlus;
namespace CPlusPlus {
TypeOfExpression::TypeOfExpression():
m_ast(nullptr),
@@ -132,8 +132,8 @@ ExpressionAST *TypeOfExpression::expressionAST() const
void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env,
QSet<QString> *processed) const
{
if (doc && ! processed->contains(doc->fileName())) {
processed->insert(doc->fileName());
if (doc && ! processed->contains(doc->filePath().path())) {
processed->insert(doc->filePath().path());
const QList<Document::Include> includes = doc->resolvedIncludes();
for (const Document::Include &incl : includes)
@@ -158,11 +158,9 @@ QByteArray TypeOfExpression::preprocessedExpression(const QByteArray &utf8code)
}
Preprocessor preproc(nullptr, m_environment.data());
return preproc.run(QLatin1String("<expression>"), utf8code);
return preproc.run(Utils::FilePath::fromParts({}, {}, u"<expression>"), utf8code);
}
namespace CPlusPlus {
ExpressionAST *extractExpressionAST(Document::Ptr doc)
{
if (! doc->translationUnit()->ast())

View File

@@ -31,6 +31,7 @@
#include <cplusplus/cppassert.h>
#include <utils/executeondestruction.h>
#include <utils/filepath.h>
#include <utils/scopedswap.h>
#include <QDebug>
@@ -235,7 +236,6 @@ struct Value
};
} // namespace Internal
} // namespace CPlusPlus
using namespace CPlusPlus;
using namespace CPlusPlus::Internal;
@@ -251,7 +251,7 @@ Macro *macroDefinition(const ByteArrayRef &name,
unsigned bytesOffset,
unsigned utf16charsOffset,
unsigned line,
Environment *env,
CPlusPlus::Environment *env,
Client *client)
{
Macro *m = env->resolve(name);
@@ -320,7 +320,7 @@ class ExpressionEvaluator
void operator = (const ExpressionEvaluator &other);
public:
ExpressionEvaluator(Client *client, Environment *env)
ExpressionEvaluator(Client *client, CPlusPlus::Environment *env)
: client(client), env(env), _lex(nullptr)
{ }
@@ -726,6 +726,14 @@ Preprocessor::Preprocessor(Client *client, Environment *env)
{
}
QByteArray Preprocessor::run(const Utils::FilePath &filePath,
const QByteArray &source,
bool noLines,
bool markGeneratedTokens)
{
return run(filePath.toString(), source, noLines, markGeneratedTokens);
}
QByteArray Preprocessor::run(const QString &fileName,
const QByteArray &source,
bool noLines,
@@ -2158,3 +2166,5 @@ void Preprocessor::maybeStartOutputLine()
if (*ch == '\\')
buffer.append('\n');
}
} // namespace CPlusPlus

View File

@@ -36,6 +36,8 @@
#include <functional>
namespace Utils { class FilePath; }
namespace CPlusPlus {
class Environment;
@@ -57,6 +59,8 @@ public:
public:
Preprocessor(Client *client, Environment *env);
QByteArray run(const Utils::FilePath &filePath, const QByteArray &source,
bool noLines = false, bool markGeneratedTokens = true);
QByteArray run(const QString &filename, const QByteArray &source,
bool noLines = false, bool markGeneratedTokens = true);