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