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