JDevlieghere updated this revision to Diff 113737. JDevlieghere added a comment.
Thanks Alex! https://reviews.llvm.org/D37390 Files: test/Misc/warning-flags-tree.c tools/diagtool/TreeView.cpp
Index: tools/diagtool/TreeView.cpp =================================================================== --- tools/diagtool/TreeView.cpp +++ tools/diagtool/TreeView.cpp @@ -32,10 +32,10 @@ public: llvm::raw_ostream &out; const bool ShowColors; - bool FlagsOnly; + bool Internal; TreePrinter(llvm::raw_ostream &out) - : out(out), ShowColors(hasColors(out)), FlagsOnly(false) {} + : out(out), ShowColors(hasColors(out)), Internal(false) {} void setColor(llvm::raw_ostream::Colors Color) { if (ShowColors) @@ -54,23 +54,41 @@ return Diags.isIgnored(DiagID, SourceLocation()); } + static bool enabledByDefault(const GroupRecord &Group) { + for (auto I = Group.diagnostics_begin(), E = Group.diagnostics_end(); + I != E; ++I) { + if (isIgnored(I->DiagID)) + return false; + } + + for (auto I = Group.subgroup_begin(), E = Group.subgroup_end(); I != E; + ++I) { + if (!enabledByDefault(*I)) + return false; + } + + return true; + } + void printGroup(const GroupRecord &Group, unsigned Indent = 0) { out.indent(Indent * 2); - setColor(llvm::raw_ostream::YELLOW); + if (enabledByDefault(Group)) + setColor(llvm::raw_ostream::GREEN); + else + setColor(llvm::raw_ostream::YELLOW); + out << "-W" << Group.getName() << "\n"; resetColor(); ++Indent; - for (GroupRecord::subgroup_iterator I = Group.subgroup_begin(), - E = Group.subgroup_end(); - I != E; ++I) { + for (auto I = Group.subgroup_begin(), E = Group.subgroup_end(); I != E; + ++I) { printGroup(*I, Indent); } - if (!FlagsOnly) { - for (GroupRecord::diagnostics_iterator I = Group.diagnostics_begin(), - E = Group.diagnostics_end(); + if (Internal) { + for (auto I = Group.diagnostics_begin(), E = Group.diagnostics_end(); I != E; ++I) { if (ShowColors && !isIgnored(I->DiagID)) setColor(llvm::raw_ostream::GREEN); @@ -107,12 +125,9 @@ ArrayRef<GroupRecord> AllGroups = getDiagnosticGroups(); llvm::DenseSet<unsigned> NonRootGroupIDs; - for (ArrayRef<GroupRecord>::iterator I = AllGroups.begin(), - E = AllGroups.end(); - I != E; ++I) { - for (GroupRecord::subgroup_iterator SI = I->subgroup_begin(), - SE = I->subgroup_end(); - SI != SE; ++SI) { + for (auto I = AllGroups.begin(), E = AllGroups.end(); I != E; ++I) { + for (auto SI = I->subgroup_begin(), SE = I->subgroup_end(); SI != SE; + ++SI) { NonRootGroupIDs.insert((unsigned)SI.getID()); } } @@ -139,16 +154,16 @@ }; static void printUsage() { - llvm::errs() << "Usage: diagtool tree [--flags-only] [<diagnostic-group>]\n"; + llvm::errs() << "Usage: diagtool tree [--internal] [<diagnostic-group>]\n"; } int TreeView::run(unsigned int argc, char **argv, llvm::raw_ostream &out) { // First check our one flag (--flags-only). - bool FlagsOnly = false; + bool Internal = false; if (argc > 0) { StringRef FirstArg(*argv); - if (FirstArg.equals("--flags-only")) { - FlagsOnly = true; + if (FirstArg.equals("--internal")) { + Internal = true; --argc; ++argv; } @@ -175,7 +190,7 @@ } TreePrinter TP(out); - TP.FlagsOnly = FlagsOnly; + TP.Internal = Internal; TP.showKey(); return ShowAll ? TP.showAll() : TP.showGroup(RootGroup); } Index: test/Misc/warning-flags-tree.c =================================================================== --- test/Misc/warning-flags-tree.c +++ test/Misc/warning-flags-tree.c @@ -1,6 +1,6 @@ -// RUN: diagtool tree | FileCheck -strict-whitespace %s -// RUN: diagtool tree -Weverything | FileCheck -strict-whitespace %s -// RUN: diagtool tree everything | FileCheck -strict-whitespace %s +// RUN: diagtool tree --internal | FileCheck -strict-whitespace %s +// RUN: diagtool tree --internal -Weverything | FileCheck -strict-whitespace %s +// RUN: diagtool tree --internal everything | FileCheck -strict-whitespace %s // // These three ways of running diagtool tree are the same: // they produce a tree for every top-level diagnostic flag. @@ -30,7 +30,7 @@ // RUN: not diagtool tree -Wthis-is-not-a-valid-flag -// RUN: diagtool tree -Wgnu | FileCheck -strict-whitespace -check-prefix CHECK-GNU %s +// RUN: diagtool tree --internal -Wgnu | FileCheck -strict-whitespace -check-prefix CHECK-GNU %s // CHECK-GNU: -Wgnu // CHECK-GNU: -Wgnu-designator // CHECK-GNU: ext_gnu_array_range @@ -40,7 +40,7 @@ // CHECK-GNU: ext_vla // There are more GNU extensions but we don't need to check them all. -// RUN: diagtool tree --flags-only -Wgnu | FileCheck -check-prefix CHECK-FLAGS-ONLY %s +// RUN: diagtool tree -Wgnu | FileCheck -check-prefix CHECK-FLAGS-ONLY %s // CHECK-FLAGS-ONLY: -Wgnu // CHECK-FLAGS-ONLY: -Wgnu-designator // CHECK-FLAGS-ONLY-NOT: ext_gnu_array_range
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits