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