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