2005-02-10 Andrew Cagney <cagney@gnu.org>
[platform/upstream/binutils.git] / gdb / expprint.c
1 /* Print in infix form a struct expression.
2
3    Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4    1998, 1999, 2000, 2003 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., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, 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
35 #ifdef HAVE_CTYPE_H
36 #include <ctype.h>
37 #endif
38
39 void
40 print_expression (struct expression *exp, struct ui_file *stream)
41 {
42   int pc = 0;
43   print_subexp (exp, &pc, stream, PREC_NULL);
44 }
45
46 /* Print the subexpression of EXP that starts in position POS, on STREAM.
47    PREC is the precedence of the surrounding operator;
48    if the precedence of the main operator of this subexpression is less,
49    parentheses are needed here.  */
50
51 void
52 print_subexp (struct expression *exp, int *pos,
53               struct ui_file *stream, enum precedence prec)
54 {
55   exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec);
56 }
57
58 /* Standard implementation of print_subexp for use in language_defn
59    vectors.  */
60 void
61 print_subexp_standard (struct expression *exp, int *pos,
62                        struct ui_file *stream, enum precedence prec)
63 {
64   unsigned tem;
65   const struct op_print *op_print_tab;
66   int pc;
67   unsigned nargs;
68   char *op_str;
69   int assign_modify = 0;
70   enum exp_opcode opcode;
71   enum precedence myprec = PREC_NULL;
72   /* Set to 1 for a right-associative operator.  */
73   int assoc = 0;
74   struct value *val;
75   char *tempstr = NULL;
76
77   op_print_tab = exp->language_defn->la_op_print_tab;
78   pc = (*pos)++;
79   opcode = exp->elts[pc].opcode;
80   switch (opcode)
81     {
82       /* Common ops */
83
84     case OP_SCOPE:
85       myprec = PREC_PREFIX;
86       assoc = 0;
87       fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream);
88       fputs_filtered ("::", stream);
89       nargs = longest_to_int (exp->elts[pc + 2].longconst);
90       (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1);
91       fputs_filtered (&exp->elts[pc + 3].string, stream);
92       return;
93
94     case OP_LONG:
95       (*pos) += 3;
96       value_print (value_from_longest (exp->elts[pc + 1].type,
97                                        exp->elts[pc + 2].longconst),
98                    stream, 0, Val_no_prettyprint);
99       return;
100
101     case OP_DOUBLE:
102       (*pos) += 3;
103       value_print (value_from_double (exp->elts[pc + 1].type,
104                                       exp->elts[pc + 2].doubleconst),
105                    stream, 0, Val_no_prettyprint);
106       return;
107
108     case OP_VAR_VALUE:
109       {
110         struct block *b;
111         (*pos) += 3;
112         b = exp->elts[pc + 1].block;
113         if (b != NULL
114             && BLOCK_FUNCTION (b) != NULL
115             && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL)
116           {
117             fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream);
118             fputs_filtered ("::", stream);
119           }
120         fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream);
121       }
122       return;
123
124     case OP_LAST:
125       (*pos) += 2;
126       fprintf_filtered (stream, "$%d",
127                         longest_to_int (exp->elts[pc + 1].longconst));
128       return;
129
130     case OP_REGISTER:
131       {
132         int regnum = longest_to_int (exp->elts[pc + 1].longconst);
133         const char *name = user_reg_map_regnum_to_name (current_gdbarch,
134                                                         regnum);
135         (*pos) += 2;
136         fprintf_filtered (stream, "$%s", name);
137         return;
138       }
139
140     case OP_BOOL:
141       (*pos) += 2;
142       fprintf_filtered (stream, "%s",
143                         longest_to_int (exp->elts[pc + 1].longconst)
144                         ? "TRUE" : "FALSE");
145       return;
146
147     case OP_INTERNALVAR:
148       (*pos) += 2;
149       fprintf_filtered (stream, "$%s",
150                         internalvar_name (exp->elts[pc + 1].internalvar));
151       return;
152
153     case OP_FUNCALL:
154       (*pos) += 2;
155       nargs = longest_to_int (exp->elts[pc + 1].longconst);
156       print_subexp (exp, pos, stream, PREC_SUFFIX);
157       fputs_filtered (" (", stream);
158       for (tem = 0; tem < nargs; tem++)
159         {
160           if (tem != 0)
161             fputs_filtered (", ", stream);
162           print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
163         }
164       fputs_filtered (")", stream);
165       return;
166
167     case OP_NAME:
168     case OP_EXPRSTRING:
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 BINOP_SUBSCRIPT:
350       print_subexp (exp, pos, stream, PREC_SUFFIX);
351       fputs_filtered ("[", stream);
352       print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
353       fputs_filtered ("]", stream);
354       return;
355
356     case UNOP_POSTINCREMENT:
357       print_subexp (exp, pos, stream, PREC_SUFFIX);
358       fputs_filtered ("++", stream);
359       return;
360
361     case UNOP_POSTDECREMENT:
362       print_subexp (exp, pos, stream, PREC_SUFFIX);
363       fputs_filtered ("--", stream);
364       return;
365
366     case UNOP_CAST:
367       (*pos) += 2;
368       if ((int) prec > (int) PREC_PREFIX)
369         fputs_filtered ("(", stream);
370       fputs_filtered ("(", stream);
371       type_print (exp->elts[pc + 1].type, "", stream, 0);
372       fputs_filtered (") ", stream);
373       print_subexp (exp, pos, stream, PREC_PREFIX);
374       if ((int) prec > (int) PREC_PREFIX)
375         fputs_filtered (")", stream);
376       return;
377
378     case UNOP_MEMVAL:
379       (*pos) += 2;
380       if ((int) prec > (int) PREC_PREFIX)
381         fputs_filtered ("(", stream);
382       if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC &&
383           exp->elts[pc + 3].opcode == OP_LONG)
384         {
385           /* We have a minimal symbol fn, probably.  It's encoded
386              as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
387              Swallow the OP_LONG (including both its opcodes); ignore
388              its type; print the value in the type of the MEMVAL.  */
389           (*pos) += 4;
390           val = value_at_lazy (exp->elts[pc + 1].type,
391                                (CORE_ADDR) exp->elts[pc + 5].longconst);
392           value_print (val, stream, 0, Val_no_prettyprint);
393         }
394       else
395         {
396           fputs_filtered ("{", stream);
397           type_print (exp->elts[pc + 1].type, "", stream, 0);
398           fputs_filtered ("} ", stream);
399           print_subexp (exp, pos, stream, PREC_PREFIX);
400         }
401       if ((int) prec > (int) PREC_PREFIX)
402         fputs_filtered (")", stream);
403       return;
404
405     case BINOP_ASSIGN_MODIFY:
406       opcode = exp->elts[pc + 1].opcode;
407       (*pos) += 2;
408       myprec = PREC_ASSIGN;
409       assoc = 1;
410       assign_modify = 1;
411       op_str = "???";
412       for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
413         if (op_print_tab[tem].opcode == opcode)
414           {
415             op_str = op_print_tab[tem].string;
416             break;
417           }
418       if (op_print_tab[tem].opcode != opcode)
419         /* Not found; don't try to keep going because we don't know how
420            to interpret further elements.  */
421         error (_("Invalid expression"));
422       break;
423
424       /* C++ ops */
425
426     case OP_THIS:
427       ++(*pos);
428       fputs_filtered ("this", stream);
429       return;
430
431       /* Objective-C ops */
432
433     case OP_OBJC_SELF:
434       ++(*pos);
435       fputs_filtered ("self", stream);  /* The ObjC equivalent of "this".  */
436       return;
437
438       /* Modula-2 ops */
439
440     case MULTI_SUBSCRIPT:
441       (*pos) += 2;
442       nargs = longest_to_int (exp->elts[pc + 1].longconst);
443       print_subexp (exp, pos, stream, PREC_SUFFIX);
444       fprintf_unfiltered (stream, " [");
445       for (tem = 0; tem < nargs; tem++)
446         {
447           if (tem != 0)
448             fprintf_unfiltered (stream, ", ");
449           print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
450         }
451       fprintf_unfiltered (stream, "]");
452       return;
453
454     case BINOP_VAL:
455       (*pos) += 2;
456       fprintf_unfiltered (stream, "VAL(");
457       type_print (exp->elts[pc + 1].type, "", stream, 0);
458       fprintf_unfiltered (stream, ",");
459       print_subexp (exp, pos, stream, PREC_PREFIX);
460       fprintf_unfiltered (stream, ")");
461       return;
462
463     case BINOP_INCL:
464     case BINOP_EXCL:
465       error (_("print_subexp:  Not implemented."));
466
467       /* Default ops */
468
469     default:
470       op_str = "???";
471       for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
472         if (op_print_tab[tem].opcode == opcode)
473           {
474             op_str = op_print_tab[tem].string;
475             myprec = op_print_tab[tem].precedence;
476             assoc = op_print_tab[tem].right_assoc;
477             break;
478           }
479       if (op_print_tab[tem].opcode != opcode)
480         /* Not found; don't try to keep going because we don't know how
481            to interpret further elements.  For example, this happens
482            if opcode is OP_TYPE.  */
483         error (_("Invalid expression"));
484     }
485
486   /* Note that PREC_BUILTIN will always emit parentheses. */
487   if ((int) myprec < (int) prec)
488     fputs_filtered ("(", stream);
489   if ((int) opcode > (int) BINOP_END)
490     {
491       if (assoc)
492         {
493           /* Unary postfix operator.  */
494           print_subexp (exp, pos, stream, PREC_SUFFIX);
495           fputs_filtered (op_str, stream);
496         }
497       else
498         {
499           /* Unary prefix operator.  */
500           fputs_filtered (op_str, stream);
501           if (myprec == PREC_BUILTIN_FUNCTION)
502             fputs_filtered ("(", stream);
503           print_subexp (exp, pos, stream, PREC_PREFIX);
504           if (myprec == PREC_BUILTIN_FUNCTION)
505             fputs_filtered (")", stream);
506         }
507     }
508   else
509     {
510       /* Binary operator.  */
511       /* Print left operand.
512          If operator is right-associative,
513          increment precedence for this operand.  */
514       print_subexp (exp, pos, stream,
515                     (enum precedence) ((int) myprec + assoc));
516       /* Print the operator itself.  */
517       if (assign_modify)
518         fprintf_filtered (stream, " %s= ", op_str);
519       else if (op_str[0] == ',')
520         fprintf_filtered (stream, "%s ", op_str);
521       else
522         fprintf_filtered (stream, " %s ", op_str);
523       /* Print right operand.
524          If operator is left-associative,
525          increment precedence for this operand.  */
526       print_subexp (exp, pos, stream,
527                     (enum precedence) ((int) myprec + !assoc));
528     }
529
530   if ((int) myprec < (int) prec)
531     fputs_filtered (")", stream);
532 }
533
534 /* Return the operator corresponding to opcode OP as
535    a string.   NULL indicates that the opcode was not found in the
536    current language table.  */
537 char *
538 op_string (enum exp_opcode op)
539 {
540   int tem;
541   const struct op_print *op_print_tab;
542
543   op_print_tab = current_language->la_op_print_tab;
544   for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
545     if (op_print_tab[tem].opcode == op)
546       return op_print_tab[tem].string;
547   return NULL;
548 }
549
550 /* Support for dumping the raw data from expressions in a human readable
551    form.  */
552
553 static char *op_name (struct expression *, enum exp_opcode);
554 static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
555
556 /* Name for OPCODE, when it appears in expression EXP. */
557
558 static char *
559 op_name (struct expression *exp, enum exp_opcode opcode)
560 {
561   return exp->language_defn->la_exp_desc->op_name (opcode);
562 }
563
564 /* Default name for the standard operator OPCODE (i.e., one defined in
565    the definition of enum exp_opcode).  */
566
567 char *
568 op_name_standard (enum exp_opcode opcode)
569 {
570   switch (opcode)
571     {
572     default:
573       {
574         static char buf[30];
575
576         sprintf (buf, "<unknown %d>", opcode);
577         return buf;
578       }
579     case OP_NULL:
580       return "OP_NULL";
581     case BINOP_ADD:
582       return "BINOP_ADD";
583     case BINOP_SUB:
584       return "BINOP_SUB";
585     case BINOP_MUL:
586       return "BINOP_MUL";
587     case BINOP_DIV:
588       return "BINOP_DIV";
589     case BINOP_REM:
590       return "BINOP_REM";
591     case BINOP_MOD:
592       return "BINOP_MOD";
593     case BINOP_LSH:
594       return "BINOP_LSH";
595     case BINOP_RSH:
596       return "BINOP_RSH";
597     case BINOP_LOGICAL_AND:
598       return "BINOP_LOGICAL_AND";
599     case BINOP_LOGICAL_OR:
600       return "BINOP_LOGICAL_OR";
601     case BINOP_BITWISE_AND:
602       return "BINOP_BITWISE_AND";
603     case BINOP_BITWISE_IOR:
604       return "BINOP_BITWISE_IOR";
605     case BINOP_BITWISE_XOR:
606       return "BINOP_BITWISE_XOR";
607     case BINOP_EQUAL:
608       return "BINOP_EQUAL";
609     case BINOP_NOTEQUAL:
610       return "BINOP_NOTEQUAL";
611     case BINOP_LESS:
612       return "BINOP_LESS";
613     case BINOP_GTR:
614       return "BINOP_GTR";
615     case BINOP_LEQ:
616       return "BINOP_LEQ";
617     case BINOP_GEQ:
618       return "BINOP_GEQ";
619     case BINOP_REPEAT:
620       return "BINOP_REPEAT";
621     case BINOP_ASSIGN:
622       return "BINOP_ASSIGN";
623     case BINOP_COMMA:
624       return "BINOP_COMMA";
625     case BINOP_SUBSCRIPT:
626       return "BINOP_SUBSCRIPT";
627     case MULTI_SUBSCRIPT:
628       return "MULTI_SUBSCRIPT";
629     case BINOP_EXP:
630       return "BINOP_EXP";
631     case BINOP_MIN:
632       return "BINOP_MIN";
633     case BINOP_MAX:
634       return "BINOP_MAX";
635     case STRUCTOP_MEMBER:
636       return "STRUCTOP_MEMBER";
637     case STRUCTOP_MPTR:
638       return "STRUCTOP_MPTR";
639     case BINOP_INTDIV:
640       return "BINOP_INTDIV";
641     case BINOP_ASSIGN_MODIFY:
642       return "BINOP_ASSIGN_MODIFY";
643     case BINOP_VAL:
644       return "BINOP_VAL";
645     case BINOP_INCL:
646       return "BINOP_INCL";
647     case BINOP_EXCL:
648       return "BINOP_EXCL";
649     case BINOP_CONCAT:
650       return "BINOP_CONCAT";
651     case BINOP_RANGE:
652       return "BINOP_RANGE";
653     case BINOP_END:
654       return "BINOP_END";
655     case TERNOP_COND:
656       return "TERNOP_COND";
657     case TERNOP_SLICE:
658       return "TERNOP_SLICE";
659     case TERNOP_SLICE_COUNT:
660       return "TERNOP_SLICE_COUNT";
661     case OP_LONG:
662       return "OP_LONG";
663     case OP_DOUBLE:
664       return "OP_DOUBLE";
665     case OP_VAR_VALUE:
666       return "OP_VAR_VALUE";
667     case OP_LAST:
668       return "OP_LAST";
669     case OP_REGISTER:
670       return "OP_REGISTER";
671     case OP_INTERNALVAR:
672       return "OP_INTERNALVAR";
673     case OP_FUNCALL:
674       return "OP_FUNCALL";
675     case OP_STRING:
676       return "OP_STRING";
677     case OP_BITSTRING:
678       return "OP_BITSTRING";
679     case OP_ARRAY:
680       return "OP_ARRAY";
681     case UNOP_CAST:
682       return "UNOP_CAST";
683     case UNOP_MEMVAL:
684       return "UNOP_MEMVAL";
685     case UNOP_NEG:
686       return "UNOP_NEG";
687     case UNOP_LOGICAL_NOT:
688       return "UNOP_LOGICAL_NOT";
689     case UNOP_COMPLEMENT:
690       return "UNOP_COMPLEMENT";
691     case UNOP_IND:
692       return "UNOP_IND";
693     case UNOP_ADDR:
694       return "UNOP_ADDR";
695     case UNOP_PREINCREMENT:
696       return "UNOP_PREINCREMENT";
697     case UNOP_POSTINCREMENT:
698       return "UNOP_POSTINCREMENT";
699     case UNOP_PREDECREMENT:
700       return "UNOP_PREDECREMENT";
701     case UNOP_POSTDECREMENT:
702       return "UNOP_POSTDECREMENT";
703     case UNOP_SIZEOF:
704       return "UNOP_SIZEOF";
705     case UNOP_LOWER:
706       return "UNOP_LOWER";
707     case UNOP_UPPER:
708       return "UNOP_UPPER";
709     case UNOP_LENGTH:
710       return "UNOP_LENGTH";
711     case UNOP_PLUS:
712       return "UNOP_PLUS";
713     case UNOP_CAP:
714       return "UNOP_CAP";
715     case UNOP_CHR:
716       return "UNOP_CHR";
717     case UNOP_ORD:
718       return "UNOP_ORD";
719     case UNOP_ABS:
720       return "UNOP_ABS";
721     case UNOP_FLOAT:
722       return "UNOP_FLOAT";
723     case UNOP_HIGH:
724       return "UNOP_HIGH";
725     case UNOP_MAX:
726       return "UNOP_MAX";
727     case UNOP_MIN:
728       return "UNOP_MIN";
729     case UNOP_ODD:
730       return "UNOP_ODD";
731     case UNOP_TRUNC:
732       return "UNOP_TRUNC";
733     case OP_BOOL:
734       return "OP_BOOL";
735     case OP_M2_STRING:
736       return "OP_M2_STRING";
737     case STRUCTOP_STRUCT:
738       return "STRUCTOP_STRUCT";
739     case STRUCTOP_PTR:
740       return "STRUCTOP_PTR";
741     case OP_THIS:
742       return "OP_THIS";
743     case OP_OBJC_SELF:
744       return "OP_OBJC_SELF";
745     case OP_SCOPE:
746       return "OP_SCOPE";
747     case OP_TYPE:
748       return "OP_TYPE";
749     case OP_LABELED:
750       return "OP_LABELED";
751     }
752 }
753
754 void
755 dump_raw_expression (struct expression *exp, struct ui_file *stream,
756                      char *note)
757 {
758   int elt;
759   char *opcode_name;
760   char *eltscan;
761   int eltsize;
762
763   fprintf_filtered (stream, "Dump of expression @ ");
764   gdb_print_host_address (exp, stream);
765   fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
766                     exp->language_defn->la_name, exp->nelts,
767                     (long) sizeof (union exp_element));
768   fprintf_filtered (stream, "\t%5s  %20s  %16s  %s\n", "Index", "Opcode",
769                     "Hex Value", "String Value");
770   for (elt = 0; elt < exp->nelts; elt++)
771     {
772       fprintf_filtered (stream, "\t%5d  ", elt);
773       opcode_name = op_name (exp, exp->elts[elt].opcode);
774
775       fprintf_filtered (stream, "%20s  ", opcode_name);
776       print_longest (stream, 'd', 0, exp->elts[elt].longconst);
777       fprintf_filtered (stream, "  ");
778
779       for (eltscan = (char *) &exp->elts[elt],
780            eltsize = sizeof (union exp_element);
781            eltsize-- > 0;
782            eltscan++)
783         {
784           fprintf_filtered (stream, "%c",
785                             isprint (*eltscan) ? (*eltscan & 0xFF) : '.');
786         }
787       fprintf_filtered (stream, "\n");
788     }
789 }
790
791 /* Dump the subexpression of prefix expression EXP whose operator is at
792    position ELT onto STREAM.  Returns the position of the next 
793    subexpression in EXP.  */
794
795 int
796 dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
797 {
798   static int indent = 0;
799   int i;
800
801   fprintf_filtered (stream, "\n");
802   fprintf_filtered (stream, "\t%5d  ", elt);
803
804   for (i = 1; i <= indent; i++)
805     fprintf_filtered (stream, " ");
806   indent += 2;
807
808   fprintf_filtered (stream, "%-20s  ", op_name (exp, exp->elts[elt].opcode));
809
810   elt = dump_subexp_body (exp, stream, elt);
811
812   indent -= 2;
813
814   return elt;
815 }
816
817 /* Dump the operands of prefix expression EXP whose opcode is at
818    position ELT onto STREAM.  Returns the position of the next 
819    subexpression in EXP.  */
820
821 static int
822 dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
823 {
824   return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
825 }
826
827 /* Default value for subexp_body in exp_descriptor vector.  */
828
829 int
830 dump_subexp_body_standard (struct expression *exp, 
831                            struct ui_file *stream, int elt)
832 {
833   int opcode = exp->elts[elt++].opcode;
834
835   switch (opcode)
836     {
837     case TERNOP_COND:
838     case TERNOP_SLICE:
839     case TERNOP_SLICE_COUNT:
840       elt = dump_subexp (exp, stream, elt);
841     case BINOP_ADD:
842     case BINOP_SUB:
843     case BINOP_MUL:
844     case BINOP_DIV:
845     case BINOP_REM:
846     case BINOP_MOD:
847     case BINOP_LSH:
848     case BINOP_RSH:
849     case BINOP_LOGICAL_AND:
850     case BINOP_LOGICAL_OR:
851     case BINOP_BITWISE_AND:
852     case BINOP_BITWISE_IOR:
853     case BINOP_BITWISE_XOR:
854     case BINOP_EQUAL:
855     case BINOP_NOTEQUAL:
856     case BINOP_LESS:
857     case BINOP_GTR:
858     case BINOP_LEQ:
859     case BINOP_GEQ:
860     case BINOP_REPEAT:
861     case BINOP_ASSIGN:
862     case BINOP_COMMA:
863     case BINOP_SUBSCRIPT:
864     case BINOP_EXP:
865     case BINOP_MIN:
866     case BINOP_MAX:
867     case BINOP_INTDIV:
868     case BINOP_ASSIGN_MODIFY:
869     case BINOP_VAL:
870     case BINOP_INCL:
871     case BINOP_EXCL:
872     case BINOP_CONCAT:
873     case BINOP_IN:
874     case BINOP_RANGE:
875     case BINOP_END:
876       elt = dump_subexp (exp, stream, elt);
877     case UNOP_NEG:
878     case UNOP_LOGICAL_NOT:
879     case UNOP_COMPLEMENT:
880     case UNOP_IND:
881     case UNOP_ADDR:
882     case UNOP_PREINCREMENT:
883     case UNOP_POSTINCREMENT:
884     case UNOP_PREDECREMENT:
885     case UNOP_POSTDECREMENT:
886     case UNOP_SIZEOF:
887     case UNOP_PLUS:
888     case UNOP_CAP:
889     case UNOP_CHR:
890     case UNOP_ORD:
891     case UNOP_ABS:
892     case UNOP_FLOAT:
893     case UNOP_HIGH:
894     case UNOP_MAX:
895     case UNOP_MIN:
896     case UNOP_ODD:
897     case UNOP_TRUNC:
898     case UNOP_LOWER:
899     case UNOP_UPPER:
900     case UNOP_LENGTH:
901     case UNOP_CARD:
902     case UNOP_CHMAX:
903     case UNOP_CHMIN:
904       elt = dump_subexp (exp, stream, elt);
905       break;
906     case OP_LONG:
907       fprintf_filtered (stream, "Type @");
908       gdb_print_host_address (exp->elts[elt].type, stream);
909       fprintf_filtered (stream, " (");
910       type_print (exp->elts[elt].type, NULL, stream, 0);
911       fprintf_filtered (stream, "), value %ld (0x%lx)",
912                         (long) exp->elts[elt + 1].longconst,
913                         (long) exp->elts[elt + 1].longconst);
914       elt += 3;
915       break;
916     case OP_DOUBLE:
917       fprintf_filtered (stream, "Type @");
918       gdb_print_host_address (exp->elts[elt].type, stream);
919       fprintf_filtered (stream, " (");
920       type_print (exp->elts[elt].type, NULL, stream, 0);
921       fprintf_filtered (stream, "), value %g",
922                         (double) exp->elts[elt + 1].doubleconst);
923       elt += 3;
924       break;
925     case OP_VAR_VALUE:
926       fprintf_filtered (stream, "Block @");
927       gdb_print_host_address (exp->elts[elt].block, stream);
928       fprintf_filtered (stream, ", symbol @");
929       gdb_print_host_address (exp->elts[elt + 1].symbol, stream);
930       fprintf_filtered (stream, " (%s)",
931                         DEPRECATED_SYMBOL_NAME (exp->elts[elt + 1].symbol));
932       elt += 3;
933       break;
934     case OP_LAST:
935       fprintf_filtered (stream, "History element %ld",
936                         (long) exp->elts[elt].longconst);
937       elt += 2;
938       break;
939     case OP_REGISTER:
940       fprintf_filtered (stream, "Register %ld",
941                         (long) exp->elts[elt].longconst);
942       elt += 2;
943       break;
944     case OP_INTERNALVAR:
945       fprintf_filtered (stream, "Internal var @");
946       gdb_print_host_address (exp->elts[elt].internalvar, stream);
947       fprintf_filtered (stream, " (%s)",
948                         exp->elts[elt].internalvar->name);
949       elt += 2;
950       break;
951     case OP_FUNCALL:
952       {
953         int i, nargs;
954
955         nargs = longest_to_int (exp->elts[elt].longconst);
956
957         fprintf_filtered (stream, "Number of args: %d", nargs);
958         elt += 2;
959
960         for (i = 1; i <= nargs + 1; i++)
961           elt = dump_subexp (exp, stream, elt);
962       }
963       break;
964     case OP_ARRAY:
965       {
966         int lower, upper;
967         int i;
968
969         lower = longest_to_int (exp->elts[elt].longconst);
970         upper = longest_to_int (exp->elts[elt + 1].longconst);
971
972         fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper);
973         elt += 3;
974
975         for (i = 1; i <= upper - lower + 1; i++)
976           elt = dump_subexp (exp, stream, elt);
977       }
978       break;
979     case UNOP_MEMVAL:
980     case UNOP_CAST:
981       fprintf_filtered (stream, "Type @");
982       gdb_print_host_address (exp->elts[elt].type, stream);
983       fprintf_filtered (stream, " (");
984       type_print (exp->elts[elt].type, NULL, stream, 0);
985       fprintf_filtered (stream, ")");
986       elt = dump_subexp (exp, stream, elt + 2);
987       break;
988     case OP_TYPE:
989       fprintf_filtered (stream, "Type @");
990       gdb_print_host_address (exp->elts[elt].type, stream);
991       fprintf_filtered (stream, " (");
992       type_print (exp->elts[elt].type, NULL, stream, 0);
993       fprintf_filtered (stream, ")");
994       elt += 2;
995       break;
996     case STRUCTOP_STRUCT:
997     case STRUCTOP_PTR:
998       {
999         char *elem_name;
1000         int len;
1001
1002         len = longest_to_int (exp->elts[elt].longconst);
1003         elem_name = &exp->elts[elt + 1].string;
1004
1005         fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name);
1006         elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1));
1007       }
1008       break;
1009     case OP_SCOPE:
1010       {
1011         char *elem_name;
1012         int len;
1013
1014         fprintf_filtered (stream, "Type @");
1015         gdb_print_host_address (exp->elts[elt].type, stream);
1016         fprintf_filtered (stream, " (");
1017         type_print (exp->elts[elt].type, NULL, stream, 0);
1018         fprintf_filtered (stream, ") ");
1019
1020         len = longest_to_int (exp->elts[elt + 1].longconst);
1021         elem_name = &exp->elts[elt + 2].string;
1022
1023         fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name);
1024         elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
1025       }
1026       break;
1027     default:
1028     case OP_NULL:
1029     case STRUCTOP_MEMBER:
1030     case STRUCTOP_MPTR:
1031     case MULTI_SUBSCRIPT:
1032     case OP_F77_UNDETERMINED_ARGLIST:
1033     case OP_COMPLEX:
1034     case OP_STRING:
1035     case OP_BITSTRING:
1036     case OP_BOOL:
1037     case OP_M2_STRING:
1038     case OP_THIS:
1039     case OP_LABELED:
1040     case OP_NAME:
1041     case OP_EXPRSTRING:
1042       fprintf_filtered (stream, "Unknown format");
1043     }
1044
1045   return elt;
1046 }
1047
1048 void
1049 dump_prefix_expression (struct expression *exp, struct ui_file *stream)
1050 {
1051   int elt;
1052
1053   fprintf_filtered (stream, "Dump of expression @ ");
1054   gdb_print_host_address (exp, stream);
1055   fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
1056   if (exp->elts[0].opcode != OP_TYPE)
1057     print_expression (exp, stream);
1058   else
1059     fputs_filtered ("Type printing not yet supported....", stream);
1060   fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1061                     exp->language_defn->la_name, exp->nelts,
1062                     (long) sizeof (union exp_element));
1063   fputs_filtered ("\n", stream);
1064
1065   for (elt = 0; elt < exp->nelts;)
1066     elt = dump_subexp (exp, stream, elt);
1067   fputs_filtered ("\n", stream);
1068 }