1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986-2016 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"
33 #include "typeprint.h"
35 #if 0 /* Currently unused. */
36 static void f_type_print_args (struct type
*, struct ui_file
*);
39 static void f_type_print_varspec_suffix (struct type
*, struct ui_file
*, int,
42 void f_type_print_varspec_prefix (struct type
*, struct ui_file
*,
45 void f_type_print_base (struct type
*, struct ui_file
*, int, int);
48 /* LEVEL is the depth to indent lines by. */
51 f_print_type (struct type
*type
, const char *varstring
, struct ui_file
*stream
,
52 int show
, int level
, const struct type_print_options
*flags
)
57 if (type_not_associated (type
))
59 val_print_not_associated (stream
);
63 if (type_not_allocated (type
))
65 val_print_not_allocated (stream
);
69 f_type_print_base (type
, stream
, show
, level
);
70 code
= TYPE_CODE (type
);
71 if ((varstring
!= NULL
&& *varstring
!= '\0')
72 /* Need a space if going to print stars or brackets;
73 but not if we will print just a type name. */
74 || ((show
> 0 || TYPE_NAME (type
) == 0)
75 && (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
76 || code
== TYPE_CODE_METHOD
77 || code
== TYPE_CODE_ARRAY
78 || code
== TYPE_CODE_REF
)))
79 fputs_filtered (" ", stream
);
80 f_type_print_varspec_prefix (type
, stream
, show
, 0);
82 if (varstring
!= NULL
)
84 fputs_filtered (varstring
, stream
);
86 /* For demangled function names, we have the arglist as part of the name,
87 so don't print an additional pair of ()'s. */
89 demangled_args
= varstring
[strlen (varstring
) - 1] == ')';
90 f_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
, 0);
94 /* Print any asterisks or open-parentheses needed before the
95 variable name (to describe its type).
97 On outermost call, pass 0 for PASSED_A_PTR.
98 On outermost call, SHOW > 0 means should ignore
99 any typename for TYPE and show its details.
100 SHOW is always zero on recursive calls. */
103 f_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
104 int show
, int passed_a_ptr
)
109 if (TYPE_NAME (type
) && show
<= 0)
114 switch (TYPE_CODE (type
))
117 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
121 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
123 fprintf_filtered (stream
, "(");
126 case TYPE_CODE_ARRAY
:
127 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
130 case TYPE_CODE_UNDEF
:
131 case TYPE_CODE_STRUCT
:
132 case TYPE_CODE_UNION
:
137 case TYPE_CODE_ERROR
:
141 case TYPE_CODE_RANGE
:
142 case TYPE_CODE_STRING
:
143 case TYPE_CODE_METHOD
:
145 case TYPE_CODE_COMPLEX
:
146 case TYPE_CODE_TYPEDEF
:
147 /* These types need no prefix. They are listed here so that
148 gcc -Wall will reveal any types that haven't been handled. */
153 /* Print any array sizes, function arguments or close parentheses
154 needed after the variable name (to describe its type).
155 Args work like c_type_print_varspec_prefix. */
158 f_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
159 int show
, int passed_a_ptr
, int demangled_args
,
160 int arrayprint_recurse_level
)
162 int upper_bound
, lower_bound
;
164 /* No static variables are permitted as an error call may occur during
165 execution of this function. */
170 if (TYPE_NAME (type
) && show
<= 0)
175 switch (TYPE_CODE (type
))
177 case TYPE_CODE_ARRAY
:
178 arrayprint_recurse_level
++;
180 if (arrayprint_recurse_level
== 1)
181 fprintf_filtered (stream
, "(");
183 if (type_not_associated (type
))
184 val_print_not_associated (stream
);
185 else if (type_not_allocated (type
))
186 val_print_not_allocated (stream
);
189 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
)
190 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
191 0, 0, arrayprint_recurse_level
);
193 lower_bound
= f77_get_lowerbound (type
);
194 if (lower_bound
!= 1) /* Not the default. */
195 fprintf_filtered (stream
, "%d:", lower_bound
);
197 /* Make sure that, if we have an assumed size array, we
198 print out a warning and print the upperbound as '*'. */
200 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
201 fprintf_filtered (stream
, "*");
204 upper_bound
= f77_get_upperbound (type
);
205 fprintf_filtered (stream
, "%d", upper_bound
);
208 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_ARRAY
)
209 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
210 0, 0, arrayprint_recurse_level
);
212 if (arrayprint_recurse_level
== 1)
213 fprintf_filtered (stream
, ")");
215 fprintf_filtered (stream
, ",");
216 arrayprint_recurse_level
--;
221 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0,
222 arrayprint_recurse_level
);
223 fprintf_filtered (stream
, ")");
227 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
228 passed_a_ptr
, 0, arrayprint_recurse_level
);
230 fprintf_filtered (stream
, ")");
232 fprintf_filtered (stream
, "()");
235 case TYPE_CODE_UNDEF
:
236 case TYPE_CODE_STRUCT
:
237 case TYPE_CODE_UNION
:
242 case TYPE_CODE_ERROR
:
246 case TYPE_CODE_RANGE
:
247 case TYPE_CODE_STRING
:
248 case TYPE_CODE_METHOD
:
249 case TYPE_CODE_COMPLEX
:
250 case TYPE_CODE_TYPEDEF
:
251 /* These types do not need a suffix. They are listed so that
252 gcc -Wall will report types that may not have been considered. */
257 /* Print the name of the type (or the ultimate pointer target,
258 function value or array element), or the description of a
261 SHOW nonzero means don't print this type as just its name;
262 show its real definition even if it has a name.
263 SHOW zero means print just typename or struct tag if there is one
264 SHOW negative means abbreviate structure elements.
265 SHOW is decremented for printing of structure elements.
267 LEVEL is the depth to indent by.
268 We increase it for some recursive calls. */
271 f_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
282 fputs_filtered ("<type unknown>", stream
);
286 /* When SHOW is zero or less, and there is a valid type name, then always
287 just print the type name directly from the type. */
289 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
291 fprintfi_filtered (level
, stream
, "%s", TYPE_NAME (type
));
295 if (TYPE_CODE (type
) != TYPE_CODE_TYPEDEF
)
296 type
= check_typedef (type
);
298 switch (TYPE_CODE (type
))
300 case TYPE_CODE_TYPEDEF
:
301 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, 0, level
);
304 case TYPE_CODE_ARRAY
:
306 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
310 fprintf_filtered (stream
, "PTR TO -> ( ");
311 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
315 fprintf_filtered (stream
, "REF TO -> ( ");
316 f_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
320 fprintfi_filtered (level
, stream
, "VOID");
323 case TYPE_CODE_UNDEF
:
324 fprintfi_filtered (level
, stream
, "struct <unknown>");
327 case TYPE_CODE_ERROR
:
328 fprintfi_filtered (level
, stream
, "%s", TYPE_ERROR_NAME (type
));
331 case TYPE_CODE_RANGE
:
332 /* This should not occur. */
333 fprintfi_filtered (level
, stream
, "<range type>");
338 /* There may be some character types that attempt to come
339 through as TYPE_CODE_INT since dbxstclass.h is so
340 C-oriented, we must change these to "character" from "char". */
342 if (strcmp (TYPE_NAME (type
), "char") == 0)
343 fprintfi_filtered (level
, stream
, "character");
348 case TYPE_CODE_STRING
:
349 /* Strings may have dynamic upperbounds (lengths) like arrays. */
351 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
352 fprintfi_filtered (level
, stream
, "character*(*)");
355 upper_bound
= f77_get_upperbound (type
);
356 fprintf_filtered (stream
, "character*%d", upper_bound
);
360 case TYPE_CODE_STRUCT
:
361 case TYPE_CODE_UNION
:
362 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
363 fprintfi_filtered (level
, stream
, "Type, C_Union :: ");
365 fprintfi_filtered (level
, stream
, "Type ");
366 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
367 /* According to the definition,
368 we only print structure elements in case show > 0. */
371 fputs_filtered ("\n", stream
);
372 for (index
= 0; index
< TYPE_NFIELDS (type
); index
++)
374 f_type_print_base (TYPE_FIELD_TYPE (type
, index
), stream
,
375 show
- 1, level
+ 4);
376 fputs_filtered (" :: ", stream
);
377 fputs_filtered (TYPE_FIELD_NAME (type
, index
), stream
);
378 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type
, index
),
379 stream
, show
- 1, 0, 0, 0);
380 fputs_filtered ("\n", stream
);
382 fprintfi_filtered (level
, stream
, "End Type ");
383 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
387 case TYPE_CODE_MODULE
:
388 fprintfi_filtered (level
, stream
, "module %s", TYPE_TAG_NAME (type
));
393 /* Handle types not explicitly handled by the other cases,
394 such as fundamental types. For these, just print whatever
395 the type name is, as recorded in the type itself. If there
396 is no type name, then complain. */
397 if (TYPE_NAME (type
) != NULL
)
398 fprintfi_filtered (level
, stream
, "%s", TYPE_NAME (type
));
400 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type
));
This page took 0.038377 seconds and 4 git commands to generate.