1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
5 Contributed by Motorola. Adapted from the C version by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_obstack.h"
28 #include "expression.h"
34 #include "gdb_string.h"
37 #if 0 /* Currently unused. */
38 static void f_type_print_args (struct type
*, struct ui_file
*);
41 static void f_type_print_varspec_suffix (struct type
*, struct ui_file
*, int,
44 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
47 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
50 /* LEVEL is the depth to indent lines by. */
53 f_print_type (struct type
*type
, const char *varstring
, struct ui_file
*stream
,
54 int show
, int level
, const struct type_print_options
*flags
)
59 f_type_print_base (type
, stream
, show
, level
);
60 code
= TYPE_CODE (type
);
61 if ((varstring
!= NULL
&& *varstring
!= '\0')
62 /* Need a space if going to print stars or brackets;
63 but not if we will print just a type name. */
64 || ((show
> 0 || TYPE_NAME (type
) == 0)
65 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
66 || code
== TYPE_CODE_METHOD
67 || code
== TYPE_CODE_ARRAY
68 || code
== TYPE_CODE_REF
)))
69 fputs_filtered (" ", stream
);
70 f_type_print_varspec_prefix (type
, stream
, show
, 0);
72 if (varstring
!= NULL
)
74 fputs_filtered (varstring
, stream
);
76 /* For demangled function names, we have the arglist as part of the name,
77 so don't print an additional pair of ()'s. */
79 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
80 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
, 0);
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_METHOD
:
135 case TYPE_CODE_COMPLEX
:
136 case TYPE_CODE_TYPEDEF
:
137 /* These types need no prefix. They are listed here so that
138 gcc -Wall will reveal any types that haven't been handled. */
143 /* Print any array sizes, function arguments or close parentheses
144 needed after the variable name (to describe its type).
145 Args work like c_type_print_varspec_prefix. */
148 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
149 int show
, int passed_a_ptr
, int demangled_args
,
150 int arrayprint_recurse_level
)
152 int upper_bound
, lower_bound
;
154 /* No static variables are permitted as an error call may occur during
155 execution of this function. */
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,
175 arrayprint_recurse_level
);
177 lower_bound
= f77_get_lowerbound (type
);
178 if (lower_bound
!= 1) /* Not the default. */
179 fprintf_filtered (stream
, "%d:", lower_bound
);
181 /* Make sure that, if we have an assumed size array, we
182 print out a warning and print the upperbound as '*'. */
184 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
185 fprintf_filtered (stream
, "*");
188 upper_bound
= f77_get_upperbound (type
);
189 fprintf_filtered (stream
, "%d", upper_bound
);
192 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
193 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0,
194 arrayprint_recurse_level
);
195 if (arrayprint_recurse_level
== 1)
196 fprintf_filtered (stream
, ")");
198 fprintf_filtered (stream
, ",");
199 arrayprint_recurse_level
--;
204 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0,
205 arrayprint_recurse_level
);
206 fprintf_filtered (stream
, ")");
210 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
211 passed_a_ptr
, 0, arrayprint_recurse_level
);
213 fprintf_filtered (stream
, ")");
215 fprintf_filtered (stream
, "()");
218 case TYPE_CODE_UNDEF
:
219 case TYPE_CODE_STRUCT
:
220 case TYPE_CODE_UNION
:
225 case TYPE_CODE_ERROR
:
229 case TYPE_CODE_RANGE
:
230 case TYPE_CODE_STRING
:
231 case TYPE_CODE_METHOD
:
232 case TYPE_CODE_COMPLEX
:
233 case TYPE_CODE_TYPEDEF
:
234 /* These types do not need a suffix. They are listed so that
235 gcc -Wall will report types that may not have been considered. */
240 /* Print the name of the type (or the ultimate pointer target,
241 function value or array element), or the description of a
244 SHOW nonzero means don't print this type as just its name;
245 show its real definition even if it has a name.
246 SHOW zero means print just typename or struct tag if there is one
247 SHOW negative means abbreviate structure elements.
248 SHOW is decremented for printing of structure elements.
250 LEVEL is the depth to indent by.
251 We increase it for some recursive calls. */
254 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
265 fputs_filtered ("<type unknown>", stream
);
269 /* When SHOW is zero or less, and there is a valid type name, then always
270 just print the type name directly from the type. */
272 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
274 fputs_filtered (TYPE_NAME (type
), stream
);
278 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
279 CHECK_TYPEDEF (type
);
281 switch (TYPE_CODE (type
))
283 case TYPE_CODE_TYPEDEF
:
284 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
287 case TYPE_CODE_ARRAY
:
289 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
293 fprintf_filtered (stream
, "PTR TO -> ( ");
294 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
298 fprintf_filtered (stream
, "REF TO -> ( ");
299 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
303 fprintfi_filtered (level
, stream
, "VOID");
306 case TYPE_CODE_UNDEF
:
307 fprintfi_filtered (level
, stream
, "struct <unknown>");
310 case TYPE_CODE_ERROR
:
311 fprintfi_filtered (level
, stream
, "%s", TYPE_ERROR_NAME (type
));
314 case TYPE_CODE_RANGE
:
315 /* This should not occur. */
316 fprintfi_filtered (level
, stream
, "<range type>");
321 /* There may be some character types that attempt to come
322 through as TYPE_CODE_INT since dbxstclass.h is so
323 C-oriented, we must change these to "character" from "char". */
325 if (strcmp (TYPE_NAME (type
), "char") == 0)
326 fprintfi_filtered (level
, stream
, "character");
331 case TYPE_CODE_STRING
:
332 /* Strings may have dynamic upperbounds (lengths) like arrays. */
334 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
335 fprintfi_filtered (level
, stream
, "character*(*)");
338 upper_bound
= f77_get_upperbound (type
);
339 fprintf_filtered (stream
, "character*%d", upper_bound
);
343 case TYPE_CODE_STRUCT
:
344 case TYPE_CODE_UNION
:
345 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
346 fprintfi_filtered (level
, stream
, "Type, C_Union :: ");
348 fprintfi_filtered (level
, stream
, "Type ");
349 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
350 fputs_filtered ("\n", stream
);
351 for (index
= 0; index
< TYPE_NFIELDS (type
); index
++)
353 f_type_print_base (TYPE_FIELD_TYPE (type
, index
), stream
, show
,
355 fputs_filtered (" :: ", stream
);
356 fputs_filtered (TYPE_FIELD_NAME (type
, index
), stream
);
357 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type
, index
),
359 fputs_filtered ("\n", stream
);
361 fprintfi_filtered (level
, stream
, "End Type ");
362 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
365 case TYPE_CODE_MODULE
:
366 fprintfi_filtered (level
, stream
, "module %s", TYPE_TAG_NAME (type
));
371 /* Handle types not explicitly handled by the other cases,
372 such as fundamental types. For these, just print whatever
373 the type name is, as recorded in the type itself. If there
374 is no type name, then complain. */
375 if (TYPE_NAME (type
) != NULL
)
376 fprintfi_filtered (level
, stream
, "%s", TYPE_NAME (type
));
378 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type
));