Commit | Line | Data |
---|---|---|
a8a69e63 FF |
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 | ||
8fbdca53 FF |
38 | static void |
39 | chill_type_print_base PARAMS ((struct type *, FILE *, int, int)); | |
a8a69e63 FF |
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; | |
ec16f701 FF |
73 | |
74 | case TYPE_CODE_STRING: | |
75 | range_type = TYPE_FIELD_TYPE (type, 0); | |
76 | index_type = TYPE_TARGET_TYPE (range_type); | |
77 | high_bound = TYPE_FIELD_BITPOS (range_type, 1); | |
8fbdca53 | 78 | fputs_filtered ("CHAR (", stream); |
ec16f701 | 79 | print_type_scalar (index_type, high_bound + 1, stream); |
8fbdca53 | 80 | fputs_filtered (")", stream); |
ec16f701 FF |
81 | break; |
82 | ||
a8a69e63 | 83 | default: |
8fbdca53 | 84 | chill_type_print_base (type, stream, show, level); |
a8a69e63 FF |
85 | break; |
86 | } | |
87 | } | |
88 | ||
89 | /* Print the name of the type (or the ultimate pointer target, | |
90 | function value or array element). | |
91 | ||
92 | SHOW nonzero means don't print this type as just its name; | |
93 | show its real definition even if it has a name. | |
94 | SHOW zero means print just typename or tag if there is one | |
95 | SHOW negative means abbreviate structure elements. | |
96 | SHOW is decremented for printing of structure elements. | |
97 | ||
98 | LEVEL is the depth to indent by. | |
99 | We increase it for some recursive calls. */ | |
100 | ||
8fbdca53 FF |
101 | static void |
102 | chill_type_print_base (type, stream, show, level) | |
a8a69e63 FF |
103 | struct type *type; |
104 | FILE *stream; | |
105 | int show; | |
106 | int level; | |
107 | { | |
8fbdca53 FF |
108 | char *name; |
109 | register int len; | |
110 | register int i; | |
111 | ||
a8a69e63 FF |
112 | QUIT; |
113 | ||
114 | wrap_here (" "); | |
115 | if (type == NULL) | |
116 | { | |
117 | fputs_filtered ("<type unknown>", stream); | |
118 | return; | |
119 | } | |
120 | ||
121 | /* When SHOW is zero or less, and there is a valid type name, then always | |
122 | just print the type name directly from the type. */ | |
123 | ||
124 | if ((show <= 0) && (TYPE_NAME (type) != NULL)) | |
125 | { | |
126 | fputs_filtered (TYPE_NAME (type), stream); | |
127 | return; | |
128 | } | |
129 | ||
130 | switch (TYPE_CODE (type)) | |
131 | { | |
132 | case TYPE_CODE_ARRAY: | |
133 | case TYPE_CODE_PTR: | |
134 | case TYPE_CODE_MEMBER: | |
135 | case TYPE_CODE_REF: | |
136 | case TYPE_CODE_FUNC: | |
8fbdca53 FF |
137 | chill_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); |
138 | break; | |
139 | ||
140 | case TYPE_CODE_STRUCT: | |
141 | fprintf_filtered (stream, "STRUCT "); | |
142 | if ((name = type_name_no_tag (type)) != NULL) | |
143 | { | |
144 | fputs_filtered (name, stream); | |
145 | fputs_filtered (" ", stream); | |
146 | wrap_here (" "); | |
147 | } | |
148 | if (show < 0) | |
149 | { | |
150 | fprintf_filtered (stream, "(...)"); | |
151 | } | |
152 | else | |
153 | { | |
154 | check_stub_type (type); | |
155 | fprintf_filtered (stream, "(\n"); | |
156 | if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0)) | |
157 | { | |
158 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
159 | { | |
160 | fprintfi_filtered (level + 4, stream, "<incomplete type>\n"); | |
161 | } | |
162 | else | |
163 | { | |
164 | fprintfi_filtered (level + 4, stream, "<no data fields>\n"); | |
165 | } | |
166 | } | |
167 | else | |
168 | { | |
169 | len = TYPE_NFIELDS (type); | |
170 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
171 | { | |
172 | QUIT; | |
173 | print_spaces_filtered (level + 4, stream); | |
174 | chill_print_type (TYPE_FIELD_TYPE (type, i), | |
175 | TYPE_FIELD_NAME (type, i), | |
176 | stream, show - 1, level + 4); | |
177 | if (i < (len - 1)) | |
178 | { | |
179 | fputs_filtered (",", stream); | |
180 | } | |
181 | fputs_filtered ("\n", stream); | |
182 | } | |
183 | } | |
184 | fprintfi_filtered (level, stream, ")"); | |
185 | } | |
a8a69e63 FF |
186 | break; |
187 | ||
188 | case TYPE_CODE_VOID: | |
189 | case TYPE_CODE_UNDEF: | |
190 | case TYPE_CODE_ERROR: | |
191 | case TYPE_CODE_RANGE: | |
192 | case TYPE_CODE_ENUM: | |
193 | case TYPE_CODE_UNION: | |
a8a69e63 | 194 | case TYPE_CODE_METHOD: |
8fbdca53 | 195 | error ("missing language support in chill_type_print_base"); |
a8a69e63 FF |
196 | break; |
197 | ||
198 | default: | |
199 | ||
200 | /* Handle types not explicitly handled by the other cases, | |
201 | such as fundamental types. For these, just print whatever | |
202 | the type name is, as recorded in the type itself. If there | |
203 | is no type name, then complain. */ | |
204 | ||
205 | if (TYPE_NAME (type) != NULL) | |
206 | { | |
207 | fputs_filtered (TYPE_NAME (type), stream); | |
208 | } | |
209 | else | |
210 | { | |
211 | error ("Unrecognized type code (%d) in symbol table.", | |
212 | TYPE_CODE (type)); | |
213 | } | |
214 | break; | |
215 | } | |
216 | } |