* buildsym.c (read_struct_type): Initialize structs allocated
[binutils-gdb.git] / gdb / gdbtypes.h
1 /* Internal type definitions 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 #if !defined (GDBTYPES_H)
22 #define GDBTYPES_H 1
23
24 /* When gdb creates fundamental types, it uses one of the following
25 type identifiers. The identifiers are used to index a vector of
26 pointers to any types that are created. */
27
28 #define FT_VOID 0
29 #define FT_BOOLEAN 1
30 #define FT_CHAR 2
31 #define FT_SIGNED_CHAR 3
32 #define FT_UNSIGNED_CHAR 4
33 #define FT_SHORT 5
34 #define FT_SIGNED_SHORT 6
35 #define FT_UNSIGNED_SHORT 7
36 #define FT_INTEGER 8
37 #define FT_SIGNED_INTEGER 9
38 #define FT_UNSIGNED_INTEGER 10
39 #define FT_LONG 11
40 #define FT_SIGNED_LONG 12
41 #define FT_UNSIGNED_LONG 13
42 #define FT_LONG_LONG 14
43 #define FT_SIGNED_LONG_LONG 15
44 #define FT_UNSIGNED_LONG_LONG 16
45 #define FT_FLOAT 17
46 #define FT_DBL_PREC_FLOAT 18
47 #define FT_EXT_PREC_FLOAT 19
48 #define FT_COMPLEX 20
49 #define FT_DBL_PREC_COMPLEX 21
50 #define FT_EXT_PREC_COMPLEX 22
51 #define FT_STRING 23
52 #define FT_FIXED_DECIMAL 24
53 #define FT_FLOAT_DECIMAL 25
54
55 #define FT_NUM_MEMBERS 26
56
57 /* Different kinds of data types are distinguished by the `code' field. */
58
59 enum type_code
60 {
61 TYPE_CODE_UNDEF, /* Not used; catches errors */
62 TYPE_CODE_PTR, /* Pointer type */
63 TYPE_CODE_ARRAY, /* Array type, lower bound zero */
64 TYPE_CODE_STRUCT, /* C struct or Pascal record */
65 TYPE_CODE_UNION, /* C union or Pascal variant part */
66 TYPE_CODE_ENUM, /* Enumeration type */
67 TYPE_CODE_FUNC, /* Function type */
68 TYPE_CODE_INT, /* Integer type */
69 TYPE_CODE_FLT, /* Floating type */
70 TYPE_CODE_VOID, /* Void type (values zero length) */
71 TYPE_CODE_SET, /* Pascal sets */
72 TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */
73 TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */
74 TYPE_CODE_ERROR, /* Unknown type */
75
76 /* C++ */
77 TYPE_CODE_MEMBER, /* Member type */
78 TYPE_CODE_METHOD, /* Method type */
79 TYPE_CODE_REF, /* C++ Reference types */
80
81 /* Modula-2 */
82 TYPE_CODE_CHAR, /* *real* character type */
83 TYPE_CODE_BOOL /* Builtin Modula-2 BOOLEAN */
84 };
85
86 /* Some bits for the type's flags word. */
87
88 /* Explicitly unsigned integer type */
89
90 #define TYPE_FLAG_UNSIGNED (1 << 0)
91
92 /* Explicitly signed integer type */
93
94 #define TYPE_FLAG_SIGNED (1 << 1)
95
96 /* This appears in a type's flags word if it is a stub type (eg. if
97 someone referenced a type that wasn't defined in a source file
98 via (struct sir_not_appearing_in_this_film *)). */
99
100 #define TYPE_FLAG_STUB (1 << 2)
101
102
103 struct type
104 {
105
106 /* Code for kind of type */
107
108 enum type_code code;
109
110 /* Name of this type, or NULL if none.
111 This is used for printing only, except by poorly designed C++ code.
112 Type names specified as input are defined by symbols. */
113
114 char *name;
115
116 /* Length in bytes of storage for a value of this type */
117
118 unsigned length;
119
120 /* Every type is now associated with a particular objfile, and the
121 type is allocated on the type_obstack for that objfile. One problem
122 however, is that there are times when gdb allocates new types while
123 it is not in the process of reading symbols from a particular objfile.
124 Fortunately, these happen when the type being created is a derived
125 type of an existing type, such as in lookup_pointer_type(). So
126 we can just allocate the new type using the same objfile as the
127 existing type, but to do this we need a backpointer to the objfile
128 from the existing type. Yes this is somewhat ugly, but without
129 major overhaul of the internal type system, it can't be avoided
130 for now. */
131
132 struct objfile *objfile;
133
134 /* For a pointer type, describes the type of object pointed to.
135 For an array type, describes the type of the elements.
136 For a function or method type, describes the type of the return value.
137 For a range type, describes the type of the full range.
138 Unused otherwise. */
139
140 struct type *target_type;
141
142 /* Type that is a pointer to this type.
143 NULL if no such pointer-to type is known yet.
144 The debugger may add the address of such a type
145 if it has to construct one later. */
146
147 struct type *pointer_type;
148
149 /* C++: also need a reference type. */
150
151 struct type *reference_type;
152
153 /* Type that is a function returning this type.
154 NULL if no such function type is known here.
155 The debugger may add the address of such a type
156 if it has to construct one later. */
157
158 struct type *function_type;
159
160 /* Flags about this type. */
161
162 short flags;
163
164 /* Number of fields described for this type */
165
166 short nfields;
167
168 /* For structure and union types, a description of each field.
169 For set and pascal array types, there is one "field",
170 whose type is the domain type of the set or array.
171 For range types, there are two "fields",
172 the minimum and maximum values (both inclusive).
173 For enum types, each possible value is described by one "field".
174
175 Using a pointer to a separate array of fields
176 allows all types to have the same size, which is useful
177 because we can allocate the space for a type before
178 we know what to put in it. */
179
180 struct field
181 {
182
183 /* Position of this field, counting in bits from start of
184 containing structure. For a function type, this is the
185 position in the argument list of this argument.
186 For a range bound or enum value, this is the value itself.
187 For BITS_BIG_ENDIAN=1 targets, it is the bit offset to the MSB.
188 For BITS_BIG_ENDIAN=0 targets, it is the bit offset to the LSB. */
189
190 int bitpos;
191
192 /* Size of this field, in bits, or zero if not packed.
193 For an unpacked field, the field's type's length
194 says how many bytes the field occupies. */
195
196 int bitsize;
197
198 /* In a struct or enum type, type of this field.
199 In a function type, type of this argument.
200 In an array type, the domain-type of the array. */
201
202 struct type *type;
203
204 /* Name of field, value or argument.
205 NULL for range bounds and array domains. */
206
207 char *name;
208
209 } *fields;
210
211 /* For types with virtual functions, VPTR_BASETYPE is the base class which
212 defined the virtual function table pointer. VPTR_FIELDNO is
213 the field number of that pointer in the structure.
214
215 For types that are pointer to member types, VPTR_BASETYPE
216 is the type that this pointer is a member of.
217
218 Unused otherwise. */
219
220 struct type *vptr_basetype;
221
222 int vptr_fieldno;
223
224 /* Slot to point to additional language-specific fields of this type. */
225
226 union type_specific
227 {
228
229 /* ARG_TYPES is for TYPE_CODE_METHOD and TYPE_CODE_FUNC. */
230
231 struct type **arg_types;
232
233 /* CPLUS_STUFF is for TYPE_CODE_STRUCT. It is initialized to point to
234 cplus_struct_default, a default static instance of a struct
235 cplus_struct_type. */
236
237 struct cplus_struct_type *cplus_stuff;
238
239 } type_specific;
240 };
241
242 #define NULL_TYPE ((struct type *) 0)
243
244 /* C++ language-specific information for TYPE_CODE_STRUCT and TYPE_CODE_UNION
245 nodes. */
246
247 struct cplus_struct_type
248 {
249 /* Number of base classes this type derives from. */
250
251 short n_baseclasses;
252
253 /* Number of methods with unique names. All overloaded methods with
254 the same name count only once. */
255
256 short nfn_fields;
257
258 /* Number of methods described for this type plus all the
259 methods that it derives from. */
260
261 int nfn_fields_total;
262
263 /* For derived classes, the number of base classes is given by
264 n_baseclasses and virtual_field_bits is a bit vector containing one bit
265 per base class.
266 If the base class is virtual, the corresponding bit will be set. */
267
268 B_TYPE *virtual_field_bits;
269
270 /* For classes with private fields, the number of fields is given by
271 nfields and private_field_bits is a bit vector containing one bit
272 per field.
273 If the field is private, the corresponding bit will be set. */
274
275 B_TYPE *private_field_bits;
276
277 /* For classes with protected fields, the number of fields is given by
278 nfields and protected_field_bits is a bit vector containing one bit
279 per field.
280 If the field is private, the corresponding bit will be set. */
281
282 B_TYPE *protected_field_bits;
283
284 /* For classes, structures, and unions, a description of each field,
285 which consists of an overloaded name, followed by the types of
286 arguments that the method expects, and then the name after it
287 has been renamed to make it distinct.
288
289 fn_fieldlists points to an array of nfn_fields of these. */
290
291 struct fn_fieldlist
292 {
293
294 /* The overloaded name. */
295
296 char *name;
297
298 /* The number of methods with this name. */
299
300 int length;
301
302 /* The list of methods. */
303
304 struct fn_field
305 {
306
307 /* The name after it has been processed */
308
309 char *physname;
310
311 /* The return value of the method */
312
313 struct type *type;
314
315 /* The argument list */
316
317 struct type **args;
318
319 /* For virtual functions.
320 First baseclass that defines this virtual function. */
321
322 struct type *fcontext;
323
324 /* Attributes. */
325
326 unsigned int is_const : 1;
327 unsigned int is_volatile : 1;
328 unsigned int is_private : 1;
329 unsigned int is_protected : 1;
330 unsigned int is_stub : 1;
331 unsigned int dummy : 3;
332
333 /* Index into that baseclass's virtual function table,
334 minus 2; else if static: VOFFSET_STATIC; else: 0. */
335
336 unsigned int voffset : 24;
337
338 # define VOFFSET_STATIC 1
339
340 } *fn_fields;
341
342 } *fn_fieldlists;
343
344 };
345
346 /* The default value of TYPE_CPLUS_SPECIFIC(T) points to the
347 this shared static structure. */
348
349 extern const struct cplus_struct_type cplus_struct_default;
350
351 extern void
352 allocate_cplus_struct_type PARAMS ((struct type *));
353
354 #define INIT_CPLUS_SPECIFIC(type) \
355 (TYPE_CPLUS_SPECIFIC(type)=(struct cplus_struct_type*)&cplus_struct_default)
356 #define ALLOCATE_CPLUS_STRUCT_TYPE(type) allocate_cplus_struct_type (type)
357 #define HAVE_CPLUS_STRUCT(type) \
358 (TYPE_CPLUS_SPECIFIC(type) != &cplus_struct_default)
359
360 #define TYPE_NAME(thistype) (thistype)->name
361 #define TYPE_TARGET_TYPE(thistype) (thistype)->target_type
362 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
363 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
364 #define TYPE_FUNCTION_TYPE(thistype) (thistype)->function_type
365 #define TYPE_LENGTH(thistype) (thistype)->length
366 #define TYPE_OBJFILE(thistype) (thistype)->objfile
367 #define TYPE_FLAGS(thistype) (thistype)->flags
368 #define TYPE_UNSIGNED(thistype) ((thistype)->flags & TYPE_FLAG_UNSIGNED)
369 #define TYPE_CODE(thistype) (thistype)->code
370 #define TYPE_NFIELDS(thistype) (thistype)->nfields
371 #define TYPE_FIELDS(thistype) (thistype)->fields
372
373 /* C++ */
374
375 #define TYPE_VPTR_BASETYPE(thistype) (thistype)->vptr_basetype
376 #define TYPE_DOMAIN_TYPE(thistype) (thistype)->vptr_basetype
377 #define TYPE_VPTR_FIELDNO(thistype) (thistype)->vptr_fieldno
378 #define TYPE_FN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fields
379 #define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields
380 #define TYPE_NFN_FIELDS_TOTAL(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields_total
381 #define TYPE_TYPE_SPECIFIC(thistype) (thistype)->type_specific
382 #define TYPE_ARG_TYPES(thistype) (thistype)->type_specific.arg_types
383 #define TYPE_CPLUS_SPECIFIC(thistype) (thistype)->type_specific.cplus_stuff
384 #define TYPE_BASECLASS(thistype,index) (thistype)->fields[index].type
385 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
386 #define TYPE_BASECLASS_NAME(thistype,index) (thistype)->fields[index].name
387 #define TYPE_BASECLASS_BITPOS(thistype,index) (thistype)->fields[index].bitpos
388 #define BASETYPE_VIA_PUBLIC(thistype, index) (!TYPE_FIELD_PRIVATE(thistype, index))
389 #define BASETYPE_VIA_VIRTUAL(thistype, index) \
390 B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (index))
391
392 #define TYPE_FIELD(thistype, n) (thistype)->fields[n]
393 #define TYPE_FIELD_TYPE(thistype, n) (thistype)->fields[n].type
394 #define TYPE_FIELD_NAME(thistype, n) (thistype)->fields[n].name
395 #define TYPE_FIELD_VALUE(thistype, n) (* (int*) &(thistype)->fields[n].type)
396 #define TYPE_FIELD_BITPOS(thistype, n) (thistype)->fields[n].bitpos
397 #define TYPE_FIELD_BITSIZE(thistype, n) (thistype)->fields[n].bitsize
398 #define TYPE_FIELD_PACKED(thistype, n) (thistype)->fields[n].bitsize
399
400 #define TYPE_FIELD_PRIVATE_BITS(thistype) \
401 TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits
402 #define TYPE_FIELD_PROTECTED_BITS(thistype) \
403 TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits
404 #define TYPE_FIELD_VIRTUAL_BITS(thistype) \
405 TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits
406 #define SET_TYPE_FIELD_PRIVATE(thistype, n) \
407 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n))
408 #define SET_TYPE_FIELD_PROTECTED(thistype, n) \
409 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n))
410 #define SET_TYPE_FIELD_VIRTUAL(thistype, n) \
411 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n))
412 #define TYPE_FIELD_PRIVATE(thistype, n) \
413 (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits == NULL ? 0 \
414 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n)))
415 #define TYPE_FIELD_PROTECTED(thistype, n) \
416 (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits == NULL ? 0 \
417 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n)))
418 #define TYPE_FIELD_VIRTUAL(thistype, n) \
419 B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n))
420
421 #define TYPE_FIELD_STATIC(thistype, n) ((thistype)->fields[n].bitpos == -1)
422 #define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) ((char *)(thistype)->fields[n].bitsize)
423
424 #define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
425 #define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
426 #define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields
427 #define TYPE_FN_FIELDLIST_NAME(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].name
428 #define TYPE_FN_FIELDLIST_LENGTH(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].length
429
430 #define TYPE_FN_FIELD(thisfn, n) (thisfn)[n]
431 #define TYPE_FN_FIELD_PHYSNAME(thisfn, n) (thisfn)[n].physname
432 #define TYPE_FN_FIELD_TYPE(thisfn, n) (thisfn)[n].type
433 #define TYPE_FN_FIELD_ARGS(thisfn, n) TYPE_ARG_TYPES ((thisfn)[n].type)
434 #define TYPE_FN_FIELD_CONST(thisfn, n) ((thisfn)[n].is_const)
435 #define TYPE_FN_FIELD_VOLATILE(thisfn, n) ((thisfn)[n].is_volatile)
436 #define TYPE_FN_FIELD_PRIVATE(thisfn, n) ((thisfn)[n].is_private)
437 #define TYPE_FN_FIELD_PROTECTED(thisfn, n) ((thisfn)[n].is_protected)
438 #define TYPE_FN_FIELD_STUB(thisfn, n) ((thisfn)[n].is_stub)
439 #define TYPE_FN_FIELD_FCONTEXT(thisfn, n) ((thisfn)[n].fcontext)
440 #define TYPE_FN_FIELD_VOFFSET(thisfn, n) ((thisfn)[n].voffset-2)
441 #define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n) ((thisfn)[n].voffset > 1)
442 #define TYPE_FN_FIELD_STATIC_P(thisfn, n) ((thisfn)[n].voffset == VOFFSET_STATIC)
443
444 extern struct type *builtin_type_void;
445 extern struct type *builtin_type_char;
446 extern struct type *builtin_type_short;
447 extern struct type *builtin_type_int;
448 extern struct type *builtin_type_long;
449 extern struct type *builtin_type_signed_char;
450 extern struct type *builtin_type_unsigned_char;
451 extern struct type *builtin_type_unsigned_short;
452 extern struct type *builtin_type_unsigned_int;
453 extern struct type *builtin_type_unsigned_long;
454 extern struct type *builtin_type_float;
455 extern struct type *builtin_type_double;
456 extern struct type *builtin_type_long_double;
457 extern struct type *builtin_type_complex;
458 extern struct type *builtin_type_double_complex;
459
460 /* This type represents a type that was unrecognized in symbol
461 read-in. */
462
463 extern struct type *builtin_type_error;
464
465 extern struct type *builtin_type_long_long;
466 extern struct type *builtin_type_unsigned_long_long;
467
468 /* Modula-2 types */
469
470 extern struct type *builtin_type_m2_char;
471 extern struct type *builtin_type_m2_int;
472 extern struct type *builtin_type_m2_card;
473 extern struct type *builtin_type_m2_real;
474 extern struct type *builtin_type_m2_bool;
475
476 /* LONG_LONG is defined if the host has "long long". */
477
478 #ifdef LONG_LONG
479
480 #define BUILTIN_TYPE_LONGEST builtin_type_long_long
481 #define BUILTIN_TYPE_UNSIGNED_LONGEST builtin_type_unsigned_long_long
482
483 #else /* not LONG_LONG. */
484
485 #define BUILTIN_TYPE_LONGEST builtin_type_long
486 #define BUILTIN_TYPE_UNSIGNED_LONGEST builtin_type_unsigned_long
487
488 #endif /* not LONG_LONG. */
489
490 /* Maximum and minimum values of built-in types */
491
492 #define MAX_OF_TYPE(t) \
493 TYPE_UNSIGNED(t) ? UMAX_OF_SIZE(TYPE_LENGTH(t)) \
494 : MAX_OF_SIZE(TYPE_LENGTH(t))
495
496 #define MIN_OF_TYPE(t) \
497 TYPE_UNSIGNED(t) ? UMIN_OF_SIZE(TYPE_LENGTH(t)) \
498 : MIN_OF_SIZE(TYPE_LENGTH(t))
499
500 extern struct type *
501 alloc_type PARAMS ((struct objfile *));
502
503 extern struct type *
504 init_type PARAMS ((enum type_code, int, int, char *, struct objfile *));
505
506 extern struct type *
507 lookup_reference_type PARAMS ((struct type *));
508
509 extern struct type *
510 make_reference_type PARAMS ((struct type *, struct type **));
511
512 extern struct type *
513 lookup_member_type PARAMS ((struct type *, struct type *));
514
515 extern void
516 smash_to_method_type PARAMS ((struct type *, struct type *, struct type *,
517 struct type **));
518
519 extern void
520 smash_to_member_type PARAMS ((struct type *, struct type *, struct type *));
521
522 extern struct type *
523 allocate_stub_method PARAMS ((struct type *));
524
525 extern char *
526 type_name_no_tag PARAMS ((const struct type *));
527
528 extern struct type *
529 lookup_struct_elt_type PARAMS ((struct type *, char *, int));
530
531 extern struct type *
532 make_pointer_type PARAMS ((struct type *, struct type **));
533
534 extern struct type *
535 lookup_pointer_type PARAMS ((struct type *));
536
537 extern struct type *
538 make_function_type PARAMS ((struct type *, struct type **));
539
540 extern struct type *
541 lookup_function_type PARAMS ((struct type *));
542
543 extern struct type *
544 create_array_type PARAMS ((struct type *, int));
545
546 extern struct type *
547 lookup_unsigned_typename PARAMS ((char *));
548
549 extern struct type *
550 lookup_signed_typename PARAMS ((char *));
551
552 extern void
553 check_stub_type PARAMS ((struct type *));
554
555 extern void
556 check_stub_method PARAMS ((struct type *, int, int));
557
558 extern struct type *
559 lookup_primitive_typename PARAMS ((char *));
560
561 extern char *
562 gdb_mangle_name PARAMS ((struct type *, int, int));
563
564 extern struct type *
565 builtin_type PARAMS ((char **));
566
567 extern struct type *
568 error_type PARAMS ((char **));
569
570 extern struct type *
571 lookup_typename PARAMS ((char *, struct block *, int));
572
573 extern struct type *
574 lookup_template_type PARAMS ((char *, struct type *, struct block *));
575
576 extern struct type *
577 lookup_fundamental_type PARAMS ((struct objfile *, int));
578
579 extern void
580 fill_in_vptr_fieldno PARAMS ((struct type *));
581
582 #if MAINTENANCE_CMDS
583 extern void recursive_dump_type PARAMS ((struct type *, int));
584 #endif
585
586 /* printcmd.c */
587
588 extern void
589 print_scalar_formatted PARAMS ((char *, struct type *, int, int, FILE *));
590
591 #if MAINTENANCE_CMDS
592 extern void maintenance_print_type PARAMS ((char *, int));
593 #endif
594
595 #endif /* GDBTYPES_H */