]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Fortran types for GDB, the GNU debugger. |
1bac305b | 2 | |
32d0add0 | 3 | Copyright (C) 1986-2015 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" | |
04ea0df1 | 24 | #include "gdb_obstack.h" |
c906108c SS |
25 | #include "bfd.h" |
26 | #include "symtab.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "expression.h" | |
29 | #include "value.h" | |
30 | #include "gdbcore.h" | |
31 | #include "target.h" | |
c906108c | 32 | #include "f-lang.h" |
c906108c | 33 | |
0963b4bd | 34 | #if 0 /* Currently unused. */ |
d9fcf2fb | 35 | static void f_type_print_args (struct type *, struct ui_file *); |
c906108c SS |
36 | #endif |
37 | ||
0311118f | 38 | static void f_type_print_varspec_suffix (struct type *, struct ui_file *, int, |
d9fcf2fb | 39 | int, int, int); |
c906108c | 40 | |
d9fcf2fb JM |
41 | void f_type_print_varspec_prefix (struct type *, struct ui_file *, |
42 | int, int); | |
c906108c | 43 | |
d9fcf2fb | 44 | void f_type_print_base (struct type *, struct ui_file *, int, int); |
c906108c | 45 | \f |
c5aa993b | 46 | |
c906108c SS |
47 | /* LEVEL is the depth to indent lines by. */ |
48 | ||
49 | void | |
25b524e8 | 50 | f_print_type (struct type *type, const char *varstring, struct ui_file *stream, |
79d43c61 | 51 | int show, int level, const struct type_print_options *flags) |
c906108c | 52 | { |
52f0bd74 | 53 | enum type_code code; |
c906108c SS |
54 | int demangled_args; |
55 | ||
56 | f_type_print_base (type, stream, show, level); | |
57 | code = TYPE_CODE (type); | |
58 | if ((varstring != NULL && *varstring != '\0') | |
c5aa993b JM |
59 | /* Need a space if going to print stars or brackets; |
60 | but not if we will print just a type name. */ | |
905e0470 PM |
61 | || ((show > 0 || TYPE_NAME (type) == 0) |
62 | && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
63 | || code == TYPE_CODE_METHOD | |
64 | || code == TYPE_CODE_ARRAY | |
65 | || code == TYPE_CODE_REF))) | |
c906108c SS |
66 | fputs_filtered (" ", stream); |
67 | f_type_print_varspec_prefix (type, stream, show, 0); | |
68 | ||
a7dfd010 MD |
69 | if (varstring != NULL) |
70 | { | |
71 | fputs_filtered (varstring, stream); | |
c906108c | 72 | |
a7dfd010 | 73 | /* For demangled function names, we have the arglist as part of the name, |
0963b4bd | 74 | so don't print an additional pair of ()'s. */ |
c906108c | 75 | |
a7dfd010 | 76 | demangled_args = varstring[strlen (varstring) - 1] == ')'; |
0311118f | 77 | f_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0); |
a7dfd010 | 78 | } |
c906108c SS |
79 | } |
80 | ||
81 | /* Print any asterisks or open-parentheses needed before the | |
82 | variable name (to describe its type). | |
83 | ||
84 | On outermost call, pass 0 for PASSED_A_PTR. | |
85 | On outermost call, SHOW > 0 means should ignore | |
86 | any typename for TYPE and show its details. | |
87 | SHOW is always zero on recursive calls. */ | |
88 | ||
89 | void | |
fba45db2 KB |
90 | f_type_print_varspec_prefix (struct type *type, struct ui_file *stream, |
91 | int show, int passed_a_ptr) | |
c906108c SS |
92 | { |
93 | if (type == 0) | |
94 | return; | |
95 | ||
96 | if (TYPE_NAME (type) && show <= 0) | |
97 | return; | |
98 | ||
99 | QUIT; | |
100 | ||
101 | switch (TYPE_CODE (type)) | |
102 | { | |
103 | case TYPE_CODE_PTR: | |
104 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
105 | break; | |
106 | ||
107 | case TYPE_CODE_FUNC: | |
108 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
109 | if (passed_a_ptr) | |
110 | fprintf_filtered (stream, "("); | |
111 | break; | |
112 | ||
113 | case TYPE_CODE_ARRAY: | |
114 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
115 | break; | |
116 | ||
117 | case TYPE_CODE_UNDEF: | |
118 | case TYPE_CODE_STRUCT: | |
119 | case TYPE_CODE_UNION: | |
120 | case TYPE_CODE_ENUM: | |
121 | case TYPE_CODE_INT: | |
122 | case TYPE_CODE_FLT: | |
123 | case TYPE_CODE_VOID: | |
124 | case TYPE_CODE_ERROR: | |
125 | case TYPE_CODE_CHAR: | |
126 | case TYPE_CODE_BOOL: | |
127 | case TYPE_CODE_SET: | |
128 | case TYPE_CODE_RANGE: | |
129 | case TYPE_CODE_STRING: | |
c906108c | 130 | case TYPE_CODE_METHOD: |
c906108c SS |
131 | case TYPE_CODE_REF: |
132 | case TYPE_CODE_COMPLEX: | |
133 | case TYPE_CODE_TYPEDEF: | |
134 | /* These types need no prefix. They are listed here so that | |
c5aa993b | 135 | gcc -Wall will reveal any types that haven't been handled. */ |
c906108c SS |
136 | break; |
137 | } | |
138 | } | |
139 | ||
c906108c SS |
140 | /* Print any array sizes, function arguments or close parentheses |
141 | needed after the variable name (to describe its type). | |
142 | Args work like c_type_print_varspec_prefix. */ | |
143 | ||
144 | static void | |
fba45db2 | 145 | f_type_print_varspec_suffix (struct type *type, struct ui_file *stream, |
0311118f JK |
146 | int show, int passed_a_ptr, int demangled_args, |
147 | int arrayprint_recurse_level) | |
c906108c SS |
148 | { |
149 | int upper_bound, lower_bound; | |
9216103f | 150 | |
0311118f JK |
151 | /* No static variables are permitted as an error call may occur during |
152 | execution of this function. */ | |
c906108c SS |
153 | |
154 | if (type == 0) | |
155 | return; | |
156 | ||
157 | if (TYPE_NAME (type) && show <= 0) | |
158 | return; | |
159 | ||
160 | QUIT; | |
161 | ||
162 | switch (TYPE_CODE (type)) | |
163 | { | |
164 | case TYPE_CODE_ARRAY: | |
165 | arrayprint_recurse_level++; | |
166 | ||
167 | if (arrayprint_recurse_level == 1) | |
c5aa993b | 168 | fprintf_filtered (stream, "("); |
c906108c SS |
169 | |
170 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY) | |
0311118f JK |
171 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0, |
172 | arrayprint_recurse_level); | |
c906108c | 173 | |
d78df370 JK |
174 | lower_bound = f77_get_lowerbound (type); |
175 | if (lower_bound != 1) /* Not the default. */ | |
176 | fprintf_filtered (stream, "%d:", lower_bound); | |
c906108c SS |
177 | |
178 | /* Make sure that, if we have an assumed size array, we | |
0963b4bd | 179 | print out a warning and print the upperbound as '*'. */ |
c906108c | 180 | |
d78df370 | 181 | if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) |
c906108c | 182 | fprintf_filtered (stream, "*"); |
c5aa993b JM |
183 | else |
184 | { | |
d78df370 JK |
185 | upper_bound = f77_get_upperbound (type); |
186 | fprintf_filtered (stream, "%d", upper_bound); | |
c5aa993b | 187 | } |
c906108c SS |
188 | |
189 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY) | |
0311118f JK |
190 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0, |
191 | arrayprint_recurse_level); | |
c906108c SS |
192 | if (arrayprint_recurse_level == 1) |
193 | fprintf_filtered (stream, ")"); | |
194 | else | |
c5aa993b | 195 | fprintf_filtered (stream, ","); |
c906108c SS |
196 | arrayprint_recurse_level--; |
197 | break; | |
198 | ||
199 | case TYPE_CODE_PTR: | |
200 | case TYPE_CODE_REF: | |
0311118f JK |
201 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0, |
202 | arrayprint_recurse_level); | |
c5aa993b | 203 | fprintf_filtered (stream, ")"); |
c906108c SS |
204 | break; |
205 | ||
206 | case TYPE_CODE_FUNC: | |
207 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
0311118f | 208 | passed_a_ptr, 0, arrayprint_recurse_level); |
c906108c SS |
209 | if (passed_a_ptr) |
210 | fprintf_filtered (stream, ")"); | |
211 | ||
212 | fprintf_filtered (stream, "()"); | |
213 | break; | |
214 | ||
215 | case TYPE_CODE_UNDEF: | |
216 | case TYPE_CODE_STRUCT: | |
217 | case TYPE_CODE_UNION: | |
218 | case TYPE_CODE_ENUM: | |
219 | case TYPE_CODE_INT: | |
220 | case TYPE_CODE_FLT: | |
221 | case TYPE_CODE_VOID: | |
222 | case TYPE_CODE_ERROR: | |
223 | case TYPE_CODE_CHAR: | |
224 | case TYPE_CODE_BOOL: | |
225 | case TYPE_CODE_SET: | |
226 | case TYPE_CODE_RANGE: | |
227 | case TYPE_CODE_STRING: | |
c906108c | 228 | case TYPE_CODE_METHOD: |
c906108c SS |
229 | case TYPE_CODE_COMPLEX: |
230 | case TYPE_CODE_TYPEDEF: | |
231 | /* These types do not need a suffix. They are listed so that | |
c5aa993b | 232 | gcc -Wall will report types that may not have been considered. */ |
c906108c SS |
233 | break; |
234 | } | |
235 | } | |
236 | ||
c906108c SS |
237 | /* Print the name of the type (or the ultimate pointer target, |
238 | function value or array element), or the description of a | |
239 | structure or union. | |
240 | ||
241 | SHOW nonzero means don't print this type as just its name; | |
242 | show its real definition even if it has a name. | |
243 | SHOW zero means print just typename or struct tag if there is one | |
244 | SHOW negative means abbreviate structure elements. | |
245 | SHOW is decremented for printing of structure elements. | |
246 | ||
247 | LEVEL is the depth to indent by. | |
248 | We increase it for some recursive calls. */ | |
249 | ||
250 | void | |
fba45db2 KB |
251 | f_type_print_base (struct type *type, struct ui_file *stream, int show, |
252 | int level) | |
c906108c | 253 | { |
c906108c | 254 | int upper_bound; |
2a5e440c WZ |
255 | int index; |
256 | ||
c906108c SS |
257 | QUIT; |
258 | ||
259 | wrap_here (" "); | |
260 | if (type == NULL) | |
261 | { | |
262 | fputs_filtered ("<type unknown>", stream); | |
263 | return; | |
264 | } | |
265 | ||
266 | /* When SHOW is zero or less, and there is a valid type name, then always | |
0963b4bd | 267 | just print the type name directly from the type. */ |
c906108c SS |
268 | |
269 | if ((show <= 0) && (TYPE_NAME (type) != NULL)) | |
270 | { | |
c244f7a6 | 271 | fputs_filtered (TYPE_NAME (type), stream); |
c906108c SS |
272 | return; |
273 | } | |
274 | ||
275 | if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) | |
f168693b | 276 | type = check_typedef (type); |
c906108c SS |
277 | |
278 | switch (TYPE_CODE (type)) | |
279 | { | |
280 | case TYPE_CODE_TYPEDEF: | |
281 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
282 | break; | |
283 | ||
284 | case TYPE_CODE_ARRAY: | |
285 | case TYPE_CODE_FUNC: | |
286 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
287 | break; | |
288 | ||
c5aa993b | 289 | case TYPE_CODE_PTR: |
c906108c SS |
290 | fprintf_filtered (stream, "PTR TO -> ( "); |
291 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
7e86466e RH |
292 | break; |
293 | ||
294 | case TYPE_CODE_REF: | |
295 | fprintf_filtered (stream, "REF TO -> ( "); | |
296 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
c906108c SS |
297 | break; |
298 | ||
299 | case TYPE_CODE_VOID: | |
2a5e440c | 300 | fprintfi_filtered (level, stream, "VOID"); |
c906108c SS |
301 | break; |
302 | ||
303 | case TYPE_CODE_UNDEF: | |
2a5e440c | 304 | fprintfi_filtered (level, stream, "struct <unknown>"); |
c906108c SS |
305 | break; |
306 | ||
307 | case TYPE_CODE_ERROR: | |
b00fdb78 | 308 | fprintfi_filtered (level, stream, "%s", TYPE_ERROR_NAME (type)); |
c906108c SS |
309 | break; |
310 | ||
311 | case TYPE_CODE_RANGE: | |
0963b4bd | 312 | /* This should not occur. */ |
2a5e440c | 313 | fprintfi_filtered (level, stream, "<range type>"); |
c906108c SS |
314 | break; |
315 | ||
316 | case TYPE_CODE_CHAR: | |
c906108c SS |
317 | case TYPE_CODE_INT: |
318 | /* There may be some character types that attempt to come | |
319 | through as TYPE_CODE_INT since dbxstclass.h is so | |
320 | C-oriented, we must change these to "character" from "char". */ | |
321 | ||
bde58177 | 322 | if (strcmp (TYPE_NAME (type), "char") == 0) |
2a5e440c | 323 | fprintfi_filtered (level, stream, "character"); |
c906108c SS |
324 | else |
325 | goto default_case; | |
326 | break; | |
327 | ||
c906108c | 328 | case TYPE_CODE_STRING: |
0963b4bd | 329 | /* Strings may have dynamic upperbounds (lengths) like arrays. */ |
c906108c | 330 | |
d78df370 | 331 | if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) |
2a5e440c | 332 | fprintfi_filtered (level, stream, "character*(*)"); |
c906108c SS |
333 | else |
334 | { | |
d78df370 JK |
335 | upper_bound = f77_get_upperbound (type); |
336 | fprintf_filtered (stream, "character*%d", upper_bound); | |
c906108c SS |
337 | } |
338 | break; | |
339 | ||
2a5e440c | 340 | case TYPE_CODE_STRUCT: |
9eec4d1e MD |
341 | case TYPE_CODE_UNION: |
342 | if (TYPE_CODE (type) == TYPE_CODE_UNION) | |
343 | fprintfi_filtered (level, stream, "Type, C_Union :: "); | |
344 | else | |
345 | fprintfi_filtered (level, stream, "Type "); | |
2a5e440c WZ |
346 | fputs_filtered (TYPE_TAG_NAME (type), stream); |
347 | fputs_filtered ("\n", stream); | |
348 | for (index = 0; index < TYPE_NFIELDS (type); index++) | |
349 | { | |
9eec4d1e MD |
350 | f_type_print_base (TYPE_FIELD_TYPE (type, index), stream, show, |
351 | level + 4); | |
2a5e440c | 352 | fputs_filtered (" :: ", stream); |
60023297 | 353 | fputs_filtered (TYPE_FIELD_NAME (type, index), stream); |
9eec4d1e | 354 | f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index), |
0311118f | 355 | stream, 0, 0, 0, 0); |
2a5e440c WZ |
356 | fputs_filtered ("\n", stream); |
357 | } | |
358 | fprintfi_filtered (level, stream, "End Type "); | |
359 | fputs_filtered (TYPE_TAG_NAME (type), stream); | |
360 | break; | |
361 | ||
f55ee35c JK |
362 | case TYPE_CODE_MODULE: |
363 | fprintfi_filtered (level, stream, "module %s", TYPE_TAG_NAME (type)); | |
364 | break; | |
365 | ||
c906108c SS |
366 | default_case: |
367 | default: | |
368 | /* Handle types not explicitly handled by the other cases, | |
c5aa993b JM |
369 | such as fundamental types. For these, just print whatever |
370 | the type name is, as recorded in the type itself. If there | |
0963b4bd | 371 | is no type name, then complain. */ |
c906108c | 372 | if (TYPE_NAME (type) != NULL) |
848359ac | 373 | fprintfi_filtered (level, stream, "%s", TYPE_NAME (type)); |
c906108c | 374 | else |
8a3fe4f8 | 375 | error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type)); |
c906108c SS |
376 | break; |
377 | } | |
378 | } |