GCC Middle and Back End API Reference
theme.h
Go to the documentation of this file.
1/* Classes for abstracting ascii vs unicode output.
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_TEXT_ART_THEME_H
22#define GCC_TEXT_ART_THEME_H
23
24#include "text-art/canvas.h"
26
27namespace text_art {
28
29class theme
30{
31 public:
32 enum class cell_kind
33 {
34 /* A left-hand edge of a range e.g. "├". */
36
37 /* Within a range e.g. "─". */
39
40 /* A border between two neighboring ranges e.g. "┼". */
42
43 /* The connector with the text label within a range e.g. "┬". */
45
46 /* As above, but when the text label is above the ruler. */
48
49 /* The vertical connection to a text label. */
51
52 /* A right-hand edge of a range e.g. "┤". */
54
61
66
67 /* The interprocedural depth indications shown in execution paths
68 with DPF_INLINE_EVENTS. */
76
77 /* CFG stuff. */
78 CFG_RIGHT, /* e.g. "-". */
79 CFG_FROM_RIGHT_TO_DOWN, /* e.g. "+". */
80 CFG_DOWN, /* e.g. "|". */
81 CFG_FROM_DOWN_TO_LEFT, /* e.g. "+". */
82 CFG_LEFT, /* e.g. "-". */
83 CFG_FROM_LEFT_TO_DOWN, /* e.g. "+". */
84 CFG_FROM_DOWN_TO_RIGHT, /* e.g. "+". */
85
86 /* Tree stuff. */
87 TREE_CHILD_NON_FINAL, /* e.g. "├" or "+". */
88 TREE_CHILD_FINAL, /* e.g. "╰" or "`". */
89 TREE_X_CONNECTOR, /* e.g. "─" or "-". */
90 TREE_Y_CONNECTOR /* e.g. "|" or "|". */
91 };
92
93 virtual ~theme () = default;
94
95 virtual bool unicode_p () const = 0;
96 virtual bool emojis_p () const = 0;
97
98 virtual canvas::cell_t
99 get_line_art (directions line_dirs) const = 0;
100
101 canvas::cell_t get_cell (enum cell_kind kind, unsigned style_idx) const
102 {
103 return canvas::cell_t (get_cppchar (kind), false, style_idx);
104 }
105
106 virtual cppchar_t get_cppchar (enum cell_kind kind) const = 0;
107
108 enum class y_arrow_dir { UP, DOWN };
110 int x,
111 canvas::range_t y_range,
112 y_arrow_dir dir,
113 style::id_t style_id) const;
114};
115
116class ascii_theme : public theme
117{
118 public:
119 bool unicode_p () const final override { return false; }
120 bool emojis_p () const final override { return false; }
121
123 get_line_art (directions line_dirs) const final override;
124
125 cppchar_t get_cppchar (enum cell_kind kind) const final override;
126};
127
128class unicode_theme : public theme
129{
130 public:
131 bool unicode_p () const final override { return true; }
132 bool emojis_p () const override { return false; }
133
135 get_line_art (directions line_dirs) const final override;
136
137 cppchar_t get_cppchar (enum cell_kind kind) const final override;
138};
139
141{
142public:
143 bool emojis_p () const final override { return true; }
144};
145
146} // namespace text_art
147
148#endif /* GCC_TEXT_ART_THEME_H */
Definition theme.h:117
bool emojis_p() const final override
Definition theme.h:120
cppchar_t get_cppchar(enum cell_kind kind) const final override
Definition theme.cc:92
bool unicode_p() const final override
Definition theme.h:119
canvas::cell_t get_line_art(directions line_dirs) const final override
Definition theme.cc:73
Definition canvas.h:38
styled_unichar cell_t
Definition canvas.h:40
range< class canvas > range_t
Definition canvas.h:43
Definition theme.h:141
bool emojis_p() const final override
Definition theme.h:143
Definition theme.h:30
y_arrow_dir
Definition theme.h:108
@ DOWN
Definition theme.h:108
@ UP
Definition theme.h:108
cell_kind
Definition theme.h:33
@ INTERPROCEDURAL_DEPTH_MARKER
Definition theme.h:72
@ TEXT_BORDER_BOTTOM_LEFT
Definition theme.h:59
@ TREE_Y_CONNECTOR
Definition theme.h:90
@ CFG_FROM_DOWN_TO_RIGHT
Definition theme.h:84
@ TREE_X_CONNECTOR
Definition theme.h:89
@ CFG_RIGHT
Definition theme.h:78
@ TEXT_BORDER_HORIZONTAL
Definition theme.h:55
@ INTERPROCEDURAL_PUSH_FRAME_LEFT
Definition theme.h:69
@ X_RULER_LEFT_EDGE
Definition theme.h:35
@ CFG_FROM_DOWN_TO_LEFT
Definition theme.h:81
@ TEXT_BORDER_VERTICAL
Definition theme.h:56
@ TEXT_BORDER_BOTTOM_RIGHT
Definition theme.h:60
@ INTERPROCEDURAL_POP_FRAMES_MIDDLE
Definition theme.h:74
@ CFG_LEFT
Definition theme.h:82
@ CFG_DOWN
Definition theme.h:80
@ TREE_CHILD_NON_FINAL
Definition theme.h:87
@ INTERPROCEDURAL_PUSH_FRAME_MIDDLE
Definition theme.h:70
@ X_RULER_CONNECTOR_TO_LABEL_ABOVE
Definition theme.h:47
@ CFG_FROM_LEFT_TO_DOWN
Definition theme.h:83
@ TEXT_BORDER_TOP_RIGHT
Definition theme.h:58
@ X_RULER_INTERNAL_EDGE
Definition theme.h:41
@ Y_ARROW_DOWN_HEAD
Definition theme.h:64
@ INTERPROCEDURAL_POP_FRAMES_LEFT
Definition theme.h:73
@ Y_ARROW_DOWN_TAIL
Definition theme.h:65
@ CFG_FROM_RIGHT_TO_DOWN
Definition theme.h:79
@ X_RULER_MIDDLE
Definition theme.h:38
@ Y_ARROW_UP_TAIL
Definition theme.h:63
@ INTERPROCEDURAL_POP_FRAMES_RIGHT
Definition theme.h:75
@ X_RULER_CONNECTOR_TO_LABEL_BELOW
Definition theme.h:44
@ INTERPROCEDURAL_PUSH_FRAME_RIGHT
Definition theme.h:71
@ TREE_CHILD_FINAL
Definition theme.h:88
@ X_RULER_RIGHT_EDGE
Definition theme.h:53
@ Y_ARROW_UP_HEAD
Definition theme.h:62
@ TEXT_BORDER_TOP_LEFT
Definition theme.h:57
@ X_RULER_VERTICAL_CONNECTOR
Definition theme.h:50
virtual bool emojis_p() const =0
virtual ~theme()=default
void paint_y_arrow(canvas &canvas, int x, canvas::range_t y_range, y_arrow_dir dir, style::id_t style_id) const
Definition theme.cc:36
virtual bool unicode_p() const =0
virtual canvas::cell_t get_line_art(directions line_dirs) const =0
canvas::cell_t get_cell(enum cell_kind kind, unsigned style_idx) const
Definition theme.h:101
virtual cppchar_t get_cppchar(enum cell_kind kind) const =0
Definition theme.h:129
cppchar_t get_cppchar(enum cell_kind kind) const final override
Definition theme.cc:179
canvas::cell_t get_line_art(directions line_dirs) const final override
Definition theme.cc:173
bool emojis_p() const override
Definition theme.h:132
bool unicode_p() const final override
Definition theme.h:131
void final(rtx_insn *first, FILE *file, int optimize_p)
Definition final.cc:2009
Definition diagnostics/context.h:57
Definition types.h:499
unsigned char id_t
Definition types.h:223