libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / text-art / theme.h
blobdec09f8439be44ee13efa733412784d621e0bb23
1 /* Classes for abstracting ascii vs unicode output.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef GCC_TEXT_ART_THEME_H
22 #define GCC_TEXT_ART_THEME_H
24 #include "text-art/canvas.h"
25 #include "text-art/box-drawing.h"
27 namespace text_art {
29 class theme
31 public:
32 enum class cell_kind
34 /* A left-hand edge of a range e.g. "├". */
35 X_RULER_LEFT_EDGE,
37 /* Within a range e.g. "─". */
38 X_RULER_MIDDLE,
40 /* A border between two neighboring ranges e.g. "┼". */
41 X_RULER_INTERNAL_EDGE,
43 /* The connector with the text label within a range e.g. "┬". */
44 X_RULER_CONNECTOR_TO_LABEL_BELOW,
46 /* As above, but when the text label is above the ruler. */
47 X_RULER_CONNECTOR_TO_LABEL_ABOVE,
49 /* The vertical connection to a text label. */
50 X_RULER_VERTICAL_CONNECTOR,
52 /* A right-hand edge of a range e.g. "┤". */
53 X_RULER_RIGHT_EDGE,
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,
62 Y_ARROW_UP_HEAD,
63 Y_ARROW_UP_TAIL,
64 Y_ARROW_DOWN_HEAD,
65 Y_ARROW_DOWN_TAIL,
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. "+". */
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. "+". */
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 "|". */
93 virtual ~theme () = default;
95 virtual bool unicode_p () const = 0;
96 virtual bool emojis_p () const = 0;
98 virtual canvas::cell_t
99 get_line_art (directions line_dirs) const = 0;
101 canvas::cell_t get_cell (enum cell_kind kind, unsigned style_idx) const
103 return canvas::cell_t (get_cppchar (kind), false, style_idx);
106 virtual cppchar_t get_cppchar (enum cell_kind kind) const = 0;
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;
116 class ascii_theme : public theme
118 public:
119 bool unicode_p () const final override { return false; }
120 bool emojis_p () const final override { return false; }
122 canvas::cell_t
123 get_line_art (directions line_dirs) const final override;
125 cppchar_t get_cppchar (enum cell_kind kind) const final override;
128 class unicode_theme : public theme
130 public:
131 bool unicode_p () const final override { return true; }
132 bool emojis_p () const override { return false; }
134 canvas::cell_t
135 get_line_art (directions line_dirs) const final override;
137 cppchar_t get_cppchar (enum cell_kind kind) const final override;
140 class emoji_theme : public unicode_theme
142 public:
143 bool emojis_p () const final override { return true; }
146 } // namespace text_art
148 #endif /* GCC_TEXT_ART_THEME_H */