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