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"
35 #include "gdb_string.h"
38 #if 0 /* Currently unused */
39 static void f_type_print_args (struct type
*, struct ui_file
*);
42 static void print_equivalent_f77_float_type (struct type
*,
45 static void f_type_print_varspec_suffix (struct type
*, struct ui_file
*,
48 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
51 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
54 /* LEVEL is the depth to indent lines by. */
57 f_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
60 register enum type_code code
;
63 f_type_print_base (type
, stream
, show
, level
);
64 code
= TYPE_CODE (type
);
65 if ((varstring
!= NULL
&& *varstring
!= '\0')
67 /* Need a space if going to print stars or brackets;
68 but not if we will print just a type name. */
69 ((show
> 0 || TYPE_NAME (type
) == 0)
71 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
72 || code
== TYPE_CODE_METHOD
73 || code
== TYPE_CODE_ARRAY
74 || code
== TYPE_CODE_MEMBER
75 || code
== TYPE_CODE_REF
)))
76 fputs_filtered (" ", stream
);
77 f_type_print_varspec_prefix (type
, stream
, show
, 0);
79 fputs_filtered (varstring
, stream
);
81 /* For demangled function names, we have the arglist as part of the name,
82 so don't print an additional pair of ()'s */
84 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
85 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
88 /* Print any asterisks or open-parentheses needed before the
89 variable name (to describe its type).
91 On outermost call, pass 0 for PASSED_A_PTR.
92 On outermost call, SHOW > 0 means should ignore
93 any typename for TYPE and show its details.
94 SHOW is always zero on recursive calls. */
97 f_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
98 int show
, int passed_a_ptr
)
103 if (TYPE_NAME (type
) && show
<= 0)
108 switch (TYPE_CODE (type
))
111 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
115 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
117 fprintf_filtered (stream
, "(");
120 case TYPE_CODE_ARRAY
:
121 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
124 case TYPE_CODE_UNDEF
:
125 case TYPE_CODE_STRUCT
:
126 case TYPE_CODE_UNION
:
131 case TYPE_CODE_ERROR
:
135 case TYPE_CODE_RANGE
:
136 case TYPE_CODE_STRING
:
137 case TYPE_CODE_BITSTRING
:
138 case TYPE_CODE_METHOD
:
139 case TYPE_CODE_MEMBER
:
141 case TYPE_CODE_COMPLEX
:
142 case TYPE_CODE_TYPEDEF
:
143 /* These types need no prefix. They are listed here so that
144 gcc -Wall will reveal any types that haven't been handled. */
149 #if 0 /* Currently unused */
152 f_type_print_args (struct type
*type
, struct ui_file
*stream
)
157 fprintf_filtered (stream
, "(");
158 args
= TYPE_ARG_TYPES (type
);
163 fprintf_filtered (stream
, "...");
167 for (i
= 1; args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
169 f_print_type (args
[i
], "", stream
, -1, 0);
170 if (args
[i
+ 1] == NULL
)
171 fprintf_filtered (stream
, "...");
172 else if (args
[i
+ 1]->code
!= TYPE_CODE_VOID
)
174 fprintf_filtered (stream
, ",");
180 fprintf_filtered (stream
, ")");
185 /* Print any array sizes, function arguments or close parentheses
186 needed after the variable name (to describe its type).
187 Args work like c_type_print_varspec_prefix. */
190 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
191 int show
, int passed_a_ptr
, int demangled_args
)
193 int upper_bound
, lower_bound
;
194 int lower_bound_was_default
= 0;
195 static int arrayprint_recurse_level
= 0;
201 if (TYPE_NAME (type
) && show
<= 0)
206 switch (TYPE_CODE (type
))
208 case TYPE_CODE_ARRAY
:
209 arrayprint_recurse_level
++;
211 if (arrayprint_recurse_level
== 1)
212 fprintf_filtered (stream
, "(");
214 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
215 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
217 retcode
= f77_get_dynamic_lowerbound (type
, &lower_bound
);
219 lower_bound_was_default
= 0;
221 if (retcode
== BOUND_FETCH_ERROR
)
222 fprintf_filtered (stream
, "???");
223 else if (lower_bound
== 1) /* The default */
224 lower_bound_was_default
= 1;
226 fprintf_filtered (stream
, "%d", lower_bound
);
228 if (lower_bound_was_default
)
229 lower_bound_was_default
= 0;
231 fprintf_filtered (stream
, ":");
233 /* Make sure that, if we have an assumed size array, we
234 print out a warning and print the upperbound as '*' */
236 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
237 fprintf_filtered (stream
, "*");
240 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
242 if (retcode
== BOUND_FETCH_ERROR
)
243 fprintf_filtered (stream
, "???");
245 fprintf_filtered (stream
, "%d", upper_bound
);
248 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
249 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
250 if (arrayprint_recurse_level
== 1)
251 fprintf_filtered (stream
, ")");
253 fprintf_filtered (stream
, ",");
254 arrayprint_recurse_level
--;
259 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
260 fprintf_filtered (stream
, ")");
264 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
267 fprintf_filtered (stream
, ")");
269 fprintf_filtered (stream
, "()");
272 case TYPE_CODE_UNDEF
:
273 case TYPE_CODE_STRUCT
:
274 case TYPE_CODE_UNION
:
279 case TYPE_CODE_ERROR
:
283 case TYPE_CODE_RANGE
:
284 case TYPE_CODE_STRING
:
285 case TYPE_CODE_BITSTRING
:
286 case TYPE_CODE_METHOD
:
287 case TYPE_CODE_MEMBER
:
288 case TYPE_CODE_COMPLEX
:
289 case TYPE_CODE_TYPEDEF
:
290 /* These types do not need a suffix. They are listed so that
291 gcc -Wall will report types that may not have been considered. */
297 print_equivalent_f77_float_type (struct type
*type
, struct ui_file
*stream
)
299 /* Override type name "float" and make it the
300 appropriate real. XLC stupidly outputs -12 as a type
301 for real when it really should be outputting -18 */
303 fprintf_filtered (stream
, "real*%d", TYPE_LENGTH (type
));
306 /* Print the name of the type (or the ultimate pointer target,
307 function value or array element), or the description of a
310 SHOW nonzero means don't print this type as just its name;
311 show its real definition even if it has a name.
312 SHOW zero means print just typename or struct tag if there is one
313 SHOW negative means abbreviate structure elements.
314 SHOW is decremented for printing of structure elements.
316 LEVEL is the depth to indent by.
317 We increase it for some recursive calls. */
320 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
331 fputs_filtered ("<type unknown>", stream
);
335 /* When SHOW is zero or less, and there is a valid type name, then always
336 just print the type name directly from the type. */
338 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
340 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
341 print_equivalent_f77_float_type (type
, stream
);
343 fputs_filtered (TYPE_NAME (type
), stream
);
347 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
348 CHECK_TYPEDEF (type
);
350 switch (TYPE_CODE (type
))
352 case TYPE_CODE_TYPEDEF
:
353 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
356 case TYPE_CODE_ARRAY
:
358 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
362 fprintf_filtered (stream
, "PTR TO -> ( ");
363 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
367 fprintf_filtered (stream
, "VOID");
370 case TYPE_CODE_UNDEF
:
371 fprintf_filtered (stream
, "struct <unknown>");
374 case TYPE_CODE_ERROR
:
375 fprintf_filtered (stream
, "<unknown type>");
378 case TYPE_CODE_RANGE
:
379 /* This should not occur */
380 fprintf_filtered (stream
, "<range type>");
384 /* Override name "char" and make it "character" */
385 fprintf_filtered (stream
, "character");
389 /* There may be some character types that attempt to come
390 through as TYPE_CODE_INT since dbxstclass.h is so
391 C-oriented, we must change these to "character" from "char". */
393 if (STREQ (TYPE_NAME (type
), "char"))
394 fprintf_filtered (stream
, "character");
399 case TYPE_CODE_COMPLEX
:
400 fprintf_filtered (stream
, "complex*%d", TYPE_LENGTH (type
));
404 print_equivalent_f77_float_type (type
, stream
);
407 case TYPE_CODE_STRING
:
408 /* Strings may have dynamic upperbounds (lengths) like arrays. */
410 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
411 fprintf_filtered (stream
, "character*(*)");
414 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
416 if (retcode
== BOUND_FETCH_ERROR
)
417 fprintf_filtered (stream
, "character*???");
419 fprintf_filtered (stream
, "character*%d", upper_bound
);
425 /* Handle types not explicitly handled by the other cases,
426 such as fundamental types. For these, just print whatever
427 the type name is, as recorded in the type itself. If there
428 is no type name, then complain. */
429 if (TYPE_NAME (type
) != NULL
)
430 fputs_filtered (TYPE_NAME (type
), stream
);
432 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type
));