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