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