1 /* Support for printing Pascal types for GDB, the GNU debugger.
2 Copyright (C) 2000, 2001, 2002, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This file is derived from p-typeprint.c */
23 #include "gdb_obstack.h"
24 #include "bfd.h" /* Binary File Description */
27 #include "expression.h"
33 #include "typeprint.h"
35 #include "gdb_string.h"
39 static void pascal_type_print_varspec_suffix (struct type
*, struct ui_file
*, int, int, int);
41 static void pascal_type_print_derivation_info (struct ui_file
*, struct type
*);
43 void pascal_type_print_varspec_prefix (struct type
*, struct ui_file
*, int, int);
46 /* LEVEL is the depth to indent lines by. */
49 pascal_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
55 code
= TYPE_CODE (type
);
60 if ((code
== TYPE_CODE_FUNC
61 || code
== TYPE_CODE_METHOD
))
63 pascal_type_print_varspec_prefix (type
, stream
, show
, 0);
66 fputs_filtered (varstring
, stream
);
68 if ((varstring
!= NULL
&& *varstring
!= '\0')
69 && !(code
== TYPE_CODE_FUNC
70 || code
== TYPE_CODE_METHOD
))
72 fputs_filtered (" : ", stream
);
75 if (!(code
== TYPE_CODE_FUNC
76 || code
== TYPE_CODE_METHOD
))
78 pascal_type_print_varspec_prefix (type
, stream
, show
, 0);
81 pascal_type_print_base (type
, stream
, show
, level
);
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
? strchr (varstring
, '(') != NULL
: 0;
86 pascal_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
90 /* Print a typedef using Pascal syntax. TYPE is the underlying type.
91 NEW_SYMBOL is the symbol naming the type. STREAM is the stream on
95 pascal_print_typedef (struct type
*type
, struct symbol
*new_symbol
,
96 struct ui_file
*stream
)
99 fprintf_filtered (stream
, "type ");
100 fprintf_filtered (stream
, "%s = ", SYMBOL_PRINT_NAME (new_symbol
));
101 type_print (type
, "", stream
, 0);
102 fprintf_filtered (stream
, ";\n");
105 /* If TYPE is a derived type, then print out derivation information.
106 Print only the actual base classes of this type, not the base classes
107 of the base classes. I.E. for the derivation hierarchy:
110 class B : public A {int b; };
111 class C : public B {int c; };
113 Print the type of class C as:
119 Not as the following (like gdb used to), which is not legal C++ syntax for
120 derived types and may be confused with the multiple inheritance form:
122 class C : public B : public A {
126 In general, gdb should try to print the types as closely as possible to
127 the form that they appear in the source code. */
130 pascal_type_print_derivation_info (struct ui_file
*stream
, struct type
*type
)
135 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
137 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
138 fprintf_filtered (stream
, "%s%s ",
139 BASETYPE_VIA_PUBLIC (type
, i
) ? "public" : "private",
140 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
141 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
142 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
146 fputs_filtered (" ", stream
);
150 /* Print the Pascal method arguments ARGS to the file STREAM. */
153 pascal_type_print_method_args (char *physname
, char *methodname
,
154 struct ui_file
*stream
)
156 int is_constructor
= (strncmp (physname
, "__ct__", 6) == 0);
157 int is_destructor
= (strncmp (physname
, "__dt__", 6) == 0);
159 if (is_constructor
|| is_destructor
)
164 fputs_filtered (methodname
, stream
);
166 if (physname
&& (*physname
!= 0))
172 fputs_filtered (" (", stream
);
173 /* we must demangle this */
174 while (isdigit (physname
[0]))
176 while (isdigit (physname
[len
]))
180 i
= strtol (physname
, &argname
, 0);
182 storec
= physname
[i
];
184 fputs_filtered (physname
, stream
);
185 physname
[i
] = storec
;
187 if (physname
[0] != 0)
189 fputs_filtered (", ", stream
);
192 fputs_filtered (")", stream
);
196 /* Print any asterisks or open-parentheses needed before the
197 variable name (to describe its type).
199 On outermost call, pass 0 for PASSED_A_PTR.
200 On outermost call, SHOW > 0 means should ignore
201 any typename for TYPE and show its details.
202 SHOW is always zero on recursive calls. */
205 pascal_type_print_varspec_prefix (struct type
*type
, struct ui_file
*stream
,
206 int show
, int passed_a_ptr
)
212 if (TYPE_NAME (type
) && show
<= 0)
217 switch (TYPE_CODE (type
))
220 fprintf_filtered (stream
, "^");
221 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
222 break; /* pointer should be handled normally in pascal */
224 case TYPE_CODE_METHOD
:
226 fprintf_filtered (stream
, "(");
227 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
229 fprintf_filtered (stream
, "function ");
233 fprintf_filtered (stream
, "procedure ");
238 fprintf_filtered (stream
, " ");
239 pascal_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
240 fprintf_filtered (stream
, "::");
245 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
246 fprintf_filtered (stream
, "&");
251 fprintf_filtered (stream
, "(");
253 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
255 fprintf_filtered (stream
, "function ");
259 fprintf_filtered (stream
, "procedure ");
264 case TYPE_CODE_ARRAY
:
266 fprintf_filtered (stream
, "(");
267 fprintf_filtered (stream
, "array ");
268 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0
269 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))
270 fprintf_filtered (stream
, "[%s..%s] ",
271 plongest (TYPE_ARRAY_LOWER_BOUND_VALUE (type
)),
272 plongest (TYPE_ARRAY_UPPER_BOUND_VALUE (type
)));
273 fprintf_filtered (stream
, "of ");
276 case TYPE_CODE_UNDEF
:
277 case TYPE_CODE_STRUCT
:
278 case TYPE_CODE_UNION
:
283 case TYPE_CODE_ERROR
:
287 case TYPE_CODE_RANGE
:
288 case TYPE_CODE_STRING
:
289 case TYPE_CODE_BITSTRING
:
290 case TYPE_CODE_COMPLEX
:
291 case TYPE_CODE_TYPEDEF
:
292 case TYPE_CODE_TEMPLATE
:
293 /* These types need no prefix. They are listed here so that
294 gcc -Wall will reveal any types that haven't been handled. */
297 error (_("type not handled in pascal_type_print_varspec_prefix()"));
303 pascal_print_func_args (struct type
*type
, struct ui_file
*stream
)
305 int i
, len
= TYPE_NFIELDS (type
);
308 fprintf_filtered (stream
, "(");
310 for (i
= 0; i
< len
; i
++)
314 fputs_filtered (", ", stream
);
317 /* can we find if it is a var parameter ??
318 if ( TYPE_FIELD(type, i) == )
320 fprintf_filtered (stream, "var ");
322 pascal_print_type (TYPE_FIELD_TYPE (type
, i
), "" /* TYPE_FIELD_NAME seems invalid ! */
327 fprintf_filtered (stream
, ")");
331 /* Print any array sizes, function arguments or close parentheses
332 needed after the variable name (to describe its type).
333 Args work like pascal_type_print_varspec_prefix. */
336 pascal_type_print_varspec_suffix (struct type
*type
, struct ui_file
*stream
,
337 int show
, int passed_a_ptr
,
343 if (TYPE_NAME (type
) && show
<= 0)
348 switch (TYPE_CODE (type
))
350 case TYPE_CODE_ARRAY
:
352 fprintf_filtered (stream
, ")");
355 case TYPE_CODE_METHOD
:
357 fprintf_filtered (stream
, ")");
358 pascal_type_print_method_args ("",
361 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
363 fprintf_filtered (stream
, " : ");
364 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
365 pascal_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, 0);
366 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
373 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
378 fprintf_filtered (stream
, ")");
380 pascal_print_func_args (type
, stream
);
381 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
383 fprintf_filtered (stream
, " : ");
384 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
385 pascal_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, 0);
386 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
391 case TYPE_CODE_UNDEF
:
392 case TYPE_CODE_STRUCT
:
393 case TYPE_CODE_UNION
:
398 case TYPE_CODE_ERROR
:
402 case TYPE_CODE_RANGE
:
403 case TYPE_CODE_STRING
:
404 case TYPE_CODE_BITSTRING
:
405 case TYPE_CODE_COMPLEX
:
406 case TYPE_CODE_TYPEDEF
:
407 case TYPE_CODE_TEMPLATE
:
408 /* These types do not need a suffix. They are listed so that
409 gcc -Wall will report types that may not have been considered. */
412 error (_("type not handled in pascal_type_print_varspec_suffix()"));
417 /* Print the name of the type (or the ultimate pointer target,
418 function value or array element), or the description of a
421 SHOW positive means print details about the type (e.g. enum values),
422 and print structure elements passing SHOW - 1 for show.
423 SHOW negative means just print the type name or struct tag if there is one.
424 If there is no name, print something sensible but concise like
426 SHOW zero means just print the type name or struct tag if there is one.
427 If there is no name, print something sensible but not as concise like
428 "struct {int x; int y;}".
430 LEVEL is the number of spaces to indent by.
431 We increase it for some recursive calls. */
434 pascal_type_print_base (struct type
*type
, struct ui_file
*stream
, int show
,
442 s_none
, s_public
, s_private
, s_protected
450 fputs_filtered ("<type unknown>", stream
);
455 if ((TYPE_CODE (type
) == TYPE_CODE_PTR
) && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_VOID
))
457 fputs_filtered (TYPE_NAME (type
) ? TYPE_NAME (type
) : "pointer",
461 /* When SHOW is zero or less, and there is a valid type name, then always
462 just print the type name directly from the type. */
465 && TYPE_NAME (type
) != NULL
)
467 fputs_filtered (TYPE_NAME (type
), stream
);
471 CHECK_TYPEDEF (type
);
473 switch (TYPE_CODE (type
))
475 case TYPE_CODE_TYPEDEF
:
478 /* case TYPE_CODE_FUNC:
479 case TYPE_CODE_METHOD: */
480 pascal_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
483 case TYPE_CODE_ARRAY
:
484 /* pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
485 pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
486 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); */
487 pascal_print_type (TYPE_TARGET_TYPE (type
), NULL
, stream
, 0, 0);
491 case TYPE_CODE_METHOD
:
493 pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
494 only after args !! */
496 case TYPE_CODE_STRUCT
:
497 if (TYPE_TAG_NAME (type
) != NULL
)
499 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
500 fputs_filtered (" = ", stream
);
502 if (HAVE_CPLUS_STRUCT (type
))
504 fprintf_filtered (stream
, "class ");
508 fprintf_filtered (stream
, "record ");
512 case TYPE_CODE_UNION
:
513 if (TYPE_TAG_NAME (type
) != NULL
)
515 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
516 fputs_filtered (" = ", stream
);
518 fprintf_filtered (stream
, "case <?> of ");
524 /* If we just printed a tag name, no need to print anything else. */
525 if (TYPE_TAG_NAME (type
) == NULL
)
526 fprintf_filtered (stream
, "{...}");
528 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
530 pascal_type_print_derivation_info (stream
, type
);
532 fprintf_filtered (stream
, "\n");
533 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
535 if (TYPE_STUB (type
))
536 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
538 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
541 /* Start off with no specific section type, so we can print
542 one for the first field we find, and use that section type
543 thereafter until we find another type. */
545 section_type
= s_none
;
547 /* If there is a base class for this type,
548 do not print the field that it occupies. */
550 len
= TYPE_NFIELDS (type
);
551 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
554 /* Don't print out virtual function table. */
555 if ((strncmp (TYPE_FIELD_NAME (type
, i
), "_vptr", 5) == 0)
556 && is_cplus_marker ((TYPE_FIELD_NAME (type
, i
))[5]))
559 /* If this is a pascal object or class we can print the
560 various section labels. */
562 if (HAVE_CPLUS_STRUCT (type
))
564 if (TYPE_FIELD_PROTECTED (type
, i
))
566 if (section_type
!= s_protected
)
568 section_type
= s_protected
;
569 fprintfi_filtered (level
+ 2, stream
,
573 else if (TYPE_FIELD_PRIVATE (type
, i
))
575 if (section_type
!= s_private
)
577 section_type
= s_private
;
578 fprintfi_filtered (level
+ 2, stream
, "private\n");
583 if (section_type
!= s_public
)
585 section_type
= s_public
;
586 fprintfi_filtered (level
+ 2, stream
, "public\n");
591 print_spaces_filtered (level
+ 4, stream
);
592 if (field_is_static (&TYPE_FIELD (type
, i
)))
593 fprintf_filtered (stream
, "static ");
594 pascal_print_type (TYPE_FIELD_TYPE (type
, i
),
595 TYPE_FIELD_NAME (type
, i
),
596 stream
, show
- 1, level
+ 4);
597 if (!field_is_static (&TYPE_FIELD (type
, i
))
598 && TYPE_FIELD_PACKED (type
, i
))
600 /* It is a bitfield. This code does not attempt
601 to look at the bitpos and reconstruct filler,
602 unnamed fields. This would lead to misleading
603 results if the compiler does not put out fields
604 for such things (I don't know what it does). */
605 fprintf_filtered (stream
, " : %d",
606 TYPE_FIELD_BITSIZE (type
, i
));
608 fprintf_filtered (stream
, ";\n");
611 /* If there are both fields and methods, put a space between. */
612 len
= TYPE_NFN_FIELDS (type
);
613 if (len
&& section_type
!= s_none
)
614 fprintf_filtered (stream
, "\n");
616 /* Pbject pascal: print out the methods */
618 for (i
= 0; i
< len
; i
++)
620 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
621 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
622 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
623 char *name
= type_name_no_tag (type
);
624 /* this is GNU C++ specific
625 how can we know constructor/destructor?
626 It might work for GNU pascal */
627 for (j
= 0; j
< len2
; j
++)
629 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
631 int is_constructor
= (strncmp (physname
, "__ct__", 6) == 0);
632 int is_destructor
= (strncmp (physname
, "__dt__", 6) == 0);
635 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
637 if (section_type
!= s_protected
)
639 section_type
= s_protected
;
640 fprintfi_filtered (level
+ 2, stream
,
644 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
646 if (section_type
!= s_private
)
648 section_type
= s_private
;
649 fprintfi_filtered (level
+ 2, stream
, "private\n");
654 if (section_type
!= s_public
)
656 section_type
= s_public
;
657 fprintfi_filtered (level
+ 2, stream
, "public\n");
661 print_spaces_filtered (level
+ 4, stream
);
662 if (TYPE_FN_FIELD_STATIC_P (f
, j
))
663 fprintf_filtered (stream
, "static ");
664 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
666 /* Keep GDB from crashing here. */
667 fprintf_filtered (stream
, "<undefined type> %s;\n",
668 TYPE_FN_FIELD_PHYSNAME (f
, j
));
674 fprintf_filtered (stream
, "constructor ");
676 else if (is_destructor
)
678 fprintf_filtered (stream
, "destructor ");
680 else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) != 0
681 && TYPE_CODE (TYPE_TARGET_TYPE (
682 TYPE_FN_FIELD_TYPE (f
, j
))) != TYPE_CODE_VOID
)
684 fprintf_filtered (stream
, "function ");
688 fprintf_filtered (stream
, "procedure ");
690 /* this does not work, no idea why !! */
692 pascal_type_print_method_args (physname
,
696 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) != 0
697 && TYPE_CODE (TYPE_TARGET_TYPE (
698 TYPE_FN_FIELD_TYPE (f
, j
))) != TYPE_CODE_VOID
)
700 fputs_filtered (" : ", stream
);
701 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
704 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
705 fprintf_filtered (stream
, "; virtual");
707 fprintf_filtered (stream
, ";\n");
710 fprintfi_filtered (level
, stream
, "end");
715 if (TYPE_TAG_NAME (type
) != NULL
)
717 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
719 fputs_filtered (" ", stream
);
721 /* enum is just defined by
722 type enume_name = (enum_member1,enum_member2,...) */
723 fprintf_filtered (stream
, " = ");
727 /* If we just printed a tag name, no need to print anything else. */
728 if (TYPE_TAG_NAME (type
) == NULL
)
729 fprintf_filtered (stream
, "(...)");
731 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
733 fprintf_filtered (stream
, "(");
734 len
= TYPE_NFIELDS (type
);
736 for (i
= 0; i
< len
; i
++)
740 fprintf_filtered (stream
, ", ");
742 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
743 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
745 fprintf_filtered (stream
, " := %d", TYPE_FIELD_BITPOS (type
, i
));
746 lastval
= TYPE_FIELD_BITPOS (type
, i
);
750 fprintf_filtered (stream
, ")");
755 fprintf_filtered (stream
, "void");
758 case TYPE_CODE_UNDEF
:
759 fprintf_filtered (stream
, "record <unknown>");
762 case TYPE_CODE_ERROR
:
763 fprintf_filtered (stream
, "<unknown type>");
766 /* this probably does not work for enums */
767 case TYPE_CODE_RANGE
:
769 struct type
*target
= TYPE_TARGET_TYPE (type
);
770 print_type_scalar (target
, TYPE_LOW_BOUND (type
), stream
);
771 fputs_filtered ("..", stream
);
772 print_type_scalar (target
, TYPE_HIGH_BOUND (type
), stream
);
777 fputs_filtered ("set of ", stream
);
778 pascal_print_type (TYPE_INDEX_TYPE (type
), "", stream
,
782 case TYPE_CODE_BITSTRING
:
783 fputs_filtered ("BitString", stream
);
786 case TYPE_CODE_STRING
:
787 fputs_filtered ("String", stream
);
791 /* Handle types not explicitly handled by the other cases,
792 such as fundamental types. For these, just print whatever
793 the type name is, as recorded in the type itself. If there
794 is no type name, then complain. */
795 if (TYPE_NAME (type
) != NULL
)
797 fputs_filtered (TYPE_NAME (type
), stream
);
801 /* At least for dump_symtab, it is important that this not be
803 fprintf_filtered (stream
, "<invalid unnamed pascal type code %d>",
This page took 0.047028 seconds and 4 git commands to generate.