]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/ASTDumperUtils.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / ASTDumperUtils.h
1 //===--- ASTDumperUtils.h - Printing of AST nodes -------------------------===//
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 // This file implements AST utilities for traversal down the tree.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_ASTDUMPERUTILS_H
15 #define LLVM_CLANG_AST_ASTDUMPERUTILS_H
16
17 #include "llvm/Support/raw_ostream.h"
18
19 namespace clang {
20
21 // Colors used for various parts of the AST dump
22 // Do not use bold yellow for any text.  It is hard to read on white screens.
23
24 struct TerminalColor {
25   llvm::raw_ostream::Colors Color;
26   bool Bold;
27 };
28
29 // Red           - CastColor
30 // Green         - TypeColor
31 // Bold Green    - DeclKindNameColor, UndeserializedColor
32 // Yellow        - AddressColor, LocationColor
33 // Blue          - CommentColor, NullColor, IndentColor
34 // Bold Blue     - AttrColor
35 // Bold Magenta  - StmtColor
36 // Cyan          - ValueKindColor, ObjectKindColor
37 // Bold Cyan     - ValueColor, DeclNameColor
38
39 // Decl kind names (VarDecl, FunctionDecl, etc)
40 static const TerminalColor DeclKindNameColor = {llvm::raw_ostream::GREEN, true};
41 // Attr names (CleanupAttr, GuardedByAttr, etc)
42 static const TerminalColor AttrColor = {llvm::raw_ostream::BLUE, true};
43 // Statement names (DeclStmt, ImplicitCastExpr, etc)
44 static const TerminalColor StmtColor = {llvm::raw_ostream::MAGENTA, true};
45 // Comment names (FullComment, ParagraphComment, TextComment, etc)
46 static const TerminalColor CommentColor = {llvm::raw_ostream::BLUE, false};
47
48 // Type names (int, float, etc, plus user defined types)
49 static const TerminalColor TypeColor = {llvm::raw_ostream::GREEN, false};
50
51 // Pointer address
52 static const TerminalColor AddressColor = {llvm::raw_ostream::YELLOW, false};
53 // Source locations
54 static const TerminalColor LocationColor = {llvm::raw_ostream::YELLOW, false};
55
56 // lvalue/xvalue
57 static const TerminalColor ValueKindColor = {llvm::raw_ostream::CYAN, false};
58 // bitfield/objcproperty/objcsubscript/vectorcomponent
59 static const TerminalColor ObjectKindColor = {llvm::raw_ostream::CYAN, false};
60
61 // Null statements
62 static const TerminalColor NullColor = {llvm::raw_ostream::BLUE, false};
63
64 // Undeserialized entities
65 static const TerminalColor UndeserializedColor = {llvm::raw_ostream::GREEN,
66                                                   true};
67
68 // CastKind from CastExpr's
69 static const TerminalColor CastColor = {llvm::raw_ostream::RED, false};
70
71 // Value of the statement
72 static const TerminalColor ValueColor = {llvm::raw_ostream::CYAN, true};
73 // Decl names
74 static const TerminalColor DeclNameColor = {llvm::raw_ostream::CYAN, true};
75
76 // Indents ( `, -. | )
77 static const TerminalColor IndentColor = {llvm::raw_ostream::BLUE, false};
78
79 class ColorScope {
80   llvm::raw_ostream &OS;
81   const bool ShowColors;
82
83 public:
84   ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
85       : OS(OS), ShowColors(ShowColors) {
86     if (ShowColors)
87       OS.changeColor(Color.Color, Color.Bold);
88   }
89   ~ColorScope() {
90     if (ShowColors)
91       OS.resetColor();
92   }
93 };
94
95 } // namespace clang
96
97 #endif // LLVM_CLANG_AST_ASTDUMPERUTILS_H