1 /* Support for printing Fortran types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 2000,
4 Free Software Foundation, Inc.
5 Contributed by Motorola. Adapted from the C version by Farooq Butt
8 This file is part of GDB.
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
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
26 #include "gdb_obstack.h"
30 #include "expression.h"
36 #include "gdb_string.h"
39 #if 0 /* Currently unused */
40 static void f_type_print_args (struct type *, struct ui_file *);
43 static void print_equivalent_f77_float_type (struct type *,
46 static void f_type_print_varspec_suffix (struct type *, struct ui_file *,
49 void f_type_print_varspec_prefix (struct type *, struct ui_file *,
52 void f_type_print_base (struct type *, struct ui_file *, int, int);
55 /* LEVEL is the depth to indent lines by. */
58 f_print_type (struct type *type, char *varstring, struct ui_file *stream,
61 register enum type_code code;
64 f_type_print_base (type, stream, show, level);
65 code = TYPE_CODE (type);
66 if ((varstring != NULL && *varstring != '\0')
68 /* Need a space if going to print stars or brackets;
69 but not if we will print just a type name. */
70 ((show > 0 || TYPE_NAME (type) == 0)
72 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
73 || code == TYPE_CODE_METHOD
74 || code == TYPE_CODE_ARRAY
75 || code == TYPE_CODE_MEMBER
76 || code == TYPE_CODE_REF)))
77 fputs_filtered (" ", stream);
78 f_type_print_varspec_prefix (type, stream, show, 0);
80 fputs_filtered (varstring, stream);
82 /* For demangled function names, we have the arglist as part of the name,
83 so don't print an additional pair of ()'s */
85 demangled_args = varstring[strlen (varstring) - 1] == ')';
86 f_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
89 /* Print any asterisks or open-parentheses needed before the
90 variable name (to describe its type).
92 On outermost call, pass 0 for PASSED_A_PTR.
93 On outermost call, SHOW > 0 means should ignore
94 any typename for TYPE and show its details.
95 SHOW is always zero on recursive calls. */
98 f_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
99 int show, int passed_a_ptr)
104 if (TYPE_NAME (type) && show <= 0)
109 switch (TYPE_CODE (type))
112 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
116 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
118 fprintf_filtered (stream, "(");
121 case TYPE_CODE_ARRAY:
122 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
125 case TYPE_CODE_UNDEF:
126 case TYPE_CODE_STRUCT:
127 case TYPE_CODE_UNION:
132 case TYPE_CODE_ERROR:
136 case TYPE_CODE_RANGE:
137 case TYPE_CODE_STRING:
138 case TYPE_CODE_BITSTRING:
139 case TYPE_CODE_METHOD:
140 case TYPE_CODE_MEMBER:
142 case TYPE_CODE_COMPLEX:
143 case TYPE_CODE_TYPEDEF:
144 /* These types need no prefix. They are listed here so that
145 gcc -Wall will reveal any types that haven't been handled. */
150 /* Print any array sizes, function arguments or close parentheses
151 needed after the variable name (to describe its type).
152 Args work like c_type_print_varspec_prefix. */
155 f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
156 int show, int passed_a_ptr, int demangled_args)
158 int upper_bound, lower_bound;
159 int lower_bound_was_default = 0;
160 static int arrayprint_recurse_level = 0;
166 if (TYPE_NAME (type) && show <= 0)
171 switch (TYPE_CODE (type))
173 case TYPE_CODE_ARRAY:
174 arrayprint_recurse_level++;
176 if (arrayprint_recurse_level == 1)
177 fprintf_filtered (stream, "(");
179 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
180 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
182 retcode = f77_get_dynamic_lowerbound (type, &lower_bound);
184 lower_bound_was_default = 0;
186 if (retcode == BOUND_FETCH_ERROR)
187 fprintf_filtered (stream, "???");
188 else if (lower_bound == 1) /* The default */
189 lower_bound_was_default = 1;
191 fprintf_filtered (stream, "%d", lower_bound);
193 if (lower_bound_was_default)
194 lower_bound_was_default = 0;
196 fprintf_filtered (stream, ":");
198 /* Make sure that, if we have an assumed size array, we
199 print out a warning and print the upperbound as '*' */
201 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
202 fprintf_filtered (stream, "*");
205 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
207 if (retcode == BOUND_FETCH_ERROR)
208 fprintf_filtered (stream, "???");
210 fprintf_filtered (stream, "%d", upper_bound);
213 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
214 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
215 if (arrayprint_recurse_level == 1)
216 fprintf_filtered (stream, ")");
218 fprintf_filtered (stream, ",");
219 arrayprint_recurse_level--;
224 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
225 fprintf_filtered (stream, ")");
229 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
232 fprintf_filtered (stream, ")");
234 fprintf_filtered (stream, "()");
237 case TYPE_CODE_UNDEF:
238 case TYPE_CODE_STRUCT:
239 case TYPE_CODE_UNION:
244 case TYPE_CODE_ERROR:
248 case TYPE_CODE_RANGE:
249 case TYPE_CODE_STRING:
250 case TYPE_CODE_BITSTRING:
251 case TYPE_CODE_METHOD:
252 case TYPE_CODE_MEMBER:
253 case TYPE_CODE_COMPLEX:
254 case TYPE_CODE_TYPEDEF:
255 /* These types do not need a suffix. They are listed so that
256 gcc -Wall will report types that may not have been considered. */
262 print_equivalent_f77_float_type (struct type *type, struct ui_file *stream)
264 /* Override type name "float" and make it the
265 appropriate real. XLC stupidly outputs -12 as a type
266 for real when it really should be outputting -18 */
268 fprintf_filtered (stream, "real*%d", TYPE_LENGTH (type));
271 /* Print the name of the type (or the ultimate pointer target,
272 function value or array element), or the description of a
275 SHOW nonzero means don't print this type as just its name;
276 show its real definition even if it has a name.
277 SHOW zero means print just typename or struct tag if there is one
278 SHOW negative means abbreviate structure elements.
279 SHOW is decremented for printing of structure elements.
281 LEVEL is the depth to indent by.
282 We increase it for some recursive calls. */
285 f_type_print_base (struct type *type, struct ui_file *stream, int show,
296 fputs_filtered ("<type unknown>", stream);
300 /* When SHOW is zero or less, and there is a valid type name, then always
301 just print the type name directly from the type. */
303 if ((show <= 0) && (TYPE_NAME (type) != NULL))
305 if (TYPE_CODE (type) == TYPE_CODE_FLT)
306 print_equivalent_f77_float_type (type, stream);
308 fputs_filtered (TYPE_NAME (type), stream);
312 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
313 CHECK_TYPEDEF (type);
315 switch (TYPE_CODE (type))
317 case TYPE_CODE_TYPEDEF:
318 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
321 case TYPE_CODE_ARRAY:
323 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
327 fprintf_filtered (stream, "PTR TO -> ( ");
328 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
332 fprintf_filtered (stream, "VOID");
335 case TYPE_CODE_UNDEF:
336 fprintf_filtered (stream, "struct <unknown>");
339 case TYPE_CODE_ERROR:
340 fprintf_filtered (stream, "<unknown type>");
343 case TYPE_CODE_RANGE:
344 /* This should not occur */
345 fprintf_filtered (stream, "<range type>");
349 /* Override name "char" and make it "character" */
350 fprintf_filtered (stream, "character");
354 /* There may be some character types that attempt to come
355 through as TYPE_CODE_INT since dbxstclass.h is so
356 C-oriented, we must change these to "character" from "char". */
358 if (STREQ (TYPE_NAME (type), "char"))
359 fprintf_filtered (stream, "character");
364 case TYPE_CODE_COMPLEX:
365 fprintf_filtered (stream, "complex*%d", TYPE_LENGTH (type));
369 print_equivalent_f77_float_type (type, stream);
372 case TYPE_CODE_STRING:
373 /* Strings may have dynamic upperbounds (lengths) like arrays. */
375 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
376 fprintf_filtered (stream, "character*(*)");
379 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
381 if (retcode == BOUND_FETCH_ERROR)
382 fprintf_filtered (stream, "character*???");
384 fprintf_filtered (stream, "character*%d", upper_bound);
390 /* Handle types not explicitly handled by the other cases,
391 such as fundamental types. For these, just print whatever
392 the type name is, as recorded in the type itself. If there
393 is no type name, then complain. */
394 if (TYPE_NAME (type) != NULL)
395 fputs_filtered (TYPE_NAME (type), stream);
397 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));