]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Fortran types for GDB, the GNU debugger. |
1bac305b | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 Free Software Foundation, Inc. |
1bac305b | 4 | |
c906108c SS |
5 | Contributed by Motorola. Adapted from the C version by Farooq Butt |
6 | (fmbutt@engage.sps.mot.com). | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
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 | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 13 | (at your option) any later version. |
c906108c | 14 | |
c5aa993b JM |
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. | |
c906108c | 19 | |
c5aa993b | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
22 | |
23 | #include "defs.h" | |
4de283e4 | 24 | #include "gdb_obstack.h" |
c906108c | 25 | #include "bfd.h" |
4de283e4 TT |
26 | #include "symtab.h" |
27 | #include "gdbtypes.h" | |
c906108c | 28 | #include "expression.h" |
4de283e4 | 29 | #include "value.h" |
c906108c SS |
30 | #include "gdbcore.h" |
31 | #include "target.h" | |
4de283e4 | 32 | #include "f-lang.h" |
3f2f83dd | 33 | #include "typeprint.h" |
7f6aba03 | 34 | #include "cli/cli-style.h" |
c906108c | 35 | |
0963b4bd | 36 | #if 0 /* Currently unused. */ |
d9fcf2fb | 37 | static void f_type_print_args (struct type *, struct ui_file *); |
c906108c SS |
38 | #endif |
39 | ||
0311118f | 40 | static void f_type_print_varspec_suffix (struct type *, struct ui_file *, int, |
584a927c | 41 | int, int, int, bool); |
c906108c | 42 | |
d9fcf2fb JM |
43 | void f_type_print_varspec_prefix (struct type *, struct ui_file *, |
44 | int, int); | |
c906108c | 45 | |
d9fcf2fb | 46 | void f_type_print_base (struct type *, struct ui_file *, int, int); |
c906108c | 47 | \f |
c5aa993b | 48 | |
1f20c35e AB |
49 | /* See documentation in f-lang.h. */ |
50 | ||
51 | void | |
52 | f_print_typedef (struct type *type, struct symbol *new_symbol, | |
53 | struct ui_file *stream) | |
54 | { | |
55 | type = check_typedef (type); | |
56 | f_print_type (type, "", stream, 0, 0, &type_print_raw_options); | |
1f20c35e AB |
57 | } |
58 | ||
c906108c SS |
59 | /* LEVEL is the depth to indent lines by. */ |
60 | ||
61 | void | |
25b524e8 | 62 | f_print_type (struct type *type, const char *varstring, struct ui_file *stream, |
79d43c61 | 63 | int show, int level, const struct type_print_options *flags) |
c906108c | 64 | { |
52f0bd74 | 65 | enum type_code code; |
c906108c SS |
66 | |
67 | f_type_print_base (type, stream, show, level); | |
78134374 | 68 | code = type->code (); |
c906108c | 69 | if ((varstring != NULL && *varstring != '\0') |
f1fdc960 AB |
70 | /* Need a space if going to print stars or brackets; but not if we |
71 | will print just a type name. */ | |
72 | || ((show > 0 | |
7d93a1e0 | 73 | || type->name () == 0) |
f1fdc960 | 74 | && (code == TYPE_CODE_FUNC |
905e0470 PM |
75 | || code == TYPE_CODE_METHOD |
76 | || code == TYPE_CODE_ARRAY | |
f1fdc960 AB |
77 | || ((code == TYPE_CODE_PTR |
78 | || code == TYPE_CODE_REF) | |
78134374 SM |
79 | && (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_FUNC |
80 | || (TYPE_TARGET_TYPE (type)->code () | |
f1fdc960 | 81 | == TYPE_CODE_METHOD) |
78134374 | 82 | || (TYPE_TARGET_TYPE (type)->code () |
f1fdc960 | 83 | == TYPE_CODE_ARRAY)))))) |
c906108c SS |
84 | fputs_filtered (" ", stream); |
85 | f_type_print_varspec_prefix (type, stream, show, 0); | |
86 | ||
a7dfd010 MD |
87 | if (varstring != NULL) |
88 | { | |
2123df0e YQ |
89 | int demangled_args; |
90 | ||
a7dfd010 | 91 | fputs_filtered (varstring, stream); |
c906108c | 92 | |
a7dfd010 | 93 | /* For demangled function names, we have the arglist as part of the name, |
0963b4bd | 94 | so don't print an additional pair of ()'s. */ |
c906108c | 95 | |
2123df0e YQ |
96 | demangled_args = (*varstring != '\0' |
97 | && varstring[strlen (varstring) - 1] == ')'); | |
584a927c | 98 | f_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0, false); |
a7dfd010 | 99 | } |
c906108c SS |
100 | } |
101 | ||
102 | /* Print any asterisks or open-parentheses needed before the | |
103 | variable name (to describe its type). | |
104 | ||
105 | On outermost call, pass 0 for PASSED_A_PTR. | |
106 | On outermost call, SHOW > 0 means should ignore | |
107 | any typename for TYPE and show its details. | |
108 | SHOW is always zero on recursive calls. */ | |
109 | ||
110 | void | |
fba45db2 KB |
111 | f_type_print_varspec_prefix (struct type *type, struct ui_file *stream, |
112 | int show, int passed_a_ptr) | |
c906108c SS |
113 | { |
114 | if (type == 0) | |
115 | return; | |
116 | ||
7d93a1e0 | 117 | if (type->name () && show <= 0) |
c906108c SS |
118 | return; |
119 | ||
120 | QUIT; | |
121 | ||
78134374 | 122 | switch (type->code ()) |
c906108c SS |
123 | { |
124 | case TYPE_CODE_PTR: | |
125 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
126 | break; | |
127 | ||
128 | case TYPE_CODE_FUNC: | |
129 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
130 | if (passed_a_ptr) | |
131 | fprintf_filtered (stream, "("); | |
132 | break; | |
133 | ||
134 | case TYPE_CODE_ARRAY: | |
135 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
136 | break; | |
137 | ||
138 | case TYPE_CODE_UNDEF: | |
139 | case TYPE_CODE_STRUCT: | |
140 | case TYPE_CODE_UNION: | |
141 | case TYPE_CODE_ENUM: | |
142 | case TYPE_CODE_INT: | |
143 | case TYPE_CODE_FLT: | |
144 | case TYPE_CODE_VOID: | |
145 | case TYPE_CODE_ERROR: | |
146 | case TYPE_CODE_CHAR: | |
147 | case TYPE_CODE_BOOL: | |
148 | case TYPE_CODE_SET: | |
149 | case TYPE_CODE_RANGE: | |
150 | case TYPE_CODE_STRING: | |
c906108c | 151 | case TYPE_CODE_METHOD: |
c906108c SS |
152 | case TYPE_CODE_REF: |
153 | case TYPE_CODE_COMPLEX: | |
154 | case TYPE_CODE_TYPEDEF: | |
155 | /* These types need no prefix. They are listed here so that | |
c5aa993b | 156 | gcc -Wall will reveal any types that haven't been handled. */ |
c906108c SS |
157 | break; |
158 | } | |
159 | } | |
160 | ||
c906108c SS |
161 | /* Print any array sizes, function arguments or close parentheses |
162 | needed after the variable name (to describe its type). | |
584a927c AB |
163 | Args work like c_type_print_varspec_prefix. |
164 | ||
165 | PRINT_RANK_ONLY is true when TYPE is an array which should be printed | |
166 | without the upper and lower bounds being specified, this will occur | |
167 | when the array is not allocated or not associated and so there are no | |
168 | known upper or lower bounds. */ | |
c906108c SS |
169 | |
170 | static void | |
fba45db2 | 171 | f_type_print_varspec_suffix (struct type *type, struct ui_file *stream, |
0311118f | 172 | int show, int passed_a_ptr, int demangled_args, |
584a927c | 173 | int arrayprint_recurse_level, bool print_rank_only) |
c906108c | 174 | { |
0311118f JK |
175 | /* No static variables are permitted as an error call may occur during |
176 | execution of this function. */ | |
c906108c SS |
177 | |
178 | if (type == 0) | |
179 | return; | |
180 | ||
7d93a1e0 | 181 | if (type->name () && show <= 0) |
c906108c SS |
182 | return; |
183 | ||
184 | QUIT; | |
185 | ||
78134374 | 186 | switch (type->code ()) |
c906108c SS |
187 | { |
188 | case TYPE_CODE_ARRAY: | |
189 | arrayprint_recurse_level++; | |
190 | ||
191 | if (arrayprint_recurse_level == 1) | |
c5aa993b | 192 | fprintf_filtered (stream, "("); |
c906108c | 193 | |
3f2f83dd | 194 | if (type_not_associated (type)) |
584a927c | 195 | print_rank_only = true; |
3f2f83dd | 196 | else if (type_not_allocated (type)) |
584a927c AB |
197 | print_rank_only = true; |
198 | else if ((TYPE_ASSOCIATED_PROP (type) | |
199 | && PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_ASSOCIATED_PROP (type))) | |
200 | || (TYPE_ALLOCATED_PROP (type) | |
201 | && PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_ALLOCATED_PROP (type))) | |
202 | || (TYPE_DATA_LOCATION (type) | |
203 | && PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_DATA_LOCATION (type)))) | |
204 | { | |
205 | /* This case exist when we ptype a typename which has the dynamic | |
206 | properties but cannot be resolved as there is no object. */ | |
207 | print_rank_only = true; | |
208 | } | |
3f2f83dd | 209 | |
78134374 | 210 | if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ARRAY) |
584a927c AB |
211 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, |
212 | 0, 0, arrayprint_recurse_level, | |
213 | print_rank_only); | |
2880242d | 214 | |
584a927c AB |
215 | if (print_rank_only) |
216 | fprintf_filtered (stream, ":"); | |
217 | else | |
218 | { | |
219 | LONGEST lower_bound = f77_get_lowerbound (type); | |
220 | if (lower_bound != 1) /* Not the default. */ | |
2880242d | 221 | fprintf_filtered (stream, "%s:", plongest (lower_bound)); |
3f2f83dd | 222 | |
584a927c AB |
223 | /* Make sure that, if we have an assumed size array, we |
224 | print out a warning and print the upperbound as '*'. */ | |
3f2f83dd | 225 | |
584a927c AB |
226 | if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) |
227 | fprintf_filtered (stream, "*"); | |
228 | else | |
229 | { | |
230 | LONGEST upper_bound = f77_get_upperbound (type); | |
2880242d KS |
231 | |
232 | fputs_filtered (plongest (upper_bound), stream); | |
584a927c AB |
233 | } |
234 | } | |
235 | ||
78134374 | 236 | if (TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_ARRAY) |
584a927c AB |
237 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, |
238 | 0, 0, arrayprint_recurse_level, | |
239 | print_rank_only); | |
3f2f83dd | 240 | |
c906108c SS |
241 | if (arrayprint_recurse_level == 1) |
242 | fprintf_filtered (stream, ")"); | |
243 | else | |
c5aa993b | 244 | fprintf_filtered (stream, ","); |
c906108c SS |
245 | arrayprint_recurse_level--; |
246 | break; | |
247 | ||
248 | case TYPE_CODE_PTR: | |
249 | case TYPE_CODE_REF: | |
0311118f | 250 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0, |
584a927c | 251 | arrayprint_recurse_level, false); |
f1fdc960 | 252 | fprintf_filtered (stream, " )"); |
c906108c SS |
253 | break; |
254 | ||
255 | case TYPE_CODE_FUNC: | |
bf7a4de1 | 256 | { |
1f704f76 | 257 | int i, nfields = type->num_fields (); |
c906108c | 258 | |
bf7a4de1 | 259 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, |
584a927c AB |
260 | passed_a_ptr, 0, |
261 | arrayprint_recurse_level, false); | |
bf7a4de1 | 262 | if (passed_a_ptr) |
f1fdc960 | 263 | fprintf_filtered (stream, ") "); |
bf7a4de1 AB |
264 | fprintf_filtered (stream, "("); |
265 | if (nfields == 0 && TYPE_PROTOTYPED (type)) | |
266 | f_print_type (builtin_f_type (get_type_arch (type))->builtin_void, | |
267 | "", stream, -1, 0, 0); | |
268 | else | |
269 | for (i = 0; i < nfields; i++) | |
270 | { | |
271 | if (i > 0) | |
272 | { | |
273 | fputs_filtered (", ", stream); | |
274 | wrap_here (" "); | |
275 | } | |
940da03e | 276 | f_print_type (type->field (i).type (), "", stream, -1, 0, 0); |
bf7a4de1 AB |
277 | } |
278 | fprintf_filtered (stream, ")"); | |
279 | } | |
c906108c SS |
280 | break; |
281 | ||
282 | case TYPE_CODE_UNDEF: | |
283 | case TYPE_CODE_STRUCT: | |
284 | case TYPE_CODE_UNION: | |
285 | case TYPE_CODE_ENUM: | |
286 | case TYPE_CODE_INT: | |
287 | case TYPE_CODE_FLT: | |
288 | case TYPE_CODE_VOID: | |
289 | case TYPE_CODE_ERROR: | |
290 | case TYPE_CODE_CHAR: | |
291 | case TYPE_CODE_BOOL: | |
292 | case TYPE_CODE_SET: | |
293 | case TYPE_CODE_RANGE: | |
294 | case TYPE_CODE_STRING: | |
c906108c | 295 | case TYPE_CODE_METHOD: |
c906108c SS |
296 | case TYPE_CODE_COMPLEX: |
297 | case TYPE_CODE_TYPEDEF: | |
298 | /* These types do not need a suffix. They are listed so that | |
c5aa993b | 299 | gcc -Wall will report types that may not have been considered. */ |
c906108c SS |
300 | break; |
301 | } | |
302 | } | |
303 | ||
c906108c SS |
304 | /* Print the name of the type (or the ultimate pointer target, |
305 | function value or array element), or the description of a | |
306 | structure or union. | |
307 | ||
308 | SHOW nonzero means don't print this type as just its name; | |
309 | show its real definition even if it has a name. | |
310 | SHOW zero means print just typename or struct tag if there is one | |
311 | SHOW negative means abbreviate structure elements. | |
312 | SHOW is decremented for printing of structure elements. | |
313 | ||
314 | LEVEL is the depth to indent by. | |
315 | We increase it for some recursive calls. */ | |
316 | ||
317 | void | |
fba45db2 KB |
318 | f_type_print_base (struct type *type, struct ui_file *stream, int show, |
319 | int level) | |
c906108c | 320 | { |
2a5e440c WZ |
321 | int index; |
322 | ||
c906108c SS |
323 | QUIT; |
324 | ||
325 | wrap_here (" "); | |
326 | if (type == NULL) | |
327 | { | |
7f6aba03 | 328 | fputs_styled ("<type unknown>", metadata_style.style (), stream); |
c906108c SS |
329 | return; |
330 | } | |
331 | ||
332 | /* When SHOW is zero or less, and there is a valid type name, then always | |
0963b4bd | 333 | just print the type name directly from the type. */ |
c906108c | 334 | |
7d93a1e0 | 335 | if ((show <= 0) && (type->name () != NULL)) |
c906108c | 336 | { |
e86ca25f | 337 | const char *prefix = ""; |
78134374 | 338 | if (type->code () == TYPE_CODE_UNION) |
e86ca25f | 339 | prefix = "Type, C_Union :: "; |
78134374 | 340 | else if (type->code () == TYPE_CODE_STRUCT) |
e86ca25f | 341 | prefix = "Type "; |
7d93a1e0 | 342 | fprintfi_filtered (level, stream, "%s%s", prefix, type->name ()); |
c906108c SS |
343 | return; |
344 | } | |
345 | ||
78134374 | 346 | if (type->code () != TYPE_CODE_TYPEDEF) |
f168693b | 347 | type = check_typedef (type); |
c906108c | 348 | |
78134374 | 349 | switch (type->code ()) |
c906108c SS |
350 | { |
351 | case TYPE_CODE_TYPEDEF: | |
352 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
353 | break; | |
354 | ||
355 | case TYPE_CODE_ARRAY: | |
c906108c | 356 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); |
7022349d PA |
357 | break; |
358 | case TYPE_CODE_FUNC: | |
359 | if (TYPE_TARGET_TYPE (type) == NULL) | |
360 | type_print_unknown_return_type (stream); | |
361 | else | |
362 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
c906108c SS |
363 | break; |
364 | ||
c5aa993b | 365 | case TYPE_CODE_PTR: |
a5ad232b FP |
366 | fprintfi_filtered (level, stream, "PTR TO -> ( "); |
367 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0); | |
7e86466e RH |
368 | break; |
369 | ||
370 | case TYPE_CODE_REF: | |
a5ad232b FP |
371 | fprintfi_filtered (level, stream, "REF TO -> ( "); |
372 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0); | |
c906108c SS |
373 | break; |
374 | ||
375 | case TYPE_CODE_VOID: | |
bbe75b9d AB |
376 | { |
377 | gdbarch *gdbarch = get_type_arch (type); | |
378 | struct type *void_type = builtin_f_type (gdbarch)->builtin_void; | |
7d93a1e0 | 379 | fprintfi_filtered (level, stream, "%s", void_type->name ()); |
bbe75b9d | 380 | } |
c906108c SS |
381 | break; |
382 | ||
383 | case TYPE_CODE_UNDEF: | |
2a5e440c | 384 | fprintfi_filtered (level, stream, "struct <unknown>"); |
c906108c SS |
385 | break; |
386 | ||
387 | case TYPE_CODE_ERROR: | |
b00fdb78 | 388 | fprintfi_filtered (level, stream, "%s", TYPE_ERROR_NAME (type)); |
c906108c SS |
389 | break; |
390 | ||
391 | case TYPE_CODE_RANGE: | |
0963b4bd | 392 | /* This should not occur. */ |
2a5e440c | 393 | fprintfi_filtered (level, stream, "<range type>"); |
c906108c SS |
394 | break; |
395 | ||
396 | case TYPE_CODE_CHAR: | |
c906108c SS |
397 | case TYPE_CODE_INT: |
398 | /* There may be some character types that attempt to come | |
399 | through as TYPE_CODE_INT since dbxstclass.h is so | |
400 | C-oriented, we must change these to "character" from "char". */ | |
401 | ||
7d93a1e0 | 402 | if (strcmp (type->name (), "char") == 0) |
2a5e440c | 403 | fprintfi_filtered (level, stream, "character"); |
c906108c SS |
404 | else |
405 | goto default_case; | |
406 | break; | |
407 | ||
c906108c | 408 | case TYPE_CODE_STRING: |
0963b4bd | 409 | /* Strings may have dynamic upperbounds (lengths) like arrays. */ |
c906108c | 410 | |
d78df370 | 411 | if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) |
2a5e440c | 412 | fprintfi_filtered (level, stream, "character*(*)"); |
c906108c SS |
413 | else |
414 | { | |
2880242d KS |
415 | LONGEST upper_bound = f77_get_upperbound (type); |
416 | ||
417 | fprintf_filtered (stream, "character*%s", pulongest (upper_bound)); | |
c906108c SS |
418 | } |
419 | break; | |
420 | ||
2a5e440c | 421 | case TYPE_CODE_STRUCT: |
9eec4d1e | 422 | case TYPE_CODE_UNION: |
78134374 | 423 | if (type->code () == TYPE_CODE_UNION) |
9eec4d1e MD |
424 | fprintfi_filtered (level, stream, "Type, C_Union :: "); |
425 | else | |
426 | fprintfi_filtered (level, stream, "Type "); | |
7d93a1e0 | 427 | fputs_filtered (type->name (), stream); |
9b2db1fd BH |
428 | /* According to the definition, |
429 | we only print structure elements in case show > 0. */ | |
430 | if (show > 0) | |
2a5e440c | 431 | { |
2a5e440c | 432 | fputs_filtered ("\n", stream); |
1f704f76 | 433 | for (index = 0; index < type->num_fields (); index++) |
9b2db1fd | 434 | { |
940da03e | 435 | f_type_print_base (type->field (index).type (), stream, |
e188eb36 | 436 | show - 1, level + 4); |
9b2db1fd | 437 | fputs_filtered (" :: ", stream); |
3f0cbb04 TT |
438 | fputs_styled (TYPE_FIELD_NAME (type, index), |
439 | variable_name_style.style (), stream); | |
940da03e | 440 | f_type_print_varspec_suffix (type->field (index).type (), |
584a927c | 441 | stream, show - 1, 0, 0, 0, false); |
9b2db1fd BH |
442 | fputs_filtered ("\n", stream); |
443 | } | |
444 | fprintfi_filtered (level, stream, "End Type "); | |
7d93a1e0 | 445 | fputs_filtered (type->name (), stream); |
9b2db1fd | 446 | } |
2a5e440c WZ |
447 | break; |
448 | ||
f55ee35c | 449 | case TYPE_CODE_MODULE: |
7d93a1e0 | 450 | fprintfi_filtered (level, stream, "module %s", type->name ()); |
f55ee35c JK |
451 | break; |
452 | ||
c906108c SS |
453 | default_case: |
454 | default: | |
455 | /* Handle types not explicitly handled by the other cases, | |
c5aa993b JM |
456 | such as fundamental types. For these, just print whatever |
457 | the type name is, as recorded in the type itself. If there | |
0963b4bd | 458 | is no type name, then complain. */ |
7d93a1e0 SM |
459 | if (type->name () != NULL) |
460 | fprintfi_filtered (level, stream, "%s", type->name ()); | |
c906108c | 461 | else |
78134374 | 462 | error (_("Invalid type code (%d) in symbol table."), type->code ()); |
c906108c SS |
463 | break; |
464 | } | |
bc68014d AB |
465 | |
466 | if (TYPE_IS_ALLOCATABLE (type)) | |
467 | fprintf_filtered (stream, ", allocatable"); | |
c906108c | 468 | } |