1 /* Support for printing Chill types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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,
19 Boston, MA 02111-1307, USA. */
23 #include "bfd.h" /* Binary File Description */
26 #include "expression.h"
35 #include "typeprint.h"
37 #include "gdb_string.h"
40 static void chill_type_print_base (struct type
*, struct ui_file
*, int, int);
43 chill_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
46 if (varstring
!= NULL
&& *varstring
!= '\0')
48 fputs_filtered (varstring
, stream
);
49 fputs_filtered (" ", stream
);
51 chill_type_print_base (type
, stream
, show
, level
);
54 /* Print the name of the type (or the ultimate pointer target,
55 function value or array element).
57 SHOW nonzero means don't print this type as just its name;
58 show its real definition even if it has a name.
59 SHOW zero means print just typename or tag if there is one
60 SHOW negative means abbreviate structure elements.
61 SHOW is decremented for printing of structure elements.
63 LEVEL is the depth to indent by.
64 We increase it for some recursive calls. */
67 chill_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
72 struct type
*index_type
;
73 struct type
*range_type
;
82 fputs_filtered ("<type unknown>", stream
);
86 /* When SHOW is zero or less, and there is a valid type name, then always
87 just print the type name directly from the type. */
89 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
91 fputs_filtered (TYPE_NAME (type
), stream
);
95 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
98 switch (TYPE_CODE (type
))
100 case TYPE_CODE_TYPEDEF
:
101 chill_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
104 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_VOID
)
106 fprintf_filtered (stream
,
107 TYPE_NAME (type
) ? TYPE_NAME (type
) : "PTR");
110 fprintf_filtered (stream
, "REF ");
111 chill_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
115 /* FIXME: we should probably just print the TYPE_NAME, in case
116 anyone ever fixes the compiler to give us the real names
117 in the presence of the chill equivalent of typedef (assuming
119 fprintf_filtered (stream
,
120 TYPE_NAME (type
) ? TYPE_NAME (type
) : "BOOL");
123 case TYPE_CODE_ARRAY
:
124 fputs_filtered ("ARRAY (", stream
);
125 range_type
= TYPE_FIELD_TYPE (type
, 0);
126 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
127 chill_print_type (range_type
, "", stream
, 0, level
);
130 index_type
= TYPE_TARGET_TYPE (range_type
);
131 low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
132 high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
133 print_type_scalar (index_type
, low_bound
, stream
);
134 fputs_filtered (":", stream
);
135 print_type_scalar (index_type
, high_bound
, stream
);
137 fputs_filtered (") ", stream
);
138 chill_print_type (TYPE_TARGET_TYPE (type
), "", stream
, 0, level
);
141 case TYPE_CODE_BITSTRING
:
142 fprintf_filtered (stream
, "BOOLS (%d)",
143 TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type
, 0), 1) + 1);
147 fputs_filtered ("POWERSET ", stream
);
148 chill_print_type (TYPE_INDEX_TYPE (type
), "", stream
,
152 case TYPE_CODE_STRING
:
153 range_type
= TYPE_FIELD_TYPE (type
, 0);
154 index_type
= TYPE_TARGET_TYPE (range_type
);
155 high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
156 fputs_filtered ("CHARS (", stream
);
157 print_type_scalar (index_type
, high_bound
+ 1, stream
);
158 fputs_filtered (")", stream
);
161 case TYPE_CODE_MEMBER
:
162 fprintf_filtered (stream
, "MEMBER ");
163 chill_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
166 fprintf_filtered (stream
, "/*LOC*/ ");
167 chill_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
170 fprintf_filtered (stream
, "PROC (");
171 len
= TYPE_NFIELDS (type
);
172 for (i
= 0; i
< len
; i
++)
174 struct type
*param_type
= TYPE_FIELD_TYPE (type
, i
);
177 fputs_filtered (", ", stream
);
180 if (TYPE_CODE (param_type
) == TYPE_CODE_REF
)
182 chill_type_print_base (TYPE_TARGET_TYPE (param_type
),
184 fputs_filtered (" LOC", stream
);
187 chill_type_print_base (param_type
, stream
, show
, level
);
189 fprintf_filtered (stream
, ")");
190 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
192 fputs_filtered (" RETURNS (", stream
);
193 chill_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
194 fputs_filtered (")", stream
);
198 case TYPE_CODE_STRUCT
:
199 if (chill_varying_type (type
))
201 chill_type_print_base (TYPE_FIELD_TYPE (type
, 1),
203 fputs_filtered (" VARYING", stream
);
207 fprintf_filtered (stream
, "STRUCT ");
209 fprintf_filtered (stream
, "(\n");
210 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
212 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
214 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
218 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
223 len
= TYPE_NFIELDS (type
);
224 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
226 struct type
*field_type
= TYPE_FIELD_TYPE (type
, i
);
228 print_spaces_filtered (level
+ 4, stream
);
229 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
231 int j
; /* variant number */
232 fputs_filtered ("CASE OF\n", stream
);
233 for (j
= 0; j
< TYPE_NFIELDS (field_type
); j
++)
235 int k
; /* variant field index */
236 struct type
*variant_type
237 = TYPE_FIELD_TYPE (field_type
, j
);
238 int var_len
= TYPE_NFIELDS (variant_type
);
239 print_spaces_filtered (level
+ 4, stream
);
240 if (strcmp (TYPE_FIELD_NAME (field_type
, j
),
242 fputs_filtered ("ELSE\n", stream
);
244 fputs_filtered (":\n", stream
);
245 if (TYPE_CODE (variant_type
) != TYPE_CODE_STRUCT
)
246 error ("variant record confusion");
247 for (k
= 0; k
< var_len
; k
++)
249 print_spaces_filtered (level
+ 8, stream
);
250 chill_print_type (TYPE_FIELD_TYPE (variant_type
, k
),
251 TYPE_FIELD_NAME (variant_type
, k
),
252 stream
, show
- 1, level
+ 8);
253 if (k
< (var_len
- 1))
254 fputs_filtered (",", stream
);
255 fputs_filtered ("\n", stream
);
258 print_spaces_filtered (level
+ 4, stream
);
259 fputs_filtered ("ESAC", stream
);
262 chill_print_type (field_type
,
263 TYPE_FIELD_NAME (type
, i
),
264 stream
, show
- 1, level
+ 4);
267 fputs_filtered (",", stream
);
269 fputs_filtered ("\n", stream
);
272 fprintfi_filtered (level
, stream
, ")");
276 case TYPE_CODE_RANGE
:
278 struct type
*target
= TYPE_TARGET_TYPE (type
);
279 if (target
&& TYPE_NAME (target
))
280 fputs_filtered (TYPE_NAME (target
), stream
);
282 fputs_filtered ("RANGE", stream
);
284 target
= builtin_type_long
;
285 fputs_filtered (" (", stream
);
286 print_type_scalar (target
, TYPE_LOW_BOUND (type
), stream
);
287 fputs_filtered (":", stream
);
288 print_type_scalar (target
, TYPE_HIGH_BOUND (type
), stream
);
289 fputs_filtered (")", stream
);
295 register int lastval
= 0;
296 fprintf_filtered (stream
, "SET (");
297 len
= TYPE_NFIELDS (type
);
298 for (i
= 0; i
< len
; i
++)
302 fprintf_filtered (stream
, ", ");
304 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
305 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
307 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
308 lastval
= TYPE_FIELD_BITPOS (type
, i
);
312 fprintf_filtered (stream
, ")");
317 case TYPE_CODE_UNDEF
:
318 case TYPE_CODE_ERROR
:
319 case TYPE_CODE_UNION
:
320 case TYPE_CODE_METHOD
:
321 error ("missing language support in chill_type_print_base");
326 /* Handle types not explicitly handled by the other cases,
327 such as fundamental types. For these, just print whatever
328 the type name is, as recorded in the type itself. If there
329 is no type name, then complain. */
331 if (TYPE_NAME (type
) != NULL
)
333 fputs_filtered (TYPE_NAME (type
), stream
);
337 error ("Unrecognized type code (%d) in symbol table.",
This page took 0.042864 seconds and 4 git commands to generate.