Remove union exp_element
[deliverable/binutils-gdb.git] / gdb / expprint.c
1 /* Print in infix form a struct expression.
2
3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "expression.h"
24 #include "value.h"
25 #include "language.h"
26 #include "parser-defs.h"
27 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
28 #include "target.h"
29 #include "block.h"
30 #include "objfiles.h"
31 #include "valprint.h"
32 #include "cli/cli-style.h"
33 #include "c-lang.h"
34 #include "expop.h"
35 #include "ada-exp.h"
36
37 #include <ctype.h>
38
39 /* Default name for the standard operator OPCODE (i.e., one defined in
40 the definition of enum exp_opcode). */
41
42 const char *
43 op_name (enum exp_opcode opcode)
44 {
45 switch (opcode)
46 {
47 default:
48 {
49 static char buf[30];
50
51 xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode);
52 return buf;
53 }
54 #define OP(name) \
55 case name: \
56 return #name ;
57 #include "std-operator.def"
58 #undef OP
59 }
60 }
61
62 void
63 dump_prefix_expression (struct expression *exp, struct ui_file *stream)
64 {
65 exp->op->dump (stream, 0);
66 }
67
68 namespace expr
69 {
70
71 void
72 dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
73 {
74 fprintf_filtered (stream, _("%*sOperation: %s\n"), depth, "", op_name (op));
75 }
76
77 void
78 dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
79 {
80 fprintf_filtered (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
81 }
82
83 void
84 dump_for_expression (struct ui_file *stream, int depth, struct type *type)
85 {
86 fprintf_filtered (stream, _("%*sType: "), depth, "");
87 type_print (type, nullptr, stream, 0);
88 fprintf_filtered (stream, "\n");
89 }
90
91 void
92 dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
93 {
94 fprintf_filtered (stream, _("%*sConstant: %s\n"), depth, "",
95 core_addr_to_string (addr));
96 }
97
98 void
99 dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
100 {
101 fprintf_filtered (stream, _("%*sInternalvar: $%s\n"), depth, "",
102 internalvar_name (ivar));
103 }
104
105 void
106 dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
107 {
108 fprintf_filtered (stream, _("%*sSymbol: %s\n"), depth, "",
109 sym->print_name ());
110 }
111
112 void
113 dump_for_expression (struct ui_file *stream, int depth, minimal_symbol *msym)
114 {
115 fprintf_filtered (stream, _("%*sMinsym: %s\n"), depth, "",
116 msym->print_name ());
117 }
118
119 void
120 dump_for_expression (struct ui_file *stream, int depth, const block *bl)
121 {
122 fprintf_filtered (stream, _("%*sBlock: %p\n"), depth, "", bl);
123 }
124
125 void
126 dump_for_expression (struct ui_file *stream, int depth,
127 type_instance_flags flags)
128 {
129 fprintf_filtered (stream, _("%*sType flags: "), depth, "");
130 if (flags & TYPE_INSTANCE_FLAG_CONST)
131 fputs_unfiltered ("const ", stream);
132 if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
133 fputs_unfiltered ("volatile", stream);
134 fprintf_filtered (stream, "\n");
135 }
136
137 void
138 dump_for_expression (struct ui_file *stream, int depth,
139 enum c_string_type_values flags)
140 {
141 fprintf_filtered (stream, _("%*sC string flags: "), depth, "");
142 switch (flags & ~C_CHAR)
143 {
144 case C_WIDE_STRING:
145 fputs_unfiltered (_("wide "), stream);
146 break;
147 case C_STRING_16:
148 fputs_unfiltered (_("u16 "), stream);
149 break;
150 case C_STRING_32:
151 fputs_unfiltered (_("u32 "), stream);
152 break;
153 default:
154 fputs_unfiltered (_("ordinary "), stream);
155 break;
156 }
157
158 if ((flags & C_CHAR) != 0)
159 fputs_unfiltered (_("char"), stream);
160 else
161 fputs_unfiltered (_("string"), stream);
162 fputs_unfiltered ("\n", stream);
163 }
164
165 void
166 dump_for_expression (struct ui_file *stream, int depth, objfile *objf)
167 {
168 fprintf_filtered (stream, _("%*sObjfile: %s\n"), depth, "",
169 objfile_name (objf));
170 }
171
172 void
173 dump_for_expression (struct ui_file *stream, int depth,
174 enum range_flag flags)
175 {
176 fprintf_filtered (stream, _("%*sRange:"), depth, "");
177 if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0)
178 fputs_unfiltered (_("low-default "), stream);
179 if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0)
180 fputs_unfiltered (_("high-default "), stream);
181 if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0)
182 fputs_unfiltered (_("high-exclusive "), stream);
183 if ((flags & RANGE_HAS_STRIDE) != 0)
184 fputs_unfiltered (_("has-stride"), stream);
185 fprintf_filtered (stream, "\n");
186 }
187
188 void
189 dump_for_expression (struct ui_file *stream, int depth,
190 const std::unique_ptr<ada_component> &comp)
191 {
192 comp->dump (stream, depth);
193 }
194
195 void
196 float_const_operation::dump (struct ui_file *stream, int depth) const
197 {
198 fprintf_filtered (stream, _("%*sFloat: "), depth, "");
199 print_floating (m_data.data (), m_type, stream);
200 fprintf_filtered (stream, "\n");
201 }
202
203 } /* namespace expr */
This page took 0.03293 seconds and 4 git commands to generate.