1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986-2015 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 #if 0 /* Currently unused. */
35 static void f_type_print_args (struct type
*, struct ui_file
*);
38 static void f_type_print_varspec_suffix (struct type
*, struct ui_file
*, int,
41 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
44 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
47 /* LEVEL is the depth to indent lines by. */
50 f_print_type (struct type
*type
, const char *varstring
, struct ui_file
*stream
,
51 int show
, int level
, const struct type_print_options
*flags
)
56 f_type_print_base (type
, stream
, show
, level
);
57 code
= TYPE_CODE (type
);
58 if ((varstring
!= NULL
&& *varstring
!= '\0')
59 /* Need a space if going to print stars or brackets;
60 but not if we will print just a type name. */
61 || ((show
> 0 || TYPE_NAME (type
) == 0)
62 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
63 || code
== TYPE_CODE_METHOD
64 || code
== TYPE_CODE_ARRAY
65 || code
== TYPE_CODE_REF
)))
66 fputs_filtered (" ", stream
);
67 f_type_print_varspec_prefix (type
, stream
, show
, 0);
69 if (varstring
!= NULL
)
71 fputs_filtered (varstring
, stream
);
73 /* For demangled function names, we have the arglist as part of the name,
74 so don't print an additional pair of ()'s. */
76 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
77 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
, 0);
81 /* Print any asterisks or open-parentheses needed before the
82 variable name (to describe its type).
84 On outermost call, pass 0 for PASSED_A_PTR.
85 On outermost call, SHOW > 0 means should ignore
86 any typename for TYPE and show its details.
87 SHOW is always zero on recursive calls. */
90 f_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
91 int show
, int passed_a_ptr
)
96 if (TYPE_NAME (type
) && show
<= 0)
101 switch (TYPE_CODE (type
))
104 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
108 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
110 fprintf_filtered (stream
, "(");
113 case TYPE_CODE_ARRAY
:
114 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
117 case TYPE_CODE_UNDEF
:
118 case TYPE_CODE_STRUCT
:
119 case TYPE_CODE_UNION
:
124 case TYPE_CODE_ERROR
:
128 case TYPE_CODE_RANGE
:
129 case TYPE_CODE_STRING
:
130 case TYPE_CODE_METHOD
:
132 case TYPE_CODE_COMPLEX
:
133 case TYPE_CODE_TYPEDEF
:
134 /* These types need no prefix. They are listed here so that
135 gcc -Wall will reveal any types that haven't been handled. */
140 /* Print any array sizes, function arguments or close parentheses
141 needed after the variable name (to describe its type).
142 Args work like c_type_print_varspec_prefix. */
145 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
146 int show
, int passed_a_ptr
, int demangled_args
,
147 int arrayprint_recurse_level
)
149 int upper_bound
, lower_bound
;
151 /* No static variables are permitted as an error call may occur during
152 execution of this function. */
157 if (TYPE_NAME (type
) && show
<= 0)
162 switch (TYPE_CODE (type
))
164 case TYPE_CODE_ARRAY
:
165 arrayprint_recurse_level
++;
167 if (arrayprint_recurse_level
== 1)
168 fprintf_filtered (stream
, "(");
170 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
171 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0,
172 arrayprint_recurse_level
);
174 lower_bound
= f77_get_lowerbound (type
);
175 if (lower_bound
!= 1) /* Not the default. */
176 fprintf_filtered (stream
, "%d:", lower_bound
);
178 /* Make sure that, if we have an assumed size array, we
179 print out a warning and print the upperbound as '*'. */
181 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
182 fprintf_filtered (stream
, "*");
185 upper_bound
= f77_get_upperbound (type
);
186 fprintf_filtered (stream
, "%d", upper_bound
);
189 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
190 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0,
191 arrayprint_recurse_level
);
192 if (arrayprint_recurse_level
== 1)
193 fprintf_filtered (stream
, ")");
195 fprintf_filtered (stream
, ",");
196 arrayprint_recurse_level
--;
201 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0,
202 arrayprint_recurse_level
);
203 fprintf_filtered (stream
, ")");
207 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
208 passed_a_ptr
, 0, arrayprint_recurse_level
);
210 fprintf_filtered (stream
, ")");
212 fprintf_filtered (stream
, "()");
215 case TYPE_CODE_UNDEF
:
216 case TYPE_CODE_STRUCT
:
217 case TYPE_CODE_UNION
:
222 case TYPE_CODE_ERROR
:
226 case TYPE_CODE_RANGE
:
227 case TYPE_CODE_STRING
:
228 case TYPE_CODE_METHOD
:
229 case TYPE_CODE_COMPLEX
:
230 case TYPE_CODE_TYPEDEF
:
231 /* These types do not need a suffix. They are listed so that
232 gcc -Wall will report types that may not have been considered. */
237 /* Print the name of the type (or the ultimate pointer target,
238 function value or array element), or the description of a
241 SHOW nonzero means don't print this type as just its name;
242 show its real definition even if it has a name.
243 SHOW zero means print just typename or struct tag if there is one
244 SHOW negative means abbreviate structure elements.
245 SHOW is decremented for printing of structure elements.
247 LEVEL is the depth to indent by.
248 We increase it for some recursive calls. */
251 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
262 fputs_filtered ("<type unknown>", stream
);
266 /* When SHOW is zero or less, and there is a valid type name, then always
267 just print the type name directly from the type. */
269 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
271 fputs_filtered (TYPE_NAME (type
), stream
);
275 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
276 type
= check_typedef (type
);
278 switch (TYPE_CODE (type
))
280 case TYPE_CODE_TYPEDEF
:
281 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
284 case TYPE_CODE_ARRAY
:
286 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
290 fprintf_filtered (stream
, "PTR TO -> ( ");
291 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
295 fprintf_filtered (stream
, "REF TO -> ( ");
296 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
300 fprintfi_filtered (level
, stream
, "VOID");
303 case TYPE_CODE_UNDEF
:
304 fprintfi_filtered (level
, stream
, "struct <unknown>");
307 case TYPE_CODE_ERROR
:
308 fprintfi_filtered (level
, stream
, "%s", TYPE_ERROR_NAME (type
));
311 case TYPE_CODE_RANGE
:
312 /* This should not occur. */
313 fprintfi_filtered (level
, stream
, "<range type>");
318 /* There may be some character types that attempt to come
319 through as TYPE_CODE_INT since dbxstclass.h is so
320 C-oriented, we must change these to "character" from "char". */
322 if (strcmp (TYPE_NAME (type
), "char") == 0)
323 fprintfi_filtered (level
, stream
, "character");
328 case TYPE_CODE_STRING
:
329 /* Strings may have dynamic upperbounds (lengths) like arrays. */
331 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
332 fprintfi_filtered (level
, stream
, "character*(*)");
335 upper_bound
= f77_get_upperbound (type
);
336 fprintf_filtered (stream
, "character*%d", upper_bound
);
340 case TYPE_CODE_STRUCT
:
341 case TYPE_CODE_UNION
:
342 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
343 fprintfi_filtered (level
, stream
, "Type, C_Union :: ");
345 fprintfi_filtered (level
, stream
, "Type ");
346 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
347 fputs_filtered ("\n", stream
);
348 for (index
= 0; index
< TYPE_NFIELDS (type
); index
++)
350 f_type_print_base (TYPE_FIELD_TYPE (type
, index
), stream
, show
,
352 fputs_filtered (" :: ", stream
);
353 fputs_filtered (TYPE_FIELD_NAME (type
, index
), stream
);
354 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type
, index
),
356 fputs_filtered ("\n", stream
);
358 fprintfi_filtered (level
, stream
, "End Type ");
359 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
362 case TYPE_CODE_MODULE
:
363 fprintfi_filtered (level
, stream
, "module %s", TYPE_TAG_NAME (type
));
368 /* Handle types not explicitly handled by the other cases,
369 such as fundamental types. For these, just print whatever
370 the type name is, as recorded in the type itself. If there
371 is no type name, then complain. */
372 if (TYPE_NAME (type
) != NULL
)
373 fprintfi_filtered (level
, stream
, "%s", TYPE_NAME (type
));
375 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type
));
This page took 0.037959 seconds and 4 git commands to generate.