Line data Source code
1 : /* Classes for abstracting ascii vs unicode output.
2 : Copyright (C) 2023-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it
8 : under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful, but
13 : WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along 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"
25 : #include "text-art/box-drawing.h"
26 :
27 : namespace text_art {
28 :
29 756721 : class theme
30 : {
31 : public:
32 : enum class cell_kind
33 : {
34 : /* A left-hand edge of a range e.g. "├". */
35 : X_RULER_LEFT_EDGE,
36 :
37 : /* Within a range e.g. "─". */
38 : X_RULER_MIDDLE,
39 :
40 : /* A border between two neighboring ranges e.g. "┼". */
41 : X_RULER_INTERNAL_EDGE,
42 :
43 : /* The connector with the text label within a range e.g. "┬". */
44 : X_RULER_CONNECTOR_TO_LABEL_BELOW,
45 :
46 : /* As above, but when the text label is above the ruler. */
47 : X_RULER_CONNECTOR_TO_LABEL_ABOVE,
48 :
49 : /* The vertical connection to a text label. */
50 : X_RULER_VERTICAL_CONNECTOR,
51 :
52 : /* A right-hand edge of a range e.g. "┤". */
53 : X_RULER_RIGHT_EDGE,
54 :
55 : TEXT_BORDER_HORIZONTAL,
56 : TEXT_BORDER_VERTICAL,
57 : TEXT_BORDER_TOP_LEFT,
58 : TEXT_BORDER_TOP_RIGHT,
59 : TEXT_BORDER_BOTTOM_LEFT,
60 : TEXT_BORDER_BOTTOM_RIGHT,
61 :
62 : Y_ARROW_UP_HEAD,
63 : Y_ARROW_UP_TAIL,
64 : Y_ARROW_DOWN_HEAD,
65 : Y_ARROW_DOWN_TAIL,
66 :
67 : /* The interprocedural depth indications shown in execution paths
68 : with DPF_INLINE_EVENTS. */
69 : INTERPROCEDURAL_PUSH_FRAME_LEFT, /* e.g. "+". */
70 : INTERPROCEDURAL_PUSH_FRAME_MIDDLE, /* e.g. "-". */
71 : INTERPROCEDURAL_PUSH_FRAME_RIGHT, /* e.g. ">". */
72 : INTERPROCEDURAL_DEPTH_MARKER, /* e.g. "|". */
73 : INTERPROCEDURAL_POP_FRAMES_LEFT, /* e.g. "<". */
74 : INTERPROCEDURAL_POP_FRAMES_MIDDLE, /* e.g. "-". */
75 : INTERPROCEDURAL_POP_FRAMES_RIGHT, /* e.g. "+". */
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 2812 : 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 8621 : canvas::cell_t get_cell (enum cell_kind kind, unsigned style_idx) const
102 : {
103 8621 : 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 };
109 : void paint_y_arrow (canvas &canvas,
110 : int x,
111 : canvas::range_t y_range,
112 : y_arrow_dir dir,
113 : style::id_t style_id) const;
114 : };
115 :
116 674151 : class ascii_theme : public theme
117 : {
118 : public:
119 1 : bool unicode_p () const final override { return false; }
120 1822 : bool emojis_p () const final override { return false; }
121 :
122 : canvas::cell_t
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 :
128 379 : class unicode_theme : public theme
129 : {
130 : public:
131 41 : bool unicode_p () const final override { return true; }
132 251 : bool emojis_p () const override { return false; }
133 :
134 : canvas::cell_t
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 :
140 85003 : class emoji_theme : public unicode_theme
141 : {
142 : public:
143 55 : bool emojis_p () const final override { return true; }
144 : };
145 :
146 : } // namespace text_art
147 :
148 : #endif /* GCC_TEXT_ART_THEME_H */
|