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