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