libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / text-art / dump.h
blob30b4fb9161fc78e30be680ed9efeaacbc126a97c
1 /* Templates for dumping objects.
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_DUMP_H
22 #define GCC_TEXT_ART_DUMP_H
24 #include "tree-diagnostic.h"
25 #include "text-art/canvas.h"
26 #include "text-art/widget.h"
27 #include "text-art/dump-widget-info.h"
29 /* A family of templates for dumping objects via the text_art::widget
30 system.
31 Any type T that has a make_dump_widget member function ought to be
32 dumpable via these functions. */
34 namespace text_art {
36 /* Dump OBJ to PP, using OBJ's make_dump_widget member function. */
38 template <typename T>
39 void dump_to_pp (const T &obj, text_art::theme *theme, pretty_printer *pp)
41 if (!theme)
42 return;
44 style_manager sm;
45 style tree_style (get_style_from_color_cap_name ("note"));
47 style::id_t tree_style_id (sm.get_or_create_id (tree_style));
49 dump_widget_info dwi (sm, *theme, tree_style_id);
50 if (std::unique_ptr<widget> w = obj.make_dump_widget (dwi))
52 text_art::canvas c (w->to_canvas (dwi.m_sm));
53 c.print_to_pp (pp);
57 /* Dump OBJ to OUTF, using OBJ's make_dump_widget member function. */
59 template <typename T>
60 void dump_to_file (const T &obj, FILE *outf)
62 tree_dump_pretty_printer pp (outf);
63 text_art::theme *theme = global_dc->get_diagram_theme ();
64 dump_to_pp (obj, theme, &pp);
67 /* Dump OBJ to stderr, using OBJ's make_dump_widget member function. */
69 template <typename T>
70 void dump (const T &obj)
72 dump_to_file (obj, stderr);
75 } // namespace text_art
77 #endif /* GCC_TEXT_ART_DUMP_H */