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