[Tooling/Inclusion] qualifed_name() => qualifiedName(), NFC

This commit is contained in:
Haojian Wu 2023-02-03 23:57:30 +01:00
parent f42e1a7484
commit d46d44e3c4
3 changed files with 12 additions and 10 deletions

View File

@ -75,11 +75,11 @@ public:
named(llvm::StringRef Scope, llvm::StringRef Name, Lang Language = Lang::CXX);
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S) {
return OS << S.qualified_name();
return OS << S.qualifiedName();
}
llvm::StringRef scope() const;
llvm::StringRef name() const;
llvm::StringRef qualified_name() const;
llvm::StringRef qualifiedName() const;
// The preferred header for this symbol (e.g. the suggested insertion).
Header header() const;
// Some symbols may be provided by multiple headers.

View File

@ -32,6 +32,11 @@ struct SymbolHeaderMapping {
const char *Data; // std::vector
unsigned ScopeLen; // ~~~~~
unsigned NameLen; // ~~~~~~
StringRef scope() const { return StringRef(Data, ScopeLen); }
StringRef name() const { return StringRef(Data + ScopeLen, NameLen); }
StringRef qualifiedName() const {
return StringRef(Data, ScopeLen + NameLen);
}
} *SymbolNames = nullptr;
// Symbol name -> Symbol::ID, within a namespace.
llvm::DenseMap<llvm::StringRef, NSSymbolMap *> *NamespaceSymbols = nullptr;
@ -162,16 +167,13 @@ std::vector<Symbol> Symbol::all(Lang L) {
return Result;
}
llvm::StringRef Symbol::scope() const {
auto &S = getMappingPerLang(Language)->SymbolNames[ID];
return StringRef(S.Data, S.ScopeLen);
return getMappingPerLang(Language)->SymbolNames[ID].scope();
}
llvm::StringRef Symbol::name() const {
auto &S = getMappingPerLang(Language)->SymbolNames[ID];
return StringRef(S.Data + S.ScopeLen, S.NameLen);
return getMappingPerLang(Language)->SymbolNames[ID].name();
}
llvm::StringRef Symbol::qualified_name() const {
auto &S = getMappingPerLang(Language)->SymbolNames[ID];
return StringRef(S.Data, S.ScopeLen + S.NameLen);
llvm::StringRef Symbol::qualifiedName() const {
return getMappingPerLang(Language)->SymbolNames[ID].qualifiedName();
}
std::optional<Symbol> Symbol::named(llvm::StringRef Scope, llvm::StringRef Name,
Lang L) {

View File

@ -47,7 +47,7 @@ TEST(StdlibTest, All) {
EXPECT_TRUE(Vector);
EXPECT_EQ(Vector->scope(), "std::");
EXPECT_EQ(Vector->name(), "vector");
EXPECT_EQ(Vector->qualified_name(), "std::vector");
EXPECT_EQ(Vector->qualifiedName(), "std::vector");
EXPECT_EQ(llvm::to_string(*Vector), "std::vector");
EXPECT_FALSE(stdlib::Symbol::named("std::", "dongle"));
EXPECT_FALSE(stdlib::Symbol::named("clang::", "ASTContext"));