]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Support routines for manipulating internal types for GDB. |
2 | Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support, using pieces from other GDB modules. | |
4 | ||
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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. | |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b JM |
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, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "gdb_string.h" | |
24 | #include "bfd.h" | |
25 | #include "symtab.h" | |
26 | #include "symfile.h" | |
27 | #include "objfiles.h" | |
28 | #include "gdbtypes.h" | |
29 | #include "expression.h" | |
30 | #include "language.h" | |
31 | #include "target.h" | |
32 | #include "value.h" | |
33 | #include "demangle.h" | |
34 | #include "complaints.h" | |
35 | #include "gdbcmd.h" | |
36 | ||
37 | /* These variables point to the objects | |
38 | representing the predefined C data types. */ | |
39 | ||
40 | struct type *builtin_type_void; | |
41 | struct type *builtin_type_char; | |
9e0b60a8 | 42 | struct type *builtin_type_true_char; |
c906108c SS |
43 | struct type *builtin_type_short; |
44 | struct type *builtin_type_int; | |
45 | struct type *builtin_type_long; | |
46 | struct type *builtin_type_long_long; | |
47 | struct type *builtin_type_signed_char; | |
48 | struct type *builtin_type_unsigned_char; | |
49 | struct type *builtin_type_unsigned_short; | |
50 | struct type *builtin_type_unsigned_int; | |
51 | struct type *builtin_type_unsigned_long; | |
52 | struct type *builtin_type_unsigned_long_long; | |
53 | struct type *builtin_type_float; | |
54 | struct type *builtin_type_double; | |
55 | struct type *builtin_type_long_double; | |
56 | struct type *builtin_type_complex; | |
57 | struct type *builtin_type_double_complex; | |
58 | struct type *builtin_type_string; | |
59 | struct type *builtin_type_int8; | |
60 | struct type *builtin_type_uint8; | |
61 | struct type *builtin_type_int16; | |
62 | struct type *builtin_type_uint16; | |
63 | struct type *builtin_type_int32; | |
64 | struct type *builtin_type_uint32; | |
65 | struct type *builtin_type_int64; | |
66 | struct type *builtin_type_uint64; | |
67 | struct type *builtin_type_bool; | |
917317f4 | 68 | struct type *builtin_type_v4sf; |
c2d11a7d JM |
69 | struct type *builtin_type_v4si; |
70 | struct type *builtin_type_v8qi; | |
71 | struct type *builtin_type_v4hi; | |
72 | struct type *builtin_type_v2si; | |
c4093a6a JM |
73 | struct type *builtin_type_ptr; |
74 | struct type *builtin_type_CORE_ADDR; | |
75 | struct type *builtin_type_bfd_vma; | |
c906108c SS |
76 | |
77 | int opaque_type_resolution = 1; | |
78 | ||
79 | ||
c5aa993b JM |
80 | struct extra |
81 | { | |
82 | char str[128]; | |
83 | int len; | |
84 | }; /* maximum extention is 128! FIXME */ | |
c906108c SS |
85 | |
86 | static void add_name PARAMS ((struct extra *, char *)); | |
87 | static void add_mangled_type PARAMS ((struct extra *, struct type *)); | |
88 | #if 0 | |
89 | static void cfront_mangle_name PARAMS ((struct type *, int, int)); | |
90 | #endif | |
91 | static void print_bit_vector PARAMS ((B_TYPE *, int)); | |
92 | static void print_arg_types PARAMS ((struct type **, int)); | |
93 | static void dump_fn_fieldlists PARAMS ((struct type *, int)); | |
94 | static void print_cplus_stuff PARAMS ((struct type *, int)); | |
c5aa993b | 95 | static void virtual_base_list_aux PARAMS ((struct type * dclass)); |
7a292a7a | 96 | |
c906108c SS |
97 | |
98 | /* Alloc a new type structure and fill it with some defaults. If | |
99 | OBJFILE is non-NULL, then allocate the space for the type structure | |
100 | in that objfile's type_obstack. */ | |
101 | ||
102 | struct type * | |
103 | alloc_type (objfile) | |
104 | struct objfile *objfile; | |
105 | { | |
106 | register struct type *type; | |
107 | ||
108 | /* Alloc the structure and start off with all fields zeroed. */ | |
109 | ||
110 | if (objfile == NULL) | |
111 | { | |
c5aa993b | 112 | type = (struct type *) xmalloc (sizeof (struct type)); |
c906108c SS |
113 | } |
114 | else | |
115 | { | |
c5aa993b JM |
116 | type = (struct type *) obstack_alloc (&objfile->type_obstack, |
117 | sizeof (struct type)); | |
c906108c SS |
118 | OBJSTAT (objfile, n_types++); |
119 | } | |
120 | memset ((char *) type, 0, sizeof (struct type)); | |
121 | ||
122 | /* Initialize the fields that might not be zero. */ | |
123 | ||
124 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
125 | TYPE_OBJFILE (type) = objfile; | |
126 | TYPE_VPTR_FIELDNO (type) = -1; | |
c5aa993b | 127 | TYPE_CV_TYPE (type) = type; /* chain back to itself */ |
c906108c SS |
128 | |
129 | return (type); | |
130 | } | |
131 | ||
132 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points | |
133 | to a pointer to memory where the pointer type should be stored. | |
134 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
135 | We allocate new memory if needed. */ | |
136 | ||
137 | struct type * | |
138 | make_pointer_type (type, typeptr) | |
139 | struct type *type; | |
140 | struct type **typeptr; | |
141 | { | |
c5aa993b | 142 | register struct type *ntype; /* New type */ |
c906108c SS |
143 | struct objfile *objfile; |
144 | ||
145 | ntype = TYPE_POINTER_TYPE (type); | |
146 | ||
c5aa993b | 147 | if (ntype) |
c906108c | 148 | { |
c5aa993b JM |
149 | if (typeptr == 0) |
150 | return ntype; /* Don't care about alloc, and have new type. */ | |
c906108c | 151 | else if (*typeptr == 0) |
c5aa993b | 152 | { |
c906108c SS |
153 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
154 | return ntype; | |
c5aa993b | 155 | } |
c906108c SS |
156 | } |
157 | ||
158 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
159 | { | |
160 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
161 | if (typeptr) | |
162 | *typeptr = ntype; | |
163 | } | |
c5aa993b JM |
164 | else |
165 | /* We have storage, but need to reset it. */ | |
c906108c SS |
166 | { |
167 | ntype = *typeptr; | |
168 | objfile = TYPE_OBJFILE (ntype); | |
169 | memset ((char *) ntype, 0, sizeof (struct type)); | |
170 | TYPE_OBJFILE (ntype) = objfile; | |
171 | } | |
172 | ||
173 | TYPE_TARGET_TYPE (ntype) = type; | |
174 | TYPE_POINTER_TYPE (type) = ntype; | |
175 | ||
176 | /* FIXME! Assume the machine has only one representation for pointers! */ | |
177 | ||
178 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
179 | TYPE_CODE (ntype) = TYPE_CODE_PTR; | |
180 | ||
181 | /* pointers are unsigned */ | |
182 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; | |
c5aa993b | 183 | |
c906108c SS |
184 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ |
185 | TYPE_POINTER_TYPE (type) = ntype; | |
186 | ||
187 | return ntype; | |
188 | } | |
189 | ||
190 | /* Given a type TYPE, return a type of pointers to that type. | |
191 | May need to construct such a type if this is the first use. */ | |
192 | ||
193 | struct type * | |
194 | lookup_pointer_type (type) | |
195 | struct type *type; | |
196 | { | |
c5aa993b | 197 | return make_pointer_type (type, (struct type **) 0); |
c906108c SS |
198 | } |
199 | ||
200 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points | |
201 | to a pointer to memory where the reference type should be stored. | |
202 | If *TYPEPTR is zero, update it to point to the reference type we return. | |
203 | We allocate new memory if needed. */ | |
204 | ||
205 | struct type * | |
206 | make_reference_type (type, typeptr) | |
207 | struct type *type; | |
208 | struct type **typeptr; | |
209 | { | |
c5aa993b | 210 | register struct type *ntype; /* New type */ |
c906108c SS |
211 | struct objfile *objfile; |
212 | ||
213 | ntype = TYPE_REFERENCE_TYPE (type); | |
214 | ||
c5aa993b | 215 | if (ntype) |
c906108c | 216 | { |
c5aa993b JM |
217 | if (typeptr == 0) |
218 | return ntype; /* Don't care about alloc, and have new type. */ | |
c906108c | 219 | else if (*typeptr == 0) |
c5aa993b | 220 | { |
c906108c SS |
221 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
222 | return ntype; | |
c5aa993b | 223 | } |
c906108c SS |
224 | } |
225 | ||
226 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
227 | { | |
228 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
229 | if (typeptr) | |
230 | *typeptr = ntype; | |
231 | } | |
c5aa993b JM |
232 | else |
233 | /* We have storage, but need to reset it. */ | |
c906108c SS |
234 | { |
235 | ntype = *typeptr; | |
236 | objfile = TYPE_OBJFILE (ntype); | |
237 | memset ((char *) ntype, 0, sizeof (struct type)); | |
238 | TYPE_OBJFILE (ntype) = objfile; | |
239 | } | |
240 | ||
241 | TYPE_TARGET_TYPE (ntype) = type; | |
242 | TYPE_REFERENCE_TYPE (type) = ntype; | |
243 | ||
244 | /* FIXME! Assume the machine has only one representation for references, | |
245 | and that it matches the (only) representation for pointers! */ | |
246 | ||
247 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
248 | TYPE_CODE (ntype) = TYPE_CODE_REF; | |
c5aa993b | 249 | |
c906108c SS |
250 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
251 | TYPE_REFERENCE_TYPE (type) = ntype; | |
252 | ||
253 | return ntype; | |
254 | } | |
255 | ||
256 | /* Same as above, but caller doesn't care about memory allocation details. */ | |
257 | ||
258 | struct type * | |
259 | lookup_reference_type (type) | |
260 | struct type *type; | |
261 | { | |
c5aa993b | 262 | return make_reference_type (type, (struct type **) 0); |
c906108c SS |
263 | } |
264 | ||
265 | /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points | |
266 | to a pointer to memory where the function type should be stored. | |
267 | If *TYPEPTR is zero, update it to point to the function type we return. | |
268 | We allocate new memory if needed. */ | |
269 | ||
270 | struct type * | |
271 | make_function_type (type, typeptr) | |
272 | struct type *type; | |
273 | struct type **typeptr; | |
274 | { | |
c5aa993b | 275 | register struct type *ntype; /* New type */ |
c906108c SS |
276 | struct objfile *objfile; |
277 | ||
278 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
279 | { | |
280 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
281 | if (typeptr) | |
282 | *typeptr = ntype; | |
283 | } | |
c5aa993b JM |
284 | else |
285 | /* We have storage, but need to reset it. */ | |
c906108c SS |
286 | { |
287 | ntype = *typeptr; | |
288 | objfile = TYPE_OBJFILE (ntype); | |
289 | memset ((char *) ntype, 0, sizeof (struct type)); | |
290 | TYPE_OBJFILE (ntype) = objfile; | |
291 | } | |
292 | ||
293 | TYPE_TARGET_TYPE (ntype) = type; | |
294 | ||
295 | TYPE_LENGTH (ntype) = 1; | |
296 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
c5aa993b | 297 | |
c906108c SS |
298 | return ntype; |
299 | } | |
300 | ||
301 | ||
302 | /* Given a type TYPE, return a type of functions that return that type. | |
303 | May need to construct such a type if this is the first use. */ | |
304 | ||
305 | struct type * | |
306 | lookup_function_type (type) | |
307 | struct type *type; | |
308 | { | |
c5aa993b | 309 | return make_function_type (type, (struct type **) 0); |
c906108c SS |
310 | } |
311 | ||
312 | ||
313 | /* Make a "c-v" variant of a type -- a type that is identical to the | |
314 | one supplied except that it may have const or volatile attributes | |
315 | CNST is a flag for setting the const attribute | |
316 | VOLTL is a flag for setting the volatile attribute | |
317 | TYPE is the base type whose variant we are creating. | |
318 | TYPEPTR, if nonzero, points | |
319 | to a pointer to memory where the reference type should be stored. | |
320 | If *TYPEPTR is zero, update it to point to the reference type we return. | |
321 | We allocate new memory if needed. */ | |
322 | ||
323 | struct type * | |
324 | make_cv_type (cnst, voltl, type, typeptr) | |
325 | int cnst; | |
326 | int voltl; | |
327 | struct type *type; | |
328 | struct type **typeptr; | |
329 | { | |
c5aa993b JM |
330 | register struct type *ntype; /* New type */ |
331 | register struct type *tmp_type = type; /* tmp type */ | |
c906108c SS |
332 | struct objfile *objfile; |
333 | ||
334 | ntype = TYPE_CV_TYPE (type); | |
335 | ||
336 | while (ntype != type) | |
337 | { | |
338 | if ((TYPE_CONST (ntype) == cnst) && | |
c5aa993b JM |
339 | (TYPE_VOLATILE (ntype) == voltl)) |
340 | { | |
341 | if (typeptr == 0) | |
342 | return ntype; | |
343 | else if (*typeptr == 0) | |
344 | { | |
345 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ | |
346 | return ntype; | |
347 | } | |
348 | } | |
c906108c SS |
349 | tmp_type = ntype; |
350 | ntype = TYPE_CV_TYPE (ntype); | |
351 | } | |
352 | ||
353 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
354 | { | |
355 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
356 | if (typeptr) | |
357 | *typeptr = ntype; | |
358 | } | |
c5aa993b JM |
359 | else |
360 | /* We have storage, but need to reset it. */ | |
c906108c SS |
361 | { |
362 | ntype = *typeptr; | |
363 | objfile = TYPE_OBJFILE (ntype); | |
364 | /* memset ((char *) ntype, 0, sizeof (struct type)); */ | |
365 | TYPE_OBJFILE (ntype) = objfile; | |
366 | } | |
367 | ||
c5aa993b | 368 | /* Copy original type */ |
c906108c SS |
369 | memcpy ((char *) ntype, (char *) type, sizeof (struct type)); |
370 | /* But zero out fields that shouldn't be copied */ | |
c5aa993b JM |
371 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */ |
372 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */ | |
c906108c SS |
373 | /* Note: TYPE_TARGET_TYPE can be left as is */ |
374 | ||
375 | /* Set flags appropriately */ | |
376 | if (cnst) | |
c5aa993b | 377 | TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST; |
c906108c | 378 | else |
c5aa993b | 379 | TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST; |
c906108c SS |
380 | |
381 | if (voltl) | |
c5aa993b | 382 | TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE; |
c906108c | 383 | else |
c5aa993b | 384 | TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE; |
c906108c SS |
385 | |
386 | /* Fix the chain of cv variants */ | |
387 | TYPE_CV_TYPE (ntype) = type; | |
388 | TYPE_CV_TYPE (tmp_type) = ntype; | |
389 | ||
390 | return ntype; | |
391 | } | |
392 | ||
393 | ||
394 | ||
395 | ||
396 | /* Implement direct support for MEMBER_TYPE in GNU C++. | |
397 | May need to construct such a type if this is the first use. | |
398 | The TYPE is the type of the member. The DOMAIN is the type | |
399 | of the aggregate that the member belongs to. */ | |
400 | ||
401 | struct type * | |
402 | lookup_member_type (type, domain) | |
403 | struct type *type; | |
404 | struct type *domain; | |
405 | { | |
406 | register struct type *mtype; | |
407 | ||
408 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
409 | smash_to_member_type (mtype, domain, type); | |
410 | return (mtype); | |
411 | } | |
412 | ||
413 | /* Allocate a stub method whose return type is TYPE. | |
414 | This apparently happens for speed of symbol reading, since parsing | |
415 | out the arguments to the method is cpu-intensive, the way we are doing | |
416 | it. So, we will fill in arguments later. | |
417 | This always returns a fresh type. */ | |
418 | ||
419 | struct type * | |
420 | allocate_stub_method (type) | |
421 | struct type *type; | |
422 | { | |
423 | struct type *mtype; | |
424 | ||
425 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
426 | TYPE_TARGET_TYPE (mtype) = type; | |
427 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
428 | /* _ARG_TYPES (mtype) = unknown yet */ | |
429 | TYPE_FLAGS (mtype) = TYPE_FLAG_STUB; | |
430 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; | |
431 | TYPE_LENGTH (mtype) = 1; | |
432 | return (mtype); | |
433 | } | |
434 | ||
435 | /* Create a range type using either a blank type supplied in RESULT_TYPE, | |
436 | or creating a new type, inheriting the objfile from INDEX_TYPE. | |
437 | ||
438 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to | |
439 | HIGH_BOUND, inclusive. | |
440 | ||
441 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
442 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
443 | ||
444 | struct type * | |
445 | create_range_type (result_type, index_type, low_bound, high_bound) | |
446 | struct type *result_type; | |
447 | struct type *index_type; | |
448 | int low_bound; | |
449 | int high_bound; | |
450 | { | |
451 | if (result_type == NULL) | |
452 | { | |
453 | result_type = alloc_type (TYPE_OBJFILE (index_type)); | |
454 | } | |
455 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; | |
456 | TYPE_TARGET_TYPE (result_type) = index_type; | |
457 | if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB) | |
458 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
459 | else | |
460 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); | |
461 | TYPE_NFIELDS (result_type) = 2; | |
462 | TYPE_FIELDS (result_type) = (struct field *) | |
463 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); | |
464 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); | |
465 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; | |
466 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; | |
c5aa993b JM |
467 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ |
468 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ | |
c906108c | 469 | |
c5aa993b | 470 | if (low_bound >= 0) |
c906108c SS |
471 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
472 | ||
473 | return (result_type); | |
474 | } | |
475 | ||
476 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. | |
477 | Return 1 of type is a range type, 0 if it is discrete (and bounds | |
478 | will fit in LONGEST), or -1 otherwise. */ | |
479 | ||
480 | int | |
481 | get_discrete_bounds (type, lowp, highp) | |
482 | struct type *type; | |
483 | LONGEST *lowp, *highp; | |
484 | { | |
485 | CHECK_TYPEDEF (type); | |
486 | switch (TYPE_CODE (type)) | |
487 | { | |
488 | case TYPE_CODE_RANGE: | |
489 | *lowp = TYPE_LOW_BOUND (type); | |
490 | *highp = TYPE_HIGH_BOUND (type); | |
491 | return 1; | |
492 | case TYPE_CODE_ENUM: | |
493 | if (TYPE_NFIELDS (type) > 0) | |
494 | { | |
495 | /* The enums may not be sorted by value, so search all | |
496 | entries */ | |
497 | int i; | |
498 | ||
499 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); | |
500 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
501 | { | |
502 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) | |
503 | *lowp = TYPE_FIELD_BITPOS (type, i); | |
504 | if (TYPE_FIELD_BITPOS (type, i) > *highp) | |
505 | *highp = TYPE_FIELD_BITPOS (type, i); | |
506 | } | |
507 | ||
508 | /* Set unsigned indicator if warranted. */ | |
c5aa993b | 509 | if (*lowp >= 0) |
c906108c SS |
510 | { |
511 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; | |
512 | } | |
513 | } | |
514 | else | |
515 | { | |
516 | *lowp = 0; | |
517 | *highp = -1; | |
518 | } | |
519 | return 0; | |
520 | case TYPE_CODE_BOOL: | |
521 | *lowp = 0; | |
522 | *highp = 1; | |
523 | return 0; | |
524 | case TYPE_CODE_INT: | |
c5aa993b | 525 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
c906108c SS |
526 | return -1; |
527 | if (!TYPE_UNSIGNED (type)) | |
528 | { | |
c5aa993b | 529 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
c906108c SS |
530 | *highp = -*lowp - 1; |
531 | return 0; | |
532 | } | |
533 | /* ... fall through for unsigned ints ... */ | |
534 | case TYPE_CODE_CHAR: | |
535 | *lowp = 0; | |
536 | /* This round-about calculation is to avoid shifting by | |
c5aa993b JM |
537 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
538 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ | |
c906108c SS |
539 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
540 | *highp = (*highp - 1) | *highp; | |
541 | return 0; | |
542 | default: | |
543 | return -1; | |
544 | } | |
545 | } | |
546 | ||
547 | /* Create an array type using either a blank type supplied in RESULT_TYPE, | |
548 | or creating a new type, inheriting the objfile from RANGE_TYPE. | |
549 | ||
550 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
551 | RANGE_TYPE. | |
552 | ||
553 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
554 | sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ | |
555 | ||
556 | struct type * | |
557 | create_array_type (result_type, element_type, range_type) | |
558 | struct type *result_type; | |
559 | struct type *element_type; | |
560 | struct type *range_type; | |
561 | { | |
562 | LONGEST low_bound, high_bound; | |
563 | ||
564 | if (result_type == NULL) | |
565 | { | |
566 | result_type = alloc_type (TYPE_OBJFILE (range_type)); | |
567 | } | |
568 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; | |
569 | TYPE_TARGET_TYPE (result_type) = element_type; | |
570 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
571 | low_bound = high_bound = 0; | |
572 | CHECK_TYPEDEF (element_type); | |
573 | TYPE_LENGTH (result_type) = | |
574 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
575 | TYPE_NFIELDS (result_type) = 1; | |
576 | TYPE_FIELDS (result_type) = | |
577 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); | |
578 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
579 | TYPE_FIELD_TYPE (result_type, 0) = range_type; | |
580 | TYPE_VPTR_FIELDNO (result_type) = -1; | |
581 | ||
582 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ | |
583 | if (TYPE_LENGTH (result_type) == 0) | |
584 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
585 | ||
586 | return (result_type); | |
587 | } | |
588 | ||
589 | /* Create a string type using either a blank type supplied in RESULT_TYPE, | |
590 | or creating a new type. String types are similar enough to array of | |
591 | char types that we can use create_array_type to build the basic type | |
592 | and then bash it into a string type. | |
593 | ||
594 | For fixed length strings, the range type contains 0 as the lower | |
595 | bound and the length of the string minus one as the upper bound. | |
596 | ||
597 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
598 | sure it is TYPE_CODE_UNDEF before we bash it into a string type? */ | |
599 | ||
600 | struct type * | |
601 | create_string_type (result_type, range_type) | |
602 | struct type *result_type; | |
603 | struct type *range_type; | |
604 | { | |
605 | result_type = create_array_type (result_type, | |
606 | *current_language->string_char_type, | |
607 | range_type); | |
608 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
609 | return (result_type); | |
610 | } | |
611 | ||
612 | struct type * | |
613 | create_set_type (result_type, domain_type) | |
614 | struct type *result_type; | |
615 | struct type *domain_type; | |
616 | { | |
617 | LONGEST low_bound, high_bound, bit_length; | |
618 | if (result_type == NULL) | |
619 | { | |
620 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); | |
621 | } | |
622 | TYPE_CODE (result_type) = TYPE_CODE_SET; | |
623 | TYPE_NFIELDS (result_type) = 1; | |
624 | TYPE_FIELDS (result_type) = (struct field *) | |
625 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); | |
626 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
627 | ||
c5aa993b | 628 | if (!(TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB)) |
c906108c SS |
629 | { |
630 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) | |
631 | low_bound = high_bound = 0; | |
632 | bit_length = high_bound - low_bound + 1; | |
633 | TYPE_LENGTH (result_type) | |
634 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; | |
635 | } | |
636 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; | |
637 | ||
c5aa993b | 638 | if (low_bound >= 0) |
c906108c SS |
639 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
640 | ||
641 | return (result_type); | |
642 | } | |
643 | ||
917317f4 JM |
644 | |
645 | /* Construct and return a type of the form: | |
646 | struct NAME { ELT_TYPE ELT_NAME[N]; } | |
647 | We use these types for SIMD registers. For example, the type of | |
648 | the SSE registers on the late x86-family processors is: | |
649 | struct __builtin_v4sf { float f[4]; } | |
650 | built by the function call: | |
651 | init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4) | |
652 | The type returned is a permanent type, allocated using malloc; it | |
653 | doesn't live in any objfile's obstack. */ | |
c2d11a7d | 654 | static struct type * |
917317f4 JM |
655 | init_simd_type (char *name, |
656 | struct type *elt_type, | |
657 | char *elt_name, | |
658 | int n) | |
659 | { | |
660 | struct type *t; | |
661 | struct field *f; | |
662 | ||
663 | /* Build the field structure. */ | |
664 | f = xmalloc (sizeof (*f)); | |
665 | memset (f, 0, sizeof (*f)); | |
666 | f->loc.bitpos = 0; | |
667 | f->type = create_array_type (0, elt_type, | |
5c44784c JM |
668 | create_range_type (0, builtin_type_int, |
669 | 0, n-1)); | |
917317f4 JM |
670 | f->name = elt_name; |
671 | ||
672 | /* Build a struct type with that field. */ | |
673 | t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0); | |
674 | t->nfields = 1; | |
675 | t->fields = f; | |
676 | t->tag_name = name; | |
677 | ||
678 | return t; | |
679 | } | |
680 | ||
681 | ||
c906108c SS |
682 | /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. |
683 | A MEMBER is a wierd thing -- it amounts to a typed offset into | |
684 | a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't | |
685 | include the offset (that's the value of the MEMBER itself), but does | |
686 | include the structure type into which it points (for some reason). | |
687 | ||
688 | When "smashing" the type, we preserve the objfile that the | |
689 | old type pointed to, since we aren't changing where the type is actually | |
690 | allocated. */ | |
691 | ||
692 | void | |
693 | smash_to_member_type (type, domain, to_type) | |
694 | struct type *type; | |
695 | struct type *domain; | |
696 | struct type *to_type; | |
697 | { | |
698 | struct objfile *objfile; | |
699 | ||
700 | objfile = TYPE_OBJFILE (type); | |
701 | ||
702 | memset ((char *) type, 0, sizeof (struct type)); | |
703 | TYPE_OBJFILE (type) = objfile; | |
704 | TYPE_TARGET_TYPE (type) = to_type; | |
705 | TYPE_DOMAIN_TYPE (type) = domain; | |
706 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
707 | TYPE_CODE (type) = TYPE_CODE_MEMBER; | |
708 | } | |
709 | ||
710 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. | |
711 | METHOD just means `function that gets an extra "this" argument'. | |
712 | ||
713 | When "smashing" the type, we preserve the objfile that the | |
714 | old type pointed to, since we aren't changing where the type is actually | |
715 | allocated. */ | |
716 | ||
717 | void | |
718 | smash_to_method_type (type, domain, to_type, args) | |
719 | struct type *type; | |
720 | struct type *domain; | |
721 | struct type *to_type; | |
722 | struct type **args; | |
723 | { | |
724 | struct objfile *objfile; | |
725 | ||
726 | objfile = TYPE_OBJFILE (type); | |
727 | ||
728 | memset ((char *) type, 0, sizeof (struct type)); | |
729 | TYPE_OBJFILE (type) = objfile; | |
730 | TYPE_TARGET_TYPE (type) = to_type; | |
731 | TYPE_DOMAIN_TYPE (type) = domain; | |
732 | TYPE_ARG_TYPES (type) = args; | |
733 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
734 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
735 | } | |
736 | ||
737 | /* Return a typename for a struct/union/enum type without "struct ", | |
738 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
739 | ||
740 | char * | |
741 | type_name_no_tag (type) | |
742 | register const struct type *type; | |
743 | { | |
744 | if (TYPE_TAG_NAME (type) != NULL) | |
745 | return TYPE_TAG_NAME (type); | |
746 | ||
747 | /* Is there code which expects this to return the name if there is no | |
748 | tag name? My guess is that this is mainly used for C++ in cases where | |
749 | the two will always be the same. */ | |
750 | return TYPE_NAME (type); | |
751 | } | |
752 | ||
753 | /* Lookup a primitive type named NAME. | |
c5aa993b | 754 | Return zero if NAME is not a primitive type. */ |
c906108c SS |
755 | |
756 | struct type * | |
757 | lookup_primitive_typename (name) | |
758 | char *name; | |
759 | { | |
c5aa993b JM |
760 | struct type **const *p; |
761 | ||
762 | for (p = current_language->la_builtin_type_vector; *p != NULL; p++) | |
763 | { | |
764 | if (STREQ ((**p)->name, name)) | |
765 | { | |
766 | return (**p); | |
767 | } | |
768 | } | |
769 | return (NULL); | |
c906108c SS |
770 | } |
771 | ||
772 | /* Lookup a typedef or primitive type named NAME, | |
773 | visible in lexical block BLOCK. | |
774 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ | |
775 | ||
776 | struct type * | |
777 | lookup_typename (name, block, noerr) | |
778 | char *name; | |
779 | struct block *block; | |
780 | int noerr; | |
781 | { | |
782 | register struct symbol *sym; | |
783 | register struct type *tmp; | |
784 | ||
785 | sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); | |
786 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) | |
787 | { | |
788 | tmp = lookup_primitive_typename (name); | |
789 | if (tmp) | |
790 | { | |
791 | return (tmp); | |
792 | } | |
793 | else if (!tmp && noerr) | |
794 | { | |
795 | return (NULL); | |
796 | } | |
797 | else | |
798 | { | |
799 | error ("No type named %s.", name); | |
800 | } | |
801 | } | |
802 | return (SYMBOL_TYPE (sym)); | |
803 | } | |
804 | ||
805 | struct type * | |
806 | lookup_unsigned_typename (name) | |
807 | char *name; | |
808 | { | |
809 | char *uns = alloca (strlen (name) + 10); | |
810 | ||
811 | strcpy (uns, "unsigned "); | |
812 | strcpy (uns + 9, name); | |
813 | return (lookup_typename (uns, (struct block *) NULL, 0)); | |
814 | } | |
815 | ||
816 | struct type * | |
817 | lookup_signed_typename (name) | |
818 | char *name; | |
819 | { | |
820 | struct type *t; | |
821 | char *uns = alloca (strlen (name) + 8); | |
822 | ||
823 | strcpy (uns, "signed "); | |
824 | strcpy (uns + 7, name); | |
825 | t = lookup_typename (uns, (struct block *) NULL, 1); | |
826 | /* If we don't find "signed FOO" just try again with plain "FOO". */ | |
827 | if (t != NULL) | |
828 | return t; | |
829 | return lookup_typename (name, (struct block *) NULL, 0); | |
830 | } | |
831 | ||
832 | /* Lookup a structure type named "struct NAME", | |
833 | visible in lexical block BLOCK. */ | |
834 | ||
835 | struct type * | |
836 | lookup_struct (name, block) | |
837 | char *name; | |
838 | struct block *block; | |
839 | { | |
840 | register struct symbol *sym; | |
841 | ||
842 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
843 | (struct symtab **) NULL); | |
844 | ||
845 | if (sym == NULL) | |
846 | { | |
847 | error ("No struct type named %s.", name); | |
848 | } | |
849 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
850 | { | |
851 | error ("This context has class, union or enum %s, not a struct.", name); | |
852 | } | |
853 | return (SYMBOL_TYPE (sym)); | |
854 | } | |
855 | ||
856 | /* Lookup a union type named "union NAME", | |
857 | visible in lexical block BLOCK. */ | |
858 | ||
859 | struct type * | |
860 | lookup_union (name, block) | |
861 | char *name; | |
862 | struct block *block; | |
863 | { | |
864 | register struct symbol *sym; | |
c5aa993b | 865 | struct type *t; |
c906108c SS |
866 | |
867 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
868 | (struct symtab **) NULL); | |
869 | ||
870 | if (sym == NULL) | |
871 | error ("No union type named %s.", name); | |
872 | ||
c5aa993b | 873 | t = SYMBOL_TYPE (sym); |
c906108c SS |
874 | |
875 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
876 | return (t); | |
877 | ||
878 | /* C++ unions may come out with TYPE_CODE_CLASS, but we look at | |
879 | * a further "declared_type" field to discover it is really a union. | |
880 | */ | |
c5aa993b JM |
881 | if (HAVE_CPLUS_STRUCT (t)) |
882 | if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION) | |
c906108c SS |
883 | return (t); |
884 | ||
885 | /* If we get here, it's not a union */ | |
886 | error ("This context has class, struct or enum %s, not a union.", name); | |
887 | } | |
888 | ||
889 | ||
890 | /* Lookup an enum type named "enum NAME", | |
891 | visible in lexical block BLOCK. */ | |
892 | ||
893 | struct type * | |
894 | lookup_enum (name, block) | |
895 | char *name; | |
896 | struct block *block; | |
897 | { | |
898 | register struct symbol *sym; | |
899 | ||
c5aa993b | 900 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, |
c906108c SS |
901 | (struct symtab **) NULL); |
902 | if (sym == NULL) | |
903 | { | |
904 | error ("No enum type named %s.", name); | |
905 | } | |
906 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
907 | { | |
908 | error ("This context has class, struct or union %s, not an enum.", name); | |
909 | } | |
910 | return (SYMBOL_TYPE (sym)); | |
911 | } | |
912 | ||
913 | /* Lookup a template type named "template NAME<TYPE>", | |
914 | visible in lexical block BLOCK. */ | |
915 | ||
916 | struct type * | |
917 | lookup_template_type (name, type, block) | |
918 | char *name; | |
919 | struct type *type; | |
920 | struct block *block; | |
921 | { | |
922 | struct symbol *sym; | |
c5aa993b | 923 | char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4); |
c906108c SS |
924 | strcpy (nam, name); |
925 | strcat (nam, "<"); | |
926 | strcat (nam, type->name); | |
c5aa993b | 927 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
c906108c | 928 | |
c5aa993b | 929 | sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); |
c906108c SS |
930 | |
931 | if (sym == NULL) | |
932 | { | |
933 | error ("No template type named %s.", name); | |
934 | } | |
935 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
936 | { | |
937 | error ("This context has class, union or enum %s, not a struct.", name); | |
938 | } | |
939 | return (SYMBOL_TYPE (sym)); | |
940 | } | |
941 | ||
942 | /* Given a type TYPE, lookup the type of the component of type named NAME. | |
943 | ||
944 | TYPE can be either a struct or union, or a pointer or reference to a struct or | |
945 | union. If it is a pointer or reference, its target type is automatically used. | |
946 | Thus '.' and '->' are interchangable, as specified for the definitions of the | |
947 | expression element types STRUCTOP_STRUCT and STRUCTOP_PTR. | |
948 | ||
949 | If NOERR is nonzero, return zero if NAME is not suitably defined. | |
950 | If NAME is the name of a baseclass type, return that type. */ | |
951 | ||
952 | struct type * | |
953 | lookup_struct_elt_type (type, name, noerr) | |
954 | struct type *type; | |
955 | char *name; | |
c5aa993b | 956 | int noerr; |
c906108c SS |
957 | { |
958 | int i; | |
959 | ||
960 | for (;;) | |
961 | { | |
962 | CHECK_TYPEDEF (type); | |
963 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
964 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
965 | break; | |
966 | type = TYPE_TARGET_TYPE (type); | |
967 | } | |
968 | ||
969 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && | |
970 | TYPE_CODE (type) != TYPE_CODE_UNION) | |
971 | { | |
972 | target_terminal_ours (); | |
973 | gdb_flush (gdb_stdout); | |
974 | fprintf_unfiltered (gdb_stderr, "Type "); | |
975 | type_print (type, "", gdb_stderr, -1); | |
976 | error (" is not a structure or union type."); | |
977 | } | |
978 | ||
979 | #if 0 | |
980 | /* FIXME: This change put in by Michael seems incorrect for the case where | |
981 | the structure tag name is the same as the member name. I.E. when doing | |
982 | "ptype bell->bar" for "struct foo { int bar; int foo; } bell;" | |
983 | Disabled by fnf. */ | |
984 | { | |
985 | char *typename; | |
986 | ||
987 | typename = type_name_no_tag (type); | |
988 | if (typename != NULL && STREQ (typename, name)) | |
989 | return type; | |
990 | } | |
991 | #endif | |
992 | ||
993 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
994 | { | |
995 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
996 | ||
997 | if (t_field_name && STREQ (t_field_name, name)) | |
998 | { | |
999 | return TYPE_FIELD_TYPE (type, i); | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
1004 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1005 | { | |
1006 | struct type *t; | |
1007 | ||
1008 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr); | |
1009 | if (t != NULL) | |
1010 | { | |
1011 | return t; | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | if (noerr) | |
1016 | { | |
1017 | return NULL; | |
1018 | } | |
c5aa993b | 1019 | |
c906108c SS |
1020 | target_terminal_ours (); |
1021 | gdb_flush (gdb_stdout); | |
1022 | fprintf_unfiltered (gdb_stderr, "Type "); | |
1023 | type_print (type, "", gdb_stderr, -1); | |
1024 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
1025 | fputs_filtered (name, gdb_stderr); | |
1026 | error ("."); | |
c5aa993b | 1027 | return (struct type *) -1; /* For lint */ |
c906108c SS |
1028 | } |
1029 | ||
1030 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE | |
1031 | valid. Callers should be aware that in some cases (for example, | |
1032 | the type or one of its baseclasses is a stub type and we are | |
1033 | debugging a .o file), this function will not be able to find the virtual | |
1034 | function table pointer, and vptr_fieldno will remain -1 and vptr_basetype | |
1035 | will remain NULL. */ | |
1036 | ||
1037 | void | |
1038 | fill_in_vptr_fieldno (type) | |
1039 | struct type *type; | |
1040 | { | |
1041 | CHECK_TYPEDEF (type); | |
1042 | ||
1043 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
1044 | { | |
1045 | int i; | |
1046 | ||
1047 | /* We must start at zero in case the first (and only) baseclass is | |
c5aa993b | 1048 | virtual (and hence we cannot share the table pointer). */ |
c906108c SS |
1049 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
1050 | { | |
1051 | fill_in_vptr_fieldno (TYPE_BASECLASS (type, i)); | |
1052 | if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0) | |
1053 | { | |
1054 | TYPE_VPTR_FIELDNO (type) | |
1055 | = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)); | |
1056 | TYPE_VPTR_BASETYPE (type) | |
1057 | = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i)); | |
1058 | break; | |
1059 | } | |
1060 | } | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | /* Find the method and field indices for the destructor in class type T. | |
1065 | Return 1 if the destructor was found, otherwise, return 0. */ | |
1066 | ||
1067 | int | |
1068 | get_destructor_fn_field (t, method_indexp, field_indexp) | |
1069 | struct type *t; | |
1070 | int *method_indexp; | |
1071 | int *field_indexp; | |
1072 | { | |
1073 | int i; | |
1074 | ||
1075 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) | |
1076 | { | |
1077 | int j; | |
1078 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); | |
1079 | ||
1080 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) | |
1081 | { | |
1082 | if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j))) | |
1083 | { | |
1084 | *method_indexp = i; | |
1085 | *field_indexp = j; | |
1086 | return 1; | |
1087 | } | |
1088 | } | |
1089 | } | |
1090 | return 0; | |
1091 | } | |
1092 | ||
1093 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. | |
1094 | ||
1095 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
1096 | we can find a full definition in some other file. If so, copy this | |
1097 | definition, so we can use it in future. There used to be a comment (but | |
1098 | not any code) that if we don't find a full definition, we'd set a flag | |
1099 | so we don't spend time in the future checking the same type. That would | |
1100 | be a mistake, though--we might load in more symbols which contain a | |
1101 | full definition for the type. | |
1102 | ||
1103 | This used to be coded as a macro, but I don't think it is called | |
1104 | often enough to merit such treatment. */ | |
1105 | ||
1106 | struct complaint stub_noname_complaint = | |
c5aa993b | 1107 | {"stub type has NULL name", 0, 0}; |
c906108c SS |
1108 | |
1109 | struct type * | |
1110 | check_typedef (type) | |
1111 | register struct type *type; | |
1112 | { | |
1113 | struct type *orig_type = type; | |
1114 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) | |
1115 | { | |
1116 | if (!TYPE_TARGET_TYPE (type)) | |
1117 | { | |
c5aa993b | 1118 | char *name; |
c906108c SS |
1119 | struct symbol *sym; |
1120 | ||
1121 | /* It is dangerous to call lookup_symbol if we are currently | |
1122 | reading a symtab. Infinite recursion is one danger. */ | |
1123 | if (currently_reading_symtab) | |
1124 | return type; | |
1125 | ||
1126 | name = type_name_no_tag (type); | |
1127 | /* FIXME: shouldn't we separately check the TYPE_NAME and the | |
1128 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE | |
1129 | as appropriate? (this code was written before TYPE_NAME and | |
1130 | TYPE_TAG_NAME were separate). */ | |
1131 | if (name == NULL) | |
1132 | { | |
1133 | complain (&stub_noname_complaint); | |
1134 | return type; | |
1135 | } | |
c5aa993b | 1136 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, |
c906108c SS |
1137 | (struct symtab **) NULL); |
1138 | if (sym) | |
1139 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
1140 | else | |
c5aa993b | 1141 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ |
c906108c SS |
1142 | } |
1143 | type = TYPE_TARGET_TYPE (type); | |
1144 | } | |
1145 | ||
1146 | /* If this is a struct/class/union with no fields, then check whether a | |
1147 | full definition exists somewhere else. This is for systems where a | |
1148 | type definition with no fields is issued for such types, instead of | |
c5aa993b JM |
1149 | identifying them as stub types in the first place */ |
1150 | ||
c906108c SS |
1151 | if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab) |
1152 | { | |
c5aa993b JM |
1153 | char *name = type_name_no_tag (type); |
1154 | struct type *newtype; | |
c906108c SS |
1155 | if (name == NULL) |
1156 | { | |
1157 | complain (&stub_noname_complaint); | |
1158 | return type; | |
1159 | } | |
1160 | newtype = lookup_transparent_type (name); | |
1161 | if (newtype) | |
1162 | { | |
1163 | memcpy ((char *) type, (char *) newtype, sizeof (struct type)); | |
1164 | } | |
1165 | } | |
1166 | /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ | |
c5aa993b | 1167 | else if ((TYPE_FLAGS (type) & TYPE_FLAG_STUB) && !currently_reading_symtab) |
c906108c | 1168 | { |
c5aa993b | 1169 | char *name = type_name_no_tag (type); |
c906108c | 1170 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
c5aa993b JM |
1171 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE |
1172 | as appropriate? (this code was written before TYPE_NAME and | |
1173 | TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1174 | struct symbol *sym; |
1175 | if (name == NULL) | |
1176 | { | |
1177 | complain (&stub_noname_complaint); | |
1178 | return type; | |
1179 | } | |
1180 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL); | |
1181 | if (sym) | |
1182 | { | |
c5aa993b | 1183 | memcpy ((char *) type, (char *) SYMBOL_TYPE (sym), sizeof (struct type)); |
c906108c SS |
1184 | } |
1185 | } | |
1186 | ||
1187 | if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB) | |
1188 | { | |
1189 | struct type *range_type; | |
1190 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1191 | ||
1192 | if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB)) | |
c5aa993b JM |
1193 | { |
1194 | } | |
c906108c SS |
1195 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
1196 | && TYPE_NFIELDS (type) == 1 | |
1197 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) | |
1198 | == TYPE_CODE_RANGE)) | |
1199 | { | |
1200 | /* Now recompute the length of the array type, based on its | |
1201 | number of elements and the target type's length. */ | |
1202 | TYPE_LENGTH (type) = | |
1203 | ((TYPE_FIELD_BITPOS (range_type, 1) | |
1204 | - TYPE_FIELD_BITPOS (range_type, 0) | |
1205 | + 1) | |
1206 | * TYPE_LENGTH (target_type)); | |
1207 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1208 | } | |
1209 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
1210 | { | |
1211 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
1212 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1213 | } | |
1214 | } | |
1215 | /* Cache TYPE_LENGTH for future use. */ | |
1216 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); | |
1217 | return type; | |
1218 | } | |
1219 | ||
1220 | /* New code added to support parsing of Cfront stabs strings */ | |
1221 | #include <ctype.h> | |
1222 | #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; } | |
1223 | #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; } | |
1224 | ||
c5aa993b JM |
1225 | static void |
1226 | add_name (pextras, n) | |
1227 | struct extra *pextras; | |
1228 | char *n; | |
c906108c SS |
1229 | { |
1230 | int nlen; | |
1231 | ||
c5aa993b | 1232 | if ((nlen = (n ? strlen (n) : 0)) == 0) |
c906108c | 1233 | return; |
c5aa993b JM |
1234 | sprintf (pextras->str + pextras->len, "%d%s", nlen, n); |
1235 | pextras->len = strlen (pextras->str); | |
c906108c SS |
1236 | } |
1237 | ||
c5aa993b JM |
1238 | static void |
1239 | add_mangled_type (pextras, t) | |
1240 | struct extra *pextras; | |
1241 | struct type *t; | |
c906108c SS |
1242 | { |
1243 | enum type_code tcode; | |
1244 | int tlen, tflags; | |
c5aa993b | 1245 | char *tname; |
c906108c | 1246 | |
c5aa993b JM |
1247 | tcode = TYPE_CODE (t); |
1248 | tlen = TYPE_LENGTH (t); | |
1249 | tflags = TYPE_FLAGS (t); | |
1250 | tname = TYPE_NAME (t); | |
c906108c SS |
1251 | /* args of "..." seem to get mangled as "e" */ |
1252 | ||
c5aa993b JM |
1253 | switch (tcode) |
1254 | { | |
1255 | case TYPE_CODE_INT: | |
1256 | if (tflags == 1) | |
1257 | ADD_EXTRA ('U'); | |
1258 | switch (tlen) | |
1259 | { | |
1260 | case 1: | |
1261 | ADD_EXTRA ('c'); | |
1262 | break; | |
1263 | case 2: | |
1264 | ADD_EXTRA ('s'); | |
1265 | break; | |
1266 | case 4: | |
1267 | { | |
1268 | char *pname; | |
1269 | if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long")) | |
9846de1b JM |
1270 | { |
1271 | ADD_EXTRA ('l'); | |
1272 | } | |
1273 | else | |
1274 | { | |
1275 | ADD_EXTRA ('i'); | |
1276 | } | |
c5aa993b JM |
1277 | } |
1278 | break; | |
1279 | default: | |
1280 | { | |
1281 | ||
1282 | static struct complaint msg = | |
1283 | {"Bad int type code length x%x\n", 0, 0}; | |
1284 | ||
1285 | complain (&msg, tlen); | |
1286 | ||
1287 | } | |
1288 | } | |
1289 | break; | |
1290 | case TYPE_CODE_FLT: | |
1291 | switch (tlen) | |
1292 | { | |
1293 | case 4: | |
1294 | ADD_EXTRA ('f'); | |
1295 | break; | |
1296 | case 8: | |
1297 | ADD_EXTRA ('d'); | |
1298 | break; | |
1299 | case 16: | |
1300 | ADD_EXTRA ('r'); | |
1301 | break; | |
1302 | default: | |
1303 | { | |
1304 | static struct complaint msg = | |
1305 | {"Bad float type code length x%x\n", 0, 0}; | |
1306 | complain (&msg, tlen); | |
1307 | } | |
1308 | } | |
1309 | break; | |
1310 | case TYPE_CODE_REF: | |
1311 | ADD_EXTRA ('R'); | |
1312 | /* followed by what it's a ref to */ | |
1313 | break; | |
1314 | case TYPE_CODE_PTR: | |
1315 | ADD_EXTRA ('P'); | |
1316 | /* followed by what it's a ptr to */ | |
1317 | break; | |
1318 | case TYPE_CODE_TYPEDEF: | |
1319 | { | |
1320 | static struct complaint msg = | |
1321 | {"Typedefs in overloaded functions not yet supported\n", 0, 0}; | |
1322 | complain (&msg); | |
1323 | } | |
c906108c SS |
1324 | /* followed by type bytes & name */ |
1325 | break; | |
1326 | case TYPE_CODE_FUNC: | |
c5aa993b | 1327 | ADD_EXTRA ('F'); |
c906108c SS |
1328 | /* followed by func's arg '_' & ret types */ |
1329 | break; | |
1330 | case TYPE_CODE_VOID: | |
c5aa993b | 1331 | ADD_EXTRA ('v'); |
c906108c SS |
1332 | break; |
1333 | case TYPE_CODE_METHOD: | |
c5aa993b | 1334 | ADD_EXTRA ('M'); |
c906108c | 1335 | /* followed by name of class and func's arg '_' & ret types */ |
c5aa993b JM |
1336 | add_name (pextras, tname); |
1337 | ADD_EXTRA ('F'); /* then mangle function */ | |
c906108c | 1338 | break; |
c5aa993b JM |
1339 | case TYPE_CODE_STRUCT: /* C struct */ |
1340 | case TYPE_CODE_UNION: /* C union */ | |
1341 | case TYPE_CODE_ENUM: /* Enumeration type */ | |
c906108c | 1342 | /* followed by name of type */ |
c5aa993b | 1343 | add_name (pextras, tname); |
c906108c SS |
1344 | break; |
1345 | ||
c5aa993b JM |
1346 | /* errors possible types/not supported */ |
1347 | case TYPE_CODE_CHAR: | |
1348 | case TYPE_CODE_ARRAY: /* Array type */ | |
1349 | case TYPE_CODE_MEMBER: /* Member type */ | |
c906108c | 1350 | case TYPE_CODE_BOOL: |
c5aa993b | 1351 | case TYPE_CODE_COMPLEX: /* Complex float */ |
c906108c | 1352 | case TYPE_CODE_UNDEF: |
c5aa993b JM |
1353 | case TYPE_CODE_SET: /* Pascal sets */ |
1354 | case TYPE_CODE_RANGE: | |
c906108c SS |
1355 | case TYPE_CODE_STRING: |
1356 | case TYPE_CODE_BITSTRING: | |
1357 | case TYPE_CODE_ERROR: | |
c5aa993b | 1358 | default: |
c906108c | 1359 | { |
c5aa993b JM |
1360 | static struct complaint msg = |
1361 | {"Unknown type code x%x\n", 0, 0}; | |
1362 | complain (&msg, tcode); | |
c906108c SS |
1363 | } |
1364 | } | |
1365 | if (t->target_type) | |
c5aa993b | 1366 | add_mangled_type (pextras, t->target_type); |
c906108c SS |
1367 | } |
1368 | ||
1369 | #if 0 | |
1370 | void | |
c5aa993b | 1371 | cfront_mangle_name (type, i, j) |
c906108c SS |
1372 | struct type *type; |
1373 | int i; | |
1374 | int j; | |
1375 | { | |
c5aa993b JM |
1376 | struct fn_field *f; |
1377 | char *mangled_name = gdb_mangle_name (type, i, j); | |
1378 | ||
1379 | f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */ | |
1380 | ||
1381 | /* kludge to support cfront methods - gdb expects to find "F" for | |
1382 | ARM_mangled names, so when we mangle, we have to add it here */ | |
1383 | if (ARM_DEMANGLING) | |
1384 | { | |
1385 | int k; | |
1386 | char *arm_mangled_name; | |
1387 | struct fn_field *method = &f[j]; | |
1388 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
1389 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); | |
1390 | char *newname = type_name_no_tag (type); | |
1391 | ||
1392 | struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); | |
1393 | int nargs = TYPE_NFIELDS (ftype); /* number of args */ | |
1394 | struct extra extras, *pextras = &extras; | |
1395 | INIT_EXTRA | |
c906108c SS |
1396 | |
1397 | if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */ | |
c5aa993b JM |
1398 | ADD_EXTRA ('S') |
1399 | ADD_EXTRA ('F') | |
c906108c | 1400 | /* add args here! */ |
c5aa993b JM |
1401 | if (nargs <= 1) /* no args besides this */ |
1402 | ADD_EXTRA ('v') | |
1403 | else | |
1404 | { | |
1405 | for (k = 1; k < nargs; k++) | |
1406 | { | |
1407 | struct type *t; | |
1408 | t = TYPE_FIELD_TYPE (ftype, k); | |
1409 | add_mangled_type (pextras, t); | |
1410 | } | |
1411 | } | |
1412 | ADD_EXTRA ('\0') | |
1413 | printf ("add_mangled_type: %s\n", extras.str); /* FIXME */ | |
1414 | arm_mangled_name = malloc (strlen (mangled_name) + extras.len); | |
1415 | sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str); | |
1416 | free (mangled_name); | |
1417 | mangled_name = arm_mangled_name; | |
1418 | } | |
c906108c | 1419 | } |
c5aa993b | 1420 | #endif /* 0 */ |
c906108c SS |
1421 | |
1422 | #undef ADD_EXTRA | |
1423 | /* End of new code added to support parsing of Cfront stabs strings */ | |
1424 | ||
1425 | /* Ugly hack to convert method stubs into method types. | |
1426 | ||
1427 | He ain't kiddin'. This demangles the name of the method into a string | |
1428 | including argument types, parses out each argument type, generates | |
1429 | a string casting a zero to that type, evaluates the string, and stuffs | |
1430 | the resulting type into an argtype vector!!! Then it knows the type | |
1431 | of the whole function (including argument types for overloading), | |
1432 | which info used to be in the stab's but was removed to hack back | |
1433 | the space required for them. */ | |
1434 | ||
1435 | void | |
1436 | check_stub_method (type, method_id, signature_id) | |
1437 | struct type *type; | |
1438 | int method_id; | |
1439 | int signature_id; | |
1440 | { | |
1441 | struct fn_field *f; | |
1442 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
1443 | char *demangled_name = cplus_demangle (mangled_name, | |
1444 | DMGL_PARAMS | DMGL_ANSI); | |
1445 | char *argtypetext, *p; | |
1446 | int depth = 0, argcount = 1; | |
1447 | struct type **argtypes; | |
1448 | struct type *mtype; | |
1449 | ||
1450 | /* Make sure we got back a function string that we can use. */ | |
1451 | if (demangled_name) | |
1452 | p = strchr (demangled_name, '('); | |
1453 | ||
1454 | if (demangled_name == NULL || p == NULL) | |
1455 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); | |
1456 | ||
1457 | /* Now, read in the parameters that define this type. */ | |
1458 | p += 1; | |
1459 | argtypetext = p; | |
1460 | while (*p) | |
1461 | { | |
1462 | if (*p == '(') | |
1463 | { | |
1464 | depth += 1; | |
1465 | } | |
1466 | else if (*p == ')') | |
1467 | { | |
1468 | depth -= 1; | |
1469 | } | |
1470 | else if (*p == ',' && depth == 0) | |
1471 | { | |
1472 | argcount += 1; | |
1473 | } | |
1474 | ||
1475 | p += 1; | |
1476 | } | |
1477 | ||
1478 | /* We need two more slots: one for the THIS pointer, and one for the | |
1479 | NULL [...] or void [end of arglist]. */ | |
1480 | ||
1481 | argtypes = (struct type **) | |
1482 | TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *)); | |
1483 | p = argtypetext; | |
1484 | /* FIXME: This is wrong for static member functions. */ | |
1485 | argtypes[0] = lookup_pointer_type (type); | |
1486 | argcount = 1; | |
1487 | ||
c5aa993b | 1488 | if (*p != ')') /* () means no args, skip while */ |
c906108c SS |
1489 | { |
1490 | depth = 0; | |
1491 | while (*p) | |
1492 | { | |
1493 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1494 | { | |
1495 | /* Avoid parsing of ellipsis, they will be handled below. */ | |
1496 | if (strncmp (argtypetext, "...", p - argtypetext) != 0) | |
1497 | { | |
1498 | argtypes[argcount] = | |
c5aa993b | 1499 | parse_and_eval_type (argtypetext, p - argtypetext); |
c906108c SS |
1500 | argcount += 1; |
1501 | } | |
1502 | argtypetext = p + 1; | |
1503 | } | |
1504 | ||
1505 | if (*p == '(') | |
1506 | { | |
1507 | depth += 1; | |
1508 | } | |
1509 | else if (*p == ')') | |
1510 | { | |
1511 | depth -= 1; | |
1512 | } | |
1513 | ||
1514 | p += 1; | |
1515 | } | |
1516 | } | |
1517 | ||
c5aa993b | 1518 | if (p[-2] != '.') /* Not '...' */ |
c906108c SS |
1519 | { |
1520 | argtypes[argcount] = builtin_type_void; /* List terminator */ | |
1521 | } | |
1522 | else | |
1523 | { | |
c5aa993b | 1524 | argtypes[argcount] = NULL; /* Ellist terminator */ |
c906108c SS |
1525 | } |
1526 | ||
1527 | free (demangled_name); | |
1528 | ||
c5aa993b | 1529 | f = TYPE_FN_FIELDLIST1 (type, method_id); |
c906108c SS |
1530 | |
1531 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; | |
1532 | ||
1533 | /* Now update the old "stub" type into a real type. */ | |
1534 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
1535 | TYPE_DOMAIN_TYPE (mtype) = type; | |
1536 | TYPE_ARG_TYPES (mtype) = argtypes; | |
1537 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; | |
1538 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; | |
1539 | } | |
1540 | ||
1541 | const struct cplus_struct_type cplus_struct_default; | |
1542 | ||
1543 | void | |
1544 | allocate_cplus_struct_type (type) | |
1545 | struct type *type; | |
1546 | { | |
1547 | if (!HAVE_CPLUS_STRUCT (type)) | |
1548 | { | |
1549 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
1550 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
c5aa993b | 1551 | *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default; |
c906108c SS |
1552 | } |
1553 | } | |
1554 | ||
1555 | /* Helper function to initialize the standard scalar types. | |
1556 | ||
1557 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy | |
1558 | of the string pointed to by name in the type_obstack for that objfile, | |
1559 | and initialize the type name to that copy. There are places (mipsread.c | |
1560 | in particular, where init_type is called with a NULL value for NAME). */ | |
1561 | ||
1562 | struct type * | |
1563 | init_type (code, length, flags, name, objfile) | |
1564 | enum type_code code; | |
1565 | int length; | |
1566 | int flags; | |
1567 | char *name; | |
1568 | struct objfile *objfile; | |
1569 | { | |
1570 | register struct type *type; | |
1571 | ||
1572 | type = alloc_type (objfile); | |
1573 | TYPE_CODE (type) = code; | |
1574 | TYPE_LENGTH (type) = length; | |
1575 | TYPE_FLAGS (type) |= flags; | |
1576 | if ((name != NULL) && (objfile != NULL)) | |
1577 | { | |
1578 | TYPE_NAME (type) = | |
c5aa993b | 1579 | obsavestring (name, strlen (name), &objfile->type_obstack); |
c906108c SS |
1580 | } |
1581 | else | |
1582 | { | |
1583 | TYPE_NAME (type) = name; | |
1584 | } | |
1585 | ||
1586 | /* C++ fancies. */ | |
1587 | ||
1588 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
1589 | { | |
1590 | INIT_CPLUS_SPECIFIC (type); | |
1591 | } | |
1592 | return (type); | |
1593 | } | |
1594 | ||
1595 | /* Look up a fundamental type for the specified objfile. | |
1596 | May need to construct such a type if this is the first use. | |
1597 | ||
1598 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
1599 | types such as "int" or "double". Others (stabs for example), do | |
1600 | define fundamental types. | |
1601 | ||
1602 | For the formats which don't provide fundamental types, gdb can create | |
1603 | such types, using defaults reasonable for the current language and | |
1604 | the current target machine. | |
1605 | ||
1606 | NOTE: This routine is obsolescent. Each debugging format reader | |
1607 | should manage it's own fundamental types, either creating them from | |
1608 | suitable defaults or reading them from the debugging information, | |
1609 | whichever is appropriate. The DWARF reader has already been | |
1610 | fixed to do this. Once the other readers are fixed, this routine | |
1611 | will go away. Also note that fundamental types should be managed | |
1612 | on a compilation unit basis in a multi-language environment, not | |
1613 | on a linkage unit basis as is done here. */ | |
1614 | ||
1615 | ||
1616 | struct type * | |
1617 | lookup_fundamental_type (objfile, typeid) | |
1618 | struct objfile *objfile; | |
1619 | int typeid; | |
1620 | { | |
1621 | register struct type **typep; | |
1622 | register int nbytes; | |
1623 | ||
1624 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
1625 | { | |
1626 | error ("internal error - invalid fundamental type id %d", typeid); | |
1627 | } | |
1628 | ||
1629 | /* If this is the first time we need a fundamental type for this objfile | |
1630 | then we need to initialize the vector of type pointers. */ | |
c5aa993b JM |
1631 | |
1632 | if (objfile->fundamental_types == NULL) | |
c906108c SS |
1633 | { |
1634 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); | |
c5aa993b JM |
1635 | objfile->fundamental_types = (struct type **) |
1636 | obstack_alloc (&objfile->type_obstack, nbytes); | |
1637 | memset ((char *) objfile->fundamental_types, 0, nbytes); | |
c906108c SS |
1638 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
1639 | } | |
1640 | ||
1641 | /* Look for this particular type in the fundamental type vector. If one is | |
1642 | not found, create and install one appropriate for the current language. */ | |
1643 | ||
c5aa993b | 1644 | typep = objfile->fundamental_types + typeid; |
c906108c SS |
1645 | if (*typep == NULL) |
1646 | { | |
1647 | *typep = create_fundamental_type (objfile, typeid); | |
1648 | } | |
1649 | ||
1650 | return (*typep); | |
1651 | } | |
1652 | ||
1653 | int | |
1654 | can_dereference (t) | |
1655 | struct type *t; | |
1656 | { | |
1657 | /* FIXME: Should we return true for references as well as pointers? */ | |
1658 | CHECK_TYPEDEF (t); | |
1659 | return | |
1660 | (t != NULL | |
1661 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
1662 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
1663 | } | |
1664 | ||
adf40b2e JM |
1665 | int |
1666 | is_integral_type (t) | |
1667 | struct type *t; | |
1668 | { | |
1669 | CHECK_TYPEDEF (t); | |
1670 | return | |
1671 | ((t != NULL) | |
d4f3574e SS |
1672 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
1673 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
1674 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) | |
1675 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
1676 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
1677 | } |
1678 | ||
c906108c SS |
1679 | /* Chill varying string and arrays are represented as follows: |
1680 | ||
1681 | struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data}; | |
1682 | ||
1683 | Return true if TYPE is such a Chill varying type. */ | |
1684 | ||
1685 | int | |
1686 | chill_varying_type (type) | |
1687 | struct type *type; | |
1688 | { | |
1689 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT | |
1690 | || TYPE_NFIELDS (type) != 2 | |
1691 | || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0) | |
1692 | return 0; | |
1693 | return 1; | |
1694 | } | |
1695 | ||
1696 | /* Check whether BASE is an ancestor or base class or DCLASS | |
1697 | Return 1 if so, and 0 if not. | |
1698 | Note: callers may want to check for identity of the types before | |
1699 | calling this function -- identical types are considered to satisfy | |
1700 | the ancestor relationship even if they're identical */ | |
1701 | ||
1702 | int | |
1703 | is_ancestor (base, dclass) | |
c5aa993b JM |
1704 | struct type *base; |
1705 | struct type *dclass; | |
c906108c SS |
1706 | { |
1707 | int i; | |
c5aa993b | 1708 | |
c906108c SS |
1709 | CHECK_TYPEDEF (base); |
1710 | CHECK_TYPEDEF (dclass); | |
1711 | ||
1712 | if (base == dclass) | |
1713 | return 1; | |
1714 | ||
1715 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1716 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) | |
1717 | return 1; | |
1718 | ||
1719 | return 0; | |
1720 | } | |
1721 | ||
1722 | ||
1723 | ||
1724 | /* See whether DCLASS has a virtual table. This routine is aimed at | |
1725 | the HP/Taligent ANSI C++ runtime model, and may not work with other | |
1726 | runtime models. Return 1 => Yes, 0 => No. */ | |
1727 | ||
1728 | int | |
1729 | has_vtable (dclass) | |
c5aa993b | 1730 | struct type *dclass; |
c906108c SS |
1731 | { |
1732 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it | |
1733 | has virtual functions or virtual bases. */ | |
1734 | ||
1735 | register int i; | |
1736 | ||
c5aa993b | 1737 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c | 1738 | return 0; |
c5aa993b | 1739 | |
c906108c | 1740 | /* First check for the presence of virtual bases */ |
c5aa993b JM |
1741 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
1742 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1743 | if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) | |
1744 | return 1; | |
1745 | ||
c906108c | 1746 | /* Next check for virtual functions */ |
c5aa993b JM |
1747 | if (TYPE_FN_FIELDLISTS (dclass)) |
1748 | for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++) | |
1749 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0)) | |
c906108c | 1750 | return 1; |
c5aa993b JM |
1751 | |
1752 | /* Recurse on non-virtual bases to see if any of them needs a vtable */ | |
1753 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) | |
1754 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1755 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) && | |
1756 | (has_vtable (TYPE_FIELD_TYPE (dclass, i)))) | |
1757 | return 1; | |
1758 | ||
1759 | /* Well, maybe we don't need a virtual table */ | |
c906108c SS |
1760 | return 0; |
1761 | } | |
1762 | ||
1763 | /* Return a pointer to the "primary base class" of DCLASS. | |
c5aa993b | 1764 | |
c906108c SS |
1765 | A NULL return indicates that DCLASS has no primary base, or that it |
1766 | couldn't be found (insufficient information). | |
c5aa993b | 1767 | |
c906108c SS |
1768 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
1769 | and may not work with other runtime models. */ | |
1770 | ||
1771 | struct type * | |
1772 | primary_base_class (dclass) | |
c5aa993b | 1773 | struct type *dclass; |
c906108c SS |
1774 | { |
1775 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class | |
1776 | is the first directly inherited, non-virtual base class that | |
1777 | requires a virtual table */ | |
1778 | ||
1779 | register int i; | |
1780 | ||
c5aa993b | 1781 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c SS |
1782 | return NULL; |
1783 | ||
c5aa993b JM |
1784 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
1785 | if (!TYPE_FIELD_VIRTUAL (dclass, i) && | |
1786 | has_vtable (TYPE_FIELD_TYPE (dclass, i))) | |
1787 | return TYPE_FIELD_TYPE (dclass, i); | |
c906108c SS |
1788 | |
1789 | return NULL; | |
1790 | } | |
1791 | ||
1792 | /* Global manipulated by virtual_base_list[_aux]() */ | |
1793 | ||
c5aa993b | 1794 | static struct vbase *current_vbase_list = NULL; |
c906108c SS |
1795 | |
1796 | /* Return a pointer to a null-terminated list of struct vbase | |
1797 | items. The vbasetype pointer of each item in the list points to the | |
1798 | type information for a virtual base of the argument DCLASS. | |
c5aa993b | 1799 | |
c906108c SS |
1800 | Helper function for virtual_base_list(). |
1801 | Note: the list goes backward, right-to-left. virtual_base_list() | |
1802 | copies the items out in reverse order. */ | |
1803 | ||
7a292a7a | 1804 | static void |
c906108c | 1805 | virtual_base_list_aux (dclass) |
c5aa993b | 1806 | struct type *dclass; |
c906108c | 1807 | { |
c5aa993b | 1808 | struct vbase *tmp_vbase; |
c906108c SS |
1809 | register int i; |
1810 | ||
c5aa993b | 1811 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
7a292a7a | 1812 | return; |
c906108c SS |
1813 | |
1814 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1815 | { | |
1816 | /* Recurse on this ancestor, first */ | |
c5aa993b | 1817 | virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i)); |
c906108c SS |
1818 | |
1819 | /* If this current base is itself virtual, add it to the list */ | |
c5aa993b JM |
1820 | if (BASETYPE_VIA_VIRTUAL (dclass, i)) |
1821 | { | |
1822 | struct type *basetype = TYPE_FIELD_TYPE (dclass, i); | |
1823 | ||
1824 | /* Check if base already recorded */ | |
1825 | tmp_vbase = current_vbase_list; | |
1826 | while (tmp_vbase) | |
1827 | { | |
1828 | if (tmp_vbase->vbasetype == basetype) | |
1829 | break; /* found it */ | |
1830 | tmp_vbase = tmp_vbase->next; | |
1831 | } | |
1832 | ||
1833 | if (!tmp_vbase) /* normal exit from loop */ | |
1834 | { | |
1835 | /* Allocate new item for this virtual base */ | |
1836 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); | |
1837 | ||
1838 | /* Stick it on at the end of the list */ | |
1839 | tmp_vbase->vbasetype = basetype; | |
1840 | tmp_vbase->next = current_vbase_list; | |
1841 | current_vbase_list = tmp_vbase; | |
1842 | } | |
1843 | } /* if virtual */ | |
1844 | } /* for loop over bases */ | |
c906108c SS |
1845 | } |
1846 | ||
1847 | ||
1848 | /* Compute the list of virtual bases in the right order. Virtual | |
1849 | bases are laid out in the object's memory area in order of their | |
1850 | occurrence in a depth-first, left-to-right search through the | |
1851 | ancestors. | |
c5aa993b | 1852 | |
c906108c SS |
1853 | Argument DCLASS is the type whose virtual bases are required. |
1854 | Return value is the address of a null-terminated array of pointers | |
1855 | to struct type items. | |
c5aa993b | 1856 | |
c906108c SS |
1857 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
1858 | and may not work with other runtime models. | |
c5aa993b | 1859 | |
c906108c SS |
1860 | This routine merely hands off the argument to virtual_base_list_aux() |
1861 | and then copies the result into an array to save space. */ | |
1862 | ||
1863 | struct type ** | |
1864 | virtual_base_list (dclass) | |
c5aa993b | 1865 | struct type *dclass; |
c906108c | 1866 | { |
c5aa993b JM |
1867 | register struct vbase *tmp_vbase; |
1868 | register struct vbase *tmp_vbase_2; | |
c906108c SS |
1869 | register int i; |
1870 | int count; | |
c5aa993b | 1871 | struct type **vbase_array; |
c906108c SS |
1872 | |
1873 | current_vbase_list = NULL; | |
c5aa993b | 1874 | virtual_base_list_aux (dclass); |
c906108c | 1875 | |
c5aa993b | 1876 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
1877 | /* no body */ ; |
1878 | ||
1879 | count = i; | |
1880 | ||
c5aa993b | 1881 | vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *)); |
c906108c | 1882 | |
c5aa993b | 1883 | for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next) |
c906108c SS |
1884 | vbase_array[i] = tmp_vbase->vbasetype; |
1885 | ||
1886 | /* Get rid of constructed chain */ | |
1887 | tmp_vbase_2 = tmp_vbase = current_vbase_list; | |
1888 | while (tmp_vbase) | |
1889 | { | |
1890 | tmp_vbase = tmp_vbase->next; | |
c5aa993b | 1891 | free (tmp_vbase_2); |
c906108c SS |
1892 | tmp_vbase_2 = tmp_vbase; |
1893 | } | |
c5aa993b | 1894 | |
c906108c SS |
1895 | vbase_array[count] = NULL; |
1896 | return vbase_array; | |
1897 | } | |
1898 | ||
1899 | /* Return the length of the virtual base list of the type DCLASS. */ | |
1900 | ||
1901 | int | |
1902 | virtual_base_list_length (dclass) | |
c5aa993b | 1903 | struct type *dclass; |
c906108c SS |
1904 | { |
1905 | register int i; | |
c5aa993b JM |
1906 | register struct vbase *tmp_vbase; |
1907 | ||
c906108c | 1908 | current_vbase_list = NULL; |
c5aa993b | 1909 | virtual_base_list_aux (dclass); |
c906108c | 1910 | |
c5aa993b | 1911 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
1912 | /* no body */ ; |
1913 | return i; | |
1914 | } | |
1915 | ||
1916 | /* Return the number of elements of the virtual base list of the type | |
1917 | DCLASS, ignoring those appearing in the primary base (and its | |
1918 | primary base, recursively). */ | |
1919 | ||
1920 | int | |
1921 | virtual_base_list_length_skip_primaries (dclass) | |
c5aa993b | 1922 | struct type *dclass; |
c906108c SS |
1923 | { |
1924 | register int i; | |
c5aa993b JM |
1925 | register struct vbase *tmp_vbase; |
1926 | struct type *primary; | |
c906108c SS |
1927 | |
1928 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; | |
1929 | ||
1930 | if (!primary) | |
1931 | return virtual_base_list_length (dclass); | |
1932 | ||
1933 | current_vbase_list = NULL; | |
c5aa993b | 1934 | virtual_base_list_aux (dclass); |
c906108c | 1935 | |
c5aa993b | 1936 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next) |
c906108c SS |
1937 | { |
1938 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) | |
c5aa993b | 1939 | continue; |
c906108c SS |
1940 | i++; |
1941 | } | |
1942 | return i; | |
1943 | } | |
1944 | ||
1945 | ||
1946 | /* Return the index (position) of type BASE, which is a virtual base | |
1947 | class of DCLASS, in the latter's virtual base list. A return of -1 | |
1948 | indicates "not found" or a problem. */ | |
1949 | ||
1950 | int | |
c5aa993b JM |
1951 | virtual_base_index (base, dclass) |
1952 | struct type *base; | |
1953 | struct type *dclass; | |
c906108c | 1954 | { |
c5aa993b | 1955 | register struct type *vbase; |
c906108c SS |
1956 | register int i; |
1957 | ||
c5aa993b JM |
1958 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
1959 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
1960 | return -1; |
1961 | ||
1962 | i = 0; | |
c5aa993b | 1963 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0]; |
c906108c SS |
1964 | while (vbase) |
1965 | { | |
1966 | if (vbase == base) | |
c5aa993b JM |
1967 | break; |
1968 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i]; | |
c906108c SS |
1969 | } |
1970 | ||
1971 | return vbase ? i : -1; | |
1972 | } | |
1973 | ||
1974 | ||
1975 | ||
1976 | /* Return the index (position) of type BASE, which is a virtual base | |
1977 | class of DCLASS, in the latter's virtual base list. Skip over all | |
1978 | bases that may appear in the virtual base list of the primary base | |
1979 | class of DCLASS (recursively). A return of -1 indicates "not | |
1980 | found" or a problem. */ | |
1981 | ||
1982 | int | |
c5aa993b JM |
1983 | virtual_base_index_skip_primaries (base, dclass) |
1984 | struct type *base; | |
1985 | struct type *dclass; | |
c906108c | 1986 | { |
c5aa993b | 1987 | register struct type *vbase; |
c906108c | 1988 | register int i, j; |
c5aa993b | 1989 | struct type *primary; |
c906108c | 1990 | |
c5aa993b JM |
1991 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
1992 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
1993 | return -1; |
1994 | ||
c5aa993b | 1995 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
c906108c SS |
1996 | |
1997 | j = -1; | |
1998 | i = 0; | |
c5aa993b | 1999 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0]; |
c906108c SS |
2000 | while (vbase) |
2001 | { | |
c5aa993b JM |
2002 | if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0)) |
2003 | j++; | |
c906108c | 2004 | if (vbase == base) |
c5aa993b JM |
2005 | break; |
2006 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i]; | |
c906108c SS |
2007 | } |
2008 | ||
2009 | return vbase ? j : -1; | |
2010 | } | |
2011 | ||
2012 | /* Return position of a derived class DCLASS in the list of | |
2013 | * primary bases starting with the remotest ancestor. | |
2014 | * Position returned is 0-based. */ | |
2015 | ||
2016 | int | |
2017 | class_index_in_primary_list (dclass) | |
c5aa993b | 2018 | struct type *dclass; |
c906108c | 2019 | { |
c5aa993b | 2020 | struct type *pbc; /* primary base class */ |
c906108c | 2021 | |
c5aa993b | 2022 | /* Simply recurse on primary base */ |
c906108c SS |
2023 | pbc = TYPE_PRIMARY_BASE (dclass); |
2024 | if (pbc) | |
2025 | return 1 + class_index_in_primary_list (pbc); | |
2026 | else | |
2027 | return 0; | |
2028 | } | |
2029 | ||
2030 | /* Return a count of the number of virtual functions a type has. | |
2031 | * This includes all the virtual functions it inherits from its | |
2032 | * base classes too. | |
2033 | */ | |
2034 | ||
2035 | /* pai: FIXME This doesn't do the right thing: count redefined virtual | |
2036 | * functions only once (latest redefinition) | |
2037 | */ | |
2038 | ||
2039 | int | |
2040 | count_virtual_fns (dclass) | |
c5aa993b | 2041 | struct type *dclass; |
c906108c | 2042 | { |
c5aa993b | 2043 | int fn, oi; /* function and overloaded instance indices */ |
c5aa993b JM |
2044 | int vfuncs; /* count to return */ |
2045 | ||
2046 | /* recurse on bases that can share virtual table */ | |
2047 | struct type *pbc = primary_base_class (dclass); | |
c906108c SS |
2048 | if (pbc) |
2049 | vfuncs = count_virtual_fns (pbc); | |
c5aa993b | 2050 | |
c906108c SS |
2051 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
2052 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) | |
2053 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) | |
c5aa993b | 2054 | vfuncs++; |
c906108c SS |
2055 | |
2056 | return vfuncs; | |
2057 | } | |
c906108c SS |
2058 | \f |
2059 | ||
c5aa993b | 2060 | |
c906108c SS |
2061 | /* Functions for overload resolution begin here */ |
2062 | ||
2063 | /* Compare two badness vectors A and B and return the result. | |
2064 | * 0 => A and B are identical | |
2065 | * 1 => A and B are incomparable | |
2066 | * 2 => A is better than B | |
2067 | * 3 => A is worse than B */ | |
2068 | ||
2069 | int | |
2070 | compare_badness (a, b) | |
c5aa993b JM |
2071 | struct badness_vector *a; |
2072 | struct badness_vector *b; | |
c906108c SS |
2073 | { |
2074 | int i; | |
2075 | int tmp; | |
c5aa993b JM |
2076 | short found_pos = 0; /* any positives in c? */ |
2077 | short found_neg = 0; /* any negatives in c? */ | |
2078 | ||
2079 | /* differing lengths => incomparable */ | |
c906108c SS |
2080 | if (a->length != b->length) |
2081 | return 1; | |
2082 | ||
c5aa993b JM |
2083 | /* Subtract b from a */ |
2084 | for (i = 0; i < a->length; i++) | |
c906108c SS |
2085 | { |
2086 | tmp = a->rank[i] - b->rank[i]; | |
2087 | if (tmp > 0) | |
c5aa993b | 2088 | found_pos = 1; |
c906108c | 2089 | else if (tmp < 0) |
c5aa993b | 2090 | found_neg = 1; |
c906108c SS |
2091 | } |
2092 | ||
2093 | if (found_pos) | |
2094 | { | |
2095 | if (found_neg) | |
c5aa993b | 2096 | return 1; /* incomparable */ |
c906108c | 2097 | else |
c5aa993b | 2098 | return 3; /* A > B */ |
c906108c | 2099 | } |
c5aa993b JM |
2100 | else |
2101 | /* no positives */ | |
c906108c SS |
2102 | { |
2103 | if (found_neg) | |
c5aa993b | 2104 | return 2; /* A < B */ |
c906108c | 2105 | else |
c5aa993b | 2106 | return 0; /* A == B */ |
c906108c SS |
2107 | } |
2108 | } | |
2109 | ||
2110 | /* Rank a function by comparing its parameter types (PARMS, length NPARMS), | |
2111 | * to the types of an argument list (ARGS, length NARGS). | |
2112 | * Return a pointer to a badness vector. This has NARGS + 1 entries. */ | |
2113 | ||
2114 | struct badness_vector * | |
2115 | rank_function (parms, nparms, args, nargs) | |
c5aa993b JM |
2116 | struct type **parms; |
2117 | int nparms; | |
2118 | struct type **args; | |
2119 | int nargs; | |
c906108c SS |
2120 | { |
2121 | int i; | |
c5aa993b | 2122 | struct badness_vector *bv; |
c906108c SS |
2123 | int min_len = nparms < nargs ? nparms : nargs; |
2124 | ||
2125 | bv = xmalloc (sizeof (struct badness_vector)); | |
c5aa993b | 2126 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
c906108c SS |
2127 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
2128 | ||
2129 | /* First compare the lengths of the supplied lists. | |
2130 | * If there is a mismatch, set it to a high value. */ | |
c5aa993b | 2131 | |
c906108c SS |
2132 | /* pai/1997-06-03 FIXME: when we have debug info about default |
2133 | * arguments and ellipsis parameter lists, we should consider those | |
2134 | * and rank the length-match more finely. */ | |
2135 | ||
2136 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; | |
2137 | ||
2138 | /* Now rank all the parameters of the candidate function */ | |
c5aa993b JM |
2139 | for (i = 1; i <= min_len; i++) |
2140 | bv->rank[i] = rank_one_type (parms[i - 1], args[i - 1]); | |
c906108c | 2141 | |
c5aa993b JM |
2142 | /* If more arguments than parameters, add dummy entries */ |
2143 | for (i = min_len + 1; i <= nargs; i++) | |
c906108c SS |
2144 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
2145 | ||
2146 | return bv; | |
2147 | } | |
2148 | ||
2149 | /* Compare one type (PARM) for compatibility with another (ARG). | |
2150 | * PARM is intended to be the parameter type of a function; and | |
2151 | * ARG is the supplied argument's type. This function tests if | |
2152 | * the latter can be converted to the former. | |
2153 | * | |
2154 | * Return 0 if they are identical types; | |
2155 | * Otherwise, return an integer which corresponds to how compatible | |
2156 | * PARM is to ARG. The higher the return value, the worse the match. | |
2157 | * Generally the "bad" conversions are all uniformly assigned a 100 */ | |
2158 | ||
2159 | int | |
2160 | rank_one_type (parm, arg) | |
c5aa993b JM |
2161 | struct type *parm; |
2162 | struct type *arg; | |
c906108c SS |
2163 | { |
2164 | /* Identical type pointers */ | |
2165 | /* However, this still doesn't catch all cases of same type for arg | |
2166 | * and param. The reason is that builtin types are different from | |
2167 | * the same ones constructed from the object. */ | |
2168 | if (parm == arg) | |
2169 | return 0; | |
2170 | ||
2171 | /* Resolve typedefs */ | |
2172 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
2173 | parm = check_typedef (parm); | |
2174 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
2175 | arg = check_typedef (arg); | |
2176 | ||
2177 | /* Check if identical after resolving typedefs */ | |
2178 | if (parm == arg) | |
2179 | return 0; | |
2180 | ||
2181 | #if 0 | |
c5aa993b JM |
2182 | /* Debugging only */ |
2183 | printf ("------ Arg is %s [%d], parm is %s [%d]\n", | |
2184 | TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c SS |
2185 | #endif |
2186 | ||
2187 | /* x -> y means arg of type x being supplied for parameter of type y */ | |
2188 | ||
2189 | switch (TYPE_CODE (parm)) | |
2190 | { | |
c5aa993b JM |
2191 | case TYPE_CODE_PTR: |
2192 | switch (TYPE_CODE (arg)) | |
2193 | { | |
2194 | case TYPE_CODE_PTR: | |
2195 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
2196 | return VOID_PTR_CONVERSION_BADNESS; | |
2197 | else | |
2198 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2199 | case TYPE_CODE_ARRAY: | |
2200 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2201 | case TYPE_CODE_FUNC: | |
2202 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); | |
2203 | case TYPE_CODE_INT: | |
2204 | case TYPE_CODE_ENUM: | |
2205 | case TYPE_CODE_CHAR: | |
2206 | case TYPE_CODE_RANGE: | |
2207 | case TYPE_CODE_BOOL: | |
2208 | return POINTER_CONVERSION_BADNESS; | |
2209 | default: | |
2210 | return INCOMPATIBLE_TYPE_BADNESS; | |
2211 | } | |
2212 | case TYPE_CODE_ARRAY: | |
2213 | switch (TYPE_CODE (arg)) | |
2214 | { | |
2215 | case TYPE_CODE_PTR: | |
2216 | case TYPE_CODE_ARRAY: | |
2217 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2218 | default: | |
2219 | return INCOMPATIBLE_TYPE_BADNESS; | |
2220 | } | |
2221 | case TYPE_CODE_FUNC: | |
2222 | switch (TYPE_CODE (arg)) | |
2223 | { | |
2224 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
2225 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); | |
2226 | default: | |
2227 | return INCOMPATIBLE_TYPE_BADNESS; | |
2228 | } | |
2229 | case TYPE_CODE_INT: | |
2230 | switch (TYPE_CODE (arg)) | |
2231 | { | |
2232 | case TYPE_CODE_INT: | |
2233 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2234 | { | |
2235 | /* Deal with signed, unsigned, and plain chars and | |
2236 | signed and unsigned ints */ | |
2237 | if (TYPE_NOSIGN (parm)) | |
2238 | { | |
2239 | /* This case only for character types */ | |
2240 | if (TYPE_NOSIGN (arg)) /* plain char -> plain char */ | |
2241 | return 0; | |
2242 | else | |
2243 | return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */ | |
2244 | } | |
2245 | else if (TYPE_UNSIGNED (parm)) | |
2246 | { | |
2247 | if (TYPE_UNSIGNED (arg)) | |
2248 | { | |
2249 | if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) | |
2250 | return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */ | |
2251 | else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long")) | |
2252 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ | |
2253 | else | |
2254 | return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */ | |
2255 | } | |
2256 | else | |
2257 | { | |
2258 | if (!strcmp (TYPE_NAME (arg), "long") && !strcmp (TYPE_NAME (parm), "int")) | |
2259 | return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */ | |
2260 | else | |
2261 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ | |
2262 | } | |
2263 | } | |
2264 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2265 | { | |
2266 | if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) | |
2267 | return 0; | |
2268 | else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long")) | |
2269 | return INTEGER_PROMOTION_BADNESS; | |
2270 | else | |
2271 | return INTEGER_COERCION_BADNESS; | |
2272 | } | |
2273 | else | |
2274 | return INTEGER_COERCION_BADNESS; | |
2275 | } | |
2276 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2277 | return INTEGER_PROMOTION_BADNESS; | |
2278 | else | |
2279 | return INTEGER_COERCION_BADNESS; | |
2280 | case TYPE_CODE_ENUM: | |
2281 | case TYPE_CODE_CHAR: | |
2282 | case TYPE_CODE_RANGE: | |
2283 | case TYPE_CODE_BOOL: | |
2284 | return INTEGER_PROMOTION_BADNESS; | |
2285 | case TYPE_CODE_FLT: | |
2286 | return INT_FLOAT_CONVERSION_BADNESS; | |
2287 | case TYPE_CODE_PTR: | |
2288 | return NS_POINTER_CONVERSION_BADNESS; | |
2289 | default: | |
2290 | return INCOMPATIBLE_TYPE_BADNESS; | |
2291 | } | |
2292 | break; | |
2293 | case TYPE_CODE_ENUM: | |
2294 | switch (TYPE_CODE (arg)) | |
2295 | { | |
2296 | case TYPE_CODE_INT: | |
2297 | case TYPE_CODE_CHAR: | |
2298 | case TYPE_CODE_RANGE: | |
2299 | case TYPE_CODE_BOOL: | |
2300 | case TYPE_CODE_ENUM: | |
2301 | return INTEGER_COERCION_BADNESS; | |
2302 | case TYPE_CODE_FLT: | |
2303 | return INT_FLOAT_CONVERSION_BADNESS; | |
2304 | default: | |
2305 | return INCOMPATIBLE_TYPE_BADNESS; | |
2306 | } | |
2307 | break; | |
2308 | case TYPE_CODE_CHAR: | |
2309 | switch (TYPE_CODE (arg)) | |
2310 | { | |
2311 | case TYPE_CODE_RANGE: | |
2312 | case TYPE_CODE_BOOL: | |
2313 | case TYPE_CODE_ENUM: | |
2314 | return INTEGER_COERCION_BADNESS; | |
2315 | case TYPE_CODE_FLT: | |
2316 | return INT_FLOAT_CONVERSION_BADNESS; | |
2317 | case TYPE_CODE_INT: | |
2318 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
2319 | return INTEGER_COERCION_BADNESS; | |
2320 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2321 | return INTEGER_PROMOTION_BADNESS; | |
2322 | /* >>> !! else fall through !! <<< */ | |
2323 | case TYPE_CODE_CHAR: | |
2324 | /* Deal with signed, unsigned, and plain chars for C++ | |
2325 | and with int cases falling through from previous case */ | |
2326 | if (TYPE_NOSIGN (parm)) | |
2327 | { | |
2328 | if (TYPE_NOSIGN (arg)) | |
2329 | return 0; | |
2330 | else | |
2331 | return INTEGER_COERCION_BADNESS; | |
2332 | } | |
2333 | else if (TYPE_UNSIGNED (parm)) | |
2334 | { | |
2335 | if (TYPE_UNSIGNED (arg)) | |
2336 | return 0; | |
2337 | else | |
2338 | return INTEGER_PROMOTION_BADNESS; | |
2339 | } | |
2340 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2341 | return 0; | |
2342 | else | |
2343 | return INTEGER_COERCION_BADNESS; | |
2344 | default: | |
2345 | return INCOMPATIBLE_TYPE_BADNESS; | |
2346 | } | |
2347 | break; | |
2348 | case TYPE_CODE_RANGE: | |
2349 | switch (TYPE_CODE (arg)) | |
2350 | { | |
2351 | case TYPE_CODE_INT: | |
2352 | case TYPE_CODE_CHAR: | |
2353 | case TYPE_CODE_RANGE: | |
2354 | case TYPE_CODE_BOOL: | |
2355 | case TYPE_CODE_ENUM: | |
2356 | return INTEGER_COERCION_BADNESS; | |
2357 | case TYPE_CODE_FLT: | |
2358 | return INT_FLOAT_CONVERSION_BADNESS; | |
2359 | default: | |
2360 | return INCOMPATIBLE_TYPE_BADNESS; | |
2361 | } | |
2362 | break; | |
2363 | case TYPE_CODE_BOOL: | |
2364 | switch (TYPE_CODE (arg)) | |
2365 | { | |
2366 | case TYPE_CODE_INT: | |
2367 | case TYPE_CODE_CHAR: | |
2368 | case TYPE_CODE_RANGE: | |
2369 | case TYPE_CODE_ENUM: | |
2370 | case TYPE_CODE_FLT: | |
2371 | case TYPE_CODE_PTR: | |
2372 | return BOOLEAN_CONVERSION_BADNESS; | |
2373 | case TYPE_CODE_BOOL: | |
2374 | return 0; | |
2375 | default: | |
2376 | return INCOMPATIBLE_TYPE_BADNESS; | |
2377 | } | |
2378 | break; | |
2379 | case TYPE_CODE_FLT: | |
2380 | switch (TYPE_CODE (arg)) | |
2381 | { | |
2382 | case TYPE_CODE_FLT: | |
2383 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2384 | return FLOAT_PROMOTION_BADNESS; | |
2385 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2386 | return 0; | |
2387 | else | |
2388 | return FLOAT_CONVERSION_BADNESS; | |
2389 | case TYPE_CODE_INT: | |
2390 | case TYPE_CODE_BOOL: | |
2391 | case TYPE_CODE_ENUM: | |
2392 | case TYPE_CODE_RANGE: | |
2393 | case TYPE_CODE_CHAR: | |
2394 | return INT_FLOAT_CONVERSION_BADNESS; | |
2395 | default: | |
2396 | return INCOMPATIBLE_TYPE_BADNESS; | |
2397 | } | |
2398 | break; | |
2399 | case TYPE_CODE_COMPLEX: | |
2400 | switch (TYPE_CODE (arg)) | |
2401 | { /* Strictly not needed for C++, but... */ | |
2402 | case TYPE_CODE_FLT: | |
2403 | return FLOAT_PROMOTION_BADNESS; | |
2404 | case TYPE_CODE_COMPLEX: | |
2405 | return 0; | |
2406 | default: | |
2407 | return INCOMPATIBLE_TYPE_BADNESS; | |
2408 | } | |
2409 | break; | |
2410 | case TYPE_CODE_STRUCT: | |
c906108c | 2411 | /* currently same as TYPE_CODE_CLASS */ |
c5aa993b JM |
2412 | switch (TYPE_CODE (arg)) |
2413 | { | |
2414 | case TYPE_CODE_STRUCT: | |
2415 | /* Check for derivation */ | |
2416 | if (is_ancestor (parm, arg)) | |
2417 | return BASE_CONVERSION_BADNESS; | |
2418 | /* else fall through */ | |
2419 | default: | |
2420 | return INCOMPATIBLE_TYPE_BADNESS; | |
2421 | } | |
2422 | break; | |
2423 | case TYPE_CODE_UNION: | |
2424 | switch (TYPE_CODE (arg)) | |
2425 | { | |
2426 | case TYPE_CODE_UNION: | |
2427 | default: | |
2428 | return INCOMPATIBLE_TYPE_BADNESS; | |
2429 | } | |
2430 | break; | |
2431 | case TYPE_CODE_MEMBER: | |
2432 | switch (TYPE_CODE (arg)) | |
2433 | { | |
2434 | default: | |
2435 | return INCOMPATIBLE_TYPE_BADNESS; | |
2436 | } | |
2437 | break; | |
2438 | case TYPE_CODE_METHOD: | |
2439 | switch (TYPE_CODE (arg)) | |
2440 | { | |
2441 | ||
2442 | default: | |
2443 | return INCOMPATIBLE_TYPE_BADNESS; | |
2444 | } | |
2445 | break; | |
2446 | case TYPE_CODE_REF: | |
2447 | switch (TYPE_CODE (arg)) | |
2448 | { | |
2449 | ||
2450 | default: | |
2451 | return INCOMPATIBLE_TYPE_BADNESS; | |
2452 | } | |
2453 | ||
2454 | break; | |
2455 | case TYPE_CODE_SET: | |
2456 | switch (TYPE_CODE (arg)) | |
2457 | { | |
2458 | /* Not in C++ */ | |
2459 | case TYPE_CODE_SET: | |
2460 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0)); | |
2461 | default: | |
2462 | return INCOMPATIBLE_TYPE_BADNESS; | |
2463 | } | |
2464 | break; | |
2465 | case TYPE_CODE_VOID: | |
2466 | default: | |
2467 | return INCOMPATIBLE_TYPE_BADNESS; | |
2468 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
2469 | } |
2470 | ||
c5aa993b JM |
2471 | |
2472 | /* End of functions for overload resolution */ | |
c906108c | 2473 | |
c906108c SS |
2474 | static void |
2475 | print_bit_vector (bits, nbits) | |
2476 | B_TYPE *bits; | |
2477 | int nbits; | |
2478 | { | |
2479 | int bitno; | |
2480 | ||
2481 | for (bitno = 0; bitno < nbits; bitno++) | |
2482 | { | |
2483 | if ((bitno % 8) == 0) | |
2484 | { | |
2485 | puts_filtered (" "); | |
2486 | } | |
2487 | if (B_TST (bits, bitno)) | |
2488 | { | |
2489 | printf_filtered ("1"); | |
2490 | } | |
2491 | else | |
2492 | { | |
2493 | printf_filtered ("0"); | |
2494 | } | |
2495 | } | |
2496 | } | |
2497 | ||
2498 | /* The args list is a strange beast. It is either terminated by a NULL | |
2499 | pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID | |
2500 | type for normal fixed argcount functions. (FIXME someday) | |
2501 | Also note the first arg should be the "this" pointer, we may not want to | |
2502 | include it since we may get into a infinitely recursive situation. */ | |
2503 | ||
2504 | static void | |
2505 | print_arg_types (args, spaces) | |
2506 | struct type **args; | |
2507 | int spaces; | |
2508 | { | |
2509 | if (args != NULL) | |
2510 | { | |
2511 | while (*args != NULL) | |
2512 | { | |
2513 | recursive_dump_type (*args, spaces + 2); | |
c5aa993b | 2514 | if ((*args++)->code == TYPE_CODE_VOID) |
c906108c SS |
2515 | { |
2516 | break; | |
2517 | } | |
2518 | } | |
2519 | } | |
2520 | } | |
2521 | ||
2522 | static void | |
2523 | dump_fn_fieldlists (type, spaces) | |
2524 | struct type *type; | |
2525 | int spaces; | |
2526 | { | |
2527 | int method_idx; | |
2528 | int overload_idx; | |
2529 | struct fn_field *f; | |
2530 | ||
2531 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 2532 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
2533 | printf_filtered ("\n"); |
2534 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
2535 | { | |
2536 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
2537 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
2538 | method_idx, | |
2539 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
2540 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
2541 | gdb_stdout); | |
c906108c SS |
2542 | printf_filtered (") length %d\n", |
2543 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); | |
2544 | for (overload_idx = 0; | |
2545 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
2546 | overload_idx++) | |
2547 | { | |
2548 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
2549 | overload_idx, | |
2550 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
2551 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
2552 | gdb_stdout); | |
c906108c SS |
2553 | printf_filtered (")\n"); |
2554 | printfi_filtered (spaces + 8, "type "); | |
d4f3574e | 2555 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); |
c906108c SS |
2556 | printf_filtered ("\n"); |
2557 | ||
2558 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
2559 | spaces + 8 + 2); | |
2560 | ||
2561 | printfi_filtered (spaces + 8, "args "); | |
d4f3574e | 2562 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); |
c906108c SS |
2563 | printf_filtered ("\n"); |
2564 | ||
2565 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces); | |
2566 | printfi_filtered (spaces + 8, "fcontext "); | |
d4f3574e SS |
2567 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
2568 | gdb_stdout); | |
c906108c SS |
2569 | printf_filtered ("\n"); |
2570 | ||
2571 | printfi_filtered (spaces + 8, "is_const %d\n", | |
2572 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
2573 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
2574 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
2575 | printfi_filtered (spaces + 8, "is_private %d\n", | |
2576 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
2577 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
2578 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
2579 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
2580 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
2581 | printfi_filtered (spaces + 8, "voffset %u\n", | |
2582 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
2583 | } | |
2584 | } | |
2585 | } | |
2586 | ||
2587 | static void | |
2588 | print_cplus_stuff (type, spaces) | |
2589 | struct type *type; | |
2590 | int spaces; | |
2591 | { | |
2592 | printfi_filtered (spaces, "n_baseclasses %d\n", | |
2593 | TYPE_N_BASECLASSES (type)); | |
2594 | printfi_filtered (spaces, "nfn_fields %d\n", | |
2595 | TYPE_NFN_FIELDS (type)); | |
2596 | printfi_filtered (spaces, "nfn_fields_total %d\n", | |
2597 | TYPE_NFN_FIELDS_TOTAL (type)); | |
2598 | if (TYPE_N_BASECLASSES (type) > 0) | |
2599 | { | |
2600 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
2601 | TYPE_N_BASECLASSES (type)); | |
d4f3574e | 2602 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); |
c906108c SS |
2603 | printf_filtered (")"); |
2604 | ||
2605 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
2606 | TYPE_N_BASECLASSES (type)); | |
2607 | puts_filtered ("\n"); | |
2608 | } | |
2609 | if (TYPE_NFIELDS (type) > 0) | |
2610 | { | |
2611 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
2612 | { | |
2613 | printfi_filtered (spaces, "private_field_bits (%d bits at *", | |
2614 | TYPE_NFIELDS (type)); | |
d4f3574e | 2615 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); |
c906108c SS |
2616 | printf_filtered (")"); |
2617 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
2618 | TYPE_NFIELDS (type)); | |
2619 | puts_filtered ("\n"); | |
2620 | } | |
2621 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
2622 | { | |
2623 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", | |
2624 | TYPE_NFIELDS (type)); | |
d4f3574e | 2625 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); |
c906108c SS |
2626 | printf_filtered (")"); |
2627 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
2628 | TYPE_NFIELDS (type)); | |
2629 | puts_filtered ("\n"); | |
2630 | } | |
2631 | } | |
2632 | if (TYPE_NFN_FIELDS (type) > 0) | |
2633 | { | |
2634 | dump_fn_fieldlists (type, spaces); | |
2635 | } | |
2636 | } | |
2637 | ||
2638 | static struct obstack dont_print_type_obstack; | |
2639 | ||
2640 | void | |
2641 | recursive_dump_type (type, spaces) | |
2642 | struct type *type; | |
2643 | int spaces; | |
2644 | { | |
2645 | int idx; | |
2646 | ||
2647 | if (spaces == 0) | |
2648 | obstack_begin (&dont_print_type_obstack, 0); | |
2649 | ||
2650 | if (TYPE_NFIELDS (type) > 0 | |
2651 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) | |
2652 | { | |
2653 | struct type **first_dont_print | |
c5aa993b | 2654 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 2655 | |
c5aa993b JM |
2656 | int i = (struct type **) obstack_next_free (&dont_print_type_obstack) |
2657 | - first_dont_print; | |
c906108c SS |
2658 | |
2659 | while (--i >= 0) | |
2660 | { | |
2661 | if (type == first_dont_print[i]) | |
2662 | { | |
2663 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2664 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
2665 | printf_filtered (" <same as already seen type>\n"); |
2666 | return; | |
2667 | } | |
2668 | } | |
2669 | ||
2670 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
2671 | } | |
2672 | ||
2673 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2674 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
2675 | printf_filtered ("\n"); |
2676 | printfi_filtered (spaces, "name '%s' (", | |
2677 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 2678 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c SS |
2679 | printf_filtered (")\n"); |
2680 | if (TYPE_TAG_NAME (type) != NULL) | |
2681 | { | |
2682 | printfi_filtered (spaces, "tagname '%s' (", | |
2683 | TYPE_TAG_NAME (type)); | |
d4f3574e | 2684 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); |
c906108c SS |
2685 | printf_filtered (")\n"); |
2686 | } | |
2687 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); | |
2688 | switch (TYPE_CODE (type)) | |
2689 | { | |
c5aa993b JM |
2690 | case TYPE_CODE_UNDEF: |
2691 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
2692 | break; | |
2693 | case TYPE_CODE_PTR: | |
2694 | printf_filtered ("(TYPE_CODE_PTR)"); | |
2695 | break; | |
2696 | case TYPE_CODE_ARRAY: | |
2697 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
2698 | break; | |
2699 | case TYPE_CODE_STRUCT: | |
2700 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
2701 | break; | |
2702 | case TYPE_CODE_UNION: | |
2703 | printf_filtered ("(TYPE_CODE_UNION)"); | |
2704 | break; | |
2705 | case TYPE_CODE_ENUM: | |
2706 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
2707 | break; | |
2708 | case TYPE_CODE_FUNC: | |
2709 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
2710 | break; | |
2711 | case TYPE_CODE_INT: | |
2712 | printf_filtered ("(TYPE_CODE_INT)"); | |
2713 | break; | |
2714 | case TYPE_CODE_FLT: | |
2715 | printf_filtered ("(TYPE_CODE_FLT)"); | |
2716 | break; | |
2717 | case TYPE_CODE_VOID: | |
2718 | printf_filtered ("(TYPE_CODE_VOID)"); | |
2719 | break; | |
2720 | case TYPE_CODE_SET: | |
2721 | printf_filtered ("(TYPE_CODE_SET)"); | |
2722 | break; | |
2723 | case TYPE_CODE_RANGE: | |
2724 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
2725 | break; | |
2726 | case TYPE_CODE_STRING: | |
2727 | printf_filtered ("(TYPE_CODE_STRING)"); | |
2728 | break; | |
2729 | case TYPE_CODE_ERROR: | |
2730 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
2731 | break; | |
2732 | case TYPE_CODE_MEMBER: | |
2733 | printf_filtered ("(TYPE_CODE_MEMBER)"); | |
2734 | break; | |
2735 | case TYPE_CODE_METHOD: | |
2736 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
2737 | break; | |
2738 | case TYPE_CODE_REF: | |
2739 | printf_filtered ("(TYPE_CODE_REF)"); | |
2740 | break; | |
2741 | case TYPE_CODE_CHAR: | |
2742 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
2743 | break; | |
2744 | case TYPE_CODE_BOOL: | |
2745 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
2746 | break; | |
2747 | case TYPE_CODE_TYPEDEF: | |
2748 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
2749 | break; | |
2750 | default: | |
2751 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
2752 | break; | |
c906108c SS |
2753 | } |
2754 | puts_filtered ("\n"); | |
2755 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
2756 | printfi_filtered (spaces, "objfile "); | |
d4f3574e | 2757 | gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout); |
c906108c SS |
2758 | printf_filtered ("\n"); |
2759 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 2760 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
2761 | printf_filtered ("\n"); |
2762 | if (TYPE_TARGET_TYPE (type) != NULL) | |
2763 | { | |
2764 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
2765 | } | |
2766 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 2767 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
2768 | printf_filtered ("\n"); |
2769 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 2770 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c SS |
2771 | printf_filtered ("\n"); |
2772 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); | |
2773 | if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED) | |
2774 | { | |
2775 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
2776 | } | |
2777 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
2778 | { | |
2779 | puts_filtered (" TYPE_FLAG_STUB"); | |
2780 | } | |
2781 | puts_filtered ("\n"); | |
2782 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 2783 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
2784 | puts_filtered ("\n"); |
2785 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
2786 | { | |
2787 | printfi_filtered (spaces + 2, | |
2788 | "[%d] bitpos %d bitsize %d type ", | |
2789 | idx, TYPE_FIELD_BITPOS (type, idx), | |
2790 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 2791 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
2792 | printf_filtered (" name '%s' (", |
2793 | TYPE_FIELD_NAME (type, idx) != NULL | |
2794 | ? TYPE_FIELD_NAME (type, idx) | |
2795 | : "<NULL>"); | |
d4f3574e | 2796 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
2797 | printf_filtered (")\n"); |
2798 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
2799 | { | |
2800 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
2801 | } | |
2802 | } | |
2803 | printfi_filtered (spaces, "vptr_basetype "); | |
d4f3574e | 2804 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
c906108c SS |
2805 | puts_filtered ("\n"); |
2806 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
2807 | { | |
2808 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
2809 | } | |
2810 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); | |
2811 | switch (TYPE_CODE (type)) | |
2812 | { | |
c5aa993b JM |
2813 | case TYPE_CODE_METHOD: |
2814 | case TYPE_CODE_FUNC: | |
2815 | printfi_filtered (spaces, "arg_types "); | |
d4f3574e | 2816 | gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout); |
c5aa993b JM |
2817 | puts_filtered ("\n"); |
2818 | print_arg_types (TYPE_ARG_TYPES (type), spaces); | |
2819 | break; | |
c906108c | 2820 | |
c5aa993b JM |
2821 | case TYPE_CODE_STRUCT: |
2822 | printfi_filtered (spaces, "cplus_stuff "); | |
d4f3574e | 2823 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
2824 | puts_filtered ("\n"); |
2825 | print_cplus_stuff (type, spaces); | |
2826 | break; | |
c906108c | 2827 | |
c5aa993b JM |
2828 | default: |
2829 | /* We have to pick one of the union types to be able print and test | |
2830 | the value. Pick cplus_struct_type, even though we know it isn't | |
2831 | any particular one. */ | |
2832 | printfi_filtered (spaces, "type_specific "); | |
d4f3574e | 2833 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
2834 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
2835 | { | |
2836 | printf_filtered (" (unknown data form)"); | |
2837 | } | |
2838 | printf_filtered ("\n"); | |
2839 | break; | |
c906108c SS |
2840 | |
2841 | } | |
2842 | if (spaces == 0) | |
2843 | obstack_free (&dont_print_type_obstack, NULL); | |
2844 | } | |
2845 | ||
c906108c SS |
2846 | static void build_gdbtypes PARAMS ((void)); |
2847 | static void | |
2848 | build_gdbtypes () | |
2849 | { | |
2850 | builtin_type_void = | |
2851 | init_type (TYPE_CODE_VOID, 1, | |
2852 | 0, | |
2853 | "void", (struct objfile *) NULL); | |
2854 | builtin_type_char = | |
2855 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2856 | 0, | |
2857 | "char", (struct objfile *) NULL); | |
2858 | TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN; | |
c5aa993b | 2859 | builtin_type_true_char = |
9e0b60a8 JM |
2860 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
2861 | 0, | |
2862 | "true character", (struct objfile *) NULL); | |
c906108c SS |
2863 | builtin_type_signed_char = |
2864 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2865 | 0, | |
2866 | "signed char", (struct objfile *) NULL); | |
2867 | builtin_type_unsigned_char = | |
2868 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2869 | TYPE_FLAG_UNSIGNED, | |
2870 | "unsigned char", (struct objfile *) NULL); | |
2871 | builtin_type_short = | |
2872 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
2873 | 0, | |
2874 | "short", (struct objfile *) NULL); | |
2875 | builtin_type_unsigned_short = | |
2876 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
2877 | TYPE_FLAG_UNSIGNED, | |
2878 | "unsigned short", (struct objfile *) NULL); | |
2879 | builtin_type_int = | |
2880 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
2881 | 0, | |
2882 | "int", (struct objfile *) NULL); | |
2883 | builtin_type_unsigned_int = | |
2884 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
2885 | TYPE_FLAG_UNSIGNED, | |
2886 | "unsigned int", (struct objfile *) NULL); | |
2887 | builtin_type_long = | |
2888 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
2889 | 0, | |
2890 | "long", (struct objfile *) NULL); | |
2891 | builtin_type_unsigned_long = | |
2892 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
2893 | TYPE_FLAG_UNSIGNED, | |
2894 | "unsigned long", (struct objfile *) NULL); | |
2895 | builtin_type_long_long = | |
2896 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
2897 | 0, | |
2898 | "long long", (struct objfile *) NULL); | |
c5aa993b | 2899 | builtin_type_unsigned_long_long = |
c906108c SS |
2900 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
2901 | TYPE_FLAG_UNSIGNED, | |
2902 | "unsigned long long", (struct objfile *) NULL); | |
2903 | builtin_type_float = | |
2904 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
2905 | 0, | |
2906 | "float", (struct objfile *) NULL); | |
2907 | builtin_type_double = | |
2908 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
2909 | 0, | |
2910 | "double", (struct objfile *) NULL); | |
2911 | builtin_type_long_double = | |
2912 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
2913 | 0, | |
2914 | "long double", (struct objfile *) NULL); | |
2915 | builtin_type_complex = | |
2916 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
2917 | 0, | |
2918 | "complex", (struct objfile *) NULL); | |
2919 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; | |
2920 | builtin_type_double_complex = | |
2921 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
2922 | 0, | |
2923 | "double complex", (struct objfile *) NULL); | |
2924 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; | |
2925 | builtin_type_string = | |
2926 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2927 | 0, | |
2928 | "string", (struct objfile *) NULL); | |
2929 | builtin_type_int8 = | |
2930 | init_type (TYPE_CODE_INT, 8 / 8, | |
2931 | 0, | |
2932 | "int8_t", (struct objfile *) NULL); | |
2933 | builtin_type_uint8 = | |
2934 | init_type (TYPE_CODE_INT, 8 / 8, | |
2935 | TYPE_FLAG_UNSIGNED, | |
2936 | "uint8_t", (struct objfile *) NULL); | |
2937 | builtin_type_int16 = | |
2938 | init_type (TYPE_CODE_INT, 16 / 8, | |
2939 | 0, | |
2940 | "int16_t", (struct objfile *) NULL); | |
2941 | builtin_type_uint16 = | |
2942 | init_type (TYPE_CODE_INT, 16 / 8, | |
2943 | TYPE_FLAG_UNSIGNED, | |
2944 | "uint16_t", (struct objfile *) NULL); | |
2945 | builtin_type_int32 = | |
2946 | init_type (TYPE_CODE_INT, 32 / 8, | |
2947 | 0, | |
2948 | "int32_t", (struct objfile *) NULL); | |
2949 | builtin_type_uint32 = | |
2950 | init_type (TYPE_CODE_INT, 32 / 8, | |
2951 | TYPE_FLAG_UNSIGNED, | |
2952 | "uint32_t", (struct objfile *) NULL); | |
2953 | builtin_type_int64 = | |
2954 | init_type (TYPE_CODE_INT, 64 / 8, | |
2955 | 0, | |
2956 | "int64_t", (struct objfile *) NULL); | |
2957 | builtin_type_uint64 = | |
2958 | init_type (TYPE_CODE_INT, 64 / 8, | |
2959 | TYPE_FLAG_UNSIGNED, | |
2960 | "uint64_t", (struct objfile *) NULL); | |
2961 | builtin_type_bool = | |
2962 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2963 | 0, | |
2964 | "bool", (struct objfile *) NULL); | |
2965 | ||
c5aa993b | 2966 | /* Add user knob for controlling resolution of opaque types */ |
c906108c | 2967 | add_show_from_set |
c5aa993b | 2968 | (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution, |
c906108c SS |
2969 | "Set resolution of opaque struct/class/union types (if set before loading symbols).", |
2970 | &setlist), | |
2971 | &showlist); | |
2972 | opaque_type_resolution = 1; | |
2973 | ||
917317f4 JM |
2974 | |
2975 | /* Build SIMD types. */ | |
2976 | builtin_type_v4sf | |
2977 | = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4); | |
c2d11a7d JM |
2978 | builtin_type_v4si |
2979 | = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4); | |
2980 | builtin_type_v8qi | |
2981 | = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8); | |
2982 | builtin_type_v4hi | |
2983 | = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4); | |
2984 | builtin_type_v2si | |
2985 | = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2); | |
c4093a6a JM |
2986 | |
2987 | /* Pointer/Address types. */ | |
2988 | /* NOTE: At present there is no way of differentiating between at | |
2989 | target address and the target C language pointer type type even | |
2990 | though the two can be different (cf d10v) */ | |
2991 | builtin_type_ptr = | |
2992 | init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8, | |
2993 | TYPE_FLAG_UNSIGNED, | |
2994 | "__ptr", (struct objfile *) NULL); | |
2995 | builtin_type_CORE_ADDR = | |
2996 | init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8, | |
2997 | TYPE_FLAG_UNSIGNED, | |
2998 | "__CORE_ADDR", (struct objfile *) NULL); | |
2999 | builtin_type_bfd_vma = | |
3000 | init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8, | |
3001 | TYPE_FLAG_UNSIGNED, | |
3002 | "__bfd_vma", (struct objfile *) NULL); | |
c906108c SS |
3003 | } |
3004 | ||
3005 | ||
3006 | extern void _initialize_gdbtypes PARAMS ((void)); | |
3007 | void | |
3008 | _initialize_gdbtypes () | |
3009 | { | |
3010 | build_gdbtypes (); | |
0f71a2f6 JM |
3011 | |
3012 | /* FIXME - For the moment, handle types by swapping them in and out. | |
3013 | Should be using the per-architecture data-pointer and a large | |
3014 | struct. */ | |
c5aa993b JM |
3015 | register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL); |
3016 | register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL); | |
3017 | register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL); | |
3018 | register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL); | |
3019 | register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL); | |
3020 | register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL); | |
3021 | register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL); | |
3022 | register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL); | |
3023 | register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL); | |
3024 | register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL); | |
3025 | register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL); | |
3026 | register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL); | |
3027 | register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL); | |
3028 | register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL); | |
3029 | register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL); | |
3030 | register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL); | |
3031 | register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL); | |
3032 | register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL); | |
3033 | register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL); | |
3034 | register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL); | |
3035 | register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL); | |
3036 | register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL); | |
3037 | register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL); | |
3038 | register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL); | |
3039 | register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL); | |
3040 | register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL); | |
917317f4 | 3041 | register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL); |
c2d11a7d JM |
3042 | register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL); |
3043 | register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL); | |
3044 | register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL); | |
3045 | register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL); | |
c4093a6a JM |
3046 | REGISTER_GDBARCH_SWAP (builtin_type_ptr); |
3047 | REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR); | |
3048 | REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma); | |
0f71a2f6 | 3049 | register_gdbarch_swap (NULL, 0, build_gdbtypes); |
c906108c | 3050 | } |