From 3233391b50713ca77404ccbe0891cc3baffcac72 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Wed, 21 Nov 2012 10:54:55 +0000 Subject: [PATCH] Use color for -ast-dump-filter only when it is supported Patch by Philip Craig. llvm-svn: 168420 --- clang/lib/Frontend/ASTConsumers.cpp | 9 ++++++--- clang/test/Tooling/clang-check-ast-dump.cpp | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp index 882d400c..c99dbf0 100644 --- a/clang/lib/Frontend/ASTConsumers.cpp +++ b/clang/lib/Frontend/ASTConsumers.cpp @@ -59,9 +59,12 @@ namespace { 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 diff --git a/clang/test/Tooling/clang-check-ast-dump.cpp b/clang/test/Tooling/clang-check-ast-dump.cpp index 43686bd..6e03f82 100644 --- a/clang/test/Tooling/clang-check-ast-dump.cpp +++ b/clang/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 // -- 2.7.4