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