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