Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Fortran types for GDB, the GNU debugger. |
1bac305b | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 2000, |
9b254dd1 | 4 | 2001, 2002, 2003, 2006, 2007, 2008 Free Software Foundation, Inc. |
1bac305b | 5 | |
c906108c SS |
6 | Contributed by Motorola. Adapted from the C version by Farooq Butt |
7 | (fmbutt@engage.sps.mot.com). | |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 14 | (at your option) any later version. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b | 21 | You should have received a copy of the GNU General Public License |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
23 | |
24 | #include "defs.h" | |
04ea0df1 | 25 | #include "gdb_obstack.h" |
c906108c SS |
26 | #include "bfd.h" |
27 | #include "symtab.h" | |
28 | #include "gdbtypes.h" | |
29 | #include "expression.h" | |
30 | #include "value.h" | |
31 | #include "gdbcore.h" | |
32 | #include "target.h" | |
c906108c | 33 | #include "f-lang.h" |
c906108c SS |
34 | |
35 | #include "gdb_string.h" | |
36 | #include <errno.h> | |
37 | ||
c5aa993b | 38 | #if 0 /* Currently unused */ |
d9fcf2fb | 39 | static void f_type_print_args (struct type *, struct ui_file *); |
c906108c SS |
40 | #endif |
41 | ||
d9fcf2fb JM |
42 | static void f_type_print_varspec_suffix (struct type *, struct ui_file *, |
43 | int, int, int); | |
c906108c | 44 | |
d9fcf2fb JM |
45 | void f_type_print_varspec_prefix (struct type *, struct ui_file *, |
46 | int, int); | |
c906108c | 47 | |
d9fcf2fb | 48 | void f_type_print_base (struct type *, struct ui_file *, int, int); |
c906108c | 49 | \f |
c5aa993b | 50 | |
c906108c SS |
51 | /* LEVEL is the depth to indent lines by. */ |
52 | ||
53 | void | |
fba45db2 KB |
54 | f_print_type (struct type *type, char *varstring, struct ui_file *stream, |
55 | int show, int level) | |
c906108c | 56 | { |
52f0bd74 | 57 | enum type_code code; |
c906108c SS |
58 | int demangled_args; |
59 | ||
60 | f_type_print_base (type, stream, show, level); | |
61 | code = TYPE_CODE (type); | |
62 | if ((varstring != NULL && *varstring != '\0') | |
63 | || | |
c5aa993b JM |
64 | /* Need a space if going to print stars or brackets; |
65 | but not if we will print just a type name. */ | |
c906108c SS |
66 | ((show > 0 || TYPE_NAME (type) == 0) |
67 | && | |
68 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
69 | || code == TYPE_CODE_METHOD | |
70 | || code == TYPE_CODE_ARRAY | |
c906108c SS |
71 | || code == TYPE_CODE_REF))) |
72 | fputs_filtered (" ", stream); | |
73 | f_type_print_varspec_prefix (type, stream, show, 0); | |
74 | ||
a7dfd010 MD |
75 | if (varstring != NULL) |
76 | { | |
77 | fputs_filtered (varstring, stream); | |
c906108c | 78 | |
a7dfd010 MD |
79 | /* For demangled function names, we have the arglist as part of the name, |
80 | so don't print an additional pair of ()'s */ | |
c906108c | 81 | |
a7dfd010 MD |
82 | demangled_args = varstring[strlen (varstring) - 1] == ')'; |
83 | f_type_print_varspec_suffix (type, stream, show, 0, demangled_args); | |
84 | } | |
c906108c SS |
85 | } |
86 | ||
87 | /* Print any asterisks or open-parentheses needed before the | |
88 | variable name (to describe its type). | |
89 | ||
90 | On outermost call, pass 0 for PASSED_A_PTR. | |
91 | On outermost call, SHOW > 0 means should ignore | |
92 | any typename for TYPE and show its details. | |
93 | SHOW is always zero on recursive calls. */ | |
94 | ||
95 | void | |
fba45db2 KB |
96 | f_type_print_varspec_prefix (struct type *type, struct ui_file *stream, |
97 | int show, int passed_a_ptr) | |
c906108c SS |
98 | { |
99 | if (type == 0) | |
100 | return; | |
101 | ||
102 | if (TYPE_NAME (type) && show <= 0) | |
103 | return; | |
104 | ||
105 | QUIT; | |
106 | ||
107 | switch (TYPE_CODE (type)) | |
108 | { | |
109 | case TYPE_CODE_PTR: | |
110 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
111 | break; | |
112 | ||
113 | case TYPE_CODE_FUNC: | |
114 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
115 | if (passed_a_ptr) | |
116 | fprintf_filtered (stream, "("); | |
117 | break; | |
118 | ||
119 | case TYPE_CODE_ARRAY: | |
120 | f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
121 | break; | |
122 | ||
123 | case TYPE_CODE_UNDEF: | |
124 | case TYPE_CODE_STRUCT: | |
125 | case TYPE_CODE_UNION: | |
126 | case TYPE_CODE_ENUM: | |
127 | case TYPE_CODE_INT: | |
128 | case TYPE_CODE_FLT: | |
129 | case TYPE_CODE_VOID: | |
130 | case TYPE_CODE_ERROR: | |
131 | case TYPE_CODE_CHAR: | |
132 | case TYPE_CODE_BOOL: | |
133 | case TYPE_CODE_SET: | |
134 | case TYPE_CODE_RANGE: | |
135 | case TYPE_CODE_STRING: | |
136 | case TYPE_CODE_BITSTRING: | |
137 | case TYPE_CODE_METHOD: | |
c906108c SS |
138 | case TYPE_CODE_REF: |
139 | case TYPE_CODE_COMPLEX: | |
140 | case TYPE_CODE_TYPEDEF: | |
141 | /* These types need no prefix. They are listed here so that | |
c5aa993b | 142 | gcc -Wall will reveal any types that haven't been handled. */ |
c906108c SS |
143 | break; |
144 | } | |
145 | } | |
146 | ||
c906108c SS |
147 | /* Print any array sizes, function arguments or close parentheses |
148 | needed after the variable name (to describe its type). | |
149 | Args work like c_type_print_varspec_prefix. */ | |
150 | ||
151 | static void | |
fba45db2 KB |
152 | f_type_print_varspec_suffix (struct type *type, struct ui_file *stream, |
153 | int show, int passed_a_ptr, int demangled_args) | |
c906108c SS |
154 | { |
155 | int upper_bound, lower_bound; | |
c906108c SS |
156 | static int arrayprint_recurse_level = 0; |
157 | int retcode; | |
158 | ||
159 | if (type == 0) | |
160 | return; | |
161 | ||
162 | if (TYPE_NAME (type) && show <= 0) | |
163 | return; | |
164 | ||
165 | QUIT; | |
166 | ||
167 | switch (TYPE_CODE (type)) | |
168 | { | |
169 | case TYPE_CODE_ARRAY: | |
170 | arrayprint_recurse_level++; | |
171 | ||
172 | if (arrayprint_recurse_level == 1) | |
c5aa993b | 173 | fprintf_filtered (stream, "("); |
c906108c SS |
174 | |
175 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY) | |
176 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
177 | ||
d78df370 JK |
178 | lower_bound = f77_get_lowerbound (type); |
179 | if (lower_bound != 1) /* Not the default. */ | |
180 | fprintf_filtered (stream, "%d:", lower_bound); | |
c906108c SS |
181 | |
182 | /* Make sure that, if we have an assumed size array, we | |
c5aa993b | 183 | print out a warning and print the upperbound as '*' */ |
c906108c | 184 | |
d78df370 | 185 | if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) |
c906108c | 186 | fprintf_filtered (stream, "*"); |
c5aa993b JM |
187 | else |
188 | { | |
d78df370 JK |
189 | upper_bound = f77_get_upperbound (type); |
190 | fprintf_filtered (stream, "%d", upper_bound); | |
c5aa993b | 191 | } |
c906108c SS |
192 | |
193 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY) | |
194 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); | |
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: | |
204 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0); | |
c5aa993b | 205 | fprintf_filtered (stream, ")"); |
c906108c SS |
206 | break; |
207 | ||
208 | case TYPE_CODE_FUNC: | |
209 | f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
c5aa993b | 210 | passed_a_ptr, 0); |
c906108c SS |
211 | if (passed_a_ptr) |
212 | fprintf_filtered (stream, ")"); | |
213 | ||
214 | fprintf_filtered (stream, "()"); | |
215 | break; | |
216 | ||
217 | case TYPE_CODE_UNDEF: | |
218 | case TYPE_CODE_STRUCT: | |
219 | case TYPE_CODE_UNION: | |
220 | case TYPE_CODE_ENUM: | |
221 | case TYPE_CODE_INT: | |
222 | case TYPE_CODE_FLT: | |
223 | case TYPE_CODE_VOID: | |
224 | case TYPE_CODE_ERROR: | |
225 | case TYPE_CODE_CHAR: | |
226 | case TYPE_CODE_BOOL: | |
227 | case TYPE_CODE_SET: | |
228 | case TYPE_CODE_RANGE: | |
229 | case TYPE_CODE_STRING: | |
230 | case TYPE_CODE_BITSTRING: | |
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 SS |
256 | { |
257 | int retcode; | |
258 | int upper_bound; | |
259 | ||
2a5e440c WZ |
260 | int index; |
261 | ||
c906108c SS |
262 | QUIT; |
263 | ||
264 | wrap_here (" "); | |
265 | if (type == NULL) | |
266 | { | |
267 | fputs_filtered ("<type unknown>", stream); | |
268 | return; | |
269 | } | |
270 | ||
271 | /* When SHOW is zero or less, and there is a valid type name, then always | |
272 | just print the type name directly from the type. */ | |
273 | ||
274 | if ((show <= 0) && (TYPE_NAME (type) != NULL)) | |
275 | { | |
c244f7a6 | 276 | fputs_filtered (TYPE_NAME (type), stream); |
c906108c SS |
277 | return; |
278 | } | |
279 | ||
280 | if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) | |
281 | CHECK_TYPEDEF (type); | |
282 | ||
283 | switch (TYPE_CODE (type)) | |
284 | { | |
285 | case TYPE_CODE_TYPEDEF: | |
286 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
287 | break; | |
288 | ||
289 | case TYPE_CODE_ARRAY: | |
290 | case TYPE_CODE_FUNC: | |
291 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
292 | break; | |
293 | ||
c5aa993b | 294 | case TYPE_CODE_PTR: |
c906108c SS |
295 | fprintf_filtered (stream, "PTR TO -> ( "); |
296 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
7e86466e RH |
297 | break; |
298 | ||
299 | case TYPE_CODE_REF: | |
300 | fprintf_filtered (stream, "REF TO -> ( "); | |
301 | f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); | |
c906108c SS |
302 | break; |
303 | ||
304 | case TYPE_CODE_VOID: | |
2a5e440c | 305 | fprintfi_filtered (level, stream, "VOID"); |
c906108c SS |
306 | break; |
307 | ||
308 | case TYPE_CODE_UNDEF: | |
2a5e440c | 309 | fprintfi_filtered (level, stream, "struct <unknown>"); |
c906108c SS |
310 | break; |
311 | ||
312 | case TYPE_CODE_ERROR: | |
2a5e440c | 313 | fprintfi_filtered (level, stream, "<unknown type>"); |
c906108c SS |
314 | break; |
315 | ||
316 | case TYPE_CODE_RANGE: | |
317 | /* This should not occur */ | |
2a5e440c | 318 | fprintfi_filtered (level, stream, "<range type>"); |
c906108c SS |
319 | break; |
320 | ||
321 | case TYPE_CODE_CHAR: | |
322 | /* Override name "char" and make it "character" */ | |
2a5e440c | 323 | fprintfi_filtered (level, stream, "character"); |
c906108c SS |
324 | break; |
325 | ||
326 | case TYPE_CODE_INT: | |
327 | /* There may be some character types that attempt to come | |
328 | through as TYPE_CODE_INT since dbxstclass.h is so | |
329 | C-oriented, we must change these to "character" from "char". */ | |
330 | ||
bde58177 | 331 | if (strcmp (TYPE_NAME (type), "char") == 0) |
2a5e440c | 332 | fprintfi_filtered (level, stream, "character"); |
c906108c SS |
333 | else |
334 | goto default_case; | |
335 | break; | |
336 | ||
c906108c SS |
337 | case TYPE_CODE_STRING: |
338 | /* Strings may have dynamic upperbounds (lengths) like arrays. */ | |
339 | ||
d78df370 | 340 | if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) |
2a5e440c | 341 | fprintfi_filtered (level, stream, "character*(*)"); |
c906108c SS |
342 | else |
343 | { | |
d78df370 JK |
344 | upper_bound = f77_get_upperbound (type); |
345 | fprintf_filtered (stream, "character*%d", upper_bound); | |
c906108c SS |
346 | } |
347 | break; | |
348 | ||
2a5e440c | 349 | case TYPE_CODE_STRUCT: |
9eec4d1e MD |
350 | case TYPE_CODE_UNION: |
351 | if (TYPE_CODE (type) == TYPE_CODE_UNION) | |
352 | fprintfi_filtered (level, stream, "Type, C_Union :: "); | |
353 | else | |
354 | fprintfi_filtered (level, stream, "Type "); | |
2a5e440c WZ |
355 | fputs_filtered (TYPE_TAG_NAME (type), stream); |
356 | fputs_filtered ("\n", stream); | |
357 | for (index = 0; index < TYPE_NFIELDS (type); index++) | |
358 | { | |
9eec4d1e MD |
359 | f_type_print_base (TYPE_FIELD_TYPE (type, index), stream, show, |
360 | level + 4); | |
2a5e440c | 361 | fputs_filtered (" :: ", stream); |
9eec4d1e MD |
362 | fprintfi_filtered (level, stream, "%s", |
363 | TYPE_FIELD_NAME (type, index)); | |
364 | f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index), | |
365 | stream, 0, 0, 0); | |
2a5e440c WZ |
366 | fputs_filtered ("\n", stream); |
367 | } | |
368 | fprintfi_filtered (level, stream, "End Type "); | |
369 | fputs_filtered (TYPE_TAG_NAME (type), stream); | |
370 | break; | |
371 | ||
c906108c SS |
372 | default_case: |
373 | default: | |
374 | /* Handle types not explicitly handled by the other cases, | |
c5aa993b JM |
375 | such as fundamental types. For these, just print whatever |
376 | the type name is, as recorded in the type itself. If there | |
377 | is no type name, then complain. */ | |
c906108c | 378 | if (TYPE_NAME (type) != NULL) |
848359ac | 379 | fprintfi_filtered (level, stream, "%s", TYPE_NAME (type)); |
c906108c | 380 | else |
8a3fe4f8 | 381 | error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type)); |
c906108c SS |
382 | break; |
383 | } | |
384 | } |