]>
Commit | Line | Data |
---|---|---|
a91a6192 | 1 | /* Support for printing Fortran types for GDB, the GNU debugger. |
22d7f91e | 2 | Copyright 1986, 1988, 1989, 1991, 1993, 1994 Free Software Foundation, Inc. |
a91a6192 SS |
3 | Contributed by Motorola. Adapted from the C version by Farooq Butt |
4 | ([email protected]). | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
6c9638b4 | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
a91a6192 SS |
21 | |
22 | #include "defs.h" | |
23 | #include "obstack.h" | |
24 | #include "bfd.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "expression.h" | |
28 | #include "value.h" | |
29 | #include "gdbcore.h" | |
30 | #include "target.h" | |
31 | #include "command.h" | |
32 | #include "gdbcmd.h" | |
33 | #include "language.h" | |
34 | #include "demangle.h" | |
35 | #include "f-lang.h" | |
36 | #include "typeprint.h" | |
37 | #include "frame.h" /* ??? */ | |
38 | ||
2b576293 | 39 | #include "gdb_string.h" |
a91a6192 SS |
40 | #include <errno.h> |
41 | ||
6b14af2b | 42 | #if 0 /* Currently unused */ |
a91a6192 | 43 | static void f_type_print_args PARAMS ((struct type *, FILE *)); |
6b14af2b | 44 | #endif |
a91a6192 SS |
45 | |
46 | static void f_type_print_varspec_suffix PARAMS ((struct type *, FILE *, | |
47 | int, int, int)); | |
48 | ||
49 | void f_type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int)); | |
50 | ||
51 | void f_type_print_base PARAMS ((struct type *, FILE *, int, int)); | |
52 | ||
53 | \f | |
54 | /* LEVEL is the depth to indent lines by. */ | |
55 | ||
56 | void | |
57 | f_print_type (type, varstring, stream, show, level) | |
58 | struct type *type; | |
59 | char *varstring; | |
60 | FILE *stream; | |
61 | int show; | |
62 | int level; | |
63 | { | |
64 | register enum type_code code; | |
65 | int demangled_args; | |
66 | ||
67 | f_type_print_base (type, stream, show, level); | |
68 | code = TYPE_CODE (type); | |
69 | if ((varstring != NULL && *varstring != '\0') | |
70 | || | |
71 | /* Need a space if going to print stars or brackets; | |
72 | but not if we will print just a type name. */ | |
73 | ((show > 0 || TYPE_NAME (type) == 0) | |
74 | && | |
75 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
76 | || code == TYPE_CODE_METHOD | |
77 | || code == TYPE_CODE_ARRAY | |
78 | || code == TYPE_CODE_MEMBER | |
79 | || code == TYPE_CODE_REF))) | |
80 | fputs_filtered (" ", stream); | |
81 | f_type_print_varspec_prefix (type, stream, show, 0); | |
82 | ||
83 | fputs_filtered (varstring, stream); | |
84 | ||
85 | /* For demangled function names, we have the arglist as part of the name, | |
86 | so don't print an additional pair of ()'s */ | |
87 | ||
88 | demangled_args = varstring[strlen(varstring) - 1] == ')'; | |
89 | f_type_print_varspec_suffix (type, stream, show, 0, demangled_args); | |
90 | } | |
91 | ||
92 | /* Print any asterisks or open-parentheses needed before the | |
93 | variable name (to describe its type). | |
94 | ||
95 | On outermost call, pass 0 for PASSED_A_PTR. | |
96 | On outermost call, SHOW > 0 means should ignore | |
97 | any typename for TYPE and show its details. | |
98 | SHOW is always zero on recursive calls. */ | |
99 | ||
100 | void | |
101 | f_type_print_varspec_prefix (type, stream, show, passed_a_ptr) | |
102 | struct type *type; | |
103 | FILE *stream; | |
104 | int show; | |
105 | int passed_a_ptr; | |
106 | { | |
a91a6192 SS |
107 | if (type == 0) |
108 | return; | |
109 | ||
110 | if (TYPE_NAME (type) && show <= 0) | |
111 | return; | |
112 | ||
113 | QUIT; | |
114 | ||
115 | switch (TYPE_CODE (type)) | |
116 | { | |
117 | case TYPE_CODE_PTR: | |
118 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
119 | break; | |
120 | ||
121 | case TYPE_CODE_FUNC: | |
122 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
123 | if (passed_a_ptr) | |
124 | fprintf_filtered (stream, "("); | |
125 | break; | |
126 | ||
127 | case TYPE_CODE_ARRAY: | |
128 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
129 | break; | |
130 | ||
131 | case TYPE_CODE_UNDEF: | |
132 | case TYPE_CODE_STRUCT: | |
133 | case TYPE_CODE_UNION: | |
134 | case TYPE_CODE_ENUM: | |
135 | case TYPE_CODE_INT: | |
136 | case TYPE_CODE_FLT: | |
137 | case TYPE_CODE_VOID: | |
138 | case TYPE_CODE_ERROR: | |
139 | case TYPE_CODE_CHAR: | |
140 | case TYPE_CODE_BOOL: | |
141 | case TYPE_CODE_SET: | |
142 | case TYPE_CODE_RANGE: | |
143 | case TYPE_CODE_STRING: | |
22d7f91e SS |
144 | case TYPE_CODE_BITSTRING: |
145 | case TYPE_CODE_METHOD: | |
146 | case TYPE_CODE_MEMBER: | |
147 | case TYPE_CODE_REF: | |
148 | case TYPE_CODE_COMPLEX: | |
b52cac6b | 149 | case TYPE_CODE_TYPEDEF: |
a91a6192 SS |
150 | /* These types need no prefix. They are listed here so that |
151 | gcc -Wall will reveal any types that haven't been handled. */ | |
152 | break; | |
153 | } | |
154 | } | |
155 | ||
6b14af2b FF |
156 | #if 0 /* Currently unused */ |
157 | ||
a91a6192 SS |
158 | static void |
159 | f_type_print_args (type, stream) | |
160 | struct type *type; | |
161 | FILE *stream; | |
162 | { | |
163 | int i; | |
164 | struct type **args; | |
165 | ||
166 | fprintf_filtered (stream, "("); | |
167 | args = TYPE_ARG_TYPES (type); | |
168 | if (args != NULL) | |
169 | { | |
170 | if (args[1] == NULL) | |
171 | { | |
172 | fprintf_filtered (stream, "..."); | |
173 | } | |
174 | else | |
175 | { | |
176 | for (i = 1; args[i] != NULL && args[i]->code != TYPE_CODE_VOID; i++) | |
177 | { | |
178 | f_print_type (args[i], "", stream, -1, 0); | |
179 | if (args[i+1] == NULL) | |
180 | fprintf_filtered (stream, "..."); | |
181 | else if (args[i+1]->code != TYPE_CODE_VOID) | |
182 | { | |
183 | fprintf_filtered (stream, ","); | |
184 | wrap_here (" "); | |
185 | } | |
186 | } | |
187 | } | |
188 | } | |
189 | fprintf_filtered (stream, ")"); | |
190 | } | |
191 | ||
6b14af2b FF |
192 | #endif /* 0 */ |
193 | ||
a91a6192 SS |
194 | /* Print any array sizes, function arguments or close parentheses |
195 | needed after the variable name (to describe its type). | |
196 | Args work like c_type_print_varspec_prefix. */ | |
197 | ||
198 | static void | |
199 | f_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args) | |
200 | struct type *type; | |
201 | FILE *stream; | |
202 | int show; | |
203 | int passed_a_ptr; | |
204 | int demangled_args; | |
205 | { | |
22d7f91e | 206 | int upper_bound, lower_bound; |
a91a6192 SS |
207 | int lower_bound_was_default = 0; |
208 | static int arrayprint_recurse_level = 0; | |
209 | int retcode; | |
210 | ||
211 | if (type == 0) | |
212 | return; | |
213 | ||
214 | if (TYPE_NAME (type) && show <= 0) | |
215 | return; | |
216 | ||
217 | QUIT; | |
218 | ||
219 | switch (TYPE_CODE (type)) | |
220 | { | |
221 | case TYPE_CODE_ARRAY: | |
222 | arrayprint_recurse_level++; | |
223 | ||
224 | if (arrayprint_recurse_level == 1) | |
225 | fprintf_filtered(stream,"("); | |
8a329002 PB |
226 | |
227 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY) | |
228 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
a91a6192 SS |
229 | |
230 | retcode = f77_get_dynamic_lowerbound (type,&lower_bound); | |
231 | ||
232 | lower_bound_was_default = 0; | |
233 | ||
234 | if (retcode == BOUND_FETCH_ERROR) | |
235 | fprintf_filtered (stream,"???"); | |
236 | else | |
237 | if (lower_bound == 1) /* The default */ | |
238 | lower_bound_was_default = 1; | |
239 | else | |
240 | fprintf_filtered (stream,"%d",lower_bound); | |
241 | ||
242 | if (lower_bound_was_default) | |
243 | lower_bound_was_default = 0; | |
244 | else | |
245 | fprintf_filtered(stream,":"); | |
246 | ||
247 | /* Make sure that, if we have an assumed size array, we | |
248 | print out a warning and print the upperbound as '*' */ | |
249 | ||
250 | if (TYPE_ARRAY_UPPER_BOUND_TYPE(type) == BOUND_CANNOT_BE_DETERMINED) | |
251 | fprintf_filtered (stream, "*"); | |
252 | else | |
253 | { | |
254 | retcode = f77_get_dynamic_upperbound(type,&upper_bound); | |
255 | ||
256 | if (retcode == BOUND_FETCH_ERROR) | |
257 | fprintf_filtered(stream,"???"); | |
258 | else | |
259 | fprintf_filtered(stream,"%d",upper_bound); | |
260 | } | |
261 | ||
8a329002 PB |
262 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY) |
263 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
a91a6192 SS |
264 | if (arrayprint_recurse_level == 1) |
265 | fprintf_filtered (stream, ")"); | |
8a329002 PB |
266 | else |
267 | fprintf_filtered(stream,","); | |
a91a6192 SS |
268 | arrayprint_recurse_level--; |
269 | break; | |
270 | ||
271 | case TYPE_CODE_PTR: | |
272 | case TYPE_CODE_REF: | |
273 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0); | |
274 | fprintf_filtered(stream,")"); | |
275 | break; | |
276 | ||
277 | case TYPE_CODE_FUNC: | |
278 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
279 | passed_a_ptr, 0); | |
280 | if (passed_a_ptr) | |
281 | fprintf_filtered (stream, ")"); | |
282 | ||
283 | fprintf_filtered (stream, "()"); | |
284 | break; | |
285 | ||
286 | case TYPE_CODE_UNDEF: | |
287 | case TYPE_CODE_STRUCT: | |
288 | case TYPE_CODE_UNION: | |
289 | case TYPE_CODE_ENUM: | |
290 | case TYPE_CODE_INT: | |
291 | case TYPE_CODE_FLT: | |
292 | case TYPE_CODE_VOID: | |
293 | case TYPE_CODE_ERROR: | |
294 | case TYPE_CODE_CHAR: | |
295 | case TYPE_CODE_BOOL: | |
296 | case TYPE_CODE_SET: | |
297 | case TYPE_CODE_RANGE: | |
a91a6192 | 298 | case TYPE_CODE_STRING: |
22d7f91e SS |
299 | case TYPE_CODE_BITSTRING: |
300 | case TYPE_CODE_METHOD: | |
301 | case TYPE_CODE_MEMBER: | |
302 | case TYPE_CODE_COMPLEX: | |
b52cac6b | 303 | case TYPE_CODE_TYPEDEF: |
a91a6192 SS |
304 | /* These types do not need a suffix. They are listed so that |
305 | gcc -Wall will report types that may not have been considered. */ | |
306 | break; | |
307 | } | |
308 | } | |
309 | ||
a91a6192 SS |
310 | void |
311 | print_equivalent_f77_float_type (type, stream) | |
312 | struct type *type; | |
313 | FILE *stream; | |
314 | { | |
315 | /* Override type name "float" and make it the | |
316 | appropriate real. XLC stupidly outputs -12 as a type | |
317 | for real when it really should be outputting -18 */ | |
318 | ||
bcbf388e | 319 | fprintf_filtered (stream, "real*%d", TYPE_LENGTH (type)); |
a91a6192 SS |
320 | } |
321 | ||
322 | /* Print the name of the type (or the ultimate pointer target, | |
323 | function value or array element), or the description of a | |
324 | structure or union. | |
325 | ||
326 | SHOW nonzero means don't print this type as just its name; | |
327 | show its real definition even if it has a name. | |
328 | SHOW zero means print just typename or struct tag if there is one | |
329 | SHOW negative means abbreviate structure elements. | |
330 | SHOW is decremented for printing of structure elements. | |
331 | ||
332 | LEVEL is the depth to indent by. | |
333 | We increase it for some recursive calls. */ | |
334 | ||
335 | void | |
336 | f_type_print_base (type, stream, show, level) | |
337 | struct type *type; | |
338 | FILE *stream; | |
339 | int show; | |
340 | int level; | |
341 | { | |
22d7f91e SS |
342 | int retcode; |
343 | int upper_bound; | |
344 | ||
a91a6192 SS |
345 | QUIT; |
346 | ||
347 | wrap_here (" "); | |
348 | if (type == NULL) | |
349 | { | |
350 | fputs_filtered ("<type unknown>", stream); | |
351 | return; | |
352 | } | |
353 | ||
354 | /* When SHOW is zero or less, and there is a valid type name, then always | |
355 | just print the type name directly from the type. */ | |
356 | ||
357 | if ((show <= 0) && (TYPE_NAME (type) != NULL)) | |
358 | { | |
a91a6192 SS |
359 | if (TYPE_CODE (type) == TYPE_CODE_FLT) |
360 | print_equivalent_f77_float_type (type, stream); | |
361 | else | |
362 | fputs_filtered (TYPE_NAME (type), stream); | |
363 | return; | |
364 | } | |
365 | ||
bcbf388e PB |
366 | if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) |
367 | CHECK_TYPEDEF (type); | |
368 | ||
a91a6192 SS |
369 | switch (TYPE_CODE (type)) |
370 | { | |
bcbf388e PB |
371 | case TYPE_CODE_TYPEDEF: |
372 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
a91a6192 SS |
373 | break; |
374 | ||
bcbf388e | 375 | case TYPE_CODE_ARRAY: |
a91a6192 SS |
376 | case TYPE_CODE_FUNC: |
377 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
378 | break; | |
379 | ||
380 | case TYPE_CODE_PTR: | |
381 | fprintf_filtered (stream, "PTR TO -> ( "); | |
bcbf388e | 382 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); |
a91a6192 SS |
383 | break; |
384 | ||
385 | case TYPE_CODE_VOID: | |
386 | fprintf_filtered (stream, "VOID"); | |
387 | break; | |
388 | ||
389 | case TYPE_CODE_UNDEF: | |
390 | fprintf_filtered (stream, "struct <unknown>"); | |
391 | break; | |
392 | ||
393 | case TYPE_CODE_ERROR: | |
394 | fprintf_filtered (stream, "<unknown type>"); | |
395 | break; | |
396 | ||
397 | case TYPE_CODE_RANGE: | |
398 | /* This should not occur */ | |
399 | fprintf_filtered (stream, "<range type>"); | |
400 | break; | |
401 | ||
402 | case TYPE_CODE_CHAR: | |
403 | /* Override name "char" and make it "character" */ | |
404 | fprintf_filtered (stream, "character"); | |
405 | break; | |
406 | ||
407 | case TYPE_CODE_INT: | |
408 | /* There may be some character types that attempt to come | |
409 | through as TYPE_CODE_INT since dbxstclass.h is so | |
410 | C-oriented, we must change these to "character" from "char". */ | |
411 | ||
22d7f91e SS |
412 | if (STREQ (TYPE_NAME (type), "char")) |
413 | fprintf_filtered (stream, "character"); | |
a91a6192 SS |
414 | else |
415 | goto default_case; | |
416 | break; | |
417 | ||
418 | case TYPE_CODE_COMPLEX: | |
bcbf388e | 419 | fprintf_filtered (stream, "complex*%d", TYPE_LENGTH (type)); |
a91a6192 SS |
420 | break; |
421 | ||
422 | case TYPE_CODE_FLT: | |
22d7f91e | 423 | print_equivalent_f77_float_type (type, stream); |
a91a6192 SS |
424 | break; |
425 | ||
a91a6192 | 426 | case TYPE_CODE_STRING: |
22d7f91e | 427 | /* Strings may have dynamic upperbounds (lengths) like arrays. */ |
a91a6192 SS |
428 | |
429 | if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED) | |
85c613aa | 430 | fprintf_filtered (stream, "character*(*)"); |
a91a6192 SS |
431 | else |
432 | { | |
22d7f91e | 433 | retcode = f77_get_dynamic_upperbound (type, &upper_bound); |
a91a6192 SS |
434 | |
435 | if (retcode == BOUND_FETCH_ERROR) | |
22d7f91e | 436 | fprintf_filtered (stream, "character*???"); |
a91a6192 | 437 | else |
22d7f91e | 438 | fprintf_filtered (stream, "character*%d", upper_bound); |
a91a6192 SS |
439 | } |
440 | break; | |
441 | ||
442 | default_case: | |
443 | default: | |
444 | /* Handle types not explicitly handled by the other cases, | |
445 | such as fundamental types. For these, just print whatever | |
446 | the type name is, as recorded in the type itself. If there | |
447 | is no type name, then complain. */ | |
448 | if (TYPE_NAME (type) != NULL) | |
449 | fputs_filtered (TYPE_NAME (type), stream); | |
450 | else | |
451 | error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type)); | |
452 | break; | |
453 | } | |
454 | } |