1 /* Support for printing Pascal types for GDB, the GNU debugger.
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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is derived from p-typeprint.c */
25 #include "bfd.h" /* Binary File Description */
28 #include "expression.h"
37 #include "typeprint.h"
39 #include "gdb_string.h"
43 static void pascal_type_print_args (struct type
*, struct ui_file
*);
45 static void pascal_type_print_varspec_suffix (struct type
*, struct ui_file
*, int, int, int);
47 static void pascal_type_print_derivation_info (struct ui_file
*, struct type
*);
49 void pascal_type_print_varspec_prefix (struct type
*, struct ui_file
*, int, int);
52 /* LEVEL is the depth to indent lines by. */
55 pascal_print_type (type
, varstring
, stream
, show
, level
)
58 struct ui_file
*stream
;
62 register enum type_code code
;
65 code
= TYPE_CODE (type
);
70 if ((code
== TYPE_CODE_FUNC
||
71 code
== TYPE_CODE_METHOD
))
73 pascal_type_print_varspec_prefix (type
, stream
, show
, 0);
76 fputs_filtered (varstring
, stream
);
78 if ((varstring
!= NULL
&& *varstring
!= '\0') &&
79 !(code
== TYPE_CODE_FUNC
||
80 code
== TYPE_CODE_METHOD
))
82 fputs_filtered (" : ", stream
);
85 if (!(code
== TYPE_CODE_FUNC
||
86 code
== TYPE_CODE_METHOD
))
88 pascal_type_print_varspec_prefix (type
, stream
, show
, 0);
91 pascal_type_print_base (type
, stream
, show
, level
);
92 /* For demangled function names, we have the arglist as part of the name,
93 so don't print an additional pair of ()'s */
95 demangled_args
= varstring
? strchr (varstring
, '(') != NULL
: 0;
96 pascal_type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
100 /* If TYPE is a derived type, then print out derivation information.
101 Print only the actual base classes of this type, not the base classes
102 of the base classes. I.E. for the derivation hierarchy:
105 class B : public A {int b; };
106 class C : public B {int c; };
108 Print the type of class C as:
114 Not as the following (like gdb used to), which is not legal C++ syntax for
115 derived types and may be confused with the multiple inheritance form:
117 class C : public B : public A {
121 In general, gdb should try to print the types as closely as possible to
122 the form that they appear in the source code. */
125 pascal_type_print_derivation_info (stream
, type
)
126 struct ui_file
*stream
;
132 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
134 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
135 fprintf_filtered (stream
, "%s%s ",
136 BASETYPE_VIA_PUBLIC (type
, i
) ? "public" : "private",
137 BASETYPE_VIA_VIRTUAL (type
, i
) ? " virtual" : "");
138 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
139 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
143 fputs_filtered (" ", stream
);
147 /* Print the Pascal method arguments ARGS to the file STREAM. */
150 pascal_type_print_method_args (physname
, methodname
, stream
)
153 struct ui_file
*stream
;
155 int is_constructor
= STREQN (physname
, "__ct__", 6);
156 int is_destructor
= STREQN (physname
, "__dt__", 6);
158 if (is_constructor
|| is_destructor
)
163 fputs_filtered (methodname
, stream
);
165 if (physname
&& (*physname
!= 0))
171 fputs_filtered (" (", stream
);
172 /* we must demangle this */
173 while (isdigit (physname
[0]))
175 while (isdigit (physname
[len
]))
179 i
= strtol (physname
, &argname
, 0);
181 storec
= physname
[i
];
183 fputs_filtered (physname
, stream
);
184 physname
[i
] = storec
;
186 if (physname
[0] != 0)
188 fputs_filtered (", ", stream
);
191 fputs_filtered (")", stream
);
195 /* Print any asterisks or open-parentheses needed before the
196 variable name (to describe its type).
198 On outermost call, pass 0 for PASSED_A_PTR.
199 On outermost call, SHOW > 0 means should ignore
200 any typename for TYPE and show its details.
201 SHOW is always zero on recursive calls. */
204 pascal_type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
206 struct ui_file
*stream
;
214 if (TYPE_NAME (type
) && show
<= 0)
219 switch (TYPE_CODE (type
))
222 fprintf_filtered (stream
, "^");
223 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
224 break; /* pointer should be handled normally in pascal */
226 case TYPE_CODE_MEMBER
:
228 fprintf_filtered (stream
, "(");
229 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
230 fprintf_filtered (stream
, " ");
231 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
233 fputs_filtered (name
, stream
);
235 pascal_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
236 fprintf_filtered (stream
, "::");
239 case TYPE_CODE_METHOD
:
241 fprintf_filtered (stream
, "(");
242 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
244 fprintf_filtered (stream
, "function ");
248 fprintf_filtered (stream
, "procedure ");
253 fprintf_filtered (stream
, " ");
254 pascal_type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
255 fprintf_filtered (stream
, "::");
260 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
261 fprintf_filtered (stream
, "&");
266 fprintf_filtered (stream
, "(");
268 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
270 fprintf_filtered (stream
, "function ");
274 fprintf_filtered (stream
, "procedure ");
279 case TYPE_CODE_ARRAY
:
281 fprintf_filtered (stream
, "(");
282 fprintf_filtered (stream
, "array ");
283 if (TYPE_LENGTH (type
) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0
284 && TYPE_ARRAY_UPPER_BOUND_TYPE (type
) != BOUND_CANNOT_BE_DETERMINED
)
285 fprintf_filtered (stream
, "[%d..%d] ",
286 TYPE_ARRAY_LOWER_BOUND_VALUE (type
),
287 TYPE_ARRAY_UPPER_BOUND_VALUE (type
)
289 fprintf_filtered (stream
, "of ");
292 case TYPE_CODE_UNDEF
:
293 case TYPE_CODE_STRUCT
:
294 case TYPE_CODE_UNION
:
299 case TYPE_CODE_ERROR
:
303 case TYPE_CODE_RANGE
:
304 case TYPE_CODE_STRING
:
305 case TYPE_CODE_BITSTRING
:
306 case TYPE_CODE_COMPLEX
:
307 case TYPE_CODE_TYPEDEF
:
308 case TYPE_CODE_TEMPLATE
:
309 /* These types need no prefix. They are listed here so that
310 gcc -Wall will reveal any types that haven't been handled. */
313 error ("type not handled in pascal_type_print_varspec_prefix()");
319 pascal_type_print_args (type
, stream
)
321 struct ui_file
*stream
;
326 /* fprintf_filtered (stream, "(");
327 no () for procedures !! */
328 args
= TYPE_ARG_TYPES (type
);
331 if ((args
[1] != NULL
&& args
[1]->code
!= TYPE_CODE_VOID
) ||
334 fprintf_filtered (stream
, "(");
338 fprintf_filtered (stream
, "...");
343 args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
;
346 pascal_print_type (args
[i
], "", stream
, -1, 0);
347 if (args
[i
+ 1] == NULL
)
349 fprintf_filtered (stream
, "...");
351 else if (args
[i
+ 1]->code
!= TYPE_CODE_VOID
)
353 fprintf_filtered (stream
, ",");
358 if ((args
[1] != NULL
&& args
[1]->code
!= TYPE_CODE_VOID
) ||
361 fprintf_filtered (stream
, ")");
367 pascal_print_func_args (struct type
*type
, struct ui_file
*stream
)
369 int i
, len
= TYPE_NFIELDS (type
);
372 fprintf_filtered (stream
, "(");
374 for (i
= 0; i
< len
; i
++)
378 fputs_filtered (", ", stream
);
381 /* can we find if it is a var parameter ??
382 if ( TYPE_FIELD(type, i) == )
384 fprintf_filtered (stream, "var ");
386 pascal_print_type (TYPE_FIELD_TYPE (type
, i
), "" /* TYPE_FIELD_NAME seems invalid ! */
391 fprintf_filtered (stream
, ")");
395 /* Print any array sizes, function arguments or close parentheses
396 needed after the variable name (to describe its type).
397 Args work like pascal_type_print_varspec_prefix. */
400 pascal_type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
, demangled_args
)
402 struct ui_file
*stream
;
410 if (TYPE_NAME (type
) && show
<= 0)
415 switch (TYPE_CODE (type
))
417 case TYPE_CODE_ARRAY
:
419 fprintf_filtered (stream
, ")");
422 case TYPE_CODE_MEMBER
:
424 fprintf_filtered (stream
, ")");
425 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
428 case TYPE_CODE_METHOD
:
430 fprintf_filtered (stream
, ")");
431 pascal_type_print_method_args ("",
434 /* pascal_type_print_args (type, stream); */
435 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
437 fprintf_filtered (stream
, " : ");
438 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
439 pascal_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, 0);
440 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
447 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
452 fprintf_filtered (stream
, ")");
454 pascal_print_func_args (type
, stream
);
455 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_VOID
)
457 fprintf_filtered (stream
, " : ");
458 pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
459 pascal_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, 0);
460 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
465 case TYPE_CODE_UNDEF
:
466 case TYPE_CODE_STRUCT
:
467 case TYPE_CODE_UNION
:
472 case TYPE_CODE_ERROR
:
476 case TYPE_CODE_RANGE
:
477 case TYPE_CODE_STRING
:
478 case TYPE_CODE_BITSTRING
:
479 case TYPE_CODE_COMPLEX
:
480 case TYPE_CODE_TYPEDEF
:
481 case TYPE_CODE_TEMPLATE
:
482 /* These types do not need a suffix. They are listed so that
483 gcc -Wall will report types that may not have been considered. */
486 error ("type not handled in pascal_type_print_varspec_suffix()");
491 /* Print the name of the type (or the ultimate pointer target,
492 function value or array element), or the description of a
495 SHOW positive means print details about the type (e.g. enum values),
496 and print structure elements passing SHOW - 1 for show.
497 SHOW negative means just print the type name or struct tag if there is one.
498 If there is no name, print something sensible but concise like
500 SHOW zero means just print the type name or struct tag if there is one.
501 If there is no name, print something sensible but not as concise like
502 "struct {int x; int y;}".
504 LEVEL is the number of spaces to indent by.
505 We increase it for some recursive calls. */
508 pascal_type_print_base (type
, stream
, show
, level
)
510 struct ui_file
*stream
;
516 register int lastval
;
519 s_none
, s_public
, s_private
, s_protected
527 fputs_filtered ("<type unknown>", stream
);
532 if ((TYPE_CODE (type
) == TYPE_CODE_PTR
) && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_VOID
))
534 fprintf_filtered (stream
,
535 TYPE_NAME (type
) ? TYPE_NAME (type
) : "pointer");
538 /* When SHOW is zero or less, and there is a valid type name, then always
539 just print the type name directly from the type. */
542 && TYPE_NAME (type
) != NULL
)
544 fputs_filtered (TYPE_NAME (type
), stream
);
548 CHECK_TYPEDEF (type
);
550 switch (TYPE_CODE (type
))
552 case TYPE_CODE_TYPEDEF
:
554 case TYPE_CODE_MEMBER
:
556 /* case TYPE_CODE_FUNC:
557 case TYPE_CODE_METHOD: */
558 pascal_type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
561 case TYPE_CODE_ARRAY
:
562 /* pascal_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
563 pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
564 pascal_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0); */
565 pascal_print_type (TYPE_TARGET_TYPE (type
), NULL
, stream
, 0, 0);
569 case TYPE_CODE_METHOD
:
571 pascal_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
572 only after args !! */
574 case TYPE_CODE_STRUCT
:
575 if (TYPE_TAG_NAME (type
) != NULL
)
577 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
578 fputs_filtered (" = ", stream
);
580 if (HAVE_CPLUS_STRUCT (type
))
582 fprintf_filtered (stream
, "class ");
586 fprintf_filtered (stream
, "record ");
590 case TYPE_CODE_UNION
:
591 if (TYPE_TAG_NAME (type
) != NULL
)
593 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
594 fputs_filtered (" = ", stream
);
596 fprintf_filtered (stream
, "case <?> of ");
602 /* If we just printed a tag name, no need to print anything else. */
603 if (TYPE_TAG_NAME (type
) == NULL
)
604 fprintf_filtered (stream
, "{...}");
606 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
608 pascal_type_print_derivation_info (stream
, type
);
610 fprintf_filtered (stream
, "\n");
611 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
613 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
614 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
616 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
619 /* Start off with no specific section type, so we can print
620 one for the first field we find, and use that section type
621 thereafter until we find another type. */
623 section_type
= s_none
;
625 /* If there is a base class for this type,
626 do not print the field that it occupies. */
628 len
= TYPE_NFIELDS (type
);
629 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
632 /* Don't print out virtual function table. */
633 if (STREQN (TYPE_FIELD_NAME (type
, i
), "_vptr", 5)
634 && is_cplus_marker ((TYPE_FIELD_NAME (type
, i
))[5]))
637 /* If this is a pascal object or class we can print the
638 various section labels. */
640 if (HAVE_CPLUS_STRUCT (type
))
642 if (TYPE_FIELD_PROTECTED (type
, i
))
644 if (section_type
!= s_protected
)
646 section_type
= s_protected
;
647 fprintfi_filtered (level
+ 2, stream
,
651 else if (TYPE_FIELD_PRIVATE (type
, i
))
653 if (section_type
!= s_private
)
655 section_type
= s_private
;
656 fprintfi_filtered (level
+ 2, stream
, "private\n");
661 if (section_type
!= s_public
)
663 section_type
= s_public
;
664 fprintfi_filtered (level
+ 2, stream
, "public\n");
669 print_spaces_filtered (level
+ 4, stream
);
670 if (TYPE_FIELD_STATIC (type
, i
))
672 fprintf_filtered (stream
, "static ");
674 pascal_print_type (TYPE_FIELD_TYPE (type
, i
),
675 TYPE_FIELD_NAME (type
, i
),
676 stream
, show
- 1, level
+ 4);
677 if (!TYPE_FIELD_STATIC (type
, i
)
678 && TYPE_FIELD_PACKED (type
, i
))
680 /* It is a bitfield. This code does not attempt
681 to look at the bitpos and reconstruct filler,
682 unnamed fields. This would lead to misleading
683 results if the compiler does not put out fields
684 for such things (I don't know what it does). */
685 fprintf_filtered (stream
, " : %d",
686 TYPE_FIELD_BITSIZE (type
, i
));
688 fprintf_filtered (stream
, ";\n");
691 /* If there are both fields and methods, put a space between. */
692 len
= TYPE_NFN_FIELDS (type
);
693 if (len
&& section_type
!= s_none
)
694 fprintf_filtered (stream
, "\n");
696 /* Pbject pascal: print out the methods */
698 for (i
= 0; i
< len
; i
++)
700 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
701 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
702 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
703 char *name
= type_name_no_tag (type
);
704 /* this is GNU C++ specific
705 how can we know constructor/destructor?
706 It might work for GNU pascal */
707 for (j
= 0; j
< len2
; j
++)
709 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
711 int is_constructor
= STREQN (physname
, "__ct__", 6);
712 int is_destructor
= STREQN (physname
, "__dt__", 6);
715 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
717 if (section_type
!= s_protected
)
719 section_type
= s_protected
;
720 fprintfi_filtered (level
+ 2, stream
,
724 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
726 if (section_type
!= s_private
)
728 section_type
= s_private
;
729 fprintfi_filtered (level
+ 2, stream
, "private\n");
734 if (section_type
!= s_public
)
736 section_type
= s_public
;
737 fprintfi_filtered (level
+ 2, stream
, "public\n");
741 print_spaces_filtered (level
+ 4, stream
);
742 if (TYPE_FN_FIELD_STATIC_P (f
, j
))
743 fprintf_filtered (stream
, "static ");
744 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
746 /* Keep GDB from crashing here. */
747 fprintf_filtered (stream
, "<undefined type> %s;\n",
748 TYPE_FN_FIELD_PHYSNAME (f
, j
));
754 fprintf_filtered (stream
, "constructor ");
756 else if (is_destructor
)
758 fprintf_filtered (stream
, "destructor ");
760 else if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) != 0 &&
761 TYPE_CODE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
))) != TYPE_CODE_VOID
)
763 fprintf_filtered (stream
, "function ");
767 fprintf_filtered (stream
, "procedure ");
769 /* this does not work, no idea why !! */
771 pascal_type_print_method_args (physname
,
775 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) != 0 &&
776 TYPE_CODE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
))) != TYPE_CODE_VOID
)
778 fputs_filtered (" : ", stream
);
779 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
782 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
783 fprintf_filtered (stream
, "; virtual");
785 fprintf_filtered (stream
, ";\n");
788 fprintfi_filtered (level
, stream
, "end");
793 if (TYPE_TAG_NAME (type
) != NULL
)
795 fputs_filtered (TYPE_TAG_NAME (type
), stream
);
797 fputs_filtered (" ", stream
);
799 /* enum is just defined by
800 type enume_name = (enum_member1,enum_member2,...) */
801 fprintf_filtered (stream
, " = ");
805 /* If we just printed a tag name, no need to print anything else. */
806 if (TYPE_TAG_NAME (type
) == NULL
)
807 fprintf_filtered (stream
, "(...)");
809 else if (show
> 0 || TYPE_TAG_NAME (type
) == NULL
)
811 fprintf_filtered (stream
, "(");
812 len
= TYPE_NFIELDS (type
);
814 for (i
= 0; i
< len
; i
++)
818 fprintf_filtered (stream
, ", ");
820 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
821 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
823 fprintf_filtered (stream
, " := %d", TYPE_FIELD_BITPOS (type
, i
));
824 lastval
= TYPE_FIELD_BITPOS (type
, i
);
828 fprintf_filtered (stream
, ")");
833 fprintf_filtered (stream
, "void");
836 case TYPE_CODE_UNDEF
:
837 fprintf_filtered (stream
, "record <unknown>");
840 case TYPE_CODE_ERROR
:
841 fprintf_filtered (stream
, "<unknown type>");
844 /* this probably does not work for enums */
845 case TYPE_CODE_RANGE
:
847 struct type
*target
= TYPE_TARGET_TYPE (type
);
849 target
= builtin_type_long
;
850 print_type_scalar (target
, TYPE_LOW_BOUND (type
), stream
);
851 fputs_filtered ("..", stream
);
852 print_type_scalar (target
, TYPE_HIGH_BOUND (type
), stream
);
857 fputs_filtered ("set of ", stream
);
858 pascal_print_type (TYPE_INDEX_TYPE (type
), "", stream
,
863 /* Handle types not explicitly handled by the other cases,
864 such as fundamental types. For these, just print whatever
865 the type name is, as recorded in the type itself. If there
866 is no type name, then complain. */
867 if (TYPE_NAME (type
) != NULL
)
869 fputs_filtered (TYPE_NAME (type
), stream
);
873 /* At least for dump_symtab, it is important that this not be
875 fprintf_filtered (stream
, "<invalid unnamed pascal type code %d>",