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