Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print in infix form a struct expression. |
d9fcf2fb | 2 | Copyright (C) 1986, 1989, 1991, 2000 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
c5aa993b JM |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "expression.h" | |
25 | #include "value.h" | |
26 | #include "language.h" | |
27 | #include "parser-defs.h" | |
28 | ||
29 | #ifdef HAVE_CTYPE_H | |
30 | #include <ctype.h> | |
31 | #endif | |
32 | ||
33 | /* Prototypes for local functions */ | |
34 | ||
d9fcf2fb JM |
35 | static void print_subexp (struct expression *, int *, struct ui_file *, |
36 | enum precedence); | |
c906108c SS |
37 | |
38 | void | |
39 | print_expression (exp, stream) | |
40 | struct expression *exp; | |
d9fcf2fb | 41 | struct ui_file *stream; |
c906108c SS |
42 | { |
43 | int pc = 0; | |
44 | print_subexp (exp, &pc, stream, PREC_NULL); | |
45 | } | |
46 | ||
47 | /* Print the subexpression of EXP that starts in position POS, on STREAM. | |
48 | PREC is the precedence of the surrounding operator; | |
49 | if the precedence of the main operator of this subexpression is less, | |
50 | parentheses are needed here. */ | |
51 | ||
52 | static void | |
53 | print_subexp (exp, pos, stream, prec) | |
54 | register struct expression *exp; | |
55 | register int *pos; | |
d9fcf2fb | 56 | struct ui_file *stream; |
c906108c SS |
57 | enum precedence prec; |
58 | { | |
59 | register unsigned tem; | |
60 | register const struct op_print *op_print_tab; | |
61 | register int pc; | |
62 | unsigned nargs; | |
63 | register char *op_str; | |
64 | int assign_modify = 0; | |
65 | enum exp_opcode opcode; | |
66 | enum precedence myprec = PREC_NULL; | |
67 | /* Set to 1 for a right-associative operator. */ | |
68 | int assoc = 0; | |
69 | value_ptr val; | |
70 | char *tempstr = NULL; | |
71 | ||
72 | op_print_tab = exp->language_defn->la_op_print_tab; | |
73 | pc = (*pos)++; | |
74 | opcode = exp->elts[pc].opcode; | |
75 | switch (opcode) | |
76 | { | |
c5aa993b | 77 | /* Common ops */ |
c906108c SS |
78 | |
79 | case OP_SCOPE: | |
80 | myprec = PREC_PREFIX; | |
81 | assoc = 0; | |
82 | fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream); | |
83 | fputs_filtered ("::", stream); | |
84 | nargs = longest_to_int (exp->elts[pc + 2].longconst); | |
85 | (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1); | |
86 | fputs_filtered (&exp->elts[pc + 3].string, stream); | |
87 | return; | |
88 | ||
89 | case OP_LONG: | |
90 | (*pos) += 3; | |
91 | value_print (value_from_longest (exp->elts[pc + 1].type, | |
92 | exp->elts[pc + 2].longconst), | |
93 | stream, 0, Val_no_prettyprint); | |
94 | return; | |
95 | ||
96 | case OP_DOUBLE: | |
97 | (*pos) += 3; | |
98 | value_print (value_from_double (exp->elts[pc + 1].type, | |
99 | exp->elts[pc + 2].doubleconst), | |
100 | stream, 0, Val_no_prettyprint); | |
101 | return; | |
102 | ||
103 | case OP_VAR_VALUE: | |
104 | { | |
105 | struct block *b; | |
106 | (*pos) += 3; | |
107 | b = exp->elts[pc + 1].block; | |
108 | if (b != NULL | |
109 | && BLOCK_FUNCTION (b) != NULL | |
110 | && SYMBOL_SOURCE_NAME (BLOCK_FUNCTION (b)) != NULL) | |
111 | { | |
112 | fputs_filtered (SYMBOL_SOURCE_NAME (BLOCK_FUNCTION (b)), stream); | |
113 | fputs_filtered ("::", stream); | |
114 | } | |
115 | fputs_filtered (SYMBOL_SOURCE_NAME (exp->elts[pc + 2].symbol), stream); | |
116 | } | |
117 | return; | |
118 | ||
119 | case OP_LAST: | |
120 | (*pos) += 2; | |
121 | fprintf_filtered (stream, "$%d", | |
122 | longest_to_int (exp->elts[pc + 1].longconst)); | |
123 | return; | |
124 | ||
125 | case OP_REGISTER: | |
126 | (*pos) += 2; | |
127 | fprintf_filtered (stream, "$%s", | |
c5aa993b | 128 | REGISTER_NAME (longest_to_int (exp->elts[pc + 1].longconst))); |
c906108c SS |
129 | return; |
130 | ||
131 | case OP_BOOL: | |
132 | (*pos) += 2; | |
133 | fprintf_filtered (stream, "%s", | |
134 | longest_to_int (exp->elts[pc + 1].longconst) | |
135 | ? "TRUE" : "FALSE"); | |
136 | return; | |
137 | ||
138 | case OP_INTERNALVAR: | |
139 | (*pos) += 2; | |
140 | fprintf_filtered (stream, "$%s", | |
c5aa993b | 141 | internalvar_name (exp->elts[pc + 1].internalvar)); |
c906108c SS |
142 | return; |
143 | ||
144 | case OP_FUNCALL: | |
145 | (*pos) += 2; | |
146 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
147 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
148 | fputs_filtered (" (", stream); | |
149 | for (tem = 0; tem < nargs; tem++) | |
150 | { | |
151 | if (tem != 0) | |
152 | fputs_filtered (", ", stream); | |
153 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
154 | } | |
155 | fputs_filtered (")", stream); | |
156 | return; | |
157 | ||
158 | case OP_NAME: | |
159 | case OP_EXPRSTRING: | |
c5aa993b | 160 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
c906108c SS |
161 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
162 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
163 | return; | |
164 | ||
165 | case OP_STRING: | |
c5aa993b | 166 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
c906108c SS |
167 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
168 | /* LA_PRINT_STRING will print using the current repeat count threshold. | |
c5aa993b JM |
169 | If necessary, we can temporarily set it to zero, or pass it as an |
170 | additional parameter to LA_PRINT_STRING. -fnf */ | |
c906108c SS |
171 | LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0); |
172 | return; | |
173 | ||
174 | case OP_BITSTRING: | |
c5aa993b | 175 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
c906108c SS |
176 | (*pos) |
177 | += 3 + BYTES_TO_EXP_ELEM ((nargs + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT); | |
178 | fprintf_unfiltered (stream, "B'<unimplemented>'"); | |
179 | return; | |
180 | ||
181 | case OP_ARRAY: | |
182 | (*pos) += 3; | |
183 | nargs = longest_to_int (exp->elts[pc + 2].longconst); | |
184 | nargs -= longest_to_int (exp->elts[pc + 1].longconst); | |
185 | nargs++; | |
186 | tem = 0; | |
187 | if (exp->elts[pc + 4].opcode == OP_LONG | |
188 | && exp->elts[pc + 5].type == builtin_type_char | |
189 | && exp->language_defn->la_language == language_c) | |
190 | { | |
191 | /* Attempt to print C character arrays using string syntax. | |
192 | Walk through the args, picking up one character from each | |
193 | of the OP_LONG expression elements. If any array element | |
194 | does not match our expection of what we should find for | |
195 | a simple string, revert back to array printing. Note that | |
196 | the last expression element is an explicit null terminator | |
197 | byte, which doesn't get printed. */ | |
198 | tempstr = alloca (nargs); | |
199 | pc += 4; | |
200 | while (tem < nargs) | |
201 | { | |
202 | if (exp->elts[pc].opcode != OP_LONG | |
203 | || exp->elts[pc + 1].type != builtin_type_char) | |
204 | { | |
205 | /* Not a simple array of char, use regular array printing. */ | |
206 | tem = 0; | |
207 | break; | |
208 | } | |
209 | else | |
210 | { | |
211 | tempstr[tem++] = | |
212 | longest_to_int (exp->elts[pc + 2].longconst); | |
213 | pc += 4; | |
214 | } | |
215 | } | |
216 | } | |
217 | if (tem > 0) | |
218 | { | |
219 | LA_PRINT_STRING (stream, tempstr, nargs - 1, 1, 0); | |
220 | (*pos) = pc; | |
221 | } | |
222 | else | |
223 | { | |
224 | int is_chill = exp->language_defn->la_language == language_chill; | |
225 | fputs_filtered (is_chill ? " [" : " {", stream); | |
226 | for (tem = 0; tem < nargs; tem++) | |
227 | { | |
228 | if (tem != 0) | |
229 | { | |
230 | fputs_filtered (", ", stream); | |
231 | } | |
232 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
233 | } | |
234 | fputs_filtered (is_chill ? "]" : "}", stream); | |
235 | } | |
236 | return; | |
237 | ||
238 | case OP_LABELED: | |
239 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
240 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
241 | ||
242 | if (exp->language_defn->la_language == language_chill) | |
243 | { | |
244 | fputs_filtered (".", stream); | |
245 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
246 | fputs_filtered (exp->elts[*pos].opcode == OP_LABELED ? ", " | |
247 | : ": ", | |
248 | stream); | |
249 | } | |
250 | else | |
251 | { | |
252 | /* Gcc support both these syntaxes. Unsure which is preferred. */ | |
253 | #if 1 | |
254 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
255 | fputs_filtered (": ", stream); | |
256 | #else | |
257 | fputs_filtered (".", stream); | |
258 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
259 | fputs_filtered ("=", stream); | |
260 | #endif | |
261 | } | |
262 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
263 | return; | |
264 | ||
265 | case TERNOP_COND: | |
266 | if ((int) prec > (int) PREC_COMMA) | |
267 | fputs_filtered ("(", stream); | |
268 | /* Print the subexpressions, forcing parentheses | |
c5aa993b JM |
269 | around any binary operations within them. |
270 | This is more parentheses than are strictly necessary, | |
271 | but it looks clearer. */ | |
c906108c SS |
272 | print_subexp (exp, pos, stream, PREC_HYPER); |
273 | fputs_filtered (" ? ", stream); | |
274 | print_subexp (exp, pos, stream, PREC_HYPER); | |
275 | fputs_filtered (" : ", stream); | |
276 | print_subexp (exp, pos, stream, PREC_HYPER); | |
277 | if ((int) prec > (int) PREC_COMMA) | |
278 | fputs_filtered (")", stream); | |
279 | return; | |
280 | ||
281 | case TERNOP_SLICE: | |
282 | case TERNOP_SLICE_COUNT: | |
283 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
284 | fputs_filtered ("(", stream); | |
285 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
286 | fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream); | |
287 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
288 | fputs_filtered (")", stream); | |
289 | return; | |
290 | ||
291 | case STRUCTOP_STRUCT: | |
292 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
293 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
294 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
295 | fputs_filtered (".", stream); | |
296 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
297 | return; | |
298 | ||
c5aa993b | 299 | /* Will not occur for Modula-2 */ |
c906108c SS |
300 | case STRUCTOP_PTR: |
301 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
302 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
303 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
304 | fputs_filtered ("->", stream); | |
305 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
306 | return; | |
307 | ||
308 | case BINOP_SUBSCRIPT: | |
309 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
310 | fputs_filtered ("[", stream); | |
311 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
312 | fputs_filtered ("]", stream); | |
313 | return; | |
314 | ||
315 | case UNOP_POSTINCREMENT: | |
316 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
317 | fputs_filtered ("++", stream); | |
318 | return; | |
319 | ||
320 | case UNOP_POSTDECREMENT: | |
321 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
322 | fputs_filtered ("--", stream); | |
323 | return; | |
324 | ||
325 | case UNOP_CAST: | |
326 | (*pos) += 2; | |
327 | if ((int) prec > (int) PREC_PREFIX) | |
c5aa993b | 328 | fputs_filtered ("(", stream); |
c906108c SS |
329 | fputs_filtered ("(", stream); |
330 | type_print (exp->elts[pc + 1].type, "", stream, 0); | |
331 | fputs_filtered (") ", stream); | |
332 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
333 | if ((int) prec > (int) PREC_PREFIX) | |
c5aa993b | 334 | fputs_filtered (")", stream); |
c906108c SS |
335 | return; |
336 | ||
337 | case UNOP_MEMVAL: | |
338 | (*pos) += 2; | |
339 | if ((int) prec > (int) PREC_PREFIX) | |
c5aa993b | 340 | fputs_filtered ("(", stream); |
c906108c | 341 | if (exp->elts[pc + 1].type->code == TYPE_CODE_FUNC && |
c5aa993b JM |
342 | exp->elts[pc + 3].opcode == OP_LONG) |
343 | { | |
344 | /* We have a minimal symbol fn, probably. It's encoded | |
345 | as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address). | |
346 | Swallow the OP_LONG (including both its opcodes); ignore | |
347 | its type; print the value in the type of the MEMVAL. */ | |
348 | (*pos) += 4; | |
349 | val = value_at_lazy (exp->elts[pc + 1].type, | |
350 | (CORE_ADDR) exp->elts[pc + 5].longconst, | |
351 | NULL); | |
352 | value_print (val, stream, 0, Val_no_prettyprint); | |
353 | } | |
354 | else | |
355 | { | |
356 | fputs_filtered ("{", stream); | |
357 | type_print (exp->elts[pc + 1].type, "", stream, 0); | |
358 | fputs_filtered ("} ", stream); | |
359 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
360 | } | |
c906108c | 361 | if ((int) prec > (int) PREC_PREFIX) |
c5aa993b | 362 | fputs_filtered (")", stream); |
c906108c SS |
363 | return; |
364 | ||
365 | case BINOP_ASSIGN_MODIFY: | |
366 | opcode = exp->elts[pc + 1].opcode; | |
367 | (*pos) += 2; | |
368 | myprec = PREC_ASSIGN; | |
369 | assoc = 1; | |
370 | assign_modify = 1; | |
371 | op_str = "???"; | |
372 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) | |
373 | if (op_print_tab[tem].opcode == opcode) | |
374 | { | |
375 | op_str = op_print_tab[tem].string; | |
376 | break; | |
377 | } | |
378 | if (op_print_tab[tem].opcode != opcode) | |
379 | /* Not found; don't try to keep going because we don't know how | |
380 | to interpret further elements. */ | |
381 | error ("Invalid expression"); | |
382 | break; | |
383 | ||
c5aa993b | 384 | /* C++ ops */ |
c906108c SS |
385 | |
386 | case OP_THIS: | |
387 | ++(*pos); | |
388 | fputs_filtered ("this", stream); | |
389 | return; | |
390 | ||
c5aa993b | 391 | /* Modula-2 ops */ |
c906108c SS |
392 | |
393 | case MULTI_SUBSCRIPT: | |
394 | (*pos) += 2; | |
395 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
396 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
397 | fprintf_unfiltered (stream, " ["); | |
398 | for (tem = 0; tem < nargs; tem++) | |
399 | { | |
400 | if (tem != 0) | |
401 | fprintf_unfiltered (stream, ", "); | |
402 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
403 | } | |
404 | fprintf_unfiltered (stream, "]"); | |
405 | return; | |
406 | ||
407 | case BINOP_VAL: | |
c5aa993b JM |
408 | (*pos) += 2; |
409 | fprintf_unfiltered (stream, "VAL("); | |
410 | type_print (exp->elts[pc + 1].type, "", stream, 0); | |
411 | fprintf_unfiltered (stream, ","); | |
412 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
413 | fprintf_unfiltered (stream, ")"); | |
c906108c | 414 | return; |
c5aa993b | 415 | |
c906108c SS |
416 | case BINOP_INCL: |
417 | case BINOP_EXCL: | |
c5aa993b | 418 | error ("print_subexp: Not implemented."); |
c906108c | 419 | |
c5aa993b | 420 | /* Default ops */ |
c906108c SS |
421 | |
422 | default: | |
423 | op_str = "???"; | |
424 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) | |
425 | if (op_print_tab[tem].opcode == opcode) | |
426 | { | |
427 | op_str = op_print_tab[tem].string; | |
428 | myprec = op_print_tab[tem].precedence; | |
429 | assoc = op_print_tab[tem].right_assoc; | |
430 | break; | |
431 | } | |
432 | if (op_print_tab[tem].opcode != opcode) | |
433 | /* Not found; don't try to keep going because we don't know how | |
434 | to interpret further elements. For example, this happens | |
435 | if opcode is OP_TYPE. */ | |
436 | error ("Invalid expression"); | |
c5aa993b | 437 | } |
c906108c SS |
438 | |
439 | /* Note that PREC_BUILTIN will always emit parentheses. */ | |
440 | if ((int) myprec < (int) prec) | |
441 | fputs_filtered ("(", stream); | |
442 | if ((int) opcode > (int) BINOP_END) | |
443 | { | |
444 | if (assoc) | |
445 | { | |
446 | /* Unary postfix operator. */ | |
447 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
448 | fputs_filtered (op_str, stream); | |
449 | } | |
450 | else | |
451 | { | |
452 | /* Unary prefix operator. */ | |
453 | fputs_filtered (op_str, stream); | |
454 | if (myprec == PREC_BUILTIN_FUNCTION) | |
455 | fputs_filtered ("(", stream); | |
456 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
457 | if (myprec == PREC_BUILTIN_FUNCTION) | |
458 | fputs_filtered (")", stream); | |
459 | } | |
460 | } | |
461 | else | |
462 | { | |
463 | /* Binary operator. */ | |
464 | /* Print left operand. | |
c5aa993b JM |
465 | If operator is right-associative, |
466 | increment precedence for this operand. */ | |
c906108c SS |
467 | print_subexp (exp, pos, stream, |
468 | (enum precedence) ((int) myprec + assoc)); | |
469 | /* Print the operator itself. */ | |
470 | if (assign_modify) | |
471 | fprintf_filtered (stream, " %s= ", op_str); | |
472 | else if (op_str[0] == ',') | |
473 | fprintf_filtered (stream, "%s ", op_str); | |
474 | else | |
475 | fprintf_filtered (stream, " %s ", op_str); | |
476 | /* Print right operand. | |
c5aa993b JM |
477 | If operator is left-associative, |
478 | increment precedence for this operand. */ | |
c906108c SS |
479 | print_subexp (exp, pos, stream, |
480 | (enum precedence) ((int) myprec + !assoc)); | |
481 | } | |
482 | ||
483 | if ((int) myprec < (int) prec) | |
484 | fputs_filtered (")", stream); | |
485 | } | |
486 | ||
487 | /* Return the operator corresponding to opcode OP as | |
488 | a string. NULL indicates that the opcode was not found in the | |
489 | current language table. */ | |
490 | char * | |
c5aa993b JM |
491 | op_string (op) |
492 | enum exp_opcode op; | |
c906108c SS |
493 | { |
494 | int tem; | |
495 | register const struct op_print *op_print_tab; | |
496 | ||
497 | op_print_tab = current_language->la_op_print_tab; | |
498 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) | |
499 | if (op_print_tab[tem].opcode == op) | |
500 | return op_print_tab[tem].string; | |
501 | return NULL; | |
502 | } | |
503 | ||
c906108c SS |
504 | /* Support for dumping the raw data from expressions in a human readable |
505 | form. */ | |
506 | ||
a14ed312 | 507 | static char *op_name (int opcode); |
c906108c SS |
508 | |
509 | static char * | |
510 | op_name (opcode) | |
c5aa993b | 511 | int opcode; |
c906108c SS |
512 | { |
513 | switch (opcode) | |
514 | { | |
515 | default: | |
516 | { | |
517 | static char buf[30]; | |
518 | ||
519 | sprintf (buf, "<unknown %d>", opcode); | |
520 | return buf; | |
521 | } | |
c5aa993b JM |
522 | case OP_NULL: |
523 | return "OP_NULL"; | |
524 | case BINOP_ADD: | |
525 | return "BINOP_ADD"; | |
526 | case BINOP_SUB: | |
527 | return "BINOP_SUB"; | |
528 | case BINOP_MUL: | |
529 | return "BINOP_MUL"; | |
530 | case BINOP_DIV: | |
531 | return "BINOP_DIV"; | |
532 | case BINOP_REM: | |
533 | return "BINOP_REM"; | |
534 | case BINOP_MOD: | |
535 | return "BINOP_MOD"; | |
536 | case BINOP_LSH: | |
537 | return "BINOP_LSH"; | |
538 | case BINOP_RSH: | |
539 | return "BINOP_RSH"; | |
540 | case BINOP_LOGICAL_AND: | |
541 | return "BINOP_LOGICAL_AND"; | |
542 | case BINOP_LOGICAL_OR: | |
543 | return "BINOP_LOGICAL_OR"; | |
544 | case BINOP_BITWISE_AND: | |
545 | return "BINOP_BITWISE_AND"; | |
546 | case BINOP_BITWISE_IOR: | |
547 | return "BINOP_BITWISE_IOR"; | |
548 | case BINOP_BITWISE_XOR: | |
549 | return "BINOP_BITWISE_XOR"; | |
550 | case BINOP_EQUAL: | |
551 | return "BINOP_EQUAL"; | |
552 | case BINOP_NOTEQUAL: | |
553 | return "BINOP_NOTEQUAL"; | |
554 | case BINOP_LESS: | |
555 | return "BINOP_LESS"; | |
556 | case BINOP_GTR: | |
557 | return "BINOP_GTR"; | |
558 | case BINOP_LEQ: | |
559 | return "BINOP_LEQ"; | |
560 | case BINOP_GEQ: | |
561 | return "BINOP_GEQ"; | |
562 | case BINOP_REPEAT: | |
563 | return "BINOP_REPEAT"; | |
564 | case BINOP_ASSIGN: | |
565 | return "BINOP_ASSIGN"; | |
566 | case BINOP_COMMA: | |
567 | return "BINOP_COMMA"; | |
568 | case BINOP_SUBSCRIPT: | |
569 | return "BINOP_SUBSCRIPT"; | |
570 | case MULTI_SUBSCRIPT: | |
571 | return "MULTI_SUBSCRIPT"; | |
572 | case BINOP_EXP: | |
573 | return "BINOP_EXP"; | |
574 | case BINOP_MIN: | |
575 | return "BINOP_MIN"; | |
576 | case BINOP_MAX: | |
577 | return "BINOP_MAX"; | |
c5aa993b JM |
578 | case STRUCTOP_MEMBER: |
579 | return "STRUCTOP_MEMBER"; | |
580 | case STRUCTOP_MPTR: | |
581 | return "STRUCTOP_MPTR"; | |
582 | case BINOP_INTDIV: | |
583 | return "BINOP_INTDIV"; | |
584 | case BINOP_ASSIGN_MODIFY: | |
585 | return "BINOP_ASSIGN_MODIFY"; | |
586 | case BINOP_VAL: | |
587 | return "BINOP_VAL"; | |
588 | case BINOP_INCL: | |
589 | return "BINOP_INCL"; | |
590 | case BINOP_EXCL: | |
591 | return "BINOP_EXCL"; | |
592 | case BINOP_CONCAT: | |
593 | return "BINOP_CONCAT"; | |
594 | case BINOP_RANGE: | |
595 | return "BINOP_RANGE"; | |
596 | case BINOP_END: | |
597 | return "BINOP_END"; | |
598 | case TERNOP_COND: | |
599 | return "TERNOP_COND"; | |
600 | case TERNOP_SLICE: | |
601 | return "TERNOP_SLICE"; | |
602 | case TERNOP_SLICE_COUNT: | |
603 | return "TERNOP_SLICE_COUNT"; | |
604 | case OP_LONG: | |
605 | return "OP_LONG"; | |
606 | case OP_DOUBLE: | |
607 | return "OP_DOUBLE"; | |
608 | case OP_VAR_VALUE: | |
609 | return "OP_VAR_VALUE"; | |
610 | case OP_LAST: | |
611 | return "OP_LAST"; | |
612 | case OP_REGISTER: | |
613 | return "OP_REGISTER"; | |
614 | case OP_INTERNALVAR: | |
615 | return "OP_INTERNALVAR"; | |
616 | case OP_FUNCALL: | |
617 | return "OP_FUNCALL"; | |
618 | case OP_STRING: | |
619 | return "OP_STRING"; | |
620 | case OP_BITSTRING: | |
621 | return "OP_BITSTRING"; | |
622 | case OP_ARRAY: | |
623 | return "OP_ARRAY"; | |
624 | case UNOP_CAST: | |
625 | return "UNOP_CAST"; | |
626 | case UNOP_MEMVAL: | |
627 | return "UNOP_MEMVAL"; | |
628 | case UNOP_NEG: | |
629 | return "UNOP_NEG"; | |
630 | case UNOP_LOGICAL_NOT: | |
631 | return "UNOP_LOGICAL_NOT"; | |
632 | case UNOP_COMPLEMENT: | |
633 | return "UNOP_COMPLEMENT"; | |
634 | case UNOP_IND: | |
635 | return "UNOP_IND"; | |
636 | case UNOP_ADDR: | |
637 | return "UNOP_ADDR"; | |
638 | case UNOP_PREINCREMENT: | |
639 | return "UNOP_PREINCREMENT"; | |
640 | case UNOP_POSTINCREMENT: | |
641 | return "UNOP_POSTINCREMENT"; | |
642 | case UNOP_PREDECREMENT: | |
643 | return "UNOP_PREDECREMENT"; | |
644 | case UNOP_POSTDECREMENT: | |
645 | return "UNOP_POSTDECREMENT"; | |
646 | case UNOP_SIZEOF: | |
647 | return "UNOP_SIZEOF"; | |
648 | case UNOP_LOWER: | |
649 | return "UNOP_LOWER"; | |
650 | case UNOP_UPPER: | |
651 | return "UNOP_UPPER"; | |
652 | case UNOP_LENGTH: | |
653 | return "UNOP_LENGTH"; | |
654 | case UNOP_PLUS: | |
655 | return "UNOP_PLUS"; | |
656 | case UNOP_CAP: | |
657 | return "UNOP_CAP"; | |
658 | case UNOP_CHR: | |
659 | return "UNOP_CHR"; | |
660 | case UNOP_ORD: | |
661 | return "UNOP_ORD"; | |
662 | case UNOP_ABS: | |
663 | return "UNOP_ABS"; | |
664 | case UNOP_FLOAT: | |
665 | return "UNOP_FLOAT"; | |
666 | case UNOP_HIGH: | |
667 | return "UNOP_HIGH"; | |
668 | case UNOP_MAX: | |
669 | return "UNOP_MAX"; | |
670 | case UNOP_MIN: | |
671 | return "UNOP_MIN"; | |
672 | case UNOP_ODD: | |
673 | return "UNOP_ODD"; | |
674 | case UNOP_TRUNC: | |
675 | return "UNOP_TRUNC"; | |
676 | case OP_BOOL: | |
677 | return "OP_BOOL"; | |
678 | case OP_M2_STRING: | |
679 | return "OP_M2_STRING"; | |
680 | case STRUCTOP_STRUCT: | |
681 | return "STRUCTOP_STRUCT"; | |
682 | case STRUCTOP_PTR: | |
683 | return "STRUCTOP_PTR"; | |
684 | case OP_THIS: | |
685 | return "OP_THIS"; | |
686 | case OP_SCOPE: | |
687 | return "OP_SCOPE"; | |
688 | case OP_TYPE: | |
689 | return "OP_TYPE"; | |
690 | case OP_LABELED: | |
691 | return "OP_LABELED"; | |
c906108c SS |
692 | } |
693 | } | |
694 | ||
695 | void | |
696 | dump_prefix_expression (exp, stream, note) | |
697 | struct expression *exp; | |
d9fcf2fb | 698 | struct ui_file *stream; |
c906108c SS |
699 | char *note; |
700 | { | |
701 | int elt; | |
702 | char *opcode_name; | |
703 | char *eltscan; | |
704 | int eltsize; | |
705 | ||
706 | fprintf_filtered (stream, "Dump of expression @ "); | |
d4f3574e | 707 | gdb_print_host_address (exp, stream); |
c906108c SS |
708 | fprintf_filtered (stream, ", %s:\nExpression: `", note); |
709 | if (exp->elts[0].opcode != OP_TYPE) | |
710 | print_expression (exp, stream); | |
711 | else | |
712 | fprintf_filtered (stream, "Type printing not yet supported...."); | |
9d271fd8 | 713 | fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", |
c5aa993b | 714 | exp->language_defn->la_name, exp->nelts, |
9d271fd8 | 715 | (long) sizeof (union exp_element)); |
c906108c SS |
716 | fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode", |
717 | "Hex Value", "String Value"); | |
c5aa993b | 718 | for (elt = 0; elt < exp->nelts; elt++) |
c906108c SS |
719 | { |
720 | fprintf_filtered (stream, "\t%5d ", elt); | |
c5aa993b | 721 | opcode_name = op_name (exp->elts[elt].opcode); |
c906108c SS |
722 | |
723 | fprintf_filtered (stream, "%20s ", opcode_name); | |
c5aa993b | 724 | print_longest (stream, 'd', 0, exp->elts[elt].longconst); |
c906108c SS |
725 | fprintf_filtered (stream, " "); |
726 | ||
727 | for (eltscan = (char *) &exp->elts[elt], | |
c5aa993b | 728 | eltsize = sizeof (union exp_element); |
c906108c SS |
729 | eltsize-- > 0; |
730 | eltscan++) | |
731 | { | |
732 | fprintf_filtered (stream, "%c", | |
733 | isprint (*eltscan) ? (*eltscan & 0xFF) : '.'); | |
734 | } | |
735 | fprintf_filtered (stream, "\n"); | |
736 | } | |
737 | } | |
738 | ||
a14ed312 KB |
739 | static int dump_subexp (struct expression *exp, struct ui_file *stream, |
740 | int elt); | |
c906108c SS |
741 | |
742 | static int | |
743 | dump_subexp (exp, stream, elt) | |
744 | struct expression *exp; | |
d9fcf2fb | 745 | struct ui_file *stream; |
c906108c SS |
746 | int elt; |
747 | { | |
748 | static int indent = 0; | |
749 | int i; | |
750 | ||
751 | fprintf_filtered (stream, "\n"); | |
752 | fprintf_filtered (stream, "\t%5d ", elt); | |
753 | ||
754 | for (i = 1; i <= indent; i++) | |
755 | fprintf_filtered (stream, " "); | |
756 | indent += 2; | |
757 | ||
758 | fprintf_filtered (stream, "%-20s ", op_name (exp->elts[elt].opcode)); | |
759 | ||
c5aa993b | 760 | switch (exp->elts[elt++].opcode) |
c906108c SS |
761 | { |
762 | case TERNOP_COND: | |
763 | case TERNOP_SLICE: | |
764 | case TERNOP_SLICE_COUNT: | |
765 | elt = dump_subexp (exp, stream, elt); | |
766 | case BINOP_ADD: | |
767 | case BINOP_SUB: | |
768 | case BINOP_MUL: | |
769 | case BINOP_DIV: | |
770 | case BINOP_REM: | |
771 | case BINOP_MOD: | |
772 | case BINOP_LSH: | |
773 | case BINOP_RSH: | |
774 | case BINOP_LOGICAL_AND: | |
775 | case BINOP_LOGICAL_OR: | |
776 | case BINOP_BITWISE_AND: | |
777 | case BINOP_BITWISE_IOR: | |
778 | case BINOP_BITWISE_XOR: | |
779 | case BINOP_EQUAL: | |
780 | case BINOP_NOTEQUAL: | |
781 | case BINOP_LESS: | |
782 | case BINOP_GTR: | |
783 | case BINOP_LEQ: | |
784 | case BINOP_GEQ: | |
785 | case BINOP_REPEAT: | |
786 | case BINOP_ASSIGN: | |
787 | case BINOP_COMMA: | |
788 | case BINOP_SUBSCRIPT: | |
789 | case BINOP_EXP: | |
790 | case BINOP_MIN: | |
791 | case BINOP_MAX: | |
c906108c SS |
792 | case BINOP_INTDIV: |
793 | case BINOP_ASSIGN_MODIFY: | |
794 | case BINOP_VAL: | |
795 | case BINOP_INCL: | |
796 | case BINOP_EXCL: | |
797 | case BINOP_CONCAT: | |
798 | case BINOP_IN: | |
799 | case BINOP_RANGE: | |
800 | case BINOP_END: | |
801 | elt = dump_subexp (exp, stream, elt); | |
802 | case UNOP_NEG: | |
803 | case UNOP_LOGICAL_NOT: | |
804 | case UNOP_COMPLEMENT: | |
805 | case UNOP_IND: | |
806 | case UNOP_ADDR: | |
807 | case UNOP_PREINCREMENT: | |
808 | case UNOP_POSTINCREMENT: | |
809 | case UNOP_PREDECREMENT: | |
810 | case UNOP_POSTDECREMENT: | |
811 | case UNOP_SIZEOF: | |
812 | case UNOP_PLUS: | |
813 | case UNOP_CAP: | |
814 | case UNOP_CHR: | |
815 | case UNOP_ORD: | |
816 | case UNOP_ABS: | |
817 | case UNOP_FLOAT: | |
818 | case UNOP_HIGH: | |
819 | case UNOP_MAX: | |
820 | case UNOP_MIN: | |
821 | case UNOP_ODD: | |
822 | case UNOP_TRUNC: | |
823 | case UNOP_LOWER: | |
824 | case UNOP_UPPER: | |
825 | case UNOP_LENGTH: | |
826 | case UNOP_CARD: | |
827 | case UNOP_CHMAX: | |
828 | case UNOP_CHMIN: | |
829 | elt = dump_subexp (exp, stream, elt); | |
830 | break; | |
831 | case OP_LONG: | |
d4f3574e SS |
832 | fprintf_filtered (stream, "Type @"); |
833 | gdb_print_host_address (exp->elts[elt].type, stream); | |
834 | fprintf_filtered (stream, " ("); | |
c906108c SS |
835 | type_print (exp->elts[elt].type, NULL, stream, 0); |
836 | fprintf_filtered (stream, "), value %ld (0x%lx)", | |
c5aa993b JM |
837 | (long) exp->elts[elt + 1].longconst, |
838 | (long) exp->elts[elt + 1].longconst); | |
c906108c SS |
839 | elt += 3; |
840 | break; | |
841 | case OP_DOUBLE: | |
d4f3574e SS |
842 | fprintf_filtered (stream, "Type @"); |
843 | gdb_print_host_address (exp->elts[elt].type, stream); | |
844 | fprintf_filtered (stream, " ("); | |
c906108c SS |
845 | type_print (exp->elts[elt].type, NULL, stream, 0); |
846 | fprintf_filtered (stream, "), value %g", | |
c5aa993b | 847 | (double) exp->elts[elt + 1].doubleconst); |
c906108c SS |
848 | elt += 3; |
849 | break; | |
850 | case OP_VAR_VALUE: | |
d4f3574e SS |
851 | fprintf_filtered (stream, "Block @"); |
852 | gdb_print_host_address (exp->elts[elt].block, stream); | |
853 | fprintf_filtered (stream, ", symbol @"); | |
854 | gdb_print_host_address (exp->elts[elt + 1].symbol, stream); | |
855 | fprintf_filtered (stream, " (%s)", | |
c5aa993b | 856 | SYMBOL_NAME (exp->elts[elt + 1].symbol)); |
c906108c SS |
857 | elt += 3; |
858 | break; | |
859 | case OP_LAST: | |
860 | fprintf_filtered (stream, "History element %ld", | |
c5aa993b | 861 | (long) exp->elts[elt].longconst); |
c906108c SS |
862 | elt += 2; |
863 | break; | |
864 | case OP_REGISTER: | |
865 | fprintf_filtered (stream, "Register %ld", | |
c5aa993b | 866 | (long) exp->elts[elt].longconst); |
c906108c SS |
867 | elt += 2; |
868 | break; | |
869 | case OP_INTERNALVAR: | |
d4f3574e SS |
870 | fprintf_filtered (stream, "Internal var @"); |
871 | gdb_print_host_address (exp->elts[elt].internalvar, stream); | |
872 | fprintf_filtered (stream, " (%s)", | |
c906108c SS |
873 | exp->elts[elt].internalvar->name); |
874 | elt += 2; | |
875 | break; | |
876 | case OP_FUNCALL: | |
877 | { | |
878 | int nargs; | |
879 | ||
880 | nargs = longest_to_int (exp->elts[elt].longconst); | |
881 | ||
882 | fprintf_filtered (stream, "Number of args: %d", nargs); | |
883 | elt += 2; | |
884 | ||
885 | for (i = 1; i <= nargs + 1; i++) | |
886 | elt = dump_subexp (exp, stream, elt); | |
887 | } | |
888 | break; | |
889 | case OP_ARRAY: | |
890 | { | |
891 | int lower, upper; | |
892 | int i; | |
893 | ||
894 | lower = longest_to_int (exp->elts[elt].longconst); | |
895 | upper = longest_to_int (exp->elts[elt + 1].longconst); | |
896 | ||
897 | fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); | |
898 | elt += 3; | |
899 | ||
900 | for (i = 1; i <= upper - lower + 1; i++) | |
901 | elt = dump_subexp (exp, stream, elt); | |
902 | } | |
903 | break; | |
904 | case UNOP_MEMVAL: | |
905 | case UNOP_CAST: | |
d4f3574e SS |
906 | fprintf_filtered (stream, "Type @"); |
907 | gdb_print_host_address (exp->elts[elt].type, stream); | |
908 | fprintf_filtered (stream, " ("); | |
c906108c SS |
909 | type_print (exp->elts[elt].type, NULL, stream, 0); |
910 | fprintf_filtered (stream, ")"); | |
911 | elt = dump_subexp (exp, stream, elt + 2); | |
912 | break; | |
913 | case OP_TYPE: | |
d4f3574e SS |
914 | fprintf_filtered (stream, "Type @"); |
915 | gdb_print_host_address (exp->elts[elt].type, stream); | |
916 | fprintf_filtered (stream, " ("); | |
c906108c SS |
917 | type_print (exp->elts[elt].type, NULL, stream, 0); |
918 | fprintf_filtered (stream, ")"); | |
919 | elt += 2; | |
920 | break; | |
921 | case STRUCTOP_STRUCT: | |
922 | case STRUCTOP_PTR: | |
923 | { | |
924 | char *elem_name; | |
925 | int len; | |
926 | ||
927 | len = longest_to_int (exp->elts[elt].longconst); | |
928 | elem_name = &exp->elts[elt + 1].string; | |
929 | ||
930 | fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); | |
931 | elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); | |
932 | } | |
933 | break; | |
934 | case OP_SCOPE: | |
935 | { | |
936 | char *elem_name; | |
937 | int len; | |
938 | ||
d4f3574e SS |
939 | fprintf_filtered (stream, "Type @"); |
940 | gdb_print_host_address (exp->elts[elt].type, stream); | |
941 | fprintf_filtered (stream, " ("); | |
c906108c SS |
942 | type_print (exp->elts[elt].type, NULL, stream, 0); |
943 | fprintf_filtered (stream, ") "); | |
944 | ||
945 | len = longest_to_int (exp->elts[elt + 1].longconst); | |
946 | elem_name = &exp->elts[elt + 2].string; | |
947 | ||
948 | fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); | |
949 | elt += 4 + BYTES_TO_EXP_ELEM (len + 1); | |
950 | } | |
951 | break; | |
952 | default: | |
953 | case OP_NULL: | |
954 | case STRUCTOP_MEMBER: | |
955 | case STRUCTOP_MPTR: | |
956 | case MULTI_SUBSCRIPT: | |
957 | case OP_F77_UNDETERMINED_ARGLIST: | |
958 | case OP_COMPLEX: | |
959 | case OP_STRING: | |
960 | case OP_BITSTRING: | |
961 | case OP_BOOL: | |
962 | case OP_M2_STRING: | |
963 | case OP_THIS: | |
964 | case OP_LABELED: | |
965 | case OP_NAME: | |
966 | case OP_EXPRSTRING: | |
967 | fprintf_filtered (stream, "Unknown format"); | |
968 | } | |
969 | ||
970 | indent -= 2; | |
971 | ||
972 | return elt; | |
973 | } | |
974 | ||
975 | void | |
976 | dump_postfix_expression (exp, stream, note) | |
977 | struct expression *exp; | |
d9fcf2fb | 978 | struct ui_file *stream; |
c906108c SS |
979 | char *note; |
980 | { | |
981 | int elt; | |
982 | ||
983 | fprintf_filtered (stream, "Dump of expression @ "); | |
d4f3574e | 984 | gdb_print_host_address (exp, stream); |
c906108c SS |
985 | fprintf_filtered (stream, ", %s:\nExpression: `", note); |
986 | if (exp->elts[0].opcode != OP_TYPE) | |
987 | print_expression (exp, stream); | |
988 | else | |
989 | fputs_filtered ("Type printing not yet supported....", stream); | |
9d271fd8 | 990 | fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n", |
c5aa993b | 991 | exp->language_defn->la_name, exp->nelts, |
9d271fd8 | 992 | (long) sizeof (union exp_element)); |
c906108c SS |
993 | fputs_filtered ("\n", stream); |
994 | ||
c5aa993b | 995 | for (elt = 0; elt < exp->nelts;) |
c906108c SS |
996 | elt = dump_subexp (exp, stream, elt); |
997 | fputs_filtered ("\n", stream); | |
998 | } |