1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002, 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Contributed by Motorola. Adapted from the C version by Farooq Butt
9 This file is part of GDB.
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.
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.
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/>. */
25 #include "gdb_obstack.h"
29 #include "expression.h"
35 #include "gdb_string.h"
38 #if 0 /* Currently unused */
39 static void f_type_print_args (struct type *, struct ui_file *);
42 static void f_type_print_varspec_suffix (struct type *, struct ui_file *,
45 void f_type_print_varspec_prefix (struct type *, struct ui_file *,
48 void f_type_print_base (struct type *, struct ui_file *, int, int);
51 /* LEVEL is the depth to indent lines by. */
54 f_print_type (struct type *type, char *varstring, struct ui_file *stream,
60 f_type_print_base (type, stream, show, level);
61 code = TYPE_CODE (type);
62 if ((varstring != NULL && *varstring != '\0')
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)
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);
75 if (varstring != NULL)
77 fputs_filtered (varstring, stream);
79 /* For demangled function names, we have the arglist as part of the name,
80 so don't print an additional pair of ()'s */
82 demangled_args = varstring[strlen (varstring) - 1] == ')';
83 f_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
87 /* Print any asterisks or open-parentheses needed before the
88 variable name (to describe its type).
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. */
96 f_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
97 int show, int passed_a_ptr)
102 if (TYPE_NAME (type) && show <= 0)
107 switch (TYPE_CODE (type))
110 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
114 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
116 fprintf_filtered (stream, "(");
119 case TYPE_CODE_ARRAY:
120 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
123 case TYPE_CODE_UNDEF:
124 case TYPE_CODE_STRUCT:
125 case TYPE_CODE_UNION:
130 case TYPE_CODE_ERROR:
134 case TYPE_CODE_RANGE:
135 case TYPE_CODE_STRING:
136 case TYPE_CODE_BITSTRING:
137 case TYPE_CODE_METHOD:
139 case TYPE_CODE_COMPLEX:
140 case TYPE_CODE_TYPEDEF:
141 /* These types need no prefix. They are listed here so that
142 gcc -Wall will reveal any types that haven't been handled. */
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. */
152 f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
153 int show, int passed_a_ptr, int demangled_args)
155 int upper_bound, lower_bound;
156 int lower_bound_was_default = 0;
157 static int arrayprint_recurse_level = 0;
163 if (TYPE_NAME (type) && show <= 0)
168 switch (TYPE_CODE (type))
170 case TYPE_CODE_ARRAY:
171 arrayprint_recurse_level++;
173 if (arrayprint_recurse_level == 1)
174 fprintf_filtered (stream, "(");
176 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
177 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
179 retcode = f77_get_dynamic_lowerbound (type, &lower_bound);
181 lower_bound_was_default = 0;
183 if (retcode == BOUND_FETCH_ERROR)
184 fprintf_filtered (stream, "???");
185 else if (lower_bound == 1) /* The default */
186 lower_bound_was_default = 1;
188 fprintf_filtered (stream, "%d", lower_bound);
190 if (lower_bound_was_default)
191 lower_bound_was_default = 0;
193 fprintf_filtered (stream, ":");
195 /* Make sure that, if we have an assumed size array, we
196 print out a warning and print the upperbound as '*' */
198 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
199 fprintf_filtered (stream, "*");
202 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
204 if (retcode == BOUND_FETCH_ERROR)
205 fprintf_filtered (stream, "???");
207 fprintf_filtered (stream, "%d", upper_bound);
210 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
211 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
212 if (arrayprint_recurse_level == 1)
213 fprintf_filtered (stream, ")");
215 fprintf_filtered (stream, ",");
216 arrayprint_recurse_level--;
221 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
222 fprintf_filtered (stream, ")");
226 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
229 fprintf_filtered (stream, ")");
231 fprintf_filtered (stream, "()");
234 case TYPE_CODE_UNDEF:
235 case TYPE_CODE_STRUCT:
236 case TYPE_CODE_UNION:
241 case TYPE_CODE_ERROR:
245 case TYPE_CODE_RANGE:
246 case TYPE_CODE_STRING:
247 case TYPE_CODE_BITSTRING:
248 case TYPE_CODE_METHOD:
249 case TYPE_CODE_COMPLEX:
250 case TYPE_CODE_TYPEDEF:
251 /* These types do not need a suffix. They are listed so that
252 gcc -Wall will report types that may not have been considered. */
257 /* Print the name of the type (or the ultimate pointer target,
258 function value or array element), or the description of a
261 SHOW nonzero means don't print this type as just its name;
262 show its real definition even if it has a name.
263 SHOW zero means print just typename or struct tag if there is one
264 SHOW negative means abbreviate structure elements.
265 SHOW is decremented for printing of structure elements.
267 LEVEL is the depth to indent by.
268 We increase it for some recursive calls. */
271 f_type_print_base (struct type *type, struct ui_file *stream, int show,
284 fputs_filtered ("<type unknown>", stream);
288 /* When SHOW is zero or less, and there is a valid type name, then always
289 just print the type name directly from the type. */
291 if ((show <= 0) && (TYPE_NAME (type) != NULL))
293 fputs_filtered (TYPE_NAME (type), stream);
297 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
298 CHECK_TYPEDEF (type);
300 switch (TYPE_CODE (type))
302 case TYPE_CODE_TYPEDEF:
303 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
306 case TYPE_CODE_ARRAY:
308 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
312 fprintf_filtered (stream, "PTR TO -> ( ");
313 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
317 fprintf_filtered (stream, "REF TO -> ( ");
318 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
322 fprintfi_filtered (level, stream, "VOID");
325 case TYPE_CODE_UNDEF:
326 fprintfi_filtered (level, stream, "struct <unknown>");
329 case TYPE_CODE_ERROR:
330 fprintfi_filtered (level, stream, "<unknown type>");
333 case TYPE_CODE_RANGE:
334 /* This should not occur */
335 fprintfi_filtered (level, stream, "<range type>");
339 /* Override name "char" and make it "character" */
340 fprintfi_filtered (level, stream, "character");
344 /* There may be some character types that attempt to come
345 through as TYPE_CODE_INT since dbxstclass.h is so
346 C-oriented, we must change these to "character" from "char". */
348 if (strcmp (TYPE_NAME (type), "char") == 0)
349 fprintfi_filtered (level, stream, "character");
354 case TYPE_CODE_STRING:
355 /* Strings may have dynamic upperbounds (lengths) like arrays. */
357 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
358 fprintfi_filtered (level, stream, "character*(*)");
361 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
363 if (retcode == BOUND_FETCH_ERROR)
364 fprintf_filtered (stream, "character*???");
366 fprintf_filtered (stream, "character*%d", upper_bound);
370 case TYPE_CODE_STRUCT:
371 case TYPE_CODE_UNION:
372 if (TYPE_CODE (type) == TYPE_CODE_UNION)
373 fprintfi_filtered (level, stream, "Type, C_Union :: ");
375 fprintfi_filtered (level, stream, "Type ");
376 fputs_filtered (TYPE_TAG_NAME (type), stream);
377 fputs_filtered ("\n", stream);
378 for (index = 0; index < TYPE_NFIELDS (type); index++)
380 f_type_print_base (TYPE_FIELD_TYPE (type, index), stream, show,
382 fputs_filtered (" :: ", stream);
383 fprintfi_filtered (level, stream, "%s",
384 TYPE_FIELD_NAME (type, index));
385 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index),
387 fputs_filtered ("\n", stream);
389 fprintfi_filtered (level, stream, "End Type ");
390 fputs_filtered (TYPE_TAG_NAME (type), stream);
395 /* Handle types not explicitly handled by the other cases,
396 such as fundamental types. For these, just print whatever
397 the type name is, as recorded in the type itself. If there
398 is no type name, then complain. */
399 if (TYPE_NAME (type) != NULL)
400 fprintfi_filtered (level, stream, "%s", TYPE_NAME (type));
402 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type));