update copyright year range in GDB files
[external/binutils.git] / gdb / ui-out.h
1 /* Output generating routines for GDB.
2
3    Copyright (C) 1999-2017 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 "common/enum-flags.h"
29
30 class ui_out_level;
31 class ui_out_table;
32 struct ui_file;
33
34 /* the current ui_out */
35
36 /* FIXME: This should not be a global but something passed down from main.c
37    or top.c.  */
38 extern struct ui_out **current_ui_current_uiout_ptr (void);
39 #define current_uiout (*current_ui_current_uiout_ptr ())
40
41 /* alignment enum */
42 enum ui_align
43   {
44     ui_left = -1,
45     ui_center,
46     ui_right,
47     ui_noalign
48   };
49
50 /* flags enum */
51 enum ui_out_flag
52   {
53     ui_source_list = (1 << 0),
54   };
55
56 DEF_ENUM_FLAGS_TYPE (ui_out_flag, ui_out_flags);
57
58 /* Prototypes for ui-out API.  */
59
60 /* A result is a recursive data structure consisting of lists and
61    tuples.  */
62
63 enum ui_out_type
64   {
65     ui_out_type_tuple,
66     ui_out_type_list
67   };
68
69 extern struct cleanup *make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out,
70                                                             int nr_cols,
71                                                             int nr_rows,
72                                                             const char *tblid);
73 /* Compatibility wrappers.  */
74
75 extern struct cleanup *make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
76                                                            const char *id);
77
78 extern struct cleanup *make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
79                                                             const char *id);
80
81 class ui_out
82 {
83  public:
84
85   explicit ui_out (ui_out_flags flags = 0);
86   virtual ~ui_out ();
87
88   void push_level (ui_out_type type);
89   void pop_level (ui_out_type type);
90
91   /* A table can be considered a special tuple/list combination with the
92      implied structure: ``table = { hdr = { header, ... } , body = [ {
93      field, ... }, ... ] }''.  If NR_ROWS is negative then there is at
94      least one row.  */
95
96   void table_begin (int nr_cols, int nr_rows, const std::string &tblid);
97   void table_header (int width, ui_align align, const std::string &col_name,
98                      const std::string &col_hdr);
99   void table_body ();
100   void table_end ();
101
102   void begin (ui_out_type type, const char *id);
103   void end (ui_out_type type);
104
105   void field_int (const char *fldname, int value);
106   void field_fmt_int (int width, ui_align align, const char *fldname,
107                       int value);
108   void field_core_addr (const char *fldname, struct gdbarch *gdbarch,
109                         CORE_ADDR address);
110   void field_string (const char *fldname, const char *string);
111   void field_stream (const char *fldname, ui_file *stream);
112   void field_skip (const char *fldname);
113   void field_fmt (const char *fldname, const char *format, ...)
114     ATTRIBUTE_PRINTF (3, 4);
115
116   void spaces (int numspaces);
117   void text (const char *string);
118   void message (const char *format, ...) ATTRIBUTE_PRINTF (2, 3);
119   void wrap_hint (const char *identstring);
120
121   void flush ();
122
123   /* Redirect the output of a ui_out object temporarily.  */
124   int redirect (ui_file *outstream);
125
126   ui_out_flags test_flags (ui_out_flags mask);
127
128   /* HACK: Code in GDB is currently checking to see the type of ui_out
129      builder when determining which output to produce.  This function is
130      a hack to encapsulate that test.  Once GDB manages to separate the
131      CLI/MI from the core of GDB the problem should just go away ....  */
132
133   bool is_mi_like_p ();
134
135   bool query_table_field (int colno, int *width, int *alignment,
136                           const char **col_name);
137
138  protected:
139
140   virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
141     = 0;
142   virtual void do_table_body () = 0;
143   virtual void do_table_end () = 0;
144   virtual void do_table_header (int width, ui_align align,
145                                 const std::string &col_name,
146                                 const std::string &col_hdr) = 0;
147
148   virtual void do_begin (ui_out_type type, const char *id) = 0;
149   virtual void do_end (ui_out_type type) = 0;
150   virtual void do_field_int (int fldno, int width, ui_align align,
151                              const char *fldname, int value) = 0;
152   virtual void do_field_skip (int fldno, int width, ui_align align,
153                               const char *fldname) = 0;
154   virtual void do_field_string (int fldno, int width, ui_align align,
155                                 const char *fldname, const char *string) = 0;
156   virtual void do_field_fmt (int fldno, int width, ui_align align,
157                              const char *fldname, const char *format,
158                              va_list args)
159     ATTRIBUTE_PRINTF (6,0) = 0;
160   virtual void do_spaces (int numspaces) = 0;
161   virtual void do_text (const char *string) = 0;
162   virtual void do_message (const char *format, va_list args)
163     ATTRIBUTE_PRINTF (2,0) = 0;
164   virtual void do_wrap_hint (const char *identstring) = 0;
165   virtual void do_flush () = 0;
166   virtual int do_redirect (struct ui_file * outstream) = 0;
167
168   /* Set as not MI-like by default.  It is overridden in subclasses if
169      necessary.  */
170
171   virtual bool do_is_mi_like_p ()
172   { return false; }
173
174  private:
175
176   ui_out_flags m_flags;
177
178   /* Vector to store and track the ui-out levels.  */
179   std::vector<std::unique_ptr<ui_out_level>> m_levels;
180
181   /* A table, if any.  At present only a single table is supported.  */
182   std::unique_ptr<ui_out_table> m_table_up;
183
184   void verify_field (int *fldno, int *width, ui_align *align);
185
186   int level () const;
187   ui_out_level *current_level () const;
188 };
189
190 #endif /* UI_OUT_H */