clang  14.0.0git
ASTDumperUtils.h
Go to the documentation of this file.
1 //===--- ASTDumperUtils.h - Printing of AST nodes -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements AST utilities for traversal down the tree.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_ASTDUMPERUTILS_H
14 #define LLVM_CLANG_AST_ASTDUMPERUTILS_H
15 
16 #include "llvm/Support/raw_ostream.h"
17 
18 namespace clang {
19 
20 /// Used to specify the format for printing AST dump information.
24 };
25 
26 // Colors used for various parts of the AST dump
27 // Do not use bold yellow for any text. It is hard to read on white screens.
28 
29 struct TerminalColor {
30  llvm::raw_ostream::Colors Color;
31  bool Bold;
32 };
33 
34 // Red - CastColor
35 // Green - TypeColor
36 // Bold Green - DeclKindNameColor, UndeserializedColor
37 // Yellow - AddressColor, LocationColor
38 // Blue - CommentColor, NullColor, IndentColor
39 // Bold Blue - AttrColor
40 // Bold Magenta - StmtColor
41 // Cyan - ValueKindColor, ObjectKindColor
42 // Bold Cyan - ValueColor, DeclNameColor
43 
44 // Decl kind names (VarDecl, FunctionDecl, etc)
45 static const TerminalColor DeclKindNameColor = {llvm::raw_ostream::GREEN, true};
46 // Attr names (CleanupAttr, GuardedByAttr, etc)
47 static const TerminalColor AttrColor = {llvm::raw_ostream::BLUE, true};
48 // Statement names (DeclStmt, ImplicitCastExpr, etc)
49 static const TerminalColor StmtColor = {llvm::raw_ostream::MAGENTA, true};
50 // Comment names (FullComment, ParagraphComment, TextComment, etc)
51 static const TerminalColor CommentColor = {llvm::raw_ostream::BLUE, false};
52 
53 // Type names (int, float, etc, plus user defined types)
54 static const TerminalColor TypeColor = {llvm::raw_ostream::GREEN, false};
55 
56 // Pointer address
57 static const TerminalColor AddressColor = {llvm::raw_ostream::YELLOW, false};
58 // Source locations
59 static const TerminalColor LocationColor = {llvm::raw_ostream::YELLOW, false};
60 
61 // lvalue/xvalue
62 static const TerminalColor ValueKindColor = {llvm::raw_ostream::CYAN, false};
63 // bitfield/objcproperty/objcsubscript/vectorcomponent
64 static const TerminalColor ObjectKindColor = {llvm::raw_ostream::CYAN, false};
65 // contains-errors
66 static const TerminalColor ErrorsColor = {llvm::raw_ostream::RED, true};
67 
68 // Null statements
69 static const TerminalColor NullColor = {llvm::raw_ostream::BLUE, false};
70 
71 // Undeserialized entities
72 static const TerminalColor UndeserializedColor = {llvm::raw_ostream::GREEN,
73  true};
74 
75 // CastKind from CastExpr's
76 static const TerminalColor CastColor = {llvm::raw_ostream::RED, false};
77 
78 // Value of the statement
79 static const TerminalColor ValueColor = {llvm::raw_ostream::CYAN, true};
80 // Decl names
81 static const TerminalColor DeclNameColor = {llvm::raw_ostream::CYAN, true};
82 
83 // Indents ( `, -. | )
84 static const TerminalColor IndentColor = {llvm::raw_ostream::BLUE, false};
85 
86 class ColorScope {
87  llvm::raw_ostream &OS;
88  const bool ShowColors;
89 
90 public:
91  ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
92  : OS(OS), ShowColors(ShowColors) {
93  if (ShowColors)
94  OS.changeColor(Color.Color, Color.Bold);
95  }
97  if (ShowColors)
98  OS.resetColor();
99  }
100 };
101 
102 } // namespace clang
103 
104 #endif // LLVM_CLANG_AST_ASTDUMPERUTILS_H
clang::AttrColor
static const TerminalColor AttrColor
Definition: ASTDumperUtils.h:47
clang::TerminalColor::Color
llvm::raw_ostream::Colors Color
Definition: ASTDumperUtils.h:30
clang::NullColor
static const TerminalColor NullColor
Definition: ASTDumperUtils.h:69
clang::IndentColor
static const TerminalColor IndentColor
Definition: ASTDumperUtils.h:84
clang::ColorScope
Definition: ASTDumperUtils.h:86
clang::LocationColor
static const TerminalColor LocationColor
Definition: ASTDumperUtils.h:59
clang::AddressColor
static const TerminalColor AddressColor
Definition: ASTDumperUtils.h:57
clang::ErrorsColor
static const TerminalColor ErrorsColor
Definition: ASTDumperUtils.h:66
clang::UndeserializedColor
static const TerminalColor UndeserializedColor
Definition: ASTDumperUtils.h:72
clang::ASTDumpOutputFormat
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
Definition: ASTDumperUtils.h:21
clang::ValueColor
static const TerminalColor ValueColor
Definition: ASTDumperUtils.h:79
clang::TerminalColor
Definition: ASTDumperUtils.h:29
clang::TypeColor
static const TerminalColor TypeColor
Definition: ASTDumperUtils.h:54
clang::CastColor
static const TerminalColor CastColor
Definition: ASTDumperUtils.h:76
clang::ObjectKindColor
static const TerminalColor ObjectKindColor
Definition: ASTDumperUtils.h:64
clang::StmtColor
static const TerminalColor StmtColor
Definition: ASTDumperUtils.h:49
clang::ColorScope::ColorScope
ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
Definition: ASTDumperUtils.h:91
clang::ValueKindColor
static const TerminalColor ValueKindColor
Definition: ASTDumperUtils.h:62
clang::TerminalColor::Bold
bool Bold
Definition: ASTDumperUtils.h:31
clang::DeclKindNameColor
static const TerminalColor DeclKindNameColor
Definition: ASTDumperUtils.h:45
clang
Definition: CalledOnceCheck.h:17
clang::ColorScope::~ColorScope
~ColorScope()
Definition: ASTDumperUtils.h:96
clang::CommentColor
static const TerminalColor CommentColor
Definition: ASTDumperUtils.h:51
clang::ADOF_Default
@ ADOF_Default
Definition: ASTDumperUtils.h:22
clang::DeclNameColor
static const TerminalColor DeclNameColor
Definition: ASTDumperUtils.h:81
clang::ADOF_JSON
@ ADOF_JSON
Definition: ASTDumperUtils.h:23