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