]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Fortran types for GDB, the GNU debugger. |
1bac305b | 2 | |
d01e8234 | 3 | Copyright (C) 1986-2025 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 | 22 | |
e5dc0d5d | 23 | #include "event-top.h" |
4de283e4 TT |
24 | #include "symtab.h" |
25 | #include "gdbtypes.h" | |
c906108c | 26 | #include "expression.h" |
4de283e4 | 27 | #include "value.h" |
c906108c SS |
28 | #include "gdbcore.h" |
29 | #include "target.h" | |
4de283e4 | 30 | #include "f-lang.h" |
3f2f83dd | 31 | #include "typeprint.h" |
7f6aba03 | 32 | #include "cli/cli-style.h" |
c906108c | 33 | |
1a0ea399 | 34 | /* See f-lang.h. */ |
1f20c35e AB |
35 | |
36 | void | |
1a0ea399 AB |
37 | f_language::print_typedef (struct type *type, struct symbol *new_symbol, |
38 | struct ui_file *stream) const | |
1f20c35e AB |
39 | { |
40 | type = check_typedef (type); | |
1a0ea399 | 41 | print_type (type, "", stream, 0, 0, &type_print_raw_options); |
1f20c35e AB |
42 | } |
43 | ||
1a0ea399 | 44 | /* See f-lang.h. */ |
c906108c SS |
45 | |
46 | void | |
1a0ea399 AB |
47 | f_language::print_type (struct type *type, const char *varstring, |
48 | struct ui_file *stream, int show, int level, | |
49 | const struct type_print_options *flags) const | |
c906108c | 50 | { |
52f0bd74 | 51 | enum type_code code; |
c906108c SS |
52 | |
53 | f_type_print_base (type, stream, show, level); | |
78134374 | 54 | code = type->code (); |
c906108c | 55 | if ((varstring != NULL && *varstring != '\0') |
f1fdc960 AB |
56 | /* Need a space if going to print stars or brackets; but not if we |
57 | will print just a type name. */ | |
58 | || ((show > 0 | |
7d93a1e0 | 59 | || type->name () == 0) |
dda83cd7 | 60 | && (code == TYPE_CODE_FUNC |
905e0470 PM |
61 | || code == TYPE_CODE_METHOD |
62 | || code == TYPE_CODE_ARRAY | |
f1fdc960 AB |
63 | || ((code == TYPE_CODE_PTR |
64 | || code == TYPE_CODE_REF) | |
27710edb SM |
65 | && (type->target_type ()->code () == TYPE_CODE_FUNC |
66 | || (type->target_type ()->code () | |
f1fdc960 | 67 | == TYPE_CODE_METHOD) |
27710edb | 68 | || (type->target_type ()->code () |
f1fdc960 | 69 | == TYPE_CODE_ARRAY)))))) |
0426ad51 | 70 | gdb_puts (" ", stream); |
c906108c SS |
71 | f_type_print_varspec_prefix (type, stream, show, 0); |
72 | ||
a7dfd010 MD |
73 | if (varstring != NULL) |
74 | { | |
2123df0e YQ |
75 | int demangled_args; |
76 | ||
0426ad51 | 77 | gdb_puts (varstring, stream); |
c906108c | 78 | |
a7dfd010 | 79 | /* For demangled function names, we have the arglist as part of the name, |
dda83cd7 | 80 | so don't print an additional pair of ()'s. */ |
c906108c | 81 | |
2123df0e YQ |
82 | demangled_args = (*varstring != '\0' |
83 | && varstring[strlen (varstring) - 1] == ')'); | |
584a927c | 84 | f_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0, false); |
a7dfd010 | 85 | } |
c906108c SS |
86 | } |
87 | ||
1a0ea399 | 88 | /* See f-lang.h. */ |
c906108c SS |
89 | |
90 | void | |
1a0ea399 AB |
91 | f_language::f_type_print_varspec_prefix (struct type *type, |
92 | struct ui_file *stream, | |
93 | int show, int passed_a_ptr) const | |
c906108c SS |
94 | { |
95 | if (type == 0) | |
96 | return; | |
97 | ||
7d93a1e0 | 98 | if (type->name () && show <= 0) |
c906108c SS |
99 | return; |
100 | ||
101 | QUIT; | |
102 | ||
78134374 | 103 | switch (type->code ()) |
c906108c SS |
104 | { |
105 | case TYPE_CODE_PTR: | |
27710edb | 106 | f_type_print_varspec_prefix (type->target_type (), stream, 0, 1); |
c906108c SS |
107 | break; |
108 | ||
109 | case TYPE_CODE_FUNC: | |
27710edb | 110 | f_type_print_varspec_prefix (type->target_type (), stream, 0, 0); |
c906108c | 111 | if (passed_a_ptr) |
6cb06a8c | 112 | gdb_printf (stream, "("); |
c906108c SS |
113 | break; |
114 | ||
115 | case TYPE_CODE_ARRAY: | |
27710edb | 116 | f_type_print_varspec_prefix (type->target_type (), stream, 0, 0); |
c906108c SS |
117 | break; |
118 | ||
119 | case TYPE_CODE_UNDEF: | |
120 | case TYPE_CODE_STRUCT: | |
121 | case TYPE_CODE_UNION: | |
e9512253 | 122 | case TYPE_CODE_NAMELIST: |
c906108c SS |
123 | case TYPE_CODE_ENUM: |
124 | case TYPE_CODE_INT: | |
125 | case TYPE_CODE_FLT: | |
126 | case TYPE_CODE_VOID: | |
127 | case TYPE_CODE_ERROR: | |
128 | case TYPE_CODE_CHAR: | |
129 | case TYPE_CODE_BOOL: | |
130 | case TYPE_CODE_SET: | |
131 | case TYPE_CODE_RANGE: | |
132 | case TYPE_CODE_STRING: | |
c906108c | 133 | case TYPE_CODE_METHOD: |
c906108c SS |
134 | case TYPE_CODE_REF: |
135 | case TYPE_CODE_COMPLEX: | |
136 | case TYPE_CODE_TYPEDEF: | |
137 | /* These types need no prefix. They are listed here so that | |
dda83cd7 | 138 | gcc -Wall will reveal any types that haven't been handled. */ |
c906108c SS |
139 | break; |
140 | } | |
141 | } | |
142 | ||
1a0ea399 | 143 | /* See f-lang.h. */ |
584a927c | 144 | |
1a0ea399 AB |
145 | void |
146 | f_language::f_type_print_varspec_suffix (struct type *type, | |
147 | struct ui_file *stream, | |
148 | int show, int passed_a_ptr, | |
149 | int demangled_args, | |
150 | int arrayprint_recurse_level, | |
151 | bool print_rank_only) const | |
c906108c | 152 | { |
0311118f JK |
153 | /* No static variables are permitted as an error call may occur during |
154 | execution of this function. */ | |
c906108c SS |
155 | |
156 | if (type == 0) | |
157 | return; | |
158 | ||
7d93a1e0 | 159 | if (type->name () && show <= 0) |
c906108c SS |
160 | return; |
161 | ||
162 | QUIT; | |
163 | ||
78134374 | 164 | switch (type->code ()) |
c906108c SS |
165 | { |
166 | case TYPE_CODE_ARRAY: | |
167 | arrayprint_recurse_level++; | |
168 | ||
169 | if (arrayprint_recurse_level == 1) | |
6cb06a8c | 170 | gdb_printf (stream, "("); |
c906108c | 171 | |
3f2f83dd | 172 | if (type_not_associated (type)) |
584a927c | 173 | print_rank_only = true; |
3f2f83dd | 174 | else if (type_not_allocated (type)) |
584a927c AB |
175 | print_rank_only = true; |
176 | else if ((TYPE_ASSOCIATED_PROP (type) | |
9c0fb734 | 177 | && !TYPE_ASSOCIATED_PROP (type)->is_constant ()) |
584a927c | 178 | || (TYPE_ALLOCATED_PROP (type) |
9c0fb734 | 179 | && !TYPE_ALLOCATED_PROP (type)->is_constant ()) |
584a927c | 180 | || (TYPE_DATA_LOCATION (type) |
9c0fb734 | 181 | && !TYPE_DATA_LOCATION (type)->is_constant ())) |
584a927c AB |
182 | { |
183 | /* This case exist when we ptype a typename which has the dynamic | |
184 | properties but cannot be resolved as there is no object. */ | |
185 | print_rank_only = true; | |
186 | } | |
3f2f83dd | 187 | |
27710edb SM |
188 | if (type->target_type ()->code () == TYPE_CODE_ARRAY) |
189 | f_type_print_varspec_suffix (type->target_type (), stream, 0, | |
584a927c AB |
190 | 0, 0, arrayprint_recurse_level, |
191 | print_rank_only); | |
2880242d | 192 | |
584a927c | 193 | if (print_rank_only) |
6cb06a8c | 194 | gdb_printf (stream, ":"); |
584a927c AB |
195 | else |
196 | { | |
197 | LONGEST lower_bound = f77_get_lowerbound (type); | |
198 | if (lower_bound != 1) /* Not the default. */ | |
6cb06a8c | 199 | gdb_printf (stream, "%s:", plongest (lower_bound)); |
3f2f83dd | 200 | |
584a927c AB |
201 | /* Make sure that, if we have an assumed size array, we |
202 | print out a warning and print the upperbound as '*'. */ | |
3f2f83dd | 203 | |
cf88be68 | 204 | if (type->bounds ()->high.kind () == PROP_UNDEFINED) |
6cb06a8c | 205 | gdb_printf (stream, "*"); |
584a927c AB |
206 | else |
207 | { | |
208 | LONGEST upper_bound = f77_get_upperbound (type); | |
2880242d | 209 | |
0426ad51 | 210 | gdb_puts (plongest (upper_bound), stream); |
584a927c AB |
211 | } |
212 | } | |
213 | ||
27710edb SM |
214 | if (type->target_type ()->code () != TYPE_CODE_ARRAY) |
215 | f_type_print_varspec_suffix (type->target_type (), stream, 0, | |
584a927c AB |
216 | 0, 0, arrayprint_recurse_level, |
217 | print_rank_only); | |
3f2f83dd | 218 | |
c906108c | 219 | if (arrayprint_recurse_level == 1) |
6cb06a8c | 220 | gdb_printf (stream, ")"); |
c906108c | 221 | else |
6cb06a8c | 222 | gdb_printf (stream, ","); |
c906108c SS |
223 | arrayprint_recurse_level--; |
224 | break; | |
225 | ||
226 | case TYPE_CODE_PTR: | |
227 | case TYPE_CODE_REF: | |
27710edb | 228 | f_type_print_varspec_suffix (type->target_type (), stream, 0, 1, 0, |
584a927c | 229 | arrayprint_recurse_level, false); |
6cb06a8c | 230 | gdb_printf (stream, " )"); |
c906108c SS |
231 | break; |
232 | ||
233 | case TYPE_CODE_FUNC: | |
bf7a4de1 | 234 | { |
1f704f76 | 235 | int i, nfields = type->num_fields (); |
c906108c | 236 | |
27710edb | 237 | f_type_print_varspec_suffix (type->target_type (), stream, 0, |
584a927c AB |
238 | passed_a_ptr, 0, |
239 | arrayprint_recurse_level, false); | |
bf7a4de1 | 240 | if (passed_a_ptr) |
6cb06a8c TT |
241 | gdb_printf (stream, ") "); |
242 | gdb_printf (stream, "("); | |
7f9f399b | 243 | if (nfields == 0 && type->is_prototyped ()) |
8ee511af SM |
244 | print_type (builtin_f_type (type->arch ())->builtin_void, |
245 | "", stream, -1, 0, 0); | |
bf7a4de1 AB |
246 | else |
247 | for (i = 0; i < nfields; i++) | |
248 | { | |
249 | if (i > 0) | |
250 | { | |
0426ad51 | 251 | gdb_puts (", ", stream); |
1285ce86 | 252 | stream->wrap_here (4); |
bf7a4de1 | 253 | } |
1a0ea399 | 254 | print_type (type->field (i).type (), "", stream, -1, 0, 0); |
bf7a4de1 | 255 | } |
6cb06a8c | 256 | gdb_printf (stream, ")"); |
bf7a4de1 | 257 | } |
c906108c SS |
258 | break; |
259 | ||
260 | case TYPE_CODE_UNDEF: | |
261 | case TYPE_CODE_STRUCT: | |
262 | case TYPE_CODE_UNION: | |
e9512253 | 263 | case TYPE_CODE_NAMELIST: |
c906108c SS |
264 | case TYPE_CODE_ENUM: |
265 | case TYPE_CODE_INT: | |
266 | case TYPE_CODE_FLT: | |
267 | case TYPE_CODE_VOID: | |
268 | case TYPE_CODE_ERROR: | |
269 | case TYPE_CODE_CHAR: | |
270 | case TYPE_CODE_BOOL: | |
271 | case TYPE_CODE_SET: | |
272 | case TYPE_CODE_RANGE: | |
273 | case TYPE_CODE_STRING: | |
c906108c | 274 | case TYPE_CODE_METHOD: |
c906108c SS |
275 | case TYPE_CODE_COMPLEX: |
276 | case TYPE_CODE_TYPEDEF: | |
277 | /* These types do not need a suffix. They are listed so that | |
dda83cd7 | 278 | gcc -Wall will report types that may not have been considered. */ |
c906108c SS |
279 | break; |
280 | } | |
281 | } | |
282 | ||
1a0ea399 | 283 | /* See f-lang.h. */ |
c906108c | 284 | |
110aae55 BH |
285 | void |
286 | f_language::f_type_print_derivation_info (struct type *type, | |
287 | struct ui_file *stream) const | |
288 | { | |
289 | /* Fortran doesn't support multiple inheritance. */ | |
290 | const int i = 0; | |
291 | ||
292 | if (TYPE_N_BASECLASSES (type) > 0) | |
293 | gdb_printf (stream, ", extends(%s) ::", TYPE_BASECLASS (type, i)->name ()); | |
294 | } | |
295 | ||
296 | /* See f-lang.h. */ | |
297 | ||
c906108c | 298 | void |
1a0ea399 AB |
299 | f_language::f_type_print_base (struct type *type, struct ui_file *stream, |
300 | int show, int level) const | |
c906108c | 301 | { |
2a5e440c WZ |
302 | int index; |
303 | ||
c906108c SS |
304 | QUIT; |
305 | ||
1285ce86 | 306 | stream->wrap_here (4); |
c906108c SS |
307 | if (type == NULL) |
308 | { | |
7f6aba03 | 309 | fputs_styled ("<type unknown>", metadata_style.style (), stream); |
c906108c SS |
310 | return; |
311 | } | |
312 | ||
313 | /* When SHOW is zero or less, and there is a valid type name, then always | |
0963b4bd | 314 | just print the type name directly from the type. */ |
c906108c | 315 | |
7d93a1e0 | 316 | if ((show <= 0) && (type->name () != NULL)) |
c906108c | 317 | { |
e86ca25f | 318 | const char *prefix = ""; |
78134374 | 319 | if (type->code () == TYPE_CODE_UNION) |
e86ca25f | 320 | prefix = "Type, C_Union :: "; |
e9512253 | 321 | else if (type->code () == TYPE_CODE_STRUCT |
287de656 | 322 | || type->code () == TYPE_CODE_NAMELIST) |
e86ca25f | 323 | prefix = "Type "; |
6cb06a8c | 324 | gdb_printf (stream, "%*s%s%s", level, "", prefix, type->name ()); |
c906108c SS |
325 | return; |
326 | } | |
327 | ||
78134374 | 328 | if (type->code () != TYPE_CODE_TYPEDEF) |
f168693b | 329 | type = check_typedef (type); |
c906108c | 330 | |
78134374 | 331 | switch (type->code ()) |
c906108c SS |
332 | { |
333 | case TYPE_CODE_TYPEDEF: | |
27710edb | 334 | f_type_print_base (type->target_type (), stream, 0, level); |
c906108c SS |
335 | break; |
336 | ||
337 | case TYPE_CODE_ARRAY: | |
27710edb | 338 | f_type_print_base (type->target_type (), stream, show, level); |
7022349d PA |
339 | break; |
340 | case TYPE_CODE_FUNC: | |
27710edb | 341 | if (type->target_type () == NULL) |
7022349d PA |
342 | type_print_unknown_return_type (stream); |
343 | else | |
27710edb | 344 | f_type_print_base (type->target_type (), stream, show, level); |
c906108c SS |
345 | break; |
346 | ||
c5aa993b | 347 | case TYPE_CODE_PTR: |
6cb06a8c | 348 | gdb_printf (stream, "%*sPTR TO -> ( ", level, ""); |
27710edb | 349 | f_type_print_base (type->target_type (), stream, show, 0); |
7e86466e RH |
350 | break; |
351 | ||
352 | case TYPE_CODE_REF: | |
6cb06a8c | 353 | gdb_printf (stream, "%*sREF TO -> ( ", level, ""); |
27710edb | 354 | f_type_print_base (type->target_type (), stream, show, 0); |
c906108c SS |
355 | break; |
356 | ||
357 | case TYPE_CODE_VOID: | |
bbe75b9d | 358 | { |
8ee511af | 359 | struct type *void_type = builtin_f_type (type->arch ())->builtin_void; |
6cb06a8c | 360 | gdb_printf (stream, "%*s%s", level, "", void_type->name ()); |
bbe75b9d | 361 | } |
c906108c SS |
362 | break; |
363 | ||
364 | case TYPE_CODE_UNDEF: | |
6cb06a8c | 365 | gdb_printf (stream, "%*sstruct <unknown>", level, ""); |
c906108c SS |
366 | break; |
367 | ||
368 | case TYPE_CODE_ERROR: | |
6cb06a8c | 369 | gdb_printf (stream, "%*s%s", level, "", TYPE_ERROR_NAME (type)); |
c906108c SS |
370 | break; |
371 | ||
372 | case TYPE_CODE_RANGE: | |
0963b4bd | 373 | /* This should not occur. */ |
6cb06a8c | 374 | gdb_printf (stream, "%*s<range type>", level, ""); |
c906108c SS |
375 | break; |
376 | ||
377 | case TYPE_CODE_CHAR: | |
c906108c SS |
378 | case TYPE_CODE_INT: |
379 | /* There may be some character types that attempt to come | |
dda83cd7 SM |
380 | through as TYPE_CODE_INT since dbxstclass.h is so |
381 | C-oriented, we must change these to "character" from "char". */ | |
c906108c | 382 | |
7d93a1e0 | 383 | if (strcmp (type->name (), "char") == 0) |
6cb06a8c | 384 | gdb_printf (stream, "%*scharacter", level, ""); |
c906108c SS |
385 | else |
386 | goto default_case; | |
387 | break; | |
388 | ||
c906108c | 389 | case TYPE_CODE_STRING: |
3dcc261c AB |
390 | /* Strings may have dynamic upperbounds (lengths) like arrays. We |
391 | check specifically for the PROP_CONST case to indicate that the | |
392 | dynamic type has been resolved. If we arrive here having been | |
393 | asked to print the type of a value with a dynamic type then the | |
394 | bounds will not have been resolved. */ | |
c906108c | 395 | |
9c0fb734 | 396 | if (type->bounds ()->high.is_constant ()) |
c906108c | 397 | { |
2880242d KS |
398 | LONGEST upper_bound = f77_get_upperbound (type); |
399 | ||
6cb06a8c | 400 | gdb_printf (stream, "character*%s", pulongest (upper_bound)); |
c906108c | 401 | } |
3dcc261c | 402 | else |
6cb06a8c | 403 | gdb_printf (stream, "%*scharacter*(*)", level, ""); |
c906108c SS |
404 | break; |
405 | ||
2a5e440c | 406 | case TYPE_CODE_STRUCT: |
9eec4d1e | 407 | case TYPE_CODE_UNION: |
e9512253 | 408 | case TYPE_CODE_NAMELIST: |
78134374 | 409 | if (type->code () == TYPE_CODE_UNION) |
110aae55 | 410 | gdb_printf (stream, "%*sType, C_Union ::", level, ""); |
9eec4d1e | 411 | else |
110aae55 BH |
412 | gdb_printf (stream, "%*sType", level, ""); |
413 | ||
414 | if (show > 0) | |
415 | f_type_print_derivation_info (type, stream); | |
416 | ||
417 | gdb_puts (" ", stream); | |
418 | ||
0426ad51 | 419 | gdb_puts (type->name (), stream); |
110aae55 | 420 | |
9b2db1fd | 421 | /* According to the definition, |
dda83cd7 | 422 | we only print structure elements in case show > 0. */ |
9b2db1fd | 423 | if (show > 0) |
2a5e440c | 424 | { |
0426ad51 | 425 | gdb_puts ("\n", stream); |
1f704f76 | 426 | for (index = 0; index < type->num_fields (); index++) |
9b2db1fd | 427 | { |
940da03e | 428 | f_type_print_base (type->field (index).type (), stream, |
e188eb36 | 429 | show - 1, level + 4); |
0426ad51 | 430 | gdb_puts (" :: ", stream); |
33d16dd9 | 431 | fputs_styled (type->field (index).name (), |
3f0cbb04 | 432 | variable_name_style.style (), stream); |
940da03e | 433 | f_type_print_varspec_suffix (type->field (index).type (), |
584a927c | 434 | stream, show - 1, 0, 0, 0, false); |
0426ad51 | 435 | gdb_puts ("\n", stream); |
9b2db1fd | 436 | } |
6cb06a8c | 437 | gdb_printf (stream, "%*sEnd Type ", level, ""); |
0426ad51 | 438 | gdb_puts (type->name (), stream); |
9b2db1fd | 439 | } |
2a5e440c WZ |
440 | break; |
441 | ||
f55ee35c | 442 | case TYPE_CODE_MODULE: |
6cb06a8c | 443 | gdb_printf (stream, "%*smodule %s", level, "", type->name ()); |
f55ee35c JK |
444 | break; |
445 | ||
c906108c SS |
446 | default_case: |
447 | default: | |
448 | /* Handle types not explicitly handled by the other cases, | |
dda83cd7 SM |
449 | such as fundamental types. For these, just print whatever |
450 | the type name is, as recorded in the type itself. If there | |
451 | is no type name, then complain. */ | |
7d93a1e0 | 452 | if (type->name () != NULL) |
6cb06a8c | 453 | gdb_printf (stream, "%*s%s", level, "", type->name ()); |
c906108c | 454 | else |
78134374 | 455 | error (_("Invalid type code (%d) in symbol table."), type->code ()); |
c906108c SS |
456 | break; |
457 | } | |
bc68014d AB |
458 | |
459 | if (TYPE_IS_ALLOCATABLE (type)) | |
6cb06a8c | 460 | gdb_printf (stream, ", allocatable"); |
c906108c | 461 | } |