* f-typeprint.c (print_equivalent_f77_float_type): Remove function.
[deliverable/binutils-gdb.git] / gdb / f-typeprint.c
1 /* Support for printing Fortran types for GDB, the GNU debugger.
2
3 Copyright (C) 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002, 2003, 2006, 2007 Free Software Foundation, Inc.
5
6 Contributed by Motorola. Adapted from the C version by Farooq Butt
7 (fmbutt@engage.sps.mot.com).
8
9 This file is part of GDB.
10
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
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
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.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23
24 #include "defs.h"
25 #include "gdb_obstack.h"
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"
33 #include "f-lang.h"
34
35 #include "gdb_string.h"
36 #include <errno.h>
37
38 #if 0 /* Currently unused */
39 static void f_type_print_args (struct type *, struct ui_file *);
40 #endif
41
42 static void f_type_print_varspec_suffix (struct type *, struct ui_file *,
43 int, int, int);
44
45 void f_type_print_varspec_prefix (struct type *, struct ui_file *,
46 int, int);
47
48 void f_type_print_base (struct type *, struct ui_file *, int, int);
49 \f
50
51 /* LEVEL is the depth to indent lines by. */
52
53 void
54 f_print_type (struct type *type, char *varstring, struct ui_file *stream,
55 int show, int level)
56 {
57 enum type_code code;
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 ||
64 /* Need a space if going to print stars or brackets;
65 but not if we will print just a type name. */
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
71 || code == TYPE_CODE_REF)))
72 fputs_filtered (" ", stream);
73 f_type_print_varspec_prefix (type, stream, show, 0);
74
75 fputs_filtered (varstring, stream);
76
77 /* For demangled function names, we have the arglist as part of the name,
78 so don't print an additional pair of ()'s */
79
80 demangled_args = varstring[strlen (varstring) - 1] == ')';
81 f_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
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
93 f_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
94 int show, int passed_a_ptr)
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:
133 case TYPE_CODE_BITSTRING:
134 case TYPE_CODE_METHOD:
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
139 gcc -Wall will reveal any types that haven't been handled. */
140 break;
141 }
142 }
143
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
148 static void
149 f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
150 int show, int passed_a_ptr, int demangled_args)
151 {
152 int upper_bound, lower_bound;
153 int lower_bound_was_default = 0;
154 static int arrayprint_recurse_level = 0;
155 int retcode;
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)
171 fprintf_filtered (stream, "(");
172
173 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
174 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
175
176 retcode = f77_get_dynamic_lowerbound (type, &lower_bound);
177
178 lower_bound_was_default = 0;
179
180 if (retcode == BOUND_FETCH_ERROR)
181 fprintf_filtered (stream, "???");
182 else if (lower_bound == 1) /* The default */
183 lower_bound_was_default = 1;
184 else
185 fprintf_filtered (stream, "%d", lower_bound);
186
187 if (lower_bound_was_default)
188 lower_bound_was_default = 0;
189 else
190 fprintf_filtered (stream, ":");
191
192 /* Make sure that, if we have an assumed size array, we
193 print out a warning and print the upperbound as '*' */
194
195 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
196 fprintf_filtered (stream, "*");
197 else
198 {
199 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
200
201 if (retcode == BOUND_FETCH_ERROR)
202 fprintf_filtered (stream, "???");
203 else
204 fprintf_filtered (stream, "%d", upper_bound);
205 }
206
207 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
208 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
209 if (arrayprint_recurse_level == 1)
210 fprintf_filtered (stream, ")");
211 else
212 fprintf_filtered (stream, ",");
213 arrayprint_recurse_level--;
214 break;
215
216 case TYPE_CODE_PTR:
217 case TYPE_CODE_REF:
218 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
219 fprintf_filtered (stream, ")");
220 break;
221
222 case TYPE_CODE_FUNC:
223 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
224 passed_a_ptr, 0);
225 if (passed_a_ptr)
226 fprintf_filtered (stream, ")");
227
228 fprintf_filtered (stream, "()");
229 break;
230
231 case TYPE_CODE_UNDEF:
232 case TYPE_CODE_STRUCT:
233 case TYPE_CODE_UNION:
234 case TYPE_CODE_ENUM:
235 case TYPE_CODE_INT:
236 case TYPE_CODE_FLT:
237 case TYPE_CODE_VOID:
238 case TYPE_CODE_ERROR:
239 case TYPE_CODE_CHAR:
240 case TYPE_CODE_BOOL:
241 case TYPE_CODE_SET:
242 case TYPE_CODE_RANGE:
243 case TYPE_CODE_STRING:
244 case TYPE_CODE_BITSTRING:
245 case TYPE_CODE_METHOD:
246 case TYPE_CODE_COMPLEX:
247 case TYPE_CODE_TYPEDEF:
248 /* These types do not need a suffix. They are listed so that
249 gcc -Wall will report types that may not have been considered. */
250 break;
251 }
252 }
253
254 /* Print the name of the type (or the ultimate pointer target,
255 function value or array element), or the description of a
256 structure or union.
257
258 SHOW nonzero means don't print this type as just its name;
259 show its real definition even if it has a name.
260 SHOW zero means print just typename or struct tag if there is one
261 SHOW negative means abbreviate structure elements.
262 SHOW is decremented for printing of structure elements.
263
264 LEVEL is the depth to indent by.
265 We increase it for some recursive calls. */
266
267 void
268 f_type_print_base (struct type *type, struct ui_file *stream, int show,
269 int level)
270 {
271 int retcode;
272 int upper_bound;
273
274 int index;
275
276 QUIT;
277
278 wrap_here (" ");
279 if (type == NULL)
280 {
281 fputs_filtered ("<type unknown>", stream);
282 return;
283 }
284
285 /* When SHOW is zero or less, and there is a valid type name, then always
286 just print the type name directly from the type. */
287
288 if ((show <= 0) && (TYPE_NAME (type) != NULL))
289 {
290 fputs_filtered (TYPE_NAME (type), stream);
291 return;
292 }
293
294 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
295 CHECK_TYPEDEF (type);
296
297 switch (TYPE_CODE (type))
298 {
299 case TYPE_CODE_TYPEDEF:
300 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
301 break;
302
303 case TYPE_CODE_ARRAY:
304 case TYPE_CODE_FUNC:
305 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
306 break;
307
308 case TYPE_CODE_PTR:
309 fprintf_filtered (stream, "PTR TO -> ( ");
310 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
311 break;
312
313 case TYPE_CODE_REF:
314 fprintf_filtered (stream, "REF TO -> ( ");
315 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
316 break;
317
318 case TYPE_CODE_VOID:
319 fprintfi_filtered (level, stream, "VOID");
320 break;
321
322 case TYPE_CODE_UNDEF:
323 fprintfi_filtered (level, stream, "struct <unknown>");
324 break;
325
326 case TYPE_CODE_ERROR:
327 fprintfi_filtered (level, stream, "<unknown type>");
328 break;
329
330 case TYPE_CODE_RANGE:
331 /* This should not occur */
332 fprintfi_filtered (level, stream, "<range type>");
333 break;
334
335 case TYPE_CODE_CHAR:
336 /* Override name "char" and make it "character" */
337 fprintfi_filtered (level, stream, "character");
338 break;
339
340 case TYPE_CODE_INT:
341 /* There may be some character types that attempt to come
342 through as TYPE_CODE_INT since dbxstclass.h is so
343 C-oriented, we must change these to "character" from "char". */
344
345 if (strcmp (TYPE_NAME (type), "char") == 0)
346 fprintfi_filtered (level, stream, "character");
347 else
348 goto default_case;
349 break;
350
351 case TYPE_CODE_STRING:
352 /* Strings may have dynamic upperbounds (lengths) like arrays. */
353
354 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
355 fprintfi_filtered (level, stream, "character*(*)");
356 else
357 {
358 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
359
360 if (retcode == BOUND_FETCH_ERROR)
361 fprintf_filtered (stream, "character*???");
362 else
363 fprintf_filtered (stream, "character*%d", upper_bound);
364 }
365 break;
366
367 case TYPE_CODE_STRUCT:
368 fprintfi_filtered (level, stream, "Type ");
369 fputs_filtered (TYPE_TAG_NAME (type), stream);
370 fputs_filtered ("\n", stream);
371 for (index = 0; index < TYPE_NFIELDS (type); index++)
372 {
373 f_print_type (TYPE_FIELD_TYPE (type, index), "", stream, show, level + 4);
374 fputs_filtered (" :: ", stream);
375 fputs_filtered (TYPE_FIELD_NAME (type, index), stream);
376 fputs_filtered ("\n", stream);
377 }
378 fprintfi_filtered (level, stream, "End Type ");
379 fputs_filtered (TYPE_TAG_NAME (type), stream);
380 break;
381
382 default_case:
383 default:
384 /* Handle types not explicitly handled by the other cases,
385 such as fundamental types. For these, just print whatever
386 the type name is, as recorded in the type itself. If there
387 is no type name, then complain. */
388 if (TYPE_NAME (type) != NULL)
389 fprintfi_filtered (level, stream, "%s", TYPE_NAME (type));
390 else
391 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type));
392 break;
393 }
394 }
This page took 0.039557 seconds and 5 git commands to generate.