* gdb.base/langs.exp, gdb.base/langs*: New test.
[deliverable/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
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
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
FF
35
36#include <string.h>
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
dda398c3
JK
102 check_stub_type (type);
103
a8a69e63
FF
104 switch (TYPE_CODE (type))
105 {
a8a69e63 106 case TYPE_CODE_PTR:
8a177da6
PB
107 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
108 {
3bcf4181
PB
109 fprintf_filtered (stream,
110 TYPE_NAME (type) ? TYPE_NAME (type) : "PTR");
8a177da6
PB
111 break;
112 }
113 fprintf_filtered (stream, "REF ");
114 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
115 break;
116
11b959da 117 case TYPE_CODE_BOOL:
61932a8e
JK
118 /* FIXME: we should probably just print the TYPE_NAME, in case
119 anyone ever fixes the compiler to give us the real names
120 in the presence of the chill equivalent of typedef (assuming
121 there is one). */
3bcf4181
PB
122 fprintf_filtered (stream,
123 TYPE_NAME (type) ? TYPE_NAME (type) : "BOOL");
11b959da
FF
124 break;
125
8a177da6
PB
126 case TYPE_CODE_ARRAY:
127 range_type = TYPE_FIELD_TYPE (type, 0);
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 fputs_filtered ("ARRAY (", stream);
132 print_type_scalar (index_type, low_bound, stream);
133 fputs_filtered (":", stream);
134 print_type_scalar (index_type, high_bound, stream);
135 fputs_filtered (") ", stream);
136 chill_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level);
137 break;
138
cba00921
PB
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
e909f287
PB
144 case TYPE_CODE_SET:
145 fputs_filtered ("POWERSET ", stream);
6f52d064 146 chill_print_type (TYPE_INDEX_TYPE (type), "", stream,
cba00921 147 show - 1, level);
e909f287
PB
148 break;
149
8a177da6
PB
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);
cba00921 154 fputs_filtered ("CHARS (", stream);
8a177da6
PB
155 print_type_scalar (index_type, high_bound + 1, stream);
156 fputs_filtered (")", stream);
157 break;
158
a8a69e63 159 case TYPE_CODE_MEMBER:
8a177da6
PB
160 fprintf_filtered (stream, "MEMBER ");
161 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
162 break;
a8a69e63 163 case TYPE_CODE_REF:
8a177da6
PB
164 fprintf_filtered (stream, "/*LOC*/ ");
165 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
166 break;
a8a69e63 167 case TYPE_CODE_FUNC:
8a177da6 168 fprintf_filtered (stream, "PROC (?)");
6d34c236
PB
169 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
170 {
171 fputs_filtered (" RETURNS (", stream);
172 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
173 fputs_filtered (")", stream);
174 }
8fbdca53
FF
175 break;
176
177 case TYPE_CODE_STRUCT:
6073b8de 178 if (chill_varying_type (type))
8fbdca53 179 {
cba00921
PB
180 chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
181 stream, show, level);
182 fputs_filtered (" VARYING", stream);
8fbdca53
FF
183 }
184 else
185 {
cba00921
PB
186 fprintf_filtered (stream, "STRUCT ");
187
8fbdca53
FF
188 fprintf_filtered (stream, "(\n");
189 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
190 {
191 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
192 {
193 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
194 }
195 else
196 {
197 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
198 }
199 }
200 else
201 {
202 len = TYPE_NFIELDS (type);
203 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
204 {
11b959da 205 struct type *field_type = TYPE_FIELD_TYPE (type, i);
8fbdca53
FF
206 QUIT;
207 print_spaces_filtered (level + 4, stream);
11b959da
FF
208 if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
209 { int j; /* variant number */
210 fputs_filtered ("CASE OF\n", stream);
211 for (j = 0; j < TYPE_NFIELDS (field_type); j++)
212 { int k; /* variant field index */
213 struct type *variant_type
214 = TYPE_FIELD_TYPE (field_type, j);
215 int var_len = TYPE_NFIELDS (variant_type);
216 print_spaces_filtered (level + 4, stream);
217 if (strcmp (TYPE_FIELD_NAME (field_type, j),
218 "else") == 0)
219 fputs_filtered ("ELSE\n", stream);
220 else
221 fputs_filtered (":\n", stream);
222 if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT)
223 error ("variant record confusion");
224 for (k = 0; k < var_len; k++)
225 {
226 print_spaces_filtered (level + 8, stream);
227 chill_print_type (TYPE_FIELD_TYPE (variant_type, k),
228 TYPE_FIELD_NAME (variant_type, k),
229 stream, show - 1, level + 8);
230 if (k < (var_len - 1))
231 fputs_filtered (",", stream);
232 fputs_filtered ("\n", stream);
233 }
234 }
235 fputs_filtered ("ESAC\n", stream);
236 }
237 else
238 chill_print_type (field_type,
239 TYPE_FIELD_NAME (type, i),
240 stream, show - 1, level + 4);
8fbdca53
FF
241 if (i < (len - 1))
242 {
243 fputs_filtered (",", stream);
244 }
245 fputs_filtered ("\n", stream);
246 }
247 }
248 fprintfi_filtered (level, stream, ")");
249 }
a8a69e63
FF
250 break;
251
11b959da 252 case TYPE_CODE_RANGE:
42fca93e
PB
253 if (TYPE_DUMMY_RANGE (type) > 0)
254 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
255 else
11b959da 256 {
42fca93e
PB
257 struct type *target = TYPE_TARGET_TYPE (type);
258 if (target && TYPE_NAME (target))
259 fputs_filtered (TYPE_NAME (target), stream);
260 else
261 fputs_filtered ("RANGE", stream);
262 if (target == NULL)
263 target = builtin_type_long;
11b959da 264 fputs_filtered (" (", stream);
42fca93e 265 print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
11b959da 266 fputs_filtered (":", stream);
42fca93e 267 print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
11b959da
FF
268 fputs_filtered (")", stream);
269 }
11b959da
FF
270 break;
271
cba00921
PB
272 case TYPE_CODE_ENUM:
273 {
274 register int lastval = 0;
275 fprintf_filtered (stream, "SET (");
276 len = TYPE_NFIELDS (type);
277 for (i = 0; i < len; i++)
278 {
279 QUIT;
280 if (i) fprintf_filtered (stream, ", ");
281 wrap_here (" ");
282 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
283 if (lastval != TYPE_FIELD_BITPOS (type, i))
284 {
285 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
286 lastval = TYPE_FIELD_BITPOS (type, i);
287 }
288 lastval++;
289 }
290 fprintf_filtered (stream, ")");
291 }
292 break;
293
a8a69e63
FF
294 case TYPE_CODE_VOID:
295 case TYPE_CODE_UNDEF:
296 case TYPE_CODE_ERROR:
a8a69e63 297 case TYPE_CODE_UNION:
a8a69e63 298 case TYPE_CODE_METHOD:
8fbdca53 299 error ("missing language support in chill_type_print_base");
a8a69e63
FF
300 break;
301
302 default:
303
304 /* Handle types not explicitly handled by the other cases,
305 such as fundamental types. For these, just print whatever
306 the type name is, as recorded in the type itself. If there
307 is no type name, then complain. */
308
309 if (TYPE_NAME (type) != NULL)
310 {
311 fputs_filtered (TYPE_NAME (type), stream);
312 }
313 else
314 {
315 error ("Unrecognized type code (%d) in symbol table.",
316 TYPE_CODE (type));
317 }
318 break;
319 }
320}
This page took 0.130535 seconds and 4 git commands to generate.