OSDN Git Service

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