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