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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [gdb/] [expprint.c] - Blame information for rev 857

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

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

powered by: WebSVN 2.1.0

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