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