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