1 /* Support for printing Chill types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 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"
41 chill_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int));
44 chill_print_type (type, varstring, stream, show, level)
51 if (varstring != NULL && *varstring != '\0')
53 fputs_filtered (varstring, stream);
54 fputs_filtered (" ", stream);
56 chill_type_print_base (type, stream, show, level);
59 /* Print the name of the type (or the ultimate pointer target,
60 function value or array element).
62 SHOW nonzero means don't print this type as just its name;
63 show its real definition even if it has a name.
64 SHOW zero means print just typename or tag if there is one
65 SHOW negative means abbreviate structure elements.
66 SHOW is decremented for printing of structure elements.
68 LEVEL is the depth to indent by.
69 We increase it for some recursive calls. */
72 chill_type_print_base (type, stream, show, level)
80 struct type *index_type;
81 struct type *range_type;
90 fputs_filtered ("<type unknown>", stream);
94 /* When SHOW is zero or less, and there is a valid type name, then always
95 just print the type name directly from the type. */
97 if ((show <= 0) && (TYPE_NAME (type) != NULL))
99 fputs_filtered (TYPE_NAME (type), stream);
103 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
104 CHECK_TYPEDEF (type);
106 switch (TYPE_CODE (type))
108 case TYPE_CODE_TYPEDEF:
109 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
112 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
114 fprintf_filtered (stream,
115 TYPE_NAME (type) ? TYPE_NAME (type) : "PTR");
118 fprintf_filtered (stream, "REF ");
119 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
123 /* FIXME: we should probably just print the TYPE_NAME, in case
124 anyone ever fixes the compiler to give us the real names
125 in the presence of the chill equivalent of typedef (assuming
127 fprintf_filtered (stream,
128 TYPE_NAME (type) ? TYPE_NAME (type) : "BOOL");
131 case TYPE_CODE_ARRAY:
132 fputs_filtered ("ARRAY (", stream);
133 range_type = TYPE_FIELD_TYPE (type, 0);
134 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
135 chill_print_type (range_type, "", stream, 0, level);
138 index_type = TYPE_TARGET_TYPE (range_type);
139 low_bound = TYPE_FIELD_BITPOS (range_type, 0);
140 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
141 print_type_scalar (index_type, low_bound, stream);
142 fputs_filtered (":", stream);
143 print_type_scalar (index_type, high_bound, stream);
145 fputs_filtered (") ", stream);
146 chill_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, level);
149 case TYPE_CODE_BITSTRING:
150 fprintf_filtered (stream, "BOOLS (%d)",
151 TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type, 0), 1) + 1);
155 fputs_filtered ("POWERSET ", stream);
156 chill_print_type (TYPE_INDEX_TYPE (type), "", stream,
160 case TYPE_CODE_STRING:
161 range_type = TYPE_FIELD_TYPE (type, 0);
162 index_type = TYPE_TARGET_TYPE (range_type);
163 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
164 fputs_filtered ("CHARS (", stream);
165 print_type_scalar (index_type, high_bound + 1, stream);
166 fputs_filtered (")", stream);
169 case TYPE_CODE_MEMBER:
170 fprintf_filtered (stream, "MEMBER ");
171 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
174 fprintf_filtered (stream, "/*LOC*/ ");
175 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
178 fprintf_filtered (stream, "PROC (");
179 len = TYPE_NFIELDS (type);
180 for (i = 0; i < len; i++)
182 struct type *param_type = TYPE_FIELD_TYPE (type, i);
185 fputs_filtered (", ", stream);
188 if (TYPE_CODE (param_type) == TYPE_CODE_REF)
190 chill_type_print_base (TYPE_TARGET_TYPE (param_type),
192 fputs_filtered (" LOC", stream);
195 chill_type_print_base (param_type, stream, show, level);
197 fprintf_filtered (stream, ")");
198 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
200 fputs_filtered (" RETURNS (", stream);
201 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
202 fputs_filtered (")", stream);
206 case TYPE_CODE_STRUCT:
207 if (chill_varying_type (type))
209 chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
211 fputs_filtered (" VARYING", stream);
215 fprintf_filtered (stream, "STRUCT ");
217 fprintf_filtered (stream, "(\n");
218 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
220 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
222 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
226 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
231 len = TYPE_NFIELDS (type);
232 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
234 struct type *field_type = TYPE_FIELD_TYPE (type, i);
236 print_spaces_filtered (level + 4, stream);
237 if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
239 int j; /* variant number */
240 fputs_filtered ("CASE OF\n", stream);
241 for (j = 0; j < TYPE_NFIELDS (field_type); j++)
243 int k; /* variant field index */
244 struct type *variant_type
245 = TYPE_FIELD_TYPE (field_type, j);
246 int var_len = TYPE_NFIELDS (variant_type);
247 print_spaces_filtered (level + 4, stream);
248 if (strcmp (TYPE_FIELD_NAME (field_type, j),
250 fputs_filtered ("ELSE\n", stream);
252 fputs_filtered (":\n", stream);
253 if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT)
254 error ("variant record confusion");
255 for (k = 0; k < var_len; k++)
257 print_spaces_filtered (level + 8, stream);
258 chill_print_type (TYPE_FIELD_TYPE (variant_type, k),
259 TYPE_FIELD_NAME (variant_type, k),
260 stream, show - 1, level + 8);
261 if (k < (var_len - 1))
262 fputs_filtered (",", stream);
263 fputs_filtered ("\n", stream);
266 print_spaces_filtered (level + 4, stream);
267 fputs_filtered ("ESAC", stream);
270 chill_print_type (field_type,
271 TYPE_FIELD_NAME (type, i),
272 stream, show - 1, level + 4);
275 fputs_filtered (",", stream);
277 fputs_filtered ("\n", stream);
280 fprintfi_filtered (level, stream, ")");
284 case TYPE_CODE_RANGE:
286 struct type *target = TYPE_TARGET_TYPE (type);
287 if (target && TYPE_NAME (target))
288 fputs_filtered (TYPE_NAME (target), stream);
290 fputs_filtered ("RANGE", stream);
292 target = builtin_type_long;
293 fputs_filtered (" (", stream);
294 print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
295 fputs_filtered (":", stream);
296 print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
297 fputs_filtered (")", stream);
303 register int lastval = 0;
304 fprintf_filtered (stream, "SET (");
305 len = TYPE_NFIELDS (type);
306 for (i = 0; i < len; i++)
310 fprintf_filtered (stream, ", ");
312 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
313 if (lastval != TYPE_FIELD_BITPOS (type, i))
315 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
316 lastval = TYPE_FIELD_BITPOS (type, i);
320 fprintf_filtered (stream, ")");
325 case TYPE_CODE_UNDEF:
326 case TYPE_CODE_ERROR:
327 case TYPE_CODE_UNION:
328 case TYPE_CODE_METHOD:
329 error ("missing language support in chill_type_print_base");
334 /* Handle types not explicitly handled by the other cases,
335 such as fundamental types. For these, just print whatever
336 the type name is, as recorded in the type itself. If there
337 is no type name, then complain. */
339 if (TYPE_NAME (type) != NULL)
341 fputs_filtered (TYPE_NAME (type), stream);
345 error ("Unrecognized type code (%d) in symbol table.",