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