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., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "bfd.h" /* Binary File Description */
25 #include "expression.h"
34 #include "typeprint.h"
40 chill_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int));
43 chill_print_type (type, varstring, stream, show, level)
50 if (varstring != NULL && *varstring != '\0')
52 fputs_filtered (varstring, stream);
53 fputs_filtered (" ", stream);
55 chill_type_print_base (type, stream, show, level);
58 /* Print the name of the type (or the ultimate pointer target,
59 function value or array element).
61 SHOW nonzero means don't print this type as just its name;
62 show its real definition even if it has a name.
63 SHOW zero means print just typename or tag if there is one
64 SHOW negative means abbreviate structure elements.
65 SHOW is decremented for printing of structure elements.
67 LEVEL is the depth to indent by.
68 We increase it for some recursive calls. */
71 chill_type_print_base (type, stream, show, level)
79 struct type *index_type;
80 struct type *range_type;
89 fputs_filtered ("<type unknown>", stream);
93 /* When SHOW is zero or less, and there is a valid type name, then always
94 just print the type name directly from the type. */
96 if ((show <= 0) && (TYPE_NAME (type) != NULL))
98 fputs_filtered (TYPE_NAME (type), stream);
102 check_stub_type (type);
104 switch (TYPE_CODE (type))
107 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
109 fprintf_filtered (stream, "PTR");
112 fprintf_filtered (stream, "REF ");
113 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
117 /* FIXME: we should probably just print the TYPE_NAME, in case
118 anyone ever fixes the compiler to give us the real names
119 in the presence of the chill equivalent of typedef (assuming
121 fprintf_filtered (stream, "BOOL");
124 case TYPE_CODE_ARRAY:
125 range_type = TYPE_FIELD_TYPE (type, 0);
126 index_type = TYPE_TARGET_TYPE (range_type);
127 low_bound = TYPE_FIELD_BITPOS (range_type, 0);
128 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
129 fputs_filtered ("ARRAY (", stream);
130 print_type_scalar (index_type, low_bound, stream);
131 fputs_filtered (":", stream);
132 print_type_scalar (index_type, high_bound, stream);
133 fputs_filtered (") ", stream);
134 chill_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level);
137 case TYPE_CODE_BITSTRING:
138 fprintf_filtered (stream, "BOOLS (%d)",
139 TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE(type,0), 1) + 1);
143 fputs_filtered ("POWERSET ", stream);
144 chill_print_type (TYPE_INDEX_TYPE (type), "", stream,
148 case TYPE_CODE_STRING:
149 range_type = TYPE_FIELD_TYPE (type, 0);
150 index_type = TYPE_TARGET_TYPE (range_type);
151 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
152 fputs_filtered ("CHARS (", stream);
153 print_type_scalar (index_type, high_bound + 1, stream);
154 fputs_filtered (")", stream);
157 case TYPE_CODE_MEMBER:
158 fprintf_filtered (stream, "MEMBER ");
159 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
162 fprintf_filtered (stream, "/*LOC*/ ");
163 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
166 fprintf_filtered (stream, "PROC (?)");
167 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
170 case TYPE_CODE_STRUCT:
171 if (chill_is_varying_struct (type))
173 chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
174 stream, show, level);
175 fputs_filtered (" VARYING", stream);
179 fprintf_filtered (stream, "STRUCT ");
181 fprintf_filtered (stream, "(\n");
182 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
184 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
186 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
190 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
195 len = TYPE_NFIELDS (type);
196 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
198 struct type *field_type = TYPE_FIELD_TYPE (type, i);
200 print_spaces_filtered (level + 4, stream);
201 if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
202 { int j; /* variant number */
203 fputs_filtered ("CASE OF\n", stream);
204 for (j = 0; j < TYPE_NFIELDS (field_type); j++)
205 { int k; /* variant field index */
206 struct type *variant_type
207 = TYPE_FIELD_TYPE (field_type, j);
208 int var_len = TYPE_NFIELDS (variant_type);
209 print_spaces_filtered (level + 4, stream);
210 if (strcmp (TYPE_FIELD_NAME (field_type, j),
212 fputs_filtered ("ELSE\n", stream);
214 fputs_filtered (":\n", stream);
215 if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT)
216 error ("variant record confusion");
217 for (k = 0; k < var_len; k++)
219 print_spaces_filtered (level + 8, stream);
220 chill_print_type (TYPE_FIELD_TYPE (variant_type, k),
221 TYPE_FIELD_NAME (variant_type, k),
222 stream, show - 1, level + 8);
223 if (k < (var_len - 1))
224 fputs_filtered (",", stream);
225 fputs_filtered ("\n", stream);
228 fputs_filtered ("ESAC\n", stream);
231 chill_print_type (field_type,
232 TYPE_FIELD_NAME (type, i),
233 stream, show - 1, level + 4);
236 fputs_filtered (",", stream);
238 fputs_filtered ("\n", stream);
241 fprintfi_filtered (level, stream, ")");
245 case TYPE_CODE_RANGE:
246 if (TYPE_DUMMY_RANGE (type) > 0)
247 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
250 struct type *target = TYPE_TARGET_TYPE (type);
251 if (target && TYPE_NAME (target))
252 fputs_filtered (TYPE_NAME (target), stream);
254 fputs_filtered ("RANGE", stream);
256 target = builtin_type_long;
257 fputs_filtered (" (", stream);
258 print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
259 fputs_filtered (":", stream);
260 print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
261 fputs_filtered (")", stream);
267 register int lastval = 0;
268 fprintf_filtered (stream, "SET (");
269 len = TYPE_NFIELDS (type);
270 for (i = 0; i < len; i++)
273 if (i) fprintf_filtered (stream, ", ");
275 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
276 if (lastval != TYPE_FIELD_BITPOS (type, i))
278 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
279 lastval = TYPE_FIELD_BITPOS (type, i);
283 fprintf_filtered (stream, ")");
288 case TYPE_CODE_UNDEF:
289 case TYPE_CODE_ERROR:
290 case TYPE_CODE_UNION:
291 case TYPE_CODE_METHOD:
292 error ("missing language support in chill_type_print_base");
297 /* Handle types not explicitly handled by the other cases,
298 such as fundamental types. For these, just print whatever
299 the type name is, as recorded in the type itself. If there
300 is no type name, then complain. */
302 if (TYPE_NAME (type) != NULL)
304 fputs_filtered (TYPE_NAME (type), stream);
308 error ("Unrecognized type code (%d) in symbol table.",