[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:
Utkarsh Saxena 2019-11-11 12:38:17 +01:00 committed by Haojian Wu
parent 0cc7c29a97
commit 02ec6ff77e
4 changed files with 8 additions and 7 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}
}