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