aboutsummaryrefslogtreecommitdiff
path: root/tools/diagtool/FindDiagnosticID.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/diagtool/FindDiagnosticID.cpp')
-rw-r--r--tools/diagtool/FindDiagnosticID.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/diagtool/FindDiagnosticID.cpp b/tools/diagtool/FindDiagnosticID.cpp
index 167b9925eedc..db6fe5e472a9 100644
--- a/tools/diagtool/FindDiagnosticID.cpp
+++ b/tools/diagtool/FindDiagnosticID.cpp
@@ -18,6 +18,15 @@ DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
using namespace clang;
using namespace diagtool;
+static StringRef getNameFromID(StringRef Name) {
+ int DiagID;
+ if(!Name.getAsInteger(0, DiagID)) {
+ const DiagnosticRecord &Diag = getDiagnosticForID(DiagID);
+ return Diag.getName();
+ }
+ return StringRef();
+}
+
static Optional<DiagnosticRecord>
findDiagnostic(ArrayRef<DiagnosticRecord> Diagnostics, StringRef Name) {
for (const auto &Diag : Diagnostics) {
@@ -38,7 +47,7 @@ int FindDiagnosticID::run(unsigned int argc, char **argv,
llvm::cl::Required, llvm::cl::cat(FindDiagnosticIDOptions));
std::vector<const char *> Args;
- Args.push_back("find-diagnostic-id");
+ Args.push_back("diagtool find-diagnostic-id");
for (const char *A : llvm::makeArrayRef(argv, argc))
Args.push_back(A);
@@ -50,6 +59,13 @@ int FindDiagnosticID::run(unsigned int argc, char **argv,
Optional<DiagnosticRecord> Diag =
findDiagnostic(AllDiagnostics, DiagnosticName);
if (!Diag) {
+ // Name to id failed, so try id to name.
+ auto Name = getNameFromID(DiagnosticName);
+ if (!Name.empty()) {
+ OS << Name << '\n';
+ return 0;
+ }
+
llvm::errs() << "error: invalid diagnostic '" << DiagnosticName << "'\n";
return 1;
}