clang
23.0.0git
include
clang
AST
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.
21
enum
ASTDumpOutputFormat
{
22
ADOF_Default
,
23
ADOF_JSON
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
struct
ASTDumpColor
{
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
89
class
ColorScope
{
90
llvm::raw_ostream &OS;
91
const
bool
ShowColors;
92
93
public
:
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
}
99
~ColorScope
() {
100
if
(ShowColors)
101
OS.resetColor();
102
}
103
};
104
105
}
// namespace clang
106
107
#endif
// LLVM_CLANG_AST_ASTDUMPERUTILS_H
clang::ColorScope::~ColorScope
~ColorScope()
Definition
ASTDumperUtils.h:99
clang::ColorScope::ColorScope
ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
Definition
ASTDumperUtils.h:94
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition
CalledOnceCheck.h:17
clang::ASTDumpOutputFormat
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
Definition
ASTDumperUtils.h:21
clang::ADOF_JSON
@ ADOF_JSON
Definition
ASTDumperUtils.h:23
clang::ADOF_Default
@ ADOF_Default
Definition
ASTDumperUtils.h:22
clang::ASTDumpColor
Definition
ASTDumperUtils.h:34
clang::ASTDumpColor::Value
static constexpr TerminalColor Value
Definition
ASTDumperUtils.h:81
clang::ASTDumpColor::Address
static constexpr TerminalColor Address
Definition
ASTDumperUtils.h:59
clang::ASTDumpColor::Comment
static constexpr TerminalColor Comment
Definition
ASTDumperUtils.h:53
clang::ASTDumpColor::DeclKindName
static constexpr TerminalColor DeclKindName
Definition
ASTDumperUtils.h:46
clang::ASTDumpColor::ObjectKind
static constexpr TerminalColor ObjectKind
Definition
ASTDumperUtils.h:66
clang::ASTDumpColor::Null
static constexpr TerminalColor Null
Definition
ASTDumperUtils.h:71
clang::ASTDumpColor::Location
static constexpr TerminalColor Location
Definition
ASTDumperUtils.h:61
clang::ASTDumpColor::Attr
static constexpr TerminalColor Attr
Definition
ASTDumperUtils.h:49
clang::ASTDumpColor::DeclName
static constexpr TerminalColor DeclName
Definition
ASTDumperUtils.h:83
clang::ASTDumpColor::Stmt
static constexpr TerminalColor Stmt
Definition
ASTDumperUtils.h:51
clang::ASTDumpColor::Indent
static constexpr TerminalColor Indent
Definition
ASTDumperUtils.h:86
clang::ASTDumpColor::Cast
static constexpr TerminalColor Cast
Definition
ASTDumperUtils.h:78
clang::ASTDumpColor::ValueKind
static constexpr TerminalColor ValueKind
Definition
ASTDumperUtils.h:64
clang::ASTDumpColor::Undeserialized
static constexpr TerminalColor Undeserialized
Definition
ASTDumperUtils.h:74
clang::ASTDumpColor::Type
static constexpr TerminalColor Type
Definition
ASTDumperUtils.h:56
clang::ASTDumpColor::Errors
static constexpr TerminalColor Errors
Definition
ASTDumperUtils.h:68
clang::TerminalColor
Definition
ASTDumperUtils.h:29
clang::TerminalColor::Bold
bool Bold
Definition
ASTDumperUtils.h:31
clang::TerminalColor::Color
llvm::raw_ostream::Colors Color
Definition
ASTDumperUtils.h:30
Generated on
for clang by
1.14.0