[PATCH 7/57][Arm][GAS] Add support for MVE instructions: vstr/vldr
[binutils-gdb.git] / gdb / f-typeprint.c
bloba7c1a00a71495d72932a1dc36c66df5308cc073a
1 /* Support for printing Fortran types for GDB, the GNU debugger.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
5 Contributed by Motorola. Adapted from the C version by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
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 3 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, see <http://www.gnu.org/licenses/>. */
23 #include "defs.h"
24 #include "gdb_obstack.h"
25 #include "bfd.h"
26 #include "symtab.h"
27 #include "gdbtypes.h"
28 #include "expression.h"
29 #include "value.h"
30 #include "gdbcore.h"
31 #include "target.h"
32 #include "f-lang.h"
33 #include "typeprint.h"
35 #if 0 /* Currently unused. */
36 static void f_type_print_args (struct type *, struct ui_file *);
37 #endif
39 static void f_type_print_varspec_suffix (struct type *, struct ui_file *, int,
40 int, int, int);
42 void f_type_print_varspec_prefix (struct type *, struct ui_file *,
43 int, int);
45 void f_type_print_base (struct type *, struct ui_file *, int, int);
48 /* LEVEL is the depth to indent lines by. */
50 void
51 f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
52 int show, int level, const struct type_print_options *flags)
54 enum type_code code;
56 if (type_not_associated (type))
58 val_print_not_associated (stream);
59 return;
62 if (type_not_allocated (type))
64 val_print_not_allocated (stream);
65 return;
68 f_type_print_base (type, stream, show, level);
69 code = TYPE_CODE (type);
70 if ((varstring != NULL && *varstring != '\0')
71 /* Need a space if going to print stars or brackets; but not if we
72 will print just a type name. */
73 || ((show > 0
74 || TYPE_NAME (type) == 0)
75 && (code == TYPE_CODE_FUNC
76 || code == TYPE_CODE_METHOD
77 || code == TYPE_CODE_ARRAY
78 || ((code == TYPE_CODE_PTR
79 || code == TYPE_CODE_REF)
80 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
81 || (TYPE_CODE (TYPE_TARGET_TYPE (type))
82 == TYPE_CODE_METHOD)
83 || (TYPE_CODE (TYPE_TARGET_TYPE (type))
84 == TYPE_CODE_ARRAY))))))
85 fputs_filtered (" ", stream);
86 f_type_print_varspec_prefix (type, stream, show, 0);
88 if (varstring != NULL)
90 int demangled_args;
92 fputs_filtered (varstring, stream);
94 /* For demangled function names, we have the arglist as part of the name,
95 so don't print an additional pair of ()'s. */
97 demangled_args = (*varstring != '\0'
98 && varstring[strlen (varstring) - 1] == ')');
99 f_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0);
103 /* Print any asterisks or open-parentheses needed before the
104 variable name (to describe its type).
106 On outermost call, pass 0 for PASSED_A_PTR.
107 On outermost call, SHOW > 0 means should ignore
108 any typename for TYPE and show its details.
109 SHOW is always zero on recursive calls. */
111 void
112 f_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
113 int show, int passed_a_ptr)
115 if (type == 0)
116 return;
118 if (TYPE_NAME (type) && show <= 0)
119 return;
121 QUIT;
123 switch (TYPE_CODE (type))
125 case TYPE_CODE_PTR:
126 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
127 break;
129 case TYPE_CODE_FUNC:
130 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
131 if (passed_a_ptr)
132 fprintf_filtered (stream, "(");
133 break;
135 case TYPE_CODE_ARRAY:
136 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
137 break;
139 case TYPE_CODE_UNDEF:
140 case TYPE_CODE_STRUCT:
141 case TYPE_CODE_UNION:
142 case TYPE_CODE_ENUM:
143 case TYPE_CODE_INT:
144 case TYPE_CODE_FLT:
145 case TYPE_CODE_VOID:
146 case TYPE_CODE_ERROR:
147 case TYPE_CODE_CHAR:
148 case TYPE_CODE_BOOL:
149 case TYPE_CODE_SET:
150 case TYPE_CODE_RANGE:
151 case TYPE_CODE_STRING:
152 case TYPE_CODE_METHOD:
153 case TYPE_CODE_REF:
154 case TYPE_CODE_COMPLEX:
155 case TYPE_CODE_TYPEDEF:
156 /* These types need no prefix. They are listed here so that
157 gcc -Wall will reveal any types that haven't been handled. */
158 break;
162 /* Print any array sizes, function arguments or close parentheses
163 needed after the variable name (to describe its type).
164 Args work like c_type_print_varspec_prefix. */
166 static void
167 f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
168 int show, int passed_a_ptr, int demangled_args,
169 int arrayprint_recurse_level)
171 /* No static variables are permitted as an error call may occur during
172 execution of this function. */
174 if (type == 0)
175 return;
177 if (TYPE_NAME (type) && show <= 0)
178 return;
180 QUIT;
182 switch (TYPE_CODE (type))
184 case TYPE_CODE_ARRAY:
185 arrayprint_recurse_level++;
187 if (arrayprint_recurse_level == 1)
188 fprintf_filtered (stream, "(");
190 if (type_not_associated (type))
191 val_print_not_associated (stream);
192 else if (type_not_allocated (type))
193 val_print_not_allocated (stream);
194 else
196 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
197 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
198 0, 0, arrayprint_recurse_level);
200 LONGEST lower_bound = f77_get_lowerbound (type);
202 if (lower_bound != 1) /* Not the default. */
203 fprintf_filtered (stream, "%s:", plongest (lower_bound));
205 /* Make sure that, if we have an assumed size array, we
206 print out a warning and print the upperbound as '*'. */
208 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
209 fprintf_filtered (stream, "*");
210 else
212 LONGEST upper_bound = f77_get_upperbound (type);
214 fputs_filtered (plongest (upper_bound), stream);
217 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
218 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
219 0, 0, arrayprint_recurse_level);
221 if (arrayprint_recurse_level == 1)
222 fprintf_filtered (stream, ")");
223 else
224 fprintf_filtered (stream, ",");
225 arrayprint_recurse_level--;
226 break;
228 case TYPE_CODE_PTR:
229 case TYPE_CODE_REF:
230 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0,
231 arrayprint_recurse_level);
232 fprintf_filtered (stream, " )");
233 break;
235 case TYPE_CODE_FUNC:
237 int i, nfields = TYPE_NFIELDS (type);
239 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
240 passed_a_ptr, 0, arrayprint_recurse_level);
241 if (passed_a_ptr)
242 fprintf_filtered (stream, ") ");
243 fprintf_filtered (stream, "(");
244 if (nfields == 0 && TYPE_PROTOTYPED (type))
245 f_print_type (builtin_f_type (get_type_arch (type))->builtin_void,
246 "", stream, -1, 0, 0);
247 else
248 for (i = 0; i < nfields; i++)
250 if (i > 0)
252 fputs_filtered (", ", stream);
253 wrap_here (" ");
255 f_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0, 0);
257 fprintf_filtered (stream, ")");
259 break;
261 case TYPE_CODE_UNDEF:
262 case TYPE_CODE_STRUCT:
263 case TYPE_CODE_UNION:
264 case TYPE_CODE_ENUM:
265 case TYPE_CODE_INT:
266 case TYPE_CODE_FLT:
267 case TYPE_CODE_VOID:
268 case TYPE_CODE_ERROR:
269 case TYPE_CODE_CHAR:
270 case TYPE_CODE_BOOL:
271 case TYPE_CODE_SET:
272 case TYPE_CODE_RANGE:
273 case TYPE_CODE_STRING:
274 case TYPE_CODE_METHOD:
275 case TYPE_CODE_COMPLEX:
276 case TYPE_CODE_TYPEDEF:
277 /* These types do not need a suffix. They are listed so that
278 gcc -Wall will report types that may not have been considered. */
279 break;
283 /* Print the name of the type (or the ultimate pointer target,
284 function value or array element), or the description of a
285 structure or union.
287 SHOW nonzero means don't print this type as just its name;
288 show its real definition even if it has a name.
289 SHOW zero means print just typename or struct tag if there is one
290 SHOW negative means abbreviate structure elements.
291 SHOW is decremented for printing of structure elements.
293 LEVEL is the depth to indent by.
294 We increase it for some recursive calls. */
296 void
297 f_type_print_base (struct type *type, struct ui_file *stream, int show,
298 int level)
300 int index;
302 QUIT;
304 wrap_here (" ");
305 if (type == NULL)
307 fputs_filtered ("<type unknown>", stream);
308 return;
311 /* When SHOW is zero or less, and there is a valid type name, then always
312 just print the type name directly from the type. */
314 if ((show <= 0) && (TYPE_NAME (type) != NULL))
316 const char *prefix = "";
317 if (TYPE_CODE (type) == TYPE_CODE_UNION)
318 prefix = "Type, C_Union :: ";
319 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
320 prefix = "Type ";
321 fprintfi_filtered (level, stream, "%s%s", prefix, TYPE_NAME (type));
322 return;
325 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
326 type = check_typedef (type);
328 switch (TYPE_CODE (type))
330 case TYPE_CODE_TYPEDEF:
331 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
332 break;
334 case TYPE_CODE_ARRAY:
335 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
336 break;
337 case TYPE_CODE_FUNC:
338 if (TYPE_TARGET_TYPE (type) == NULL)
339 type_print_unknown_return_type (stream);
340 else
341 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
342 break;
344 case TYPE_CODE_PTR:
345 fprintfi_filtered (level, stream, "PTR TO -> ( ");
346 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0);
347 break;
349 case TYPE_CODE_REF:
350 fprintfi_filtered (level, stream, "REF TO -> ( ");
351 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, 0);
352 break;
354 case TYPE_CODE_VOID:
356 gdbarch *gdbarch = get_type_arch (type);
357 struct type *void_type = builtin_f_type (gdbarch)->builtin_void;
358 fprintfi_filtered (level, stream, "%s", TYPE_NAME (void_type));
360 break;
362 case TYPE_CODE_UNDEF:
363 fprintfi_filtered (level, stream, "struct <unknown>");
364 break;
366 case TYPE_CODE_ERROR:
367 fprintfi_filtered (level, stream, "%s", TYPE_ERROR_NAME (type));
368 break;
370 case TYPE_CODE_RANGE:
371 /* This should not occur. */
372 fprintfi_filtered (level, stream, "<range type>");
373 break;
375 case TYPE_CODE_CHAR:
376 case TYPE_CODE_INT:
377 /* There may be some character types that attempt to come
378 through as TYPE_CODE_INT since dbxstclass.h is so
379 C-oriented, we must change these to "character" from "char". */
381 if (strcmp (TYPE_NAME (type), "char") == 0)
382 fprintfi_filtered (level, stream, "character");
383 else
384 goto default_case;
385 break;
387 case TYPE_CODE_STRING:
388 /* Strings may have dynamic upperbounds (lengths) like arrays. */
390 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
391 fprintfi_filtered (level, stream, "character*(*)");
392 else
394 LONGEST upper_bound = f77_get_upperbound (type);
396 fprintf_filtered (stream, "character*%s", pulongest (upper_bound));
398 break;
400 case TYPE_CODE_STRUCT:
401 case TYPE_CODE_UNION:
402 if (TYPE_CODE (type) == TYPE_CODE_UNION)
403 fprintfi_filtered (level, stream, "Type, C_Union :: ");
404 else
405 fprintfi_filtered (level, stream, "Type ");
406 fputs_filtered (TYPE_NAME (type), stream);
407 /* According to the definition,
408 we only print structure elements in case show > 0. */
409 if (show > 0)
411 fputs_filtered ("\n", stream);
412 for (index = 0; index < TYPE_NFIELDS (type); index++)
414 f_type_print_base (TYPE_FIELD_TYPE (type, index), stream,
415 show - 1, level + 4);
416 fputs_filtered (" :: ", stream);
417 fputs_filtered (TYPE_FIELD_NAME (type, index), stream);
418 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index),
419 stream, show - 1, 0, 0, 0);
420 fputs_filtered ("\n", stream);
422 fprintfi_filtered (level, stream, "End Type ");
423 fputs_filtered (TYPE_NAME (type), stream);
425 break;
427 case TYPE_CODE_MODULE:
428 fprintfi_filtered (level, stream, "module %s", TYPE_NAME (type));
429 break;
431 default_case:
432 default:
433 /* Handle types not explicitly handled by the other cases,
434 such as fundamental types. For these, just print whatever
435 the type name is, as recorded in the type itself. If there
436 is no type name, then complain. */
437 if (TYPE_NAME (type) != NULL)
438 fprintfi_filtered (level, stream, "%s", TYPE_NAME (type));
439 else
440 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type));
441 break;
444 if (TYPE_IS_ALLOCATABLE (type))
445 fprintf_filtered (stream, ", allocatable");