]>
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" | |
32 | ||
33 | /* Alloc a new type structure and fill it with some defaults. If | |
34 | OBJFILE is non-NULL, then allocate the space for the type structure | |
35 | in that objfile's type_obstack. */ | |
36 | ||
37 | struct type * | |
38 | alloc_type (objfile) | |
39 | struct objfile *objfile; | |
40 | { | |
41 | register struct type *type; | |
42 | ||
43 | /* Alloc the structure and start off with all fields zeroed. */ | |
44 | ||
45 | if (objfile == NULL) | |
46 | { | |
47 | type = (struct type *) xmalloc (sizeof (struct type)); | |
48 | } | |
49 | else | |
50 | { | |
51 | type = (struct type *) obstack_alloc (&objfile -> type_obstack, | |
52 | sizeof (struct type)); | |
53 | } | |
93fe4e33 | 54 | (void) memset ((char *)type, 0, sizeof (struct type)); |
1ab3bf1b JG |
55 | |
56 | /* Initialize the fields that might not be zero. */ | |
57 | ||
58 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
59 | TYPE_OBJFILE (type) = objfile; | |
60 | TYPE_VPTR_FIELDNO (type) = -1; | |
61 | ||
62 | return (type); | |
63 | } | |
64 | ||
65 | /* Given a type TYPE, return a type of pointers to that type. | |
66 | May need to construct such a type if this is the first use. */ | |
67 | ||
68 | struct type * | |
69 | lookup_pointer_type (type) | |
70 | struct type *type; | |
71 | { | |
72 | register struct type *ptype; | |
73 | ||
74 | if ((ptype = TYPE_POINTER_TYPE (type)) == NULL) | |
75 | { | |
76 | /* This is the first time anyone wanted a pointer to a TYPE. */ | |
77 | ||
78 | ptype = alloc_type (TYPE_OBJFILE (type)); | |
79 | TYPE_TARGET_TYPE (ptype) = type; | |
80 | TYPE_POINTER_TYPE (type) = ptype; | |
81 | ||
82 | /* We assume the machine has only one representation for pointers! */ | |
1ab3bf1b | 83 | |
96743d3c | 84 | TYPE_LENGTH (ptype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; |
1ab3bf1b JG |
85 | TYPE_CODE (ptype) = TYPE_CODE_PTR; |
86 | ||
96743d3c SC |
87 | /* pointers are unsigned */ |
88 | TYPE_FLAGS(ptype) |= TYPE_FLAG_UNSIGNED; | |
89 | ||
1ab3bf1b JG |
90 | } |
91 | return (ptype); | |
92 | } | |
93 | ||
94 | struct type * | |
95 | lookup_reference_type (type) | |
96 | struct type *type; | |
97 | { | |
98 | register struct type *rtype; | |
99 | ||
100 | if ((rtype = TYPE_REFERENCE_TYPE (type)) == NULL) | |
101 | { | |
102 | /* This is the first time anyone wanted a pointer to a TYPE. */ | |
103 | ||
104 | rtype = alloc_type (TYPE_OBJFILE (type)); | |
105 | TYPE_TARGET_TYPE (rtype) = type; | |
106 | TYPE_REFERENCE_TYPE (type) = rtype; | |
107 | ||
108 | /* We assume the machine has only one representation for pointers! */ | |
109 | /* FIXME: This confuses host<->target data representations, and is a | |
110 | poor assumption besides. */ | |
111 | ||
112 | TYPE_LENGTH (rtype) = sizeof (char *); | |
113 | TYPE_CODE (rtype) = TYPE_CODE_REF; | |
114 | ||
115 | } | |
116 | return (rtype); | |
117 | } | |
118 | ||
119 | /* Given a type TYPE, return a type of functions that return that type. | |
120 | May need to construct such a type if this is the first use. */ | |
121 | ||
122 | struct type * | |
123 | lookup_function_type (type) | |
124 | struct type *type; | |
125 | { | |
126 | register struct type *ptype; | |
127 | ||
128 | if ((ptype = TYPE_FUNCTION_TYPE (type)) == NULL) | |
129 | { | |
130 | /* This is the first time anyone wanted a function returning a TYPE. */ | |
131 | ||
132 | ptype = alloc_type (TYPE_OBJFILE (type)); | |
133 | TYPE_TARGET_TYPE (ptype) = type; | |
134 | TYPE_FUNCTION_TYPE (type) = ptype; | |
135 | ||
136 | TYPE_LENGTH (ptype) = 1; | |
137 | TYPE_CODE (ptype) = TYPE_CODE_FUNC; | |
138 | } | |
139 | return (ptype); | |
140 | } | |
141 | ||
142 | /* Implement direct support for MEMBER_TYPE in GNU C++. | |
143 | May need to construct such a type if this is the first use. | |
144 | The TYPE is the type of the member. The DOMAIN is the type | |
145 | of the aggregate that the member belongs to. */ | |
146 | ||
147 | struct type * | |
148 | lookup_member_type (type, domain) | |
149 | struct type *type; | |
150 | struct type *domain; | |
151 | { | |
152 | register struct type *mtype; | |
153 | ||
154 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
155 | smash_to_member_type (mtype, domain, type); | |
156 | return (mtype); | |
157 | } | |
158 | ||
159 | /* Allocate a stub method whose return type is TYPE. | |
160 | This apparently happens for speed of symbol reading, since parsing | |
161 | out the arguments to the method is cpu-intensive, the way we are doing | |
162 | it. So, we will fill in arguments later. | |
163 | This always returns a fresh type. */ | |
164 | ||
165 | struct type * | |
166 | allocate_stub_method (type) | |
167 | struct type *type; | |
168 | { | |
169 | struct type *mtype; | |
170 | ||
171 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
172 | TYPE_TARGET_TYPE (mtype) = type; | |
173 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
174 | /* _ARG_TYPES (mtype) = unknown yet */ | |
175 | TYPE_FLAGS (mtype) = TYPE_FLAG_STUB; | |
176 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; | |
177 | TYPE_LENGTH (mtype) = 1; | |
178 | return (mtype); | |
179 | } | |
180 | ||
181 | /* Create an array type. Elements will be of type TYPE, and there will | |
182 | be NUM of them. | |
183 | ||
184 | Eventually this should be extended to take two more arguments which | |
185 | specify the bounds of the array and the type of the index. | |
186 | It should also be changed to be a "lookup" function, with the | |
187 | appropriate data structures added to the type field. | |
188 | Then read array type should call here. */ | |
189 | ||
190 | struct type * | |
191 | create_array_type (element_type, number) | |
192 | struct type *element_type; | |
193 | int number; | |
194 | { | |
195 | struct type *result_type; | |
196 | struct type *range_type; | |
197 | ||
198 | result_type = alloc_type (TYPE_OBJFILE (element_type)); | |
199 | ||
200 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; | |
201 | TYPE_TARGET_TYPE (result_type) = element_type; | |
202 | TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type); | |
203 | TYPE_NFIELDS (result_type) = 1; | |
204 | TYPE_FIELDS (result_type) = (struct field *) | |
205 | obstack_alloc (&TYPE_OBJFILE (result_type) -> type_obstack, | |
206 | sizeof (struct field)); | |
207 | ||
208 | { | |
209 | /* Create range type. */ | |
210 | range_type = alloc_type (TYPE_OBJFILE (result_type)); | |
211 | TYPE_CODE (range_type) = TYPE_CODE_RANGE; | |
212 | TYPE_TARGET_TYPE (range_type) = builtin_type_int; /* FIXME */ | |
213 | ||
214 | /* This should never be needed. */ | |
215 | TYPE_LENGTH (range_type) = sizeof (int); | |
216 | ||
217 | TYPE_NFIELDS (range_type) = 2; | |
218 | TYPE_FIELDS (range_type) = (struct field *) | |
219 | obstack_alloc (&TYPE_OBJFILE (range_type) -> type_obstack, | |
220 | 2 * sizeof (struct field)); | |
221 | TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */ | |
222 | TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */ | |
223 | TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */ | |
224 | TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */ | |
225 | } | |
226 | TYPE_FIELD_TYPE(result_type,0)=range_type; | |
227 | TYPE_VPTR_FIELDNO (result_type) = -1; | |
228 | ||
229 | return (result_type); | |
230 | } | |
231 | ||
232 | ||
233 | /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. | |
234 | A MEMBER is a wierd thing -- it amounts to a typed offset into | |
235 | a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't | |
236 | include the offset (that's the value of the MEMBER itself), but does | |
237 | include the structure type into which it points (for some reason). | |
238 | ||
239 | FIXME: When "smashing" the type, we preserve the objfile that the | |
240 | old type pointed to, since we aren't changing where the type is actually | |
241 | allocated. If the two types aren't associated with the same objfile, | |
242 | then we are in deep-s**t anyway... */ | |
243 | ||
244 | void | |
245 | smash_to_member_type (type, domain, to_type) | |
246 | struct type *type; | |
247 | struct type *domain; | |
248 | struct type *to_type; | |
249 | { | |
250 | struct objfile *objfile; | |
251 | ||
252 | objfile = TYPE_OBJFILE (type); | |
253 | ||
93fe4e33 | 254 | (void) memset ((char *)type, 0, sizeof (struct type)); |
1ab3bf1b JG |
255 | TYPE_OBJFILE (type) = objfile; |
256 | TYPE_TARGET_TYPE (type) = to_type; | |
257 | TYPE_DOMAIN_TYPE (type) = domain; | |
258 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
259 | TYPE_CODE (type) = TYPE_CODE_MEMBER; | |
260 | } | |
261 | ||
262 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. | |
263 | METHOD just means `function that gets an extra "this" argument'. | |
264 | ||
265 | FIXME: When "smashing" the type, we preserve the objfile that the | |
266 | old type pointed to, since we aren't changing where the type is actually | |
267 | allocated. If the two types aren't associated with the same objfile, | |
268 | then we are in deep-s**t anyway... */ | |
269 | ||
270 | void | |
271 | smash_to_method_type (type, domain, to_type, args) | |
272 | struct type *type; | |
273 | struct type *domain; | |
274 | struct type *to_type; | |
275 | struct type **args; | |
276 | { | |
277 | struct objfile *objfile; | |
278 | ||
279 | objfile = TYPE_OBJFILE (type); | |
280 | ||
93fe4e33 | 281 | (void) memset ((char *)type, 0, sizeof (struct type)); |
1ab3bf1b JG |
282 | TYPE_OBJFILE (type) = objfile; |
283 | TYPE_TARGET_TYPE (type) = to_type; | |
284 | TYPE_DOMAIN_TYPE (type) = domain; | |
285 | TYPE_ARG_TYPES (type) = args; | |
286 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
287 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
288 | } | |
289 | ||
290 | /* Return a typename for a struct/union/enum type | |
291 | without the tag qualifier. If the type has a NULL name, | |
292 | NULL is returned. */ | |
293 | ||
294 | char * | |
295 | type_name_no_tag (type) | |
296 | register const struct type *type; | |
297 | { | |
298 | register char *name; | |
299 | ||
300 | if ((name = TYPE_NAME (type)) != NULL) | |
301 | { | |
302 | switch (TYPE_CODE (type)) | |
303 | { | |
304 | case TYPE_CODE_STRUCT: | |
305 | if(!strncmp (name, "struct ", 7)) | |
306 | { | |
307 | name += 7; | |
308 | } | |
309 | break; | |
310 | case TYPE_CODE_UNION: | |
311 | if(!strncmp (name, "union ", 6)) | |
312 | { | |
313 | name += 6; | |
314 | } | |
315 | break; | |
316 | case TYPE_CODE_ENUM: | |
317 | if(!strncmp (name, "enum ", 5)) | |
318 | { | |
319 | name += 5; | |
320 | } | |
321 | break; | |
322 | } | |
323 | } | |
324 | return (name); | |
325 | } | |
326 | ||
327 | /* Lookup a primitive type named NAME. | |
328 | Return zero if NAME is not a primitive type.*/ | |
329 | ||
330 | struct type * | |
331 | lookup_primitive_typename (name) | |
332 | char *name; | |
333 | { | |
334 | struct type ** const *p; | |
335 | ||
336 | for (p = current_language -> la_builtin_type_vector; *p != NULL; p++) | |
337 | { | |
338 | if (!strcmp ((**p) -> name, name)) | |
339 | { | |
340 | return (**p); | |
341 | } | |
342 | } | |
343 | return (NULL); | |
344 | } | |
345 | ||
346 | /* Lookup a typedef or primitive type named NAME, | |
347 | visible in lexical block BLOCK. | |
348 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ | |
349 | ||
350 | struct type * | |
351 | lookup_typename (name, block, noerr) | |
352 | char *name; | |
353 | struct block *block; | |
354 | int noerr; | |
355 | { | |
356 | register struct symbol *sym; | |
357 | register struct type *tmp; | |
358 | ||
359 | sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); | |
360 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) | |
361 | { | |
362 | tmp = lookup_primitive_typename (name); | |
363 | if (tmp) | |
364 | { | |
365 | return (tmp); | |
366 | } | |
367 | else if (!tmp && noerr) | |
368 | { | |
369 | return (NULL); | |
370 | } | |
371 | else | |
372 | { | |
373 | error ("No type named %s.", name); | |
374 | } | |
375 | } | |
376 | return (SYMBOL_TYPE (sym)); | |
377 | } | |
378 | ||
379 | struct type * | |
380 | lookup_unsigned_typename (name) | |
381 | char *name; | |
382 | { | |
383 | char *uns = alloca (strlen (name) + 10); | |
384 | ||
385 | strcpy (uns, "unsigned "); | |
386 | strcpy (uns + 9, name); | |
387 | return (lookup_typename (uns, (struct block *) NULL, 0)); | |
388 | } | |
389 | ||
390 | /* Lookup a structure type named "struct NAME", | |
391 | visible in lexical block BLOCK. */ | |
392 | ||
393 | struct type * | |
394 | lookup_struct (name, block) | |
395 | char *name; | |
396 | struct block *block; | |
397 | { | |
398 | register struct symbol *sym; | |
399 | ||
400 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
401 | (struct symtab **) NULL); | |
402 | ||
403 | if (sym == NULL) | |
404 | { | |
405 | error ("No struct type named %s.", name); | |
406 | } | |
407 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
408 | { | |
409 | error ("This context has class, union or enum %s, not a struct.", name); | |
410 | } | |
411 | return (SYMBOL_TYPE (sym)); | |
412 | } | |
413 | ||
414 | /* Lookup a union type named "union NAME", | |
415 | visible in lexical block BLOCK. */ | |
416 | ||
417 | struct type * | |
418 | lookup_union (name, block) | |
419 | char *name; | |
420 | struct block *block; | |
421 | { | |
422 | register struct symbol *sym; | |
423 | ||
424 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
425 | (struct symtab **) NULL); | |
426 | ||
427 | if (sym == NULL) | |
428 | { | |
429 | error ("No union type named %s.", name); | |
430 | } | |
431 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION) | |
432 | { | |
433 | error ("This context has class, struct or enum %s, not a union.", name); | |
434 | } | |
435 | return (SYMBOL_TYPE (sym)); | |
436 | } | |
437 | ||
438 | /* Lookup an enum type named "enum NAME", | |
439 | visible in lexical block BLOCK. */ | |
440 | ||
441 | struct type * | |
442 | lookup_enum (name, block) | |
443 | char *name; | |
444 | struct block *block; | |
445 | { | |
446 | register struct symbol *sym; | |
447 | ||
448 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
449 | (struct symtab **) NULL); | |
450 | if (sym == NULL) | |
451 | { | |
452 | error ("No enum type named %s.", name); | |
453 | } | |
454 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
455 | { | |
456 | error ("This context has class, struct or union %s, not an enum.", name); | |
457 | } | |
458 | return (SYMBOL_TYPE (sym)); | |
459 | } | |
460 | ||
461 | /* Lookup a template type named "template NAME<TYPE>", | |
462 | visible in lexical block BLOCK. */ | |
463 | ||
464 | struct type * | |
465 | lookup_template_type (name, type, block) | |
466 | char *name; | |
467 | struct type *type; | |
468 | struct block *block; | |
469 | { | |
470 | struct symbol *sym; | |
471 | char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4); | |
472 | strcpy (nam, name); | |
473 | strcat (nam, "<"); | |
474 | strcat (nam, type->name); | |
475 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ | |
476 | ||
477 | sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL); | |
478 | ||
479 | if (sym == NULL) | |
480 | { | |
481 | error ("No template type named %s.", name); | |
482 | } | |
483 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
484 | { | |
485 | error ("This context has class, union or enum %s, not a struct.", name); | |
486 | } | |
487 | return (SYMBOL_TYPE (sym)); | |
488 | } | |
489 | ||
490 | /* Given a type TYPE, lookup the type of the component of type named | |
491 | NAME. | |
492 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ | |
493 | ||
494 | struct type * | |
495 | lookup_struct_elt_type (type, name, noerr) | |
496 | struct type *type; | |
497 | char *name; | |
498 | int noerr; | |
499 | { | |
500 | int i; | |
501 | ||
502 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && | |
503 | TYPE_CODE (type) != TYPE_CODE_UNION) | |
504 | { | |
505 | target_terminal_ours (); | |
506 | fflush (stdout); | |
507 | fprintf (stderr, "Type "); | |
508 | type_print (type, "", stderr, -1); | |
509 | error (" is not a structure or union type."); | |
510 | } | |
511 | ||
512 | check_stub_type (type); | |
513 | ||
514 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
515 | { | |
516 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
517 | ||
518 | if (t_field_name && !strcmp (t_field_name, name)) | |
519 | { | |
520 | return TYPE_FIELD_TYPE (type, i); | |
521 | } | |
522 | } | |
523 | ||
524 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
525 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
526 | { | |
527 | struct type *t; | |
528 | ||
529 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 0); | |
530 | if (t != NULL) | |
531 | { | |
532 | return t; | |
533 | } | |
534 | } | |
535 | ||
536 | if (noerr) | |
537 | { | |
538 | return NULL; | |
539 | } | |
540 | ||
541 | target_terminal_ours (); | |
542 | fflush (stdout); | |
543 | fprintf (stderr, "Type "); | |
544 | type_print (type, "", stderr, -1); | |
545 | fprintf (stderr, " has no component named "); | |
546 | fputs_filtered (name, stderr); | |
547 | error ("."); | |
548 | return (struct type *)-1; /* For lint */ | |
549 | } | |
550 | ||
551 | /* This function is really horrible, but to avoid it, there would need | |
552 | to be more filling in of forward references. */ | |
553 | ||
554 | void | |
555 | fill_in_vptr_fieldno (type) | |
556 | struct type *type; | |
557 | { | |
558 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
559 | { | |
560 | int i; | |
561 | for (i = 1; i < TYPE_N_BASECLASSES (type); i++) | |
562 | { | |
563 | fill_in_vptr_fieldno (TYPE_BASECLASS (type, i)); | |
564 | if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0) | |
565 | { | |
566 | TYPE_VPTR_FIELDNO (type) | |
567 | = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)); | |
568 | TYPE_VPTR_BASETYPE (type) | |
569 | = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i)); | |
570 | break; | |
571 | } | |
572 | } | |
573 | } | |
574 | } | |
575 | ||
576 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. | |
577 | ||
578 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
579 | we can find a full definition in some other file. If so, copy this | |
580 | definition, so we can use it in future. If not, set a flag so we | |
581 | don't waste too much time in future. (FIXME, this doesn't seem | |
582 | to be happening...) | |
583 | ||
584 | This used to be coded as a macro, but I don't think it is called | |
585 | often enough to merit such treatment. | |
586 | */ | |
587 | ||
588 | struct complaint stub_noname_complaint = | |
589 | {"stub type has NULL name", 0, 0}; | |
590 | ||
591 | void | |
592 | check_stub_type (type) | |
593 | struct type *type; | |
594 | { | |
595 | if (TYPE_FLAGS(type) & TYPE_FLAG_STUB) | |
596 | { | |
597 | char* name = type_name_no_tag (type); | |
598 | struct symbol *sym; | |
599 | if (name == NULL) | |
600 | { | |
601 | complain (&stub_noname_complaint, 0); | |
602 | return; | |
603 | } | |
604 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, | |
605 | (struct symtab **) NULL); | |
606 | if (sym) | |
607 | { | |
93fe4e33 | 608 | memcpy ((char *)type, (char *)SYMBOL_TYPE(sym), sizeof (struct type)); |
1ab3bf1b JG |
609 | } |
610 | } | |
611 | } | |
612 | ||
613 | /* Ugly hack to convert method stubs into method types. | |
614 | ||
615 | He ain't kiddin'. This demangles the name of the method into a string | |
616 | including argument types, parses out each argument type, generates | |
617 | a string casting a zero to that type, evaluates the string, and stuffs | |
618 | the resulting type into an argtype vector!!! Then it knows the type | |
619 | of the whole function (including argument types for overloading), | |
620 | which info used to be in the stab's but was removed to hack back | |
621 | the space required for them. */ | |
622 | ||
623 | void | |
624 | check_stub_method (type, i, j) | |
625 | struct type *type; | |
626 | int i; | |
627 | int j; | |
628 | { | |
629 | struct fn_field *f; | |
630 | char *mangled_name = gdb_mangle_name (type, i, j); | |
631 | char *demangled_name = cplus_demangle (mangled_name, 0); | |
632 | char *argtypetext, *p; | |
633 | int depth = 0, argcount = 1; | |
634 | struct type **argtypes; | |
635 | struct type *mtype; | |
636 | ||
637 | if (demangled_name == NULL) | |
638 | { | |
639 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); | |
640 | } | |
641 | ||
642 | /* Now, read in the parameters that define this type. */ | |
643 | argtypetext = strchr (demangled_name, '(') + 1; | |
644 | p = argtypetext; | |
645 | while (*p) | |
646 | { | |
647 | if (*p == '(') | |
648 | { | |
649 | depth += 1; | |
650 | } | |
651 | else if (*p == ')') | |
652 | { | |
653 | depth -= 1; | |
654 | } | |
655 | else if (*p == ',' && depth == 0) | |
656 | { | |
657 | argcount += 1; | |
658 | } | |
659 | ||
660 | p += 1; | |
661 | } | |
662 | ||
663 | /* We need two more slots: one for the THIS pointer, and one for the | |
664 | NULL [...] or void [end of arglist]. */ | |
665 | ||
666 | argtypes = (struct type **) | |
667 | obstack_alloc (&TYPE_OBJFILE (type) -> type_obstack, | |
668 | (argcount+2) * sizeof (struct type *)); | |
669 | p = argtypetext; | |
670 | argtypes[0] = lookup_pointer_type (type); | |
671 | argcount = 1; | |
672 | ||
673 | if (*p != ')') /* () means no args, skip while */ | |
674 | { | |
675 | depth = 0; | |
676 | while (*p) | |
677 | { | |
678 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
679 | { | |
680 | argtypes[argcount] = | |
681 | parse_and_eval_type (argtypetext, p - argtypetext); | |
682 | argcount += 1; | |
683 | argtypetext = p + 1; | |
684 | } | |
685 | ||
686 | if (*p == '(') | |
687 | { | |
688 | depth += 1; | |
689 | } | |
690 | else if (*p == ')') | |
691 | { | |
692 | depth -= 1; | |
693 | } | |
694 | ||
695 | p += 1; | |
696 | } | |
697 | } | |
698 | ||
699 | if (p[-2] != '.') /* ... */ | |
700 | { | |
701 | argtypes[argcount] = builtin_type_void; /* Ellist terminator */ | |
702 | } | |
703 | else | |
704 | { | |
705 | argtypes[argcount] = NULL; /* List terminator */ | |
706 | } | |
707 | ||
708 | free (demangled_name); | |
709 | ||
710 | f = TYPE_FN_FIELDLIST1 (type, i); | |
711 | TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name; | |
712 | ||
713 | /* Now update the old "stub" type into a real type. */ | |
714 | mtype = TYPE_FN_FIELD_TYPE (f, j); | |
715 | TYPE_DOMAIN_TYPE (mtype) = type; | |
716 | TYPE_ARG_TYPES (mtype) = argtypes; | |
717 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; | |
718 | TYPE_FN_FIELD_STUB (f, j) = 0; | |
719 | } | |
720 | ||
721 | const struct cplus_struct_type cplus_struct_default; | |
722 | ||
723 | void | |
724 | allocate_cplus_struct_type (type) | |
725 | struct type *type; | |
726 | { | |
727 | if (!HAVE_CPLUS_STRUCT (type)) | |
728 | { | |
729 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
730 | obstack_alloc (¤t_objfile -> type_obstack, | |
731 | sizeof (struct cplus_struct_type)); | |
732 | *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default; | |
733 | } | |
734 | } | |
735 | ||
736 | /* Helper function to initialize the standard scalar types. */ | |
737 | ||
738 | struct type * | |
739 | init_type (code, length, flags, name, objfile) | |
740 | enum type_code code; | |
741 | int length; | |
742 | int flags; | |
743 | char *name; | |
744 | struct objfile *objfile; | |
745 | { | |
746 | register struct type *type; | |
747 | ||
748 | type = alloc_type (objfile); | |
749 | TYPE_CODE (type) = code; | |
750 | TYPE_LENGTH (type) = length; | |
751 | TYPE_FLAGS (type) |= flags; | |
752 | TYPE_NAME (type) = name; | |
753 | ||
754 | /* C++ fancies. */ | |
755 | ||
756 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
757 | { | |
758 | INIT_CPLUS_SPECIFIC (type); | |
759 | } | |
760 | return (type); | |
761 | } | |
762 | ||
763 | /* Look up a fundamental type for the specified objfile. | |
764 | May need to construct such a type if this is the first use. | |
765 | ||
766 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
767 | types such as "int" or "double". Others (stabs for example), do | |
768 | define fundamental types. | |
769 | ||
770 | For the formats which don't provide fundamental types, gdb can create | |
771 | such types, using defaults reasonable for the current target machine. */ | |
772 | ||
773 | struct type * | |
774 | lookup_fundamental_type (objfile, typeid) | |
775 | struct objfile *objfile; | |
776 | int typeid; | |
777 | { | |
778 | register struct type *type = NULL; | |
779 | register struct type **typep; | |
780 | register int nbytes; | |
781 | ||
782 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
783 | { | |
784 | error ("internal error - invalid fundamental type id %d", typeid); | |
785 | } | |
786 | else | |
787 | { | |
788 | /* If this is the first time we */ | |
789 | if (objfile -> fundamental_types == NULL) | |
790 | { | |
791 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); | |
792 | objfile -> fundamental_types = (struct type **) | |
793 | obstack_alloc (&objfile -> type_obstack, nbytes); | |
93fe4e33 | 794 | (void) memset ((char *)objfile -> fundamental_types, 0, nbytes); |
1ab3bf1b JG |
795 | } |
796 | typep = objfile -> fundamental_types + typeid; | |
797 | if ((type = *typep) == NULL) | |
798 | { | |
799 | switch (typeid) | |
800 | { | |
801 | default: | |
802 | error ("internal error: unhandled type id %d", typeid); | |
803 | break; | |
804 | case FT_VOID: | |
805 | type = init_type (TYPE_CODE_VOID, | |
806 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
807 | 0, | |
808 | "void", objfile); | |
809 | break; | |
810 | case FT_BOOLEAN: | |
811 | type = init_type (TYPE_CODE_INT, | |
812 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
813 | TYPE_FLAG_UNSIGNED, | |
318bf84f | 814 | "boolean", objfile); |
1ab3bf1b JG |
815 | break; |
816 | case FT_STRING: | |
817 | type = init_type (TYPE_CODE_PASCAL_ARRAY, | |
818 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
819 | 0, | |
318bf84f | 820 | "string", objfile); |
1ab3bf1b JG |
821 | break; |
822 | case FT_CHAR: | |
823 | type = init_type (TYPE_CODE_INT, | |
824 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
825 | 0, | |
318bf84f | 826 | "char", objfile); |
1ab3bf1b JG |
827 | break; |
828 | case FT_SIGNED_CHAR: | |
829 | type = init_type (TYPE_CODE_INT, | |
830 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
831 | TYPE_FLAG_SIGNED, | |
318bf84f | 832 | "signed char", objfile); |
1ab3bf1b JG |
833 | break; |
834 | case FT_UNSIGNED_CHAR: | |
835 | type = init_type (TYPE_CODE_INT, | |
836 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
837 | TYPE_FLAG_UNSIGNED, | |
318bf84f | 838 | "unsigned char", objfile); |
1ab3bf1b JG |
839 | break; |
840 | case FT_SHORT: | |
841 | type = init_type (TYPE_CODE_INT, | |
842 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
843 | 0, | |
318bf84f | 844 | "short", objfile); |
1ab3bf1b JG |
845 | break; |
846 | case FT_SIGNED_SHORT: | |
847 | type = init_type (TYPE_CODE_INT, | |
848 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
849 | TYPE_FLAG_SIGNED, | |
318bf84f | 850 | "signed short", objfile); |
1ab3bf1b JG |
851 | break; |
852 | case FT_UNSIGNED_SHORT: | |
853 | type = init_type (TYPE_CODE_INT, | |
854 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
855 | TYPE_FLAG_UNSIGNED, | |
318bf84f | 856 | "unsigned short", objfile); |
1ab3bf1b JG |
857 | break; |
858 | case FT_INTEGER: | |
859 | type = init_type (TYPE_CODE_INT, | |
860 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
861 | 0, | |
318bf84f | 862 | "int", objfile); |
1ab3bf1b JG |
863 | break; |
864 | case FT_SIGNED_INTEGER: | |
865 | type = init_type (TYPE_CODE_INT, | |
866 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
867 | TYPE_FLAG_SIGNED, | |
318bf84f | 868 | "signed int", objfile); |
1ab3bf1b JG |
869 | break; |
870 | case FT_UNSIGNED_INTEGER: | |
871 | type = init_type (TYPE_CODE_INT, | |
872 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
873 | TYPE_FLAG_UNSIGNED, | |
318bf84f | 874 | "unsigned int", objfile); |
1ab3bf1b JG |
875 | break; |
876 | case FT_LONG: | |
877 | type = init_type (TYPE_CODE_INT, | |
878 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
879 | 0, | |
318bf84f | 880 | "long", objfile); |
1ab3bf1b JG |
881 | break; |
882 | case FT_SIGNED_LONG: | |
883 | type = init_type (TYPE_CODE_INT, | |
884 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
885 | TYPE_FLAG_SIGNED, | |
318bf84f | 886 | "signed long", objfile); |
1ab3bf1b JG |
887 | break; |
888 | case FT_UNSIGNED_LONG: | |
889 | type = init_type (TYPE_CODE_INT, | |
890 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
891 | TYPE_FLAG_UNSIGNED, | |
318bf84f | 892 | "unsigned long", objfile); |
1ab3bf1b JG |
893 | break; |
894 | case FT_LONG_LONG: | |
895 | type = init_type (TYPE_CODE_INT, | |
896 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
897 | 0, | |
318bf84f | 898 | "long long", objfile); |
1ab3bf1b JG |
899 | break; |
900 | case FT_SIGNED_LONG_LONG: | |
901 | type = init_type (TYPE_CODE_INT, | |
902 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
903 | TYPE_FLAG_SIGNED, | |
318bf84f | 904 | "signed long long", objfile); |
1ab3bf1b JG |
905 | break; |
906 | case FT_UNSIGNED_LONG_LONG: | |
907 | type = init_type (TYPE_CODE_INT, | |
908 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
909 | TYPE_FLAG_UNSIGNED, | |
910 | "unsigned long long", | |
318bf84f | 911 | objfile); |
1ab3bf1b JG |
912 | break; |
913 | case FT_FLOAT: | |
914 | type = init_type (TYPE_CODE_FLT, | |
915 | TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
916 | 0, | |
318bf84f | 917 | "float", objfile); |
1ab3bf1b JG |
918 | break; |
919 | case FT_DBL_PREC_FLOAT: | |
920 | type = init_type (TYPE_CODE_FLT, | |
921 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
922 | 0, | |
318bf84f | 923 | "double", objfile); |
1ab3bf1b JG |
924 | break; |
925 | case FT_EXT_PREC_FLOAT: | |
926 | type = init_type (TYPE_CODE_FLT, | |
927 | TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
928 | 0, | |
318bf84f | 929 | "long double", objfile); |
1ab3bf1b JG |
930 | break; |
931 | case FT_COMPLEX: | |
932 | type = init_type (TYPE_CODE_FLT, | |
933 | TARGET_COMPLEX_BIT / TARGET_CHAR_BIT, | |
934 | 0, | |
318bf84f | 935 | "complex", objfile); |
1ab3bf1b JG |
936 | break; |
937 | case FT_DBL_PREC_COMPLEX: | |
938 | type = init_type (TYPE_CODE_FLT, | |
939 | TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT, | |
940 | 0, | |
318bf84f | 941 | "double complex", objfile); |
1ab3bf1b JG |
942 | break; |
943 | case FT_EXT_PREC_COMPLEX: | |
944 | type = init_type (TYPE_CODE_FLT, | |
945 | TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT, | |
946 | 0, | |
947 | "long double complex", | |
318bf84f | 948 | objfile); |
1ab3bf1b JG |
949 | break; |
950 | } | |
951 | /* Install the newly created type in the objfile's fundamental_types | |
952 | vector. */ | |
953 | *typep = type; | |
954 | } | |
955 | } | |
956 | return (type); | |
957 | } | |
958 |