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