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