Debian Codegraph @

gcc/text-art/dump.h

raw
1 /* Templates for dumping objects.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <[email protected]>.
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_DUMP_H
22 #define GCC_TEXT_ART_DUMP_H
23
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"
28
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. */
33
34 namespace text_art {
35
36 /* Dump OBJ to PP, using OBJ's make_dump_widget member function. */
37
38 template <typename T>
39 void dump_to_pp (const T &obj, text_art::theme *theme, pretty_printer *pp)
40 {
41 if (!theme)
42 return;
43
44 style_manager sm;
45 style tree_style (get_style_from_color_cap_name ("note"));
46
47 style::id_t tree_style_id (sm.get_or_create_id (tree_style));
48
49 dump_widget_info dwi (sm, *theme, tree_style_id);
50 if (std::unique_ptr<widget> w = obj.make_dump_widget (dwi))
51 {
52 text_art::canvas c (w->to_canvas (dwi.m_sm));
53 c.print_to_pp (pp);
54 }
55 }
56
57 /* Dump OBJ to OUTF, using OBJ's make_dump_widget member function. */
58
59 template <typename T>
60 void dump_to_file (const T &obj, FILE *outf)
61 {
62 tree_dump_pretty_printer pp (outf);
63 text_art::theme *theme = global_dc->get_diagram_theme ();
64 dump_to_pp (obj, theme, &pp);
65 }
66
67 /* Dump OBJ to stderr, using OBJ's make_dump_widget member function. */
68
69 template <typename T>
70 void dump (const T &obj)
71 {
72 dump_to_file (obj, stderr);
73 }
74
75 } // namespace text_art
76
77 #endif /* GCC_TEXT_ART_DUMP_H */