[clang-tools-extra] e5739eb - [include-cleaner] Defer decl->stdlib conversion into decl->location conversion

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 16 07:52:45 PST 2022


Author: Kadir Cetinkaya
Date: 2022-11-16T16:52:39+01:00
New Revision: e5739eb4f8135e20da7590c86d724920fd66753e

URL: https://github.com/llvm/llvm-project/commit/e5739eb4f8135e20da7590c86d724920fd66753e
DIFF: https://github.com/llvm/llvm-project/commit/e5739eb4f8135e20da7590c86d724920fd66753e.diff

LOG: [include-cleaner] Defer decl->stdlib conversion into decl->location conversion

We preserve decls for stdlib symbols after this patch in symbol. That
way we have a more unified view of stdlib and regular decls and can provide
reacher information in applications.

Differential Revision: https://reviews.llvm.org/D138134

Added: 
    

Modified: 
    clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
    clang-tools-extra/include-cleaner/lib/Analysis.cpp
    clang-tools-extra/include-cleaner/lib/Types.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
index 85e3fe4d7827d..29a3aa7ea7f73 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -52,27 +52,21 @@ struct Symbol {
     Declaration,
     /// A preprocessor macro, as defined in a specific location.
     Macro,
-    /// A recognized symbol from the standard library, like std::string.
-    Standard,
   };
 
   Symbol(const Decl &D) : Storage(&D) {}
   Symbol(struct Macro M) : Storage(M) {}
-  Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
 
   Kind kind() const { return static_cast<Kind>(Storage.index()); }
   bool operator==(const Symbol &RHS) const { return Storage == RHS.Storage; }
 
   const Decl &declaration() const { return *std::get<Declaration>(Storage); }
   struct Macro macro() const { return std::get<Macro>(Storage); }
-  tooling::stdlib::Symbol standard() const {
-    return std::get<Standard>(Storage);
-  }
 
 private:
   // FIXME: Add support for macros.
   // Order must match Kind enum!
-  std::variant<const Decl *, struct Macro, tooling::stdlib::Symbol> Storage;
+  std::variant<const Decl *, struct Macro> Storage;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Symbol &);
 
@@ -122,9 +116,7 @@ struct Header {
   tooling::stdlib::Header standard() const {
     return std::get<Standard>(Storage);
   }
-  StringRef verbatim() const {
-    return std::get<Verbatim>(Storage);
-  }
+  StringRef verbatim() const { return std::get<Verbatim>(Storage); }
 
 private:
   // Order must match Kind enum!

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 9e04ab7dd5668..890e5e13fa57f 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -25,13 +25,14 @@ void walkUsed(llvm::ArrayRef<Decl *> ASTRoots,
   for (auto *Root : ASTRoots) {
     auto &SM = Root->getASTContext().getSourceManager();
     walkAST(*Root, [&](SourceLocation Loc, NamedDecl &ND, RefType RT) {
+      SymbolReference SymRef{Loc, ND, RT};
       if (auto SS = Recognizer(&ND)) {
         // FIXME: Also report forward decls from main-file, so that the caller
         // can decide to insert/ignore a header.
-        return CB({Loc, Symbol(*SS), RT}, findHeaders(*SS, SM, PI));
+        return CB(SymRef, findHeaders(*SS, SM, PI));
       }
       // FIXME: Extract locations from redecls.
-      return CB({Loc, Symbol(ND), RT}, findHeaders(ND.getLocation(), SM, PI));
+      return CB(SymRef, findHeaders(ND.getLocation(), SM, PI));
     });
   }
   for (const SymbolReference &MacroRef : MacroRefs) {

diff  --git a/clang-tools-extra/include-cleaner/lib/Types.cpp b/clang-tools-extra/include-cleaner/lib/Types.cpp
index d7b17376d1319..08c9b5980060b 100644
--- a/clang-tools-extra/include-cleaner/lib/Types.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -22,8 +22,6 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S) {
     return OS << S.declaration().getDeclKindName();
   case Symbol::Macro:
     return OS << S.macro().Name;
-  case Symbol::Standard:
-    return OS << S.standard().scope() << S.standard().name();
   }
   llvm_unreachable("Unhandled Symbol kind");
 }


        


More information about the cfe-commits mailing list