Commit | Line | Data |
---|---|---|
a8a69e63 FF |
1 | /* Support for printing Chill types for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
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 | 39 | static void |
199b2450 | 40 | chill_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int)); |
a8a69e63 FF |
41 | |
42 | void | |
43 | chill_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 |
70 | static void |
71 | chill_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 | char *name; |
78 | register int len; | |
79 | register int i; | |
8a177da6 PB |
80 | struct type *index_type; |
81 | struct type *range_type; | |
82 | LONGEST low_bound; | |
83 | LONGEST high_bound; | |
8fbdca53 | 84 | |
a8a69e63 FF |
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 | ||
dda398c3 JK |
103 | check_stub_type (type); |
104 | ||
a8a69e63 FF |
105 | switch (TYPE_CODE (type)) |
106 | { | |
a8a69e63 | 107 | case TYPE_CODE_PTR: |
8a177da6 PB |
108 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID) |
109 | { | |
110 | fprintf_filtered (stream, "PTR"); | |
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). */ | |
11b959da FF |
122 | fprintf_filtered (stream, "BOOL"); |
123 | break; | |
124 | ||
8a177da6 PB |
125 | case TYPE_CODE_ARRAY: |
126 | range_type = TYPE_FIELD_TYPE (type, 0); | |
127 | index_type = TYPE_TARGET_TYPE (range_type); | |
128 | low_bound = TYPE_FIELD_BITPOS (range_type, 0); | |
129 | high_bound = TYPE_FIELD_BITPOS (range_type, 1); | |
130 | fputs_filtered ("ARRAY (", stream); | |
131 | print_type_scalar (index_type, low_bound, stream); | |
132 | fputs_filtered (":", stream); | |
133 | print_type_scalar (index_type, high_bound, stream); | |
134 | fputs_filtered (") ", stream); | |
135 | chill_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level); | |
136 | break; | |
137 | ||
cba00921 PB |
138 | case TYPE_CODE_BITSTRING: |
139 | fprintf_filtered (stream, "BOOLS (%d)", | |
140 | TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE(type,0), 1) + 1); | |
141 | break; | |
142 | ||
e909f287 PB |
143 | case TYPE_CODE_SET: |
144 | fputs_filtered ("POWERSET ", stream); | |
cba00921 PB |
145 | chill_print_type (TYPE_FIELD_TYPE (type, 0), "", stream, |
146 | show - 1, level); | |
e909f287 PB |
147 | break; |
148 | ||
8a177da6 PB |
149 | case TYPE_CODE_STRING: |
150 | range_type = TYPE_FIELD_TYPE (type, 0); | |
151 | index_type = TYPE_TARGET_TYPE (range_type); | |
152 | high_bound = TYPE_FIELD_BITPOS (range_type, 1); | |
cba00921 | 153 | fputs_filtered ("CHARS (", stream); |
8a177da6 PB |
154 | print_type_scalar (index_type, high_bound + 1, stream); |
155 | fputs_filtered (")", stream); | |
156 | break; | |
157 | ||
a8a69e63 | 158 | case TYPE_CODE_MEMBER: |
8a177da6 PB |
159 | fprintf_filtered (stream, "MEMBER "); |
160 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
161 | break; | |
a8a69e63 | 162 | case TYPE_CODE_REF: |
8a177da6 PB |
163 | fprintf_filtered (stream, "/*LOC*/ "); |
164 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
165 | break; | |
a8a69e63 | 166 | case TYPE_CODE_FUNC: |
8a177da6 | 167 | fprintf_filtered (stream, "PROC (?)"); |
8fbdca53 FF |
168 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); |
169 | break; | |
170 | ||
171 | case TYPE_CODE_STRUCT: | |
cba00921 | 172 | if (chill_is_varying_struct (type)) |
8fbdca53 | 173 | { |
cba00921 PB |
174 | chill_type_print_base (TYPE_FIELD_TYPE (type, 1), |
175 | stream, show, level); | |
176 | fputs_filtered (" VARYING", stream); | |
8fbdca53 FF |
177 | } |
178 | else | |
179 | { | |
cba00921 PB |
180 | fprintf_filtered (stream, "STRUCT "); |
181 | ||
8fbdca53 FF |
182 | fprintf_filtered (stream, "(\n"); |
183 | if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) | |
184 | { | |
185 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
186 | { | |
187 | fprintfi_filtered (level + 4, stream, "<incomplete type>\n"); | |
188 | } | |
189 | else | |
190 | { | |
191 | fprintfi_filtered (level + 4, stream, "<no data fields>\n"); | |
192 | } | |
193 | } | |
194 | else | |
195 | { | |
196 | len = TYPE_NFIELDS (type); | |
197 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
198 | { | |
11b959da | 199 | struct type *field_type = TYPE_FIELD_TYPE (type, i); |
8fbdca53 FF |
200 | QUIT; |
201 | print_spaces_filtered (level + 4, stream); | |
11b959da FF |
202 | if (TYPE_CODE (field_type) == TYPE_CODE_UNION) |
203 | { int j; /* variant number */ | |
204 | fputs_filtered ("CASE OF\n", stream); | |
205 | for (j = 0; j < TYPE_NFIELDS (field_type); j++) | |
206 | { int k; /* variant field index */ | |
207 | struct type *variant_type | |
208 | = TYPE_FIELD_TYPE (field_type, j); | |
209 | int var_len = TYPE_NFIELDS (variant_type); | |
210 | print_spaces_filtered (level + 4, stream); | |
211 | if (strcmp (TYPE_FIELD_NAME (field_type, j), | |
212 | "else") == 0) | |
213 | fputs_filtered ("ELSE\n", stream); | |
214 | else | |
215 | fputs_filtered (":\n", stream); | |
216 | if (TYPE_CODE (variant_type) != TYPE_CODE_STRUCT) | |
217 | error ("variant record confusion"); | |
218 | for (k = 0; k < var_len; k++) | |
219 | { | |
220 | print_spaces_filtered (level + 8, stream); | |
221 | chill_print_type (TYPE_FIELD_TYPE (variant_type, k), | |
222 | TYPE_FIELD_NAME (variant_type, k), | |
223 | stream, show - 1, level + 8); | |
224 | if (k < (var_len - 1)) | |
225 | fputs_filtered (",", stream); | |
226 | fputs_filtered ("\n", stream); | |
227 | } | |
228 | } | |
229 | fputs_filtered ("ESAC\n", stream); | |
230 | } | |
231 | else | |
232 | chill_print_type (field_type, | |
233 | TYPE_FIELD_NAME (type, i), | |
234 | stream, show - 1, level + 4); | |
8fbdca53 FF |
235 | if (i < (len - 1)) |
236 | { | |
237 | fputs_filtered (",", stream); | |
238 | } | |
239 | fputs_filtered ("\n", stream); | |
240 | } | |
241 | } | |
242 | fprintfi_filtered (level, stream, ")"); | |
243 | } | |
a8a69e63 FF |
244 | break; |
245 | ||
11b959da | 246 | case TYPE_CODE_RANGE: |
cba00921 PB |
247 | if (TYPE_DUMMY_RANGE (type)) |
248 | chill_type_print_base (TYPE_TARGET_TYPE (type), | |
249 | stream, show, level); | |
250 | else if (TYPE_TARGET_TYPE (type)) | |
11b959da FF |
251 | { |
252 | chill_type_print_base (TYPE_TARGET_TYPE (type), | |
253 | stream, show, level); | |
254 | fputs_filtered (" (", stream); | |
255 | print_type_scalar (TYPE_TARGET_TYPE (type), | |
256 | TYPE_FIELD_BITPOS (type, 0), stream); | |
257 | fputs_filtered (":", stream); | |
258 | print_type_scalar (TYPE_TARGET_TYPE (type), | |
259 | TYPE_FIELD_BITPOS (type, 1), stream); | |
260 | fputs_filtered (")", stream); | |
261 | } | |
262 | else | |
263 | fprintf_filtered (stream, "RANGE? (%s : %d)", | |
264 | TYPE_FIELD_BITPOS (type, 0), | |
265 | TYPE_FIELD_BITPOS (type, 1)); | |
266 | break; | |
267 | ||
cba00921 PB |
268 | case TYPE_CODE_ENUM: |
269 | { | |
270 | register int lastval = 0; | |
271 | fprintf_filtered (stream, "SET ("); | |
272 | len = TYPE_NFIELDS (type); | |
273 | for (i = 0; i < len; i++) | |
274 | { | |
275 | QUIT; | |
276 | if (i) fprintf_filtered (stream, ", "); | |
277 | wrap_here (" "); | |
278 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
279 | if (lastval != TYPE_FIELD_BITPOS (type, i)) | |
280 | { | |
281 | fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); | |
282 | lastval = TYPE_FIELD_BITPOS (type, i); | |
283 | } | |
284 | lastval++; | |
285 | } | |
286 | fprintf_filtered (stream, ")"); | |
287 | } | |
288 | break; | |
289 | ||
a8a69e63 FF |
290 | case TYPE_CODE_VOID: |
291 | case TYPE_CODE_UNDEF: | |
292 | case TYPE_CODE_ERROR: | |
a8a69e63 | 293 | case TYPE_CODE_UNION: |
a8a69e63 | 294 | case TYPE_CODE_METHOD: |
8fbdca53 | 295 | error ("missing language support in chill_type_print_base"); |
a8a69e63 FF |
296 | break; |
297 | ||
298 | default: | |
299 | ||
300 | /* Handle types not explicitly handled by the other cases, | |
301 | such as fundamental types. For these, just print whatever | |
302 | the type name is, as recorded in the type itself. If there | |
303 | is no type name, then complain. */ | |
304 | ||
305 | if (TYPE_NAME (type) != NULL) | |
306 | { | |
307 | fputs_filtered (TYPE_NAME (type), stream); | |
308 | } | |
309 | else | |
310 | { | |
311 | error ("Unrecognized type code (%d) in symbol table.", | |
312 | TYPE_CODE (type)); | |
313 | } | |
314 | break; | |
315 | } | |
316 | } |