Add ADL support
[platform/upstream/binutils.git] / gdb / expprint.c
1 /* Print in infix form a struct expression.
2
3    Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4    1998, 1999, 2000, 2003, 2007, 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, NULL, 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, NULL, 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, NULL, 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_DYNAMIC_CAST:
414     case UNOP_REINTERPRET_CAST:
415       fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast"
416                       : "reinterpret_cast", stream);
417       fputs_filtered ("<", stream);
418       (*pos) += 2;
419       type_print (exp->elts[pc + 1].type, "", stream, 0);
420       fputs_filtered ("> (", stream);
421       print_subexp (exp, pos, stream, PREC_PREFIX);
422       fputs_filtered (")", stream);
423       return;
424
425     case UNOP_MEMVAL:
426       (*pos) += 2;
427       if ((int) prec > (int) PREC_PREFIX)
428         fputs_filtered ("(", stream);
429       if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC
430           && exp->elts[pc + 3].opcode == OP_LONG)
431         {
432           struct value_print_options opts;
433
434           /* We have a minimal symbol fn, probably.  It's encoded
435              as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
436              Swallow the OP_LONG (including both its opcodes); ignore
437              its type; print the value in the type of the MEMVAL.  */
438           (*pos) += 4;
439           val = value_at_lazy (exp->elts[pc + 1].type,
440                                (CORE_ADDR) exp->elts[pc + 5].longconst);
441           get_raw_print_options (&opts);
442           value_print (val, stream, &opts);
443         }
444       else
445         {
446           fputs_filtered ("{", stream);
447           type_print (exp->elts[pc + 1].type, "", stream, 0);
448           fputs_filtered ("} ", stream);
449           print_subexp (exp, pos, stream, PREC_PREFIX);
450         }
451       if ((int) prec > (int) PREC_PREFIX)
452         fputs_filtered (")", stream);
453       return;
454
455     case UNOP_MEMVAL_TLS:
456       (*pos) += 3;
457       if ((int) prec > (int) PREC_PREFIX)
458         fputs_filtered ("(", stream);
459       fputs_filtered ("{", stream);
460       type_print (exp->elts[pc + 2].type, "", stream, 0);
461       fputs_filtered ("} ", stream);
462       print_subexp (exp, pos, stream, PREC_PREFIX);
463       if ((int) prec > (int) PREC_PREFIX)
464         fputs_filtered (")", stream);
465       return;
466
467     case BINOP_ASSIGN_MODIFY:
468       opcode = exp->elts[pc + 1].opcode;
469       (*pos) += 2;
470       myprec = PREC_ASSIGN;
471       assoc = 1;
472       assign_modify = 1;
473       op_str = "???";
474       for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
475         if (op_print_tab[tem].opcode == opcode)
476           {
477             op_str = op_print_tab[tem].string;
478             break;
479           }
480       if (op_print_tab[tem].opcode != opcode)
481         /* Not found; don't try to keep going because we don't know how
482            to interpret further elements.  */
483         error (_("Invalid expression"));
484       break;
485
486       /* C++ ops */
487
488     case OP_THIS:
489       ++(*pos);
490       fputs_filtered ("this", stream);
491       return;
492
493       /* Objective-C ops */
494
495     case OP_OBJC_SELF:
496       ++(*pos);
497       fputs_filtered ("self", stream);  /* The ObjC equivalent of "this".  */
498       return;
499
500       /* Modula-2 ops */
501
502     case MULTI_SUBSCRIPT:
503       (*pos) += 2;
504       nargs = longest_to_int (exp->elts[pc + 1].longconst);
505       print_subexp (exp, pos, stream, PREC_SUFFIX);
506       fprintf_unfiltered (stream, " [");
507       for (tem = 0; tem < nargs; tem++)
508         {
509           if (tem != 0)
510             fprintf_unfiltered (stream, ", ");
511           print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
512         }
513       fprintf_unfiltered (stream, "]");
514       return;
515
516     case BINOP_VAL:
517       (*pos) += 2;
518       fprintf_unfiltered (stream, "VAL(");
519       type_print (exp->elts[pc + 1].type, "", stream, 0);
520       fprintf_unfiltered (stream, ",");
521       print_subexp (exp, pos, stream, PREC_PREFIX);
522       fprintf_unfiltered (stream, ")");
523       return;
524
525     case BINOP_INCL:
526     case BINOP_EXCL:
527       error (_("print_subexp:  Not implemented."));
528
529       /* Default ops */
530
531     default:
532       op_str = "???";
533       for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
534         if (op_print_tab[tem].opcode == opcode)
535           {
536             op_str = op_print_tab[tem].string;
537             myprec = op_print_tab[tem].precedence;
538             assoc = op_print_tab[tem].right_assoc;
539             break;
540           }
541       if (op_print_tab[tem].opcode != opcode)
542         /* Not found; don't try to keep going because we don't know how
543            to interpret further elements.  For example, this happens
544            if opcode is OP_TYPE.  */
545         error (_("Invalid expression"));
546     }
547
548   /* Note that PREC_BUILTIN will always emit parentheses. */
549   if ((int) myprec < (int) prec)
550     fputs_filtered ("(", stream);
551   if ((int) opcode > (int) BINOP_END)
552     {
553       if (assoc)
554         {
555           /* Unary postfix operator.  */
556           print_subexp (exp, pos, stream, PREC_SUFFIX);
557           fputs_filtered (op_str, stream);
558         }
559       else
560         {
561           /* Unary prefix operator.  */
562           fputs_filtered (op_str, stream);
563           if (myprec == PREC_BUILTIN_FUNCTION)
564             fputs_filtered ("(", stream);
565           print_subexp (exp, pos, stream, PREC_PREFIX);
566           if (myprec == PREC_BUILTIN_FUNCTION)
567             fputs_filtered (")", stream);
568         }
569     }
570   else
571     {
572       /* Binary operator.  */
573       /* Print left operand.
574          If operator is right-associative,
575          increment precedence for this operand.  */
576       print_subexp (exp, pos, stream,
577                     (enum precedence) ((int) myprec + assoc));
578       /* Print the operator itself.  */
579       if (assign_modify)
580         fprintf_filtered (stream, " %s= ", op_str);
581       else if (op_str[0] == ',')
582         fprintf_filtered (stream, "%s ", op_str);
583       else
584         fprintf_filtered (stream, " %s ", op_str);
585       /* Print right operand.
586          If operator is left-associative,
587          increment precedence for this operand.  */
588       print_subexp (exp, pos, stream,
589                     (enum precedence) ((int) myprec + !assoc));
590     }
591
592   if ((int) myprec < (int) prec)
593     fputs_filtered (")", stream);
594 }
595
596 /* Return the operator corresponding to opcode OP as
597    a string.   NULL indicates that the opcode was not found in the
598    current language table.  */
599 char *
600 op_string (enum exp_opcode op)
601 {
602   int tem;
603   const struct op_print *op_print_tab;
604
605   op_print_tab = current_language->la_op_print_tab;
606   for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
607     if (op_print_tab[tem].opcode == op)
608       return op_print_tab[tem].string;
609   return NULL;
610 }
611
612 /* Support for dumping the raw data from expressions in a human readable
613    form.  */
614
615 static char *op_name (struct expression *, enum exp_opcode);
616 static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
617
618 /* Name for OPCODE, when it appears in expression EXP. */
619
620 static char *
621 op_name (struct expression *exp, enum exp_opcode opcode)
622 {
623   return exp->language_defn->la_exp_desc->op_name (opcode);
624 }
625
626 /* Default name for the standard operator OPCODE (i.e., one defined in
627    the definition of enum exp_opcode).  */
628
629 char *
630 op_name_standard (enum exp_opcode opcode)
631 {
632   switch (opcode)
633     {
634     default:
635       {
636         static char buf[30];
637
638         sprintf (buf, "<unknown %d>", opcode);
639         return buf;
640       }
641     case OP_NULL:
642       return "OP_NULL";
643     case BINOP_ADD:
644       return "BINOP_ADD";
645     case BINOP_SUB:
646       return "BINOP_SUB";
647     case BINOP_MUL:
648       return "BINOP_MUL";
649     case BINOP_DIV:
650       return "BINOP_DIV";
651     case BINOP_REM:
652       return "BINOP_REM";
653     case BINOP_MOD:
654       return "BINOP_MOD";
655     case BINOP_LSH:
656       return "BINOP_LSH";
657     case BINOP_RSH:
658       return "BINOP_RSH";
659     case BINOP_LOGICAL_AND:
660       return "BINOP_LOGICAL_AND";
661     case BINOP_LOGICAL_OR:
662       return "BINOP_LOGICAL_OR";
663     case BINOP_BITWISE_AND:
664       return "BINOP_BITWISE_AND";
665     case BINOP_BITWISE_IOR:
666       return "BINOP_BITWISE_IOR";
667     case BINOP_BITWISE_XOR:
668       return "BINOP_BITWISE_XOR";
669     case BINOP_EQUAL:
670       return "BINOP_EQUAL";
671     case BINOP_NOTEQUAL:
672       return "BINOP_NOTEQUAL";
673     case BINOP_LESS:
674       return "BINOP_LESS";
675     case BINOP_GTR:
676       return "BINOP_GTR";
677     case BINOP_LEQ:
678       return "BINOP_LEQ";
679     case BINOP_GEQ:
680       return "BINOP_GEQ";
681     case BINOP_REPEAT:
682       return "BINOP_REPEAT";
683     case BINOP_ASSIGN:
684       return "BINOP_ASSIGN";
685     case BINOP_COMMA:
686       return "BINOP_COMMA";
687     case BINOP_SUBSCRIPT:
688       return "BINOP_SUBSCRIPT";
689     case MULTI_SUBSCRIPT:
690       return "MULTI_SUBSCRIPT";
691     case BINOP_EXP:
692       return "BINOP_EXP";
693     case BINOP_MIN:
694       return "BINOP_MIN";
695     case BINOP_MAX:
696       return "BINOP_MAX";
697     case STRUCTOP_MEMBER:
698       return "STRUCTOP_MEMBER";
699     case STRUCTOP_MPTR:
700       return "STRUCTOP_MPTR";
701     case BINOP_INTDIV:
702       return "BINOP_INTDIV";
703     case BINOP_ASSIGN_MODIFY:
704       return "BINOP_ASSIGN_MODIFY";
705     case BINOP_VAL:
706       return "BINOP_VAL";
707     case BINOP_INCL:
708       return "BINOP_INCL";
709     case BINOP_EXCL:
710       return "BINOP_EXCL";
711     case BINOP_CONCAT:
712       return "BINOP_CONCAT";
713     case BINOP_RANGE:
714       return "BINOP_RANGE";
715     case BINOP_END:
716       return "BINOP_END";
717     case TERNOP_COND:
718       return "TERNOP_COND";
719     case TERNOP_SLICE:
720       return "TERNOP_SLICE";
721     case TERNOP_SLICE_COUNT:
722       return "TERNOP_SLICE_COUNT";
723     case OP_LONG:
724       return "OP_LONG";
725     case OP_DOUBLE:
726       return "OP_DOUBLE";
727     case OP_VAR_VALUE:
728       return "OP_VAR_VALUE";
729     case OP_LAST:
730       return "OP_LAST";
731     case OP_REGISTER:
732       return "OP_REGISTER";
733     case OP_INTERNALVAR:
734       return "OP_INTERNALVAR";
735     case OP_FUNCALL:
736       return "OP_FUNCALL";
737     case OP_STRING:
738       return "OP_STRING";
739     case OP_BITSTRING:
740       return "OP_BITSTRING";
741     case OP_ARRAY:
742       return "OP_ARRAY";
743     case UNOP_CAST:
744       return "UNOP_CAST";
745     case UNOP_DYNAMIC_CAST:
746       return "UNOP_DYNAMIC_CAST";
747     case UNOP_REINTERPRET_CAST:
748       return "UNOP_REINTERPRET_CAST";
749     case UNOP_MEMVAL:
750       return "UNOP_MEMVAL";
751     case UNOP_MEMVAL_TLS:
752       return "UNOP_MEMVAL_TLS";
753     case UNOP_NEG:
754       return "UNOP_NEG";
755     case UNOP_LOGICAL_NOT:
756       return "UNOP_LOGICAL_NOT";
757     case UNOP_COMPLEMENT:
758       return "UNOP_COMPLEMENT";
759     case UNOP_IND:
760       return "UNOP_IND";
761     case UNOP_ADDR:
762       return "UNOP_ADDR";
763     case UNOP_PREINCREMENT:
764       return "UNOP_PREINCREMENT";
765     case UNOP_POSTINCREMENT:
766       return "UNOP_POSTINCREMENT";
767     case UNOP_PREDECREMENT:
768       return "UNOP_PREDECREMENT";
769     case UNOP_POSTDECREMENT:
770       return "UNOP_POSTDECREMENT";
771     case UNOP_SIZEOF:
772       return "UNOP_SIZEOF";
773     case UNOP_LOWER:
774       return "UNOP_LOWER";
775     case UNOP_UPPER:
776       return "UNOP_UPPER";
777     case UNOP_LENGTH:
778       return "UNOP_LENGTH";
779     case UNOP_PLUS:
780       return "UNOP_PLUS";
781     case UNOP_CAP:
782       return "UNOP_CAP";
783     case UNOP_CHR:
784       return "UNOP_CHR";
785     case UNOP_ORD:
786       return "UNOP_ORD";
787     case UNOP_ABS:
788       return "UNOP_ABS";
789     case UNOP_FLOAT:
790       return "UNOP_FLOAT";
791     case UNOP_HIGH:
792       return "UNOP_HIGH";
793     case UNOP_MAX:
794       return "UNOP_MAX";
795     case UNOP_MIN:
796       return "UNOP_MIN";
797     case UNOP_ODD:
798       return "UNOP_ODD";
799     case UNOP_TRUNC:
800       return "UNOP_TRUNC";
801     case OP_BOOL:
802       return "OP_BOOL";
803     case OP_M2_STRING:
804       return "OP_M2_STRING";
805     case STRUCTOP_STRUCT:
806       return "STRUCTOP_STRUCT";
807     case STRUCTOP_PTR:
808       return "STRUCTOP_PTR";
809     case OP_THIS:
810       return "OP_THIS";
811     case OP_OBJC_SELF:
812       return "OP_OBJC_SELF";
813     case OP_SCOPE:
814       return "OP_SCOPE";
815     case OP_TYPE:
816       return "OP_TYPE";
817     case OP_LABELED:
818       return "OP_LABELED";
819     case OP_ADL_FUNC:
820       return "OP_ADL_FUNC";
821     }
822 }
823
824 /* Print a raw dump of expression EXP to STREAM.
825    NOTE, if non-NULL, is printed as extra explanatory text.  */
826
827 void
828 dump_raw_expression (struct expression *exp, struct ui_file *stream,
829                      char *note)
830 {
831   int elt;
832   char *opcode_name;
833   char *eltscan;
834   int eltsize;
835
836   fprintf_filtered (stream, "Dump of expression @ ");
837   gdb_print_host_address (exp, stream);
838   if (note)
839     fprintf_filtered (stream, ", %s:", note);
840   fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
841                     exp->language_defn->la_name, exp->nelts,
842                     (long) sizeof (union exp_element));
843   fprintf_filtered (stream, "\t%5s  %20s  %16s  %s\n", "Index", "Opcode",
844                     "Hex Value", "String Value");
845   for (elt = 0; elt < exp->nelts; elt++)
846     {
847       fprintf_filtered (stream, "\t%5d  ", elt);
848       opcode_name = op_name (exp, exp->elts[elt].opcode);
849
850       fprintf_filtered (stream, "%20s  ", opcode_name);
851       print_longest (stream, 'd', 0, exp->elts[elt].longconst);
852       fprintf_filtered (stream, "  ");
853
854       for (eltscan = (char *) &exp->elts[elt],
855            eltsize = sizeof (union exp_element);
856            eltsize-- > 0;
857            eltscan++)
858         {
859           fprintf_filtered (stream, "%c",
860                             isprint (*eltscan) ? (*eltscan & 0xFF) : '.');
861         }
862       fprintf_filtered (stream, "\n");
863     }
864 }
865
866 /* Dump the subexpression of prefix expression EXP whose operator is at
867    position ELT onto STREAM.  Returns the position of the next 
868    subexpression in EXP.  */
869
870 int
871 dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
872 {
873   static int indent = 0;
874   int i;
875
876   fprintf_filtered (stream, "\n");
877   fprintf_filtered (stream, "\t%5d  ", elt);
878
879   for (i = 1; i <= indent; i++)
880     fprintf_filtered (stream, " ");
881   indent += 2;
882
883   fprintf_filtered (stream, "%-20s  ", op_name (exp, exp->elts[elt].opcode));
884
885   elt = dump_subexp_body (exp, stream, elt);
886
887   indent -= 2;
888
889   return elt;
890 }
891
892 /* Dump the operands of prefix expression EXP whose opcode is at
893    position ELT onto STREAM.  Returns the position of the next 
894    subexpression in EXP.  */
895
896 static int
897 dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
898 {
899   return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
900 }
901
902 /* Default value for subexp_body in exp_descriptor vector.  */
903
904 int
905 dump_subexp_body_standard (struct expression *exp, 
906                            struct ui_file *stream, int elt)
907 {
908   int opcode = exp->elts[elt++].opcode;
909
910   switch (opcode)
911     {
912     case TERNOP_COND:
913     case TERNOP_SLICE:
914     case TERNOP_SLICE_COUNT:
915       elt = dump_subexp (exp, stream, elt);
916     case BINOP_ADD:
917     case BINOP_SUB:
918     case BINOP_MUL:
919     case BINOP_DIV:
920     case BINOP_REM:
921     case BINOP_MOD:
922     case BINOP_LSH:
923     case BINOP_RSH:
924     case BINOP_LOGICAL_AND:
925     case BINOP_LOGICAL_OR:
926     case BINOP_BITWISE_AND:
927     case BINOP_BITWISE_IOR:
928     case BINOP_BITWISE_XOR:
929     case BINOP_EQUAL:
930     case BINOP_NOTEQUAL:
931     case BINOP_LESS:
932     case BINOP_GTR:
933     case BINOP_LEQ:
934     case BINOP_GEQ:
935     case BINOP_REPEAT:
936     case BINOP_ASSIGN:
937     case BINOP_COMMA:
938     case BINOP_SUBSCRIPT:
939     case BINOP_EXP:
940     case BINOP_MIN:
941     case BINOP_MAX:
942     case BINOP_INTDIV:
943     case BINOP_ASSIGN_MODIFY:
944     case BINOP_VAL:
945     case BINOP_INCL:
946     case BINOP_EXCL:
947     case BINOP_CONCAT:
948     case BINOP_IN:
949     case BINOP_RANGE:
950     case BINOP_END:
951     case STRUCTOP_MEMBER:
952     case STRUCTOP_MPTR:
953       elt = dump_subexp (exp, stream, elt);
954     case UNOP_NEG:
955     case UNOP_LOGICAL_NOT:
956     case UNOP_COMPLEMENT:
957     case UNOP_IND:
958     case UNOP_ADDR:
959     case UNOP_PREINCREMENT:
960     case UNOP_POSTINCREMENT:
961     case UNOP_PREDECREMENT:
962     case UNOP_POSTDECREMENT:
963     case UNOP_SIZEOF:
964     case UNOP_PLUS:
965     case UNOP_CAP:
966     case UNOP_CHR:
967     case UNOP_ORD:
968     case UNOP_ABS:
969     case UNOP_FLOAT:
970     case UNOP_HIGH:
971     case UNOP_MAX:
972     case UNOP_MIN:
973     case UNOP_ODD:
974     case UNOP_TRUNC:
975     case UNOP_LOWER:
976     case UNOP_UPPER:
977     case UNOP_LENGTH:
978     case UNOP_CARD:
979     case UNOP_CHMAX:
980     case UNOP_CHMIN:
981       elt = dump_subexp (exp, stream, elt);
982       break;
983     case OP_LONG:
984       fprintf_filtered (stream, "Type @");
985       gdb_print_host_address (exp->elts[elt].type, stream);
986       fprintf_filtered (stream, " (");
987       type_print (exp->elts[elt].type, NULL, stream, 0);
988       fprintf_filtered (stream, "), value %ld (0x%lx)",
989                         (long) exp->elts[elt + 1].longconst,
990                         (long) exp->elts[elt + 1].longconst);
991       elt += 3;
992       break;
993     case OP_DOUBLE:
994       fprintf_filtered (stream, "Type @");
995       gdb_print_host_address (exp->elts[elt].type, stream);
996       fprintf_filtered (stream, " (");
997       type_print (exp->elts[elt].type, NULL, stream, 0);
998       fprintf_filtered (stream, "), value %g",
999                         (double) exp->elts[elt + 1].doubleconst);
1000       elt += 3;
1001       break;
1002     case OP_VAR_VALUE:
1003       fprintf_filtered (stream, "Block @");
1004       gdb_print_host_address (exp->elts[elt].block, stream);
1005       fprintf_filtered (stream, ", symbol @");
1006       gdb_print_host_address (exp->elts[elt + 1].symbol, stream);
1007       fprintf_filtered (stream, " (%s)",
1008                         SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol));
1009       elt += 3;
1010       break;
1011     case OP_LAST:
1012       fprintf_filtered (stream, "History element %ld",
1013                         (long) exp->elts[elt].longconst);
1014       elt += 2;
1015       break;
1016     case OP_REGISTER:
1017       fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string);
1018       elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1);
1019       break;
1020     case OP_INTERNALVAR:
1021       fprintf_filtered (stream, "Internal var @");
1022       gdb_print_host_address (exp->elts[elt].internalvar, stream);
1023       fprintf_filtered (stream, " (%s)",
1024                         internalvar_name (exp->elts[elt].internalvar));
1025       elt += 2;
1026       break;
1027     case OP_FUNCALL:
1028       {
1029         int i, nargs;
1030
1031         nargs = longest_to_int (exp->elts[elt].longconst);
1032
1033         fprintf_filtered (stream, "Number of args: %d", nargs);
1034         elt += 2;
1035
1036         for (i = 1; i <= nargs + 1; i++)
1037           elt = dump_subexp (exp, stream, elt);
1038       }
1039       break;
1040     case OP_ARRAY:
1041       {
1042         int lower, upper;
1043         int i;
1044
1045         lower = longest_to_int (exp->elts[elt].longconst);
1046         upper = longest_to_int (exp->elts[elt + 1].longconst);
1047
1048         fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper);
1049         elt += 3;
1050
1051         for (i = 1; i <= upper - lower + 1; i++)
1052           elt = dump_subexp (exp, stream, elt);
1053       }
1054       break;
1055     case UNOP_MEMVAL:
1056     case UNOP_CAST:
1057     case UNOP_DYNAMIC_CAST:
1058     case UNOP_REINTERPRET_CAST:
1059       fprintf_filtered (stream, "Type @");
1060       gdb_print_host_address (exp->elts[elt].type, stream);
1061       fprintf_filtered (stream, " (");
1062       type_print (exp->elts[elt].type, NULL, stream, 0);
1063       fprintf_filtered (stream, ")");
1064       elt = dump_subexp (exp, stream, elt + 2);
1065       break;
1066     case UNOP_MEMVAL_TLS:
1067       fprintf_filtered (stream, "TLS type @");
1068       gdb_print_host_address (exp->elts[elt + 1].type, stream);
1069       fprintf_filtered (stream, " (__thread /* \"%s\" */ ",
1070                         (exp->elts[elt].objfile == NULL ? "(null)"
1071                          : exp->elts[elt].objfile->name));
1072       type_print (exp->elts[elt + 1].type, NULL, stream, 0);
1073       fprintf_filtered (stream, ")");
1074       elt = dump_subexp (exp, stream, elt + 3);
1075       break;
1076     case OP_TYPE:
1077       fprintf_filtered (stream, "Type @");
1078       gdb_print_host_address (exp->elts[elt].type, stream);
1079       fprintf_filtered (stream, " (");
1080       type_print (exp->elts[elt].type, NULL, stream, 0);
1081       fprintf_filtered (stream, ")");
1082       elt += 2;
1083       break;
1084     case STRUCTOP_STRUCT:
1085     case STRUCTOP_PTR:
1086       {
1087         char *elem_name;
1088         int len;
1089
1090         len = longest_to_int (exp->elts[elt].longconst);
1091         elem_name = &exp->elts[elt + 1].string;
1092
1093         fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name);
1094         elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1));
1095       }
1096       break;
1097     case OP_SCOPE:
1098       {
1099         char *elem_name;
1100         int len;
1101
1102         fprintf_filtered (stream, "Type @");
1103         gdb_print_host_address (exp->elts[elt].type, stream);
1104         fprintf_filtered (stream, " (");
1105         type_print (exp->elts[elt].type, NULL, stream, 0);
1106         fprintf_filtered (stream, ") ");
1107
1108         len = longest_to_int (exp->elts[elt + 1].longconst);
1109         elem_name = &exp->elts[elt + 2].string;
1110
1111         fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name);
1112         elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
1113       }
1114       break;
1115     default:
1116     case OP_NULL:
1117     case MULTI_SUBSCRIPT:
1118     case OP_F77_UNDETERMINED_ARGLIST:
1119     case OP_COMPLEX:
1120     case OP_STRING:
1121     case OP_BITSTRING:
1122     case OP_BOOL:
1123     case OP_M2_STRING:
1124     case OP_THIS:
1125     case OP_LABELED:
1126     case OP_NAME:
1127       fprintf_filtered (stream, "Unknown format");
1128     }
1129
1130   return elt;
1131 }
1132
1133 void
1134 dump_prefix_expression (struct expression *exp, struct ui_file *stream)
1135 {
1136   int elt;
1137
1138   fprintf_filtered (stream, "Dump of expression @ ");
1139   gdb_print_host_address (exp, stream);
1140   fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
1141   if (exp->elts[0].opcode != OP_TYPE)
1142     print_expression (exp, stream);
1143   else
1144     fputs_filtered ("Type printing not yet supported....", stream);
1145   fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
1146                     exp->language_defn->la_name, exp->nelts,
1147                     (long) sizeof (union exp_element));
1148   fputs_filtered ("\n", stream);
1149
1150   for (elt = 0; elt < exp->nelts;)
1151     elt = dump_subexp (exp, stream, elt);
1152   fputs_filtered ("\n", stream);
1153 }