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