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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [ch-typeprint.c] - Blame information for rev 1767

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

Line No. Rev Author Line
1 578 markom
/* Support for printing Chill types for GDB, the GNU debugger.
2
   Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 2000
3
   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 "obstack.h"
24
#include "bfd.h"                /* Binary File Description */
25
#include "symtab.h"
26
#include "gdbtypes.h"
27
#include "expression.h"
28
#include "value.h"
29
#include "gdbcore.h"
30
#include "target.h"
31
#include "language.h"
32
#include "ch-lang.h"
33
#include "typeprint.h"
34
 
35
#include "gdb_string.h"
36
#include <errno.h>
37
 
38
static void chill_type_print_base (struct type *, struct ui_file *, int, int);
39
 
40
void
41
chill_print_type (struct type *type, char *varstring, struct ui_file *stream,
42
                  int show, int level)
43
{
44
  if (varstring != NULL && *varstring != '\0')
45
    {
46
      fputs_filtered (varstring, stream);
47
      fputs_filtered (" ", stream);
48
    }
49
  chill_type_print_base (type, stream, show, level);
50
}
51
 
52
/* Print the name of the type (or the ultimate pointer target,
53
   function value or array element).
54
 
55
   SHOW nonzero means don't print this type as just its name;
56
   show its real definition even if it has a name.
57
   SHOW zero means print just typename or tag if there is one
58
   SHOW negative means abbreviate structure elements.
59
   SHOW is decremented for printing of structure elements.
60
 
61
   LEVEL is the depth to indent by.
62
   We increase it for some recursive calls.  */
63
 
64
static void
65
chill_type_print_base (struct type *type, struct ui_file *stream, int show,
66
                       int level)
67
{
68
  register int len;
69
  register int i;
70
  struct type *index_type;
71
  struct type *range_type;
72
  LONGEST low_bound;
73
  LONGEST high_bound;
74
 
75
  QUIT;
76
 
77
  wrap_here ("    ");
78
  if (type == NULL)
79
    {
80
      fputs_filtered ("<type unknown>", stream);
81
      return;
82
    }
83
 
84
  /* When SHOW is zero or less, and there is a valid type name, then always
85
     just print the type name directly from the type. */
86
 
87
  if ((show <= 0) && (TYPE_NAME (type) != NULL))
88
    {
89
      fputs_filtered (TYPE_NAME (type), stream);
90
      return;
91
    }
92
 
93
  if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
94
    CHECK_TYPEDEF (type);
95
 
96
  switch (TYPE_CODE (type))
97
    {
98
    case TYPE_CODE_TYPEDEF:
99
      chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
100
      break;
101
    case TYPE_CODE_PTR:
102
      if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
103
        {
104
          fprintf_filtered (stream,
105
                            TYPE_NAME (type) ? TYPE_NAME (type) : "PTR");
106
          break;
107
        }
108
      fprintf_filtered (stream, "REF ");
109
      chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
110
      break;
111
 
112
    case TYPE_CODE_BOOL:
113
      /* FIXME: we should probably just print the TYPE_NAME, in case
114
         anyone ever fixes the compiler to give us the real names
115
         in the presence of the chill equivalent of typedef (assuming
116
         there is one).  */
117
      fprintf_filtered (stream,
118
                        TYPE_NAME (type) ? TYPE_NAME (type) : "BOOL");
119
      break;
120
 
121
    case TYPE_CODE_ARRAY:
122
      fputs_filtered ("ARRAY (", stream);
123
      range_type = TYPE_FIELD_TYPE (type, 0);
124
      if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
125
        chill_print_type (range_type, "", stream, 0, level);
126
      else
127
        {
128
          index_type = TYPE_TARGET_TYPE (range_type);
129
          low_bound = TYPE_FIELD_BITPOS (range_type, 0);
130
          high_bound = TYPE_FIELD_BITPOS (range_type, 1);
131
          print_type_scalar (index_type, low_bound, stream);
132
          fputs_filtered (":", stream);
133
          print_type_scalar (index_type, high_bound, stream);
134
        }
135
      fputs_filtered (") ", stream);
136
      chill_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, level);
137
      break;
138
 
139
    case TYPE_CODE_BITSTRING:
140
      fprintf_filtered (stream, "BOOLS (%d)",
141
                      TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type, 0), 1) + 1);
142
      break;
143
 
144
    case TYPE_CODE_SET:
145
      fputs_filtered ("POWERSET ", stream);
146
      chill_print_type (TYPE_INDEX_TYPE (type), "", stream,
147
                        show - 1, level);
148
      break;
149
 
150
    case TYPE_CODE_STRING:
151
      range_type = TYPE_FIELD_TYPE (type, 0);
152
      index_type = TYPE_TARGET_TYPE (range_type);
153
      high_bound = TYPE_FIELD_BITPOS (range_type, 1);
154
      fputs_filtered ("CHARS (", stream);
155
      print_type_scalar (index_type, high_bound + 1, stream);
156
      fputs_filtered (")", stream);
157
      break;
158
 
159
    case TYPE_CODE_MEMBER:
160
      fprintf_filtered (stream, "MEMBER ");
161
      chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
162
      break;
163
    case TYPE_CODE_REF:
164
      fprintf_filtered (stream, "/*LOC*/ ");
165
      chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
166
      break;
167
    case TYPE_CODE_FUNC:
168
      fprintf_filtered (stream, "PROC (");
169
      len = TYPE_NFIELDS (type);
170
      for (i = 0; i < len; i++)
