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