]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ch-typeprint.c
import gdb-1999-07-07 post reformat
[thirdparty/binutils-gdb.git] / gdb / ch-typeprint.c
CommitLineData
c906108c
SS
1/* Support for printing Chill types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b
JM
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. */
c906108c
SS
20
21#include "defs.h"
22#include "obstack.h"
23#include "bfd.h" /* Binary File Description */
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "value.h"
28#include "gdbcore.h"
29#include "target.h"
30#include "command.h"
31#include "gdbcmd.h"
32#include "language.h"
33#include "demangle.h"
34#include "ch-lang.h"
35#include "typeprint.h"
36
37#include "gdb_string.h"
38#include <errno.h>
39
40static void
41chill_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int));
42
43void
44chill_print_type (type, varstring, stream, show, level)
45 struct type *type;
46 char *varstring;
47 GDB_FILE *stream;
48 int show;
49 int level;
50{
51 if (varstring != NULL && *varstring != '\0')
52 {
53 fputs_filtered (varstring, stream);
54 fputs_filtered (" ", stream);
55 }
56 chill_type_print_base (type, stream, show, level);
57}
58
59/* Print the name of the type (or the ultimate pointer target,
60 function value or array element).
61
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.
67
68 LEVEL is the depth to indent by.
69 We increase it for some recursive calls. */
70
71static void
72chill_type_print_base (type, stream, show, level)
73 struct type *type;
74 GDB_FILE *stream;
75 int show;
76 int level;
77{
78 register int len;
79 register int i;
80 struct type *index_type;
81 struct type *range_type;
82 LONGEST low_bound;
83 LONGEST high_bound;
84
85 QUIT;
86
87 wrap_here (" ");
88 if (type == NULL)
89 {
90 fputs_filtered ("<type unknown>", stream);
91 return;
92 }
93
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. */
96
97 if ((show <= 0) && (TYPE_NAME (type) != NULL))
98 {
99 fputs_filtered (TYPE_NAME (type), stream);
100 return;
101 }
102
103 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
104 CHECK_TYPEDEF (type);
105
106 switch (TYPE_CODE (type))
107 {
c5aa993b
JM
108 case TYPE_CODE_TYPEDEF:
109 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
110 break;
111 case TYPE_CODE_PTR:
112 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
113 {
114 fprintf_filtered (stream,
115 TYPE_NAME (type) ? TYPE_NAME (type) : "PTR");
116 break;
117 }
118 fprintf_filtered (stream, "REF ");
119 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
120 break;
121
122 case TYPE_CODE_BOOL:
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
126 there is one). */
127 fprintf_filtered (stream,
128 TYPE_NAME (type) ? TYPE_NAME (type) : "BOOL");
129 break;
130
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);
136 else
137 {
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);
144 }
145 fputs_filtered (") ", stream);
146 chill_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, level);
147 break;
148
149 case TYPE_CODE_BITSTRING:
150 fprintf_filtered (stream, "BOOLS (%d)",
151 TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type, 0), 1) + 1);
152 break;
153
154 case TYPE_CODE_SET:
155 fputs_filtered ("POWERSET ", stream);
156 chill_print_type (TYPE_INDEX_TYPE (type), "", stream,
157 show - 1, level);
158 break;
159
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);
167 break;
168
169 case TYPE_CODE_MEMBER:
170 fprintf_filtered (stream, "MEMBER ");
171 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
172 break;
173 case TYPE_CODE_REF:
174 fprintf_filtered (stream, "/*LOC*/ ");
175 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
176 break;
177 case TYPE_CODE_FUNC:
178 fprintf_filtered (stream, "PROC (");
179 len = TYPE_NFIELDS (type);
180 for (i = 0; i < len; i++)
181 {
182 struct type *param_type = TYPE_FIELD_TYPE (type, i);
183 if (i > 0)
184 {
185 fputs_filtered (", ", stream);
186 wrap_here (" ");
187 }
188 if (TYPE_CODE (param_type) == TYPE_CODE_REF)
189 {
190 chill_type_print_base (TYPE_TARGET_TYPE (param_type),
191 stream, 0, level);
192 fputs_filtered (" LOC", stream);
193 }
194 else
195 chill_type_print_base (param_type, stream, show, level);
196 }
197 fprintf_filtered (stream, ")");
198 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
199 {
200 fputs_filtered (" RETURNS (", stream);
201 chill_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
202 fputs_filtered (")", stream);
203 }
204 break;
205
206 case TYPE_CODE_STRUCT:
207 if (chill_varying_type (type))
208 {
209 chill_type_print_base (TYPE_FIELD_TYPE (type, 1),
210 stream, 0, level);
211 fputs_filtered (" VARYING", stream);
212 }
213 else
214 {
215 fprintf_filtered (stream, "STRUCT ");
216
217 fprintf_filtered (stream, "(\n");
218 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
219 {
220 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
221 {
222 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
223 }
224 else
225 {
226 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
227 }
228 }
229 else
230 {
231 len = TYPE_NFIELDS (type);
232 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
233 {
234 struct type *field_type = TYPE_FIELD_TYPE (type, i);
235 QUIT;
236 print_spaces_filtered (level + 4, stream);
237 if (TYPE_CODE (field_type) == TYPE_CODE_UNION)
238 {
239 int j; /* variant number */
240 fputs_filtered ("CASE OF\n", stream);
241 for (j = 0; j < TYPE_NFIELDS (field_type); j++)
242 {
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),
249 "else") == 0)
250 fputs_filtered ("ELSE\n", stream);
251 else
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++)
256 {
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);
264 }
265 }
266 print_spaces_filtered (level + 4, stream);
267 fputs_filtered ("ESAC", stream);
268 }
269 else
270 chill_print_type (field_type,
271 TYPE_FIELD_NAME (type, i),
272 stream, show - 1, level + 4);
273 if (i < (len - 1))
274 {
275 fputs_filtered (",", stream);
276 }
277 fputs_filtered ("\n", stream);
278 }
279 }
280 fprintfi_filtered (level, stream, ")");
281 }
282 break;
283
284 case TYPE_CODE_RANGE:
285 {
286 struct type *target = TYPE_TARGET_TYPE (type);
287 if (target && TYPE_NAME (target))
288 fputs_filtered (TYPE_NAME (target), stream);
c906108c 289 else
c5aa993b
JM
290 fputs_filtered ("RANGE", stream);
291 if (target == NULL)
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);
c906108c 297 fputs_filtered (")", stream);
c5aa993b
JM
298 }
299 break;
300
301 case TYPE_CODE_ENUM:
302 {
303 register int lastval = 0;
304 fprintf_filtered (stream, "SET (");
c906108c
SS
305 len = TYPE_NFIELDS (type);
306 for (i = 0; i < len; i++)
307 {
c5aa993b
JM
308 QUIT;
309 if (i)
310 fprintf_filtered (stream, ", ");
311 wrap_here (" ");
312 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
313 if (lastval != TYPE_FIELD_BITPOS (type, i))
c906108c 314 {
c5aa993b
JM
315 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
316 lastval = TYPE_FIELD_BITPOS (type, i);
c906108c 317 }
c5aa993b 318 lastval++;
c906108c
SS
319 }
320 fprintf_filtered (stream, ")");
c5aa993b
JM
321 }
322 break;
c906108c 323
c5aa993b
JM
324 case TYPE_CODE_VOID:
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");
330 break;
c906108c 331
c5aa993b 332 default:
c906108c 333
c5aa993b
JM
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. */
c906108c 338
c5aa993b 339 if (TYPE_NAME (type) != NULL)
c906108c 340 {
c5aa993b 341 fputs_filtered (TYPE_NAME (type), stream);
c906108c 342 }
c5aa993b
JM
343 else
344 {
345 error ("Unrecognized type code (%d) in symbol table.",
346 TYPE_CODE (type));
347 }
348 break;
349 }
c906108c 350}