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