1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002, 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Contributed by Motorola. Adapted from the C version by Farooq Butt
7 (fmbutt@engage.sps.mot.com).
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_obstack.h"
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 f_type_print_varspec_suffix (struct type
*, struct ui_file
*,
45 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
48 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
51 /* LEVEL is the depth to indent lines by. */
54 f_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
60 f_type_print_base (type
, stream
, show
, level
);
61 code
= TYPE_CODE (type
);
62 if ((varstring
!= NULL
&& *varstring
!= '\0')
64 /* Need a space if going to print stars or brackets;
65 but not if we will print just a type name. */
66 ((show
> 0 || TYPE_NAME (type
) == 0)
68 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
69 || code
== TYPE_CODE_METHOD
70 || code
== TYPE_CODE_ARRAY
71 || code
== TYPE_CODE_REF
)))
72 fputs_filtered (" ", stream
);
73 f_type_print_varspec_prefix (type
, stream
, show
, 0);
75 fputs_filtered (varstring
, stream
);
77 /* For demangled function names, we have the arglist as part of the name,
78 so don't print an additional pair of ()'s */
80 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
81 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
84 /* Print any asterisks or open-parentheses needed before the
85 variable name (to describe its type).
87 On outermost call, pass 0 for PASSED_A_PTR.
88 On outermost call, SHOW > 0 means should ignore
89 any typename for TYPE and show its details.
90 SHOW is always zero on recursive calls. */
93 f_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
94 int show
, int passed_a_ptr
)
99 if (TYPE_NAME (type
) && show
<= 0)
104 switch (TYPE_CODE (type
))
107 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
111 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
113 fprintf_filtered (stream
, "(");
116 case TYPE_CODE_ARRAY
:
117 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
120 case TYPE_CODE_UNDEF
:
121 case TYPE_CODE_STRUCT
:
122 case TYPE_CODE_UNION
:
127 case TYPE_CODE_ERROR
:
131 case TYPE_CODE_RANGE
:
132 case TYPE_CODE_STRING
:
133 case TYPE_CODE_BITSTRING
:
134 case TYPE_CODE_METHOD
:
136 case TYPE_CODE_COMPLEX
:
137 case TYPE_CODE_TYPEDEF
:
138 /* These types need no prefix. They are listed here so that
139 gcc -Wall will reveal any types that haven't been handled. */
144 /* Print any array sizes, function arguments or close parentheses
145 needed after the variable name (to describe its type).
146 Args work like c_type_print_varspec_prefix. */
149 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
150 int show
, int passed_a_ptr
, int demangled_args
)
152 int upper_bound
, lower_bound
;
153 int lower_bound_was_default
= 0;
154 static int arrayprint_recurse_level
= 0;
160 if (TYPE_NAME (type
) && show
<= 0)
165 switch (TYPE_CODE (type
))
167 case TYPE_CODE_ARRAY
:
168 arrayprint_recurse_level
++;
170 if (arrayprint_recurse_level
== 1)
171 fprintf_filtered (stream
, "(");
173 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
174 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
176 retcode
= f77_get_dynamic_lowerbound (type
, &lower_bound
);
178 lower_bound_was_default
= 0;
180 if (retcode
== BOUND_FETCH_ERROR
)
181 fprintf_filtered (stream
, "???");
182 else if (lower_bound
== 1) /* The default */
183 lower_bound_was_default
= 1;
185 fprintf_filtered (stream
, "%d", lower_bound
);
187 if (lower_bound_was_default
)
188 lower_bound_was_default
= 0;
190 fprintf_filtered (stream
, ":");
192 /* Make sure that, if we have an assumed size array, we
193 print out a warning and print the upperbound as '*' */
195 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
196 fprintf_filtered (stream
, "*");
199 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
201 if (retcode
== BOUND_FETCH_ERROR
)
202 fprintf_filtered (stream
, "???");
204 fprintf_filtered (stream
, "%d", upper_bound
);
207 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
208 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
209 if (arrayprint_recurse_level
== 1)
210 fprintf_filtered (stream
, ")");
212 fprintf_filtered (stream
, ",");
213 arrayprint_recurse_level
--;
218 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
219 fprintf_filtered (stream
, ")");
223 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
226 fprintf_filtered (stream
, ")");
228 fprintf_filtered (stream
, "()");
231 case TYPE_CODE_UNDEF
:
232 case TYPE_CODE_STRUCT
:
233 case TYPE_CODE_UNION
:
238 case TYPE_CODE_ERROR
:
242 case TYPE_CODE_RANGE
:
243 case TYPE_CODE_STRING
:
244 case TYPE_CODE_BITSTRING
:
245 case TYPE_CODE_METHOD
:
246 case TYPE_CODE_COMPLEX
:
247 case TYPE_CODE_TYPEDEF
:
248 /* These types do not need a suffix. They are listed so that
249 gcc -Wall will report types that may not have been considered. */
254 /* Print the name of the type (or the ultimate pointer target,
255 function value or array element), or the description of a
258 SHOW nonzero means don't print this type as just its name;
259 show its real definition even if it has a name.
260 SHOW zero means print just typename or struct tag if there is one
261 SHOW negative means abbreviate structure elements.
262 SHOW is decremented for printing of structure elements.
264 LEVEL is the depth to indent by.
265 We increase it for some recursive calls. */
268 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
281 fputs_filtered ("<type unknown>", stream
);
285 /* When SHOW is zero or less, and there is a valid type name, then always
286 just print the type name directly from the type. */
288 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
290 fputs_filtered (TYPE_NAME (type
), stream
);
294 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
295 CHECK_TYPEDEF (type
);
297 switch (TYPE_CODE (type
))
299 case TYPE_CODE_TYPEDEF
:
300 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
303 case TYPE_CODE_ARRAY
:
305 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
309 fprintf_filtered (stream
, "PTR TO -> ( ");
310 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
314 fprintf_filtered (stream
, "REF TO -> ( ");
315 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
319 fprintfi_filtered (level
, stream
, "VOID");
322 case TYPE_CODE_UNDEF
:
323 fprintfi_filtered (level
, stream
, "struct <unknown>");
326 case TYPE_CODE_ERROR
:
327 fprintfi_filtered (level
, stream
, "<unknown type>");
330 case TYPE_CODE_RANGE
:
331 /* This should not occur */
332 fprintfi_filtered (level
, stream
, "<range type>");
336 /* Override name "char" and make it "character" */
337 fprintfi_filtered (level
, stream
, "character");
341 /* There may be some character types that attempt to come
342 through as TYPE_CODE_INT since dbxstclass.h is so
343 C-oriented, we must change these to "character" from "char". */
345 if (strcmp (TYPE_NAME (type
), "char") == 0)
346 fprintfi_filtered (level
, stream
, "character");
351 case TYPE_CODE_STRING
:
352 /* Strings may have dynamic upperbounds (lengths) like arrays. */
354 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type
) == BOUND_CANNOT_BE_DETERMINED
)
355 fprintfi_filtered (level
, stream
, "character*(*)");
358 retcode
= f77_get_dynamic_upperbound (type
, &upper_bound
);
360 if (retcode
== BOUND_FETCH_ERROR
)
361 fprintf_filtered (stream
, "character*???");
363 fprintf_filtered (stream
, "character*%d", upper_bound
);
367 case TYPE_CODE_STRUCT
:
368 fprintfi_filtered (level
, stream
, "Type ");
369 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
370 fputs_filtered ("\n", stream
);
371 for (index
= 0; index
< TYPE_NFIELDS (type
); index
++)
373 f_print_type (TYPE_FIELD_TYPE (type
, index
), "", stream
, show
, level
+ 4);
374 fputs_filtered (" :: ", stream
);
375 fputs_filtered (TYPE_FIELD_NAME (type
, index
), stream
);
376 fputs_filtered ("\n", stream
);
378 fprintfi_filtered (level
, stream
, "End Type ");
379 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
384 /* Handle types not explicitly handled by the other cases,
385 such as fundamental types. For these, just print whatever
386 the type name is, as recorded in the type itself. If there
387 is no type name, then complain. */
388 if (TYPE_NAME (type
) != NULL
)
389 fprintfi_filtered (level
, stream
, "%s", TYPE_NAME (type
));
391 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type
));