GCC Middle and Back End API Reference
dump.h
Go to the documentation of this file.
1/* Templates for dumping objects.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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"
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
34namespace text_art {
35
36/* Dump OBJ to PP, using OBJ's make_dump_widget member function. */
37
38template <typename T>
40{
41 if (!theme)
42 return;
43
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
59template <typename T>
60void dump_to_file (const T &obj, FILE *outf)
61{
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
69template <typename T>
70void 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 */
Definition pretty-print.h:241
Definition canvas.h:38
Definition types.h:342
style::id_t get_or_create_id(const style &style)
Definition style.cc:284
Definition theme.h:30
Definition tree-diagnostic.h:63
diagnostics::context * global_dc
Definition diagnostic-global-context.cc:35
static struct token T
Definition gengtype-parse.cc:45
Definition diagnostics/context.h:56
void dump(const T &obj)
Definition dump.h:70
void dump_to_pp(const T &obj, text_art::theme *theme, pretty_printer *pp)
Definition dump.h:39
style get_style_from_color_cap_name(const char *name)
Definition style.cc:263
void dump_to_file(const T &obj, FILE *outf)
Definition dump.h:60
Definition gengtype.h:377
Definition dump-widget-info.h:31
text_art::style_manager & m_sm
Definition dump-widget-info.h:46
Definition types.h:222
unsigned char id_t
Definition types.h:223