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