* ch-exp.y (match_dollar_tokens): Fix off-by-one bug.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
1 /* Support routines for manipulating internal types for GDB.
2 Copyright (C) 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include "defs.h"
22 #include <string.h>
23 #include "bfd.h"
24 #include "symtab.h"
25 #include "symfile.h"
26 #include "objfiles.h"
27 #include "gdbtypes.h"
28 #include "expression.h"
29 #include "language.h"
30 #include "target.h"
31 #include "value.h"
32 #include "demangle.h"
33 #include "complaints.h"
34
35 /* These variables point to the objects
36 representing the predefined C data types. */
37
38 struct type *builtin_type_void;
39 struct type *builtin_type_char;
40 struct type *builtin_type_short;
41 struct type *builtin_type_int;
42 struct type *builtin_type_long;
43 struct type *builtin_type_long_long;
44 struct type *builtin_type_signed_char;
45 struct type *builtin_type_unsigned_char;
46 struct type *builtin_type_unsigned_short;
47 struct type *builtin_type_unsigned_int;
48 struct type *builtin_type_unsigned_long;
49 struct type *builtin_type_unsigned_long_long;
50 struct type *builtin_type_float;
51 struct type *builtin_type_double;
52 struct type *builtin_type_long_double;
53 struct type *builtin_type_complex;
54 struct type *builtin_type_double_complex;
55 struct type *builtin_type_string;
56
57 /* Alloc a new type structure and fill it with some defaults. If
58 OBJFILE is non-NULL, then allocate the space for the type structure
59 in that objfile's type_obstack. */
60
61 struct type *
62 alloc_type (objfile)
63 struct objfile *objfile;
64 {
65 register struct type *type;
66
67 /* Alloc the structure and start off with all fields zeroed. */
68
69 if (objfile == NULL)
70 {
71 type = (struct type *) xmalloc (sizeof (struct type));
72 }
73 else
74 {
75 type = (struct type *) obstack_alloc (&objfile -> type_obstack,
76 sizeof (struct type));
77 }
78 memset ((char *) type, 0, sizeof (struct type));
79
80 /* Initialize the fields that might not be zero. */
81
82 TYPE_CODE (type) = TYPE_CODE_UNDEF;
83 TYPE_OBJFILE (type) = objfile;
84 TYPE_VPTR_FIELDNO (type) = -1;
85
86 return (type);
87 }
88
89 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
90 to a pointer to memory where the pointer type should be stored.
91 If *TYPEPTR is zero, update it to point to the pointer type we return.
92 We allocate new memory if needed. */
93
94 struct type *
95 make_pointer_type (type, typeptr)
96 struct type *type;
97 struct type **typeptr;
98 {
99 register struct type *ntype; /* New type */
100 struct objfile *objfile;
101
102 ntype = TYPE_POINTER_TYPE (type);
103
104 if (ntype)
105 if (typeptr == 0)
106 return ntype; /* Don't care about alloc, and have new type. */
107 else if (*typeptr == 0)
108 {
109 *typeptr = ntype; /* Tracking alloc, and we have new type. */
110 return ntype;
111 }
112
113 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
114 {
115 ntype = alloc_type (TYPE_OBJFILE (type));
116 if (typeptr)
117 *typeptr = ntype;
118 }
119 else /* We have storage, but need to reset it. */
120 {
121 ntype = *typeptr;
122 objfile = TYPE_OBJFILE (ntype);
123 memset ((char *) ntype, 0, sizeof (struct type));
124 TYPE_OBJFILE (ntype) = objfile;
125 }
126
127 TYPE_TARGET_TYPE (ntype) = type;
128 TYPE_POINTER_TYPE (type) = ntype;
129
130 /* FIXME! Assume the machine has only one representation for pointers! */
131
132 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
133 TYPE_CODE (ntype) = TYPE_CODE_PTR;
134
135 /* pointers are unsigned */
136 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
137
138 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
139 TYPE_POINTER_TYPE (type) = ntype;
140
141 return ntype;
142 }
143
144 /* Given a type TYPE, return a type of pointers to that type.
145 May need to construct such a type if this is the first use. */
146
147 struct type *
148 lookup_pointer_type (type)
149 struct type *type;
150 {
151 return make_pointer_type (type, (struct type **)0);
152 }
153
154 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
155 to a pointer to memory where the reference type should be stored.
156 If *TYPEPTR is zero, update it to point to the reference type we return.
157 We allocate new memory if needed. */
158
159 struct type *
160 make_reference_type (type, typeptr)
161 struct type *type;
162 struct type **typeptr;
163 {
164 register struct type *ntype; /* New type */
165 struct objfile *objfile;
166
167 ntype = TYPE_REFERENCE_TYPE (type);
168
169 if (ntype)
170 if (typeptr == 0)
171 return ntype; /* Don't care about alloc, and have new type. */
172 else if (*typeptr == 0)
173 {
174 *typeptr = ntype; /* Tracking alloc, and we have new type. */
175 return ntype;
176 }
177
178 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
179 {
180 ntype = alloc_type (TYPE_OBJFILE (type));
181 if (typeptr)
182 *typeptr = ntype;
183 }
184 else /* We have storage, but need to reset it. */
185 {
186 ntype = *typeptr;
187 objfile = TYPE_OBJFILE (ntype);
188 memset ((char *) ntype, 0, sizeof (struct type));
189 TYPE_OBJFILE (ntype) = objfile;
190 }
191
192 TYPE_TARGET_TYPE (ntype) = type;
193 TYPE_REFERENCE_TYPE (type) = ntype;
194
195 /* FIXME! Assume the machine has only one representation for references,
196 and that it matches the (only) representation for pointers! */
197
198 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
199 TYPE_CODE (ntype) = TYPE_CODE_REF;
200
201 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
202 TYPE_REFERENCE_TYPE (type) = ntype;
203
204 return ntype;
205 }
206
207 /* Same as above, but caller doesn't care about memory allocation details. */
208
209 struct type *
210 lookup_reference_type (type)
211 struct type *type;
212 {
213 return make_reference_type (type, (struct type **)0);
214 }
215
216 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
217 to a pointer to memory where the function type should be stored.
218 If *TYPEPTR is zero, update it to point to the function type we return.
219 We allocate new memory if needed. */
220
221 struct type *
222 make_function_type (type, typeptr)
223 struct type *type;
224 struct type **typeptr;
225 {
226 register struct type *ntype; /* New type */
227 struct objfile *objfile;
228
229 ntype = TYPE_FUNCTION_TYPE (type);
230
231 if (ntype)
232 if (typeptr == 0)
233 return ntype; /* Don't care about alloc, and have new type. */
234 else if (*typeptr == 0)
235 {
236 *typeptr = ntype; /* Tracking alloc, and we have new type. */
237 return ntype;
238 }
239
240 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
241 {
242 ntype = alloc_type (TYPE_OBJFILE (type));
243 if (typeptr)
244 *typeptr = ntype;
245 }
246 else /* We have storage, but need to reset it. */
247 {
248 ntype = *typeptr;
249 objfile = TYPE_OBJFILE (ntype);
250 memset ((char *) ntype, 0, sizeof (struct type));
251 TYPE_OBJFILE (ntype) = objfile;
252 }
253
254 TYPE_TARGET_TYPE (ntype) = type;
255 TYPE_FUNCTION_TYPE (type) = ntype;
256
257 TYPE_LENGTH (ntype) = 1;
258 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
259
260 if (!TYPE_FUNCTION_TYPE (type)) /* Remember it, if don't have one. */
261 TYPE_FUNCTION_TYPE (type) = ntype;
262
263 return ntype;
264 }
265
266
267 /* Given a type TYPE, return a type of functions that return that type.
268 May need to construct such a type if this is the first use. */
269
270 struct type *
271 lookup_function_type (type)
272 struct type *type;
273 {
274 return make_function_type (type, (struct type **)0);
275 }
276
277 /* Implement direct support for MEMBER_TYPE in GNU C++.
278 May need to construct such a type if this is the first use.
279 The TYPE is the type of the member. The DOMAIN is the type
280 of the aggregate that the member belongs to. */
281
282 struct type *
283 lookup_member_type (type, domain)
284 struct type *type;
285 struct type *domain;
286 {
287 register struct type *mtype;
288
289 mtype = alloc_type (TYPE_OBJFILE (type));
290 smash_to_member_type (mtype, domain, type);
291 return (mtype);
292 }
293
294 /* Allocate a stub method whose return type is TYPE.
295 This apparently happens for speed of symbol reading, since parsing
296 out the arguments to the method is cpu-intensive, the way we are doing
297 it. So, we will fill in arguments later.
298 This always returns a fresh type. */
299
300 struct type *
301 allocate_stub_method (type)
302 struct type *type;
303 {
304 struct type *mtype;
305
306 mtype = alloc_type (TYPE_OBJFILE (type));
307 TYPE_TARGET_TYPE (mtype) = type;
308 /* _DOMAIN_TYPE (mtype) = unknown yet */
309 /* _ARG_TYPES (mtype) = unknown yet */
310 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
311 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
312 TYPE_LENGTH (mtype) = 1;
313 return (mtype);
314 }
315
316 /* Create a range type using either a blank type supplied in RESULT_TYPE,
317 or creating a new type, inheriting the objfile from INDEX_TYPE.
318
319 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
320 HIGH_BOUND, inclusive.
321
322 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
323 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
324
325 struct type *
326 create_range_type (result_type, index_type, low_bound, high_bound)
327 struct type *result_type;
328 struct type *index_type;
329 int low_bound;
330 int high_bound;
331 {
332 if (result_type == NULL)
333 {
334 result_type = alloc_type (TYPE_OBJFILE (index_type));
335 }
336 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
337 TYPE_TARGET_TYPE (result_type) = index_type;
338 TYPE_LENGTH (result_type) = TYPE_LENGTH (index_type);
339 TYPE_NFIELDS (result_type) = 2;
340 TYPE_FIELDS (result_type) = (struct field *)
341 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
342 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
343 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
344 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
345 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
346 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
347
348 return (result_type);
349 }
350
351 /* A lot of code assumes that the "index type" of an array/string/
352 set/bitstring is specifically a range type, though in some languages
353 it can be any discrete type. */
354
355 struct type *
356 force_to_range_type (type)
357 struct type *type;
358 {
359 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
360 return type;
361
362 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
363 {
364 int low_bound = TYPE_FIELD_BITPOS (type, 0);
365 int high_bound = TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
366 struct type *range_type = create_range_type (NULL, type, low_bound, high_bound);
367 TYPE_NAME (range_type) = TYPE_NAME (range_type);
368 TYPE_DUMMY_RANGE (range_type) = 1;
369 return range_type;
370 }
371 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
372 {
373 struct type *range_type = create_range_type (NULL, type, 0, 1);
374 TYPE_NAME (range_type) = TYPE_NAME (range_type);
375 TYPE_DUMMY_RANGE (range_type) = 1;
376 return range_type;
377 }
378 if (TYPE_CODE (type) == TYPE_CODE_CHAR)
379 {
380 struct type *range_type = create_range_type (NULL, type, 0, 255);
381 TYPE_NAME (range_type) = TYPE_NAME (range_type);
382 TYPE_DUMMY_RANGE (range_type) = 1;
383 return range_type;
384 }
385
386 warning ("internal error: array index type must be a discrete type");
387 type = lookup_fundamental_type (TYPE_OBJFILE (type), FT_INTEGER);
388 return create_range_type ((struct type *) NULL, type, 0, 0);
389 }
390
391 /* Create an array type using either a blank type supplied in RESULT_TYPE,
392 or creating a new type, inheriting the objfile from RANGE_TYPE.
393
394 Elements will be of type ELEMENT_TYPE, the indices will be of type
395 RANGE_TYPE.
396
397 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
398 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
399
400 struct type *
401 create_array_type (result_type, element_type, range_type)
402 struct type *result_type;
403 struct type *element_type;
404 struct type *range_type;
405 {
406 int low_bound;
407 int high_bound;
408
409 range_type = force_to_range_type (range_type);
410 if (result_type == NULL)
411 {
412 result_type = alloc_type (TYPE_OBJFILE (range_type));
413 }
414 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
415 TYPE_TARGET_TYPE (result_type) = element_type;
416 low_bound = TYPE_LOW_BOUND (range_type);
417 high_bound = TYPE_HIGH_BOUND (range_type);
418 TYPE_LENGTH (result_type) =
419 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
420 TYPE_NFIELDS (result_type) = 1;
421 TYPE_FIELDS (result_type) =
422 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
423 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
424 TYPE_FIELD_TYPE (result_type, 0) = range_type;
425 TYPE_VPTR_FIELDNO (result_type) = -1;
426
427 return (result_type);
428 }
429
430 /* Create a string type using either a blank type supplied in RESULT_TYPE,
431 or creating a new type. String types are similar enough to array of
432 char types that we can use create_array_type to build the basic type
433 and then bash it into a string type.
434
435 For fixed length strings, the range type contains 0 as the lower
436 bound and the length of the string minus one as the upper bound.
437
438 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
439 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
440
441 struct type *
442 create_string_type (result_type, range_type)
443 struct type *result_type;
444 struct type *range_type;
445 {
446 result_type = create_array_type (result_type, builtin_type_char, range_type);
447 TYPE_CODE (result_type) = TYPE_CODE_STRING;
448 return (result_type);
449 }
450
451 struct type *
452 create_set_type (result_type, domain_type)
453 struct type *result_type;
454 struct type *domain_type;
455 {
456 int low_bound, high_bound, bit_length;
457 if (result_type == NULL)
458 {
459 result_type = alloc_type (TYPE_OBJFILE (domain_type));
460 }
461 domain_type = force_to_range_type (domain_type);
462 TYPE_CODE (result_type) = TYPE_CODE_SET;
463 TYPE_NFIELDS (result_type) = 1;
464 TYPE_FIELDS (result_type) = (struct field *)
465 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
466 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
467 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
468 low_bound = TYPE_LOW_BOUND (domain_type);
469 high_bound = TYPE_HIGH_BOUND (domain_type);
470 bit_length = high_bound - low_bound + 1;
471 if (bit_length <= TARGET_CHAR_BIT)
472 TYPE_LENGTH (result_type) = 1;
473 else if (bit_length <= TARGET_SHORT_BIT)
474 TYPE_LENGTH (result_type) = TARGET_SHORT_BIT / TARGET_CHAR_BIT;
475 else
476 TYPE_LENGTH (result_type)
477 = ((bit_length + TARGET_INT_BIT - 1) / TARGET_INT_BIT)
478 * TARGET_CHAR_BIT;
479 return (result_type);
480 }
481
482 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
483 A MEMBER is a wierd thing -- it amounts to a typed offset into
484 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
485 include the offset (that's the value of the MEMBER itself), but does
486 include the structure type into which it points (for some reason).
487
488 When "smashing" the type, we preserve the objfile that the
489 old type pointed to, since we aren't changing where the type is actually
490 allocated. */
491
492 void
493 smash_to_member_type (type, domain, to_type)
494 struct type *type;
495 struct type *domain;
496 struct type *to_type;
497 {
498 struct objfile *objfile;
499
500 objfile = TYPE_OBJFILE (type);
501
502 memset ((char *) type, 0, sizeof (struct type));
503 TYPE_OBJFILE (type) = objfile;
504 TYPE_TARGET_TYPE (type) = to_type;
505 TYPE_DOMAIN_TYPE (type) = domain;
506 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
507 TYPE_CODE (type) = TYPE_CODE_MEMBER;
508 }
509
510 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
511 METHOD just means `function that gets an extra "this" argument'.
512
513 When "smashing" the type, we preserve the objfile that the
514 old type pointed to, since we aren't changing where the type is actually
515 allocated. */
516
517 void
518 smash_to_method_type (type, domain, to_type, args)
519 struct type *type;
520 struct type *domain;
521 struct type *to_type;
522 struct type **args;
523 {
524 struct objfile *objfile;
525
526 objfile = TYPE_OBJFILE (type);
527
528 memset ((char *) type, 0, sizeof (struct type));
529 TYPE_OBJFILE (type) = objfile;
530 TYPE_TARGET_TYPE (type) = to_type;
531 TYPE_DOMAIN_TYPE (type) = domain;
532 TYPE_ARG_TYPES (type) = args;
533 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
534 TYPE_CODE (type) = TYPE_CODE_METHOD;
535 }
536
537 /* Return a typename for a struct/union/enum type without "struct ",
538 "union ", or "enum ". If the type has a NULL name, return NULL. */
539
540 char *
541 type_name_no_tag (type)
542 register const struct type *type;
543 {
544 if (TYPE_TAG_NAME (type) != NULL)
545 return TYPE_TAG_NAME (type);
546
547 /* Is there code which expects this to return the name if there is no
548 tag name? My guess is that this is mainly used for C++ in cases where
549 the two will always be the same. */
550 return TYPE_NAME (type);
551 }
552
553 /* Lookup a primitive type named NAME.
554 Return zero if NAME is not a primitive type.*/
555
556 struct type *
557 lookup_primitive_typename (name)
558 char *name;
559 {
560 struct type ** const *p;
561
562 for (p = current_language -> la_builtin_type_vector; *p != NULL; p++)
563 {
564 if (STREQ ((**p) -> name, name))
565 {
566 return (**p);
567 }
568 }
569 return (NULL);
570 }
571
572 /* Lookup a typedef or primitive type named NAME,
573 visible in lexical block BLOCK.
574 If NOERR is nonzero, return zero if NAME is not suitably defined. */
575
576 struct type *
577 lookup_typename (name, block, noerr)
578 char *name;
579 struct block *block;
580 int noerr;
581 {
582 register struct symbol *sym;
583 register struct type *tmp;
584
585 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
586 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
587 {
588 tmp = lookup_primitive_typename (name);
589 if (tmp)
590 {
591 return (tmp);
592 }
593 else if (!tmp && noerr)
594 {
595 return (NULL);
596 }
597 else
598 {
599 error ("No type named %s.", name);
600 }
601 }
602 return (SYMBOL_TYPE (sym));
603 }
604
605 struct type *
606 lookup_unsigned_typename (name)
607 char *name;
608 {
609 char *uns = alloca (strlen (name) + 10);
610
611 strcpy (uns, "unsigned ");
612 strcpy (uns + 9, name);
613 return (lookup_typename (uns, (struct block *) NULL, 0));
614 }
615
616 struct type *
617 lookup_signed_typename (name)
618 char *name;
619 {
620 struct type *t;
621 char *uns = alloca (strlen (name) + 8);
622
623 strcpy (uns, "signed ");
624 strcpy (uns + 7, name);
625 t = lookup_typename (uns, (struct block *) NULL, 1);
626 /* If we don't find "signed FOO" just try again with plain "FOO". */
627 if (t != NULL)
628 return t;
629 return lookup_typename (name, (struct block *) NULL, 0);
630 }
631
632 /* Lookup a structure type named "struct NAME",
633 visible in lexical block BLOCK. */
634
635 struct type *
636 lookup_struct (name, block)
637 char *name;
638 struct block *block;
639 {
640 register struct symbol *sym;
641
642 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
643 (struct symtab **) NULL);
644
645 if (sym == NULL)
646 {
647 error ("No struct type named %s.", name);
648 }
649 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
650 {
651 error ("This context has class, union or enum %s, not a struct.", name);
652 }
653 return (SYMBOL_TYPE (sym));
654 }
655
656 /* Lookup a union type named "union NAME",
657 visible in lexical block BLOCK. */
658
659 struct type *
660 lookup_union (name, block)
661 char *name;
662 struct block *block;
663 {
664 register struct symbol *sym;
665
666 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
667 (struct symtab **) NULL);
668
669 if (sym == NULL)
670 {
671 error ("No union type named %s.", name);
672 }
673 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
674 {
675 error ("This context has class, struct or enum %s, not a union.", name);
676 }
677 return (SYMBOL_TYPE (sym));
678 }
679
680 /* Lookup an enum type named "enum NAME",
681 visible in lexical block BLOCK. */
682
683 struct type *
684 lookup_enum (name, block)
685 char *name;
686 struct block *block;
687 {
688 register struct symbol *sym;
689
690 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
691 (struct symtab **) NULL);
692 if (sym == NULL)
693 {
694 error ("No enum type named %s.", name);
695 }
696 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
697 {
698 error ("This context has class, struct or union %s, not an enum.", name);
699 }
700 return (SYMBOL_TYPE (sym));
701 }
702
703 /* Lookup a template type named "template NAME<TYPE>",
704 visible in lexical block BLOCK. */
705
706 struct type *
707 lookup_template_type (name, type, block)
708 char *name;
709 struct type *type;
710 struct block *block;
711 {
712 struct symbol *sym;
713 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
714 strcpy (nam, name);
715 strcat (nam, "<");
716 strcat (nam, type->name);
717 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
718
719 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
720
721 if (sym == NULL)
722 {
723 error ("No template type named %s.", name);
724 }
725 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
726 {
727 error ("This context has class, union or enum %s, not a struct.", name);
728 }
729 return (SYMBOL_TYPE (sym));
730 }
731
732 /* Given a type TYPE, lookup the type of the component of type named NAME.
733
734 TYPE can be either a struct or union, or a pointer or reference to a struct or
735 union. If it is a pointer or reference, its target type is automatically used.
736 Thus '.' and '->' are interchangable, as specified for the definitions of the
737 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
738
739 If NOERR is nonzero, return zero if NAME is not suitably defined.
740 If NAME is the name of a baseclass type, return that type. */
741
742 struct type *
743 lookup_struct_elt_type (type, name, noerr)
744 struct type *type;
745 char *name;
746 int noerr;
747 {
748 int i;
749
750 while (TYPE_CODE (type) == TYPE_CODE_PTR ||
751 TYPE_CODE (type) == TYPE_CODE_REF)
752 type = TYPE_TARGET_TYPE (type);
753
754 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
755 TYPE_CODE (type) != TYPE_CODE_UNION)
756 {
757 target_terminal_ours ();
758 gdb_flush (gdb_stdout);
759 fprintf_unfiltered (gdb_stderr, "Type ");
760 type_print (type, "", gdb_stderr, -1);
761 error (" is not a structure or union type.");
762 }
763
764 check_stub_type (type);
765
766 #if 0
767 /* FIXME: This change put in by Michael seems incorrect for the case where
768 the structure tag name is the same as the member name. I.E. when doing
769 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
770 Disabled by fnf. */
771 {
772 char *typename;
773
774 typename = type_name_no_tag (type);
775 if (typename != NULL && STREQ (typename, name))
776 return type;
777 }
778 #endif
779
780 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
781 {
782 char *t_field_name = TYPE_FIELD_NAME (type, i);
783
784 if (t_field_name && STREQ (t_field_name, name))
785 {
786 return TYPE_FIELD_TYPE (type, i);
787 }
788 }
789
790 /* OK, it's not in this class. Recursively check the baseclasses. */
791 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
792 {
793 struct type *t;
794
795 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
796 if (t != NULL)
797 {
798 return t;
799 }
800 }
801
802 if (noerr)
803 {
804 return NULL;
805 }
806
807 target_terminal_ours ();
808 gdb_flush (gdb_stdout);
809 fprintf_unfiltered (gdb_stderr, "Type ");
810 type_print (type, "", gdb_stderr, -1);
811 fprintf_unfiltered (gdb_stderr, " has no component named ");
812 fputs_filtered (name, gdb_stderr);
813 error (".");
814 return (struct type *)-1; /* For lint */
815 }
816
817 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
818 valid. Callers should be aware that in some cases (for example,
819 the type or one of its baseclasses is a stub type and we are
820 debugging a .o file), this function will not be able to find the virtual
821 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
822 will remain NULL. */
823
824 void
825 fill_in_vptr_fieldno (type)
826 struct type *type;
827 {
828 check_stub_type (type);
829
830 if (TYPE_VPTR_FIELDNO (type) < 0)
831 {
832 int i;
833
834 /* We must start at zero in case the first (and only) baseclass is
835 virtual (and hence we cannot share the table pointer). */
836 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
837 {
838 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
839 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
840 {
841 TYPE_VPTR_FIELDNO (type)
842 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
843 TYPE_VPTR_BASETYPE (type)
844 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
845 break;
846 }
847 }
848 }
849 }
850
851 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
852
853 If this is a stubbed struct (i.e. declared as struct foo *), see if
854 we can find a full definition in some other file. If so, copy this
855 definition, so we can use it in future. There used to be a comment (but
856 not any code) that if we don't find a full definition, we'd set a flag
857 so we don't spend time in the future checking the same type. That would
858 be a mistake, though--we might load in more symbols which contain a
859 full definition for the type.
860
861 This used to be coded as a macro, but I don't think it is called
862 often enough to merit such treatment. */
863
864 struct complaint stub_noname_complaint =
865 {"stub type has NULL name", 0, 0};
866
867 void
868 check_stub_type (type)
869 struct type *type;
870 {
871 if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
872 {
873 char* name = type_name_no_tag (type);
874 /* FIXME: shouldn't we separately check the TYPE_NAME and the
875 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
876 as appropriate? (this code was written before TYPE_NAME and
877 TYPE_TAG_NAME were separate). */
878 struct symbol *sym;
879 if (name == NULL)
880 {
881 complain (&stub_noname_complaint);
882 return;
883 }
884 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
885 (struct symtab **) NULL);
886 if (sym)
887 {
888 memcpy ((char *)type,
889 (char *)SYMBOL_TYPE(sym),
890 sizeof (struct type));
891 }
892 }
893
894 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
895 {
896 struct type *range_type;
897
898 check_stub_type (TYPE_TARGET_TYPE (type));
899 if (!(TYPE_FLAGS (TYPE_TARGET_TYPE (type)) & TYPE_FLAG_STUB)
900 && TYPE_CODE (type) == TYPE_CODE_ARRAY
901 && TYPE_NFIELDS (type) == 1
902 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
903 == TYPE_CODE_RANGE))
904 {
905 /* Now recompute the length of the array type, based on its
906 number of elements and the target type's length. */
907 TYPE_LENGTH (type) =
908 ((TYPE_FIELD_BITPOS (range_type, 1)
909 - TYPE_FIELD_BITPOS (range_type, 0)
910 + 1)
911 * TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
912 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
913 }
914 }
915 }
916
917 /* Ugly hack to convert method stubs into method types.
918
919 He ain't kiddin'. This demangles the name of the method into a string
920 including argument types, parses out each argument type, generates
921 a string casting a zero to that type, evaluates the string, and stuffs
922 the resulting type into an argtype vector!!! Then it knows the type
923 of the whole function (including argument types for overloading),
924 which info used to be in the stab's but was removed to hack back
925 the space required for them. */
926
927 void
928 check_stub_method (type, i, j)
929 struct type *type;
930 int i;
931 int j;
932 {
933 struct fn_field *f;
934 char *mangled_name = gdb_mangle_name (type, i, j);
935 char *demangled_name = cplus_demangle (mangled_name,
936 DMGL_PARAMS | DMGL_ANSI);
937 char *argtypetext, *p;
938 int depth = 0, argcount = 1;
939 struct type **argtypes;
940 struct type *mtype;
941
942 if (demangled_name == NULL)
943 {
944 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
945 }
946
947 /* Now, read in the parameters that define this type. */
948 argtypetext = strchr (demangled_name, '(') + 1;
949 p = argtypetext;
950 while (*p)
951 {
952 if (*p == '(')
953 {
954 depth += 1;
955 }
956 else if (*p == ')')
957 {
958 depth -= 1;
959 }
960 else if (*p == ',' && depth == 0)
961 {
962 argcount += 1;
963 }
964
965 p += 1;
966 }
967
968 /* We need two more slots: one for the THIS pointer, and one for the
969 NULL [...] or void [end of arglist]. */
970
971 argtypes = (struct type **)
972 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
973 p = argtypetext;
974 argtypes[0] = lookup_pointer_type (type);
975 argcount = 1;
976
977 if (*p != ')') /* () means no args, skip while */
978 {
979 depth = 0;
980 while (*p)
981 {
982 if (depth <= 0 && (*p == ',' || *p == ')'))
983 {
984 argtypes[argcount] =
985 parse_and_eval_type (argtypetext, p - argtypetext);
986 argcount += 1;
987 argtypetext = p + 1;
988 }
989
990 if (*p == '(')
991 {
992 depth += 1;
993 }
994 else if (*p == ')')
995 {
996 depth -= 1;
997 }
998
999 p += 1;
1000 }
1001 }
1002
1003 if (p[-2] != '.') /* Not '...' */
1004 {
1005 argtypes[argcount] = builtin_type_void; /* List terminator */
1006 }
1007 else
1008 {
1009 argtypes[argcount] = NULL; /* Ellist terminator */
1010 }
1011
1012 free (demangled_name);
1013
1014 f = TYPE_FN_FIELDLIST1 (type, i);
1015 TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name;
1016
1017 /* Now update the old "stub" type into a real type. */
1018 mtype = TYPE_FN_FIELD_TYPE (f, j);
1019 TYPE_DOMAIN_TYPE (mtype) = type;
1020 TYPE_ARG_TYPES (mtype) = argtypes;
1021 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1022 TYPE_FN_FIELD_STUB (f, j) = 0;
1023 }
1024
1025 const struct cplus_struct_type cplus_struct_default;
1026
1027 void
1028 allocate_cplus_struct_type (type)
1029 struct type *type;
1030 {
1031 if (!HAVE_CPLUS_STRUCT (type))
1032 {
1033 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1034 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1035 *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
1036 }
1037 }
1038
1039 /* Helper function to initialize the standard scalar types.
1040
1041 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1042 of the string pointed to by name in the type_obstack for that objfile,
1043 and initialize the type name to that copy. There are places (mipsread.c
1044 in particular, where init_type is called with a NULL value for NAME). */
1045
1046 struct type *
1047 init_type (code, length, flags, name, objfile)
1048 enum type_code code;
1049 int length;
1050 int flags;
1051 char *name;
1052 struct objfile *objfile;
1053 {
1054 register struct type *type;
1055
1056 type = alloc_type (objfile);
1057 TYPE_CODE (type) = code;
1058 TYPE_LENGTH (type) = length;
1059 TYPE_FLAGS (type) |= flags;
1060 if ((name != NULL) && (objfile != NULL))
1061 {
1062 TYPE_NAME (type) =
1063 obsavestring (name, strlen (name), &objfile -> type_obstack);
1064 }
1065 else
1066 {
1067 TYPE_NAME (type) = name;
1068 }
1069
1070 /* C++ fancies. */
1071
1072 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1073 {
1074 INIT_CPLUS_SPECIFIC (type);
1075 }
1076 return (type);
1077 }
1078
1079 /* Look up a fundamental type for the specified objfile.
1080 May need to construct such a type if this is the first use.
1081
1082 Some object file formats (ELF, COFF, etc) do not define fundamental
1083 types such as "int" or "double". Others (stabs for example), do
1084 define fundamental types.
1085
1086 For the formats which don't provide fundamental types, gdb can create
1087 such types, using defaults reasonable for the current language and
1088 the current target machine.
1089
1090 NOTE: This routine is obsolescent. Each debugging format reader
1091 should manage it's own fundamental types, either creating them from
1092 suitable defaults or reading them from the debugging information,
1093 whichever is appropriate. The DWARF reader has already been
1094 fixed to do this. Once the other readers are fixed, this routine
1095 will go away. Also note that fundamental types should be managed
1096 on a compilation unit basis in a multi-language environment, not
1097 on a linkage unit basis as is done here. */
1098
1099
1100 struct type *
1101 lookup_fundamental_type (objfile, typeid)
1102 struct objfile *objfile;
1103 int typeid;
1104 {
1105 register struct type **typep;
1106 register int nbytes;
1107
1108 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1109 {
1110 error ("internal error - invalid fundamental type id %d", typeid);
1111 }
1112
1113 /* If this is the first time we need a fundamental type for this objfile
1114 then we need to initialize the vector of type pointers. */
1115
1116 if (objfile -> fundamental_types == NULL)
1117 {
1118 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1119 objfile -> fundamental_types = (struct type **)
1120 obstack_alloc (&objfile -> type_obstack, nbytes);
1121 memset ((char *) objfile -> fundamental_types, 0, nbytes);
1122 }
1123
1124 /* Look for this particular type in the fundamental type vector. If one is
1125 not found, create and install one appropriate for the current language. */
1126
1127 typep = objfile -> fundamental_types + typeid;
1128 if (*typep == NULL)
1129 {
1130 *typep = create_fundamental_type (objfile, typeid);
1131 }
1132
1133 return (*typep);
1134 }
1135
1136 #if MAINTENANCE_CMDS
1137
1138 static void
1139 print_bit_vector (bits, nbits)
1140 B_TYPE *bits;
1141 int nbits;
1142 {
1143 int bitno;
1144
1145 for (bitno = 0; bitno < nbits; bitno++)
1146 {
1147 if ((bitno % 8) == 0)
1148 {
1149 puts_filtered (" ");
1150 }
1151 if (B_TST (bits, bitno))
1152 {
1153 printf_filtered ("1");
1154 }
1155 else
1156 {
1157 printf_filtered ("0");
1158 }
1159 }
1160 }
1161
1162 /* The args list is a strange beast. It is either terminated by a NULL
1163 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1164 type for normal fixed argcount functions. (FIXME someday)
1165 Also note the first arg should be the "this" pointer, we may not want to
1166 include it since we may get into a infinitely recursive situation. */
1167
1168 static void
1169 print_arg_types (args, spaces)
1170 struct type **args;
1171 int spaces;
1172 {
1173 if (args != NULL)
1174 {
1175 while (*args != NULL)
1176 {
1177 recursive_dump_type (*args, spaces + 2);
1178 if ((*args++) -> code == TYPE_CODE_VOID)
1179 {
1180 break;
1181 }
1182 }
1183 }
1184 }
1185
1186 static void
1187 dump_fn_fieldlists (type, spaces)
1188 struct type *type;
1189 int spaces;
1190 {
1191 int method_idx;
1192 int overload_idx;
1193 struct fn_field *f;
1194
1195 printfi_filtered (spaces, "fn_fieldlists 0x%lx\n",
1196 (unsigned long) TYPE_FN_FIELDLISTS (type));
1197 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
1198 {
1199 f = TYPE_FN_FIELDLIST1 (type, method_idx);
1200 printfi_filtered (spaces + 2, "[%d] name '%s' (0x%lx) length %d\n",
1201 method_idx,
1202 TYPE_FN_FIELDLIST_NAME (type, method_idx),
1203 (unsigned long) TYPE_FN_FIELDLIST_NAME (type, method_idx),
1204 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
1205 for (overload_idx = 0;
1206 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
1207 overload_idx++)
1208 {
1209 printfi_filtered (spaces + 4, "[%d] physname '%s' (0x%lx)\n",
1210 overload_idx,
1211 TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
1212 (unsigned long) TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
1213 printfi_filtered (spaces + 8, "type 0x%lx\n",
1214 (unsigned long) TYPE_FN_FIELD_TYPE (f, overload_idx));
1215 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
1216 spaces + 8 + 2);
1217 printfi_filtered (spaces + 8, "args 0x%lx\n",
1218 (unsigned long) TYPE_FN_FIELD_ARGS (f, overload_idx));
1219 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
1220 printfi_filtered (spaces + 8, "fcontext 0x%lx\n",
1221 (unsigned long) TYPE_FN_FIELD_FCONTEXT (f, overload_idx));
1222 printfi_filtered (spaces + 8, "is_const %d\n",
1223 TYPE_FN_FIELD_CONST (f, overload_idx));
1224 printfi_filtered (spaces + 8, "is_volatile %d\n",
1225 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
1226 printfi_filtered (spaces + 8, "is_private %d\n",
1227 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
1228 printfi_filtered (spaces + 8, "is_protected %d\n",
1229 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
1230 printfi_filtered (spaces + 8, "is_stub %d\n",
1231 TYPE_FN_FIELD_STUB (f, overload_idx));
1232 printfi_filtered (spaces + 8, "voffset %u\n",
1233 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
1234 }
1235 }
1236 }
1237
1238 static void
1239 print_cplus_stuff (type, spaces)
1240 struct type *type;
1241 int spaces;
1242 {
1243 printfi_filtered (spaces, "n_baseclasses %d\n",
1244 TYPE_N_BASECLASSES (type));
1245 printfi_filtered (spaces, "nfn_fields %d\n",
1246 TYPE_NFN_FIELDS (type));
1247 printfi_filtered (spaces, "nfn_fields_total %d\n",
1248 TYPE_NFN_FIELDS_TOTAL (type));
1249 if (TYPE_N_BASECLASSES (type) > 0)
1250 {
1251 printfi_filtered (spaces, "virtual_field_bits (%d bits at *0x%lx)",
1252 TYPE_N_BASECLASSES (type),
1253 (unsigned long) TYPE_FIELD_VIRTUAL_BITS (type));
1254 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
1255 TYPE_N_BASECLASSES (type));
1256 puts_filtered ("\n");
1257 }
1258 if (TYPE_NFIELDS (type) > 0)
1259 {
1260 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
1261 {
1262 printfi_filtered (spaces, "private_field_bits (%d bits at *0x%lx)",
1263 TYPE_NFIELDS (type),
1264 (unsigned long) TYPE_FIELD_PRIVATE_BITS (type));
1265 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
1266 TYPE_NFIELDS (type));
1267 puts_filtered ("\n");
1268 }
1269 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
1270 {
1271 printfi_filtered (spaces, "protected_field_bits (%d bits at *0x%lx)",
1272 TYPE_NFIELDS (type),
1273 (unsigned long) TYPE_FIELD_PROTECTED_BITS (type));
1274 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
1275 TYPE_NFIELDS (type));
1276 puts_filtered ("\n");
1277 }
1278 }
1279 if (TYPE_NFN_FIELDS (type) > 0)
1280 {
1281 dump_fn_fieldlists (type, spaces);
1282 }
1283 }
1284
1285 void
1286 recursive_dump_type (type, spaces)
1287 struct type *type;
1288 int spaces;
1289 {
1290 int idx;
1291
1292 printfi_filtered (spaces, "type node 0x%lx\n", (unsigned long)type);
1293 printfi_filtered (spaces, "name '%s' (0x%lx)\n",
1294 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>",
1295 (unsigned long)TYPE_NAME (type));
1296 if (TYPE_TAG_NAME (type) != NULL)
1297 printfi_filtered (spaces, "tagname '%s' (0x%lx)\n",
1298 TYPE_TAG_NAME (type),
1299 (unsigned long)TYPE_TAG_NAME (type));
1300 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
1301 switch (TYPE_CODE (type))
1302 {
1303 case TYPE_CODE_UNDEF:
1304 printf_filtered ("(TYPE_CODE_UNDEF)");
1305 break;
1306 case TYPE_CODE_PTR:
1307 printf_filtered ("(TYPE_CODE_PTR)");
1308 break;
1309 case TYPE_CODE_ARRAY:
1310 printf_filtered ("(TYPE_CODE_ARRAY)");
1311 break;
1312 case TYPE_CODE_STRUCT:
1313 printf_filtered ("(TYPE_CODE_STRUCT)");
1314 break;
1315 case TYPE_CODE_UNION:
1316 printf_filtered ("(TYPE_CODE_UNION)");
1317 break;
1318 case TYPE_CODE_ENUM:
1319 printf_filtered ("(TYPE_CODE_ENUM)");
1320 break;
1321 case TYPE_CODE_FUNC:
1322 printf_filtered ("(TYPE_CODE_FUNC)");
1323 break;
1324 case TYPE_CODE_INT:
1325 printf_filtered ("(TYPE_CODE_INT)");
1326 break;
1327 case TYPE_CODE_FLT:
1328 printf_filtered ("(TYPE_CODE_FLT)");
1329 break;
1330 case TYPE_CODE_VOID:
1331 printf_filtered ("(TYPE_CODE_VOID)");
1332 break;
1333 case TYPE_CODE_SET:
1334 printf_filtered ("(TYPE_CODE_SET)");
1335 break;
1336 case TYPE_CODE_RANGE:
1337 printf_filtered ("(TYPE_CODE_RANGE)");
1338 break;
1339 case TYPE_CODE_STRING:
1340 printf_filtered ("(TYPE_CODE_STRING)");
1341 break;
1342 case TYPE_CODE_ERROR:
1343 printf_filtered ("(TYPE_CODE_ERROR)");
1344 break;
1345 case TYPE_CODE_MEMBER:
1346 printf_filtered ("(TYPE_CODE_MEMBER)");
1347 break;
1348 case TYPE_CODE_METHOD:
1349 printf_filtered ("(TYPE_CODE_METHOD)");
1350 break;
1351 case TYPE_CODE_REF:
1352 printf_filtered ("(TYPE_CODE_REF)");
1353 break;
1354 case TYPE_CODE_CHAR:
1355 printf_filtered ("(TYPE_CODE_CHAR)");
1356 break;
1357 case TYPE_CODE_BOOL:
1358 printf_filtered ("(TYPE_CODE_BOOL)");
1359 break;
1360 default:
1361 printf_filtered ("(UNKNOWN TYPE CODE)");
1362 break;
1363 }
1364 puts_filtered ("\n");
1365 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
1366 printfi_filtered (spaces, "objfile 0x%lx\n",
1367 (unsigned long) TYPE_OBJFILE (type));
1368 printfi_filtered (spaces, "target_type 0x%lx\n",
1369 (unsigned long) TYPE_TARGET_TYPE (type));
1370 if (TYPE_TARGET_TYPE (type) != NULL)
1371 {
1372 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
1373 }
1374 printfi_filtered (spaces, "pointer_type 0x%lx\n",
1375 (unsigned long) TYPE_POINTER_TYPE (type));
1376 printfi_filtered (spaces, "reference_type 0x%lx\n",
1377 (unsigned long) TYPE_REFERENCE_TYPE (type));
1378 printfi_filtered (spaces, "function_type 0x%lx\n",
1379 (unsigned long) TYPE_FUNCTION_TYPE (type));
1380 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
1381 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
1382 {
1383 puts_filtered (" TYPE_FLAG_UNSIGNED");
1384 }
1385 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1386 {
1387 puts_filtered (" TYPE_FLAG_STUB");
1388 }
1389 puts_filtered ("\n");
1390 printfi_filtered (spaces, "nfields %d 0x%lx\n", TYPE_NFIELDS (type),
1391 (unsigned long) TYPE_FIELDS (type));
1392 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
1393 {
1394 printfi_filtered (spaces + 2,
1395 "[%d] bitpos %d bitsize %d type 0x%lx name '%s' (0x%lx)\n",
1396 idx, TYPE_FIELD_BITPOS (type, idx),
1397 TYPE_FIELD_BITSIZE (type, idx),
1398 (unsigned long) TYPE_FIELD_TYPE (type, idx),
1399 TYPE_FIELD_NAME (type, idx) != NULL
1400 ? TYPE_FIELD_NAME (type, idx)
1401 : "<NULL>",
1402 (unsigned long) TYPE_FIELD_NAME (type, idx));
1403 if (TYPE_FIELD_TYPE (type, idx) != NULL)
1404 {
1405 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
1406 }
1407 }
1408 printfi_filtered (spaces, "vptr_basetype 0x%lx\n",
1409 (unsigned long) TYPE_VPTR_BASETYPE (type));
1410 if (TYPE_VPTR_BASETYPE (type) != NULL)
1411 {
1412 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
1413 }
1414 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
1415 switch (TYPE_CODE (type))
1416 {
1417 case TYPE_CODE_METHOD:
1418 case TYPE_CODE_FUNC:
1419 printfi_filtered (spaces, "arg_types 0x%lx\n",
1420 (unsigned long) TYPE_ARG_TYPES (type));
1421 print_arg_types (TYPE_ARG_TYPES (type), spaces);
1422 break;
1423
1424 case TYPE_CODE_STRUCT:
1425 printfi_filtered (spaces, "cplus_stuff 0x%lx\n",
1426 (unsigned long) TYPE_CPLUS_SPECIFIC (type));
1427 print_cplus_stuff (type, spaces);
1428 break;
1429
1430 default:
1431 /* We have to pick one of the union types to be able print and test
1432 the value. Pick cplus_struct_type, even though we know it isn't
1433 any particular one. */
1434 printfi_filtered (spaces, "type_specific 0x%lx",
1435 (unsigned long) TYPE_CPLUS_SPECIFIC (type));
1436 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
1437 {
1438 printf_filtered (" (unknown data form)");
1439 }
1440 printf_filtered ("\n");
1441 break;
1442
1443 }
1444 }
1445
1446 #endif /* MAINTENANCE_CMDS */
1447
1448 void
1449 _initialize_gdbtypes ()
1450 {
1451 builtin_type_void =
1452 init_type (TYPE_CODE_VOID, 1,
1453 0,
1454 "void", (struct objfile *) NULL);
1455 builtin_type_char =
1456 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1457 0,
1458 "char", (struct objfile *) NULL);
1459 builtin_type_signed_char =
1460 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1461 0,
1462 "signed char", (struct objfile *) NULL);
1463 builtin_type_unsigned_char =
1464 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1465 TYPE_FLAG_UNSIGNED,
1466 "unsigned char", (struct objfile *) NULL);
1467 builtin_type_short =
1468 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1469 0,
1470 "short", (struct objfile *) NULL);
1471 builtin_type_unsigned_short =
1472 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1473 TYPE_FLAG_UNSIGNED,
1474 "unsigned short", (struct objfile *) NULL);
1475 builtin_type_int =
1476 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1477 0,
1478 "int", (struct objfile *) NULL);
1479 builtin_type_unsigned_int =
1480 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1481 TYPE_FLAG_UNSIGNED,
1482 "unsigned int", (struct objfile *) NULL);
1483 builtin_type_long =
1484 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1485 0,
1486 "long", (struct objfile *) NULL);
1487 builtin_type_unsigned_long =
1488 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1489 TYPE_FLAG_UNSIGNED,
1490 "unsigned long", (struct objfile *) NULL);
1491 builtin_type_long_long =
1492 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1493 0,
1494 "long long", (struct objfile *) NULL);
1495 builtin_type_unsigned_long_long =
1496 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1497 TYPE_FLAG_UNSIGNED,
1498 "unsigned long long", (struct objfile *) NULL);
1499 builtin_type_float =
1500 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1501 0,
1502 "float", (struct objfile *) NULL);
1503 builtin_type_double =
1504 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1505 0,
1506 "double", (struct objfile *) NULL);
1507 builtin_type_long_double =
1508 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
1509 0,
1510 "long double", (struct objfile *) NULL);
1511 builtin_type_complex =
1512 init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
1513 0,
1514 "complex", (struct objfile *) NULL);
1515 builtin_type_double_complex =
1516 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
1517 0,
1518 "double complex", (struct objfile *) NULL);
1519 builtin_type_string =
1520 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1521 0,
1522 "string", (struct objfile *) NULL);
1523 }
This page took 0.059544 seconds and 5 git commands to generate.