LCOV - code coverage report
Current view: top level - lib/DebugInfo/DWARF - SyntaxHighlighting.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 12 24 50.0 %
Date: 2018-03-09 04:40:07 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- SyntaxHighlighting.cpp ---------------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "SyntaxHighlighting.h"
      11             : #include "llvm/Support/CommandLine.h"
      12             : #include "llvm/Support/raw_ostream.h"
      13             : 
      14             : using namespace llvm;
      15             : using namespace dwarf;
      16             : using namespace syntax;
      17             : 
      18             : static cl::opt<cl::boolOrDefault>
      19       82247 :     UseColor("color",
      20       82247 :              cl::desc("use colored syntax highlighting (default=autodetect)"),
      21      246741 :              cl::init(cl::BOU_UNSET));
      22             : 
      23      145024 : bool WithColor::colorsEnabled(raw_ostream &OS) {
      24      145024 :   if (UseColor == cl::BOU_UNSET)
      25      145024 :     return OS.has_colors();
      26           0 :   return UseColor == cl::BOU_TRUE;
      27             : }
      28             : 
      29       72512 : WithColor::WithColor(raw_ostream &OS, enum HighlightColor Type) : OS(OS) {
      30             :   // Detect color from terminal type unless the user passed the --color option.
      31       72512 :   if (colorsEnabled(OS)) {
      32           0 :     switch (Type) {
      33           0 :     case Address:    OS.changeColor(raw_ostream::YELLOW);         break;
      34           0 :     case String:     OS.changeColor(raw_ostream::GREEN);          break;
      35           0 :     case Tag:        OS.changeColor(raw_ostream::BLUE);           break;
      36           0 :     case Attribute:  OS.changeColor(raw_ostream::CYAN);           break;
      37           0 :     case Enumerator: OS.changeColor(raw_ostream::MAGENTA);        break;
      38           0 :     case Macro:      OS.changeColor(raw_ostream::RED);            break;
      39           0 :     case Error:      OS.changeColor(raw_ostream::RED, true);      break;
      40           0 :     case Warning:    OS.changeColor(raw_ostream::MAGENTA, true);  break;
      41           0 :     case Note:       OS.changeColor(raw_ostream::BLACK, true);    break;
      42             :     }
      43             :   }
      44       72512 : }
      45             : 
      46      145024 : WithColor::~WithColor() {
      47       72512 :   if (colorsEnabled(OS))
      48           0 :     OS.resetColor();
      49      319253 : }

Generated by: LCOV version 1.13