1 /* Support for printing Fortran types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1993, 1994, 2000 Free Software Foundation, Inc.
3 Contributed by Motorola. Adapted from the C version by Farooq Butt
4 (fmbutt@engage.sps.mot.com).
6 This file is part of GDB.
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.
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.
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
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #include "expression.h"
37 #include "typeprint.h"
38 #include "frame.h" /* ??? */
40 #include "gdb_string.h"
43 #if 0 /* Currently unused */
44 static void f_type_print_args (struct type
*, struct ui_file
*);
47 static void print_equivalent_f77_float_type (struct type
*,
50 static void f_type_print_varspec_suffix (struct type
*, struct ui_file
*,
53 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
56 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
59 /* LEVEL is the depth to indent lines by. */
62 f_print_type (type
, varstring
, stream
, show
, level
)
65 struct ui_file
*stream
;
69 register enum type_code code
;
72 f_type_print_base (type
, stream
, show
, level
);
73 code
= TYPE_CODE (type
);
74 if ((varstring
!= NULL
&& *varstring
!= '\0')
76 /* Need a space if going to print stars or brackets;
77 but not if we will print just a type name. */
78 ((show
> 0 || TYPE_NAME (type
) == 0)
80 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
81 || code
== TYPE_CODE_METHOD
82 || code
== TYPE_CODE_ARRAY
83 || code
== TYPE_CODE_MEMBER
84 || code
== TYPE_CODE_REF
)))
85 fputs_filtered (" ", stream
);
86 f_type_print_varspec_prefix (type
, stream
, show
, 0);
88 fputs_filtered (varstring
, stream
);
90 /* For demangled function names, we have the arglist as part of the name,
91 so don't print an additional pair of ()'s */
93 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
94 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
97 /* Print any asterisks or open-parentheses needed before the
98 variable name (to describe its type).
100 On outermost call, pass 0 for PASSED_A_PTR.
101 On outermost call, SHOW > 0 means should ignore
102 any typename for TYPE and show its details.
103 SHOW is always zero on recursive calls. */
106 f_type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
108 struct ui_file
*stream
;
115 if (TYPE_NAME (type
) && show
<= 0)
120 switch (TYPE_CODE (type
))
123 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
127 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
129 fprintf_filtered (stream
, "(");
132 case TYPE_CODE_ARRAY
:
133 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
136 case TYPE_CODE_UNDEF
:
137 case TYPE_CODE_STRUCT
:
138 case TYPE_CODE_UNION
:
143 case TYPE_CODE_ERROR
:
147 case TYPE_CODE_RANGE
:
148 case TYPE_CODE_STRING
:
149 case TYPE_CODE_BITSTRING
:
150 case TYPE_CODE_METHOD
:
151 case TYPE_CODE_MEMBER
:
153 case TYPE_CODE_COMPLEX
:
154 case TYPE_CODE_TYPEDEF
:
155 /* These types need no prefix. They are listed here so that
156 gcc -Wall will reveal any types that haven't been handled. */
161 #if 0 /* Currently unused */
164 f_type_print_args (type
, stream
)
166 struct ui_file
*stream
;
171 fprintf_filtered (stream
, "(");
172 args
= TYPE_ARG_TYPES (type
);
177 fprintf_filtered (stream
, "...");
181 for (i
= 1; args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
183 f_print_type (args
[i
], "", stream
, -1, 0);
184 if (args
[i
+ 1] == NULL
)
185 fprintf_filtered (stream
, "...");
186 else if (args
[i
+ 1]->code
!= TYPE_CODE_VOID
)
188 fprintf_filtered (stream
, ",");
194 fprintf_filtered (stream
, ")");
199 /* Print any array sizes, function arguments or close parentheses
200 needed after the variable name (to describe its type).
201 Args work like c_type_print_varspec_prefix. */
204 f_type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
, demangled_args
)
206 struct ui_file
*stream
;
211 int upper_bound
, lower_bound
;
212 int lower_bound_was_default
= 0;
213 static int arrayprint_recurse_level
= 0;
219 if (TYPE_NAME (type
) && show
<= 0)
224 switch (TYPE_CODE (type
))
226 case TYPE_CODE_ARRAY
:
227 arrayprint_recurse_level
++;
229 if (arrayprint_recurse_level
== 1)
230 fprintf_filtered (stream
, "(");
232 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
233 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
235 retcode
= f77_get_dynamic_lowerbound (type
, &lower_bound
);
237 lower_bound_was_default
= 0;
239 if (retcode
== BOUND_FETCH_ERROR
)
240 fprintf_filtered (stream
, "???");
241 else if (lower_bound
== 1) /* The default */
242 lower_bound_was_default
= 1;
244 fprintf_filtered (stream
, "%d", lower_bound
);
246 if (lower_bound_was_default
)
247 lower_bound_was_default
= 0;
249 fprintf_filtered (stream
, ":");
251 /* Make sure that, if we have an assumed size array, we
252 print out a warning and print the upperbound as '*' */
254 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
255 fprintf_filtered (stream
, "*");
258 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
260 if (retcode
== BOUND_FETCH_ERROR
)
261 fprintf_filtered (stream
, "???");
263 fprintf_filtered (stream
, "%d", upper_bound
);
266 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
267 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
268 if (arrayprint_recurse_level
== 1)
269 fprintf_filtered (stream
, ")");
271 fprintf_filtered (stream
, ",");
272 arrayprint_recurse_level
--;
277 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
278 fprintf_filtered (stream
, ")");
282 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
285 fprintf_filtered (stream
, ")");
287 fprintf_filtered (stream
, "()");
290 case TYPE_CODE_UNDEF
:
291 case TYPE_CODE_STRUCT
:
292 case TYPE_CODE_UNION
:
297 case TYPE_CODE_ERROR
:
301 case TYPE_CODE_RANGE
:
302 case TYPE_CODE_STRING
:
303 case TYPE_CODE_BITSTRING
:
304 case TYPE_CODE_METHOD
:
305 case TYPE_CODE_MEMBER
:
306 case TYPE_CODE_COMPLEX
:
307 case TYPE_CODE_TYPEDEF
:
308 /* These types do not need a suffix. They are listed so that
309 gcc -Wall will report types that may not have been considered. */
315 print_equivalent_f77_float_type (type
, stream
)
317 struct ui_file
*stream
;
319 /* Override type name "float" and make it the
320 appropriate real. XLC stupidly outputs -12 as a type
321 for real when it really should be outputting -18 */
323 fprintf_filtered (stream
, "real*%d", TYPE_LENGTH (type
));
326 /* Print the name of the type (or the ultimate pointer target,
327 function value or array element), or the description of a
330 SHOW nonzero means don't print this type as just its name;
331 show its real definition even if it has a name.
332 SHOW zero means print just typename or struct tag if there is one
333 SHOW negative means abbreviate structure elements.
334 SHOW is decremented for printing of structure elements.
336 LEVEL is the depth to indent by.
337 We increase it for some recursive calls. */
340 f_type_print_base (type
, stream
, show
, level
)
342 struct ui_file
*stream
;
354 fputs_filtered ("<type unknown>", stream
);
358 /* When SHOW is zero or less, and there is a valid type name, then always
359 just print the type name directly from the type. */
361 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
363 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
364 print_equivalent_f77_float_type (type
, stream
);
366 fputs_filtered (TYPE_NAME (type
), stream
);
370 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
371 CHECK_TYPEDEF (type
);
373 switch (TYPE_CODE (type
))
375 case TYPE_CODE_TYPEDEF
:
376 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
379 case TYPE_CODE_ARRAY
:
381 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
385 fprintf_filtered (stream
, "PTR TO -> ( ");
386 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
390 fprintf_filtered (stream
, "VOID");
393 case TYPE_CODE_UNDEF
:
394 fprintf_filtered (stream
, "struct <unknown>");
397 case TYPE_CODE_ERROR
:
398 fprintf_filtered (stream
, "<unknown type>");
401 case TYPE_CODE_RANGE
:
402 /* This should not occur */
403 fprintf_filtered (stream
, "<range type>");
407 /* Override name "char" and make it "character" */
408 fprintf_filtered (stream
, "character");
412 /* There may be some character types that attempt to come
413 through as TYPE_CODE_INT since dbxstclass.h is so
414 C-oriented, we must change these to "character" from "char". */
416 if (STREQ (TYPE_NAME (type
), "char"))
417 fprintf_filtered (stream
, "character");
422 case TYPE_CODE_COMPLEX
:
423 fprintf_filtered (stream
, "complex*%d", TYPE_LENGTH (type
));
427 print_equivalent_f77_float_type (type
, stream
);
430 case TYPE_CODE_STRING
:
431 /* Strings may have dynamic upperbounds (lengths) like arrays. */
433 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
434 fprintf_filtered (stream
, "character*(*)");
437 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
439 if (retcode
== BOUND_FETCH_ERROR
)
440 fprintf_filtered (stream
, "character*???");
442 fprintf_filtered (stream
, "character*%d", upper_bound
);
448 /* Handle types not explicitly handled by the other cases,
449 such as fundamental types. For these, just print whatever
450 the type name is, as recorded in the type itself. If there
451 is no type name, then complain. */
452 if (TYPE_NAME (type
) != NULL
)
453 fputs_filtered (TYPE_NAME (type
), stream
);
455 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type
));