From f68db427ef763b995f9e4fa3f1dbf2c9b90ad943 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 28 Nov 2022 13:06:13 +0100 Subject: [PATCH] CPlusPlus: Migrate Macro to FilePath Change-Id: I94e8702e81e809e4d8318572cc070a0531edaefa Reviewed-by: Christian Kandeler --- src/libs/cplusplus/Macro.h | 11 ++++------- src/libs/cplusplus/PreprocessorEnvironment.cpp | 6 ++++-- src/libs/cplusplus/pp-engine.cpp | 2 +- src/plugins/cppeditor/builtincursorinfo.cpp | 2 +- src/plugins/cppeditor/cppfindreferences.cpp | 7 +++---- .../cppeditor/cppfollowsymbolundercursor.cpp | 15 +++++++-------- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/libs/cplusplus/Macro.h b/src/libs/cplusplus/Macro.h index ca71d10d4c3..37c8cd78b04 100644 --- a/src/libs/cplusplus/Macro.h +++ b/src/libs/cplusplus/Macro.h @@ -68,13 +68,10 @@ public: void addFormal(const QByteArray &formal) { _formals.append(formal); } - const QString &fileName() const + const Utils::FilePath &filePath() const { return _fileName; } - Utils::FilePath filePath() const - { return Utils::FilePath::fromString(_fileName); } - - void setFileName(const QString &fileName) + void setFilePath(const Utils::FilePath &fileName) { _fileName = fileName; } unsigned fileRevision() const @@ -145,7 +142,7 @@ private: QByteArray _definitionText; QVector _definitionTokens; QVector _formals; - QString _fileName; + Utils::FilePath _fileName; unsigned _hashcode; unsigned _fileRevision; int _line; @@ -160,4 +157,4 @@ private: }; }; -} // namespace CPlusPlus +} // CPlusPlus diff --git a/src/libs/cplusplus/PreprocessorEnvironment.cpp b/src/libs/cplusplus/PreprocessorEnvironment.cpp index 4d7f5c76340..213a0bf04a4 100644 --- a/src/libs/cplusplus/PreprocessorEnvironment.cpp +++ b/src/libs/cplusplus/PreprocessorEnvironment.cpp @@ -29,6 +29,8 @@ #include +using namespace Utils; + namespace CPlusPlus { static unsigned hashCode(const char *str, int length) @@ -116,7 +118,7 @@ Macro *Environment::remove(const ByteArrayRef &name) Macro macro; macro.setName(name.toByteArray()); macro.setHidden(true); - macro.setFileName(currentFile); + macro.setFilePath(FilePath::fromString(currentFile)); macro.setLine(currentLine); return bind(macro); } @@ -246,4 +248,4 @@ void Environment::dump() const } } -} // namespace CPlusPlus +} // CPlusPlus diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index a846c468408..a484e568864 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -1703,7 +1703,7 @@ void Preprocessor::handleDefineDirective(PPToken *tk) return; Macro macro; - macro.setFileName(m_env->currentFile); + macro.setFilePath(FilePath::fromString(m_env->currentFile)); macro.setLine(tk->lineno); QByteArray macroName = tk->asByteArrayRef().toByteArray(); macro.setName(macroName); diff --git a/src/plugins/cppeditor/builtincursorinfo.cpp b/src/plugins/cppeditor/builtincursorinfo.cpp index bc48189225a..7f5650a7131 100644 --- a/src/plugins/cppeditor/builtincursorinfo.cpp +++ b/src/plugins/cppeditor/builtincursorinfo.cpp @@ -254,7 +254,7 @@ bool isMacroUseOf(const Document::MacroUse &marcoUse, const Macro ¯o) return candidate.line() == macro.line() && candidate.utf16CharOffset() == macro.utf16CharOffset() && candidate.length() == macro.length() - && candidate.fileName() == macro.fileName(); + && candidate.filePath() == macro.filePath(); } bool handleMacroCase(const Document::Ptr document, diff --git a/src/plugins/cppeditor/cppfindreferences.cpp b/src/plugins/cppeditor/cppfindreferences.cpp index 39d839f2412..a65142d3d78 100644 --- a/src/plugins/cppeditor/cppfindreferences.cpp +++ b/src/plugins/cppeditor/cppfindreferences.cpp @@ -650,7 +650,7 @@ restart_search: for (const CPlusPlus::Document::MacroUse &use : doc->macroUses()) { const CPlusPlus::Macro &useMacro = use.macro(); - if (useMacro.fileName() == macro.fileName()) { // Check if this is a match, but possibly against an outdated document. + if (useMacro.filePath() == macro.filePath()) { // Check if this is a match, but possibly against an outdated document. if (source.isEmpty()) source = getSource(fileName, workingCopy); @@ -752,13 +752,12 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri // add the macro definition itself { - const QByteArray &source = getSource(Utils::FilePath::fromString(macro.fileName()), - workingCopy); + const QByteArray &source = getSource(macro.filePath(), workingCopy); unsigned column; const QString line = FindMacroUsesInFile::matchingLine(macro.bytesOffset(), source, &column); SearchResultItem item; - const Utils::FilePath filePath = Utils::FilePath::fromString(macro.fileName()); + const FilePath filePath = macro.filePath(); item.setFilePath(filePath); item.setLineText(line); item.setMainRange(macro.line(), column, macro.nameToQString().length()); diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index 38939b8ddbf..dda644e2346 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -25,8 +25,7 @@ using namespace CPlusPlus; using namespace TextEditor; - -using Link = Utils::Link; +using namespace Utils; namespace CppEditor { @@ -188,7 +187,7 @@ Link findMacroLink_helper(const QByteArray &name, Document::Ptr doc, const Snaps for (const Macro ¯o : doc->definedMacros()) { if (macro.name() == name) { Link link; - link.targetFilePath = Utils::FilePath::fromString(macro.fileName()); + link.targetFilePath = macro.filePath(); link.targetLine = macro.line(); return link; } @@ -648,12 +647,12 @@ void FollowSymbolUnderCursor::findLink( if (macro->name() == name) return processLinkCallback(link); //already on definition! } else if (const Document::MacroUse *use = doc->findMacroUseAt(endOfToken - 1)) { - const QString fileName = use->macro().fileName(); - if (fileName == CppModelManager::editorConfigurationFileName()) { + const FilePath filePath = use->macro().filePath(); + if (filePath.path() == CppModelManager::editorConfigurationFileName()) { editorWidget->showPreProcessorWidget(); - } else if (fileName != CppModelManager::configurationFileName().path()) { + } else if (filePath.path() != CppModelManager::configurationFileName().path()) { const Macro ¯o = use->macro(); - link.targetFilePath = Utils::FilePath::fromString(macro.fileName()); + link.targetFilePath = macro.filePath(); link.targetLine = macro.line(); link.linkTextStart = use->utf16charsBegin(); link.linkTextEnd = use->utf16charsEnd(); @@ -866,4 +865,4 @@ void FollowSymbolUnderCursor::setVirtualFunctionAssistProvider( m_virtualFunctionAssistProvider = provider; } -} // namespace CppEditor +} // CppEditor