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