* ppc-opc.c (powerpc_opcodes) <"lswx">: Use RAX for the second and
[binutils-gdb.git] / gdb / expprint.c
blobbaaa08ad14aaaae7522d2298c39548cf7609f075
1 /* Print in infix form a struct expression.
3 Copyright (C) 1986, 1988-1989, 1991-2000, 2003, 2007-2012 Free
4 Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "value.h"
26 #include "language.h"
27 #include "parser-defs.h"
28 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
29 #include "target.h"
30 #include "gdb_string.h"
31 #include "block.h"
32 #include "objfiles.h"
33 #include "gdb_assert.h"
34 #include "valprint.h"
36 #ifdef HAVE_CTYPE_H
37 #include <ctype.h>
38 #endif
40 void
41 print_expression (struct expression *exp, struct ui_file *stream)
43 int pc = 0;
45 print_subexp (exp, &pc, stream, PREC_NULL);
48 /* Print the subexpression of EXP that starts in position POS, on STREAM.
49 PREC is the precedence of the surrounding operator;
50 if the precedence of the main operator of this subexpression is less,
51 parentheses are needed here. */
53 void
54 print_subexp (struct expression *exp, int *pos,
55 struct ui_file *stream, enum precedence prec)
57 exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec);
60 /* Standard implementation of print_subexp for use in language_defn
61 vectors. */
62 void
63 print_subexp_standard (struct expression *exp, int *pos,
64 struct ui_file *stream, enum precedence prec)
66 unsigned tem;
67 const struct op_print *op_print_tab;
68 int pc;
69 unsigned nargs;
70 char *op_str;
71 int assign_modify = 0;
72 enum exp_opcode opcode;
73 enum precedence myprec = PREC_NULL;
74 /* Set to 1 for a right-associative operator. */
75 int assoc = 0;
76 struct value *val;
77 char *tempstr = NULL;
79 op_print_tab = exp->language_defn->la_op_print_tab;
80 pc = (*pos)++;
81 opcode = exp->elts[pc].opcode;
82 switch (opcode)
84 /* Common ops */
86 case OP_TYPE:
87 (*pos) += 2;
88 type_print (exp->elts[pc + 1].type, "", stream, 0);
89 return;
91 case OP_SCOPE:
92 myprec = PREC_PREFIX;
93 assoc = 0;
94 fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream);
95 fputs_filtered ("::", stream);
96 nargs = longest_to_int (exp->elts[pc + 2].longconst);
97 (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1);
98 fputs_filtered (&exp->elts[pc + 3].string, stream);
99 return;
101 case OP_LONG:
103 struct value_print_options opts;
105 get_raw_print_options (&opts);
106 (*pos) += 3;
107 value_print (value_from_longest (exp->elts[pc + 1].type,
108 exp->elts[pc + 2].longconst),
109 stream, &opts);
111 return;
113 case OP_DOUBLE:
115 struct value_print_options opts;
117 get_raw_print_options (&opts);
118 (*pos) += 3;
119 value_print (value_from_double (exp->elts[pc + 1].type,
120 exp->elts[pc + 2].doubleconst),
121 stream, &opts);
123 return;
125 case OP_VAR_VALUE:
127 struct block *b;
129 (*pos) += 3;
130 b = exp->elts[pc + 1].block;
131 if (b != NULL
132 && BLOCK_FUNCTION (b) != NULL
133 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL)
135 fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream);
136 fputs_filtered ("::", stream);
138 fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream);
140 return;
142 case OP_VAR_ENTRY_VALUE:
144 (*pos) += 2;
145 fprintf_filtered (stream, "%s@entry",
146 SYMBOL_PRINT_NAME (exp->elts[pc + 1].symbol));
148 return;
150 case OP_LAST:
151 (*pos) += 2;
152 fprintf_filtered (stream, "$%d",
153 longest_to_int (exp->elts[pc + 1].longconst));
154 return;
156 case OP_REGISTER:
158 const char *name = &exp->elts[pc + 2].string;
160 (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
161 fprintf_filtered (stream, "$%s", name);
162 return;
165 case OP_BOOL:
166 (*pos) += 2;
167 fprintf_filtered (stream, "%s",
168 longest_to_int (exp->elts[pc + 1].longconst)
169 ? "TRUE" : "FALSE");
170 return;
172 case OP_INTERNALVAR:
173 (*pos) += 2;
174 fprintf_filtered (stream, "$%s",
175 internalvar_name (exp->elts[pc + 1].internalvar));
176 return;
178 case OP_FUNCALL:
179 (*pos) += 2;
180 nargs = longest_to_int (exp->elts[pc + 1].longconst);
181 print_subexp (exp, pos, stream, PREC_SUFFIX);
182 fputs_filtered (" (", stream);
183 for (tem = 0; tem < nargs; tem++)
185 if (tem != 0)
186 fputs_filtered (", ", stream);
187 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
189 fputs_filtered (")", stream);
190 return;
192 case OP_NAME:
193 nargs = longest_to_int (exp->elts[pc + 1].longconst);
194 (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
195 fputs_filtered (&exp->elts[pc + 2].string, stream);
196 return;
198 case OP_STRING:
200 struct value_print_options opts;
202 nargs = longest_to_int (exp->elts[pc + 1].longconst);
203 (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
204 /* LA_PRINT_STRING will print using the current repeat count threshold.
205 If necessary, we can temporarily set it to zero, or pass it as an
206 additional parameter to LA_PRINT_STRING. -fnf */
207 get_user_print_options (&opts);
208 LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
209 &exp->elts[pc + 2].string, nargs, NULL, 0, &opts);
211 return;
213 case OP_OBJC_NSSTRING: /* Objective-C Foundation Class
214 NSString constant. */
216 struct value_print_options opts;
218 nargs = longest_to_int (exp->elts[pc + 1].longconst);
219 (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1);
220 fputs_filtered ("@\"", stream);
221 get_user_print_options (&opts);
222 LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
223 &exp->elts[pc + 2].string, nargs, NULL, 0, &opts);
224 fputs_filtered ("\"", stream);
226 return;
228 case OP_OBJC_MSGCALL:
229 { /* Objective C message (method) call. */
230 char *selector;
232 (*pos) += 3;
233 nargs = longest_to_int (exp->elts[pc + 2].longconst);
234 fprintf_unfiltered (stream, "[");
235 print_subexp (exp, pos, stream, PREC_SUFFIX);
236 if (0 == target_read_string (exp->elts[pc + 1].longconst,
237 &selector, 1024, NULL))
239 error (_("bad selector"));
240 return;
242 if (nargs)
244 char *s, *nextS;
246 s = alloca (strlen (selector) + 1);
247 strcpy (s, selector);
248 for (tem = 0; tem < nargs; tem++)
250 nextS = strchr (s, ':');
251 gdb_assert (nextS); /* Make sure we found ':'. */
252 *nextS = '\0';
253 fprintf_unfiltered (stream, " %s: ", s);
254 s = nextS + 1;
255 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
258 else
260 fprintf_unfiltered (stream, " %s", selector);
262 fprintf_unfiltered (stream, "]");
263 /* "selector" was malloc'd by target_read_string. Free it. */
264 xfree (selector);
265 return;
268 case OP_ARRAY:
269 (*pos) += 3;
270 nargs = longest_to_int (exp->elts[pc + 2].longconst);
271 nargs -= longest_to_int (exp->elts[pc + 1].longconst);
272 nargs++;
273 tem = 0;
274 if (exp->elts[pc + 4].opcode == OP_LONG
275 && exp->elts[pc + 5].type
276 == builtin_type (exp->gdbarch)->builtin_char
277 && exp->language_defn->la_language == language_c)
279 /* Attempt to print C character arrays using string syntax.
280 Walk through the args, picking up one character from each
281 of the OP_LONG expression elements. If any array element
282 does not match our expection of what we should find for
283 a simple string, revert back to array printing. Note that
284 the last expression element is an explicit null terminator
285 byte, which doesn't get printed. */
286 tempstr = alloca (nargs);
287 pc += 4;
288 while (tem < nargs)
290 if (exp->elts[pc].opcode != OP_LONG
291 || exp->elts[pc + 1].type
292 != builtin_type (exp->gdbarch)->builtin_char)
294 /* Not a simple array of char, use regular array
295 printing. */
296 tem = 0;
297 break;
299 else
301 tempstr[tem++] =
302 longest_to_int (exp->elts[pc + 2].longconst);
303 pc += 4;
307 if (tem > 0)
309 struct value_print_options opts;
311 get_user_print_options (&opts);
312 LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char,
313 tempstr, nargs - 1, NULL, 0, &opts);
314 (*pos) = pc;
316 else
318 fputs_filtered (" {", stream);
319 for (tem = 0; tem < nargs; tem++)
321 if (tem != 0)
323 fputs_filtered (", ", stream);
325 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
327 fputs_filtered ("}", stream);
329 return;
331 case OP_LABELED:
332 tem = longest_to_int (exp->elts[pc + 1].longconst);
333 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
334 /* Gcc support both these syntaxes. Unsure which is preferred. */
335 #if 1
336 fputs_filtered (&exp->elts[pc + 2].string, stream);
337 fputs_filtered (": ", stream);
338 #else
339 fputs_filtered (".", stream);
340 fputs_filtered (&exp->elts[pc + 2].string, stream);
341 fputs_filtered ("=", stream);
342 #endif
343 print_subexp (exp, pos, stream, PREC_SUFFIX);
344 return;
346 case TERNOP_COND:
347 if ((int) prec > (int) PREC_COMMA)
348 fputs_filtered ("(", stream);
349 /* Print the subexpressions, forcing parentheses
350 around any binary operations within them.
351 This is more parentheses than are strictly necessary,
352 but it looks clearer. */
353 print_subexp (exp, pos, stream, PREC_HYPER);
354 fputs_filtered (" ? ", stream);
355 print_subexp (exp, pos, stream, PREC_HYPER);
356 fputs_filtered (" : ", stream);
357 print_subexp (exp, pos, stream, PREC_HYPER);
358 if ((int) prec > (int) PREC_COMMA)
359 fputs_filtered (")", stream);
360 return;
362 case TERNOP_SLICE:
363 print_subexp (exp, pos, stream, PREC_SUFFIX);
364 fputs_filtered ("(", stream);
365 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
366 fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream);
367 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
368 fputs_filtered (")", stream);
369 return;
371 case STRUCTOP_STRUCT:
372 tem = longest_to_int (exp->elts[pc + 1].longconst);
373 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
374 print_subexp (exp, pos, stream, PREC_SUFFIX);
375 fputs_filtered (".", stream);
376 fputs_filtered (&exp->elts[pc + 2].string, stream);
377 return;
379 /* Will not occur for Modula-2. */
380 case STRUCTOP_PTR:
381 tem = longest_to_int (exp->elts[pc + 1].longconst);
382 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
383 print_subexp (exp, pos, stream, PREC_SUFFIX);
384 fputs_filtered ("->", stream);
385 fputs_filtered (&exp->elts[pc + 2].string, stream);
386 return;
388 case STRUCTOP_MEMBER:
389 print_subexp (exp, pos, stream, PREC_SUFFIX);
390 fputs_filtered (".*", stream);
391 print_subexp (exp, pos, stream, PREC_SUFFIX);
392 return;
394 case STRUCTOP_MPTR:
395 print_subexp (exp, pos, stream, PREC_SUFFIX);
396 fputs_filtered ("->*", stream);
397 print_subexp (exp, pos, stream, PREC_SUFFIX);
398 return;
400 case BINOP_SUBSCRIPT:
401 print_subexp (exp, pos, stream, PREC_SUFFIX);
402 fputs_filtered ("[", stream);
403 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
404 fputs_filtered ("]", stream);
405 return;
407 case UNOP_POSTINCREMENT:
408 print_subexp (exp, pos, stream, PREC_SUFFIX);
409 fputs_filtered ("++", stream);
410 return;
412 case UNOP_POSTDECREMENT:
413 print_subexp (exp, pos, stream, PREC_SUFFIX);
414 fputs_filtered ("--", stream);
415 return;
417 case UNOP_CAST:
418 (*pos) += 2;
419 if ((int) prec > (int) PREC_PREFIX)
420 fputs_filtered ("(", stream);
421 fputs_filtered ("(", stream);
422 type_print (exp->elts[pc + 1].type, "", stream, 0);
423 fputs_filtered (") ", stream);
424 print_subexp (exp, pos, stream, PREC_PREFIX);
425 if ((int) prec > (int) PREC_PREFIX)
426 fputs_filtered (")", stream);
427 return;
429 case UNOP_CAST_TYPE:
430 if ((int) prec > (int) PREC_PREFIX)
431 fputs_filtered ("(", stream);
432 fputs_filtered ("(", stream);
433 print_subexp (exp, pos, stream, PREC_PREFIX);
434 fputs_filtered (") ", stream);
435 print_subexp (exp, pos, stream, PREC_PREFIX);
436 if ((int) prec > (int) PREC_PREFIX)
437 fputs_filtered (")", stream);
438 return;
440 case UNOP_DYNAMIC_CAST:
441 case UNOP_REINTERPRET_CAST:
442 fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast"
443 : "reinterpret_cast", stream);
444 fputs_filtered ("<", stream);
445 print_subexp (exp, pos, stream, PREC_PREFIX);
446 fputs_filtered ("> (", stream);
447 print_subexp (exp, pos, stream, PREC_PREFIX);
448 fputs_filtered (")", stream);
449 return;
451 case UNOP_MEMVAL:
452 (*pos) += 2;
453 if ((int) prec > (int) PREC_PREFIX)
454 fputs_filtered ("(", stream);
455 if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC
456 && exp->elts[pc + 3].opcode == OP_LONG)
458 struct value_print_options opts;
460 /* We have a minimal symbol fn, probably. It's encoded
461 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
462 Swallow the OP_LONG (including both its opcodes); ignore
463 its type; print the value in the type of the MEMVAL. */
464 (*pos) += 4;
465 val = value_at_lazy (exp->elts[pc + 1].type,
466 (CORE_ADDR) exp->elts[pc + 5].longconst);
467 get_raw_print_options (&opts);
468 value_print (val, stream, &opts);
470 else
472 fputs_filtered ("{", stream);
473 type_print (exp->elts[pc + 1].type, "", stream, 0);
474 fputs_filtered ("} ", stream);
475 print_subexp (exp, pos, stream, PREC_PREFIX);
477 if ((int) prec > (int) PREC_PREFIX)
478 fputs_filtered (")", stream);
479 return;
481 case UNOP_MEMVAL_TYPE:
482 if ((int) prec > (int) PREC_PREFIX)
483 fputs_filtered ("(", stream);
484 fputs_filtered ("{", stream);
485 print_subexp (exp, pos, stream, PREC_PREFIX);
486 fputs_filtered ("} ", stream);
487 print_subexp (exp, pos, stream, PREC_PREFIX);
488 if ((int) prec > (int) PREC_PREFIX)
489 fputs_filtered (")", stream);
490 return;
492 case UNOP_MEMVAL_TLS:
493 (*pos) += 3;
494 if ((int) prec > (int) PREC_PREFIX)
495 fputs_filtered ("(", stream);
496 fputs_filtered ("{", stream);
497 type_print (exp->elts[pc + 2].type, "", stream, 0);
498 fputs_filtered ("} ", stream);
499 print_subexp (exp, pos, stream, PREC_PREFIX);
500 if ((int) prec > (int) PREC_PREFIX)
501 fputs_filtered (")", stream);
502 return;
504 case BINOP_ASSIGN_MODIFY:
505 opcode = exp->elts[pc + 1].opcode;
506 (*pos) += 2;
507 myprec = PREC_ASSIGN;
508 assoc = 1;
509 assign_modify = 1;
510 op_str = "???";
511 for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
512 if (op_print_tab[tem].opcode == opcode)
514 op_str = op_print_tab[tem].string;
515 break;
517 if (op_print_tab[tem].opcode != opcode)
518 /* Not found; don't try to keep going because we don't know how
519 to interpret further elements. */
520 error (_("Invalid expression"));
521 break;
523 /* C++ ops */
525 case OP_THIS:
526 ++(*pos);
527 if (exp->language_defn->la_name_of_this)
528 fputs_filtered (exp->language_defn->la_name_of_this, stream);
529 else
530 fprintf_filtered (stream, _("<language %s has no 'this'>"),
531 exp->language_defn->la_name);
532 return;
534 /* Modula-2 ops */
536 case MULTI_SUBSCRIPT:
537 (*pos) += 2;
538 nargs = longest_to_int (exp->elts[pc + 1].longconst);
539 print_subexp (exp, pos, stream, PREC_SUFFIX);
540 fprintf_unfiltered (stream, " [");
541 for (tem = 0; tem < nargs; tem++)
543 if (tem != 0)
544 fprintf_unfiltered (stream, ", ");
545 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
547 fprintf_unfiltered (stream, "]");
548 return;
550 case BINOP_VAL:
551 (*pos) += 2;
552 fprintf_unfiltered (stream, "VAL(");
553 type_print (exp->elts[pc + 1].type, "", stream, 0);
554 fprintf_unfiltered (stream, ",");
555 print_subexp (exp, pos, stream, PREC_PREFIX);
556 fprintf_unfiltered (stream, ")");
557 return;
559 case TYPE_INSTANCE:
561 LONGEST count = exp->elts[pc + 1].longconst;
563 /* The COUNT. */
564 (*pos)++;
565 fputs_unfiltered ("TypesInstance(", stream);
566 while (count-- > 0)
568 type_print (exp->elts[(*pos)++].type, "", stream, 0);
569 if (count > 0)
570 fputs_unfiltered (",", stream);
572 fputs_unfiltered (",", stream);
573 /* Ending COUNT and ending TYPE_INSTANCE. */
574 (*pos) += 2;
575 print_subexp (exp, pos, stream, PREC_PREFIX);
576 fputs_unfiltered (")", stream);
577 return;
580 /* Default ops */
582 default:
583 op_str = "???";
584 for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
585 if (op_print_tab[tem].opcode == opcode)
587 op_str = op_print_tab[tem].string;
588 myprec = op_print_tab[tem].precedence;
589 assoc = op_print_tab[tem].right_assoc;
590 break;
592 if (op_print_tab[tem].opcode != opcode)
593 /* Not found; don't try to keep going because we don't know how
594 to interpret further elements. For example, this happens
595 if opcode is OP_TYPE. */
596 error (_("Invalid expression"));
599 /* Note that PREC_BUILTIN will always emit parentheses. */
600 if ((int) myprec < (int) prec)
601 fputs_filtered ("(", stream);
602 if ((int) opcode > (int) BINOP_END)
604 if (assoc)
606 /* Unary postfix operator. */
607 print_subexp (exp, pos, stream, PREC_SUFFIX);
608 fputs_filtered (op_str, stream);
610 else
612 /* Unary prefix operator. */
613 fputs_filtered (op_str, stream);
614 if (myprec == PREC_BUILTIN_FUNCTION)
615 fputs_filtered ("(", stream);
616 print_subexp (exp, pos, stream, PREC_PREFIX);
617 if (myprec == PREC_BUILTIN_FUNCTION)
618 fputs_filtered (")", stream);
621 else
623 /* Binary operator. */
624 /* Print left operand.
625 If operator is right-associative,
626 increment precedence for this operand. */
627 print_subexp (exp, pos, stream,
628 (enum precedence) ((int) myprec + assoc));
629 /* Print the operator itself. */
630 if (assign_modify)
631 fprintf_filtered (stream, " %s= ", op_str);
632 else if (op_str[0] == ',')
633 fprintf_filtered (stream, "%s ", op_str);
634 else
635 fprintf_filtered (stream, " %s ", op_str);
636 /* Print right operand.
637 If operator is left-associative,
638 increment precedence for this operand. */
639 print_subexp (exp, pos, stream,
640 (enum precedence) ((int) myprec + !assoc));
643 if ((int) myprec < (int) prec)
644 fputs_filtered (")", stream);
647 /* Return the operator corresponding to opcode OP as
648 a string. NULL indicates that the opcode was not found in the
649 current language table. */
650 char *
651 op_string (enum exp_opcode op)
653 int tem;
654 const struct op_print *op_print_tab;
656 op_print_tab = current_language->la_op_print_tab;
657 for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
658 if (op_print_tab[tem].opcode == op)
659 return op_print_tab[tem].string;
660 return NULL;
663 /* Support for dumping the raw data from expressions in a human readable
664 form. */
666 static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
668 /* Name for OPCODE, when it appears in expression EXP. */
670 char *
671 op_name (struct expression *exp, enum exp_opcode opcode)
673 return exp->language_defn->la_exp_desc->op_name (opcode);
676 /* Default name for the standard operator OPCODE (i.e., one defined in
677 the definition of enum exp_opcode). */
679 char *
680 op_name_standard (enum exp_opcode opcode)
682 switch (opcode)
684 default:
686 static char buf[30];
688 sprintf (buf, "<unknown %d>", opcode);
689 return buf;
691 #define OP(name) \
692 case name: \
693 return #name ;
694 #include "std-operator.def"
695 #undef OP
699 /* Print a raw dump of expression EXP to STREAM.
700 NOTE, if non-NULL, is printed as extra explanatory text. */
702 void
703 dump_raw_expression (struct expression *exp, struct ui_file *stream,
704 char *note)
706 int elt;
707 char *opcode_name;
708 char *eltscan;
709 int eltsize;
711 fprintf_filtered (stream, "Dump of expression @ ");
712 gdb_print_host_address (exp, stream);
713 if (note)
714 fprintf_filtered (stream, ", %s:", note);
715 fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
716 exp->language_defn->la_name, exp->nelts,
717 (long) sizeof (union exp_element));
718 fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode",
719 "Hex Value", "String Value");
720 for (elt = 0; elt < exp->nelts; elt++)
722 fprintf_filtered (stream, "\t%5d ", elt);
723 opcode_name = op_name (exp, exp->elts[elt].opcode);
725 fprintf_filtered (stream, "%20s ", opcode_name);
726 print_longest (stream, 'd', 0, exp->elts[elt].longconst);
727 fprintf_filtered (stream, " ");
729 for (eltscan = (char *) &exp->elts[elt],
730 eltsize = sizeof (union exp_element);
731 eltsize-- > 0;
732 eltscan++)
734 fprintf_filtered (stream, "%c",
735 isprint (*eltscan) ? (*eltscan & 0xFF) : '.');
737 fprintf_filtered (stream, "\n");
741 /* Dump the subexpression of prefix expression EXP whose operator is at
742 position ELT onto STREAM. Returns the position of the next
743 subexpression in EXP. */
746 dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
748 static int indent = 0;
749 int i;
751 fprintf_filtered (stream, "\n");
752 fprintf_filtered (stream, "\t%5d ", elt);
754 for (i = 1; i <= indent; i++)
755 fprintf_filtered (stream, " ");
756 indent += 2;
758 fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode));
760 elt = dump_subexp_body (exp, stream, elt);
762 indent -= 2;
764 return elt;
767 /* Dump the operands of prefix expression EXP whose opcode is at
768 position ELT onto STREAM. Returns the position of the next
769 subexpression in EXP. */
771 static int
772 dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
774 return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
777 /* Default value for subexp_body in exp_descriptor vector. */
780 dump_subexp_body_standard (struct expression *exp,
781 struct ui_file *stream, int elt)
783 int opcode = exp->elts[elt++].opcode;
785 switch (opcode)
787 case TERNOP_COND:
788 case TERNOP_SLICE:
789 elt = dump_subexp (exp, stream, elt);
790 /* FALL THROUGH */
791 case BINOP_ADD:
792 case BINOP_SUB:
793 case BINOP_MUL:
794 case BINOP_DIV:
795 case BINOP_REM:
796 case BINOP_MOD:
797 case BINOP_LSH:
798 case BINOP_RSH:
799 case BINOP_LOGICAL_AND:
800 case BINOP_LOGICAL_OR:
801 case BINOP_BITWISE_AND:
802 case BINOP_BITWISE_IOR:
803 case BINOP_BITWISE_XOR:
804 case BINOP_EQUAL:
805 case BINOP_NOTEQUAL:
806 case BINOP_LESS:
807 case BINOP_GTR:
808 case BINOP_LEQ:
809 case BINOP_GEQ:
810 case BINOP_REPEAT:
811 case BINOP_ASSIGN:
812 case BINOP_COMMA:
813 case BINOP_SUBSCRIPT:
814 case BINOP_EXP:
815 case BINOP_MIN:
816 case BINOP_MAX:
817 case BINOP_INTDIV:
818 case BINOP_ASSIGN_MODIFY:
819 case BINOP_VAL:
820 case BINOP_CONCAT:
821 case BINOP_IN:
822 case BINOP_RANGE:
823 case BINOP_END:
824 case STRUCTOP_MEMBER:
825 case STRUCTOP_MPTR:
826 elt = dump_subexp (exp, stream, elt);
827 /* FALL THROUGH */
828 case UNOP_NEG:
829 case UNOP_LOGICAL_NOT:
830 case UNOP_COMPLEMENT:
831 case UNOP_IND:
832 case UNOP_ADDR:
833 case UNOP_PREINCREMENT:
834 case UNOP_POSTINCREMENT:
835 case UNOP_PREDECREMENT:
836 case UNOP_POSTDECREMENT:
837 case UNOP_SIZEOF:
838 case UNOP_PLUS:
839 case UNOP_CAP:
840 case UNOP_CHR:
841 case UNOP_ORD:
842 case UNOP_ABS:
843 case UNOP_FLOAT:
844 case UNOP_HIGH:
845 case UNOP_MAX:
846 case UNOP_MIN:
847 case UNOP_ODD:
848 case UNOP_TRUNC:
849 elt = dump_subexp (exp, stream, elt);
850 break;
851 case OP_LONG:
852 fprintf_filtered (stream, "Type @");
853 gdb_print_host_address (exp->elts[elt].type, stream);
854 fprintf_filtered (stream, " (");
855 type_print (exp->elts[elt].type, NULL, stream, 0);
856 fprintf_filtered (stream, "), value %ld (0x%lx)",
857 (long) exp->elts[elt + 1].longconst,
858 (long) exp->elts[elt + 1].longconst);
859 elt += 3;
860 break;
861 case OP_DOUBLE:
862 fprintf_filtered (stream, "Type @");
863 gdb_print_host_address (exp->elts[elt].type, stream);
864 fprintf_filtered (stream, " (");
865 type_print (exp->elts[elt].type, NULL, stream, 0);
866 fprintf_filtered (stream, "), value %g",
867 (double) exp->elts[elt + 1].doubleconst);
868 elt += 3;
869 break;
870 case OP_VAR_VALUE:
871 fprintf_filtered (stream, "Block @");
872 gdb_print_host_address (exp->elts[elt].block, stream);
873 fprintf_filtered (stream, ", symbol @");
874 gdb_print_host_address (exp->elts[elt + 1].symbol, stream);
875 fprintf_filtered (stream, " (%s)",
876 SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol));
877 elt += 3;
878 break;
879 case OP_VAR_ENTRY_VALUE:
880 fprintf_filtered (stream, "Entry value of symbol @");
881 gdb_print_host_address (exp->elts[elt].symbol, stream);
882 fprintf_filtered (stream, " (%s)",
883 SYMBOL_PRINT_NAME (exp->elts[elt].symbol));
884 elt += 2;
885 break;
886 case OP_LAST:
887 fprintf_filtered (stream, "History element %ld",
888 (long) exp->elts[elt].longconst);
889 elt += 2;
890 break;
891 case OP_REGISTER:
892 fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string);
893 elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1);
894 break;
895 case OP_INTERNALVAR:
896 fprintf_filtered (stream, "Internal var @");
897 gdb_print_host_address (exp->elts[elt].internalvar, stream);
898 fprintf_filtered (stream, " (%s)",
899 internalvar_name (exp->elts[elt].internalvar));
900 elt += 2;
901 break;
902 case OP_FUNCALL:
904 int i, nargs;
906 nargs = longest_to_int (exp->elts[elt].longconst);
908 fprintf_filtered (stream, "Number of args: %d", nargs);
909 elt += 2;
911 for (i = 1; i <= nargs + 1; i++)
912 elt = dump_subexp (exp, stream, elt);
914 break;
915 case OP_ARRAY:
917 int lower, upper;
918 int i;
920 lower = longest_to_int (exp->elts[elt].longconst);
921 upper = longest_to_int (exp->elts[elt + 1].longconst);
923 fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper);
924 elt += 3;
926 for (i = 1; i <= upper - lower + 1; i++)
927 elt = dump_subexp (exp, stream, elt);
929 break;
930 case UNOP_DYNAMIC_CAST:
931 case UNOP_REINTERPRET_CAST:
932 case UNOP_CAST_TYPE:
933 case UNOP_MEMVAL_TYPE:
934 fprintf_filtered (stream, " (");
935 elt = dump_subexp (exp, stream, elt);
936 fprintf_filtered (stream, ")");
937 elt = dump_subexp (exp, stream, elt);
938 break;
939 case UNOP_MEMVAL:
940 case UNOP_CAST:
941 fprintf_filtered (stream, "Type @");
942 gdb_print_host_address (exp->elts[elt].type, stream);
943 fprintf_filtered (stream, " (");
944 type_print (exp->elts[elt].type, NULL, stream, 0);
945 fprintf_filtered (stream, ")");
946 elt = dump_subexp (exp, stream, elt + 2);
947 break;
948 case UNOP_MEMVAL_TLS:
949 fprintf_filtered (stream, "TLS type @");
950 gdb_print_host_address (exp->elts[elt + 1].type, stream);
951 fprintf_filtered (stream, " (__thread /* \"%s\" */ ",
952 (exp->elts[elt].objfile == NULL ? "(null)"
953 : exp->elts[elt].objfile->name));
954 type_print (exp->elts[elt + 1].type, NULL, stream, 0);
955 fprintf_filtered (stream, ")");
956 elt = dump_subexp (exp, stream, elt + 3);
957 break;
958 case OP_TYPE:
959 fprintf_filtered (stream, "Type @");
960 gdb_print_host_address (exp->elts[elt].type, stream);
961 fprintf_filtered (stream, " (");
962 type_print (exp->elts[elt].type, NULL, stream, 0);
963 fprintf_filtered (stream, ")");
964 elt += 2;
965 break;
966 case OP_TYPEOF:
967 case OP_DECLTYPE:
968 fprintf_filtered (stream, "Typeof (");
969 elt = dump_subexp (exp, stream, elt);
970 fprintf_filtered (stream, ")");
971 break;
972 case STRUCTOP_STRUCT:
973 case STRUCTOP_PTR:
975 char *elem_name;
976 int len;
978 len = longest_to_int (exp->elts[elt].longconst);
979 elem_name = &exp->elts[elt + 1].string;
981 fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name);
982 elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1));
984 break;
985 case OP_SCOPE:
987 char *elem_name;
988 int len;
990 fprintf_filtered (stream, "Type @");
991 gdb_print_host_address (exp->elts[elt].type, stream);
992 fprintf_filtered (stream, " (");
993 type_print (exp->elts[elt].type, NULL, stream, 0);
994 fprintf_filtered (stream, ") ");
996 len = longest_to_int (exp->elts[elt + 1].longconst);
997 elem_name = &exp->elts[elt + 2].string;
999 fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name);
1000 elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
1002 break;
1003 case TYPE_INSTANCE:
1005 LONGEST len;
1007 len = exp->elts[elt++].longconst;
1008 fprintf_filtered (stream, "%s TypeInstance: ", plongest (len));
1009 while (len-- > 0)
1011 fprintf_filtered (stream, "Type @");
1012 gdb_print_host_address (exp->elts[elt].type, stream);
1013 fprintf_filtered (stream, " (");
1014 type_print (exp->elts[elt].type, NULL, stream, 0);
1015 fprintf_filtered (stream, ")");
1016 elt++;
1017 if (len > 0)
1018 fputs_filtered (", ", stream);
1020 /* Ending LEN and ending TYPE_INSTANCE. */
1021 elt += 2;
1022 elt = dump_subexp (exp, stream, elt);
1024 break;
1025 default:
1026 case OP_NULL:
1027 case MULTI_SUBSCRIPT:
1028 case OP_F77_UNDETERMINED_ARGLIST:
1029 case OP_COMPLEX:
1030 case OP_STRING:
1031 case OP_BOOL:
1032 case OP_M2_STRING:
1033 case OP_THIS:
1034 case OP_LABELED:
1035 case OP_NAME:
1036 fprintf_filtered (stream, "Unknown format");
1039 return elt;
1042 void
1043 dump_prefix_expression (struct expression *exp, struct ui_file *stream)
1045 int elt;
1047 fprintf_filtered (stream, "Dump of expression @ ");
1048 gdb_print_host_address (exp, stream);
1049 fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
1050 print_expression (exp, stream);
1051 fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1052 exp->language_defn->la_name, exp->nelts,
1053 (long) sizeof (union exp_element));
1054 fputs_filtered ("\n", stream);
1056 for (elt = 0; elt < exp->nelts;)
1057 elt = dump_subexp (exp, stream, elt);
1058 fputs_filtered ("\n", stream);