* c-typeprint.c (c_print_type): Assume demangled arguments
[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 {
109 fprintf_filtered (stream, "PTR");
110 break;
111 }
112 fprintf_filtered (stream, "REF ");
113 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
114 break;
115
11b959da 116 case TYPE_CODE_BOOL:
61932a8e
JK
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
120 there is one). */
11b959da
FF
121 fprintf_filtered (stream, "BOOL");
122 break;
123
8a177da6
PB
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);
135 break;
136
cba00921
PB
137 case TYPE_CODE_BITSTRING:
138 fprintf_filtered (stream, "BOOLS (%d)",
139 TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE(type,0), 1) + 1);
140 break;
141
e909f287
PB
142 case TYPE_CODE_SET:
143 fputs_filtered ("POWERSET ", stream);
cba00921
PB
144 chill_print_type (TYPE_FIELD_TYPE (type, 0), "", stream,
145 show - 1, level);
e909f287
PB
146 break;
147
8a177da6
PB
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);
cba00921 152 fputs_filtered ("CHARS (", stream);
8a177da6
PB
153 print_type_scalar (index_type, high_bound + 1, stream);
154 fputs_filtered (")", stream);
155 break;
156
a8a69e63 157 case TYPE_CODE_MEMBER:
8a177da6
PB
158 fprintf_filtered (stream, "MEMBER ");
159 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
160 break;
a8a69e63 161 case TYPE_CODE_REF:
8a177da6
PB
162 fprintf_filtered (stream, "/*LOC*/ ");
163 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
164 break;
a8a69e63 165 case TYPE_CODE_FUNC:
8a177da6 166 fprintf_filtered (stream, "PROC (?)");
8fbdca53
FF
167 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
168 break;
169
170 case TYPE_CODE_STRUCT:
cba00921 171 if (chill_is_varying_struct (type))
8fbdca53 172 {
cba00921
PB
173 chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
174 stream, show, level);
175 fputs_filtered (" VARYING", stream);
8fbdca53
FF
176 }
177 else
178 {
cba00921
PB
179 fprintf_filtered (stream, "STRUCT ");
180
8fbdca53
FF
181 fprintf_filtered (stream, "(\n");
182 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
183 {
184 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
185 {
186 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
187 }
188 else
189 {
190 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
191 }
192 }
193 else
194 {
195 len = TYPE_NFIELDS (type);
196 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
197 {
11b959da 198 struct type *field_type = TYPE_FIELD_TYPE (type, i);
8fbdca53
FF
199 QUIT;
200 print_spaces_filtered (level + 4, stream);
11b959da
FF
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),
211 "else") == 0)
212 fputs_filtered ("ELSE\n", stream);
213 else
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++)
218 {
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);
226 }
227 }
228 fputs_filtered ("ESAC\n", stream);
229 }
230 else
231 chill_print_type (field_type,
232 TYPE_FIELD_NAME (type, i),
233 stream, show - 1, level + 4);
8fbdca53
FF
234 if (i < (len - 1))
235 {
236 fputs_filtered (",", stream);
237 }
238 fputs_filtered ("\n", stream);
239 }
240 }
241 fprintfi_filtered (level, stream, ")");
242 }
a8a69e63
FF
243 break;
244
11b959da 245 case TYPE_CODE_RANGE:
cba00921
PB
246 if (TYPE_DUMMY_RANGE (type))
247 chill_type_print_base (TYPE_TARGET_TYPE (type),
248 stream, show, level);
249 else if (TYPE_TARGET_TYPE (type))
11b959da
FF
250 {
251 chill_type_print_base (TYPE_TARGET_TYPE (type),
252 stream, show, level);
253 fputs_filtered (" (", stream);
254 print_type_scalar (TYPE_TARGET_TYPE (type),
255 TYPE_FIELD_BITPOS (type, 0), stream);
256 fputs_filtered (":", stream);
257 print_type_scalar (TYPE_TARGET_TYPE (type),
258 TYPE_FIELD_BITPOS (type, 1), stream);
259 fputs_filtered (")", stream);
260 }
261 else
262 fprintf_filtered (stream, "RANGE? (%s : %d)",
263 TYPE_FIELD_BITPOS (type, 0),
264 TYPE_FIELD_BITPOS (type, 1));
265 break;
266
cba00921
PB
267 case TYPE_CODE_ENUM:
268 {
269 register int lastval = 0;
270 fprintf_filtered (stream, "SET (");
271 len = TYPE_NFIELDS (type);
272 for (i = 0; i < len; i++)
273 {
274 QUIT;
275 if (i) fprintf_filtered (stream, ", ");
276 wrap_here (" ");
277 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
278 if (lastval != TYPE_FIELD_BITPOS (type, i))
279 {
280 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
281 lastval = TYPE_FIELD_BITPOS (type, i);
282 }
283 lastval++;
284 }
285 fprintf_filtered (stream, ")");
286 }
287 break;
288
a8a69e63
FF
289 case TYPE_CODE_VOID:
290 case TYPE_CODE_UNDEF:
291 case TYPE_CODE_ERROR:
a8a69e63 292 case TYPE_CODE_UNION:
a8a69e63 293 case TYPE_CODE_METHOD:
8fbdca53 294 error ("missing language support in chill_type_print_base");
a8a69e63
FF
295 break;
296
297 default:
298
299 /* Handle types not explicitly handled by the other cases,
300 such as fundamental types. For these, just print whatever
301 the type name is, as recorded in the type itself. If there
302 is no type name, then complain. */
303
304 if (TYPE_NAME (type) != NULL)
305 {
306 fputs_filtered (TYPE_NAME (type), stream);
307 }
308 else
309 {
310 error ("Unrecognized type code (%d) in symbol table.",
311 TYPE_CODE (type));
312 }
313 break;
314 }
315}
This page took 0.137564 seconds and 4 git commands to generate.