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