OSDN Git Service

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