mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-20 15:14:45 +00:00
[clangd] Use name of Macro to compute its SymbolID, NFC.
Summary: We use the name from the IdentifierInfo of the Macro to compute its SymbolID. It is better to just take the Name as a parameter to avoid storing the IdentifierInfo whenever we need the SymbolID for the Macro. Patch by UTKARSH SAXENA! Reviewers: hokein Reviewed By: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69937
This commit is contained in:
parent
0cc7c29a97
commit
02ec6ff77e
@ -203,13 +203,13 @@ llvm::Optional<SymbolID> getSymbolID(const Decl *D) {
|
||||
return SymbolID(USR);
|
||||
}
|
||||
|
||||
llvm::Optional<SymbolID> getSymbolID(const IdentifierInfo &II,
|
||||
llvm::Optional<SymbolID> getSymbolID(const llvm::StringRef MacroName,
|
||||
const MacroInfo *MI,
|
||||
const SourceManager &SM) {
|
||||
if (MI == nullptr)
|
||||
return None;
|
||||
llvm::SmallString<128> USR;
|
||||
if (index::generateUSRForMacro(II.getName(), MI->getDefinitionLoc(), SM, USR))
|
||||
if (index::generateUSRForMacro(MacroName, MI->getDefinitionLoc(), SM, USR))
|
||||
return None;
|
||||
return SymbolID(USR);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "clang/Lex/MacroInfo.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace clang {
|
||||
class SourceManager;
|
||||
@ -69,7 +70,7 @@ llvm::Optional<SymbolID> getSymbolID(const Decl *D);
|
||||
/// macro (e.g. a change in definition offset can result in a different USR). We
|
||||
/// could change these semantics in the future by reimplementing this funcure
|
||||
/// (e.g. avoid USR for macros).
|
||||
llvm::Optional<SymbolID> getSymbolID(const IdentifierInfo &II,
|
||||
llvm::Optional<SymbolID> getSymbolID(const llvm::StringRef MacroName,
|
||||
const MacroInfo *MI,
|
||||
const SourceManager &SM);
|
||||
|
||||
|
@ -492,7 +492,7 @@ llvm::Optional<SymbolID> getSymbolID(const CodeCompletionResult &R,
|
||||
return clang::clangd::getSymbolID(R.Declaration);
|
||||
}
|
||||
case CodeCompletionResult::RK_Macro:
|
||||
return clang::clangd::getSymbolID(*R.Macro, R.MacroDefInfo, SM);
|
||||
return clang::clangd::getSymbolID(R.Macro->getName(), R.MacroDefInfo, SM);
|
||||
case CodeCompletionResult::RK_Keyword:
|
||||
return None;
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ bool SymbolCollector::handleMacroOccurence(const IdentifierInfo *Name,
|
||||
Roles & static_cast<unsigned>(index::SymbolRole::Definition)))
|
||||
return true;
|
||||
|
||||
auto ID = getSymbolID(*Name, MI, SM);
|
||||
auto ID = getSymbolID(Name->getName(), MI, SM);
|
||||
if (!ID)
|
||||
return true;
|
||||
|
||||
@ -473,14 +473,14 @@ void SymbolCollector::finish() {
|
||||
// First, drop header guards. We can't identify these until EOF.
|
||||
for (const IdentifierInfo *II : IndexedMacros) {
|
||||
if (const auto *MI = PP->getMacroDefinition(II).getMacroInfo())
|
||||
if (auto ID = getSymbolID(*II, MI, PP->getSourceManager()))
|
||||
if (auto ID = getSymbolID(II->getName(), MI, PP->getSourceManager()))
|
||||
if (MI->isUsedForHeaderGuard())
|
||||
Symbols.erase(*ID);
|
||||
}
|
||||
// Now increment refcounts.
|
||||
for (const IdentifierInfo *II : ReferencedMacros) {
|
||||
if (const auto *MI = PP->getMacroDefinition(II).getMacroInfo())
|
||||
if (auto ID = getSymbolID(*II, MI, PP->getSourceManager()))
|
||||
if (auto ID = getSymbolID(II->getName(), MI, PP->getSourceManager()))
|
||||
IncRef(*ID);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user