]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ch-typeprint.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / ch-typeprint.c
CommitLineData
a8a69e63
FF
1/* Support for printing Chill types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
6c9638b4 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
a8a69e63
FF
19
20#include "defs.h"
21#include "obstack.h"
22#include "bfd.h" /* Binary File Description */
23#include "symtab.h"
24#include "gdbtypes.h"
25#include "expression.h"
26#include "value.h"
27#include "gdbcore.h"
28#include "target.h"
29#include "command.h"
30#include "gdbcmd.h"
31#include "language.h"
32#include "demangle.h"
33#include "ch-lang.h"
100f92e2 34#include "typeprint.h"
a8a69e63 35
2b576293 36#include "gdb_string.h"
a8a69e63
FF
37#include <errno.h>
38
8fbdca53 39static void
199b2450 40chill_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int));
a8a69e63
FF
41
42void
43chill_print_type (type, varstring, stream, show, level)
44 struct type *type;
45 char *varstring;
199b2450 46 GDB_FILE *stream;
a8a69e63
FF
47 int show;
48 int level;
49{
a8a69e63
FF
50 if (varstring != NULL && *varstring != '\0')
51 {
52 fputs_filtered (varstring, stream);
53 fputs_filtered (" ", stream);
54 }
8a177da6 55 chill_type_print_base (type, stream, show, level);
a8a69e63
FF
56}
57
58/* Print the name of the type (or the ultimate pointer target,
59 function value or array element).
60
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.
66
67 LEVEL is the depth to indent by.
68 We increase it for some recursive calls. */
69
8fbdca53
FF
70static void
71chill_type_print_base (type, stream, show, level)
a8a69e63 72 struct type *type;
199b2450 73 GDB_FILE *stream;
a8a69e63
FF
74 int show;
75 int level;
76{
8fbdca53
FF
77 register int len;
78 register int i;
8a177da6
PB
79 struct type *index_type;
80 struct type *range_type;
81 LONGEST low_bound;
82 LONGEST high_bound;
8fbdca53 83
a8a69e63
FF
84 QUIT;
85
86 wrap_here (" ");
87 if (type == NULL)
88 {
89 fputs_filtered ("<type unknown>", stream);
90 return;
91 }
92
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. */
95
96 if ((show <= 0) && (TYPE_NAME (type) != NULL))
97 {
98 fputs_filtered (TYPE_NAME (type), stream);
99 return;
100 }
101
d1f4065e
PB
102 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
103 CHECK_TYPEDEF (type);
dda398c3 104
a8a69e63
FF
105 switch (TYPE_CODE (type))
106 {
d1f4065e
PB
107 case TYPE_CODE_TYPEDEF:
108 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
109 break;
a8a69e63 110 case TYPE_CODE_PTR:
8a177da6
PB
111 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
112 {
3bcf4181
PB
113 fprintf_filtered (stream,
114 TYPE_NAME (type) ? TYPE_NAME (type) : "PTR");
8a177da6
PB
115 break;
116 }
117 fprintf_filtered (stream, "REF ");
d1f4065e 118 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
8a177da6
PB
119 break;
120
11b959da 121 case TYPE_CODE_BOOL:
61932a8e
JK
122 /* FIXME: we should probably just print the TYPE_NAME, in case
123 anyone ever fixes the compiler to give us the real names
124 in the presence of the chill equivalent of typedef (assuming
125 there is one). */
3bcf4181
PB
126 fprintf_filtered (stream,
127 TYPE_NAME (type) ? TYPE_NAME (type) : "BOOL");
11b959da
FF
128 break;
129
8a177da6 130 case TYPE_CODE_ARRAY:
8a177da6 131 fputs_filtered ("ARRAY (", stream);
d1f4065e
PB
132 range_type = TYPE_FIELD_TYPE (type, 0);
133 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
134 chill_print_type (range_type, "", stream, 0, level);
135 else
136 {
137 index_type = TYPE_TARGET_TYPE (range_type);
138 low_bound = TYPE_FIELD_BITPOS (range_type, 0);
139 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
140 print_type_scalar (index_type, low_bound, stream);
141 fputs_filtered (":", stream);
142 print_type_scalar (index_type, high_bound, stream);
143 }
8a177da6 144 fputs_filtered (") ", stream);
d1f4065e 145 chill_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, level);
8a177da6
PB
146 break;
147
cba00921
PB
148 case TYPE_CODE_BITSTRING:
149 fprintf_filtered (stream, "BOOLS (%d)",
150 TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE(type,0), 1) + 1);
151 break;
152
e909f287
PB
153 case TYPE_CODE_SET:
154 fputs_filtered ("POWERSET ", stream);
6f52d064 155 chill_print_type (TYPE_INDEX_TYPE (type), "", stream,
cba00921 156 show - 1, level);
e909f287
PB
157 break;
158
8a177da6
PB
159 case TYPE_CODE_STRING:
160 range_type = TYPE_FIELD_TYPE (type, 0);
161 index_type = TYPE_TARGET_TYPE (range_type);
162 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
cba00921 163 fputs_filtered ("CHARS (", stream);
8a177da6
PB
164 print_type_scalar (index_type, high_bound + 1, stream);
165 fputs_filtered (")", stream);
166 break;
167
a8a69e63 168 case TYPE_CODE_MEMBER:
8a177da6 169 fprintf_filtered (stream, "MEMBER ");
d1f4065e 170 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
8a177da6 171 break;
a8a69e63 172 case TYPE_CODE_REF:
8a177da6
PB
173 fprintf_filtered (stream, "/*LOC*/ ");
174 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
175 break;
a8a69e63 176 case TYPE_CODE_FUNC:
27202b6a
PB
177 fprintf_filtered (stream, "PROC (");
178 len = TYPE_NFIELDS (type);
179 for (i = 0; i < len; i++)
180 {
181 struct type *param_type = TYPE_FIELD_TYPE (type, i);
182 if (i > 0)
183 {
184 fputs_filtered (", ", stream);
185 wrap_here (" ");
186 }
187 if (TYPE_CODE (param_type) == TYPE_CODE_REF)
188 {
189 chill_type_print_base (TYPE_TARGET_TYPE (param_type),
d1f4065e 190 stream, 0, level);
27202b6a
PB
191 fputs_filtered (" LOC", stream);
192 }
193 else
194 chill_type_print_base (param_type, stream, show, level);
195 }
196 fprintf_filtered (stream, ")");
6d34c236
PB
197 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
198 {
199 fputs_filtered (" RETURNS (", stream);
d1f4065e 200 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
6d34c236
PB
201 fputs_filtered (")", stream);
202 }
8fbdca53
FF
203 break;
204
205 case TYPE_CODE_STRUCT:
6073b8de 206 if (chill_varying_type (type))
8fbdca53 207 {
cba00921 208 chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
d1f4065e 209 stream, 0, level);
cba00921 210 fputs_filtered (" VARYING", stream);
8fbdca53
FF
211 }
212 else
213 {
cba00921
PB
214 fprintf_filtered (stream, "STRUCT ");
215
8fbdca53
FF
216 fprintf_filtered (stream, "(\n");
217 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
218 {
219 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
220 {
221 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
222 }
223 else
224 {
225 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
226 }
227 }
228 else
229 {
230 len = TYPE_NFIELDS (type);
231 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
232 {
11b959da 233 struct type *field_type = TYPE_FIELD_TYPE (type, i);
8fbdca53
FF
234 QUIT;
235 print_spaces_filtered (level + 4, stream);
11b959da
FF
236 if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
237 { int j; /* variant number */
238 fputs_filtered ("CASE OF\n", stream);
239 for (j = 0; j < TYPE_NFIELDS (field_type); j++)
240 { int k; /* variant field index */
241 struct type *variant_type
242 = TYPE_FIELD_TYPE (field_type, j);
243 int var_len = TYPE_NFIELDS (variant_type);
244 print_spaces_filtered (level + 4, stream);
245 if (strcmp (TYPE_FIELD_NAME (field_type, j),
246 "else") == 0)
247 fputs_filtered ("ELSE\n", stream);
248 else
249 fputs_filtered (":\n", stream);
250 if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT)
251 error ("variant record confusion");
252 for (k = 0; k < var_len; k++)
253 {
254 print_spaces_filtered (level + 8, stream);
255 chill_print_type (TYPE_FIELD_TYPE (variant_type, k),
256 TYPE_FIELD_NAME (variant_type, k),
257 stream, show - 1, level + 8);
258 if (k < (var_len - 1))
259 fputs_filtered (",", stream);
260 fputs_filtered ("\n", stream);
261 }
262 }
8104c47b
WM
263 print_spaces_filtered (level + 4, stream);
264 fputs_filtered ("ESAC", stream);
11b959da
FF
265 }
266 else
267 chill_print_type (field_type,
268 TYPE_FIELD_NAME (type, i),
269 stream, show - 1, level + 4);
8fbdca53
FF
270 if (i < (len - 1))
271 {
272 fputs_filtered (",", stream);
273 }
274 fputs_filtered ("\n", stream);
275 }
276 }
277 fprintfi_filtered (level, stream, ")");
278 }
a8a69e63
FF
279 break;
280
11b959da 281 case TYPE_CODE_RANGE:
11b959da 282 {
42fca93e
PB
283 struct type *target = TYPE_TARGET_TYPE (type);
284 if (target && TYPE_NAME (target))
285 fputs_filtered (TYPE_NAME (target), stream);
286 else
287 fputs_filtered ("RANGE", stream);
288 if (target == NULL)
289 target = builtin_type_long;
11b959da 290 fputs_filtered (" (", stream);
42fca93e 291 print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
11b959da 292 fputs_filtered (":", stream);
42fca93e 293 print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
11b959da
FF
294 fputs_filtered (")", stream);
295 }
11b959da
FF
296 break;
297
cba00921
PB
298 case TYPE_CODE_ENUM:
299 {
300 register int lastval = 0;
301 fprintf_filtered (stream, "SET (");
302 len = TYPE_NFIELDS (type);
303 for (i = 0; i < len; i++)
304 {
305 QUIT;
306 if (i) fprintf_filtered (stream, ", ");
307 wrap_here (" ");
308 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
309 if (lastval != TYPE_FIELD_BITPOS (type, i))
310 {
311 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
312 lastval = TYPE_FIELD_BITPOS (type, i);
313 }
314 lastval++;
315 }
316 fprintf_filtered (stream, ")");
317 }
318 break;
319
a8a69e63
FF
320 case TYPE_CODE_VOID:
321 case TYPE_CODE_UNDEF:
322 case TYPE_CODE_ERROR:
a8a69e63 323 case TYPE_CODE_UNION:
a8a69e63 324 case TYPE_CODE_METHOD:
8fbdca53 325 error ("missing language support in chill_type_print_base");
a8a69e63
FF
326 break;
327
328 default:
329
330 /* Handle types not explicitly handled by the other cases,
331 such as fundamental types. For these, just print whatever
332 the type name is, as recorded in the type itself. If there
333 is no type name, then complain. */
334
335 if (TYPE_NAME (type) != NULL)
336 {
337 fputs_filtered (TYPE_NAME (type), stream);
338 }
339 else
340 {
341 error ("Unrecognized type code (%d) in symbol table.",
342 TYPE_CODE (type));
343 }
344 break;
345 }
346}