From d46d44e3c4a6f1f980f595386fc7ddd03c1f3fcd Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 3 Feb 2023 23:57:30 +0100 Subject: [PATCH] [Tooling/Inclusion] qualifed_name() => qualifiedName(), NFC --- .../clang/Tooling/Inclusions/StandardLibrary.h | 4 ++-- .../Inclusions/Stdlib/StandardLibrary.cpp | 16 +++++++++------- clang/unittests/Tooling/StandardLibraryTest.cpp | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h index 60509a9cebca..830cbd5873bc 100644 --- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h +++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h @@ -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. diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp index add8414eaf09..23e4ee0054cd 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp +++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp @@ -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 *NamespaceSymbols = nullptr; @@ -162,16 +167,13 @@ std::vector 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::named(llvm::StringRef Scope, llvm::StringRef Name, Lang L) { diff --git a/clang/unittests/Tooling/StandardLibraryTest.cpp b/clang/unittests/Tooling/StandardLibraryTest.cpp index 136b7b80dc4f..dee34ab233e6 100644 --- a/clang/unittests/Tooling/StandardLibraryTest.cpp +++ b/clang/unittests/Tooling/StandardLibraryTest.cpp @@ -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"));