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