Remove the ui_out_style_kind enum
[deliverable/binutils-gdb.git] / gdb / ui-out.h
1 /* Output generating routines for GDB.
2
3 Copyright (C) 1999-2019 Free Software Foundation, Inc.
4
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23 #ifndef UI_OUT_H
24 #define UI_OUT_H 1
25
26 #include <vector>
27
28 #include "gdbsupport/enum-flags.h"
29 #include "ui-style.h"
30
31 class ui_out_level;
32 class ui_out_table;
33 struct ui_file;
34
35 /* the current ui_out */
36
37 /* FIXME: This should not be a global but something passed down from main.c
38 or top.c. */
39 extern struct ui_out **current_ui_current_uiout_ptr (void);
40 #define current_uiout (*current_ui_current_uiout_ptr ())
41
42 /* alignment enum */
43 enum ui_align
44 {
45 ui_left = -1,
46 ui_center,
47 ui_right,
48 ui_noalign
49 };
50
51 /* flags enum */
52 enum ui_out_flag
53 {
54 ui_source_list = (1 << 0),
55 fix_multi_location_breakpoint_output = (1 << 1),
56 };
57
58 DEF_ENUM_FLAGS_TYPE (ui_out_flag, ui_out_flags);
59
60 /* Prototypes for ui-out API. */
61
62 /* A result is a recursive data structure consisting of lists and
63 tuples. */
64
65 enum ui_out_type
66 {
67 ui_out_type_tuple,
68 ui_out_type_list
69 };
70
71 class ui_out
72 {
73 public:
74
75 explicit ui_out (ui_out_flags flags = 0);
76 virtual ~ui_out ();
77
78 void push_level (ui_out_type type);
79 void pop_level (ui_out_type type);
80
81 /* A table can be considered a special tuple/list combination with the
82 implied structure: ``table = { hdr = { header, ... } , body = [ {
83 field, ... }, ... ] }''. If NR_ROWS is negative then there is at
84 least one row. */
85
86 void table_begin (int nr_cols, int nr_rows, const std::string &tblid);
87 void table_header (int width, ui_align align, const std::string &col_name,
88 const std::string &col_hdr);
89 void table_body ();
90 void table_end ();
91
92 void begin (ui_out_type type, const char *id);
93 void end (ui_out_type type);
94
95 void field_signed (const char *fldname, LONGEST value);
96 void field_fmt_signed (int width, ui_align align, const char *fldname,
97 LONGEST value);
98 /* Like field_signed, but print an unsigned value. */
99 void field_unsigned (const char *fldname, ULONGEST value);
100 void field_core_addr (const char *fldname, struct gdbarch *gdbarch,
101 CORE_ADDR address);
102 void field_string (const char *fldname, const char *string,
103 const ui_file_style &style = ui_file_style ());
104 void field_string (const char *fldname, const std::string &string);
105 void field_stream (const char *fldname, string_file &stream,
106 const ui_file_style &style = ui_file_style ());
107 void field_skip (const char *fldname);
108 void field_fmt (const char *fldname, const char *format, ...)
109 ATTRIBUTE_PRINTF (3, 4);
110
111 void spaces (int numspaces);
112 void text (const char *string);
113 void message (const char *format, ...) ATTRIBUTE_PRINTF (2, 3);
114 void wrap_hint (const char *identstring);
115
116 void flush ();
117
118 /* Redirect the output of a ui_out object temporarily. */
119 void redirect (ui_file *outstream);
120
121 ui_out_flags test_flags (ui_out_flags mask);
122
123 /* HACK: Code in GDB is currently checking to see the type of ui_out
124 builder when determining which output to produce. This function is
125 a hack to encapsulate that test. Once GDB manages to separate the
126 CLI/MI from the core of GDB the problem should just go away .... */
127
128 bool is_mi_like_p () const;
129
130 bool query_table_field (int colno, int *width, int *alignment,
131 const char **col_name);
132
133 /* Return true if this stream is prepared to handle style
134 escapes. */
135 virtual bool can_emit_style_escape () const = 0;
136
137 protected:
138
139 virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
140 = 0;
141 virtual void do_table_body () = 0;
142 virtual void do_table_end () = 0;
143 virtual void do_table_header (int width, ui_align align,
144 const std::string &col_name,
145 const std::string &col_hdr) = 0;
146
147 virtual void do_begin (ui_out_type type, const char *id) = 0;
148 virtual void do_end (ui_out_type type) = 0;
149 virtual void do_field_signed (int fldno, int width, ui_align align,
150 const char *fldname, LONGEST value) = 0;
151 virtual void do_field_unsigned (int fldno, int width, ui_align align,
152 const char *fldname, ULONGEST value) = 0;
153 virtual void do_field_skip (int fldno, int width, ui_align align,
154 const char *fldname) = 0;
155 virtual void do_field_string (int fldno, int width, ui_align align,
156 const char *fldname, const char *string,
157 const ui_file_style &style) = 0;
158 virtual void do_field_fmt (int fldno, int width, ui_align align,
159 const char *fldname, const char *format,
160 va_list args)
161 ATTRIBUTE_PRINTF (6,0) = 0;
162 virtual void do_spaces (int numspaces) = 0;
163 virtual void do_text (const char *string) = 0;
164 virtual void do_message (const char *format, va_list args)
165 ATTRIBUTE_PRINTF (2,0) = 0;
166 virtual void do_wrap_hint (const char *identstring) = 0;
167 virtual void do_flush () = 0;
168 virtual void do_redirect (struct ui_file *outstream) = 0;
169
170 /* Set as not MI-like by default. It is overridden in subclasses if
171 necessary. */
172
173 virtual bool do_is_mi_like_p () const
174 { return false; }
175
176 private:
177
178 ui_out_flags m_flags;
179
180 /* Vector to store and track the ui-out levels. */
181 std::vector<std::unique_ptr<ui_out_level>> m_levels;
182
183 /* A table, if any. At present only a single table is supported. */
184 std::unique_ptr<ui_out_table> m_table_up;
185
186 void verify_field (int *fldno, int *width, ui_align *align);
187
188 int level () const;
189 ui_out_level *current_level () const;
190 };
191
192 /* Start a new tuple or list on construction, and end it on
193 destruction. Normally this is used via the typedefs
194 ui_out_emit_tuple and ui_out_emit_list. */
195 template<ui_out_type Type>
196 class ui_out_emit_type
197 {
198 public:
199
200 ui_out_emit_type (struct ui_out *uiout, const char *id)
201 : m_uiout (uiout)
202 {
203 uiout->begin (Type, id);
204 }
205
206 ~ui_out_emit_type ()
207 {
208 m_uiout->end (Type);
209 }
210
211 DISABLE_COPY_AND_ASSIGN (ui_out_emit_type<Type>);
212
213 private:
214
215 struct ui_out *m_uiout;
216 };
217
218 typedef ui_out_emit_type<ui_out_type_tuple> ui_out_emit_tuple;
219 typedef ui_out_emit_type<ui_out_type_list> ui_out_emit_list;
220
221 /* Start a new table on construction, and end the table on
222 destruction. */
223 class ui_out_emit_table
224 {
225 public:
226
227 ui_out_emit_table (struct ui_out *uiout, int nr_cols, int nr_rows,
228 const char *tblid)
229 : m_uiout (uiout)
230 {
231 m_uiout->table_begin (nr_cols, nr_rows, tblid);
232 }
233
234 ~ui_out_emit_table ()
235 {
236 m_uiout->table_end ();
237 }
238
239 ui_out_emit_table (const ui_out_emit_table &) = delete;
240 ui_out_emit_table &operator= (const ui_out_emit_table &) = delete;
241
242 private:
243
244 struct ui_out *m_uiout;
245 };
246
247 /* On destruction, pop the last redirection by calling the uiout's
248 redirect method with a NULL parameter. */
249 class ui_out_redirect_pop
250 {
251 public:
252
253 ui_out_redirect_pop (ui_out *uiout)
254 : m_uiout (uiout)
255 {
256 }
257
258 ~ui_out_redirect_pop ()
259 {
260 m_uiout->redirect (NULL);
261 }
262
263 ui_out_redirect_pop (const ui_out_redirect_pop &) = delete;
264 ui_out_redirect_pop &operator= (const ui_out_redirect_pop &) = delete;
265
266 private:
267 struct ui_out *m_uiout;
268 };
269
270 #endif /* UI_OUT_H */
This page took 0.038242 seconds and 5 git commands to generate.