Clang Project

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