diff --git a/src/libs/cplusplus/FastPreprocessor.cpp b/src/libs/cplusplus/FastPreprocessor.cpp index 607dd55364b..c948776c4b9 100644 --- a/src/libs/cplusplus/FastPreprocessor.cpp +++ b/src/libs/cplusplus/FastPreprocessor.cpp @@ -87,7 +87,7 @@ void FastPreprocessor::macroAdded(const Macro ¯o) 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; diff --git a/src/libs/cplusplus/Macro.h b/src/libs/cplusplus/Macro.h index 603dca0ccdf..ca71d10d4c3 100644 --- a/src/libs/cplusplus/Macro.h +++ b/src/libs/cplusplus/Macro.h @@ -27,6 +27,8 @@ #include +#include + #include #include #include @@ -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; } diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 69a5a0b3539..a846c468408 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -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 diff --git a/src/plugins/cppeditor/builtincursorinfo.cpp b/src/plugins/cppeditor/builtincursorinfo.cpp index 870c9addbe5..bc48189225a 100644 --- a/src/plugins/cppeditor/builtincursorinfo.cpp +++ b/src/plugins/cppeditor/builtincursorinfo.cpp @@ -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 diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index 281083f6ebd..e835e0443bf 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -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(); } }; diff --git a/src/plugins/cppeditor/cppfindreferences.cpp b/src/plugins/cppeditor/cppfindreferences.cpp index 42d77a5493c..39d839f2412 100644 --- a/src/plugins/cppeditor/cppfindreferences.cpp +++ b/src/plugins/cppeditor/cppfindreferences.cpp @@ -706,8 +706,8 @@ static void findMacroUses_helper(QFutureInterface &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()); diff --git a/src/plugins/cppeditor/cppsourceprocessor.cpp b/src/plugins/cppeditor/cppsourceprocessor.cpp index afb0bf79c0a..340c441d39d 100644 --- a/src/plugins/cppeditor/cppsourceprocessor.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor.cpp @@ -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 ¯o) { 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); diff --git a/src/plugins/cppeditor/cppsourceprocessor.h b/src/plugins/cppeditor/cppsourceprocessor.h index 1d8c3464122..0270a87abb0 100644 --- a/src/plugins/cppeditor/cppsourceprocessor.h +++ b/src/plugins/cppeditor/cppsourceprocessor.h @@ -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); diff --git a/src/plugins/cppeditor/cppworkingcopy.h b/src/plugins/cppeditor/cppworkingcopy.h index 31ea5758d03..074930ed6d9 100644 --- a/src/plugins/cppeditor/cppworkingcopy.h +++ b/src/plugins/cppeditor/cppworkingcopy.h @@ -5,7 +5,7 @@ #include "cppeditor_global.h" -#include +#include #include #include @@ -36,9 +36,6 @@ public: unsigned revision(const Utils::FilePath &fileName) const { return _elements.value(fileName).second; } - QPair get(const QString &fileName) const - { return get(Utils::FilePath::fromString(fileName)); } - QPair get(const Utils::FilePath &fileName) const { return _elements.value(fileName); } @@ -53,4 +50,4 @@ private: Table _elements; }; -} // namespace CppEditor +} // CppEditor