@@ -18,6 +18,15 @@ DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
18
18
using namespace clang;
19
19
using namespace diagtool ;
20
20
21
+ static StringRef getNameFromID (StringRef Name) {
22
+ int DiagID;
23
+ if (!Name.getAsInteger (0 , DiagID)) {
24
+ const DiagnosticRecord &Diag = getDiagnosticForID (DiagID);
25
+ return Diag.getName ();
26
+ }
27
+ return StringRef ();
28
+ }
29
+
21
30
static Optional<DiagnosticRecord>
22
31
findDiagnostic (ArrayRef<DiagnosticRecord> Diagnostics, StringRef Name) {
23
32
for (const auto &Diag : Diagnostics) {
@@ -38,7 +47,7 @@ int FindDiagnosticID::run(unsigned int argc, char **argv,
38
47
llvm::cl::Required, llvm::cl::cat (FindDiagnosticIDOptions));
39
48
40
49
std::vector<const char *> Args;
41
- Args.push_back (" find-diagnostic-id" );
50
+ Args.push_back (" diagtool find-diagnostic-id" );
42
51
for (const char *A : llvm::makeArrayRef (argv, argc))
43
52
Args.push_back (A);
44
53
@@ -50,6 +59,13 @@ int FindDiagnosticID::run(unsigned int argc, char **argv,
50
59
Optional<DiagnosticRecord> Diag =
51
60
findDiagnostic (AllDiagnostics, DiagnosticName);
52
61
if (!Diag) {
62
+ // Name to id failed, so try id to name.
63
+ auto Name = getNameFromID (DiagnosticName);
64
+ if (!Name.empty ()) {
65
+ OS << Name << ' \n ' ;
66
+ return 0 ;
67
+ }
68
+
53
69
llvm::errs () << " error: invalid diagnostic '" << DiagnosticName << " '\n " ;
54
70
return 1 ;
55
71
}
0 commit comments