OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [VER_5_3/] [gdb-5.3/] [gdb/] [expprint.c] - Blame information for rev 1766

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.