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