1 /* Support for printing Fortran types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 2000
3 Free Software Foundation, Inc.
4 Contributed by Motorola. Adapted from the C version by Farooq Butt
5 (fmbutt@engage.sps.mot.com).
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
29 #include "expression.h"
38 #include "typeprint.h"
39 #include "frame.h" /* ??? */
41 #include "gdb_string.h"
44 #if 0 /* Currently unused */
45 static void f_type_print_args (struct type
*, struct ui_file
*);
48 static void print_equivalent_f77_float_type (struct type
*,
51 static void f_type_print_varspec_suffix (struct type
*, struct ui_file
*,
54 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
57 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
60 /* LEVEL is the depth to indent lines by. */
63 f_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
66 register enum type_code code
;
69 f_type_print_base (type
, stream
, show
, level
);
70 code
= TYPE_CODE (type
);
71 if ((varstring
!= NULL
&& *varstring
!= '\0')
73 /* Need a space if going to print stars or brackets;
74 but not if we will print just a type name. */
75 ((show
> 0 || TYPE_NAME (type
) == 0)
77 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
78 || code
== TYPE_CODE_METHOD
79 || code
== TYPE_CODE_ARRAY
80 || code
== TYPE_CODE_MEMBER
81 || code
== TYPE_CODE_REF
)))
82 fputs_filtered (" ", stream
);
83 f_type_print_varspec_prefix (type
, stream
, show
, 0);
85 fputs_filtered (varstring
, stream
);
87 /* For demangled function names, we have the arglist as part of the name,
88 so don't print an additional pair of ()'s */
90 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
91 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
94 /* Print any asterisks or open-parentheses needed before the
95 variable name (to describe its type).
97 On outermost call, pass 0 for PASSED_A_PTR.
98 On outermost call, SHOW > 0 means should ignore
99 any typename for TYPE and show its details.
100 SHOW is always zero on recursive calls. */
103 f_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
104 int show
, int passed_a_ptr
)
109 if (TYPE_NAME (type
) && show
<= 0)
114 switch (TYPE_CODE (type
))
117 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
121 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
123 fprintf_filtered (stream
, "(");
126 case TYPE_CODE_ARRAY
:
127 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
130 case TYPE_CODE_UNDEF
:
131 case TYPE_CODE_STRUCT
:
132 case TYPE_CODE_UNION
:
137 case TYPE_CODE_ERROR
:
141 case TYPE_CODE_RANGE
:
142 case TYPE_CODE_STRING
:
143 case TYPE_CODE_BITSTRING
:
144 case TYPE_CODE_METHOD
:
145 case TYPE_CODE_MEMBER
:
147 case TYPE_CODE_COMPLEX
:
148 case TYPE_CODE_TYPEDEF
:
149 /* These types need no prefix. They are listed here so that
150 gcc -Wall will reveal any types that haven't been handled. */
155 #if 0 /* Currently unused */
158 f_type_print_args (struct type
*type
, struct ui_file
*stream
)
163 fprintf_filtered (stream
, "(");
164 args
= TYPE_ARG_TYPES (type
);
169 fprintf_filtered (stream
, "...");
173 for (i
= 1; args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
175 f_print_type (args
[i
], "", stream
, -1, 0);
176 if (args
[i
+ 1] == NULL
)
177 fprintf_filtered (stream
, "...");
178 else if (args
[i
+ 1]->code
!= TYPE_CODE_VOID
)
180 fprintf_filtered (stream
, ",");
186 fprintf_filtered (stream
, ")");
191 /* Print any array sizes, function arguments or close parentheses
192 needed after the variable name (to describe its type).
193 Args work like c_type_print_varspec_prefix. */
196 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
197 int show
, int passed_a_ptr
, int demangled_args
)
199 int upper_bound
, lower_bound
;
200 int lower_bound_was_default
= 0;
201 static int arrayprint_recurse_level
= 0;
207 if (TYPE_NAME (type
) && show
<= 0)
212 switch (TYPE_CODE (type
))
214 case TYPE_CODE_ARRAY
:
215 arrayprint_recurse_level
++;
217 if (arrayprint_recurse_level
== 1)
218 fprintf_filtered (stream
, "(");
220 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
221 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
223 retcode
= f77_get_dynamic_lowerbound (type
, &lower_bound
);
225 lower_bound_was_default
= 0;
227 if (retcode
== BOUND_FETCH_ERROR
)
228 fprintf_filtered (stream
, "???");
229 else if (lower_bound
== 1) /* The default */
230 lower_bound_was_default
= 1;
232 fprintf_filtered (stream
, "%d", lower_bound
);
234 if (lower_bound_was_default
)
235 lower_bound_was_default
= 0;
237 fprintf_filtered (stream
, ":");
239 /* Make sure that, if we have an assumed size array, we
240 print out a warning and print the upperbound as '*' */
242 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
243 fprintf_filtered (stream
, "*");
246 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
248 if (retcode
== BOUND_FETCH_ERROR
)
249 fprintf_filtered (stream
, "???");
251 fprintf_filtered (stream
, "%d", upper_bound
);
254 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
255 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
256 if (arrayprint_recurse_level
== 1)
257 fprintf_filtered (stream
, ")");
259 fprintf_filtered (stream
, ",");
260 arrayprint_recurse_level
--;
265 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
266 fprintf_filtered (stream
, ")");
270 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
273 fprintf_filtered (stream
, ")");
275 fprintf_filtered (stream
, "()");
278 case TYPE_CODE_UNDEF
:
279 case TYPE_CODE_STRUCT
:
280 case TYPE_CODE_UNION
:
285 case TYPE_CODE_ERROR
:
289 case TYPE_CODE_RANGE
:
290 case TYPE_CODE_STRING
:
291 case TYPE_CODE_BITSTRING
:
292 case TYPE_CODE_METHOD
:
293 case TYPE_CODE_MEMBER
:
294 case TYPE_CODE_COMPLEX
:
295 case TYPE_CODE_TYPEDEF
:
296 /* These types do not need a suffix. They are listed so that
297 gcc -Wall will report types that may not have been considered. */
303 print_equivalent_f77_float_type (struct type
*type
, struct ui_file
*stream
)
305 /* Override type name "float" and make it the
306 appropriate real. XLC stupidly outputs -12 as a type
307 for real when it really should be outputting -18 */
309 fprintf_filtered (stream
, "real*%d", TYPE_LENGTH (type
));
312 /* Print the name of the type (or the ultimate pointer target,
313 function value or array element), or the description of a
316 SHOW nonzero means don't print this type as just its name;
317 show its real definition even if it has a name.
318 SHOW zero means print just typename or struct tag if there is one
319 SHOW negative means abbreviate structure elements.
320 SHOW is decremented for printing of structure elements.
322 LEVEL is the depth to indent by.
323 We increase it for some recursive calls. */
326 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
337 fputs_filtered ("<type unknown>", stream
);
341 /* When SHOW is zero or less, and there is a valid type name, then always
342 just print the type name directly from the type. */
344 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
346 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
347 print_equivalent_f77_float_type (type
, stream
);
349 fputs_filtered (TYPE_NAME (type
), stream
);
353 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
354 CHECK_TYPEDEF (type
);
356 switch (TYPE_CODE (type
))
358 case TYPE_CODE_TYPEDEF
:
359 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
362 case TYPE_CODE_ARRAY
:
364 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
368 fprintf_filtered (stream
, "PTR TO -> ( ");
369 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
373 fprintf_filtered (stream
, "VOID");
376 case TYPE_CODE_UNDEF
:
377 fprintf_filtered (stream
, "struct <unknown>");
380 case TYPE_CODE_ERROR
:
381 fprintf_filtered (stream
, "<unknown type>");
384 case TYPE_CODE_RANGE
:
385 /* This should not occur */
386 fprintf_filtered (stream
, "<range type>");
390 /* Override name "char" and make it "character" */
391 fprintf_filtered (stream
, "character");
395 /* There may be some character types that attempt to come
396 through as TYPE_CODE_INT since dbxstclass.h is so
397 C-oriented, we must change these to "character" from "char". */
399 if (STREQ (TYPE_NAME (type
), "char"))
400 fprintf_filtered (stream
, "character");
405 case TYPE_CODE_COMPLEX
:
406 fprintf_filtered (stream
, "complex*%d", TYPE_LENGTH (type
));
410 print_equivalent_f77_float_type (type
, stream
);
413 case TYPE_CODE_STRING
:
414 /* Strings may have dynamic upperbounds (lengths) like arrays. */
416 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
417 fprintf_filtered (stream
, "character*(*)");
420 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
422 if (retcode
== BOUND_FETCH_ERROR
)
423 fprintf_filtered (stream
, "character*???");
425 fprintf_filtered (stream
, "character*%d", upper_bound
);
431 /* Handle types not explicitly handled by the other cases,
432 such as fundamental types. For these, just print whatever
433 the type name is, as recorded in the type itself. If there
434 is no type name, then complain. */
435 if (TYPE_NAME (type
) != NULL
)
436 fputs_filtered (TYPE_NAME (type
), stream
);
438 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type
));