CppEditor: Remove WorkingCopy::get(QString) overload

... and fix fallout.

Change-Id: I8fe67616f8f327428b1c166ae69ec34c2924ee9f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-11-23 17:33:36 +01:00
parent 9ceaf39929
commit 49d6456b66
9 changed files with 27 additions and 24 deletions

View File

@@ -87,7 +87,7 @@ void FastPreprocessor::macroAdded(const Macro &macro)
static const Macro revision(const Snapshot &s, const Macro &m)
{
if (Document::Ptr d = s.document(m.fileName())) {
if (Document::Ptr d = s.document(m.filePath())) {
Macro newMacro(m);
newMacro.setFileRevision(d->revision());
return newMacro;

View File

@@ -27,6 +27,8 @@
#include <cplusplus/CPlusPlusForwardDeclarations.h>
#include <utils/filepath.h>
#include <QByteArray>
#include <QVector>
#include <QString>
@@ -69,6 +71,9 @@ public:
const QString &fileName() const
{ return _fileName; }
Utils::FilePath filePath() const
{ return Utils::FilePath::fromString(_fileName); }
void setFileName(const QString &fileName)
{ _fileName = fileName; }

View File

@@ -2014,7 +2014,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk)
// the macro is a feature constraint(e.g. QT_NO_XXX)
if (checkUndefined && macroName.startsWith("QT_NO_")) {
if (macro->fileName() == configurationFileName().pathView()) {
if (macro->filePath() == configurationFileName()) {
// and it' defined in a pro file (e.g. DEFINES += QT_NO_QOBJECT)
value = false; // take the branch

View File

@@ -270,7 +270,7 @@ bool handleMacroCase(const Document::Ptr document,
const int length = macro->nameToQString().size();
// Macro definition
if (macro->fileName() == document->filePath().pathView())
if (macro->filePath() == document->filePath())
ranges->append(toRange(textCursor, macro->utf16CharOffset(), length));
// Other macro uses

View File

@@ -86,7 +86,7 @@ public:
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
helpIdCandidates = QStringList(macroName);
helpMark = macroName;
link = Utils::Link(Utils::FilePath::fromString(macro.fileName()), macro.line());
link = Utils::Link(macro.filePath(), macro.line());
tooltip = macro.toStringWithLineBreaks();
}
};

View File

@@ -706,8 +706,8 @@ static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
const CPlusPlus::Snapshot snapshot,
const CPlusPlus::Macro macro)
{
const Utils::FilePath sourceFile = Utils::FilePath::fromString(macro.fileName());
Utils::FilePaths files{sourceFile};
const FilePath sourceFile = macro.filePath();
FilePaths files{sourceFile};
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
future.setProgressRange(0, files.size());

View File

@@ -31,6 +31,7 @@
*/
using namespace CPlusPlus;
using namespace Utils;
using Message = Document::DiagnosticMessage;
@@ -81,7 +82,7 @@ inline const CPlusPlus::Macro revision(const WorkingCopy &workingCopy,
const CPlusPlus::Macro &macro)
{
CPlusPlus::Macro newMacro(macro);
newMacro.setFileRevision(workingCopy.get(macro.fileName()).second);
newMacro.setFileRevision(workingCopy.get(macro.filePath()).second);
return newMacro;
}
@@ -181,7 +182,7 @@ void CppSourceProcessor::resetEnvironment()
m_included.clear();
}
bool CppSourceProcessor::getFileContents(const QString &absoluteFilePath,
bool CppSourceProcessor::getFileContents(const FilePath &absoluteFilePath,
QByteArray *contents,
unsigned *revision) const
{
@@ -199,12 +200,12 @@ bool CppSourceProcessor::getFileContents(const QString &absoluteFilePath,
// Get from file
*revision = 0;
QString error;
if (Utils::TextFileFormat::readFileUTF8(Utils::FilePath::fromString(absoluteFilePath),
if (Utils::TextFileFormat::readFileUTF8(absoluteFilePath,
m_defaultCodec,
contents,
&error)
!= Utils::TextFileFormat::ReadSuccess) {
qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath),
qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath.toString()),
qPrintable(error));
return false;
}
@@ -410,8 +411,9 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
if (fileName.isEmpty())
return;
QString absoluteFileName = resolveFile(fileName, type);
absoluteFileName = QDir::cleanPath(absoluteFileName);
const QString absoluteFileName = QDir::cleanPath(resolveFile(fileName, type));
const FilePath absoluteFilePath = FilePath::fromString(absoluteFileName);
if (m_currentDoc) {
m_currentDoc->addIncludeFile(Document::Include(fileName, absoluteFileName, line, type));
if (absoluteFileName.isEmpty()) {
@@ -437,15 +439,15 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
// Otherwise get file contents
unsigned editorRevision = 0;
QByteArray contents;
const bool gotFileContents = getFileContents(absoluteFileName, &contents, &editorRevision);
const bool gotFileContents = getFileContents(absoluteFilePath, &contents, &editorRevision);
if (m_currentDoc && !gotFileContents) {
m_currentDoc->addDiagnosticMessage(messageNoFileContents(m_currentDoc, fileName, line));
return;
}
qCDebug(log) << "Parsing:" << absoluteFileName << "contents:" << contents.size() << "bytes";
qCDebug(log) << "Parsing:" << absoluteFilePath.toString() << "contents:" << contents.size() << "bytes";
Document::Ptr document = Document::create(Utils::FilePath::fromString(absoluteFileName));
Document::Ptr document = Document::create(absoluteFilePath);
document->setEditorRevision(editorRevision);
document->setLanguageFeatures(m_languageFeatures);
for (const QString &include : initialIncludes) {
@@ -457,8 +459,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
document->setLastModified(info.lastModified());
const Document::Ptr previousDocument = switchCurrentDocument(document);
const QByteArray preprocessedCode =
m_preprocess.run(Utils::FilePath::fromString(absoluteFileName), contents);
const QByteArray preprocessedCode = m_preprocess.run(absoluteFilePath, contents);
// {
// QByteArray b(preprocessedCode); b.replace("\n", "<<<\n");
// qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData());
@@ -466,7 +467,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
document->setFingerprint(generateFingerPrint(document->definedMacros(), preprocessedCode));
// Re-use document from global snapshot if possible
Document::Ptr globalDocument = m_globalSnapshot.document(absoluteFileName);
Document::Ptr globalDocument = m_globalSnapshot.document(absoluteFilePath);
if (globalDocument && globalDocument->fingerprint() == document->fingerprint()) {
switchCurrentDocument(previousDocument);
mergeEnvironment(globalDocument);

View File

@@ -59,7 +59,7 @@ private:
CPlusPlus::Document::Ptr switchCurrentDocument(CPlusPlus::Document::Ptr doc);
bool getFileContents(const QString &absoluteFilePath, QByteArray *contents,
bool getFileContents(const Utils::FilePath &absoluteFilePath, QByteArray *contents,
unsigned *revision) const;
bool checkFile(const QString &absoluteFilePath) const;
QString resolveFile(const QString &fileName, IncludeType type);

View File

@@ -5,7 +5,7 @@
#include "cppeditor_global.h"
#include <utils/fileutils.h>
#include <utils/filepath.h>
#include <QHash>
#include <QString>
@@ -36,9 +36,6 @@ public:
unsigned revision(const Utils::FilePath &fileName) const
{ return _elements.value(fileName).second; }
QPair<QByteArray, unsigned> get(const QString &fileName) const
{ return get(Utils::FilePath::fromString(fileName)); }
QPair<QByteArray, unsigned> get(const Utils::FilePath &fileName) const
{ return _elements.value(fileName); }
@@ -53,4 +50,4 @@ private:
Table _elements;
};
} // namespace CppEditor
} // CppEditor