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