Skip to content

Commit 8dfaf99

Browse files
committed
[include-cleaner] Provide public to_string of RefType (for HTMLReport), clean up includes. NFC
1 parent 29ef16c commit 8dfaf99

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ enum class RefType {
8585
/// Target's use can't be proven, e.g. a candidate for an unresolved overload.
8686
Ambiguous,
8787
};
88+
llvm::raw_ostream &operator<<(llvm::raw_ostream &, RefType);
8889

8990
/// Indicates that a piece of code refers to a symbol.
9091
struct SymbolReference {

clang-tools-extra/include-cleaner/lib/Types.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,16 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolReference &R) {
5454
/*Width=*/CHAR_BIT * sizeof(SourceLocation::UIntTy));
5555
}
5656

57+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, RefType T) {
58+
switch (T) {
59+
case RefType::Explicit:
60+
return OS << "explicit";
61+
case RefType::Implicit:
62+
return OS << "implicit";
63+
case RefType::Ambiguous:
64+
return OS << "ambiguous";
65+
}
66+
llvm_unreachable("Unexpected RefType");
67+
}
68+
5769
} // namespace clang::include_cleaner

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "AnalysisInternal.h"
10-
#include "clang-include-cleaner/Analysis.h"
1110
#include "clang/AST/Decl.h"
1211
#include "clang/AST/DeclCXX.h"
1312
#include "clang/AST/Expr.h"

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
#include "llvm/ADT/ArrayRef.h"
1515
#include "llvm/ADT/StringRef.h"
1616
#include "llvm/Support/Error.h"
17-
#include "llvm/Support/ErrorHandling.h"
17+
#include "llvm/Support/ScopedPrinter.h"
1818
#include "llvm/Testing/Support/Annotations.h"
19-
#include "gmock/gmock.h"
2019
#include "gtest/gtest.h"
2120
#include <cstddef>
2221
#include <unordered_map>
@@ -25,20 +24,6 @@
2524

2625
namespace clang::include_cleaner {
2726
namespace {
28-
using testing::Pair;
29-
using testing::UnorderedElementsAre;
30-
31-
llvm::StringLiteral to_string(RefType RT) {
32-
switch (RT) {
33-
case RefType::Explicit:
34-
return "explicit";
35-
case RefType::Implicit:
36-
return "implicit";
37-
case RefType::Ambiguous:
38-
return "ambiguous";
39-
}
40-
llvm_unreachable("Unexpected RefType");
41-
}
4227

4328
// Specifies a test of which symbols are referenced by a piece of code.
4429
// If `// c++-header` is present, treats referencing code as a header file.
@@ -100,14 +85,14 @@ void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
10085
DiagnosticsEngine::Note, Message, {}, {});
10186
};
10287
for (auto RT : {RefType::Explicit, RefType::Implicit, RefType::Ambiguous}) {
103-
auto RTStr = to_string(RT);
88+
auto RTStr = llvm::to_string(RT);
10489
for (auto Expected : Target.points(RTStr))
10590
if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
106-
DiagnosePoint(("location not marked used with type " + RTStr).str(),
91+
DiagnosePoint("location not marked used with type " + RTStr,
10792
Expected);
10893
for (auto Actual : ReferencedOffsets[RT])
10994
if (!llvm::is_contained(Target.points(RTStr), Actual))
110-
DiagnosePoint(("location unexpectedly used with type " + RTStr).str(),
95+
DiagnosePoint("location unexpectedly used with type " + RTStr,
11196
Actual);
11297
}
11398

0 commit comments

Comments
 (0)