Commit | Line | Data |
---|---|---|
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 | 40 | void |
fba45db2 | 41 | print_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 | 52 | void |
f86f5ca3 | 53 | print_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. */ | |
61 | void | |
62 | print_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); | |
189 | LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0, | |
190 | &opts); | |
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); | |
208 | LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0, | |
209 | &opts); | |
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); | |
294 | LA_PRINT_STRING (stream, tempstr, nargs - 1, 1, 0, | |
295 | &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. */ | |
586 | char * | |
fba45db2 | 587 | op_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 | 602 | static char *op_name (struct expression *, enum exp_opcode); |
24daaebc | 603 | static 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 | 607 | static char * |
5f9769d1 PH |
608 | op_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 | ||
616 | char * | |
617 | op_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 | ||
805 | void | |
24daaebc PH |
806 | dump_raw_expression (struct expression *exp, struct ui_file *stream, |
807 | char *note) | |
c906108c SS |
808 | { |
809 | int elt; | |
810 | char *opcode_name; | |
811 | char *eltscan; | |
812 | int eltsize; | |
813 | ||
814 | fprintf_filtered (stream, "Dump of expression @ "); | |
d4f3574e | 815 | gdb_print_host_address (exp, stream); |
9d271fd8 | 816 | fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", |
c5aa993b | 817 | exp->language_defn->la_name, exp->nelts, |
9d271fd8 | 818 | (long) sizeof (union exp_element)); |
c906108c SS |
819 | fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode", |
820 | "Hex Value", "String Value"); | |
c5aa993b | 821 | for (elt = 0; elt < exp->nelts; elt++) |
c906108c SS |
822 | { |
823 | fprintf_filtered (stream, "\t%5d ", elt); | |
5f9769d1 | 824 | opcode_name = op_name (exp, exp->elts[elt].opcode); |
c906108c SS |
825 | |
826 | fprintf_filtered (stream, "%20s ", opcode_name); | |
c5aa993b | 827 | print_longest (stream, 'd', 0, exp->elts[elt].longconst); |
c906108c SS |
828 | fprintf_filtered (stream, " "); |
829 | ||
830 | for (eltscan = (char *) &exp->elts[elt], | |
c5aa993b | 831 | eltsize = sizeof (union exp_element); |
c906108c SS |
832 | eltsize-- > 0; |
833 | eltscan++) | |
834 | { | |
835 | fprintf_filtered (stream, "%c", | |
836 | isprint (*eltscan) ? (*eltscan & 0xFF) : '.'); | |
837 | } | |
838 | fprintf_filtered (stream, "\n"); | |
839 | } | |
840 | } | |
841 | ||
24daaebc PH |
842 | /* Dump the subexpression of prefix expression EXP whose operator is at |
843 | position ELT onto STREAM. Returns the position of the next | |
844 | subexpression in EXP. */ | |
c906108c | 845 | |
24daaebc | 846 | int |
fba45db2 | 847 | dump_subexp (struct expression *exp, struct ui_file *stream, int elt) |
c906108c SS |
848 | { |
849 | static int indent = 0; | |
850 | int i; | |
851 | ||
852 | fprintf_filtered (stream, "\n"); | |
853 | fprintf_filtered (stream, "\t%5d ", elt); | |
854 | ||
855 | for (i = 1; i <= indent; i++) | |
856 | fprintf_filtered (stream, " "); | |
857 | indent += 2; | |
858 | ||
5f9769d1 | 859 | fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode)); |
c906108c | 860 | |
24daaebc PH |
861 | elt = dump_subexp_body (exp, stream, elt); |
862 | ||
863 | indent -= 2; | |
864 | ||
865 | return elt; | |
866 | } | |
867 | ||
868 | /* Dump the operands of prefix expression EXP whose opcode is at | |
869 | position ELT onto STREAM. Returns the position of the next | |
870 | subexpression in EXP. */ | |
871 | ||
872 | static int | |
873 | dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) | |
5f9769d1 PH |
874 | { |
875 | return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt); | |
876 | } | |
877 | ||
878 | /* Default value for subexp_body in exp_descriptor vector. */ | |
879 | ||
880 | int | |
881 | dump_subexp_body_standard (struct expression *exp, | |
882 | struct ui_file *stream, int elt) | |
24daaebc PH |
883 | { |
884 | int opcode = exp->elts[elt++].opcode; | |
885 | ||
886 | switch (opcode) | |
c906108c SS |
887 | { |
888 | case TERNOP_COND: | |
889 | case TERNOP_SLICE: | |
890 | case TERNOP_SLICE_COUNT: | |
891 | elt = dump_subexp (exp, stream, elt); | |
892 | case BINOP_ADD: | |
893 | case BINOP_SUB: | |
894 | case BINOP_MUL: | |
895 | case BINOP_DIV: | |
896 | case BINOP_REM: | |
897 | case BINOP_MOD: | |
898 | case BINOP_LSH: | |
899 | case BINOP_RSH: | |
900 | case BINOP_LOGICAL_AND: | |
901 | case BINOP_LOGICAL_OR: | |
902 | case BINOP_BITWISE_AND: | |
903 | case BINOP_BITWISE_IOR: | |
904 | case BINOP_BITWISE_XOR: | |
905 | case BINOP_EQUAL: | |
906 | case BINOP_NOTEQUAL: | |
907 | case BINOP_LESS: | |
908 | case BINOP_GTR: | |
909 | case BINOP_LEQ: | |
910 | case BINOP_GEQ: | |
911 | case BINOP_REPEAT: | |
912 | case BINOP_ASSIGN: | |
913 | case BINOP_COMMA: | |
914 | case BINOP_SUBSCRIPT: | |
915 | case BINOP_EXP: | |
916 | case BINOP_MIN: | |
917 | case BINOP_MAX: | |
c906108c SS |
918 | case BINOP_INTDIV: |
919 | case BINOP_ASSIGN_MODIFY: | |
920 | case BINOP_VAL: | |
921 | case BINOP_INCL: | |
922 | case BINOP_EXCL: | |
923 | case BINOP_CONCAT: | |
924 | case BINOP_IN: | |
925 | case BINOP_RANGE: | |
926 | case BINOP_END: | |
0534816d DJ |
927 | case STRUCTOP_MEMBER: |
928 | case STRUCTOP_MPTR: | |
c906108c SS |
929 | elt = dump_subexp (exp, stream, elt); |
930 | case UNOP_NEG: | |
931 | case UNOP_LOGICAL_NOT: | |
932 | case UNOP_COMPLEMENT: | |
933 | case UNOP_IND: | |
934 | case UNOP_ADDR: | |
935 | case UNOP_PREINCREMENT: | |
936 | case UNOP_POSTINCREMENT: | |
937 | case UNOP_PREDECREMENT: | |
938 | case UNOP_POSTDECREMENT: | |
939 | case UNOP_SIZEOF: | |
940 | case UNOP_PLUS: | |
941 | case UNOP_CAP: | |
942 | case UNOP_CHR: | |
943 | case UNOP_ORD: | |
944 | case UNOP_ABS: | |
945 | case UNOP_FLOAT: | |
946 | case UNOP_HIGH: | |
947 | case UNOP_MAX: | |
948 | case UNOP_MIN: | |
949 | case UNOP_ODD: | |
950 | case UNOP_TRUNC: | |
951 | case UNOP_LOWER: | |
952 | case UNOP_UPPER: | |
953 | case UNOP_LENGTH: | |
954 | case UNOP_CARD: | |
955 | case UNOP_CHMAX: | |
956 | case UNOP_CHMIN: | |
957 | elt = dump_subexp (exp, stream, elt); | |
958 | break; | |
959 | case OP_LONG: | |
d4f3574e SS |
960 | fprintf_filtered (stream, "Type @"); |
961 | gdb_print_host_address (exp->elts[elt].type, stream); | |
962 | fprintf_filtered (stream, " ("); | |
c906108c SS |
963 | type_print (exp->elts[elt].type, NULL, stream, 0); |
964 | fprintf_filtered (stream, "), value %ld (0x%lx)", | |
c5aa993b JM |
965 | (long) exp->elts[elt + 1].longconst, |
966 | (long) exp->elts[elt + 1].longconst); | |
c906108c SS |
967 | elt += 3; |
968 | break; | |
969 | case OP_DOUBLE: | |
d4f3574e SS |
970 | fprintf_filtered (stream, "Type @"); |
971 | gdb_print_host_address (exp->elts[elt].type, stream); | |
972 | fprintf_filtered (stream, " ("); | |
c906108c SS |
973 | type_print (exp->elts[elt].type, NULL, stream, 0); |
974 | fprintf_filtered (stream, "), value %g", | |
c5aa993b | 975 | (double) exp->elts[elt + 1].doubleconst); |
c906108c SS |
976 | elt += 3; |
977 | break; | |
978 | case OP_VAR_VALUE: | |
d4f3574e SS |
979 | fprintf_filtered (stream, "Block @"); |
980 | gdb_print_host_address (exp->elts[elt].block, stream); | |
981 | fprintf_filtered (stream, ", symbol @"); | |
982 | gdb_print_host_address (exp->elts[elt + 1].symbol, stream); | |
983 | fprintf_filtered (stream, " (%s)", | |
3567439c | 984 | SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol)); |
c906108c SS |
985 | elt += 3; |
986 | break; | |
987 | case OP_LAST: | |
988 | fprintf_filtered (stream, "History element %ld", | |
c5aa993b | 989 | (long) exp->elts[elt].longconst); |
c906108c SS |
990 | elt += 2; |
991 | break; | |
992 | case OP_REGISTER: | |
67f3407f DJ |
993 | fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string); |
994 | elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1); | |
c906108c SS |
995 | break; |
996 | case OP_INTERNALVAR: | |
d4f3574e SS |
997 | fprintf_filtered (stream, "Internal var @"); |
998 | gdb_print_host_address (exp->elts[elt].internalvar, stream); | |
999 | fprintf_filtered (stream, " (%s)", | |
c906108c SS |
1000 | exp->elts[elt].internalvar->name); |
1001 | elt += 2; | |
1002 | break; | |
1003 | case OP_FUNCALL: | |
1004 | { | |
24daaebc | 1005 | int i, nargs; |
c906108c SS |
1006 | |
1007 | nargs = longest_to_int (exp->elts[elt].longconst); | |
1008 | ||
1009 | fprintf_filtered (stream, "Number of args: %d", nargs); | |
1010 | elt += 2; | |
1011 | ||
1012 | for (i = 1; i <= nargs + 1; i++) | |
1013 | elt = dump_subexp (exp, stream, elt); | |
1014 | } | |
1015 | break; | |
1016 | case OP_ARRAY: | |
1017 | { | |
1018 | int lower, upper; | |
1019 | int i; | |
1020 | ||
1021 | lower = longest_to_int (exp->elts[elt].longconst); | |
1022 | upper = longest_to_int (exp->elts[elt + 1].longconst); | |
1023 | ||
1024 | fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); | |
1025 | elt += 3; | |
1026 | ||
1027 | for (i = 1; i <= upper - lower + 1; i++) | |
1028 | elt = dump_subexp (exp, stream, elt); | |
1029 | } | |
1030 | break; | |
1031 | case UNOP_MEMVAL: | |
1032 | case UNOP_CAST: | |
d4f3574e SS |
1033 | fprintf_filtered (stream, "Type @"); |
1034 | gdb_print_host_address (exp->elts[elt].type, stream); | |
1035 | fprintf_filtered (stream, " ("); | |
c906108c SS |
1036 | type_print (exp->elts[elt].type, NULL, stream, 0); |
1037 | fprintf_filtered (stream, ")"); | |
1038 | elt = dump_subexp (exp, stream, elt + 2); | |
1039 | break; | |
9e35dae4 DJ |
1040 | case UNOP_MEMVAL_TLS: |
1041 | fprintf_filtered (stream, "TLS type @"); | |
1042 | gdb_print_host_address (exp->elts[elt + 1].type, stream); | |
1043 | fprintf_filtered (stream, " (__thread /* \"%s\" */ ", | |
1044 | (exp->elts[elt].objfile == NULL ? "(null)" | |
1045 | : exp->elts[elt].objfile->name)); | |
1046 | type_print (exp->elts[elt + 1].type, NULL, stream, 0); | |
1047 | fprintf_filtered (stream, ")"); | |
1048 | elt = dump_subexp (exp, stream, elt + 3); | |
1049 | break; | |
c906108c | 1050 | case OP_TYPE: |
d4f3574e SS |
1051 | fprintf_filtered (stream, "Type @"); |
1052 | gdb_print_host_address (exp->elts[elt].type, stream); | |
1053 | fprintf_filtered (stream, " ("); | |
c906108c SS |
1054 | type_print (exp->elts[elt].type, NULL, stream, 0); |
1055 | fprintf_filtered (stream, ")"); | |
1056 | elt += 2; | |
1057 | break; | |
1058 | case STRUCTOP_STRUCT: | |
1059 | case STRUCTOP_PTR: | |
1060 | { | |
1061 | char *elem_name; | |
1062 | int len; | |
1063 | ||
1064 | len = longest_to_int (exp->elts[elt].longconst); | |
1065 | elem_name = &exp->elts[elt + 1].string; | |
1066 | ||
1067 | fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); | |
1068 | elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); | |
1069 | } | |
1070 | break; | |
1071 | case OP_SCOPE: | |
1072 | { | |
1073 | char *elem_name; | |
1074 | int len; | |
1075 | ||
d4f3574e SS |
1076 | fprintf_filtered (stream, "Type @"); |
1077 | gdb_print_host_address (exp->elts[elt].type, stream); | |
1078 | fprintf_filtered (stream, " ("); | |
c906108c SS |
1079 | type_print (exp->elts[elt].type, NULL, stream, 0); |
1080 | fprintf_filtered (stream, ") "); | |
1081 | ||
1082 | len = longest_to_int (exp->elts[elt + 1].longconst); | |
1083 | elem_name = &exp->elts[elt + 2].string; | |
1084 | ||
1085 | fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); | |
1086 | elt += 4 + BYTES_TO_EXP_ELEM (len + 1); | |
1087 | } | |
1088 | break; | |
1089 | default: | |
1090 | case OP_NULL: | |
c906108c SS |
1091 | case MULTI_SUBSCRIPT: |
1092 | case OP_F77_UNDETERMINED_ARGLIST: | |
1093 | case OP_COMPLEX: | |
1094 | case OP_STRING: | |
1095 | case OP_BITSTRING: | |
1096 | case OP_BOOL: | |
1097 | case OP_M2_STRING: | |
1098 | case OP_THIS: | |
1099 | case OP_LABELED: | |
1100 | case OP_NAME: | |
c906108c SS |
1101 | fprintf_filtered (stream, "Unknown format"); |
1102 | } | |
1103 | ||
c906108c SS |
1104 | return elt; |
1105 | } | |
1106 | ||
1107 | void | |
24daaebc | 1108 | dump_prefix_expression (struct expression *exp, struct ui_file *stream) |
c906108c SS |
1109 | { |
1110 | int elt; | |
1111 | ||
1112 | fprintf_filtered (stream, "Dump of expression @ "); | |
d4f3574e | 1113 | gdb_print_host_address (exp, stream); |
24daaebc | 1114 | fputs_filtered (", after conversion to prefix form:\nExpression: `", stream); |
c906108c SS |
1115 | if (exp->elts[0].opcode != OP_TYPE) |
1116 | print_expression (exp, stream); | |
1117 | else | |
1118 | fputs_filtered ("Type printing not yet supported....", stream); | |
9d271fd8 | 1119 | fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", |
c5aa993b | 1120 | exp->language_defn->la_name, exp->nelts, |
9d271fd8 | 1121 | (long) sizeof (union exp_element)); |
c906108c SS |
1122 | fputs_filtered ("\n", stream); |
1123 | ||
c5aa993b | 1124 | for (elt = 0; elt < exp->nelts;) |
c906108c SS |
1125 | elt = dump_subexp (exp, stream, elt); |
1126 | fputs_filtered ("\n", stream); | |
1127 | } |