1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986-2019 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/>. */
25 /* Local non-gdb includes. */
27 #include "expression.h"
29 #include "gdb_obstack.h"
34 #include "typeprint.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
)
58 if (type_not_associated (type
))
60 val_print_not_associated (stream
);
64 if (type_not_allocated (type
))
66 val_print_not_allocated (stream
);
70 f_type_print_base (type
, stream
, show
, level
);
71 code
= TYPE_CODE (type
);
72 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)
76 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
77 || code
== TYPE_CODE_METHOD
78 || code
== TYPE_CODE_ARRAY
79 || code
== TYPE_CODE_REF
)))
80 fputs_filtered (" ", stream
);
81 f_type_print_varspec_prefix (type
, stream
, show
, 0);
83 if (varstring
!= NULL
)
87 fputs_filtered (varstring
, stream
);
89 /* For demangled function names, we have the arglist as part of the name,
90 so don't print an additional pair of ()'s. */
92 demangled_args
= (*varstring
!= '\0'
93 && varstring
[strlen (varstring
) - 1] == ')');
94 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
, 0);
98 /* Print any asterisks or open-parentheses needed before the
99 variable name (to describe its type).
101 On outermost call, pass 0 for PASSED_A_PTR.
102 On outermost call, SHOW > 0 means should ignore
103 any typename for TYPE and show its details.
104 SHOW is always zero on recursive calls. */
107 f_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
108 int show
, int passed_a_ptr
)
113 if (TYPE_NAME (type
) && show
<= 0)
118 switch (TYPE_CODE (type
))
121 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
125 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
127 fprintf_filtered (stream
, "(");
130 case TYPE_CODE_ARRAY
:
131 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
134 case TYPE_CODE_UNDEF
:
135 case TYPE_CODE_STRUCT
:
136 case TYPE_CODE_UNION
:
141 case TYPE_CODE_ERROR
:
145 case TYPE_CODE_RANGE
:
146 case TYPE_CODE_STRING
:
147 case TYPE_CODE_METHOD
:
149 case TYPE_CODE_COMPLEX
:
150 case TYPE_CODE_TYPEDEF
:
151 /* These types need no prefix. They are listed here so that
152 gcc -Wall will reveal any types that haven't been handled. */
157 /* Print any array sizes, function arguments or close parentheses
158 needed after the variable name (to describe its type).
159 Args work like c_type_print_varspec_prefix. */
162 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
163 int show
, int passed_a_ptr
, int demangled_args
,
164 int arrayprint_recurse_level
)
166 /* No static variables are permitted as an error call may occur during
167 execution of this function. */
172 if (TYPE_NAME (type
) && show
<= 0)
177 switch (TYPE_CODE (type
))
179 case TYPE_CODE_ARRAY
:
180 arrayprint_recurse_level
++;
182 if (arrayprint_recurse_level
== 1)
183 fprintf_filtered (stream
, "(");
185 if (type_not_associated (type
))
186 val_print_not_associated (stream
);
187 else if (type_not_allocated (type
))
188 val_print_not_allocated (stream
);
191 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
192 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
193 0, 0, arrayprint_recurse_level
);
195 LONGEST lower_bound
= f77_get_lowerbound (type
);
197 if (lower_bound
!= 1) /* Not the default. */
198 fprintf_filtered (stream
, "%s:", plongest (lower_bound
));
200 /* Make sure that, if we have an assumed size array, we
201 print out a warning and print the upperbound as '*'. */
203 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
204 fprintf_filtered (stream
, "*");
207 LONGEST upper_bound
= f77_get_upperbound (type
);
209 fputs_filtered (plongest (upper_bound
), stream
);
212 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
213 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
214 0, 0, arrayprint_recurse_level
);
216 if (arrayprint_recurse_level
== 1)
217 fprintf_filtered (stream
, ")");
219 fprintf_filtered (stream
, ",");
220 arrayprint_recurse_level
--;
225 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0,
226 arrayprint_recurse_level
);
227 fprintf_filtered (stream
, ")");
231 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
232 passed_a_ptr
, 0, arrayprint_recurse_level
);
234 fprintf_filtered (stream
, ")");
236 fprintf_filtered (stream
, "()");
239 case TYPE_CODE_UNDEF
:
240 case TYPE_CODE_STRUCT
:
241 case TYPE_CODE_UNION
:
246 case TYPE_CODE_ERROR
:
250 case TYPE_CODE_RANGE
:
251 case TYPE_CODE_STRING
:
252 case TYPE_CODE_METHOD
:
253 case TYPE_CODE_COMPLEX
:
254 case TYPE_CODE_TYPEDEF
:
255 /* These types do not need a suffix. They are listed so that
256 gcc -Wall will report types that may not have been considered. */
261 /* Print the name of the type (or the ultimate pointer target,
262 function value or array element), or the description of a
265 SHOW nonzero means don't print this type as just its name;
266 show its real definition even if it has a name.
267 SHOW zero means print just typename or struct tag if there is one
268 SHOW negative means abbreviate structure elements.
269 SHOW is decremented for printing of structure elements.
271 LEVEL is the depth to indent by.
272 We increase it for some recursive calls. */
275 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
285 fputs_filtered ("<type unknown>", stream
);
289 /* When SHOW is zero or less, and there is a valid type name, then always
290 just print the type name directly from the type. */
292 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
294 const char *prefix
= "";
295 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
296 prefix
= "Type, C_Union :: ";
297 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
299 fprintfi_filtered (level
, stream
, "%s%s", prefix
, TYPE_NAME (type
));
303 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
304 type
= check_typedef (type
);
306 switch (TYPE_CODE (type
))
308 case TYPE_CODE_TYPEDEF
:
309 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
312 case TYPE_CODE_ARRAY
:
313 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
316 if (TYPE_TARGET_TYPE (type
) == NULL
)
317 type_print_unknown_return_type (stream
);
319 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
323 fprintfi_filtered (level
, stream
, "PTR TO -> ( ");
324 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, 0);
328 fprintfi_filtered (level
, stream
, "REF TO -> ( ");
329 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, 0);
333 fprintfi_filtered (level
, stream
, "VOID");
336 case TYPE_CODE_UNDEF
:
337 fprintfi_filtered (level
, stream
, "struct <unknown>");
340 case TYPE_CODE_ERROR
:
341 fprintfi_filtered (level
, stream
, "%s", TYPE_ERROR_NAME (type
));
344 case TYPE_CODE_RANGE
:
345 /* This should not occur. */
346 fprintfi_filtered (level
, stream
, "<range type>");
351 /* There may be some character types that attempt to come
352 through as TYPE_CODE_INT since dbxstclass.h is so
353 C-oriented, we must change these to "character" from "char". */
355 if (strcmp (TYPE_NAME (type
), "char") == 0)
356 fprintfi_filtered (level
, stream
, "character");
361 case TYPE_CODE_STRING
:
362 /* Strings may have dynamic upperbounds (lengths) like arrays. */
364 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
365 fprintfi_filtered (level
, stream
, "character*(*)");
368 LONGEST upper_bound
= f77_get_upperbound (type
);
370 fprintf_filtered (stream
, "character*%s", pulongest (upper_bound
));
374 case TYPE_CODE_STRUCT
:
375 case TYPE_CODE_UNION
:
376 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
377 fprintfi_filtered (level
, stream
, "Type, C_Union :: ");
379 fprintfi_filtered (level
, stream
, "Type ");
380 fputs_filtered (TYPE_NAME (type
), stream
);
381 /* According to the definition,
382 we only print structure elements in case show > 0. */
385 fputs_filtered ("\n", stream
);
386 for (index
= 0; index
< TYPE_NFIELDS (type
); index
++)
388 f_type_print_base (TYPE_FIELD_TYPE (type
, index
), stream
,
389 show
- 1, level
+ 4);
390 fputs_filtered (" :: ", stream
);
391 fputs_filtered (TYPE_FIELD_NAME (type
, index
), stream
);
392 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type
, index
),
393 stream
, show
- 1, 0, 0, 0);
394 fputs_filtered ("\n", stream
);
396 fprintfi_filtered (level
, stream
, "End Type ");
397 fputs_filtered (TYPE_NAME (type
), stream
);
401 case TYPE_CODE_MODULE
:
402 fprintfi_filtered (level
, stream
, "module %s", TYPE_NAME (type
));
407 /* Handle types not explicitly handled by the other cases,
408 such as fundamental types. For these, just print whatever
409 the type name is, as recorded in the type itself. If there
410 is no type name, then complain. */
411 if (TYPE_NAME (type
) != NULL
)
412 fprintfi_filtered (level
, stream
, "%s", TYPE_NAME (type
));
414 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type
));
This page took 0.039919 seconds and 4 git commands to generate.