]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/f-typeprint.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / f-typeprint.c
CommitLineData
a91a6192 1/* Support for printing Fortran types for GDB, the GNU debugger.
22d7f91e 2 Copyright 1986, 1988, 1989, 1991, 1993, 1994 Free Software Foundation, Inc.
a91a6192
SS
3 Contributed by Motorola. Adapted from the C version by Farooq Butt
4 (fmbutt@engage.sps.mot.com).
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
6c9638b4 20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
a91a6192
SS
21
22#include "defs.h"
23#include "obstack.h"
24#include "bfd.h"
25#include "symtab.h"
26#include "gdbtypes.h"
27#include "expression.h"
28#include "value.h"
29#include "gdbcore.h"
30#include "target.h"
31#include "command.h"
32#include "gdbcmd.h"
33#include "language.h"
34#include "demangle.h"
35#include "f-lang.h"
36#include "typeprint.h"
37#include "frame.h" /* ??? */
38
2b576293 39#include "gdb_string.h"
a91a6192
SS
40#include <errno.h>
41
6b14af2b 42#if 0 /* Currently unused */
65b07ddc 43static void f_type_print_args PARAMS ((struct type *, GDB_FILE *));
6b14af2b 44#endif
a91a6192 45
65b07ddc
DT
46static void print_equivalent_f77_float_type PARAMS ((struct type *,
47 GDB_FILE *));
b607efe7 48
65b07ddc 49static void f_type_print_varspec_suffix PARAMS ((struct type *, GDB_FILE *,
a91a6192
SS
50 int, int, int));
51
65b07ddc
DT
52void f_type_print_varspec_prefix PARAMS ((struct type *, GDB_FILE *,
53 int, int));
a91a6192 54
65b07ddc 55void f_type_print_base PARAMS ((struct type *, GDB_FILE *, int, int));
a91a6192
SS
56
57\f
58/* LEVEL is the depth to indent lines by. */
59
60void
61f_print_type (type, varstring, stream, show, level)
62 struct type *type;
63 char *varstring;
65b07ddc 64 GDB_FILE *stream;
a91a6192
SS
65 int show;
66 int level;
67{
68 register enum type_code code;
69 int demangled_args;
70
71 f_type_print_base (type, stream, show, level);
72 code = TYPE_CODE (type);
73 if ((varstring != NULL && *varstring != '\0')
74 ||
75 /* Need a space if going to print stars or brackets;
76 but not if we will print just a type name. */
77 ((show > 0 || TYPE_NAME (type) == 0)
78 &&
79 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
80 || code == TYPE_CODE_METHOD
81 || code == TYPE_CODE_ARRAY
82 || code == TYPE_CODE_MEMBER
83 || code == TYPE_CODE_REF)))
84 fputs_filtered (" ", stream);
85 f_type_print_varspec_prefix (type, stream, show, 0);
86
87 fputs_filtered (varstring, stream);
88
89 /* For demangled function names, we have the arglist as part of the name,
90 so don't print an additional pair of ()'s */
91
92 demangled_args = varstring[strlen(varstring) - 1] == ')';
93 f_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
94}
95
96/* Print any asterisks or open-parentheses needed before the
97 variable name (to describe its type).
98
99 On outermost call, pass 0 for PASSED_A_PTR.
100 On outermost call, SHOW > 0 means should ignore
101 any typename for TYPE and show its details.
102 SHOW is always zero on recursive calls. */
103
104void
105f_type_print_varspec_prefix (type, stream, show, passed_a_ptr)
106 struct type *type;
65b07ddc 107 GDB_FILE *stream;
a91a6192
SS
108 int show;
109 int passed_a_ptr;
110{
a91a6192
SS
111 if (type == 0)
112 return;
113
114 if (TYPE_NAME (type) && show <= 0)
115 return;
116
117 QUIT;
118
119 switch (TYPE_CODE (type))
120 {
121 case TYPE_CODE_PTR:
122 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
123 break;
124
125 case TYPE_CODE_FUNC:
126 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
127 if (passed_a_ptr)
128 fprintf_filtered (stream, "(");
129 break;
130
131 case TYPE_CODE_ARRAY:
132 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
133 break;
134
135 case TYPE_CODE_UNDEF:
136 case TYPE_CODE_STRUCT:
137 case TYPE_CODE_UNION:
138 case TYPE_CODE_ENUM:
139 case TYPE_CODE_INT:
140 case TYPE_CODE_FLT:
141 case TYPE_CODE_VOID:
142 case TYPE_CODE_ERROR:
143 case TYPE_CODE_CHAR:
144 case TYPE_CODE_BOOL:
145 case TYPE_CODE_SET:
146 case TYPE_CODE_RANGE:
147 case TYPE_CODE_STRING:
22d7f91e
SS
148 case TYPE_CODE_BITSTRING:
149 case TYPE_CODE_METHOD:
150 case TYPE_CODE_MEMBER:
151 case TYPE_CODE_REF:
152 case TYPE_CODE_COMPLEX:
b52cac6b 153 case TYPE_CODE_TYPEDEF:
a91a6192
SS
154 /* These types need no prefix. They are listed here so that
155 gcc -Wall will reveal any types that haven't been handled. */
156 break;
157 }
158}
159
6b14af2b
FF
160#if 0 /* Currently unused */
161
a91a6192
SS
162static void
163f_type_print_args (type, stream)
164 struct type *type;
65b07ddc 165 GDB_FILE *stream;
a91a6192
SS
166{
167 int i;
168 struct type **args;
169
170 fprintf_filtered (stream, "(");
171 args = TYPE_ARG_TYPES (type);
172 if (args != NULL)
173 {
174 if (args[1] == NULL)
175 {
176 fprintf_filtered (stream, "...");
177 }
178 else
179 {
180 for (i = 1; args[i] != NULL && args[i]->code != TYPE_CODE_VOID; i++)
181 {
182 f_print_type (args[i], "", stream, -1, 0);
183 if (args[i+1] == NULL)
184 fprintf_filtered (stream, "...");
185 else if (args[i+1]->code != TYPE_CODE_VOID)
186 {
187 fprintf_filtered (stream, ",");
188 wrap_here (" ");
189 }
190 }
191 }
192 }
193 fprintf_filtered (stream, ")");
194}
195
6b14af2b
FF
196#endif /* 0 */
197
a91a6192
SS
198/* Print any array sizes, function arguments or close parentheses
199 needed after the variable name (to describe its type).
200 Args work like c_type_print_varspec_prefix. */
201
202static void
203f_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
204 struct type *type;
65b07ddc 205 GDB_FILE *stream;
a91a6192
SS
206 int show;
207 int passed_a_ptr;
208 int demangled_args;
209{
22d7f91e 210 int upper_bound, lower_bound;
a91a6192
SS
211 int lower_bound_was_default = 0;
212 static int arrayprint_recurse_level = 0;
213 int retcode;
214
215 if (type == 0)
216 return;
217
218 if (TYPE_NAME (type) && show <= 0)
219 return;
220
221 QUIT;
222
223 switch (TYPE_CODE (type))
224 {
225 case TYPE_CODE_ARRAY:
226 arrayprint_recurse_level++;
227
228 if (arrayprint_recurse_level == 1)
229 fprintf_filtered(stream,"(");
8a329002
PB
230
231 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
232 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
a91a6192
SS
233
234 retcode = f77_get_dynamic_lowerbound (type,&lower_bound);
235
236 lower_bound_was_default = 0;
237
238 if (retcode == BOUND_FETCH_ERROR)
239 fprintf_filtered (stream,"???");
240 else
241 if (lower_bound == 1) /* The default */
242 lower_bound_was_default = 1;
243 else
244 fprintf_filtered (stream,"%d",lower_bound);
245
246 if (lower_bound_was_default)
247 lower_bound_was_default = 0;
248 else
249 fprintf_filtered(stream,":");
250
251 /* Make sure that, if we have an assumed size array, we
252 print out a warning and print the upperbound as '*' */
253
254 if (TYPE_ARRAY_UPPER_BOUND_TYPE(type) == BOUND_CANNOT_BE_DETERMINED)
255 fprintf_filtered (stream, "*");
256 else
257 {
258 retcode = f77_get_dynamic_upperbound(type,&upper_bound);
259
260 if (retcode == BOUND_FETCH_ERROR)
261 fprintf_filtered(stream,"???");
262 else
263 fprintf_filtered(stream,"%d",upper_bound);
264 }
265
8a329002
PB
266 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
267 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
a91a6192
SS
268 if (arrayprint_recurse_level == 1)
269 fprintf_filtered (stream, ")");
8a329002
PB
270 else
271 fprintf_filtered(stream,",");
a91a6192
SS
272 arrayprint_recurse_level--;
273 break;
274
275 case TYPE_CODE_PTR:
276 case TYPE_CODE_REF:
277 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
278 fprintf_filtered(stream,")");
279 break;
280
281 case TYPE_CODE_FUNC:
282 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
283 passed_a_ptr, 0);
284 if (passed_a_ptr)
285 fprintf_filtered (stream, ")");
286
287 fprintf_filtered (stream, "()");
288 break;
289
290 case TYPE_CODE_UNDEF:
291 case TYPE_CODE_STRUCT:
292 case TYPE_CODE_UNION:
293 case TYPE_CODE_ENUM:
294 case TYPE_CODE_INT:
295 case TYPE_CODE_FLT:
296 case TYPE_CODE_VOID:
297 case TYPE_CODE_ERROR:
298 case TYPE_CODE_CHAR:
299 case TYPE_CODE_BOOL:
300 case TYPE_CODE_SET:
301 case TYPE_CODE_RANGE:
a91a6192 302 case TYPE_CODE_STRING:
22d7f91e
SS
303 case TYPE_CODE_BITSTRING:
304 case TYPE_CODE_METHOD:
305 case TYPE_CODE_MEMBER:
306 case TYPE_CODE_COMPLEX:
b52cac6b 307 case TYPE_CODE_TYPEDEF:
a91a6192
SS
308 /* These types do not need a suffix. They are listed so that
309 gcc -Wall will report types that may not have been considered. */
310 break;
311 }
312}
313
b607efe7 314static void
a91a6192
SS
315print_equivalent_f77_float_type (type, stream)
316 struct type *type;
65b07ddc 317 GDB_FILE *stream;
a91a6192
SS
318{
319 /* Override type name "float" and make it the
320 appropriate real. XLC stupidly outputs -12 as a type
321 for real when it really should be outputting -18 */
322
bcbf388e 323 fprintf_filtered (stream, "real*%d", TYPE_LENGTH (type));
a91a6192
SS
324}
325
326/* Print the name of the type (or the ultimate pointer target,
327 function value or array element), or the description of a
328 structure or union.
329
330 SHOW nonzero means don't print this type as just its name;
331 show its real definition even if it has a name.
332 SHOW zero means print just typename or struct tag if there is one
333 SHOW negative means abbreviate structure elements.
334 SHOW is decremented for printing of structure elements.
335
336 LEVEL is the depth to indent by.
337 We increase it for some recursive calls. */
338
339void
340f_type_print_base (type, stream, show, level)
341 struct type *type;
65b07ddc 342 GDB_FILE *stream;
a91a6192
SS
343 int show;
344 int level;
345{
22d7f91e
SS
346 int retcode;
347 int upper_bound;
348
a91a6192
SS
349 QUIT;
350
351 wrap_here (" ");
352 if (type == NULL)
353 {
354 fputs_filtered ("<type unknown>", stream);
355 return;
356 }
357
358 /* When SHOW is zero or less, and there is a valid type name, then always
359 just print the type name directly from the type. */
360
361 if ((show <= 0) && (TYPE_NAME (type) != NULL))
362 {
a91a6192
SS
363 if (TYPE_CODE (type) == TYPE_CODE_FLT)
364 print_equivalent_f77_float_type (type, stream);
365 else
366 fputs_filtered (TYPE_NAME (type), stream);
367 return;
368 }
369
bcbf388e
PB
370 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
371 CHECK_TYPEDEF (type);
372
a91a6192
SS
373 switch (TYPE_CODE (type))
374 {
bcbf388e
PB
375 case TYPE_CODE_TYPEDEF:
376 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
a91a6192
SS
377 break;
378
bcbf388e 379 case TYPE_CODE_ARRAY:
a91a6192
SS
380 case TYPE_CODE_FUNC:
381 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
382 break;
383
384 case TYPE_CODE_PTR:
385 fprintf_filtered (stream, "PTR TO -> ( ");
bcbf388e 386 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
a91a6192
SS
387 break;
388
389 case TYPE_CODE_VOID:
390 fprintf_filtered (stream, "VOID");
391 break;
392
393 case TYPE_CODE_UNDEF:
394 fprintf_filtered (stream, "struct <unknown>");
395 break;
396
397 case TYPE_CODE_ERROR:
398 fprintf_filtered (stream, "<unknown type>");
399 break;
400
401 case TYPE_CODE_RANGE:
402 /* This should not occur */
403 fprintf_filtered (stream, "<range type>");
404 break;
405
406 case TYPE_CODE_CHAR:
407 /* Override name "char" and make it "character" */
408 fprintf_filtered (stream, "character");
409 break;
410
411 case TYPE_CODE_INT:
412 /* There may be some character types that attempt to come
413 through as TYPE_CODE_INT since dbxstclass.h is so
414 C-oriented, we must change these to "character" from "char". */
415
22d7f91e
SS
416 if (STREQ (TYPE_NAME (type), "char"))
417 fprintf_filtered (stream, "character");
a91a6192
SS
418 else
419 goto default_case;
420 break;
421
422 case TYPE_CODE_COMPLEX:
bcbf388e 423 fprintf_filtered (stream, "complex*%d", TYPE_LENGTH (type));
a91a6192
SS
424 break;
425
426 case TYPE_CODE_FLT:
22d7f91e 427 print_equivalent_f77_float_type (type, stream);
a91a6192
SS
428 break;
429
a91a6192 430 case TYPE_CODE_STRING:
22d7f91e 431 /* Strings may have dynamic upperbounds (lengths) like arrays. */
a91a6192
SS
432
433 if (TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
85c613aa 434 fprintf_filtered (stream, "character*(*)");
a91a6192
SS
435 else
436 {
22d7f91e 437 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
a91a6192
SS
438
439 if (retcode == BOUND_FETCH_ERROR)
22d7f91e 440 fprintf_filtered (stream, "character*???");
a91a6192 441 else
22d7f91e 442 fprintf_filtered (stream, "character*%d", upper_bound);
a91a6192
SS
443 }
444 break;
445
446 default_case:
447 default:
448 /* Handle types not explicitly handled by the other cases,
449 such as fundamental types. For these, just print whatever
450 the type name is, as recorded in the type itself. If there
451 is no type name, then complain. */
452 if (TYPE_NAME (type) != NULL)
453 fputs_filtered (TYPE_NAME (type), stream);
454 else
455 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));
456 break;
457 }
458}