clang 23.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
18namespace clang {
19
20/// Used to specify the format for printing AST dump information.
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
30 llvm::raw_ostream::Colors Color;
31 bool Bold;
32};
33
35 // Red - Cast
36 // Green - Type
37 // Bold Green - DeclKindName, Undeserialized
38 // Yellow - Address, Location
39 // Blue - Comment, Null, Indent
40 // Bold Blue - Attr
41 // Bold Magenta - Stmt
42 // Cyan - ValueKind, ObjectKind
43 // Bold Cyan - Value, DeclName
44
45 // Decl kind names (VarDecl, FunctionDecl, etc)
46 static constexpr TerminalColor DeclKindName = {llvm::raw_ostream::GREEN,
47 true};
48 // Attr names (CleanupAttr, GuardedByAttr, etc)
49 static constexpr TerminalColor Attr = {llvm::raw_ostream::BLUE, true};
50 // Statement names (DeclStmt, ImplicitCastExpr, etc)
51 static constexpr TerminalColor Stmt = {llvm::raw_ostream::MAGENTA, true};
52 // Comment names (FullComment, ParagraphComment, TextComment, etc)
53 static constexpr TerminalColor Comment = {llvm::raw_ostream::BLUE, false};
54
55 // Type names (int, float, etc, plus user defined types)
56 static constexpr TerminalColor Type = {llvm::raw_ostream::GREEN, false};
57
58 // Pointer address
59 static constexpr TerminalColor Address = {llvm::raw_ostream::YELLOW, false};
60 // Source locations
61 static constexpr TerminalColor Location = {llvm::raw_ostream::YELLOW, false};
62
63 // lvalue/xvalue
64 static constexpr TerminalColor ValueKind = {llvm::raw_ostream::CYAN, false};
65 // bitfield/objcproperty/objcsubscript/vectorcomponent
66 static constexpr TerminalColor ObjectKind = {llvm::raw_ostream::CYAN, false};
67 // contains-errors
68 static constexpr TerminalColor Errors = {llvm::raw_ostream::RED, true};
69
70 // Null statements
71 static constexpr TerminalColor Null = {llvm::raw_ostream::BLUE, false};
72
73 // Undeserialized entities
74 static constexpr TerminalColor Undeserialized = {llvm::raw_ostream::GREEN,
75 true};
76
77 // CastKind from CastExpr's
78 static constexpr TerminalColor Cast = {llvm::raw_ostream::RED, false};
79
80 // Value of the statement
81 static constexpr TerminalColor Value = {llvm::raw_ostream::CYAN, true};
82 // Decl names
83 static constexpr TerminalColor DeclName = {llvm::raw_ostream::CYAN, true};
84
85 // Indents ( `, -. | )
86 static constexpr TerminalColor Indent = {llvm::raw_ostream::BLUE, false};
87};
88
90 llvm::raw_ostream &OS;
91 const bool ShowColors;
92
93public:
94 ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
95 : OS(OS), ShowColors(ShowColors) {
96 if (ShowColors)
97 OS.changeColor(Color.Color, Color.Bold);
98 }
100 if (ShowColors)
101 OS.resetColor();
102 }
103};
104
105} // namespace clang
106
107#endif // LLVM_CLANG_AST_ASTDUMPERUTILS_H
ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
The JSON file list parser is used to communicate input to InstallAPI.
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
static constexpr TerminalColor Value
static constexpr TerminalColor Address
static constexpr TerminalColor Comment
static constexpr TerminalColor DeclKindName
static constexpr TerminalColor ObjectKind
static constexpr TerminalColor Null
static constexpr TerminalColor Location
static constexpr TerminalColor Attr
static constexpr TerminalColor DeclName
static constexpr TerminalColor Stmt
static constexpr TerminalColor Indent
static constexpr TerminalColor Cast
static constexpr TerminalColor ValueKind
static constexpr TerminalColor Undeserialized
static constexpr TerminalColor Type
static constexpr TerminalColor Errors
llvm::raw_ostream::Colors Color