[clang-tools-extra] 8dfaf99 - [include-cleaner] Provide public to_string of RefType (for HTMLReport), clean up includes. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 11 04:25:38 PST 2022


Author: Sam McCall
Date: 2022-11-11T13:25:22+01:00
New Revision: 8dfaf9940abe029e4fd35c63e3d7f2df66306a06

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

LOG: [include-cleaner] Provide public to_string of RefType (for HTMLReport), clean up includes. NFC

Added: 
    

Modified: 
    clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
    clang-tools-extra/include-cleaner/lib/Types.cpp
    clang-tools-extra/include-cleaner/lib/WalkAST.cpp
    clang-tools-extra/include-cleaner/unittests/WalkASTTest.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 78e61b81166a..85e3fe4d7827 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
@@ -85,6 +85,7 @@ enum class RefType {
   /// Target's use can't be proven, e.g. a candidate for an unresolved overload.
   Ambiguous,
 };
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, RefType);
 
 /// Indicates that a piece of code refers to a symbol.
 struct SymbolReference {

diff  --git a/clang-tools-extra/include-cleaner/lib/Types.cpp b/clang-tools-extra/include-cleaner/lib/Types.cpp
index a3b2731401ae..d7b17376d131 100644
--- a/clang-tools-extra/include-cleaner/lib/Types.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -54,4 +54,16 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolReference &R) {
                    /*Width=*/CHAR_BIT * sizeof(SourceLocation::UIntTy));
 }
 
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, RefType T) {
+  switch (T) {
+  case RefType::Explicit:
+    return OS << "explicit";
+  case RefType::Implicit:
+    return OS << "implicit";
+  case RefType::Ambiguous:
+    return OS << "ambiguous";
+  }
+  llvm_unreachable("Unexpected RefType");
+}
+
 } // namespace clang::include_cleaner

diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index fd6fcee7e457..3d338cd59b28 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "AnalysisInternal.h"
-#include "clang-include-cleaner/Analysis.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index c4e5af21f20c..17d13018d152 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -14,9 +14,8 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include <cstddef>
 #include <unordered_map>
@@ -25,20 +24,6 @@
 
 namespace clang::include_cleaner {
 namespace {
-using testing::Pair;
-using testing::UnorderedElementsAre;
-
-llvm::StringLiteral to_string(RefType RT) {
-  switch (RT) {
-  case RefType::Explicit:
-    return "explicit";
-  case RefType::Implicit:
-    return "implicit";
-  case RefType::Ambiguous:
-    return "ambiguous";
-  }
-  llvm_unreachable("Unexpected RefType");
-}
 
 // Specifies a test of which symbols are referenced by a piece of code.
 // If `// c++-header` is present, treats referencing code as a header file.
@@ -100,14 +85,14 @@ void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
         DiagnosticsEngine::Note, Message, {}, {});
   };
   for (auto RT : {RefType::Explicit, RefType::Implicit, RefType::Ambiguous}) {
-    auto RTStr = to_string(RT);
+    auto RTStr = llvm::to_string(RT);
     for (auto Expected : Target.points(RTStr))
       if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-        DiagnosePoint(("location not marked used with type " + RTStr).str(),
+        DiagnosePoint("location not marked used with type " + RTStr,
                       Expected);
     for (auto Actual : ReferencedOffsets[RT])
       if (!llvm::is_contained(Target.points(RTStr), Actual))
-        DiagnosePoint(("location unexpectedly used with type " + RTStr).str(),
+        DiagnosePoint("location unexpectedly used with type " + RTStr,
                       Actual);
   }
 


        


More information about the cfe-commits mailing list