]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Print in infix form a struct expression. |
28de880c | 2 | Copyright (C) 1986, 1989, 1991 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
10147c02 | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
10147c02 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
10147c02 | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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 | |
10147c02 | 17 | along with this program; if not, write to the Free Software |
cd10c7e3 | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 19 | |
bd5635a1 RP |
20 | #include "defs.h" |
21 | #include "symtab.h" | |
28de880c | 22 | #include "gdbtypes.h" |
bd5635a1 RP |
23 | #include "expression.h" |
24 | #include "value.h" | |
28de880c JG |
25 | #include "language.h" |
26 | #include "parser-defs.h" | |
bd5635a1 | 27 | |
28de880c JG |
28 | /* Prototypes for local functions */ |
29 | ||
30 | static void | |
dcda44a0 | 31 | print_subexp PARAMS ((struct expression *, int *, GDB_FILE *, enum precedence)); |
28de880c | 32 | |
bd5635a1 RP |
33 | void |
34 | print_expression (exp, stream) | |
35 | struct expression *exp; | |
dcda44a0 | 36 | GDB_FILE *stream; |
bd5635a1 RP |
37 | { |
38 | int pc = 0; | |
39 | print_subexp (exp, &pc, stream, PREC_NULL); | |
40 | } | |
41 | ||
42 | /* Print the subexpression of EXP that starts in position POS, on STREAM. | |
43 | PREC is the precedence of the surrounding operator; | |
44 | if the precedence of the main operator of this subexpression is less, | |
45 | parentheses are needed here. */ | |
46 | ||
47 | static void | |
48 | print_subexp (exp, pos, stream, prec) | |
49 | register struct expression *exp; | |
50 | register int *pos; | |
dcda44a0 | 51 | GDB_FILE *stream; |
bd5635a1 RP |
52 | enum precedence prec; |
53 | { | |
54 | register unsigned tem; | |
28de880c | 55 | register const struct op_print *op_print_tab; |
bd5635a1 RP |
56 | register int pc; |
57 | unsigned nargs; | |
58 | register char *op_str; | |
59 | int assign_modify = 0; | |
60 | enum exp_opcode opcode; | |
dcda44a0 | 61 | enum precedence myprec = PREC_NULL; |
bd5635a1 | 62 | /* Set to 1 for a right-associative operator. */ |
dcda44a0 PB |
63 | int assoc = 0; |
64 | value_ptr val; | |
65 | char *tempstr = NULL; | |
bd5635a1 | 66 | |
28de880c | 67 | op_print_tab = exp->language_defn->la_op_print_tab; |
bd5635a1 RP |
68 | pc = (*pos)++; |
69 | opcode = exp->elts[pc].opcode; | |
70 | switch (opcode) | |
71 | { | |
28de880c JG |
72 | /* Common ops */ |
73 | ||
bd5635a1 | 74 | case OP_SCOPE: |
5d074aa9 FF |
75 | myprec = PREC_PREFIX; |
76 | assoc = 0; | |
f661c4ca PS |
77 | fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream); |
78 | fputs_filtered ("::", stream); | |
a8a69e63 | 79 | nargs = longest_to_int (exp->elts[pc + 2].longconst); |
f661c4ca | 80 | (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1); |
a8a69e63 | 81 | fputs_filtered (&exp->elts[pc + 3].string, stream); |
bd5635a1 RP |
82 | return; |
83 | ||
84 | case OP_LONG: | |
85 | (*pos) += 3; | |
28de880c | 86 | value_print (value_from_longest (exp->elts[pc + 1].type, |
a8a69e63 | 87 | exp->elts[pc + 2].longconst), |
bd5635a1 RP |
88 | stream, 0, Val_no_prettyprint); |
89 | return; | |
90 | ||
91 | case OP_DOUBLE: | |
92 | (*pos) += 3; | |
93 | value_print (value_from_double (exp->elts[pc + 1].type, | |
94 | exp->elts[pc + 2].doubleconst), | |
95 | stream, 0, Val_no_prettyprint); | |
96 | return; | |
97 | ||
98 | case OP_VAR_VALUE: | |
dcda44a0 PB |
99 | { |
100 | struct block *b; | |
101 | (*pos) += 3; | |
102 | b = exp->elts[pc + 1].block; | |
103 | if (b != NULL | |
104 | && BLOCK_FUNCTION (b) != NULL | |
105 | && SYMBOL_SOURCE_NAME (BLOCK_FUNCTION (b)) != NULL) | |
106 | { | |
107 | fputs_filtered (SYMBOL_SOURCE_NAME (BLOCK_FUNCTION (b)), stream); | |
108 | fputs_filtered ("::", stream); | |
109 | } | |
110 | fputs_filtered (SYMBOL_SOURCE_NAME (exp->elts[pc + 2].symbol), stream); | |
111 | } | |
bd5635a1 RP |
112 | return; |
113 | ||
114 | case OP_LAST: | |
115 | (*pos) += 2; | |
10147c02 JG |
116 | fprintf_filtered (stream, "$%d", |
117 | longest_to_int (exp->elts[pc + 1].longconst)); | |
bd5635a1 RP |
118 | return; |
119 | ||
120 | case OP_REGISTER: | |
121 | (*pos) += 2; | |
10147c02 | 122 | fprintf_filtered (stream, "$%s", |
35fcebce | 123 | reg_names[longest_to_int (exp->elts[pc + 1].longconst)]); |
bd5635a1 RP |
124 | return; |
125 | ||
5d074aa9 FF |
126 | case OP_BOOL: |
127 | (*pos) += 2; | |
128 | fprintf_filtered (stream, "%s", | |
129 | longest_to_int (exp->elts[pc + 1].longconst) | |
130 | ? "TRUE" : "FALSE"); | |
131 | return; | |
132 | ||
bd5635a1 RP |
133 | case OP_INTERNALVAR: |
134 | (*pos) += 2; | |
10147c02 | 135 | fprintf_filtered (stream, "$%s", |
bd5635a1 RP |
136 | internalvar_name (exp->elts[pc + 1].internalvar)); |
137 | return; | |
138 | ||
139 | case OP_FUNCALL: | |
140 | (*pos) += 2; | |
10147c02 | 141 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
bd5635a1 | 142 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
10147c02 | 143 | fputs_filtered (" (", stream); |
bd5635a1 RP |
144 | for (tem = 0; tem < nargs; tem++) |
145 | { | |
146 | if (tem != 0) | |
10147c02 | 147 | fputs_filtered (", ", stream); |
bd5635a1 RP |
148 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
149 | } | |
10147c02 | 150 | fputs_filtered (")", stream); |
bd5635a1 RP |
151 | return; |
152 | ||
cd10c7e3 SG |
153 | case OP_NAME: |
154 | case OP_EXPRSTRING: | |
155 | nargs = longest_to_int (exp -> elts[pc + 1].longconst); | |
156 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); | |
157 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
158 | return; | |
159 | ||
bd5635a1 | 160 | case OP_STRING: |
a8a69e63 | 161 | nargs = longest_to_int (exp -> elts[pc + 1].longconst); |
c4413e2c | 162 | (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); |
a8a69e63 | 163 | /* LA_PRINT_STRING will print using the current repeat count threshold. |
5d074aa9 | 164 | If necessary, we can temporarily set it to zero, or pass it as an |
a8a69e63 FF |
165 | additional parameter to LA_PRINT_STRING. -fnf */ |
166 | LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 0); | |
bd5635a1 RP |
167 | return; |
168 | ||
c4413e2c | 169 | case OP_BITSTRING: |
cd10c7e3 SG |
170 | nargs = longest_to_int (exp -> elts[pc + 1].longconst); |
171 | (*pos) | |
172 | += 3 + BYTES_TO_EXP_ELEM ((nargs + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT); | |
173 | fprintf (stream, "B'<unimplemented>'"); | |
174 | return; | |
c4413e2c FF |
175 | |
176 | case OP_ARRAY: | |
f661c4ca PS |
177 | (*pos) += 3; |
178 | nargs = longest_to_int (exp->elts[pc + 2].longconst); | |
179 | nargs -= longest_to_int (exp->elts[pc + 1].longconst); | |
180 | nargs++; | |
181 | tem = 0; | |
182 | if (exp->elts[pc + 4].opcode == OP_LONG | |
183 | && exp->elts[pc + 5].type == builtin_type_char | |
184 | && exp->language_defn->la_language == language_c) | |
185 | { | |
186 | /* Attempt to print C character arrays using string syntax. | |
187 | Walk through the args, picking up one character from each | |
188 | of the OP_LONG expression elements. If any array element | |
189 | does not match our expection of what we should find for | |
190 | a simple string, revert back to array printing. Note that | |
191 | the last expression element is an explicit null terminator | |
192 | byte, which doesn't get printed. */ | |
193 | tempstr = alloca (nargs); | |
194 | pc += 4; | |
195 | while (tem < nargs) | |
196 | { | |
197 | if (exp->elts[pc].opcode != OP_LONG | |
198 | || exp->elts[pc + 1].type != builtin_type_char) | |
199 | { | |
200 | /* Not a simple array of char, use regular array printing. */ | |
201 | tem = 0; | |
202 | break; | |
203 | } | |
204 | else | |
205 | { | |
206 | tempstr[tem++] = | |
207 | longest_to_int (exp->elts[pc + 2].longconst); | |
208 | pc += 4; | |
209 | } | |
210 | } | |
211 | } | |
212 | if (tem > 0) | |
213 | { | |
214 | LA_PRINT_STRING (stream, tempstr, nargs - 1, 0); | |
215 | (*pos) = pc; | |
216 | } | |
217 | else | |
218 | { | |
dcda44a0 PB |
219 | int is_chill = exp->language_defn->la_language == language_chill; |
220 | fputs_filtered (is_chill ? " [" : " {", stream); | |
f661c4ca PS |
221 | for (tem = 0; tem < nargs; tem++) |
222 | { | |
223 | if (tem != 0) | |
224 | { | |
225 | fputs_filtered (", ", stream); | |
226 | } | |
227 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
228 | } | |
dcda44a0 | 229 | fputs_filtered (is_chill ? "]" : "}", stream); |
f661c4ca PS |
230 | } |
231 | return; | |
c4413e2c | 232 | |
dcda44a0 PB |
233 | case OP_LABELED: |
234 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
235 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
236 | ||
237 | if (exp->language_defn->la_language == language_chill) | |
238 | { | |
239 | fputs_filtered (".", stream); | |
240 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
241 | fputs_filtered (exp->elts[*pos].opcode == OP_LABELED ? ", " | |
242 | : ": ", | |
243 | stream); | |
244 | } | |
245 | else | |
246 | { | |
247 | /* Gcc support both these syntaxes. Unsure which is preferred. */ | |
248 | #if 1 | |
249 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
250 | fputs_filtered (": ", stream); | |
251 | #else | |
252 | fputs_filtered (".", stream); | |
253 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
254 | fputs_filtered ("=", stream); | |
255 | #endif | |
256 | } | |
257 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
258 | return; | |
259 | ||
bd5635a1 RP |
260 | case TERNOP_COND: |
261 | if ((int) prec > (int) PREC_COMMA) | |
10147c02 | 262 | fputs_filtered ("(", stream); |
bd5635a1 RP |
263 | /* Print the subexpressions, forcing parentheses |
264 | around any binary operations within them. | |
265 | This is more parentheses than are strictly necessary, | |
266 | but it looks clearer. */ | |
267 | print_subexp (exp, pos, stream, PREC_HYPER); | |
10147c02 | 268 | fputs_filtered (" ? ", stream); |
bd5635a1 | 269 | print_subexp (exp, pos, stream, PREC_HYPER); |
10147c02 | 270 | fputs_filtered (" : ", stream); |
bd5635a1 RP |
271 | print_subexp (exp, pos, stream, PREC_HYPER); |
272 | if ((int) prec > (int) PREC_COMMA) | |
10147c02 | 273 | fputs_filtered (")", stream); |
bd5635a1 RP |
274 | return; |
275 | ||
cd10c7e3 SG |
276 | case TERNOP_SLICE: |
277 | case TERNOP_SLICE_COUNT: | |
278 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
279 | fputs_filtered ("(", stream); | |
280 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
281 | fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream); | |
282 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
283 | fputs_filtered (")", stream); | |
284 | return; | |
285 | ||
bd5635a1 | 286 | case STRUCTOP_STRUCT: |
a8a69e63 | 287 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
c4413e2c | 288 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 | 289 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
10147c02 | 290 | fputs_filtered (".", stream); |
a8a69e63 | 291 | fputs_filtered (&exp->elts[pc + 2].string, stream); |
bd5635a1 RP |
292 | return; |
293 | ||
28de880c | 294 | /* Will not occur for Modula-2 */ |
bd5635a1 | 295 | case STRUCTOP_PTR: |
a8a69e63 | 296 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
c4413e2c | 297 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 | 298 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
10147c02 | 299 | fputs_filtered ("->", stream); |
a8a69e63 | 300 | fputs_filtered (&exp->elts[pc + 2].string, stream); |
bd5635a1 RP |
301 | return; |
302 | ||
cd10c7e3 SG |
303 | /* start-sanitize-gm */ |
304 | #ifdef GENERAL_MAGIC_HACKS | |
305 | case STRUCTOP_FIELD: | |
306 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
307 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
308 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
309 | fputs_filtered ("@", stream); | |
310 | fputs_filtered (&exp->elts[pc + 2].string, stream); | |
311 | return; | |
312 | ||
313 | #endif /* GENERAL_MAGIC_HACKS */ | |
314 | /* end-sanitize-gm */ | |
315 | ||
bd5635a1 RP |
316 | case BINOP_SUBSCRIPT: |
317 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10147c02 | 318 | fputs_filtered ("[", stream); |
bd5635a1 | 319 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
10147c02 | 320 | fputs_filtered ("]", stream); |
bd5635a1 RP |
321 | return; |
322 | ||
323 | case UNOP_POSTINCREMENT: | |
324 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10147c02 | 325 | fputs_filtered ("++", stream); |
bd5635a1 RP |
326 | return; |
327 | ||
328 | case UNOP_POSTDECREMENT: | |
329 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10147c02 | 330 | fputs_filtered ("--", stream); |
bd5635a1 RP |
331 | return; |
332 | ||
333 | case UNOP_CAST: | |
334 | (*pos) += 2; | |
335 | if ((int) prec > (int) PREC_PREFIX) | |
10147c02 JG |
336 | fputs_filtered ("(", stream); |
337 | fputs_filtered ("(", stream); | |
bd5635a1 | 338 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
10147c02 | 339 | fputs_filtered (") ", stream); |
bd5635a1 RP |
340 | print_subexp (exp, pos, stream, PREC_PREFIX); |
341 | if ((int) prec > (int) PREC_PREFIX) | |
10147c02 | 342 | fputs_filtered (")", stream); |
bd5635a1 RP |
343 | return; |
344 | ||
345 | case UNOP_MEMVAL: | |
346 | (*pos) += 2; | |
347 | if ((int) prec > (int) PREC_PREFIX) | |
10147c02 | 348 | fputs_filtered ("(", stream); |
28de880c JG |
349 | if (exp->elts[pc + 1].type->code == TYPE_CODE_FUNC && |
350 | exp->elts[pc + 3].opcode == OP_LONG) { | |
351 | /* We have a minimal symbol fn, probably. It's encoded | |
352 | as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address). | |
353 | Swallow the OP_LONG (including both its opcodes); ignore | |
354 | its type; print the value in the type of the MEMVAL. */ | |
355 | (*pos) += 4; | |
356 | val = value_at_lazy (exp->elts[pc + 1].type, | |
357 | (CORE_ADDR) exp->elts[pc + 5].longconst); | |
358 | value_print (val, stream, 0, Val_no_prettyprint); | |
359 | } else { | |
360 | fputs_filtered ("{", stream); | |
361 | type_print (exp->elts[pc + 1].type, "", stream, 0); | |
362 | fputs_filtered ("} ", stream); | |
363 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
364 | } | |
bd5635a1 | 365 | if ((int) prec > (int) PREC_PREFIX) |
10147c02 | 366 | fputs_filtered (")", stream); |
bd5635a1 RP |
367 | return; |
368 | ||
369 | case BINOP_ASSIGN_MODIFY: | |
370 | opcode = exp->elts[pc + 1].opcode; | |
371 | (*pos) += 2; | |
372 | myprec = PREC_ASSIGN; | |
373 | assoc = 1; | |
374 | assign_modify = 1; | |
28de880c JG |
375 | op_str = "???"; |
376 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) | |
bd5635a1 RP |
377 | if (op_print_tab[tem].opcode == opcode) |
378 | { | |
379 | op_str = op_print_tab[tem].string; | |
380 | break; | |
381 | } | |
f661c4ca PS |
382 | if (op_print_tab[tem].opcode != opcode) |
383 | /* Not found; don't try to keep going because we don't know how | |
384 | to interpret further elements. */ | |
385 | error ("Invalid expression"); | |
81919cc8 | 386 | break; |
bd5635a1 | 387 | |
28de880c JG |
388 | /* C++ ops */ |
389 | ||
bd5635a1 RP |
390 | case OP_THIS: |
391 | ++(*pos); | |
10147c02 | 392 | fputs_filtered ("this", stream); |
bd5635a1 RP |
393 | return; |
394 | ||
28de880c JG |
395 | /* Modula-2 ops */ |
396 | ||
54bbbfb4 | 397 | case MULTI_SUBSCRIPT: |
28de880c JG |
398 | (*pos) += 2; |
399 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
400 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
dcda44a0 | 401 | fprintf_unfiltered (stream, " ["); |
28de880c JG |
402 | for (tem = 0; tem < nargs; tem++) |
403 | { | |
404 | if (tem != 0) | |
dcda44a0 | 405 | fprintf_unfiltered (stream, ", "); |
28de880c JG |
406 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
407 | } | |
dcda44a0 | 408 | fprintf_unfiltered (stream, "]"); |
28de880c JG |
409 | return; |
410 | ||
411 | case BINOP_VAL: | |
412 | (*pos)+=2; | |
dcda44a0 | 413 | fprintf_unfiltered(stream,"VAL("); |
28de880c | 414 | type_print(exp->elts[pc+1].type,"",stream,0); |
dcda44a0 | 415 | fprintf_unfiltered(stream,","); |
28de880c | 416 | print_subexp(exp,pos,stream,PREC_PREFIX); |
dcda44a0 | 417 | fprintf_unfiltered(stream,")"); |
28de880c | 418 | return; |
28de880c JG |
419 | |
420 | case BINOP_INCL: | |
421 | case BINOP_EXCL: | |
422 | error("print_subexp: Not implemented."); | |
423 | ||
424 | /* Default ops */ | |
425 | ||
bd5635a1 | 426 | default: |
28de880c JG |
427 | op_str = "???"; |
428 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) | |
bd5635a1 RP |
429 | if (op_print_tab[tem].opcode == opcode) |
430 | { | |
431 | op_str = op_print_tab[tem].string; | |
432 | myprec = op_print_tab[tem].precedence; | |
433 | assoc = op_print_tab[tem].right_assoc; | |
434 | break; | |
435 | } | |
f661c4ca PS |
436 | if (op_print_tab[tem].opcode != opcode) |
437 | /* Not found; don't try to keep going because we don't know how | |
438 | to interpret further elements. For example, this happens | |
439 | if opcode is OP_TYPE. */ | |
440 | error ("Invalid expression"); | |
28de880c | 441 | } |
bd5635a1 | 442 | |
cd10c7e3 | 443 | /* Note that PREC_BUILTIN will always emit parentheses. */ |
bd5635a1 | 444 | if ((int) myprec < (int) prec) |
10147c02 | 445 | fputs_filtered ("(", stream); |
bd5635a1 RP |
446 | if ((int) opcode > (int) BINOP_END) |
447 | { | |
dcda44a0 PB |
448 | if (assoc) |
449 | { | |
450 | /* Unary postfix operator. */ | |
451 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
452 | fputs_filtered (op_str, stream); | |
453 | } | |
454 | else | |
455 | { | |
456 | /* Unary prefix operator. */ | |
457 | fputs_filtered (op_str, stream); | |
cd10c7e3 SG |
458 | if (myprec == PREC_BUILTIN_FUNCTION) |
459 | fputs_filtered ("(", stream); | |
dcda44a0 | 460 | print_subexp (exp, pos, stream, PREC_PREFIX); |
cd10c7e3 SG |
461 | if (myprec == PREC_BUILTIN_FUNCTION) |
462 | fputs_filtered (")", stream); | |
dcda44a0 | 463 | } |
bd5635a1 RP |
464 | } |
465 | else | |
466 | { | |
467 | /* Binary operator. */ | |
468 | /* Print left operand. | |
469 | If operator is right-associative, | |
470 | increment precedence for this operand. */ | |
10147c02 JG |
471 | print_subexp (exp, pos, stream, |
472 | (enum precedence) ((int) myprec + assoc)); | |
bd5635a1 RP |
473 | /* Print the operator itself. */ |
474 | if (assign_modify) | |
10147c02 | 475 | fprintf_filtered (stream, " %s= ", op_str); |
bd5635a1 | 476 | else if (op_str[0] == ',') |
10147c02 | 477 | fprintf_filtered (stream, "%s ", op_str); |
bd5635a1 | 478 | else |
10147c02 | 479 | fprintf_filtered (stream, " %s ", op_str); |
bd5635a1 RP |
480 | /* Print right operand. |
481 | If operator is left-associative, | |
482 | increment precedence for this operand. */ | |
10147c02 JG |
483 | print_subexp (exp, pos, stream, |
484 | (enum precedence) ((int) myprec + !assoc)); | |
bd5635a1 | 485 | } |
28de880c | 486 | |
bd5635a1 | 487 | if ((int) myprec < (int) prec) |
10147c02 | 488 | fputs_filtered (")", stream); |
bd5635a1 | 489 | } |
28de880c | 490 | |
28de880c JG |
491 | /* Return the operator corresponding to opcode OP as |
492 | a string. NULL indicates that the opcode was not found in the | |
493 | current language table. */ | |
494 | char * | |
495 | op_string(op) | |
496 | enum exp_opcode op; | |
497 | { | |
498 | int tem; | |
499 | register const struct op_print *op_print_tab; | |
500 | ||
501 | op_print_tab = current_language->la_op_print_tab; | |
502 | for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) | |
503 | if (op_print_tab[tem].opcode == op) | |
504 | return op_print_tab[tem].string; | |
505 | return NULL; | |
506 | } | |
54bbbfb4 FF |
507 | |
508 | #ifdef DEBUG_EXPRESSIONS | |
509 | ||
510 | /* Support for dumping the raw data from expressions in a human readable | |
511 | form. */ | |
512 | ||
513 | void | |
514 | dump_expression (exp, stream, note) | |
515 | struct expression *exp; | |
dcda44a0 | 516 | GDB_FILE *stream; |
54bbbfb4 FF |
517 | char *note; |
518 | { | |
519 | int elt; | |
520 | char *opcode_name; | |
521 | char *eltscan; | |
522 | int eltsize; | |
523 | ||
dcda44a0 PB |
524 | fprintf_filtered (stream, "Dump of expression @ "); |
525 | gdb_print_address (exp, stream); | |
526 | fprintf_filtered (stream, ", %s:\n", note); | |
54bbbfb4 FF |
527 | fprintf_filtered (stream, "\tLanguage %s, %d elements, %d bytes each.\n", |
528 | exp->language_defn->la_name, exp -> nelts, | |
529 | sizeof (union exp_element)); | |
530 | fprintf_filtered (stream, "\t%5s %20s %16s %s\n", "Index", "Opcode", | |
531 | "Hex Value", "String Value"); | |
532 | for (elt = 0; elt < exp -> nelts; elt++) | |
533 | { | |
534 | fprintf_filtered (stream, "\t%5d ", elt); | |
535 | switch (exp -> elts[elt].opcode) | |
536 | { | |
537 | default: opcode_name = "<unknown>"; break; | |
538 | case OP_NULL: opcode_name = "OP_NULL"; break; | |
539 | case BINOP_ADD: opcode_name = "BINOP_ADD"; break; | |
540 | case BINOP_SUB: opcode_name = "BINOP_SUB"; break; | |
541 | case BINOP_MUL: opcode_name = "BINOP_MUL"; break; | |
542 | case BINOP_DIV: opcode_name = "BINOP_DIV"; break; | |
543 | case BINOP_REM: opcode_name = "BINOP_REM"; break; | |
76a0ffb4 | 544 | case BINOP_MOD: opcode_name = "BINOP_MOD"; break; |
54bbbfb4 FF |
545 | case BINOP_LSH: opcode_name = "BINOP_LSH"; break; |
546 | case BINOP_RSH: opcode_name = "BINOP_RSH"; break; | |
547 | case BINOP_LOGICAL_AND: opcode_name = "BINOP_LOGICAL_AND"; break; | |
548 | case BINOP_LOGICAL_OR: opcode_name = "BINOP_LOGICAL_OR"; break; | |
549 | case BINOP_BITWISE_AND: opcode_name = "BINOP_BITWISE_AND"; break; | |
550 | case BINOP_BITWISE_IOR: opcode_name = "BINOP_BITWISE_IOR"; break; | |
551 | case BINOP_BITWISE_XOR: opcode_name = "BINOP_BITWISE_XOR"; break; | |
552 | case BINOP_EQUAL: opcode_name = "BINOP_EQUAL"; break; | |
553 | case BINOP_NOTEQUAL: opcode_name = "BINOP_NOTEQUAL"; break; | |
554 | case BINOP_LESS: opcode_name = "BINOP_LESS"; break; | |
555 | case BINOP_GTR: opcode_name = "BINOP_GTR"; break; | |
556 | case BINOP_LEQ: opcode_name = "BINOP_LEQ"; break; | |
557 | case BINOP_GEQ: opcode_name = "BINOP_GEQ"; break; | |
558 | case BINOP_REPEAT: opcode_name = "BINOP_REPEAT"; break; | |
559 | case BINOP_ASSIGN: opcode_name = "BINOP_ASSIGN"; break; | |
560 | case BINOP_COMMA: opcode_name = "BINOP_COMMA"; break; | |
561 | case BINOP_SUBSCRIPT: opcode_name = "BINOP_SUBSCRIPT"; break; | |
562 | case MULTI_SUBSCRIPT: opcode_name = "MULTI_SUBSCRIPT"; break; | |
563 | case BINOP_EXP: opcode_name = "BINOP_EXP"; break; | |
564 | case BINOP_MIN: opcode_name = "BINOP_MIN"; break; | |
565 | case BINOP_MAX: opcode_name = "BINOP_MAX"; break; | |
566 | case BINOP_SCOPE: opcode_name = "BINOP_SCOPE"; break; | |
567 | case STRUCTOP_MEMBER: opcode_name = "STRUCTOP_MEMBER"; break; | |
568 | case STRUCTOP_MPTR: opcode_name = "STRUCTOP_MPTR"; break; | |
569 | case BINOP_INTDIV: opcode_name = "BINOP_INTDIV"; break; | |
570 | case BINOP_ASSIGN_MODIFY: opcode_name = "BINOP_ASSIGN_MODIFY"; break; | |
571 | case BINOP_VAL: opcode_name = "BINOP_VAL"; break; | |
572 | case BINOP_INCL: opcode_name = "BINOP_INCL"; break; | |
573 | case BINOP_EXCL: opcode_name = "BINOP_EXCL"; break; | |
f661c4ca | 574 | case BINOP_CONCAT: opcode_name = "BINOP_CONCAT"; break; |
54bbbfb4 FF |
575 | case BINOP_END: opcode_name = "BINOP_END"; break; |
576 | case TERNOP_COND: opcode_name = "TERNOP_COND"; break; | |
cd10c7e3 SG |
577 | case TERNOP_SLICE: opcode_name = "TERNOP_SLICE"; break; |
578 | case TERNOP_SLICE_COUNT: opcode_name = "TERNOP_SLICE_COUNT"; break; | |
54bbbfb4 FF |
579 | case OP_LONG: opcode_name = "OP_LONG"; break; |
580 | case OP_DOUBLE: opcode_name = "OP_DOUBLE"; break; | |
581 | case OP_VAR_VALUE: opcode_name = "OP_VAR_VALUE"; break; | |
582 | case OP_LAST: opcode_name = "OP_LAST"; break; | |
583 | case OP_REGISTER: opcode_name = "OP_REGISTER"; break; | |
584 | case OP_INTERNALVAR: opcode_name = "OP_INTERNALVAR"; break; | |
585 | case OP_FUNCALL: opcode_name = "OP_FUNCALL"; break; | |
586 | case OP_STRING: opcode_name = "OP_STRING"; break; | |
c4413e2c FF |
587 | case OP_BITSTRING: opcode_name = "OP_BITSTRING"; break; |
588 | case OP_ARRAY: opcode_name = "OP_ARRAY"; break; | |
54bbbfb4 FF |
589 | case UNOP_CAST: opcode_name = "UNOP_CAST"; break; |
590 | case UNOP_MEMVAL: opcode_name = "UNOP_MEMVAL"; break; | |
591 | case UNOP_NEG: opcode_name = "UNOP_NEG"; break; | |
592 | case UNOP_LOGICAL_NOT: opcode_name = "UNOP_LOGICAL_NOT"; break; | |
593 | case UNOP_COMPLEMENT: opcode_name = "UNOP_COMPLEMENT"; break; | |
594 | case UNOP_IND: opcode_name = "UNOP_IND"; break; | |
595 | case UNOP_ADDR: opcode_name = "UNOP_ADDR"; break; | |
596 | case UNOP_PREINCREMENT: opcode_name = "UNOP_PREINCREMENT"; break; | |
597 | case UNOP_POSTINCREMENT: opcode_name = "UNOP_POSTINCREMENT"; break; | |
598 | case UNOP_PREDECREMENT: opcode_name = "UNOP_PREDECREMENT"; break; | |
599 | case UNOP_POSTDECREMENT: opcode_name = "UNOP_POSTDECREMENT"; break; | |
600 | case UNOP_SIZEOF: opcode_name = "UNOP_SIZEOF"; break; | |
cd10c7e3 SG |
601 | case UNOP_LOWER: opcode_name = "UNOP_LOWER"; break; |
602 | case UNOP_UPPER: opcode_name = "UNOP_UPPER"; break; | |
603 | case UNOP_LENGTH: opcode_name = "UNOP_LENGTH"; break; | |
54bbbfb4 FF |
604 | case UNOP_PLUS: opcode_name = "UNOP_PLUS"; break; |
605 | case UNOP_CAP: opcode_name = "UNOP_CAP"; break; | |
606 | case UNOP_CHR: opcode_name = "UNOP_CHR"; break; | |
607 | case UNOP_ORD: opcode_name = "UNOP_ORD"; break; | |
608 | case UNOP_ABS: opcode_name = "UNOP_ABS"; break; | |
609 | case UNOP_FLOAT: opcode_name = "UNOP_FLOAT"; break; | |
610 | case UNOP_HIGH: opcode_name = "UNOP_HIGH"; break; | |
611 | case UNOP_MAX: opcode_name = "UNOP_MAX"; break; | |
612 | case UNOP_MIN: opcode_name = "UNOP_MIN"; break; | |
613 | case UNOP_ODD: opcode_name = "UNOP_ODD"; break; | |
614 | case UNOP_TRUNC: opcode_name = "UNOP_TRUNC"; break; | |
615 | case OP_BOOL: opcode_name = "OP_BOOL"; break; | |
616 | case OP_M2_STRING: opcode_name = "OP_M2_STRING"; break; | |
617 | case STRUCTOP_STRUCT: opcode_name = "STRUCTOP_STRUCT"; break; | |
618 | case STRUCTOP_PTR: opcode_name = "STRUCTOP_PTR"; break; | |
cd10c7e3 SG |
619 | /* start-sanitize-gm */ |
620 | #ifdef GENERAL_MAGIC_HACKS | |
621 | + case STRUCTOP_FIELD: opcode_name = "STRUCTOP_FIELD"; break; | |
622 | #endif /* GENERAL_MAGIC_HACKS */ | |
623 | /* end-sanitize-gm */ | |
54bbbfb4 FF |
624 | case OP_THIS: opcode_name = "OP_THIS"; break; |
625 | case OP_SCOPE: opcode_name = "OP_SCOPE"; break; | |
626 | case OP_TYPE: opcode_name = "OP_TYPE"; break; | |
dcda44a0 | 627 | case OP_LABELED: opcode_name = "OP_LABELED"; break; |
54bbbfb4 FF |
628 | } |
629 | fprintf_filtered (stream, "%20s ", opcode_name); | |
630 | fprintf_filtered (stream, | |
dcda44a0 | 631 | #if defined (PRINTF_HAS_LONG_LONG) |
54bbbfb4 FF |
632 | "%ll16x ", |
633 | #else | |
634 | "%l16x ", | |
635 | #endif | |
636 | exp -> elts[elt].longconst); | |
637 | ||
638 | for (eltscan = (char *) &exp->elts[elt], | |
639 | eltsize = sizeof (union exp_element) ; | |
640 | eltsize-- > 0; | |
641 | eltscan++) | |
642 | { | |
643 | fprintf_filtered (stream, "%c", | |
644 | isprint (*eltscan) ? (*eltscan & 0xFF) : '.'); | |
645 | } | |
646 | fprintf_filtered (stream, "\n"); | |
647 | } | |
648 | } | |
649 | ||
650 | #endif /* DEBUG_EXPRESSIONS */ |