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