libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / text-art / tree-widget.h
blob73550ccf4eae075179f7508fdc5d9dd07a7f409a
1 /* Tree diagrams.
2 Copyright (C) 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_TREE_WIDGET_H
22 #define GCC_TEXT_ART_TREE_WIDGET_H
24 #include "text-art/canvas.h"
25 #include "text-art/widget.h"
27 namespace text_art {
29 class dump_widget_info;
31 class tree_widget : public widget
33 public:
34 tree_widget (std::unique_ptr<widget> node,
35 const theme &theme,
36 style::id_t style_id)
37 : m_node (std::move (node)),
38 m_theme (theme),
39 m_style_id (style_id)
43 static std::unique_ptr<tree_widget>
44 make (styled_string str, const theme &theme, style::id_t style_id);
46 static std::unique_ptr<tree_widget>
47 make (const dump_widget_info &dwi, pretty_printer *pp);
49 static std::unique_ptr<tree_widget>
50 make (const dump_widget_info &dwi, const char *str);
52 static std::unique_ptr<tree_widget>
53 from_fmt (const dump_widget_info &dwi,
54 printer_fn format_decoder,
55 const char *fmt, ...)
56 ATTRIBUTE_GCC_PPDIAG(3, 4);
58 const char *get_desc () const override;
59 canvas::size_t calc_req_size () final override;
60 void update_child_alloc_rects () final override;
61 void paint_to_canvas (canvas &canvas) final override;
63 void add_child (std::unique_ptr<widget> child)
65 if (child)
66 m_children.push_back (std::move (child));
69 size_t get_num_children () const
71 return m_children.size ();
74 private:
75 std::unique_ptr<widget> m_node;
76 std::vector<std::unique_ptr<widget>> m_children;
77 const theme &m_theme;
78 style::id_t m_style_id;
81 } // namespace text_art
83 #endif /* GCC_TEXT_ART_TREE_WIDGET_H */