* Makefile.in (VERSION): Bump to 4.7.4.
[binutils-gdb.git] / gdb / ch-typeprint.c
1 /* Support for printing Chill types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "defs.h"
21 #include "obstack.h"
22 #include "bfd.h" /* Binary File Description */
23 #include "symtab.h"
24 #include "gdbtypes.h"
25 #include "expression.h"
26 #include "value.h"
27 #include "gdbcore.h"
28 #include "target.h"
29 #include "command.h"
30 #include "gdbcmd.h"
31 #include "language.h"
32 #include "demangle.h"
33 #include "ch-lang.h"
34
35 #include <string.h>
36 #include <errno.h>
37
38 void
39 chill_print_type_base PARAMS ((struct type *, FILE *, int, int));
40
41 void
42 chill_print_type (type, varstring, stream, show, level)
43 struct type *type;
44 char *varstring;
45 FILE *stream;
46 int show;
47 int level;
48 {
49 struct type *index_type;
50 struct type *range_type;
51 LONGEST low_bound;
52 LONGEST high_bound;
53
54 if (varstring != NULL && *varstring != '\0')
55 {
56 fputs_filtered (varstring, stream);
57 fputs_filtered (" ", stream);
58 }
59 switch (TYPE_CODE (type))
60 {
61 case TYPE_CODE_ARRAY:
62 range_type = TYPE_FIELD_TYPE (type, 0);
63 index_type = TYPE_TARGET_TYPE (range_type);
64 low_bound = TYPE_FIELD_BITPOS (range_type, 0);
65 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
66 fputs_filtered ("array (", stream);
67 print_type_scalar (index_type, low_bound, stream);
68 fputs_filtered (":", stream);
69 print_type_scalar (index_type, high_bound, stream);
70 fputs_filtered (") ", stream);
71 chill_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level);
72 break;
73 default:
74 chill_print_type_base (type, stream, show, level);
75 break;
76 }
77 }
78
79 /* Print the name of the type (or the ultimate pointer target,
80 function value or array element).
81
82 SHOW nonzero means don't print this type as just its name;
83 show its real definition even if it has a name.
84 SHOW zero means print just typename or tag if there is one
85 SHOW negative means abbreviate structure elements.
86 SHOW is decremented for printing of structure elements.
87
88 LEVEL is the depth to indent by.
89 We increase it for some recursive calls. */
90
91 void
92 chill_print_type_base (type, stream, show, level)
93 struct type *type;
94 FILE *stream;
95 int show;
96 int level;
97 {
98 QUIT;
99
100 wrap_here (" ");
101 if (type == NULL)
102 {
103 fputs_filtered ("<type unknown>", stream);
104 return;
105 }
106
107 /* When SHOW is zero or less, and there is a valid type name, then always
108 just print the type name directly from the type. */
109
110 if ((show <= 0) && (TYPE_NAME (type) != NULL))
111 {
112 fputs_filtered (TYPE_NAME (type), stream);
113 return;
114 }
115
116 switch (TYPE_CODE (type))
117 {
118 case TYPE_CODE_ARRAY:
119 case TYPE_CODE_PTR:
120 case TYPE_CODE_MEMBER:
121 case TYPE_CODE_REF:
122 case TYPE_CODE_FUNC:
123 chill_print_type_base (TYPE_TARGET_TYPE (type), stream, show, level);
124 break;
125
126 case TYPE_CODE_VOID:
127 case TYPE_CODE_UNDEF:
128 case TYPE_CODE_ERROR:
129 case TYPE_CODE_RANGE:
130 case TYPE_CODE_ENUM:
131 case TYPE_CODE_UNION:
132 case TYPE_CODE_STRUCT:
133 case TYPE_CODE_METHOD:
134 error ("missing language support in chill_print_type_base");
135 break;
136
137 default:
138
139 /* Handle types not explicitly handled by the other cases,
140 such as fundamental types. For these, just print whatever
141 the type name is, as recorded in the type itself. If there
142 is no type name, then complain. */
143
144 if (TYPE_NAME (type) != NULL)
145 {
146 fputs_filtered (TYPE_NAME (type), stream);
147 }
148 else
149 {
150 error ("Unrecognized type code (%d) in symbol table.",
151 TYPE_CODE (type));
152 }
153 break;
154 }
155 }