aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-11-21 16:48:50 +0100
committerhjk <hjk@qt.io>2022-11-22 15:30:00 +0000
commitfa1adf4d4001207902a5572b39da4f1cbc8752f1 (patch)
treeff9cbc1c951ab862f03902d38fc4495c3e1a3ae9 /src/libs
parent822e2a224a283581b38948d4626f873c6b38c044 (diff)
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>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/cplusplus/CppDocument.cpp12
-rw-r--r--src/libs/cplusplus/CppDocument.h14
-rw-r--r--src/libs/cplusplus/FastPreprocessor.cpp9
-rw-r--r--src/libs/cplusplus/FindUsages.cpp2
-rw-r--r--src/libs/cplusplus/SnapshotSymbolVisitor.cpp4
-rw-r--r--src/libs/cplusplus/TypeOfExpression.cpp10
-rw-r--r--src/libs/cplusplus/pp-engine.cpp16
-rw-r--r--src/libs/cplusplus/pp-engine.h4
-rw-r--r--src/libs/qmljs/qmljsfindexportedcpptypes.cpp11
-rw-r--r--src/libs/qmljs/qmljsmodelmanagerinterface.cpp16
10 files changed, 56 insertions, 42 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index 12ce8ea0cd..6362bf0659 100644
--- a/src/libs/cplusplus/CppDocument.cpp
+++ b/src/libs/cplusplus/CppDocument.cpp
@@ -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);
diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h
index c3ee363f26..fd98098763 100644
--- a/src/libs/cplusplus/CppDocument.h
+++ b/src/libs/cplusplus/CppDocument.h
@@ -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;
diff --git a/src/libs/cplusplus/FastPreprocessor.cpp b/src/libs/cplusplus/FastPreprocessor.cpp
index fb89ed26bf..607dd55364 100644
--- a/src/libs/cplusplus/FastPreprocessor.cpp
+++ b/src/libs/cplusplus/FastPreprocessor.cpp
@@ -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;
diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp
index 6e1731ca11..4928c4f771 100644
--- a/src/libs/cplusplus/FindUsages.cpp
+++ b/src/libs/cplusplus/FindUsages.cpp
@@ -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);
diff --git a/src/libs/cplusplus/SnapshotSymbolVisitor.cpp b/src/libs/cplusplus/SnapshotSymbolVisitor.cpp
index 0c459aa373..4692c25108 100644
--- a/src/libs/cplusplus/SnapshotSymbolVisitor.cpp
+++ b/src/libs/cplusplus/SnapshotSymbolVisitor.cpp
@@ -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) {
diff --git a/src/libs/cplusplus/TypeOfExpression.cpp b/src/libs/cplusplus/TypeOfExpression.cpp
index 88efe41695..2453ad829f 100644
--- a/src/libs/cplusplus/TypeOfExpression.cpp
+++ b/src/libs/cplusplus/TypeOfExpression.cpp
@@ -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())
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index 836e2ad05b..58fa33b0a9 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -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
diff --git a/src/libs/cplusplus/pp-engine.h b/src/libs/cplusplus/pp-engine.h
index 4cbda7162c..f5c2474ffc 100644
--- a/src/libs/cplusplus/pp-engine.h
+++ b/src/libs/cplusplus/pp-engine.h
@@ -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);
diff --git a/src/libs/qmljs/qmljsfindexportedcpptypes.cpp b/src/libs/qmljs/qmljsfindexportedcpptypes.cpp
index 2e07d91f22..427a73ef3f 100644
--- a/src/libs/qmljs/qmljsfindexportedcpptypes.cpp
+++ b/src/libs/qmljs/qmljsfindexportedcpptypes.cpp
@@ -248,7 +248,7 @@ protected:
translationUnit()->getTokenStartPosition(nameExp->firstToken(), &line, &column);
_messages += Document::DiagnosticMessage(
Document::DiagnosticMessage::Warning,
- _doc->fileName(),
+ _doc->filePath(),
line, column,
QmlJS::FindExportedCppTypes::tr(
"The type will only be available in the QML editors when the type name is a string literal."));
@@ -309,7 +309,7 @@ protected:
translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column);
_messages += Document::DiagnosticMessage(
Document::DiagnosticMessage::Warning,
- _doc->fileName(),
+ _doc->filePath(),
line, column,
QmlJS::FindExportedCppTypes::tr(
"The module URI cannot be determined by static analysis. The type will not be available\n"
@@ -491,7 +491,7 @@ protected:
translationUnit()->getTokenStartPosition(ast->expression_list->value->firstToken(), &line, &column);
_messages += Document::DiagnosticMessage(
Document::DiagnosticMessage::Warning,
- _doc->fileName(),
+ _doc->filePath(),
line, column,
QmlJS::FindExportedCppTypes::tr(
"must be a string literal to be available in the QML editor"));
@@ -840,7 +840,7 @@ QStringList FindExportedCppTypes::operator()(const CPlusPlus::Document::Ptr &doc
FindExportsVisitor finder(document);
finder();
static const QString kindKey = QLatin1String("QmlJSTools.ExportedQmlTypesDiagnostic");
- CppModelManagerBase::trySetExtraDiagnostics(document->fileName(), kindKey,
+ CppModelManagerBase::trySetExtraDiagnostics(document->filePath().toString(), kindKey,
finder.messages());
// if nothing was found, done
@@ -852,7 +852,8 @@ QStringList FindExportedCppTypes::operator()(const CPlusPlus::Document::Ptr &doc
// context properties need lookup inside function scope, and thus require a full check
CPlusPlus::Document::Ptr localDoc = document;
if (document->checkMode() != CPlusPlus::Document::FullCheck && !contextPropertyDescriptions.isEmpty()) {
- localDoc = m_snapshot.documentFromSource(document->utf8Source(), document->fileName());
+ localDoc = m_snapshot.documentFromSource(document->utf8Source(),
+ document->filePath().toString());
localDoc->check();
}
diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
index 70eebf6faf..71bd55119b 100644
--- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
+++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
@@ -1350,10 +1350,10 @@ void ModelManagerInterface::maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document
void ModelManagerInterface::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan)
{
- QPair<CPlusPlus::Document::Ptr, bool> prev = m_queuedCppDocuments.value(doc->fileName());
+ QPair<CPlusPlus::Document::Ptr, bool> prev = m_queuedCppDocuments.value(doc->filePath().path());
if (prev.first && prev.second)
prev.first->releaseSourceAndAST();
- m_queuedCppDocuments.insert(doc->fileName(), {doc, scan});
+ m_queuedCppDocuments.insert(doc->filePath().path(), {doc, scan});
m_updateCppQmlTypesTimer->start();
}
@@ -1439,13 +1439,13 @@ void ModelManagerInterface::updateCppQmlTypes(
CPlusPlus::Document::Ptr doc = pair.first;
const bool scan = pair.second;
- const QString fileName = doc->fileName();
+ const FilePath filePath = doc->filePath();
if (!scan) {
- hasNewInfo = newData.remove(fileName) || hasNewInfo;
- const auto savedDocs = newDeclarations.value(fileName);
+ hasNewInfo = newData.remove(filePath.path()) || hasNewInfo;
+ const auto savedDocs = newDeclarations.value(filePath.path());
for (const CPlusPlus::Document::Ptr &savedDoc : savedDocs) {
finder(savedDoc);
- hasNewInfo = rescanExports(savedDoc->fileName(), finder, newData) || hasNewInfo;
+ hasNewInfo = rescanExports(savedDoc->filePath().path(), finder, newData) || hasNewInfo;
}
continue;
}
@@ -1453,7 +1453,7 @@ void ModelManagerInterface::updateCppQmlTypes(
for (auto it = newDeclarations.begin(), end = newDeclarations.end(); it != end;) {
for (auto docIt = it->begin(), endDocIt = it->end(); docIt != endDocIt;) {
const CPlusPlus::Document::Ptr &savedDoc = *docIt;
- if (savedDoc->fileName() == fileName) {
+ if (savedDoc->filePath() == filePath) {
savedDoc->releaseSourceAndAST();
it->erase(docIt);
break;
@@ -1472,7 +1472,7 @@ void ModelManagerInterface::updateCppQmlTypes(
doc->keepSourceAndAST(); // keep for later reparsing when dependent doc changes
}
- hasNewInfo = rescanExports(fileName, finder, newData) || hasNewInfo;
+ hasNewInfo = rescanExports(filePath.path(), finder, newData) || hasNewInfo;
doc->releaseSourceAndAST();
}