]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/f-typeprint.c
* gdb.cp/classes.exp (test_ptype_class_objects): Remove
[thirdparty/binutils-gdb.git] / gdb / f-typeprint.c
CommitLineData
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 (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
0963b4bd 38#if 0 /* Currently unused. */
d9fcf2fb 39static void f_type_print_args (struct type *, struct ui_file *);
c906108c
SS
40#endif
41
0311118f 42static void f_type_print_varspec_suffix (struct type *, struct ui_file *, int,
d9fcf2fb 43 int, int, int);
c906108c 44
d9fcf2fb
JM
45void f_type_print_varspec_prefix (struct type *, struct ui_file *,
46 int, int);
c906108c 47
d9fcf2fb 48void 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
53void
25b524e8 54f_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
93void
fba45db2
KB
94f_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:
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
c5aa993b 139 gcc -Wall will reveal any types that haven't been handled. */
c906108c
SS
140 break;
141 }
142}
143
c906108c
SS
144/* Print any array sizes, function arguments or close parentheses
145 needed after the variable name (to describe its type).
146 Args work like c_type_print_varspec_prefix. */
147
148static void
fba45db2 149f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
0311118f
JK
150 int show, int passed_a_ptr, int demangled_args,
151 int arrayprint_recurse_level)
c906108c
SS
152{
153 int upper_bound, lower_bound;
9216103f 154
0311118f
JK
155 /* No static variables are permitted as an error call may occur during
156 execution of this function. */
c906108c
SS
157
158 if (type == 0)
159 return;
160
161 if (TYPE_NAME (type) && show <= 0)
162 return;
163
164 QUIT;
165
166 switch (TYPE_CODE (type))
167 {
168 case TYPE_CODE_ARRAY:
169 arrayprint_recurse_level++;
170
171 if (arrayprint_recurse_level == 1)
c5aa993b 172 fprintf_filtered (stream, "(");
c906108c
SS
173
174 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
0311118f
JK
175 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0,
176 arrayprint_recurse_level);
c906108c 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
0963b4bd 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)
0311118f
JK
194 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0,
195 arrayprint_recurse_level);
c906108c
SS
196 if (arrayprint_recurse_level == 1)
197 fprintf_filtered (stream, ")");
198 else
c5aa993b 199 fprintf_filtered (stream, ",");
c906108c
SS
200 arrayprint_recurse_level--;
201 break;
202
203 case TYPE_CODE_PTR:
204 case TYPE_CODE_REF:
0311118f
JK
205 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0,
206 arrayprint_recurse_level);
c5aa993b 207 fprintf_filtered (stream, ")");
c906108c
SS
208 break;
209
210 case TYPE_CODE_FUNC:
211 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
0311118f 212 passed_a_ptr, 0, arrayprint_recurse_level);
c906108c
SS
213 if (passed_a_ptr)
214 fprintf_filtered (stream, ")");
215
216 fprintf_filtered (stream, "()");
217 break;
218
219 case TYPE_CODE_UNDEF:
220 case TYPE_CODE_STRUCT:
221 case TYPE_CODE_UNION:
222 case TYPE_CODE_ENUM:
223 case TYPE_CODE_INT:
224 case TYPE_CODE_FLT:
225 case TYPE_CODE_VOID:
226 case TYPE_CODE_ERROR:
227 case TYPE_CODE_CHAR:
228 case TYPE_CODE_BOOL:
229 case TYPE_CODE_SET:
230 case TYPE_CODE_RANGE:
231 case TYPE_CODE_STRING:
c906108c 232 case TYPE_CODE_METHOD:
c906108c
SS
233 case TYPE_CODE_COMPLEX:
234 case TYPE_CODE_TYPEDEF:
235 /* These types do not need a suffix. They are listed so that
c5aa993b 236 gcc -Wall will report types that may not have been considered. */
c906108c
SS
237 break;
238 }
239}
240
c906108c
SS
241/* Print the name of the type (or the ultimate pointer target,
242 function value or array element), or the description of a
243 structure or union.
244
245 SHOW nonzero means don't print this type as just its name;
246 show its real definition even if it has a name.
247 SHOW zero means print just typename or struct tag if there is one
248 SHOW negative means abbreviate structure elements.
249 SHOW is decremented for printing of structure elements.
250
251 LEVEL is the depth to indent by.
252 We increase it for some recursive calls. */
253
254void
fba45db2
KB
255f_type_print_base (struct type *type, struct ui_file *stream, int show,
256 int level)
c906108c 257{
c906108c 258 int upper_bound;
2a5e440c
WZ
259 int index;
260
c906108c
SS
261 QUIT;
262
263 wrap_here (" ");
264 if (type == NULL)
265 {
266 fputs_filtered ("<type unknown>", stream);
267 return;
268 }
269
270 /* When SHOW is zero or less, and there is a valid type name, then always
0963b4bd 271 just print the type name directly from the type. */
c906108c
SS
272
273 if ((show <= 0) && (TYPE_NAME (type) != NULL))
274 {
c244f7a6 275 fputs_filtered (TYPE_NAME (type), stream);
c906108c
SS
276 return;
277 }
278
279 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
280 CHECK_TYPEDEF (type);
281
282 switch (TYPE_CODE (type))
283 {
284 case TYPE_CODE_TYPEDEF:
285 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
286 break;
287
288 case TYPE_CODE_ARRAY:
289 case TYPE_CODE_FUNC:
290 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
291 break;
292
c5aa993b 293 case TYPE_CODE_PTR:
c906108c
SS
294 fprintf_filtered (stream, "PTR TO -> ( ");
295 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
7e86466e
RH
296 break;
297
298 case TYPE_CODE_REF:
299 fprintf_filtered (stream, "REF TO -> ( ");
300 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
c906108c
SS
301 break;
302
303 case TYPE_CODE_VOID:
2a5e440c 304 fprintfi_filtered (level, stream, "VOID");
c906108c
SS
305 break;
306
307 case TYPE_CODE_UNDEF:
2a5e440c 308 fprintfi_filtered (level, stream, "struct <unknown>");
c906108c
SS
309 break;
310
311 case TYPE_CODE_ERROR:
b00fdb78 312 fprintfi_filtered (level, stream, "%s", TYPE_ERROR_NAME (type));
c906108c
SS
313 break;
314
315 case TYPE_CODE_RANGE:
0963b4bd 316 /* This should not occur. */
2a5e440c 317 fprintfi_filtered (level, stream, "<range type>");
c906108c
SS
318 break;
319
320 case TYPE_CODE_CHAR:
c906108c
SS
321 case TYPE_CODE_INT:
322 /* There may be some character types that attempt to come
323 through as TYPE_CODE_INT since dbxstclass.h is so
324 C-oriented, we must change these to "character" from "char". */
325
bde58177 326 if (strcmp (TYPE_NAME (type), "char") == 0)
2a5e440c 327 fprintfi_filtered (level, stream, "character");
c906108c
SS
328 else
329 goto default_case;
330 break;
331
c906108c 332 case TYPE_CODE_STRING:
0963b4bd 333 /* Strings may have dynamic upperbounds (lengths) like arrays. */
c906108c 334
d78df370 335 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2a5e440c 336 fprintfi_filtered (level, stream, "character*(*)");
c906108c
SS
337 else
338 {
d78df370
JK
339 upper_bound = f77_get_upperbound (type);
340 fprintf_filtered (stream, "character*%d", upper_bound);
c906108c
SS
341 }
342 break;
343
2a5e440c 344 case TYPE_CODE_STRUCT:
9eec4d1e
MD
345 case TYPE_CODE_UNION:
346 if (TYPE_CODE (type) == TYPE_CODE_UNION)
347 fprintfi_filtered (level, stream, "Type, C_Union :: ");
348 else
349 fprintfi_filtered (level, stream, "Type ");
2a5e440c
WZ
350 fputs_filtered (TYPE_TAG_NAME (type), stream);
351 fputs_filtered ("\n", stream);
352 for (index = 0; index < TYPE_NFIELDS (type); index++)
353 {
9eec4d1e
MD
354 f_type_print_base (TYPE_FIELD_TYPE (type, index), stream, show,
355 level + 4);
2a5e440c 356 fputs_filtered (" :: ", stream);
60023297 357 fputs_filtered (TYPE_FIELD_NAME (type, index), stream);
9eec4d1e 358 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index),
0311118f 359 stream, 0, 0, 0, 0);
2a5e440c
WZ
360 fputs_filtered ("\n", stream);
361 }
362 fprintfi_filtered (level, stream, "End Type ");
363 fputs_filtered (TYPE_TAG_NAME (type), stream);
364 break;
365
f55ee35c
JK
366 case TYPE_CODE_MODULE:
367 fprintfi_filtered (level, stream, "module %s", TYPE_TAG_NAME (type));
368 break;
369
c906108c
SS
370 default_case:
371 default:
372 /* Handle types not explicitly handled by the other cases,
c5aa993b
JM
373 such as fundamental types. For these, just print whatever
374 the type name is, as recorded in the type itself. If there
0963b4bd 375 is no type name, then complain. */
c906108c 376 if (TYPE_NAME (type) != NULL)
848359ac 377 fprintfi_filtered (level, stream, "%s", TYPE_NAME (type));
c906108c 378 else
8a3fe4f8 379 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type));
c906108c
SS
380 break;
381 }
382}