[cfe-commits] [PATCH] Use color for -ast-dump-filter only when it is supported

Philip Craig philipjcraig at gmail.com
Mon Nov 19 03:49:46 PST 2012


This was causing me problems when I was adding tests for the indentation of -ast-dump.

I haven't added a test to check that it still works when color is supported. Any suggestion for how to do that?

http://llvm-reviews.chandlerc.com/D127

Files:
  lib/Frontend/ASTConsumers.cpp
  test/Tooling/clang-check-ast-dump.cpp

Index: lib/Frontend/ASTConsumers.cpp
===================================================================
--- lib/Frontend/ASTConsumers.cpp
+++ lib/Frontend/ASTConsumers.cpp
@@ -59,9 +59,12 @@
 
     bool TraverseDecl(Decl *D) {
       if (D != NULL && filterMatches(D)) {
-        Out.changeColor(llvm::raw_ostream::BLUE) <<
-            (Dump ? "Dumping " : "Printing ") << getName(D) << ":\n";
-        Out.resetColor();
+        bool ShowColors = Out.has_colors();
+        if (ShowColors)
+          Out.changeColor(llvm::raw_ostream::BLUE);
+        Out << (Dump ? "Dumping " : "Printing ") << getName(D) << ":\n";
+        if (ShowColors)
+          Out.resetColor();
         if (Dump)
           D->dump(Out);
         else
Index: test/Tooling/clang-check-ast-dump.cpp
===================================================================
--- test/Tooling/clang-check-ast-dump.cpp
+++ test/Tooling/clang-check-ast-dump.cpp
@@ -8,7 +8,8 @@
 // RUN: clang-check -ast-dump -ast-dump-filter test_namespace::TheClass::theMethod "%s" -- 2>&1 | FileCheck -check-prefix CHECK-FILTER %s
 // CHECK-FILTER-NOT: namespace test_namespace
 // CHECK-FILTER-NOT: class TheClass
-// CHECK-FILTER: int theMethod(int x) (CompoundStmt
+// CHECK-FILTER: {{^}}Dumping test_namespace::TheClass::theMethod
+// CHECK-FILTER-NEXT: {{^}}int theMethod(int x) (CompoundStmt
 // CHECK-FILTER-NEXT:   (ReturnStmt
 // CHECK-FILTER-NEXT:     (BinaryOperator
 //
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127.1.patch
Type: text/x-patch
Size: 1435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121119/be1b91d1/attachment.bin>


More information about the cfe-commits mailing list