171
        {
172
          struct type *param_type = TYPE_FIELD_TYPE (type, i);
173
          if (i > 0)
174
            {
175
              fputs_filtered (", ", stream);
176
              wrap_here ("    ");
177
            }
178
          if (TYPE_CODE (param_type) == TYPE_CODE_REF)
179
            {
180
              chill_type_print_base (TYPE_TARGET_TYPE (param_type),
181
                                     stream, 0, level);
182
              fputs_filtered (" LOC", stream);
183
            }
184
          else
185
            chill_type_print_base (param_type, stream, show, level);
186
        }
187
      fprintf_filtered (stream, ")");
188
      if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
189
        {
190
          fputs_filtered (" RETURNS (", stream);
191
          chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
192
          fputs_filtered (")", stream);
193
        }
194
      break;
195
 
196
    case TYPE_CODE_STRUCT:
197
      if (chill_varying_type (type))
198
        {
199
          chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
200
                                 stream, 0, level);
201
          fputs_filtered (" VARYING", stream);
202
        }
203
      else
204
        {
205
          fprintf_filtered (stream, "STRUCT ");
206
 
207
          fprintf_filtered (stream, "(\n");
208
          if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
209
            {
210
              if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
211
                {
212
                  fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
213
                }
214
              else
215
                {
216
                  fprintfi_filtered (level + 4, stream, "<no data fields>\n");
217
                }
218
            }
219
          else
220
            {
221
              len = TYPE_NFIELDS (type);
222
              for (i = TYPE_N_BASECLASSES (type); i < len; i++)
223
                {
224
                  struct type *field_type = TYPE_FIELD_TYPE (type, i);
225
                  QUIT;
226
                  print_spaces_filtered (level + 4, stream);
227
                  if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
228
                    {
229
                      int j;    /* variant number */
230
                      fputs_filtered ("CASE OF\n", stream);
231
                      for (j = 0; j < TYPE_NFIELDS (field_type); j++)
232
                        {
233
                          int k;        /* variant field index */
234
                          struct type *variant_type
235
                          = TYPE_FIELD_TYPE (field_type, j);
236
                          int var_len = TYPE_NFIELDS (variant_type);
237
                          print_spaces_filtered (level + 4, stream);
238
                          if (strcmp (TYPE_FIELD_NAME (field_type, j),
239
                                      "else") == 0)
240
                            fputs_filtered ("ELSE\n", stream);
241
                          else
242
                            fputs_filtered (":\n", stream);
243
                          if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT)
244
                            error ("variant record confusion");
245
                          for (k = 0; k < var_len; k++)
246
                            {
247
                              print_spaces_filtered (level + 8, stream);
248
                              chill_print_type (TYPE_FIELD_TYPE (variant_type, k),
249
                                          TYPE_FIELD_NAME (variant_type, k),
250
                                                stream, show - 1, level + 8);
251
                              if (k < (var_len - 1))
252
                                fputs_filtered (",", stream);
253
                              fputs_filtered ("\n", stream);
254
                            }
255
                        }
256
                      print_spaces_filtered (level + 4, stream);
257
                      fputs_filtered ("ESAC", stream);
258
                    }
259
                  else
260
                    chill_print_type (field_type,
261
                                      TYPE_FIELD_NAME (type, i),
262
                                      stream, show - 1, level + 4);
263
                  if (i < (len - 1))
264
                    {
265
                      fputs_filtered (",", stream);
266
                    }
267
                  fputs_filtered ("\n", stream);
268
                }
269
            }
270
          fprintfi_filtered (level, stream, ")");
271
        }
272
      break;
273
 
274
    case TYPE_CODE_RANGE:
275
      {
276
        struct type *target = TYPE_TARGET_TYPE (type);
277
        if (target && TYPE_NAME (target))
278
          fputs_filtered (TYPE_NAME (target), stream);
279
        else
280
          fputs_filtered ("RANGE", stream);
281
        if (target == NULL)
282
          target = builtin_type_long;
283
        fputs_filtered (" (", stream);
284
        print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
285
        fputs_filtered (":", stream);
286
        print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
287
        fputs_filtered (")", stream);
288
      }
289
      break;
290
 
291
    case TYPE_CODE_ENUM:
292
      {
293
        register int lastval = 0;
294
        fprintf_filtered (stream, "SET (");
295
        len = TYPE_NFIELDS (type);
296
        for (i = 0; i < len; i++)
297
          {
298
            QUIT;
299
            if (i)
300
              fprintf_filtered (stream, ", ");
301
            wrap_here ("    ");
302
            fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
303
            if (lastval != TYPE_FIELD_BITPOS (type, i))
304
              {
305
                fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
306
                lastval = TYPE_FIELD_BITPOS (type, i);
307
              }
308
            lastval++;
309
          }
310
        fprintf_filtered (stream, ")");
311
      }
312
      break;
313
 
314
    case TYPE_CODE_VOID:
315
    case TYPE_CODE_UNDEF:
316
    case TYPE_CODE_ERROR:
317
    case TYPE_CODE_UNION:
318
    case TYPE_CODE_METHOD:
319
      error ("missing language support in chill_type_print_base");
320
      break;
321
 
322
    default:
323
 
324
      /* Handle types not explicitly handled by the other cases,
325
         such as fundamental types.  For these, just print whatever
326
         the type name is, as recorded in the type itself.  If there
327
         is no type name, then complain. */
328
 
329
      if (TYPE_NAME (type) != NULL)
330
        {
331
          fputs_filtered (TYPE_NAME (type), stream);
332
        }
333
      else
334
        {
335
          error ("Unrecognized type code (%d) in symbol table.",
336
                 TYPE_CODE (type));
337
        }
338
      break;
339
    }
340
}

powered by: WebSVN 2.1.0

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