aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-10-05 22:07:14 +0000
committerTed Kremenek <kremenek@apple.com>2012-10-05 22:07:14 +0000
commitefdfc1d38bdfa6c9c2ac47f883dd602f12e29807 (patch)
treee7dfaf83edd6d88c3528ee10bd93fc96e43284ad /tools
parent54db3244f425dae51cde7c6298ec42d0764f8ed8 (diff)
Add color output to 'diagtool tree' to show what warnings are enabled by default.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/diagtool/TreeView.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/tools/diagtool/TreeView.cpp b/tools/diagtool/TreeView.cpp
index 9db2c26dd9..aee7554151 100644
--- a/tools/diagtool/TreeView.cpp
+++ b/tools/diagtool/TreeView.cpp
@@ -19,6 +19,7 @@
#include "llvm/ADT/DenseSet.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/Basic/AllDiagnostics.h"
+#include "llvm/Support/Process.h"
DEF_DIAGTOOL("tree",
"Show warning flags in a tree view",
@@ -31,11 +32,37 @@ static void printUsage() {
llvm::errs() << "Usage: diagtool tree [--flags-only] [<diagnostic-group>]\n";
}
+static bool showColors(llvm::raw_ostream &out) {
+ if (&out != &llvm::errs() && &out != &llvm::outs())
+ return false;
+ return llvm::errs().is_displayed() && llvm::outs().is_displayed();
+}
+
+static void setColor(bool ShowColors, llvm::raw_ostream &out,
+ llvm::raw_ostream::Colors Color) {
+ if (ShowColors)
+ out << llvm::sys::Process::OutputColor(Color, false, false);
+}
+
+static void resetColor(bool ShowColors, llvm::raw_ostream &out) {
+ if (ShowColors)
+ out << llvm::sys::Process::ResetColor();
+}
+
+static clang::DiagnosticsEngine::Level getLevel(unsigned DiagID) {
+ static clang::DiagnosticsEngine Diags(new DiagnosticIDs);
+ return Diags.getDiagnosticLevel(DiagID, SourceLocation());
+}
+
static void printGroup(llvm::raw_ostream &out, const GroupRecord &Group,
bool FlagsOnly, unsigned Indent = 0) {
out.indent(Indent * 2);
+
+ bool ShowColors = showColors(out);
+ setColor(ShowColors, out, llvm::raw_ostream::YELLOW);
out << "-W" << Group.getName() << "\n";
-
+ resetColor(ShowColors, out);
+
++Indent;
for (GroupRecord::subgroup_iterator I = Group.subgroup_begin(),
E = Group.subgroup_end();
@@ -47,8 +74,15 @@ static void printGroup(llvm::raw_ostream &out, const GroupRecord &Group,
for (GroupRecord::diagnostics_iterator I = Group.diagnostics_begin(),
E = Group.diagnostics_end();
I != E; ++I) {
+ if (ShowColors) {
+ if (getLevel(I->DiagID) != DiagnosticsEngine::Ignored) {
+ setColor(ShowColors, out, llvm::raw_ostream::GREEN);
+ }
+ }
out.indent(Indent * 2);
- out << I->getName() << "\n";
+ out << I->getName();
+ resetColor(ShowColors, out);
+ out << "\n";
}
}
}
@@ -106,7 +140,7 @@ int TreeView::run(unsigned int argc, char **argv, llvm::raw_ostream &out) {
++argv;
}
}
-
+
bool ShowAll = false;
StringRef RootGroup;
@@ -127,6 +161,14 @@ int TreeView::run(unsigned int argc, char **argv, llvm::raw_ostream &out) {
return -1;
}
+ if (showColors(out)) {
+ out << '\n';
+ setColor(true, out, llvm::raw_ostream::GREEN);
+ out << "GREEN";
+ resetColor(true, out);
+ out << " = enabled by default\n\n";
+ }
+
if (ShowAll)
return showAll(out, FlagsOnly);