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