Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print in infix form a struct expression. |
1bac305b | 2 | |
e2882c85 | 3 | Copyright (C) 1986-2018 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" | |
21 | #include "symtab.h" | |
22 | #include "gdbtypes.h" | |
23 | #include "expression.h" | |
24 | #include "value.h" | |
25 | #include "language.h" | |
26 | #include "parser-defs.h" | |
eb8bc282 | 27 | #include "user-regs.h" /* For user_reg_map_regnum_to_name. */ |
82eeeb94 | 28 | #include "target.h" |
fe898f56 | 29 | #include "block.h" |
9e35dae4 | 30 | #include "objfiles.h" |
79a45b7d | 31 | #include "valprint.h" |
c906108c | 32 | |
c906108c | 33 | #include <ctype.h> |
c906108c | 34 | |
c906108c | 35 | void |
fba45db2 | 36 | print_expression (struct expression *exp, struct ui_file *stream) |
c906108c SS |
37 | { |
38 | int pc = 0; | |
d7f9d729 | 39 | |
c906108c SS |
40 | print_subexp (exp, &pc, stream, PREC_NULL); |
41 | } | |
42 | ||
43 | /* Print the subexpression of EXP that starts in position POS, on STREAM. | |
44 | PREC is the precedence of the surrounding operator; | |
45 | if the precedence of the main operator of this subexpression is less, | |
46 | parentheses are needed here. */ | |
47 | ||
5f9769d1 | 48 | void |
f86f5ca3 | 49 | print_subexp (struct expression *exp, int *pos, |
fba45db2 | 50 | struct ui_file *stream, enum precedence prec) |
5f9769d1 PH |
51 | { |
52 | exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec); | |
53 | } | |
54 | ||
55 | /* Standard implementation of print_subexp for use in language_defn | |
56 | vectors. */ | |
57 | void | |
58 | print_subexp_standard (struct expression *exp, int *pos, | |
59 | struct ui_file *stream, enum precedence prec) | |
c906108c | 60 | { |
f86f5ca3 PH |
61 | unsigned tem; |
62 | const struct op_print *op_print_tab; | |
63 | int pc; | |
c906108c | 64 | unsigned nargs; |
a121b7c1 | 65 | const char *op_str; |
c906108c SS |
66 | int assign_modify = 0; |
67 | enum exp_opcode opcode; | |
68 | enum precedence myprec = PREC_NULL; | |
69 | /* Set to 1 for a right-associative operator. */ | |
70 | int assoc = 0; | |
3d6d86c6 | 71 | struct value *val; |
c906108c SS |
72 | char *tempstr = NULL; |
73 | ||
74 | op_print_tab = exp->language_defn->la_op_print_tab; | |
75 | pc = (*pos)++; | |
76 | opcode = exp->elts[pc].opcode; | |
77 | switch (opcode) | |
78 | { | |
c5aa993b | 79 | /* Common ops */ |
c906108c | 80 | |
4f485ebc DE |
81 | case OP_TYPE: |
82 | (*pos) += 2; | |
83 | type_print (exp->elts[pc + 1].type, "", stream, 0); | |
84 | return; | |
85 | ||
c906108c SS |
86 | case OP_SCOPE: |
87 | myprec = PREC_PREFIX; | |
88 | assoc = 0; | |
89 | fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream); | |
90 | fputs_filtered ("::", stream); | |
91 | nargs = longest_to_int (exp->elts[pc + 2].longconst); | |
92 | (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1); | |
93 | fputs_filtered (&exp->elts[pc + 3].string, stream); | |
94 | return; | |
95 | ||
96 | case OP_LONG: | |
79a45b7d TT |
97 | { |
98 | struct value_print_options opts; | |
d7f9d729 | 99 | |
2a998fc0 | 100 | get_no_prettyformat_print_options (&opts); |
79a45b7d TT |
101 | (*pos) += 3; |
102 | value_print (value_from_longest (exp->elts[pc + 1].type, | |
103 | exp->elts[pc + 2].longconst), | |
104 | stream, &opts); | |
105 | } | |
c906108c SS |
106 | return; |
107 | ||
edd079d9 | 108 | case OP_FLOAT: |
79a45b7d TT |
109 | { |
110 | struct value_print_options opts; | |
d7f9d729 | 111 | |
2a998fc0 | 112 | get_no_prettyformat_print_options (&opts); |
79a45b7d | 113 | (*pos) += 3; |
edd079d9 UW |
114 | value_print (value_from_contents (exp->elts[pc + 1].type, |
115 | exp->elts[pc + 2].floatconst), | |
79a45b7d TT |
116 | stream, &opts); |
117 | } | |
c906108c SS |
118 | return; |
119 | ||
120 | case OP_VAR_VALUE: | |
121 | { | |
270140bd | 122 | const struct block *b; |
d7f9d729 | 123 | |
c906108c SS |
124 | (*pos) += 3; |
125 | b = exp->elts[pc + 1].block; | |
126 | if (b != NULL | |
127 | && BLOCK_FUNCTION (b) != NULL | |
de5ad195 | 128 | && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL) |
c906108c | 129 | { |
de5ad195 | 130 | fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream); |
c906108c SS |
131 | fputs_filtered ("::", stream); |
132 | } | |
de5ad195 | 133 | fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream); |
c906108c SS |
134 | } |
135 | return; | |
136 | ||
74ea4be4 PA |
137 | case OP_VAR_MSYM_VALUE: |
138 | { | |
139 | (*pos) += 3; | |
140 | fputs_filtered (MSYMBOL_PRINT_NAME (exp->elts[pc + 2].msymbol), stream); | |
141 | } | |
142 | return; | |
143 | ||
858be34c PA |
144 | case OP_FUNC_STATIC_VAR: |
145 | { | |
146 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
147 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
148 | fputs_filtered (&exp->elts[pc + 1].string, stream); | |
149 | } | |
150 | return; | |
151 | ||
36b11add JK |
152 | case OP_VAR_ENTRY_VALUE: |
153 | { | |
36b11add JK |
154 | (*pos) += 2; |
155 | fprintf_filtered (stream, "%s@entry", | |
156 | SYMBOL_PRINT_NAME (exp->elts[pc + 1].symbol)); | |
157 | } | |
158 | return; | |
159 | ||
c906108c SS |
160 | case OP_LAST: |
161 | (*pos) += 2; | |
162 | fprintf_filtered (stream, "$%d", | |
163 | longest_to_int (exp->elts[pc + 1].longconst)); | |
164 | return; | |
165 | ||
166 | case OP_REGISTER: | |
e36180d7 | 167 | { |
67f3407f | 168 | const char *name = &exp->elts[pc + 2].string; |
d7f9d729 | 169 | |
67f3407f | 170 | (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); |
eb8bc282 | 171 | fprintf_filtered (stream, "$%s", name); |
e36180d7 AC |
172 | return; |
173 | } | |
c906108c SS |
174 | |
175 | case OP_BOOL: | |
176 | (*pos) += 2; | |
177 | fprintf_filtered (stream, "%s", | |
178 | longest_to_int (exp->elts[pc + 1].longconst) | |
179 | ? "TRUE" : "FALSE"); | |
180 | return; | |
181 | ||
182 | case OP_INTERNALVAR: | |
183 | (*pos) += 2; | |
184 | fprintf_filtered (stream, "$%s", | |
c5aa993b | 185 | internalvar_name (exp->elts[pc + 1].internalvar)); |
c906108c SS |
186 | return; |
187 | ||
188 | case OP_FUNCALL: | |
bca65a23 | 189 | case OP_F77_UNDETERMINED_ARGLIST: |
c906108c SS |
190 | (*pos) += 2; |
191 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
192 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
193 | fputs_filtered (" (", stream); | |
194 | for (tem = 0; tem < nargs; tem++) | |
195 | { | |
196 | if (tem != 0) | |
197 | fputs_filtered (", ", stream); | |
198 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
199 | } | |
200 | fputs_filtered (")", stream); | |
201 | return; | |
202 | ||
203 | case OP_NAME: | |
c5aa993b | 204 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
c906108c SS |
205 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
206 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
207 | return; | |
208 | ||
209 | case OP_STRING: | |
79a45b7d TT |
210 | { |
211 | struct value_print_options opts; | |
d7f9d729 | 212 | |
79a45b7d TT |
213 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
214 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); | |
215 | /* LA_PRINT_STRING will print using the current repeat count threshold. | |
216 | If necessary, we can temporarily set it to zero, or pass it as an | |
217 | additional parameter to LA_PRINT_STRING. -fnf */ | |
218 | get_user_print_options (&opts); | |
6c7a06a3 | 219 | LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, |
ac91cd70 PA |
220 | (gdb_byte *) &exp->elts[pc + 2].string, nargs, |
221 | NULL, 0, &opts); | |
79a45b7d | 222 | } |
c906108c SS |
223 | return; |
224 | ||
3e43a32a MS |
225 | case OP_OBJC_NSSTRING: /* Objective-C Foundation Class |
226 | NSString constant. */ | |
79a45b7d TT |
227 | { |
228 | struct value_print_options opts; | |
d7f9d729 | 229 | |
79a45b7d TT |
230 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
231 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); | |
232 | fputs_filtered ("@\"", stream); | |
233 | get_user_print_options (&opts); | |
6c7a06a3 | 234 | LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, |
ac91cd70 PA |
235 | (gdb_byte *) &exp->elts[pc + 2].string, nargs, |
236 | NULL, 0, &opts); | |
79a45b7d TT |
237 | fputs_filtered ("\"", stream); |
238 | } | |
82eeeb94 AF |
239 | return; |
240 | ||
241 | case OP_OBJC_MSGCALL: | |
242 | { /* Objective C message (method) call. */ | |
243 | char *selector; | |
d7f9d729 | 244 | |
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); | |
249 | if (0 == target_read_string (exp->elts[pc + 1].longconst, | |
250 | &selector, 1024, NULL)) | |
251 | { | |
8a3fe4f8 | 252 | error (_("bad selector")); |
82eeeb94 AF |
253 | return; |
254 | } | |
255 | if (nargs) | |
256 | { | |
257 | char *s, *nextS; | |
d7f9d729 | 258 | |
224c3ddb | 259 | s = (char *) alloca (strlen (selector) + 1); |
82eeeb94 AF |
260 | strcpy (s, selector); |
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 | { | |
273 | fprintf_unfiltered (stream, " %s", selector); | |
274 | } | |
275 | fprintf_unfiltered (stream, "]"); | |
0963b4bd | 276 | /* "selector" was malloc'd by target_read_string. Free it. */ |
4ef3f3be | 277 | xfree (selector); |
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 | ||
584 | fputs_filtered ("RANGE(", stream); | |
585 | if (range_type == HIGH_BOUND_DEFAULT | |
586 | || range_type == NONE_BOUND_DEFAULT) | |
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 | { | |
689 | return exp->language_defn->la_exp_desc->op_name (opcode); | |
690 | } | |
691 | ||
692 | /* Default name for the standard operator OPCODE (i.e., one defined in | |
693 | the definition of enum exp_opcode). */ | |
694 | ||
a121b7c1 | 695 | const char * |
5f9769d1 | 696 | op_name_standard (enum exp_opcode opcode) |
c906108c SS |
697 | { |
698 | switch (opcode) | |
699 | { | |
700 | default: | |
701 | { | |
702 | static char buf[30]; | |
703 | ||
08850b56 | 704 | xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode); |
c906108c SS |
705 | return buf; |
706 | } | |
56c12414 JK |
707 | #define OP(name) \ |
708 | case name: \ | |
709 | return #name ; | |
710 | #include "std-operator.def" | |
711 | #undef OP | |
c906108c SS |
712 | } |
713 | } | |
714 | ||
a411cd0e DE |
715 | /* Print a raw dump of expression EXP to STREAM. |
716 | NOTE, if non-NULL, is printed as extra explanatory text. */ | |
717 | ||
c906108c | 718 | void |
24daaebc | 719 | dump_raw_expression (struct expression *exp, struct ui_file *stream, |
a121b7c1 | 720 | const char *note) |
c906108c SS |
721 | { |
722 | int elt; | |
c906108c SS |
723 | char *eltscan; |
724 | int eltsize; | |
725 | ||
726 | fprintf_filtered (stream, "Dump of expression @ "); | |
d4f3574e | 727 | gdb_print_host_address (exp, stream); |
a411cd0e DE |
728 | if (note) |
729 | fprintf_filtered (stream, ", %s:", note); | |
730 | fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n", | |
c5aa993b | 731 | exp->language_defn->la_name, exp->nelts, |
9d271fd8 | 732 | (long) sizeof (union exp_element)); |
c906108c SS |
733 | fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode", |
734 | "Hex Value", "String Value"); | |
c5aa993b | 735 | for (elt = 0; elt < exp->nelts; elt++) |
c906108c SS |
736 | { |
737 | fprintf_filtered (stream, "\t%5d ", elt); | |
c906108c | 738 | |
a121b7c1 | 739 | const char *opcode_name = op_name (exp, exp->elts[elt].opcode); |
c906108c | 740 | fprintf_filtered (stream, "%20s ", opcode_name); |
a121b7c1 | 741 | |
c5aa993b | 742 | print_longest (stream, 'd', 0, exp->elts[elt].longconst); |
c906108c SS |
743 | fprintf_filtered (stream, " "); |
744 | ||
745 | for (eltscan = (char *) &exp->elts[elt], | |
c5aa993b | 746 | eltsize = sizeof (union exp_element); |
c906108c SS |
747 | eltsize-- > 0; |
748 | eltscan++) | |
749 | { | |
750 | fprintf_filtered (stream, "%c", | |
751 | isprint (*eltscan) ? (*eltscan & 0xFF) : '.'); | |
752 | } | |
753 | fprintf_filtered (stream, "\n"); | |
754 | } | |
755 | } | |
756 | ||
24daaebc PH |
757 | /* Dump the subexpression of prefix expression EXP whose operator is at |
758 | position ELT onto STREAM. Returns the position of the next | |
759 | subexpression in EXP. */ | |
c906108c | 760 | |
24daaebc | 761 | int |
fba45db2 | 762 | dump_subexp (struct expression *exp, struct ui_file *stream, int elt) |
c906108c SS |
763 | { |
764 | static int indent = 0; | |
765 | int i; | |
766 | ||
767 | fprintf_filtered (stream, "\n"); | |
768 | fprintf_filtered (stream, "\t%5d ", elt); | |
769 | ||
770 | for (i = 1; i <= indent; i++) | |
771 | fprintf_filtered (stream, " "); | |
772 | indent += 2; | |
773 | ||
5f9769d1 | 774 | fprintf_filtered (stream, "%-20s ", op_name (exp, exp->elts[elt].opcode)); |
c906108c | 775 | |
24daaebc PH |
776 | elt = dump_subexp_body (exp, stream, elt); |
777 | ||
778 | indent -= 2; | |
779 | ||
780 | return elt; | |
781 | } | |
782 | ||
783 | /* Dump the operands of prefix expression EXP whose opcode is at | |
784 | position ELT onto STREAM. Returns the position of the next | |
785 | subexpression in EXP. */ | |
786 | ||
787 | static int | |
788 | dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) | |
5f9769d1 PH |
789 | { |
790 | return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt); | |
791 | } | |
792 | ||
793 | /* Default value for subexp_body in exp_descriptor vector. */ | |
794 | ||
795 | int | |
796 | dump_subexp_body_standard (struct expression *exp, | |
797 | struct ui_file *stream, int elt) | |
24daaebc PH |
798 | { |
799 | int opcode = exp->elts[elt++].opcode; | |
800 | ||
801 | switch (opcode) | |
c906108c SS |
802 | { |
803 | case TERNOP_COND: | |
804 | case TERNOP_SLICE: | |
c906108c | 805 | elt = dump_subexp (exp, stream, elt); |
cb969d61 | 806 | /* FALL THROUGH */ |
c906108c SS |
807 | case BINOP_ADD: |
808 | case BINOP_SUB: | |
809 | case BINOP_MUL: | |
810 | case BINOP_DIV: | |
811 | case BINOP_REM: | |
812 | case BINOP_MOD: | |
813 | case BINOP_LSH: | |
814 | case BINOP_RSH: | |
815 | case BINOP_LOGICAL_AND: | |
816 | case BINOP_LOGICAL_OR: | |
817 | case BINOP_BITWISE_AND: | |
818 | case BINOP_BITWISE_IOR: | |
819 | case BINOP_BITWISE_XOR: | |
820 | case BINOP_EQUAL: | |
821 | case BINOP_NOTEQUAL: | |
822 | case BINOP_LESS: | |
823 | case BINOP_GTR: | |
824 | case BINOP_LEQ: | |
825 | case BINOP_GEQ: | |
826 | case BINOP_REPEAT: | |
827 | case BINOP_ASSIGN: | |
828 | case BINOP_COMMA: | |
829 | case BINOP_SUBSCRIPT: | |
830 | case BINOP_EXP: | |
831 | case BINOP_MIN: | |
832 | case BINOP_MAX: | |
c906108c SS |
833 | case BINOP_INTDIV: |
834 | case BINOP_ASSIGN_MODIFY: | |
835 | case BINOP_VAL: | |
c906108c | 836 | case BINOP_CONCAT: |
c906108c | 837 | case BINOP_END: |
0534816d DJ |
838 | case STRUCTOP_MEMBER: |
839 | case STRUCTOP_MPTR: | |
c906108c | 840 | elt = dump_subexp (exp, stream, elt); |
cb969d61 | 841 | /* FALL THROUGH */ |
c906108c SS |
842 | case UNOP_NEG: |
843 | case UNOP_LOGICAL_NOT: | |
844 | case UNOP_COMPLEMENT: | |
845 | case UNOP_IND: | |
846 | case UNOP_ADDR: | |
847 | case UNOP_PREINCREMENT: | |
848 | case UNOP_POSTINCREMENT: | |
849 | case UNOP_PREDECREMENT: | |
850 | case UNOP_POSTDECREMENT: | |
851 | case UNOP_SIZEOF: | |
852 | case UNOP_PLUS: | |
853 | case UNOP_CAP: | |
854 | case UNOP_CHR: | |
855 | case UNOP_ORD: | |
856 | case UNOP_ABS: | |
857 | case UNOP_FLOAT: | |
858 | case UNOP_HIGH: | |
859 | case UNOP_MAX: | |
860 | case UNOP_MIN: | |
861 | case UNOP_ODD: | |
862 | case UNOP_TRUNC: | |
c906108c SS |
863 | elt = dump_subexp (exp, stream, elt); |
864 | break; | |
865 | case OP_LONG: | |
d4f3574e SS |
866 | fprintf_filtered (stream, "Type @"); |
867 | gdb_print_host_address (exp->elts[elt].type, stream); | |
868 | fprintf_filtered (stream, " ("); | |
c906108c SS |
869 | type_print (exp->elts[elt].type, NULL, stream, 0); |
870 | fprintf_filtered (stream, "), value %ld (0x%lx)", | |
c5aa993b JM |
871 | (long) exp->elts[elt + 1].longconst, |
872 | (long) exp->elts[elt + 1].longconst); | |
c906108c SS |
873 | elt += 3; |
874 | break; | |
edd079d9 | 875 | case OP_FLOAT: |
d4f3574e SS |
876 | fprintf_filtered (stream, "Type @"); |
877 | gdb_print_host_address (exp->elts[elt].type, stream); | |
878 | fprintf_filtered (stream, " ("); | |
c906108c | 879 | type_print (exp->elts[elt].type, NULL, stream, 0); |
edd079d9 UW |
880 | fprintf_filtered (stream, "), value "); |
881 | print_floating (exp->elts[elt + 1].floatconst, | |
882 | exp->elts[elt].type, stream); | |
c906108c SS |
883 | elt += 3; |
884 | break; | |
885 | case OP_VAR_VALUE: | |
d4f3574e SS |
886 | fprintf_filtered (stream, "Block @"); |
887 | gdb_print_host_address (exp->elts[elt].block, stream); | |
888 | fprintf_filtered (stream, ", symbol @"); | |
889 | gdb_print_host_address (exp->elts[elt + 1].symbol, stream); | |
890 | fprintf_filtered (stream, " (%s)", | |
3567439c | 891 | SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol)); |
c906108c SS |
892 | elt += 3; |
893 | break; | |
74ea4be4 PA |
894 | case OP_VAR_MSYM_VALUE: |
895 | fprintf_filtered (stream, "Objfile @"); | |
896 | gdb_print_host_address (exp->elts[elt].objfile, stream); | |
897 | fprintf_filtered (stream, ", msymbol @"); | |
898 | gdb_print_host_address (exp->elts[elt + 1].msymbol, stream); | |
899 | fprintf_filtered (stream, " (%s)", | |
900 | MSYMBOL_PRINT_NAME (exp->elts[elt + 1].msymbol)); | |
901 | elt += 3; | |
902 | break; | |
36b11add JK |
903 | case OP_VAR_ENTRY_VALUE: |
904 | fprintf_filtered (stream, "Entry value of symbol @"); | |
905 | gdb_print_host_address (exp->elts[elt].symbol, stream); | |
906 | fprintf_filtered (stream, " (%s)", | |
907 | SYMBOL_PRINT_NAME (exp->elts[elt].symbol)); | |
908 | elt += 2; | |
909 | break; | |
c906108c SS |
910 | case OP_LAST: |
911 | fprintf_filtered (stream, "History element %ld", | |
c5aa993b | 912 | (long) exp->elts[elt].longconst); |
c906108c SS |
913 | elt += 2; |
914 | break; | |
915 | case OP_REGISTER: | |
67f3407f DJ |
916 | fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string); |
917 | elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1); | |
c906108c SS |
918 | break; |
919 | case OP_INTERNALVAR: | |
d4f3574e SS |
920 | fprintf_filtered (stream, "Internal var @"); |
921 | gdb_print_host_address (exp->elts[elt].internalvar, stream); | |
922 | fprintf_filtered (stream, " (%s)", | |
4fa62494 | 923 | internalvar_name (exp->elts[elt].internalvar)); |
c906108c SS |
924 | elt += 2; |
925 | break; | |
926 | case OP_FUNCALL: | |
bca65a23 | 927 | case OP_F77_UNDETERMINED_ARGLIST: |
c906108c | 928 | { |
24daaebc | 929 | int i, nargs; |
c906108c SS |
930 | |
931 | nargs = longest_to_int (exp->elts[elt].longconst); | |
932 | ||
933 | fprintf_filtered (stream, "Number of args: %d", nargs); | |
934 | elt += 2; | |
935 | ||
936 | for (i = 1; i <= nargs + 1; i++) | |
937 | elt = dump_subexp (exp, stream, elt); | |
938 | } | |
939 | break; | |
940 | case OP_ARRAY: | |
941 | { | |
942 | int lower, upper; | |
943 | int i; | |
944 | ||
945 | lower = longest_to_int (exp->elts[elt].longconst); | |
946 | upper = longest_to_int (exp->elts[elt + 1].longconst); | |
947 | ||
948 | fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); | |
949 | elt += 3; | |
950 | ||
951 | for (i = 1; i <= upper - lower + 1; i++) | |
952 | elt = dump_subexp (exp, stream, elt); | |
953 | } | |
954 | break; | |
4e8f195d TT |
955 | case UNOP_DYNAMIC_CAST: |
956 | case UNOP_REINTERPRET_CAST: | |
9eaf6705 TT |
957 | case UNOP_CAST_TYPE: |
958 | case UNOP_MEMVAL_TYPE: | |
9eaf6705 TT |
959 | fprintf_filtered (stream, " ("); |
960 | elt = dump_subexp (exp, stream, elt); | |
961 | fprintf_filtered (stream, ")"); | |
962 | elt = dump_subexp (exp, stream, elt); | |
963 | break; | |
964 | case UNOP_MEMVAL: | |
965 | case UNOP_CAST: | |
d4f3574e SS |
966 | fprintf_filtered (stream, "Type @"); |
967 | gdb_print_host_address (exp->elts[elt].type, stream); | |
968 | fprintf_filtered (stream, " ("); | |
c906108c SS |
969 | type_print (exp->elts[elt].type, NULL, stream, 0); |
970 | fprintf_filtered (stream, ")"); | |
971 | elt = dump_subexp (exp, stream, elt + 2); | |
972 | break; | |
973 | case OP_TYPE: | |
d4f3574e SS |
974 | fprintf_filtered (stream, "Type @"); |
975 | gdb_print_host_address (exp->elts[elt].type, stream); | |
976 | fprintf_filtered (stream, " ("); | |
c906108c SS |
977 | type_print (exp->elts[elt].type, NULL, stream, 0); |
978 | fprintf_filtered (stream, ")"); | |
979 | elt += 2; | |
980 | break; | |
608b4967 TT |
981 | case OP_TYPEOF: |
982 | case OP_DECLTYPE: | |
983 | fprintf_filtered (stream, "Typeof ("); | |
984 | elt = dump_subexp (exp, stream, elt); | |
985 | fprintf_filtered (stream, ")"); | |
986 | break; | |
6e72ca20 TT |
987 | case OP_TYPEID: |
988 | fprintf_filtered (stream, "typeid ("); | |
989 | elt = dump_subexp (exp, stream, elt); | |
990 | fprintf_filtered (stream, ")"); | |
991 | break; | |
c906108c SS |
992 | case STRUCTOP_STRUCT: |
993 | case STRUCTOP_PTR: | |
994 | { | |
995 | char *elem_name; | |
996 | int len; | |
997 | ||
998 | len = longest_to_int (exp->elts[elt].longconst); | |
999 | elem_name = &exp->elts[elt + 1].string; | |
1000 | ||
1001 | fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); | |
1002 | elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); | |
1003 | } | |
1004 | break; | |
1005 | case OP_SCOPE: | |
1006 | { | |
1007 | char *elem_name; | |
1008 | int len; | |
1009 | ||
d4f3574e SS |
1010 | fprintf_filtered (stream, "Type @"); |
1011 | gdb_print_host_address (exp->elts[elt].type, stream); | |
1012 | fprintf_filtered (stream, " ("); | |
c906108c SS |
1013 | type_print (exp->elts[elt].type, NULL, stream, 0); |
1014 | fprintf_filtered (stream, ") "); | |
1015 | ||
1016 | len = longest_to_int (exp->elts[elt + 1].longconst); | |
1017 | elem_name = &exp->elts[elt + 2].string; | |
1018 | ||
1019 | fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); | |
1020 | elt += 4 + BYTES_TO_EXP_ELEM (len + 1); | |
1021 | } | |
1022 | break; | |
858be34c PA |
1023 | |
1024 | case OP_FUNC_STATIC_VAR: | |
1025 | { | |
1026 | int len = longest_to_int (exp->elts[elt].longconst); | |
1027 | const char *var_name = &exp->elts[elt + 1].string; | |
1028 | fprintf_filtered (stream, "Field name: `%.*s'", len, var_name); | |
1029 | elt += 3 + BYTES_TO_EXP_ELEM (len + 1); | |
1030 | } | |
1031 | break; | |
1032 | ||
600ea1be JK |
1033 | case TYPE_INSTANCE: |
1034 | { | |
3693fdb3 PA |
1035 | type_instance_flags flags |
1036 | = (type_instance_flag_value) longest_to_int (exp->elts[elt++].longconst); | |
1037 | LONGEST len = exp->elts[elt++].longconst; | |
600ea1be JK |
1038 | fprintf_filtered (stream, "%s TypeInstance: ", plongest (len)); |
1039 | while (len-- > 0) | |
1040 | { | |
1041 | fprintf_filtered (stream, "Type @"); | |
1042 | gdb_print_host_address (exp->elts[elt].type, stream); | |
1043 | fprintf_filtered (stream, " ("); | |
1044 | type_print (exp->elts[elt].type, NULL, stream, 0); | |
1045 | fprintf_filtered (stream, ")"); | |
1046 | elt++; | |
1047 | if (len > 0) | |
1048 | fputs_filtered (", ", stream); | |
1049 | } | |
3693fdb3 PA |
1050 | |
1051 | fprintf_filtered (stream, " Flags: %s (", hex_string (flags)); | |
1052 | bool space = false; | |
1053 | auto print_one = [&] (const char *mod) | |
1054 | { | |
1055 | if (space) | |
1056 | fputs_filtered (" ", stream); | |
1057 | space = true; | |
d6b687ac | 1058 | fprintf_filtered (stream, "%s", mod); |
3693fdb3 PA |
1059 | }; |
1060 | if (flags & TYPE_INSTANCE_FLAG_CONST) | |
1061 | print_one ("const"); | |
1062 | if (flags & TYPE_INSTANCE_FLAG_VOLATILE) | |
1063 | print_one ("volatile"); | |
1064 | fprintf_filtered (stream, ")"); | |
1065 | ||
600ea1be JK |
1066 | /* Ending LEN and ending TYPE_INSTANCE. */ |
1067 | elt += 2; | |
1068 | elt = dump_subexp (exp, stream, elt); | |
1069 | } | |
1070 | break; | |
2d40be18 SM |
1071 | case OP_STRING: |
1072 | { | |
1073 | LONGEST len = exp->elts[elt].longconst; | |
1074 | LONGEST type = exp->elts[elt + 1].longconst; | |
1075 | ||
1076 | fprintf_filtered (stream, "Language-specific string type: %s", | |
1077 | plongest (type)); | |
1078 | ||
1079 | /* Skip length. */ | |
1080 | elt += 1; | |
1081 | ||
1082 | /* Skip string content. */ | |
1083 | elt += BYTES_TO_EXP_ELEM (len); | |
1084 | ||
1085 | /* Skip length and ending OP_STRING. */ | |
1086 | elt += 2; | |
1087 | } | |
1088 | break; | |
01739a3b | 1089 | case OP_RANGE: |
e4b8a1c8 | 1090 | { |
01739a3b | 1091 | enum range_type range_type; |
e4b8a1c8 | 1092 | |
01739a3b | 1093 | range_type = (enum range_type) |
e4b8a1c8 TT |
1094 | longest_to_int (exp->elts[elt].longconst); |
1095 | elt += 2; | |
1096 | ||
1097 | switch (range_type) | |
1098 | { | |
1099 | case BOTH_BOUND_DEFAULT: | |
1100 | fputs_filtered ("Range '..'", stream); | |
1101 | break; | |
1102 | case LOW_BOUND_DEFAULT: | |
1103 | fputs_filtered ("Range '..EXP'", stream); | |
1104 | break; | |
1105 | case HIGH_BOUND_DEFAULT: | |
1106 | fputs_filtered ("Range 'EXP..'", stream); | |
1107 | break; | |
1108 | case NONE_BOUND_DEFAULT: | |
1109 | fputs_filtered ("Range 'EXP..EXP'", stream); | |
1110 | break; | |
1111 | default: | |
1112 | fputs_filtered ("Invalid Range!", stream); | |
1113 | break; | |
1114 | } | |
1115 | ||
1116 | if (range_type == HIGH_BOUND_DEFAULT | |
1117 | || range_type == NONE_BOUND_DEFAULT) | |
1118 | elt = dump_subexp (exp, stream, elt); | |
1119 | if (range_type == LOW_BOUND_DEFAULT | |
1120 | || range_type == NONE_BOUND_DEFAULT) | |
1121 | elt = dump_subexp (exp, stream, elt); | |
1122 | } | |
1123 | break; | |
1124 | ||
c906108c SS |
1125 | default: |
1126 | case OP_NULL: | |
c906108c | 1127 | case MULTI_SUBSCRIPT: |
c906108c | 1128 | case OP_COMPLEX: |
c906108c SS |
1129 | case OP_BOOL: |
1130 | case OP_M2_STRING: | |
1131 | case OP_THIS: | |
c906108c | 1132 | case OP_NAME: |
c906108c SS |
1133 | fprintf_filtered (stream, "Unknown format"); |
1134 | } | |
1135 | ||
c906108c SS |
1136 | return elt; |
1137 | } | |
1138 | ||
1139 | void | |
24daaebc | 1140 | dump_prefix_expression (struct expression *exp, struct ui_file *stream) |
c906108c SS |
1141 | { |
1142 | int elt; | |
1143 | ||
1144 | fprintf_filtered (stream, "Dump of expression @ "); | |
d4f3574e | 1145 | gdb_print_host_address (exp, stream); |
24daaebc | 1146 | fputs_filtered (", after conversion to prefix form:\nExpression: `", stream); |
4f485ebc | 1147 | print_expression (exp, stream); |
9d271fd8 | 1148 | fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", |
c5aa993b | 1149 | exp->language_defn->la_name, exp->nelts, |
9d271fd8 | 1150 | (long) sizeof (union exp_element)); |
c906108c SS |
1151 | fputs_filtered ("\n", stream); |
1152 | ||
c5aa993b | 1153 | for (elt = 0; elt < exp->nelts;) |
c906108c SS |
1154 | elt = dump_subexp (exp, stream, elt); |
1155 | fputs_filtered ("\n", stream); | |
1156 | } |