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