expprint.c revision 1.8 1 1.1 christos /* Print in infix form a struct expression.
2 1.1 christos
3 1.8 christos Copyright (C) 1986-2019 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "defs.h"
21 1.1 christos #include "symtab.h"
22 1.1 christos #include "gdbtypes.h"
23 1.1 christos #include "expression.h"
24 1.1 christos #include "value.h"
25 1.1 christos #include "language.h"
26 1.1 christos #include "parser-defs.h"
27 1.1 christos #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
28 1.1 christos #include "target.h"
29 1.1 christos #include "block.h"
30 1.1 christos #include "objfiles.h"
31 1.1 christos #include "valprint.h"
32 1.1 christos
33 1.1 christos #include <ctype.h>
34 1.1 christos
35 1.1 christos void
36 1.1 christos print_expression (struct expression *exp, struct ui_file *stream)
37 1.1 christos {
38 1.1 christos int pc = 0;
39 1.1 christos
40 1.1 christos print_subexp (exp, &pc, stream, PREC_NULL);
41 1.1 christos }
42 1.1 christos
43 1.1 christos /* Print the subexpression of EXP that starts in position POS, on STREAM.
44 1.1 christos PREC is the precedence of the surrounding operator;
45 1.1 christos if the precedence of the main operator of this subexpression is less,
46 1.1 christos parentheses are needed here. */
47 1.1 christos
48 1.1 christos void
49 1.1 christos print_subexp (struct expression *exp, int *pos,
50 1.1 christos struct ui_file *stream, enum precedence prec)
51 1.1 christos {
52 1.1 christos exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec);
53 1.1 christos }
54 1.1 christos
55 1.1 christos /* Standard implementation of print_subexp for use in language_defn
56 1.1 christos vectors. */
57 1.1 christos void
58 1.1 christos print_subexp_standard (struct expression *exp, int *pos,
59 1.1 christos struct ui_file *stream, enum precedence prec)
60 1.1 christos {
61 1.1 christos unsigned tem;
62 1.1 christos const struct op_print *op_print_tab;
63 1.1 christos int pc;
64 1.1 christos unsigned nargs;
65 1.7 christos const char *op_str;
66 1.1 christos int assign_modify = 0;
67 1.1 christos enum exp_opcode opcode;
68 1.1 christos enum precedence myprec = PREC_NULL;
69 1.1 christos /* Set to 1 for a right-associative operator. */
70 1.1 christos int assoc = 0;
71 1.1 christos struct value *val;
72 1.1 christos char *tempstr = NULL;
73 1.1 christos
74 1.1 christos op_print_tab = exp->language_defn->la_op_print_tab;
75 1.1 christos pc = (*pos)++;
76 1.1 christos opcode = exp->elts[pc].opcode;
77 1.1 christos switch (opcode)
78 1.1 christos {
79 1.1 christos /* Common ops */
80 1.1 christos
81 1.1 christos case OP_TYPE:
82 1.1 christos (*pos) += 2;
83 1.1 christos type_print (exp->elts[pc + 1].type, "", stream, 0);
84 1.1 christos return;
85 1.1 christos
86 1.1 christos case OP_SCOPE:
87 1.1 christos myprec = PREC_PREFIX;
88 1.1 christos assoc = 0;
89 1.8 christos fputs_filtered (TYPE_NAME (exp->elts[pc + 1].type), stream);
90 1.1 christos fputs_filtered ("::", stream);
91 1.1 christos nargs = longest_to_int (exp->elts[pc + 2].longconst);
92 1.1 christos (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1);
93 1.1 christos fputs_filtered (&exp->elts[pc + 3].string, stream);
94 1.1 christos return;
95 1.1 christos
96 1.1 christos case OP_LONG:
97 1.1 christos {
98 1.1 christos struct value_print_options opts;
99 1.1 christos
100 1.1 christos get_no_prettyformat_print_options (&opts);
101 1.1 christos (*pos) += 3;
102 1.1 christos value_print (value_from_longest (exp->elts[pc + 1].type,
103 1.1 christos exp->elts[pc + 2].longconst),
104 1.1 christos stream, &opts);
105 1.1 christos }
106 1.1 christos return;
107 1.1 christos
108 1.8 christos case OP_FLOAT:
109 1.1 christos {
110 1.1 christos struct value_print_options opts;
111 1.1 christos
112 1.1 christos get_no_prettyformat_print_options (&opts);
113 1.1 christos (*pos) += 3;
114 1.8 christos value_print (value_from_contents (exp->elts[pc + 1].type,
115 1.8 christos exp->elts[pc + 2].floatconst),
116 1.1 christos stream, &opts);
117 1.1 christos }
118 1.1 christos return;
119 1.1 christos
120 1.1 christos case OP_VAR_VALUE:
121 1.1 christos {
122 1.1 christos const struct block *b;
123 1.1 christos
124 1.1 christos (*pos) += 3;
125 1.1 christos b = exp->elts[pc + 1].block;
126 1.1 christos if (b != NULL
127 1.1 christos && BLOCK_FUNCTION (b) != NULL
128 1.1 christos && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL)
129 1.1 christos {
130 1.1 christos fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream);
131 1.1 christos fputs_filtered ("::", stream);
132 1.1 christos }
133 1.1 christos fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream);
134 1.1 christos }
135 1.1 christos return;
136 1.1 christos
137 1.8 christos case OP_VAR_MSYM_VALUE:
138 1.8 christos {
139 1.8 christos (*pos) += 3;
140 1.8 christos fputs_filtered (MSYMBOL_PRINT_NAME (exp->elts[pc + 2].msymbol), stream);
141 1.8 christos }
142 1.8 christos return;
143 1.8 christos
144 1.8 christos case OP_FUNC_STATIC_VAR:
145 1.8 christos {
146 1.8 christos tem = longest_to_int (exp->elts[pc + 1].longconst);
147 1.8 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
148 1.8 christos fputs_filtered (&exp->elts[pc + 1].string, stream);
149 1.8 christos }
150 1.8 christos return;
151 1.8 christos
152 1.1 christos case OP_VAR_ENTRY_VALUE:
153 1.1 christos {
154 1.1 christos (*pos) += 2;
155 1.1 christos fprintf_filtered (stream, "%s@entry",
156 1.1 christos SYMBOL_PRINT_NAME (exp->elts[pc + 1].symbol));
157 1.1 christos }
158 1.1 christos return;
159 1.1 christos
160 1.1 christos case OP_LAST:
161 1.1 christos (*pos) += 2;
162 1.1 christos fprintf_filtered (stream, "$%d",
163 1.1 christos longest_to_int (exp->elts[pc + 1].longconst));
164 1.1 christos return;
165 1.1 christos
166 1.1 christos case OP_REGISTER:
167 1.1 christos {
168 1.1 christos const char *name = &exp->elts[pc + 2].string;
169 1.1 christos
170 1.1 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
171 1.1 christos fprintf_filtered (stream, "$%s", name);
172 1.1 christos return;
173 1.1 christos }
174 1.1 christos
175 1.1 christos case OP_BOOL:
176 1.1 christos (*pos) += 2;
177 1.1 christos fprintf_filtered (stream, "%s",
178 1.1 christos longest_to_int (exp->elts[pc + 1].longconst)
179 1.1 christos ? "TRUE" : "FALSE");
180 1.1 christos return;
181 1.1 christos
182 1.1 christos case OP_INTERNALVAR:
183 1.1 christos (*pos) += 2;
184 1.1 christos fprintf_filtered (stream, "$%s",
185 1.1 christos internalvar_name (exp->elts[pc + 1].internalvar));
186 1.1 christos return;
187 1.1 christos
188 1.1 christos case OP_FUNCALL:
189 1.8 christos case OP_F77_UNDETERMINED_ARGLIST:
190 1.1 christos (*pos) += 2;
191 1.1 christos nargs = longest_to_int (exp->elts[pc + 1].longconst);
192 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
193 1.1 christos fputs_filtered (" (", stream);
194 1.1 christos for (tem = 0; tem < nargs; tem++)
195 1.1 christos {
196 1.1 christos if (tem != 0)
197 1.1 christos fputs_filtered (", ", stream);
198 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
199 1.1 christos }
200 1.1 christos fputs_filtered (")", stream);
201 1.1 christos return;
202 1.1 christos
203 1.1 christos case OP_NAME:
204 1.1 christos nargs = longest_to_int (exp->elts[pc + 1].longconst);
205 1.1 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
206 1.1 christos fputs_filtered (&exp->elts[pc + 2].string, stream);
207 1.1 christos return;
208 1.1 christos
209 1.1 christos case OP_STRING:
210 1.1 christos {
211 1.1 christos struct value_print_options opts;
212 1.1 christos
213 1.1 christos nargs = longest_to_int (exp->elts[pc + 1].longconst);
214 1.1 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
215 1.1 christos /* LA_PRINT_STRING will print using the current repeat count threshold.
216 1.1 christos If necessary, we can temporarily set it to zero, or pass it as an
217 1.1 christos additional parameter to LA_PRINT_STRING. -fnf */
218 1.1 christos get_user_print_options (&opts);
219 1.1 christos LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
220 1.1 christos (gdb_byte *) &exp->elts[pc + 2].string, nargs,
221 1.1 christos NULL, 0, &opts);
222 1.1 christos }
223 1.1 christos return;
224 1.1 christos
225 1.1 christos case OP_OBJC_NSSTRING: /* Objective-C Foundation Class
226 1.1 christos NSString constant. */
227 1.1 christos {
228 1.1 christos struct value_print_options opts;
229 1.1 christos
230 1.1 christos nargs = longest_to_int (exp->elts[pc + 1].longconst);
231 1.1 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
232 1.1 christos fputs_filtered ("@\"", stream);
233 1.1 christos get_user_print_options (&opts);
234 1.1 christos LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
235 1.1 christos (gdb_byte *) &exp->elts[pc + 2].string, nargs,
236 1.1 christos NULL, 0, &opts);
237 1.1 christos fputs_filtered ("\"", stream);
238 1.1 christos }
239 1.1 christos return;
240 1.1 christos
241 1.1 christos case OP_OBJC_MSGCALL:
242 1.1 christos { /* Objective C message (method) call. */
243 1.8 christos gdb::unique_xmalloc_ptr<char> selector;
244 1.1 christos
245 1.1 christos (*pos) += 3;
246 1.1 christos nargs = longest_to_int (exp->elts[pc + 2].longconst);
247 1.1 christos fprintf_unfiltered (stream, "[");
248 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
249 1.1 christos if (0 == target_read_string (exp->elts[pc + 1].longconst,
250 1.1 christos &selector, 1024, NULL))
251 1.1 christos {
252 1.1 christos error (_("bad selector"));
253 1.1 christos return;
254 1.1 christos }
255 1.1 christos if (nargs)
256 1.1 christos {
257 1.1 christos char *s, *nextS;
258 1.1 christos
259 1.8 christos s = selector.get ();
260 1.1 christos for (tem = 0; tem < nargs; tem++)
261 1.1 christos {
262 1.1 christos nextS = strchr (s, ':');
263 1.1 christos gdb_assert (nextS); /* Make sure we found ':'. */
264 1.1 christos *nextS = '\0';
265 1.1 christos fprintf_unfiltered (stream, " %s: ", s);
266 1.1 christos s = nextS + 1;
267 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
268 1.1 christos }
269 1.1 christos }
270 1.1 christos else
271 1.1 christos {
272 1.8 christos fprintf_unfiltered (stream, " %s", selector.get ());
273 1.1 christos }
274 1.1 christos fprintf_unfiltered (stream, "]");
275 1.1 christos return;
276 1.1 christos }
277 1.1 christos
278 1.1 christos case OP_ARRAY:
279 1.1 christos (*pos) += 3;
280 1.1 christos nargs = longest_to_int (exp->elts[pc + 2].longconst);
281 1.1 christos nargs -= longest_to_int (exp->elts[pc + 1].longconst);
282 1.1 christos nargs++;
283 1.1 christos tem = 0;
284 1.1 christos if (exp->elts[pc + 4].opcode == OP_LONG
285 1.1 christos && exp->elts[pc + 5].type
286 1.1 christos == builtin_type (exp->gdbarch)->builtin_char
287 1.1 christos && exp->language_defn->la_language == language_c)
288 1.1 christos {
289 1.1 christos /* Attempt to print C character arrays using string syntax.
290 1.1 christos Walk through the args, picking up one character from each
291 1.1 christos of the OP_LONG expression elements. If any array element
292 1.1 christos does not match our expection of what we should find for
293 1.1 christos a simple string, revert back to array printing. Note that
294 1.1 christos the last expression element is an explicit null terminator
295 1.1 christos byte, which doesn't get printed. */
296 1.6 christos tempstr = (char *) alloca (nargs);
297 1.1 christos pc += 4;
298 1.1 christos while (tem < nargs)
299 1.1 christos {
300 1.1 christos if (exp->elts[pc].opcode != OP_LONG
301 1.1 christos || exp->elts[pc + 1].type
302 1.1 christos != builtin_type (exp->gdbarch)->builtin_char)
303 1.1 christos {
304 1.1 christos /* Not a simple array of char, use regular array
305 1.1 christos printing. */
306 1.1 christos tem = 0;
307 1.1 christos break;
308 1.1 christos }
309 1.1 christos else
310 1.1 christos {
311 1.1 christos tempstr[tem++] =
312 1.1 christos longest_to_int (exp->elts[pc + 2].longconst);
313 1.1 christos pc += 4;
314 1.1 christos }
315 1.1 christos }
316 1.1 christos }
317 1.1 christos if (tem > 0)
318 1.1 christos {
319 1.1 christos struct value_print_options opts;
320 1.1 christos
321 1.1 christos get_user_print_options (&opts);
322 1.1 christos LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
323 1.1 christos (gdb_byte *) tempstr, nargs - 1, NULL, 0, &opts);
324 1.1 christos (*pos) = pc;
325 1.1 christos }
326 1.1 christos else
327 1.1 christos {
328 1.1 christos fputs_filtered (" {", stream);
329 1.1 christos for (tem = 0; tem < nargs; tem++)
330 1.1 christos {
331 1.1 christos if (tem != 0)
332 1.1 christos {
333 1.1 christos fputs_filtered (", ", stream);
334 1.1 christos }
335 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
336 1.1 christos }
337 1.1 christos fputs_filtered ("}", stream);
338 1.1 christos }
339 1.1 christos return;
340 1.1 christos
341 1.1 christos case TERNOP_COND:
342 1.1 christos if ((int) prec > (int) PREC_COMMA)
343 1.1 christos fputs_filtered ("(", stream);
344 1.1 christos /* Print the subexpressions, forcing parentheses
345 1.1 christos around any binary operations within them.
346 1.1 christos This is more parentheses than are strictly necessary,
347 1.1 christos but it looks clearer. */
348 1.1 christos print_subexp (exp, pos, stream, PREC_HYPER);
349 1.1 christos fputs_filtered (" ? ", stream);
350 1.1 christos print_subexp (exp, pos, stream, PREC_HYPER);
351 1.1 christos fputs_filtered (" : ", stream);
352 1.1 christos print_subexp (exp, pos, stream, PREC_HYPER);
353 1.1 christos if ((int) prec > (int) PREC_COMMA)
354 1.1 christos fputs_filtered (")", stream);
355 1.1 christos return;
356 1.1 christos
357 1.1 christos case TERNOP_SLICE:
358 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
359 1.1 christos fputs_filtered ("(", stream);
360 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
361 1.1 christos fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream);
362 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
363 1.1 christos fputs_filtered (")", stream);
364 1.1 christos return;
365 1.1 christos
366 1.1 christos case STRUCTOP_STRUCT:
367 1.1 christos tem = longest_to_int (exp->elts[pc + 1].longconst);
368 1.1 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
369 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
370 1.1 christos fputs_filtered (".", stream);
371 1.1 christos fputs_filtered (&exp->elts[pc + 2].string, stream);
372 1.1 christos return;
373 1.1 christos
374 1.1 christos /* Will not occur for Modula-2. */
375 1.1 christos case STRUCTOP_PTR:
376 1.1 christos tem = longest_to_int (exp->elts[pc + 1].longconst);
377 1.1 christos (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
378 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
379 1.1 christos fputs_filtered ("->", stream);
380 1.1 christos fputs_filtered (&exp->elts[pc + 2].string, stream);
381 1.1 christos return;
382 1.1 christos
383 1.1 christos case STRUCTOP_MEMBER:
384 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
385 1.1 christos fputs_filtered (".*", stream);
386 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
387 1.1 christos return;
388 1.1 christos
389 1.1 christos case STRUCTOP_MPTR:
390 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
391 1.1 christos fputs_filtered ("->*", stream);
392 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
393 1.1 christos return;
394 1.1 christos
395 1.1 christos case BINOP_SUBSCRIPT:
396 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
397 1.1 christos fputs_filtered ("[", stream);
398 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
399 1.1 christos fputs_filtered ("]", stream);
400 1.1 christos return;
401 1.1 christos
402 1.1 christos case UNOP_POSTINCREMENT:
403 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
404 1.1 christos fputs_filtered ("++", stream);
405 1.1 christos return;
406 1.1 christos
407 1.1 christos case UNOP_POSTDECREMENT:
408 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
409 1.1 christos fputs_filtered ("--", stream);
410 1.1 christos return;
411 1.1 christos
412 1.1 christos case UNOP_CAST:
413 1.1 christos (*pos) += 2;
414 1.1 christos if ((int) prec > (int) PREC_PREFIX)
415 1.1 christos fputs_filtered ("(", stream);
416 1.1 christos fputs_filtered ("(", stream);
417 1.1 christos type_print (exp->elts[pc + 1].type, "", stream, 0);
418 1.1 christos fputs_filtered (") ", stream);
419 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
420 1.1 christos if ((int) prec > (int) PREC_PREFIX)
421 1.1 christos fputs_filtered (")", stream);
422 1.1 christos return;
423 1.1 christos
424 1.1 christos case UNOP_CAST_TYPE:
425 1.1 christos if ((int) prec > (int) PREC_PREFIX)
426 1.1 christos fputs_filtered ("(", stream);
427 1.1 christos fputs_filtered ("(", stream);
428 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
429 1.1 christos fputs_filtered (") ", stream);
430 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
431 1.1 christos if ((int) prec > (int) PREC_PREFIX)
432 1.1 christos fputs_filtered (")", stream);
433 1.1 christos return;
434 1.1 christos
435 1.1 christos case UNOP_DYNAMIC_CAST:
436 1.1 christos case UNOP_REINTERPRET_CAST:
437 1.1 christos fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast"
438 1.1 christos : "reinterpret_cast", stream);
439 1.1 christos fputs_filtered ("<", stream);
440 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
441 1.1 christos fputs_filtered ("> (", stream);
442 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
443 1.1 christos fputs_filtered (")", stream);
444 1.1 christos return;
445 1.1 christos
446 1.1 christos case UNOP_MEMVAL:
447 1.1 christos (*pos) += 2;
448 1.1 christos if ((int) prec > (int) PREC_PREFIX)
449 1.1 christos fputs_filtered ("(", stream);
450 1.1 christos if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC
451 1.1 christos && exp->elts[pc + 3].opcode == OP_LONG)
452 1.1 christos {
453 1.1 christos struct value_print_options opts;
454 1.1 christos
455 1.1 christos /* We have a minimal symbol fn, probably. It's encoded
456 1.1 christos as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
457 1.1 christos Swallow the OP_LONG (including both its opcodes); ignore
458 1.1 christos its type; print the value in the type of the MEMVAL. */
459 1.1 christos (*pos) += 4;
460 1.1 christos val = value_at_lazy (exp->elts[pc + 1].type,
461 1.1 christos (CORE_ADDR) exp->elts[pc + 5].longconst);
462 1.1 christos get_no_prettyformat_print_options (&opts);
463 1.1 christos value_print (val, stream, &opts);
464 1.1 christos }
465 1.1 christos else
466 1.1 christos {
467 1.1 christos fputs_filtered ("{", stream);
468 1.1 christos type_print (exp->elts[pc + 1].type, "", stream, 0);
469 1.1 christos fputs_filtered ("} ", stream);
470 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
471 1.1 christos }
472 1.1 christos if ((int) prec > (int) PREC_PREFIX)
473 1.1 christos fputs_filtered (")", stream);
474 1.1 christos return;
475 1.1 christos
476 1.1 christos case UNOP_MEMVAL_TYPE:
477 1.1 christos if ((int) prec > (int) PREC_PREFIX)
478 1.1 christos fputs_filtered ("(", stream);
479 1.1 christos fputs_filtered ("{", stream);
480 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
481 1.1 christos fputs_filtered ("} ", stream);
482 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
483 1.1 christos if ((int) prec > (int) PREC_PREFIX)
484 1.1 christos fputs_filtered (")", stream);
485 1.1 christos return;
486 1.1 christos
487 1.1 christos case BINOP_ASSIGN_MODIFY:
488 1.1 christos opcode = exp->elts[pc + 1].opcode;
489 1.1 christos (*pos) += 2;
490 1.1 christos myprec = PREC_ASSIGN;
491 1.1 christos assoc = 1;
492 1.1 christos assign_modify = 1;
493 1.1 christos op_str = "???";
494 1.1 christos for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
495 1.1 christos if (op_print_tab[tem].opcode == opcode)
496 1.1 christos {
497 1.1 christos op_str = op_print_tab[tem].string;
498 1.1 christos break;
499 1.1 christos }
500 1.1 christos if (op_print_tab[tem].opcode != opcode)
501 1.1 christos /* Not found; don't try to keep going because we don't know how
502 1.1 christos to interpret further elements. */
503 1.1 christos error (_("Invalid expression"));
504 1.1 christos break;
505 1.1 christos
506 1.1 christos /* C++ ops */
507 1.1 christos
508 1.1 christos case OP_THIS:
509 1.1 christos ++(*pos);
510 1.1 christos if (exp->language_defn->la_name_of_this)
511 1.1 christos fputs_filtered (exp->language_defn->la_name_of_this, stream);
512 1.1 christos else
513 1.1 christos fprintf_filtered (stream, _("<language %s has no 'this'>"),
514 1.1 christos exp->language_defn->la_name);
515 1.1 christos return;
516 1.1 christos
517 1.1 christos /* Modula-2 ops */
518 1.1 christos
519 1.1 christos case MULTI_SUBSCRIPT:
520 1.1 christos (*pos) += 2;
521 1.1 christos nargs = longest_to_int (exp->elts[pc + 1].longconst);
522 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
523 1.1 christos fprintf_unfiltered (stream, " [");
524 1.1 christos for (tem = 0; tem < nargs; tem++)
525 1.1 christos {
526 1.1 christos if (tem != 0)
527 1.1 christos fprintf_unfiltered (stream, ", ");
528 1.1 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
529 1.1 christos }
530 1.1 christos fprintf_unfiltered (stream, "]");
531 1.1 christos return;
532 1.1 christos
533 1.1 christos case BINOP_VAL:
534 1.1 christos (*pos) += 2;
535 1.1 christos fprintf_unfiltered (stream, "VAL(");
536 1.1 christos type_print (exp->elts[pc + 1].type, "", stream, 0);
537 1.1 christos fprintf_unfiltered (stream, ",");
538 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
539 1.1 christos fprintf_unfiltered (stream, ")");
540 1.1 christos return;
541 1.1 christos
542 1.1 christos case TYPE_INSTANCE:
543 1.1 christos {
544 1.8 christos type_instance_flags flags
545 1.8 christos = (type_instance_flag_value) longest_to_int (exp->elts[pc + 1].longconst);
546 1.8 christos LONGEST count = exp->elts[pc + 2].longconst;
547 1.1 christos
548 1.8 christos /* The FLAGS. */
549 1.8 christos (*pos)++;
550 1.1 christos /* The COUNT. */
551 1.1 christos (*pos)++;
552 1.8 christos fputs_unfiltered ("TypeInstance(", stream);
553 1.1 christos while (count-- > 0)
554 1.1 christos {
555 1.1 christos type_print (exp->elts[(*pos)++].type, "", stream, 0);
556 1.1 christos if (count > 0)
557 1.1 christos fputs_unfiltered (",", stream);
558 1.1 christos }
559 1.1 christos fputs_unfiltered (",", stream);
560 1.1 christos /* Ending COUNT and ending TYPE_INSTANCE. */
561 1.1 christos (*pos) += 2;
562 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
563 1.8 christos
564 1.8 christos if (flags & TYPE_INSTANCE_FLAG_CONST)
565 1.8 christos fputs_unfiltered (",const", stream);
566 1.8 christos if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
567 1.8 christos fputs_unfiltered (",volatile", stream);
568 1.8 christos
569 1.1 christos fputs_unfiltered (")", stream);
570 1.1 christos return;
571 1.1 christos }
572 1.1 christos
573 1.6 christos case OP_RANGE:
574 1.6 christos {
575 1.6 christos enum range_type range_type;
576 1.6 christos
577 1.6 christos range_type = (enum range_type)
578 1.6 christos longest_to_int (exp->elts[pc + 1].longconst);
579 1.6 christos *pos += 2;
580 1.6 christos
581 1.8 christos if (range_type == NONE_BOUND_DEFAULT_EXCLUSIVE
582 1.8 christos || range_type == LOW_BOUND_DEFAULT_EXCLUSIVE)
583 1.8 christos fputs_filtered ("EXCLUSIVE_", stream);
584 1.6 christos fputs_filtered ("RANGE(", stream);
585 1.6 christos if (range_type == HIGH_BOUND_DEFAULT
586 1.8 christos || range_type == NONE_BOUND_DEFAULT
587 1.8 christos || range_type == NONE_BOUND_DEFAULT_EXCLUSIVE)
588 1.6 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
589 1.6 christos fputs_filtered ("..", stream);
590 1.6 christos if (range_type == LOW_BOUND_DEFAULT
591 1.6 christos || range_type == NONE_BOUND_DEFAULT)
592 1.6 christos print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
593 1.6 christos fputs_filtered (")", stream);
594 1.6 christos return;
595 1.6 christos }
596 1.6 christos
597 1.1 christos /* Default ops */
598 1.1 christos
599 1.1 christos default:
600 1.1 christos op_str = "???";
601 1.1 christos for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
602 1.1 christos if (op_print_tab[tem].opcode == opcode)
603 1.1 christos {
604 1.1 christos op_str = op_print_tab[tem].string;
605 1.1 christos myprec = op_print_tab[tem].precedence;
606 1.1 christos assoc = op_print_tab[tem].right_assoc;
607 1.1 christos break;
608 1.1 christos }
609 1.1 christos if (op_print_tab[tem].opcode != opcode)
610 1.1 christos /* Not found; don't try to keep going because we don't know how
611 1.1 christos to interpret further elements. For example, this happens
612 1.1 christos if opcode is OP_TYPE. */
613 1.1 christos error (_("Invalid expression"));
614 1.1 christos }
615 1.1 christos
616 1.1 christos /* Note that PREC_BUILTIN will always emit parentheses. */
617 1.1 christos if ((int) myprec < (int) prec)
618 1.1 christos fputs_filtered ("(", stream);
619 1.1 christos if ((int) opcode > (int) BINOP_END)
620 1.1 christos {
621 1.1 christos if (assoc)
622 1.1 christos {
623 1.1 christos /* Unary postfix operator. */
624 1.1 christos print_subexp (exp, pos, stream, PREC_SUFFIX);
625 1.1 christos fputs_filtered (op_str, stream);
626 1.1 christos }
627 1.1 christos else
628 1.1 christos {
629 1.1 christos /* Unary prefix operator. */
630 1.1 christos fputs_filtered (op_str, stream);
631 1.1 christos if (myprec == PREC_BUILTIN_FUNCTION)
632 1.1 christos fputs_filtered ("(", stream);
633 1.1 christos print_subexp (exp, pos, stream, PREC_PREFIX);
634 1.1 christos if (myprec == PREC_BUILTIN_FUNCTION)
635 1.1 christos fputs_filtered (")", stream);
636 1.1 christos }
637 1.1 christos }
638 1.1 christos else
639 1.1 christos {
640 1.1 christos /* Binary operator. */
641 1.1 christos /* Print left operand.
642 1.1 christos If operator is right-associative,
643 1.1 christos increment precedence for this operand. */
644 1.1 christos print_subexp (exp, pos, stream,
645 1.1 christos (enum precedence) ((int) myprec + assoc));
646 1.1 christos /* Print the operator itself. */
647 1.1 christos if (assign_modify)
648 1.1 christos fprintf_filtered (stream, " %s= ", op_str);
649 1.1 christos else if (op_str[0] == ',')
650 1.1 christos fprintf_filtered (stream, "%s ", op_str);
651 1.1 christos else
652 1.1 christos fprintf_filtered (stream, " %s ", op_str);
653 1.1 christos /* Print right operand.
654 1.1 christos If operator is left-associative,
655 1.1 christos increment precedence for this operand. */
656 1.1 christos print_subexp (exp, pos, stream,
657 1.1 christos (enum precedence) ((int) myprec + !assoc));
658 1.1 christos }
659 1.1 christos
660 1.1 christos if ((int) myprec < (int) prec)
661 1.1 christos fputs_filtered (")", stream);
662 1.1 christos }
663 1.1 christos
664 1.1 christos /* Return the operator corresponding to opcode OP as
665 1.1 christos a string. NULL indicates that the opcode was not found in the
666 1.1 christos current language table. */
667 1.7 christos const char *
668 1.1 christos op_string (enum exp_opcode op)
669 1.1 christos {
670 1.1 christos int tem;
671 1.1 christos const struct op_print *op_print_tab;
672 1.1 christos
673 1.1 christos op_print_tab = current_language->la_op_print_tab;
674 1.1 christos for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
675 1.1 christos if (op_print_tab[tem].opcode == op)
676 1.1 christos return op_print_tab[tem].string;
677 1.1 christos return NULL;
678 1.1 christos }
679 1.1 christos
680 1.1 christos /* Support for dumping the raw data from expressions in a human readable
681 1.1 christos form. */
682 1.1 christos
683 1.1 christos static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
684 1.1 christos
685 1.1 christos /* Name for OPCODE, when it appears in expression EXP. */
686 1.1 christos
687 1.7 christos const char *
688 1.1 christos op_name (struct expression *exp, enum exp_opcode opcode)
689 1.1 christos {
690 1.8 christos if (opcode >= OP_UNUSED_LAST)
691 1.8 christos {
692 1.8 christos char *cell = get_print_cell ();
693 1.8 christos xsnprintf (cell, PRINT_CELL_SIZE, "unknown opcode: %u",
694 1.8 christos unsigned (opcode));
695 1.8 christos return cell;
696 1.8 christos }
697 1.1 christos return exp->language_defn->la_exp_desc->op_name (opcode);
698 1.1 christos }
699 1.1 christos
700 1.1 christos /* Default name for the standard operator OPCODE (i.e., one defined in
701 1.1 christos the definition of enum exp_opcode). */
702 1.1 christos
703 1.7 christos const char *
704 1.1 christos op_name_standard (enum exp_opcode opcode)
705 1.1 christos {
706 1.1 christos switch (opcode)
707 1.1 christos {
708 1.1 christos default:
709 1.1 christos {
710 1.1 christos static char buf[30];
711 1.1 christos
712 1.1 christos xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode);
713 1.1 christos return buf;
714 1.1 christos }
715 1.1 christos #define OP(name) \
716 1.1 christos case name: \
717 1.1 christos return #name ;
718 1.1 christos #include "std-operator.def"
719 1.1 christos #undef OP
720 1.1 christos }
721 1.1 christos }
722 1.1 christos
723 1.1 christos /* Print a raw dump of expression EXP to STREAM.
724 1.1 christos NOTE, if non-NULL, is printed as extra explanatory text. */
725 1.1 christos
726 1.1 christos void
727 1.1 christos dump_raw_expression (struct expression *exp, struct ui_file *stream,
728 1.7 christos const char *note)
729 1.1 christos {
730 1.1 christos int elt;
731 1.1 christos char *eltscan;
732 1.1 christos int eltsize;
733 1.1 christos
734 1.1 christos fprintf_filtered (stream, "Dump of expression @ ");
735 1.1 christos gdb_print_host_address (exp, stream);
736 1.1 christos if (note)
737 1.1 christos fprintf_filtered (stream, ", %s:", note);
738 1.1 christos fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
739 1.1 christos exp->language_defn->la_name, exp->nelts,
740 1.1 christos (long) sizeof (union exp_element));
741 1.1 christos fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode",
742 1.1 christos "Hex Value", "String Value");
743 1.1 christos for (elt = 0; elt < exp->nelts; elt++)
744 1.1 christos {
745 1.1 christos fprintf_filtered (stream, "\t%5d ", elt);
746 1.1 christos
747 1.7 christos const char *opcode_name = op_name (exp, exp->elts[elt].opcode);
748 1.1 christos fprintf_filtered (stream, "%20s ", opcode_name);
749 1.7 christos
750 1.1 christos print_longest (stream, 'd', 0, exp->elts[elt].longconst);
751 1.1 christos fprintf_filtered (stream, " ");
752 1.1 christos
753 1.1 christos for (eltscan = (char *) &exp->elts[elt],
754 1.1 christos eltsize = sizeof (union exp_element);
755 1.1 christos eltsize-- > 0;
756 1.1 christos eltscan++)
757 1.1 christos {
758 1.1 christos fprintf_filtered (stream, "%c",
759 1.1 christos isprint (*eltscan) ? (*eltscan & 0xFF) : '.');
760 1.1 christos }
761 1.1 christos fprintf_filtered (stream, "\n");
762 1.1 christos }
763 1.1 christos }
764 1.1 christos
765 1.1 christos /* Dump the subexpression of prefix expression EXP whose operator is at
766 1.1 christos position ELT onto STREAM. Returns the position of the next
767 1.1 christos subexpression in EXP. */
768 1.1 christos
769 1.1 christos int
770 1.1 christos dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
771 1.1 christos {
772 1.1 christos static int indent = 0;
773 1.1 christos int i;
774 1.1 christos
775 1.1 christos fprintf_filtered (stream, "\n");
776 1.1 christos fprintf_filtered (stream, "\t%5d ", elt);
777 1.1 christos
778 1.1 christos for (i = 1; i <= indent; i++)
779 1.1 christos fprintf_filtered (stream, " ");
780 1.1 christos indent += 2;
781 1.1 christos
782 1.1 christos fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode));
783 1.1 christos
784 1.1 christos elt = dump_subexp_body (exp, stream, elt);
785 1.1 christos
786 1.1 christos indent -= 2;
787 1.1 christos
788 1.1 christos return elt;
789 1.1 christos }
790 1.1 christos
791 1.1 christos /* Dump the operands of prefix expression EXP whose opcode is at
792 1.1 christos position ELT onto STREAM. Returns the position of the next
793 1.1 christos subexpression in EXP. */
794 1.1 christos
795 1.1 christos static int
796 1.1 christos dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
797 1.1 christos {
798 1.1 christos return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
799 1.1 christos }
800 1.1 christos
801 1.1 christos /* Default value for subexp_body in exp_descriptor vector. */
802 1.1 christos
803 1.1 christos int
804 1.1 christos dump_subexp_body_standard (struct expression *exp,
805 1.1 christos struct ui_file *stream, int elt)
806 1.1 christos {
807 1.1 christos int opcode = exp->elts[elt++].opcode;
808 1.1 christos
809 1.1 christos switch (opcode)
810 1.1 christos {
811 1.1 christos case TERNOP_COND:
812 1.1 christos case TERNOP_SLICE:
813 1.1 christos elt = dump_subexp (exp, stream, elt);
814 1.1 christos /* FALL THROUGH */
815 1.1 christos case BINOP_ADD:
816 1.1 christos case BINOP_SUB:
817 1.1 christos case BINOP_MUL:
818 1.1 christos case BINOP_DIV:
819 1.1 christos case BINOP_REM:
820 1.1 christos case BINOP_MOD:
821 1.1 christos case BINOP_LSH:
822 1.1 christos case BINOP_RSH:
823 1.1 christos case BINOP_LOGICAL_AND:
824 1.1 christos case BINOP_LOGICAL_OR:
825 1.1 christos case BINOP_BITWISE_AND:
826 1.1 christos case BINOP_BITWISE_IOR:
827 1.1 christos case BINOP_BITWISE_XOR:
828 1.1 christos case BINOP_EQUAL:
829 1.1 christos case BINOP_NOTEQUAL:
830 1.1 christos case BINOP_LESS:
831 1.1 christos case BINOP_GTR:
832 1.1 christos case BINOP_LEQ:
833 1.1 christos case BINOP_GEQ:
834 1.1 christos case BINOP_REPEAT:
835 1.1 christos case BINOP_ASSIGN:
836 1.1 christos case BINOP_COMMA:
837 1.1 christos case BINOP_SUBSCRIPT:
838 1.1 christos case BINOP_EXP:
839 1.1 christos case BINOP_MIN:
840 1.1 christos case BINOP_MAX:
841 1.1 christos case BINOP_INTDIV:
842 1.1 christos case BINOP_ASSIGN_MODIFY:
843 1.1 christos case BINOP_VAL:
844 1.1 christos case BINOP_CONCAT:
845 1.1 christos case BINOP_END:
846 1.1 christos case STRUCTOP_MEMBER:
847 1.1 christos case STRUCTOP_MPTR:
848 1.1 christos elt = dump_subexp (exp, stream, elt);
849 1.1 christos /* FALL THROUGH */
850 1.1 christos case UNOP_NEG:
851 1.1 christos case UNOP_LOGICAL_NOT:
852 1.1 christos case UNOP_COMPLEMENT:
853 1.1 christos case UNOP_IND:
854 1.1 christos case UNOP_ADDR:
855 1.1 christos case UNOP_PREINCREMENT:
856 1.1 christos case UNOP_POSTINCREMENT:
857 1.1 christos case UNOP_PREDECREMENT:
858 1.1 christos case UNOP_POSTDECREMENT:
859 1.1 christos case UNOP_SIZEOF:
860 1.8 christos case UNOP_ALIGNOF:
861 1.1 christos case UNOP_PLUS:
862 1.1 christos case UNOP_CAP:
863 1.1 christos case UNOP_CHR:
864 1.1 christos case UNOP_ORD:
865 1.1 christos case UNOP_ABS:
866 1.1 christos case UNOP_FLOAT:
867 1.1 christos case UNOP_HIGH:
868 1.1 christos case UNOP_MAX:
869 1.1 christos case UNOP_MIN:
870 1.1 christos case UNOP_ODD:
871 1.1 christos case UNOP_TRUNC:
872 1.1 christos elt = dump_subexp (exp, stream, elt);
873 1.1 christos break;
874 1.1 christos case OP_LONG:
875 1.1 christos fprintf_filtered (stream, "Type @");
876 1.1 christos gdb_print_host_address (exp->elts[elt].type, stream);
877 1.1 christos fprintf_filtered (stream, " (");
878 1.1 christos type_print (exp->elts[elt].type, NULL, stream, 0);
879 1.1 christos fprintf_filtered (stream, "), value %ld (0x%lx)",
880 1.1 christos (long) exp->elts[elt + 1].longconst,
881 1.1 christos (long) exp->elts[elt + 1].longconst);
882 1.1 christos elt += 3;
883 1.1 christos break;
884 1.8 christos case OP_FLOAT:
885 1.1 christos fprintf_filtered (stream, "Type @");
886 1.1 christos gdb_print_host_address (exp->elts[elt].type, stream);
887 1.1 christos fprintf_filtered (stream, " (");
888 1.1 christos type_print (exp->elts[elt].type, NULL, stream, 0);
889 1.8 christos fprintf_filtered (stream, "), value ");
890 1.8 christos print_floating (exp->elts[elt + 1].floatconst,
891 1.8 christos exp->elts[elt].type, stream);
892 1.1 christos elt += 3;
893 1.1 christos break;
894 1.1 christos case OP_VAR_VALUE:
895 1.1 christos fprintf_filtered (stream, "Block @");
896 1.1 christos gdb_print_host_address (exp->elts[elt].block, stream);
897 1.1 christos fprintf_filtered (stream, ", symbol @");
898 1.1 christos gdb_print_host_address (exp->elts[elt + 1].symbol, stream);
899 1.1 christos fprintf_filtered (stream, " (%s)",
900 1.1 christos SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol));
901 1.1 christos elt += 3;
902 1.1 christos break;
903 1.8 christos case OP_VAR_MSYM_VALUE:
904 1.8 christos fprintf_filtered (stream, "Objfile @");
905 1.8 christos gdb_print_host_address (exp->elts[elt].objfile, stream);
906 1.8 christos fprintf_filtered (stream, ", msymbol @");
907 1.8 christos gdb_print_host_address (exp->elts[elt + 1].msymbol, stream);
908 1.8 christos fprintf_filtered (stream, " (%s)",
909 1.8 christos MSYMBOL_PRINT_NAME (exp->elts[elt + 1].msymbol));
910 1.8 christos elt += 3;
911 1.8 christos break;
912 1.1 christos case OP_VAR_ENTRY_VALUE:
913 1.1 christos fprintf_filtered (stream, "Entry value of symbol @");
914 1.1 christos gdb_print_host_address (exp->elts[elt].symbol, stream);
915 1.1 christos fprintf_filtered (stream, " (%s)",
916 1.1 christos SYMBOL_PRINT_NAME (exp->elts[elt].symbol));
917 1.1 christos elt += 2;
918 1.1 christos break;
919 1.1 christos case OP_LAST:
920 1.1 christos fprintf_filtered (stream, "History element %ld",
921 1.1 christos (long) exp->elts[elt].longconst);
922 1.1 christos elt += 2;
923 1.1 christos break;
924 1.1 christos case OP_REGISTER:
925 1.1 christos fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string);
926 1.1 christos elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1);
927 1.1 christos break;
928 1.1 christos case OP_INTERNALVAR:
929 1.1 christos fprintf_filtered (stream, "Internal var @");
930 1.1 christos gdb_print_host_address (exp->elts[elt].internalvar, stream);
931 1.1 christos fprintf_filtered (stream, " (%s)",
932 1.1 christos internalvar_name (exp->elts[elt].internalvar));
933 1.1 christos elt += 2;
934 1.1 christos break;
935 1.1 christos case OP_FUNCALL:
936 1.8 christos case OP_F77_UNDETERMINED_ARGLIST:
937 1.1 christos {
938 1.1 christos int i, nargs;
939 1.1 christos
940 1.1 christos nargs = longest_to_int (exp->elts[elt].longconst);
941 1.1 christos
942 1.1 christos fprintf_filtered (stream, "Number of args: %d", nargs);
943 1.1 christos elt += 2;
944 1.1 christos
945 1.1 christos for (i = 1; i <= nargs + 1; i++)
946 1.1 christos elt = dump_subexp (exp, stream, elt);
947 1.1 christos }
948 1.1 christos break;
949 1.1 christos case OP_ARRAY:
950 1.1 christos {
951 1.1 christos int lower, upper;
952 1.1 christos int i;
953 1.1 christos
954 1.1 christos lower = longest_to_int (exp->elts[elt].longconst);
955 1.1 christos upper = longest_to_int (exp->elts[elt + 1].longconst);
956 1.1 christos
957 1.1 christos fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper);
958 1.1 christos elt += 3;
959 1.1 christos
960 1.1 christos for (i = 1; i <= upper - lower + 1; i++)
961 1.1 christos elt = dump_subexp (exp, stream, elt);
962 1.1 christos }
963 1.1 christos break;
964 1.1 christos case UNOP_DYNAMIC_CAST:
965 1.1 christos case UNOP_REINTERPRET_CAST:
966 1.1 christos case UNOP_CAST_TYPE:
967 1.1 christos case UNOP_MEMVAL_TYPE:
968 1.1 christos fprintf_filtered (stream, " (");
969 1.1 christos elt = dump_subexp (exp, stream, elt);
970 1.1 christos fprintf_filtered (stream, ")");
971 1.1 christos elt = dump_subexp (exp, stream, elt);
972 1.1 christos break;
973 1.1 christos case UNOP_MEMVAL:
974 1.1 christos case UNOP_CAST:
975 1.1 christos fprintf_filtered (stream, "Type @");
976 1.1 christos gdb_print_host_address (exp->elts[elt].type, stream);
977 1.1 christos fprintf_filtered (stream, " (");
978 1.1 christos type_print (exp->elts[elt].type, NULL, stream, 0);
979 1.1 christos fprintf_filtered (stream, ")");
980 1.1 christos elt = dump_subexp (exp, stream, elt + 2);
981 1.1 christos break;
982 1.1 christos case OP_TYPE:
983 1.1 christos fprintf_filtered (stream, "Type @");
984 1.1 christos gdb_print_host_address (exp->elts[elt].type, stream);
985 1.1 christos fprintf_filtered (stream, " (");
986 1.1 christos type_print (exp->elts[elt].type, NULL, stream, 0);
987 1.1 christos fprintf_filtered (stream, ")");
988 1.1 christos elt += 2;
989 1.1 christos break;
990 1.1 christos case OP_TYPEOF:
991 1.1 christos case OP_DECLTYPE:
992 1.1 christos fprintf_filtered (stream, "Typeof (");
993 1.1 christos elt = dump_subexp (exp, stream, elt);
994 1.1 christos fprintf_filtered (stream, ")");
995 1.1 christos break;
996 1.1 christos case OP_TYPEID:
997 1.1 christos fprintf_filtered (stream, "typeid (");
998 1.1 christos elt = dump_subexp (exp, stream, elt);
999 1.1 christos fprintf_filtered (stream, ")");
1000 1.1 christos break;
1001 1.1 christos case STRUCTOP_STRUCT:
1002 1.1 christos case STRUCTOP_PTR:
1003 1.1 christos {
1004 1.1 christos char *elem_name;
1005 1.1 christos int len;
1006 1.1 christos
1007 1.1 christos len = longest_to_int (exp->elts[elt].longconst);
1008 1.1 christos elem_name = &exp->elts[elt + 1].string;
1009 1.1 christos
1010 1.1 christos fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name);
1011 1.1 christos elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1));
1012 1.1 christos }
1013 1.1 christos break;
1014 1.1 christos case OP_SCOPE:
1015 1.1 christos {
1016 1.1 christos char *elem_name;
1017 1.1 christos int len;
1018 1.1 christos
1019 1.1 christos fprintf_filtered (stream, "Type @");
1020 1.1 christos gdb_print_host_address (exp->elts[elt].type, stream);
1021 1.1 christos fprintf_filtered (stream, " (");
1022 1.1 christos type_print (exp->elts[elt].type, NULL, stream, 0);
1023 1.1 christos fprintf_filtered (stream, ") ");
1024 1.1 christos
1025 1.1 christos len = longest_to_int (exp->elts[elt + 1].longconst);
1026 1.1 christos elem_name = &exp->elts[elt + 2].string;
1027 1.1 christos
1028 1.1 christos fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name);
1029 1.1 christos elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
1030 1.1 christos }
1031 1.1 christos break;
1032 1.8 christos
1033 1.8 christos case OP_FUNC_STATIC_VAR:
1034 1.8 christos {
1035 1.8 christos int len = longest_to_int (exp->elts[elt].longconst);
1036 1.8 christos const char *var_name = &exp->elts[elt + 1].string;
1037 1.8 christos fprintf_filtered (stream, "Field name: `%.*s'", len, var_name);
1038 1.8 christos elt += 3 + BYTES_TO_EXP_ELEM (len + 1);
1039 1.8 christos }
1040 1.8 christos break;
1041 1.8 christos
1042 1.1 christos case TYPE_INSTANCE:
1043 1.1 christos {
1044 1.8 christos type_instance_flags flags
1045 1.8 christos = (type_instance_flag_value) longest_to_int (exp->elts[elt++].longconst);
1046 1.8 christos LONGEST len = exp->elts[elt++].longconst;
1047 1.1 christos fprintf_filtered (stream, "%s TypeInstance: ", plongest (len));
1048 1.1 christos while (len-- > 0)
1049 1.1 christos {
1050 1.1 christos fprintf_filtered (stream, "Type @");
1051 1.1 christos gdb_print_host_address (exp->elts[elt].type, stream);
1052 1.1 christos fprintf_filtered (stream, " (");
1053 1.1 christos type_print (exp->elts[elt].type, NULL, stream, 0);
1054 1.1 christos fprintf_filtered (stream, ")");
1055 1.1 christos elt++;
1056 1.1 christos if (len > 0)
1057 1.1 christos fputs_filtered (", ", stream);
1058 1.1 christos }
1059 1.8 christos
1060 1.8 christos fprintf_filtered (stream, " Flags: %s (", hex_string (flags));
1061 1.8 christos bool space = false;
1062 1.8 christos auto print_one = [&] (const char *mod)
1063 1.8 christos {
1064 1.8 christos if (space)
1065 1.8 christos fputs_filtered (" ", stream);
1066 1.8 christos space = true;
1067 1.8 christos fprintf_filtered (stream, "%s", mod);
1068 1.8 christos };
1069 1.8 christos if (flags & TYPE_INSTANCE_FLAG_CONST)
1070 1.8 christos print_one ("const");
1071 1.8 christos if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
1072 1.8 christos print_one ("volatile");
1073 1.8 christos fprintf_filtered (stream, ")");
1074 1.8 christos
1075 1.1 christos /* Ending LEN and ending TYPE_INSTANCE. */
1076 1.1 christos elt += 2;
1077 1.1 christos elt = dump_subexp (exp, stream, elt);
1078 1.1 christos }
1079 1.1 christos break;
1080 1.3 christos case OP_STRING:
1081 1.3 christos {
1082 1.3 christos LONGEST len = exp->elts[elt].longconst;
1083 1.3 christos LONGEST type = exp->elts[elt + 1].longconst;
1084 1.3 christos
1085 1.3 christos fprintf_filtered (stream, "Language-specific string type: %s",
1086 1.3 christos plongest (type));
1087 1.3 christos
1088 1.3 christos /* Skip length. */
1089 1.3 christos elt += 1;
1090 1.3 christos
1091 1.3 christos /* Skip string content. */
1092 1.3 christos elt += BYTES_TO_EXP_ELEM (len);
1093 1.3 christos
1094 1.3 christos /* Skip length and ending OP_STRING. */
1095 1.3 christos elt += 2;
1096 1.3 christos }
1097 1.3 christos break;
1098 1.6 christos case OP_RANGE:
1099 1.6 christos {
1100 1.6 christos enum range_type range_type;
1101 1.6 christos
1102 1.6 christos range_type = (enum range_type)
1103 1.6 christos longest_to_int (exp->elts[elt].longconst);
1104 1.6 christos elt += 2;
1105 1.6 christos
1106 1.6 christos switch (range_type)
1107 1.6 christos {
1108 1.6 christos case BOTH_BOUND_DEFAULT:
1109 1.6 christos fputs_filtered ("Range '..'", stream);
1110 1.6 christos break;
1111 1.6 christos case LOW_BOUND_DEFAULT:
1112 1.6 christos fputs_filtered ("Range '..EXP'", stream);
1113 1.6 christos break;
1114 1.8 christos case LOW_BOUND_DEFAULT_EXCLUSIVE:
1115 1.8 christos fputs_filtered ("ExclusiveRange '..EXP'", stream);
1116 1.8 christos break;
1117 1.6 christos case HIGH_BOUND_DEFAULT:
1118 1.6 christos fputs_filtered ("Range 'EXP..'", stream);
1119 1.6 christos break;
1120 1.6 christos case NONE_BOUND_DEFAULT:
1121 1.6 christos fputs_filtered ("Range 'EXP..EXP'", stream);
1122 1.6 christos break;
1123 1.8 christos case NONE_BOUND_DEFAULT_EXCLUSIVE:
1124 1.8 christos fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream);
1125 1.8 christos break;
1126 1.6 christos default:
1127 1.6 christos fputs_filtered ("Invalid Range!", stream);
1128 1.6 christos break;
1129 1.6 christos }
1130 1.6 christos
1131 1.6 christos if (range_type == HIGH_BOUND_DEFAULT
1132 1.6 christos || range_type == NONE_BOUND_DEFAULT)
1133 1.6 christos elt = dump_subexp (exp, stream, elt);
1134 1.6 christos if (range_type == LOW_BOUND_DEFAULT
1135 1.6 christos || range_type == NONE_BOUND_DEFAULT)
1136 1.6 christos elt = dump_subexp (exp, stream, elt);
1137 1.6 christos }
1138 1.6 christos break;
1139 1.6 christos
1140 1.1 christos default:
1141 1.1 christos case OP_NULL:
1142 1.1 christos case MULTI_SUBSCRIPT:
1143 1.1 christos case OP_COMPLEX:
1144 1.1 christos case OP_BOOL:
1145 1.1 christos case OP_M2_STRING:
1146 1.1 christos case OP_THIS:
1147 1.1 christos case OP_NAME:
1148 1.1 christos fprintf_filtered (stream, "Unknown format");
1149 1.1 christos }
1150 1.1 christos
1151 1.1 christos return elt;
1152 1.1 christos }
1153 1.1 christos
1154 1.1 christos void
1155 1.1 christos dump_prefix_expression (struct expression *exp, struct ui_file *stream)
1156 1.1 christos {
1157 1.1 christos int elt;
1158 1.1 christos
1159 1.1 christos fprintf_filtered (stream, "Dump of expression @ ");
1160 1.1 christos gdb_print_host_address (exp, stream);
1161 1.1 christos fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
1162 1.1 christos print_expression (exp, stream);
1163 1.1 christos fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1164 1.1 christos exp->language_defn->la_name, exp->nelts,
1165 1.1 christos (long) sizeof (union exp_element));
1166 1.1 christos fputs_filtered ("\n", stream);
1167 1.1 christos
1168 1.1 christos for (elt = 0; elt < exp->nelts;)
1169 1.1 christos elt = dump_subexp (exp, stream, elt);
1170 1.1 christos fputs_filtered ("\n", stream);
1171 1.1 christos }
1172