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