2002-02-19 Daniel Jacobowitz <drow@mvista.com>
[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
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 int is_chill = exp->language_defn->la_language == language_chill;
221 fputs_filtered (is_chill ? " [" : " {", stream);
222 for (tem = 0; tem < nargs; tem++)
223 {
224 if (tem != 0)
225 {
226 fputs_filtered (", ", stream);
227 }
228 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
229 }
230 fputs_filtered (is_chill ? "]" : "}", stream);
231 }
232 return;
233
234 case OP_LABELED:
235 tem = longest_to_int (exp->elts[pc + 1].longconst);
236 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
237
238 if (exp->language_defn->la_language == language_chill)
239 {
240 fputs_filtered (".", stream);
241 fputs_filtered (&exp->elts[pc + 2].string, stream);
242 fputs_filtered (exp->elts[*pos].opcode == OP_LABELED ? ", "
243 : ": ",
244 stream);
245 }
246 else
247 {
248 /* Gcc support both these syntaxes. Unsure which is preferred. */
249 #if 1
250 fputs_filtered (&exp->elts[pc + 2].string, stream);
251 fputs_filtered (": ", stream);
252 #else
253 fputs_filtered (".", stream);
254 fputs_filtered (&exp->elts[pc + 2].string, stream);
255 fputs_filtered ("=", stream);
256 #endif
257 }
258 print_subexp (exp, pos, stream, PREC_SUFFIX);
259 return;
260
261 case TERNOP_COND:
262 if ((int) prec > (int) PREC_COMMA)
263 fputs_filtered ("(", stream);
264 /* Print the subexpressions, forcing parentheses
265 around any binary operations within them.
266 This is more parentheses than are strictly necessary,
267 but it looks clearer. */
268 print_subexp (exp, pos, stream, PREC_HYPER);
269 fputs_filtered (" ? ", stream);
270 print_subexp (exp, pos, stream, PREC_HYPER);
271 fputs_filtered (" : ", stream);
272 print_subexp (exp, pos, stream, PREC_HYPER);
273 if ((int) prec > (int) PREC_COMMA)
274 fputs_filtered (")", stream);
275 return;
276
277 case TERNOP_SLICE:
278 case TERNOP_SLICE_COUNT:
279 print_subexp (exp, pos, stream, PREC_SUFFIX);
280 fputs_filtered ("(", stream);
281 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
282 fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream);
283 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
284 fputs_filtered (")", stream);
285 return;
286
287 case STRUCTOP_STRUCT:
288 tem = longest_to_int (exp->elts[pc + 1].longconst);
289 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
290 print_subexp (exp, pos, stream, PREC_SUFFIX);
291 fputs_filtered (".", stream);
292 fputs_filtered (&exp->elts[pc + 2].string, stream);
293 return;
294
295 /* Will not occur for Modula-2 */
296 case STRUCTOP_PTR:
297 tem = longest_to_int (exp->elts[pc + 1].longconst);
298 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
299 print_subexp (exp, pos, stream, PREC_SUFFIX);
300 fputs_filtered ("->", stream);
301 fputs_filtered (&exp->elts[pc + 2].string, stream);
302 return;
303
304 case BINOP_SUBSCRIPT:
305 print_subexp (exp, pos, stream, PREC_SUFFIX);
306 fputs_filtered ("[", stream);
307 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
308 fputs_filtered ("]", stream);
309 return;
310
311 case UNOP_POSTINCREMENT:
312 print_subexp (exp, pos, stream, PREC_SUFFIX);
313 fputs_filtered ("++", stream);
314 return;
315
316 case UNOP_POSTDECREMENT:
317 print_subexp (exp, pos, stream, PREC_SUFFIX);
318 fputs_filtered ("--", stream);
319 return;
320
321 case UNOP_CAST:
322 (*pos) += 2;
323 if ((int) prec > (int) PREC_PREFIX)
324 fputs_filtered ("(", stream);
325 fputs_filtered ("(", stream);
326 type_print (exp->elts[pc + 1].type, "", stream, 0);
327 fputs_filtered (") ", stream);
328 print_subexp (exp, pos, stream, PREC_PREFIX);
329 if ((int) prec > (int) PREC_PREFIX)
330 fputs_filtered (")", stream);
331 return;
332
333 case UNOP_MEMVAL:
334 (*pos) += 2;
335 if ((int) prec > (int) PREC_PREFIX)
336 fputs_filtered ("(", stream);
337 if (exp->elts[pc + 1].type->code == TYPE_CODE_FUNC &&
338 exp->elts[pc + 3].opcode == OP_LONG)
339 {
340 /* We have a minimal symbol fn, probably. It's encoded
341 as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
342 Swallow the OP_LONG (including both its opcodes); ignore
343 its type; print the value in the type of the MEMVAL. */
344 (*pos) += 4;
345 val = value_at_lazy (exp->elts[pc + 1].type,
346 (CORE_ADDR) exp->elts[pc + 5].longconst,
347 NULL);
348 value_print (val, stream, 0, Val_no_prettyprint);
349 }
350 else
351 {
352 fputs_filtered ("{", stream);
353 type_print (exp->elts[pc + 1].type, "", stream, 0);
354 fputs_filtered ("} ", stream);
355 print_subexp (exp, pos, stream, PREC_PREFIX);
356 }
357 if ((int) prec > (int) PREC_PREFIX)
358 fputs_filtered (")", stream);
359 return;
360
361 case BINOP_ASSIGN_MODIFY:
362 opcode = exp->elts[pc + 1].opcode;
363 (*pos) += 2;
364 myprec = PREC_ASSIGN;
365 assoc = 1;
366 assign_modify = 1;
367 op_str = "???";
368 for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
369 if (op_print_tab[tem].opcode == opcode)
370 {
371 op_str = op_print_tab[tem].string;
372 break;
373 }
374 if (op_print_tab[tem].opcode != opcode)
375 /* Not found; don't try to keep going because we don't know how
376 to interpret further elements. */
377 error ("Invalid expression");
378 break;
379
380 /* C++ ops */
381
382 case OP_THIS:
383 ++(*pos);
384 fputs_filtered ("this", stream);
385 return;
386
387 /* Modula-2 ops */
388
389 case MULTI_SUBSCRIPT:
390 (*pos) += 2;
391 nargs = longest_to_int (exp->elts[pc + 1].longconst);
392 print_subexp (exp, pos, stream, PREC_SUFFIX);
393 fprintf_unfiltered (stream, " [");
394 for (tem = 0; tem < nargs; tem++)
395 {
396 if (tem != 0)
397 fprintf_unfiltered (stream, ", ");
398 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
399 }
400 fprintf_unfiltered (stream, "]");
401 return;
402
403 case BINOP_VAL:
404 (*pos) += 2;
405 fprintf_unfiltered (stream, "VAL(");
406 type_print (exp->elts[pc + 1].type, "", stream, 0);
407 fprintf_unfiltered (stream, ",");
408 print_subexp (exp, pos, stream, PREC_PREFIX);
409 fprintf_unfiltered (stream, ")");
410 return;
411
412 case BINOP_INCL:
413 case BINOP_EXCL:
414 error ("print_subexp: Not implemented.");
415
416 /* Default ops */
417
418 default:
419 op_str = "???";
420 for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
421 if (op_print_tab[tem].opcode == opcode)
422 {
423 op_str = op_print_tab[tem].string;
424 myprec = op_print_tab[tem].precedence;
425 assoc = op_print_tab[tem].right_assoc;
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. For example, this happens
431 if opcode is OP_TYPE. */
432 error ("Invalid expression");
433 }
434
435 /* Note that PREC_BUILTIN will always emit parentheses. */
436 if ((int) myprec < (int) prec)
437 fputs_filtered ("(", stream);
438 if ((int) opcode > (int) BINOP_END)
439 {
440 if (assoc)
441 {
442 /* Unary postfix operator. */
443 print_subexp (exp, pos, stream, PREC_SUFFIX);
444 fputs_filtered (op_str, stream);
445 }
446 else
447 {
448 /* Unary prefix operator. */
449 fputs_filtered (op_str, stream);
450 if (myprec == PREC_BUILTIN_FUNCTION)
451 fputs_filtered ("(", stream);
452 print_subexp (exp, pos, stream, PREC_PREFIX);
453 if (myprec == PREC_BUILTIN_FUNCTION)
454 fputs_filtered (")", stream);
455 }
456 }
457 else
458 {
459 /* Binary operator. */
460 /* Print left operand.
461 If operator is right-associative,
462 increment precedence for this operand. */
463 print_subexp (exp, pos, stream,
464 (enum precedence) ((int) myprec + assoc));
465 /* Print the operator itself. */
466 if (assign_modify)
467 fprintf_filtered (stream, " %s= ", op_str);
468 else if (op_str[0] == ',')
469 fprintf_filtered (stream, "%s ", op_str);
470 else
471 fprintf_filtered (stream, " %s ", op_str);
472 /* Print right operand.
473 If operator is left-associative,
474 increment precedence for this operand. */
475 print_subexp (exp, pos, stream,
476 (enum precedence) ((int) myprec + !assoc));
477 }
478
479 if ((int) myprec < (int) prec)
480 fputs_filtered (")", stream);
481 }
482
483 /* Return the operator corresponding to opcode OP as
484 a string. NULL indicates that the opcode was not found in the
485 current language table. */
486 char *
487 op_string (enum exp_opcode op)
488 {
489 int tem;
490 register const struct op_print *op_print_tab;
491
492 op_print_tab = current_language->la_op_print_tab;
493 for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
494 if (op_print_tab[tem].opcode == op)
495 return op_print_tab[tem].string;
496 return NULL;
497 }
498
499 /* Support for dumping the raw data from expressions in a human readable
500 form. */
501
502 static char *op_name (int opcode);
503
504 static char *
505 op_name (int opcode)
506 {
507 switch (opcode)
508 {
509 default:
510 {
511 static char buf[30];
512
513 sprintf (buf, "<unknown %d>", opcode);
514 return buf;
515 }
516 case OP_NULL:
517 return "OP_NULL";
518 case BINOP_ADD:
519 return "BINOP_ADD";
520 case BINOP_SUB:
521 return "BINOP_SUB";
522 case BINOP_MUL:
523 return "BINOP_MUL";
524 case BINOP_DIV:
525 return "BINOP_DIV";
526 case BINOP_REM:
527 return "BINOP_REM";
528 case BINOP_MOD:
529 return "BINOP_MOD";
530 case BINOP_LSH:
531 return "BINOP_LSH";
532 case BINOP_RSH:
533 return "BINOP_RSH";
534 case BINOP_LOGICAL_AND:
535 return "BINOP_LOGICAL_AND";
536 case BINOP_LOGICAL_OR:
537 return "BINOP_LOGICAL_OR";
538 case BINOP_BITWISE_AND:
539 return "BINOP_BITWISE_AND";
540 case BINOP_BITWISE_IOR:
541 return "BINOP_BITWISE_IOR";
542 case BINOP_BITWISE_XOR:
543 return "BINOP_BITWISE_XOR";
544 case BINOP_EQUAL:
545 return "BINOP_EQUAL";
546 case BINOP_NOTEQUAL:
547 return "BINOP_NOTEQUAL";
548 case BINOP_LESS:
549 return "BINOP_LESS";
550 case BINOP_GTR:
551 return "BINOP_GTR";
552 case BINOP_LEQ:
553 return "BINOP_LEQ";
554 case BINOP_GEQ:
555 return "BINOP_GEQ";
556 case BINOP_REPEAT:
557 return "BINOP_REPEAT";
558 case BINOP_ASSIGN:
559 return "BINOP_ASSIGN";
560 case BINOP_COMMA:
561 return "BINOP_COMMA";
562 case BINOP_SUBSCRIPT:
563 return "BINOP_SUBSCRIPT";
564 case MULTI_SUBSCRIPT:
565 return "MULTI_SUBSCRIPT";
566 case BINOP_EXP:
567 return "BINOP_EXP";
568 case BINOP_MIN:
569 return "BINOP_MIN";
570 case BINOP_MAX:
571 return "BINOP_MAX";
572 case STRUCTOP_MEMBER:
573 return "STRUCTOP_MEMBER";
574 case STRUCTOP_MPTR:
575 return "STRUCTOP_MPTR";
576 case BINOP_INTDIV:
577 return "BINOP_INTDIV";
578 case BINOP_ASSIGN_MODIFY:
579 return "BINOP_ASSIGN_MODIFY";
580 case BINOP_VAL:
581 return "BINOP_VAL";
582 case BINOP_INCL:
583 return "BINOP_INCL";
584 case BINOP_EXCL:
585 return "BINOP_EXCL";
586 case BINOP_CONCAT:
587 return "BINOP_CONCAT";
588 case BINOP_RANGE:
589 return "BINOP_RANGE";
590 case BINOP_END:
591 return "BINOP_END";
592 case TERNOP_COND:
593 return "TERNOP_COND";
594 case TERNOP_SLICE:
595 return "TERNOP_SLICE";
596 case TERNOP_SLICE_COUNT:
597 return "TERNOP_SLICE_COUNT";
598 case OP_LONG:
599 return "OP_LONG";
600 case OP_DOUBLE:
601 return "OP_DOUBLE";
602 case OP_VAR_VALUE:
603 return "OP_VAR_VALUE";
604 case OP_LAST:
605 return "OP_LAST";
606 case OP_REGISTER:
607 return "OP_REGISTER";
608 case OP_INTERNALVAR:
609 return "OP_INTERNALVAR";
610 case OP_FUNCALL:
611 return "OP_FUNCALL";
612 case OP_STRING:
613 return "OP_STRING";
614 case OP_BITSTRING:
615 return "OP_BITSTRING";
616 case OP_ARRAY:
617 return "OP_ARRAY";
618 case UNOP_CAST:
619 return "UNOP_CAST";
620 case UNOP_MEMVAL:
621 return "UNOP_MEMVAL";
622 case UNOP_NEG:
623 return "UNOP_NEG";
624 case UNOP_LOGICAL_NOT:
625 return "UNOP_LOGICAL_NOT";
626 case UNOP_COMPLEMENT:
627 return "UNOP_COMPLEMENT";
628 case UNOP_IND:
629 return "UNOP_IND";
630 case UNOP_ADDR:
631 return "UNOP_ADDR";
632 case UNOP_PREINCREMENT:
633 return "UNOP_PREINCREMENT";
634 case UNOP_POSTINCREMENT:
635 return "UNOP_POSTINCREMENT";
636 case UNOP_PREDECREMENT:
637 return "UNOP_PREDECREMENT";
638 case UNOP_POSTDECREMENT:
639 return "UNOP_POSTDECREMENT";
640 case UNOP_SIZEOF:
641 return "UNOP_SIZEOF";
642 case UNOP_LOWER:
643 return "UNOP_LOWER";
644 case UNOP_UPPER:
645 return "UNOP_UPPER";
646 case UNOP_LENGTH:
647 return "UNOP_LENGTH";
648 case UNOP_PLUS:
649 return "UNOP_PLUS";
650 case UNOP_CAP:
651 return "UNOP_CAP";
652 case UNOP_CHR:
653 return "UNOP_CHR";
654 case UNOP_ORD:
655 return "UNOP_ORD";
656 case UNOP_ABS:
657 return "UNOP_ABS";
658 case UNOP_FLOAT:
659 return "UNOP_FLOAT";
660 case UNOP_HIGH:
661 return "UNOP_HIGH";
662 case UNOP_MAX:
663 return "UNOP_MAX";
664 case UNOP_MIN:
665 return "UNOP_MIN";
666 case UNOP_ODD:
667 return "UNOP_ODD";
668 case UNOP_TRUNC:
669 return "UNOP_TRUNC";
670 case OP_BOOL:
671 return "OP_BOOL";
672 case OP_M2_STRING:
673 return "OP_M2_STRING";
674 case STRUCTOP_STRUCT:
675 return "STRUCTOP_STRUCT";
676 case STRUCTOP_PTR:
677 return "STRUCTOP_PTR";
678 case OP_THIS:
679 return "OP_THIS";
680 case OP_SCOPE:
681 return "OP_SCOPE";
682 case OP_TYPE:
683 return "OP_TYPE";
684 case OP_LABELED:
685 return "OP_LABELED";
686 }
687 }
688
689 void
690 dump_prefix_expression (struct expression *exp, struct ui_file *stream,
691 char *note)
692 {
693 int elt;
694 char *opcode_name;
695 char *eltscan;
696 int eltsize;
697
698 fprintf_filtered (stream, "Dump of expression @ ");
699 gdb_print_host_address (exp, stream);
700 fprintf_filtered (stream, ", %s:\nExpression: `", note);
701 if (exp->elts[0].opcode != OP_TYPE)
702 print_expression (exp, stream);
703 else
704 fprintf_filtered (stream, "Type printing not yet supported....");
705 fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
706 exp->language_defn->la_name, exp->nelts,
707 (long) sizeof (union exp_element));
708 fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode",
709 "Hex Value", "String Value");
710 for (elt = 0; elt < exp->nelts; elt++)
711 {
712 fprintf_filtered (stream, "\t%5d ", elt);
713 opcode_name = op_name (exp->elts[elt].opcode);
714
715 fprintf_filtered (stream, "%20s ", opcode_name);
716 print_longest (stream, 'd', 0, exp->elts[elt].longconst);
717 fprintf_filtered (stream, " ");
718
719 for (eltscan = (char *) &exp->elts[elt],
720 eltsize = sizeof (union exp_element);
721 eltsize-- > 0;
722 eltscan++)
723 {
724 fprintf_filtered (stream, "%c",
725 isprint (*eltscan) ? (*eltscan & 0xFF) : '.');
726 }
727 fprintf_filtered (stream, "\n");
728 }
729 }
730
731 static int dump_subexp (struct expression *exp, struct ui_file *stream,
732 int elt);
733
734 static int
735 dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
736 {
737 static int indent = 0;
738 int i;
739
740 fprintf_filtered (stream, "\n");
741 fprintf_filtered (stream, "\t%5d ", elt);
742
743 for (i = 1; i <= indent; i++)
744 fprintf_filtered (stream, " ");
745 indent += 2;
746
747 fprintf_filtered (stream, "%-20s ", op_name (exp->elts[elt].opcode));
748
749 switch (exp->elts[elt++].opcode)
750 {
751 case TERNOP_COND:
752 case TERNOP_SLICE:
753 case TERNOP_SLICE_COUNT:
754 elt = dump_subexp (exp, stream, elt);
755 case BINOP_ADD:
756 case BINOP_SUB:
757 case BINOP_MUL:
758 case BINOP_DIV:
759 case BINOP_REM:
760 case BINOP_MOD:
761 case BINOP_LSH:
762 case BINOP_RSH:
763 case BINOP_LOGICAL_AND:
764 case BINOP_LOGICAL_OR:
765 case BINOP_BITWISE_AND:
766 case BINOP_BITWISE_IOR:
767 case BINOP_BITWISE_XOR:
768 case BINOP_EQUAL:
769 case BINOP_NOTEQUAL:
770 case BINOP_LESS:
771 case BINOP_GTR:
772 case BINOP_LEQ:
773 case BINOP_GEQ:
774 case BINOP_REPEAT:
775 case BINOP_ASSIGN:
776 case BINOP_COMMA:
777 case BINOP_SUBSCRIPT:
778 case BINOP_EXP:
779 case BINOP_MIN:
780 case BINOP_MAX:
781 case BINOP_INTDIV:
782 case BINOP_ASSIGN_MODIFY:
783 case BINOP_VAL:
784 case BINOP_INCL:
785 case BINOP_EXCL:
786 case BINOP_CONCAT:
787 case BINOP_IN:
788 case BINOP_RANGE:
789 case BINOP_END:
790 elt = dump_subexp (exp, stream, elt);
791 case UNOP_NEG:
792 case UNOP_LOGICAL_NOT:
793 case UNOP_COMPLEMENT:
794 case UNOP_IND:
795 case UNOP_ADDR:
796 case UNOP_PREINCREMENT:
797 case UNOP_POSTINCREMENT:
798 case UNOP_PREDECREMENT:
799 case UNOP_POSTDECREMENT:
800 case UNOP_SIZEOF:
801 case UNOP_PLUS:
802 case UNOP_CAP:
803 case UNOP_CHR:
804 case UNOP_ORD:
805 case UNOP_ABS:
806 case UNOP_FLOAT:
807 case UNOP_HIGH:
808 case UNOP_MAX:
809 case UNOP_MIN:
810 case UNOP_ODD:
811 case UNOP_TRUNC:
812 case UNOP_LOWER:
813 case UNOP_UPPER:
814 case UNOP_LENGTH:
815 case UNOP_CARD:
816 case UNOP_CHMAX:
817 case UNOP_CHMIN:
818 elt = dump_subexp (exp, stream, elt);
819 break;
820 case OP_LONG:
821 fprintf_filtered (stream, "Type @");
822 gdb_print_host_address (exp->elts[elt].type, stream);
823 fprintf_filtered (stream, " (");
824 type_print (exp->elts[elt].type, NULL, stream, 0);
825 fprintf_filtered (stream, "), value %ld (0x%lx)",
826 (long) exp->elts[elt + 1].longconst,
827 (long) exp->elts[elt + 1].longconst);
828 elt += 3;
829 break;
830 case OP_DOUBLE:
831 fprintf_filtered (stream, "Type @");
832 gdb_print_host_address (exp->elts[elt].type, stream);
833 fprintf_filtered (stream, " (");
834 type_print (exp->elts[elt].type, NULL, stream, 0);
835 fprintf_filtered (stream, "), value %g",
836 (double) exp->elts[elt + 1].doubleconst);
837 elt += 3;
838 break;
839 case OP_VAR_VALUE:
840 fprintf_filtered (stream, "Block @");
841 gdb_print_host_address (exp->elts[elt].block, stream);
842 fprintf_filtered (stream, ", symbol @");
843 gdb_print_host_address (exp->elts[elt + 1].symbol, stream);
844 fprintf_filtered (stream, " (%s)",
845 SYMBOL_NAME (exp->elts[elt + 1].symbol));
846 elt += 3;
847 break;
848 case OP_LAST:
849 fprintf_filtered (stream, "History element %ld",
850 (long) exp->elts[elt].longconst);
851 elt += 2;
852 break;
853 case OP_REGISTER:
854 fprintf_filtered (stream, "Register %ld",
855 (long) exp->elts[elt].longconst);
856 elt += 2;
857 break;
858 case OP_INTERNALVAR:
859 fprintf_filtered (stream, "Internal var @");
860 gdb_print_host_address (exp->elts[elt].internalvar, stream);
861 fprintf_filtered (stream, " (%s)",
862 exp->elts[elt].internalvar->name);
863 elt += 2;
864 break;
865 case OP_FUNCALL:
866 {
867 int nargs;
868
869 nargs = longest_to_int (exp->elts[elt].longconst);
870
871 fprintf_filtered (stream, "Number of args: %d", nargs);
872 elt += 2;
873
874 for (i = 1; i <= nargs + 1; i++)
875 elt = dump_subexp (exp, stream, elt);
876 }
877 break;
878 case OP_ARRAY:
879 {
880 int lower, upper;
881 int i;
882
883 lower = longest_to_int (exp->elts[elt].longconst);
884 upper = longest_to_int (exp->elts[elt + 1].longconst);
885
886 fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper);
887 elt += 3;
888
889 for (i = 1; i <= upper - lower + 1; i++)
890 elt = dump_subexp (exp, stream, elt);
891 }
892 break;
893 case UNOP_MEMVAL:
894 case UNOP_CAST:
895 fprintf_filtered (stream, "Type @");
896 gdb_print_host_address (exp->elts[elt].type, stream);
897 fprintf_filtered (stream, " (");
898 type_print (exp->elts[elt].type, NULL, stream, 0);
899 fprintf_filtered (stream, ")");
900 elt = dump_subexp (exp, stream, elt + 2);
901 break;
902 case OP_TYPE:
903 fprintf_filtered (stream, "Type @");
904 gdb_print_host_address (exp->elts[elt].type, stream);
905 fprintf_filtered (stream, " (");
906 type_print (exp->elts[elt].type, NULL, stream, 0);
907 fprintf_filtered (stream, ")");
908 elt += 2;
909 break;
910 case STRUCTOP_STRUCT:
911 case STRUCTOP_PTR:
912 {
913 char *elem_name;
914 int len;
915
916 len = longest_to_int (exp->elts[elt].longconst);
917 elem_name = &exp->elts[elt + 1].string;
918
919 fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name);
920 elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1));
921 }
922 break;
923 case OP_SCOPE:
924 {
925 char *elem_name;
926 int len;
927
928 fprintf_filtered (stream, "Type @");
929 gdb_print_host_address (exp->elts[elt].type, stream);
930 fprintf_filtered (stream, " (");
931 type_print (exp->elts[elt].type, NULL, stream, 0);
932 fprintf_filtered (stream, ") ");
933
934 len = longest_to_int (exp->elts[elt + 1].longconst);
935 elem_name = &exp->elts[elt + 2].string;
936
937 fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name);
938 elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
939 }
940 break;
941 default:
942 case OP_NULL:
943 case STRUCTOP_MEMBER:
944 case STRUCTOP_MPTR:
945 case MULTI_SUBSCRIPT:
946 case OP_F77_UNDETERMINED_ARGLIST:
947 case OP_COMPLEX:
948 case OP_STRING:
949 case OP_BITSTRING:
950 case OP_BOOL:
951 case OP_M2_STRING:
952 case OP_THIS:
953 case OP_LABELED:
954 case OP_NAME:
955 case OP_EXPRSTRING:
956 fprintf_filtered (stream, "Unknown format");
957 }
958
959 indent -= 2;
960
961 return elt;
962 }
963
964 void
965 dump_postfix_expression (struct expression *exp, struct ui_file *stream,
966 char *note)
967 {
968 int elt;
969
970 fprintf_filtered (stream, "Dump of expression @ ");
971 gdb_print_host_address (exp, stream);
972 fprintf_filtered (stream, ", %s:\nExpression: `", note);
973 if (exp->elts[0].opcode != OP_TYPE)
974 print_expression (exp, stream);
975 else
976 fputs_filtered ("Type printing not yet supported....", stream);
977 fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
978 exp->language_defn->la_name, exp->nelts,
979 (long) sizeof (union exp_element));
980 fputs_filtered ("\n", stream);
981
982 for (elt = 0; elt < exp->nelts;)
983 elt = dump_subexp (exp, stream, elt);
984 fputs_filtered ("\n", stream);
985 }
This page took 0.049045 seconds and 4 git commands to generate.