1 //===- SyntaxHighlighting.cpp ---------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "SyntaxHighlighting.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Support/raw_ostream.h"
15 using namespace dwarf;
16 using namespace syntax;
18 static cl::opt<cl::boolOrDefault>
20 cl::desc("use colored syntax highlighting (default=autodetect)"),
21 cl::init(cl::BOU_UNSET));
23 WithColor::WithColor(raw_ostream &OS, enum HighlightColor Type) : OS(OS) {
24 // Detect color from terminal type unless the user passed the --color option.
25 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) {
27 case Address: OS.changeColor(raw_ostream::YELLOW); break;
28 case String: OS.changeColor(raw_ostream::GREEN); break;
29 case Tag: OS.changeColor(raw_ostream::BLUE); break;
30 case Attribute: OS.changeColor(raw_ostream::CYAN); break;
31 case Enumerator: OS.changeColor(raw_ostream::MAGENTA); break;
32 case Macro: OS.changeColor(raw_ostream::RED); break;
33 case Error: OS.changeColor(raw_ostream::RED, true); break;
34 case Warning: OS.changeColor(raw_ostream::MAGENTA, true); break;
35 case Note: OS.changeColor(raw_ostream::BLACK, true); break;
40 WithColor::~WithColor() {
41 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE)