[llvm-pdbdump] Colorize output.
[oota-llvm.git] / tools / llvm-pdbdump / TypedefDumper.cpp
index 7bb4b9d2d434099382aa7db1dafef5b4cdbbd9e9..615b8d57aa19ecf752ad2e6ffb51d9eb2295e8c1 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "BuiltinDumper.h"
 #include "FunctionDumper.h"
+#include "LinePrinter.h"
 #include "llvm-pdbdump.h"
 
 #include "llvm/DebugInfo/PDB/IPDBSession.h"
 
 using namespace llvm;
 
-TypedefDumper::TypedefDumper() : PDBSymDumper(true) {}
+TypedefDumper::TypedefDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
 
 void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
                           int Indent) {
-  OS << "typedef ";
+  WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
   uint32_t TargetId = Symbol.getTypeId();
   if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId))
     TypeSymbol->dump(OS, 0, *this);
-  OS << " " << Symbol.getName();
+  WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
 }
 
 void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS,
@@ -39,21 +40,22 @@ void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS,
 
 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS,
                          int Indent) {
-  BuiltinDumper Dumper;
+  BuiltinDumper Dumper(Printer);
   Dumper.start(Symbol, OS);
 }
 
 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
                          int Indent) {
-  OS << "enum " << Symbol.getName();
+  WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
+  WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
 }
 
 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
                          int Indent) {
   if (Symbol.isConstType())
-    OS << "const ";
+    WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
   if (Symbol.isVolatileType())
-    OS << "volatile ";
+    WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
   uint32_t PointeeId = Symbol.getTypeId();
   auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
   if (!PointeeType)
@@ -62,7 +64,7 @@ void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
     if (Symbol.isReference())
       Pointer = FunctionDumper::PointerType::Reference;
-    FunctionDumper NestedDumper;
+    FunctionDumper NestedDumper(Printer);
     NestedDumper.start(*FuncSig, nullptr, Pointer, OS);
   } else {
     PointeeType->dump(OS, Indent, *this);
@@ -72,11 +74,12 @@ void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
 
 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol,
                          raw_ostream &OS, int Indent) {
-  FunctionDumper Dumper;
+  FunctionDumper Dumper(Printer);
   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None, OS);
 }
 
 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
                          int Indent) {
-  OS << "class " << Symbol.getName();
+  WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
+  WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
 }