Rename gdb exception types
[deliverable/binutils-gdb.git] / gdb / guile / scm-type.c
CommitLineData
ed3ef339
DE
1/* Scheme interface to types.
2
42a4f53d 3 Copyright (C) 2008-2019 Free Software Foundation, Inc.
ed3ef339
DE
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 3 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, see <http://www.gnu.org/licenses/>. */
19
20/* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
22
23#include "defs.h"
24#include "arch-utils.h"
25#include "value.h"
ed3ef339
DE
26#include "gdbtypes.h"
27#include "objfiles.h"
28#include "language.h"
0747795c 29#include "common/vec.h"
ed3ef339
DE
30#include "bcache.h"
31#include "dwarf2loc.h"
32#include "typeprint.h"
33#include "guile-internal.h"
34
35/* The <gdb:type> smob.
36 The type is chained with all types associated with its objfile, if any.
37 This lets us copy the underlying struct type when the objfile is
1913f160
DE
38 deleted.
39 The typedef for this struct is in guile-internal.h. */
ed3ef339 40
1913f160 41struct _type_smob
ed3ef339
DE
42{
43 /* This always appears first.
44 eqable_gdb_smob is used so that types are eq?-able.
45 Also, a type object can be associated with an objfile. eqable_gdb_smob
46 lets us track the lifetime of all types associated with an objfile.
47 When an objfile is deleted we need to invalidate the type object. */
48 eqable_gdb_smob base;
49
50 /* The GDB type structure this smob is wrapping. */
51 struct type *type;
1913f160 52};
ed3ef339
DE
53
54/* A field smob. */
55
56typedef struct
57{
58 /* This always appears first. */
59 gdb_smob base;
60
61 /* Backlink to the containing <gdb:type> object. */
62 SCM type_scm;
63
64 /* The field number in TYPE_SCM. */
65 int field_num;
66} field_smob;
67
68static const char type_smob_name[] = "gdb:type";
69static const char field_smob_name[] = "gdb:field";
70
71static const char not_composite_error[] =
72 N_("type is not a structure, union, or enum type");
73
74/* The tag Guile knows the type smob by. */
75static scm_t_bits type_smob_tag;
76
77/* The tag Guile knows the field smob by. */
78static scm_t_bits field_smob_tag;
79
80/* The "next" procedure for field iterators. */
81static SCM tyscm_next_field_x_proc;
82
83/* Keywords used in argument passing. */
84static SCM block_keyword;
85
86static const struct objfile_data *tyscm_objfile_data_key;
87
88/* Hash table to uniquify global (non-objfile-owned) types. */
89static htab_t global_types_map;
90
91static struct type *tyscm_get_composite (struct type *type);
92
93/* Return the type field of T_SMOB.
94 This exists so that we don't have to export the struct's contents. */
95
96struct type *
97tyscm_type_smob_type (type_smob *t_smob)
98{
99 return t_smob->type;
100}
101
3ab692db
PA
102/* Return the name of TYPE in expanded form. If there's an error
103 computing the name, throws the gdb exception with scm_throw. */
ed3ef339 104
3ab692db
PA
105static std::string
106tyscm_type_name (struct type *type)
ed3ef339 107{
a70b8144 108 try
ed3ef339 109 {
d7e74731 110 string_file stb;
ed3ef339 111
d7e74731
PA
112 LA_PRINT_TYPE (type, "", &stb, -1, 0, &type_print_raw_options);
113 return std::move (stb.string ());
ed3ef339 114 }
230d2906 115 catch (const gdb_exception &except)
ed3ef339 116 {
3ab692db
PA
117 SCM excp = gdbscm_scm_from_gdb_exception (except);
118 gdbscm_throw (excp);
ed3ef339
DE
119 }
120
3ab692db 121 gdb_assert_not_reached ("no way to get here");
ed3ef339
DE
122}
123\f
124/* Administrivia for type smobs. */
125
126/* Helper function to hash a type_smob. */
127
128static hashval_t
129tyscm_hash_type_smob (const void *p)
130{
9a3c8263 131 const type_smob *t_smob = (const type_smob *) p;
ed3ef339
DE
132
133 return htab_hash_pointer (t_smob->type);
134}
135
136/* Helper function to compute equality of type_smobs. */
137
138static int
139tyscm_eq_type_smob (const void *ap, const void *bp)
140{
9a3c8263
SM
141 const type_smob *a = (const type_smob *) ap;
142 const type_smob *b = (const type_smob *) bp;
ed3ef339
DE
143
144 return (a->type == b->type
145 && a->type != NULL);
146}
147
148/* Return the struct type pointer -> SCM mapping table.
149 If type is owned by an objfile, the mapping table is created if necessary.
150 Otherwise, type is not owned by an objfile, and we use
151 global_types_map. */
152
153static htab_t
154tyscm_type_map (struct type *type)
155{
156 struct objfile *objfile = TYPE_OBJFILE (type);
157 htab_t htab;
158
159 if (objfile == NULL)
160 return global_types_map;
161
9a3c8263 162 htab = (htab_t) objfile_data (objfile, tyscm_objfile_data_key);
ed3ef339
DE
163 if (htab == NULL)
164 {
165 htab = gdbscm_create_eqable_gsmob_ptr_map (tyscm_hash_type_smob,
166 tyscm_eq_type_smob);
167 set_objfile_data (objfile, tyscm_objfile_data_key, htab);
168 }
169
170 return htab;
171}
172
ed3ef339
DE
173/* The smob "free" function for <gdb:type>. */
174
175static size_t
176tyscm_free_type_smob (SCM self)
177{
178 type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (self);
179
180 if (t_smob->type != NULL)
181 {
182 htab_t htab = tyscm_type_map (t_smob->type);
183
184 gdbscm_clear_eqable_gsmob_ptr_slot (htab, &t_smob->base);
185 }
186
187 /* Not necessary, done to catch bugs. */
188 t_smob->type = NULL;
189
190 return 0;
191}
192
193/* The smob "print" function for <gdb:type>. */
194
195static int
196tyscm_print_type_smob (SCM self, SCM port, scm_print_state *pstate)
197{
198 type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (self);
3ab692db 199 std::string name = tyscm_type_name (t_smob->type);
ed3ef339
DE
200
201 /* pstate->writingp = zero if invoked by display/~A, and nonzero if
202 invoked by write/~S. What to do here may need to evolve.
203 IWBN if we could pass an argument to format that would we could use
204 instead of writingp. */
205 if (pstate->writingp)
206 gdbscm_printf (port, "#<%s ", type_smob_name);
207
3ab692db 208 scm_puts (name.c_str (), port);
ed3ef339
DE
209
210 if (pstate->writingp)
211 scm_puts (">", port);
212
213 scm_remember_upto_here_1 (self);
214
215 /* Non-zero means success. */
216 return 1;
217}
218
219/* The smob "equal?" function for <gdb:type>. */
220
221static SCM
222tyscm_equal_p_type_smob (SCM type1_scm, SCM type2_scm)
223{
224 type_smob *type1_smob, *type2_smob;
225 struct type *type1, *type2;
894882e3 226 bool result = false;
ed3ef339
DE
227
228 SCM_ASSERT_TYPE (tyscm_is_type (type1_scm), type1_scm, SCM_ARG1, FUNC_NAME,
229 type_smob_name);
230 SCM_ASSERT_TYPE (tyscm_is_type (type2_scm), type2_scm, SCM_ARG2, FUNC_NAME,
231 type_smob_name);
232 type1_smob = (type_smob *) SCM_SMOB_DATA (type1_scm);
233 type2_smob = (type_smob *) SCM_SMOB_DATA (type2_scm);
234 type1 = type1_smob->type;
235 type2 = type2_smob->type;
236
a70b8144 237 try
ed3ef339
DE
238 {
239 result = types_deeply_equal (type1, type2);
240 }
230d2906 241 catch (const gdb_exception &except)
492d29ea
PA
242 {
243 GDBSCM_HANDLE_GDB_EXCEPTION (except);
244 }
ed3ef339
DE
245
246 return scm_from_bool (result);
247}
248
249/* Low level routine to create a <gdb:type> object. */
250
251static SCM
252tyscm_make_type_smob (void)
253{
254 type_smob *t_smob = (type_smob *)
255 scm_gc_malloc (sizeof (type_smob), type_smob_name);
256 SCM t_scm;
257
258 /* This must be filled in by the caller. */
259 t_smob->type = NULL;
260
261 t_scm = scm_new_smob (type_smob_tag, (scm_t_bits) t_smob);
1254eefc 262 gdbscm_init_eqable_gsmob (&t_smob->base, t_scm);
ed3ef339
DE
263
264 return t_scm;
265}
266
267/* Return non-zero if SCM is a <gdb:type> object. */
268
269int
270tyscm_is_type (SCM self)
271{
272 return SCM_SMOB_PREDICATE (type_smob_tag, self);
273}
274
275/* (type? object) -> boolean */
276
277static SCM
278gdbscm_type_p (SCM self)
279{
280 return scm_from_bool (tyscm_is_type (self));
281}
282
283/* Return the existing object that encapsulates TYPE, or create a new
284 <gdb:type> object. */
285
286SCM
287tyscm_scm_from_type (struct type *type)
288{
289 htab_t htab;
290 eqable_gdb_smob **slot;
291 type_smob *t_smob, t_smob_for_lookup;
292 SCM t_scm;
293
294 /* If we've already created a gsmob for this type, return it.
295 This makes types eq?-able. */
296 htab = tyscm_type_map (type);
297 t_smob_for_lookup.type = type;
298 slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &t_smob_for_lookup.base);
299 if (*slot != NULL)
300 return (*slot)->containing_scm;
301
302 t_scm = tyscm_make_type_smob ();
303 t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
304 t_smob->type = type;
1254eefc 305 gdbscm_fill_eqable_gsmob_ptr_slot (slot, &t_smob->base);
ed3ef339
DE
306
307 return t_scm;
308}
309
310/* Returns the <gdb:type> object in SELF.
311 Throws an exception if SELF is not a <gdb:type> object. */
312
313static SCM
314tyscm_get_type_arg_unsafe (SCM self, int arg_pos, const char *func_name)
315{
316 SCM_ASSERT_TYPE (tyscm_is_type (self), self, arg_pos, func_name,
317 type_smob_name);
318
319 return self;
320}
321
322/* Returns a pointer to the type smob of SELF.
323 Throws an exception if SELF is not a <gdb:type> object. */
324
325type_smob *
326tyscm_get_type_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
327{
328 SCM t_scm = tyscm_get_type_arg_unsafe (self, arg_pos, func_name);
329 type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
330
331 return t_smob;
332}
333
a3a5fecc
DE
334/* Return the type field of T_SCM, an object of type <gdb:type>.
335 This exists so that we don't have to export the struct's contents. */
336
337struct type *
338tyscm_scm_to_type (SCM t_scm)
339{
340 type_smob *t_smob;
341
342 gdb_assert (tyscm_is_type (t_scm));
343 t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
344 return t_smob->type;
345}
346
ed3ef339
DE
347/* Helper function for save_objfile_types to make a deep copy of the type. */
348
349static int
350tyscm_copy_type_recursive (void **slot, void *info)
351{
352 type_smob *t_smob = (type_smob *) *slot;
9a3c8263 353 htab_t copied_types = (htab_t) info;
ed3ef339 354 struct objfile *objfile = TYPE_OBJFILE (t_smob->type);
5a1e8c7a
DE
355 htab_t htab;
356 eqable_gdb_smob **new_slot;
357 type_smob t_smob_for_lookup;
ed3ef339
DE
358
359 gdb_assert (objfile != NULL);
360
361 htab_empty (copied_types);
362 t_smob->type = copy_type_recursive (objfile, t_smob->type, copied_types);
5a1e8c7a
DE
363
364 /* The eq?-hashtab that the type lived in is going away.
365 Add the type to its new eq?-hashtab: Otherwise if/when the type is later
366 garbage collected we'll assert-fail if the type isn't in the hashtab.
367 PR 16612.
368
369 Types now live in "arch space", and things like "char" that came from
370 the objfile *could* be considered eq? with the arch "char" type.
371 However, they weren't before the objfile got deleted, so making them
372 eq? now is debatable. */
373 htab = tyscm_type_map (t_smob->type);
374 t_smob_for_lookup.type = t_smob->type;
375 new_slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &t_smob_for_lookup.base);
376 gdb_assert (*new_slot == NULL);
377 gdbscm_fill_eqable_gsmob_ptr_slot (new_slot, &t_smob->base);
378
ed3ef339
DE
379 return 1;
380}
381
382/* Called when OBJFILE is about to be deleted.
383 Make a copy of all types associated with OBJFILE. */
384
385static void
386save_objfile_types (struct objfile *objfile, void *datum)
387{
9a3c8263 388 htab_t htab = (htab_t) datum;
ed3ef339
DE
389 htab_t copied_types;
390
391 if (!gdb_scheme_initialized)
392 return;
393
394 copied_types = create_copied_types_hash (objfile);
395
396 if (htab != NULL)
397 {
398 htab_traverse_noresize (htab, tyscm_copy_type_recursive, copied_types);
399 htab_delete (htab);
400 }
401
402 htab_delete (copied_types);
403}
404\f
405/* Administrivia for field smobs. */
406
ed3ef339
DE
407/* The smob "print" function for <gdb:field>. */
408
409static int
410tyscm_print_field_smob (SCM self, SCM port, scm_print_state *pstate)
411{
412 field_smob *f_smob = (field_smob *) SCM_SMOB_DATA (self);
413
414 gdbscm_printf (port, "#<%s ", field_smob_name);
415 scm_write (f_smob->type_scm, port);
416 gdbscm_printf (port, " %d", f_smob->field_num);
417 scm_puts (">", port);
418
419 scm_remember_upto_here_1 (self);
420
421 /* Non-zero means success. */
422 return 1;
423}
424
425/* Low level routine to create a <gdb:field> object for field FIELD_NUM
426 of type TYPE_SCM. */
427
428static SCM
429tyscm_make_field_smob (SCM type_scm, int field_num)
430{
431 field_smob *f_smob = (field_smob *)
432 scm_gc_malloc (sizeof (field_smob), field_smob_name);
433 SCM result;
434
435 f_smob->type_scm = type_scm;
436 f_smob->field_num = field_num;
437 result = scm_new_smob (field_smob_tag, (scm_t_bits) f_smob);
438 gdbscm_init_gsmob (&f_smob->base);
439
440 return result;
441}
442
443/* Return non-zero if SCM is a <gdb:field> object. */
444
445static int
446tyscm_is_field (SCM self)
447{
448 return SCM_SMOB_PREDICATE (field_smob_tag, self);
449}
450
451/* (field? object) -> boolean */
452
453static SCM
454gdbscm_field_p (SCM self)
455{
456 return scm_from_bool (tyscm_is_field (self));
457}
458
459/* Create a new <gdb:field> object that encapsulates field FIELD_NUM
460 in type TYPE_SCM. */
461
462SCM
463tyscm_scm_from_field (SCM type_scm, int field_num)
464{
465 return tyscm_make_field_smob (type_scm, field_num);
466}
467
468/* Returns the <gdb:field> object in SELF.
469 Throws an exception if SELF is not a <gdb:field> object. */
470
471static SCM
472tyscm_get_field_arg_unsafe (SCM self, int arg_pos, const char *func_name)
473{
474 SCM_ASSERT_TYPE (tyscm_is_field (self), self, arg_pos, func_name,
475 field_smob_name);
476
477 return self;
478}
479
480/* Returns a pointer to the field smob of SELF.
481 Throws an exception if SELF is not a <gdb:field> object. */
482
483static field_smob *
484tyscm_get_field_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
485{
486 SCM f_scm = tyscm_get_field_arg_unsafe (self, arg_pos, func_name);
487 field_smob *f_smob = (field_smob *) SCM_SMOB_DATA (f_scm);
488
489 return f_smob;
490}
491
492/* Returns a pointer to the type struct in F_SMOB
493 (the type the field is in). */
494
495static struct type *
496tyscm_field_smob_containing_type (field_smob *f_smob)
497{
498 type_smob *t_smob;
499
500 gdb_assert (tyscm_is_type (f_smob->type_scm));
501 t_smob = (type_smob *) SCM_SMOB_DATA (f_smob->type_scm);
502
503 return t_smob->type;
504}
505
506/* Returns a pointer to the field struct of F_SMOB. */
507
508static struct field *
509tyscm_field_smob_to_field (field_smob *f_smob)
510{
511 struct type *type = tyscm_field_smob_containing_type (f_smob);
512
513 /* This should be non-NULL by construction. */
514 gdb_assert (TYPE_FIELDS (type) != NULL);
515
516 return &TYPE_FIELD (type, f_smob->field_num);
517}
518\f
519/* Type smob accessors. */
520
521/* (type-code <gdb:type>) -> integer
522 Return the code for this type. */
523
524static SCM
525gdbscm_type_code (SCM self)
526{
527 type_smob *t_smob
528 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
529 struct type *type = t_smob->type;
530
531 return scm_from_int (TYPE_CODE (type));
532}
533
534/* (type-fields <gdb:type>) -> list
535 Return a list of all fields. Each element is a <gdb:field> object.
536 This also supports arrays, we return a field list of one element,
537 the range type. */
538
539static SCM
540gdbscm_type_fields (SCM self)
541{
542 type_smob *t_smob
543 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
544 struct type *type = t_smob->type;
545 struct type *containing_type;
546 SCM containing_type_scm, result;
547 int i;
548
549 containing_type = tyscm_get_composite (type);
550 if (containing_type == NULL)
551 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
552 _(not_composite_error));
553
554 /* If SELF is a typedef or reference, we want the underlying type,
555 which is what tyscm_get_composite returns. */
556 if (containing_type == type)
557 containing_type_scm = self;
558 else
559 containing_type_scm = tyscm_scm_from_type (containing_type);
560
561 result = SCM_EOL;
562 for (i = 0; i < TYPE_NFIELDS (containing_type); ++i)
563 result = scm_cons (tyscm_make_field_smob (containing_type_scm, i), result);
564
565 return scm_reverse_x (result, SCM_EOL);
566}
567
568/* (type-tag <gdb:type>) -> string
569 Return the type's tag, or #f. */
570
571static SCM
572gdbscm_type_tag (SCM self)
573{
574 type_smob *t_smob
575 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
576 struct type *type = t_smob->type;
e86ca25f 577 const char *tagname = nullptr;
ed3ef339 578
e86ca25f
TT
579 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
580 || TYPE_CODE (type) == TYPE_CODE_UNION
581 || TYPE_CODE (type) == TYPE_CODE_ENUM)
582 tagname = TYPE_NAME (type);
583
584 if (tagname == nullptr)
ed3ef339 585 return SCM_BOOL_F;
e86ca25f 586 return gdbscm_scm_from_c_string (tagname);
ed3ef339
DE
587}
588
589/* (type-name <gdb:type>) -> string
590 Return the type's name, or #f. */
591
592static SCM
593gdbscm_type_name (SCM self)
594{
595 type_smob *t_smob
596 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
597 struct type *type = t_smob->type;
598
599 if (!TYPE_NAME (type))
600 return SCM_BOOL_F;
601 return gdbscm_scm_from_c_string (TYPE_NAME (type));
602}
603
604/* (type-print-name <gdb:type>) -> string
605 Return the print name of type.
606 TODO: template support elided for now. */
607
608static SCM
609gdbscm_type_print_name (SCM self)
610{
611 type_smob *t_smob
612 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
613 struct type *type = t_smob->type;
3ab692db
PA
614 std::string thetype = tyscm_type_name (type);
615 SCM result = gdbscm_scm_from_c_string (thetype.c_str ());
ed3ef339
DE
616
617 return result;
618}
619
620/* (type-sizeof <gdb:type>) -> integer
621 Return the size of the type represented by SELF, in bytes. */
622
623static SCM
624gdbscm_type_sizeof (SCM self)
625{
626 type_smob *t_smob
627 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
628 struct type *type = t_smob->type;
ed3ef339 629
a70b8144 630 try
ed3ef339
DE
631 {
632 check_typedef (type);
633 }
230d2906 634 catch (const gdb_exception &except)
492d29ea
PA
635 {
636 }
492d29ea 637
ed3ef339
DE
638 /* Ignore exceptions. */
639
640 return scm_from_long (TYPE_LENGTH (type));
641}
642
643/* (type-strip-typedefs <gdb:type>) -> <gdb:type>
644 Return the type, stripped of typedefs. */
645
646static SCM
647gdbscm_type_strip_typedefs (SCM self)
648{
649 type_smob *t_smob
650 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
651 struct type *type = t_smob->type;
ed3ef339 652
a70b8144 653 try
ed3ef339
DE
654 {
655 type = check_typedef (type);
656 }
230d2906 657 catch (const gdb_exception &except)
492d29ea
PA
658 {
659 GDBSCM_HANDLE_GDB_EXCEPTION (except);
660 }
ed3ef339
DE
661
662 return tyscm_scm_from_type (type);
663}
664
665/* Strip typedefs and pointers/reference from a type. Then check that
666 it is a struct, union, or enum type. If not, return NULL. */
667
668static struct type *
669tyscm_get_composite (struct type *type)
670{
ed3ef339
DE
671
672 for (;;)
673 {
a70b8144 674 try
ed3ef339
DE
675 {
676 type = check_typedef (type);
677 }
230d2906 678 catch (const gdb_exception &except)
492d29ea
PA
679 {
680 GDBSCM_HANDLE_GDB_EXCEPTION (except);
681 }
ed3ef339
DE
682
683 if (TYPE_CODE (type) != TYPE_CODE_PTR
684 && TYPE_CODE (type) != TYPE_CODE_REF)
685 break;
686 type = TYPE_TARGET_TYPE (type);
687 }
688
689 /* If this is not a struct, union, or enum type, raise TypeError
690 exception. */
691 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
692 && TYPE_CODE (type) != TYPE_CODE_UNION
693 && TYPE_CODE (type) != TYPE_CODE_ENUM)
694 return NULL;
695
696 return type;
697}
698
699/* Helper for tyscm_array and tyscm_vector. */
700
701static SCM
702tyscm_array_1 (SCM self, SCM n1_scm, SCM n2_scm, int is_vector,
703 const char *func_name)
704{
705 type_smob *t_smob
706 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, func_name);
707 struct type *type = t_smob->type;
708 long n1, n2 = 0;
709 struct type *array = NULL;
ed3ef339
DE
710
711 gdbscm_parse_function_args (func_name, SCM_ARG2, NULL, "l|l",
712 n1_scm, &n1, n2_scm, &n2);
713
714 if (SCM_UNBNDP (n2_scm))
715 {
716 n2 = n1;
717 n1 = 0;
718 }
719
e810d75b 720 if (n2 < n1 - 1) /* Note: An empty array has n2 == n1 - 1. */
ed3ef339
DE
721 {
722 gdbscm_out_of_range_error (func_name, SCM_ARG3,
723 scm_cons (scm_from_long (n1),
724 scm_from_long (n2)),
725 _("Array length must not be negative"));
726 }
727
a70b8144 728 try
ed3ef339
DE
729 {
730 array = lookup_array_range_type (type, n1, n2);
731 if (is_vector)
732 make_vector_type (array);
733 }
230d2906 734 catch (const gdb_exception &except)
492d29ea
PA
735 {
736 GDBSCM_HANDLE_GDB_EXCEPTION (except);
737 }
ed3ef339
DE
738
739 return tyscm_scm_from_type (array);
740}
741
742/* (type-array <gdb:type> [low-bound] high-bound) -> <gdb:type>
743 The array has indices [low-bound,high-bound].
744 If low-bound is not provided zero is used.
745 Return an array type.
746
747 IWBN if the one argument version specified a size, not the high bound.
748 It's too easy to pass one argument thinking it is the size of the array.
749 The current semantics are for compatibility with the Python version.
750 Later we can add #:size. */
751
752static SCM
753gdbscm_type_array (SCM self, SCM n1, SCM n2)
754{
755 return tyscm_array_1 (self, n1, n2, 0, FUNC_NAME);
756}
757
758/* (type-vector <gdb:type> [low-bound] high-bound) -> <gdb:type>
759 The array has indices [low-bound,high-bound].
760 If low-bound is not provided zero is used.
761 Return a vector type.
762
763 IWBN if the one argument version specified a size, not the high bound.
764 It's too easy to pass one argument thinking it is the size of the array.
765 The current semantics are for compatibility with the Python version.
766 Later we can add #:size. */
767
768static SCM
769gdbscm_type_vector (SCM self, SCM n1, SCM n2)
770{
771 return tyscm_array_1 (self, n1, n2, 1, FUNC_NAME);
772}
773
774/* (type-pointer <gdb:type>) -> <gdb:type>
775 Return a <gdb:type> object which represents a pointer to SELF. */
776
777static SCM
778gdbscm_type_pointer (SCM self)
779{
780 type_smob *t_smob
781 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
782 struct type *type = t_smob->type;
ed3ef339 783
a70b8144 784 try
ed3ef339
DE
785 {
786 type = lookup_pointer_type (type);
787 }
230d2906 788 catch (const gdb_exception &except)
492d29ea
PA
789 {
790 GDBSCM_HANDLE_GDB_EXCEPTION (except);
791 }
ed3ef339
DE
792
793 return tyscm_scm_from_type (type);
794}
795
796/* (type-range <gdb:type>) -> (low high)
797 Return the range of a type represented by SELF. The return type is
798 a list. The first element is the low bound, and the second element
799 is the high bound. */
800
801static SCM
802gdbscm_type_range (SCM self)
803{
804 type_smob *t_smob
805 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
806 struct type *type = t_smob->type;
807 SCM low_scm, high_scm;
808 /* Initialize these to appease GCC warnings. */
809 LONGEST low = 0, high = 0;
810
811 SCM_ASSERT_TYPE (TYPE_CODE (type) == TYPE_CODE_ARRAY
812 || TYPE_CODE (type) == TYPE_CODE_STRING
813 || TYPE_CODE (type) == TYPE_CODE_RANGE,
814 self, SCM_ARG1, FUNC_NAME, _("ranged type"));
815
816 switch (TYPE_CODE (type))
817 {
818 case TYPE_CODE_ARRAY:
819 case TYPE_CODE_STRING:
820 low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
821 high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type));
822 break;
823 case TYPE_CODE_RANGE:
824 low = TYPE_LOW_BOUND (type);
825 high = TYPE_HIGH_BOUND (type);
826 break;
827 }
828
829 low_scm = gdbscm_scm_from_longest (low);
830 high_scm = gdbscm_scm_from_longest (high);
831
832 return scm_list_2 (low_scm, high_scm);
833}
834
835/* (type-reference <gdb:type>) -> <gdb:type>
836 Return a <gdb:type> object which represents a reference to SELF. */
837
838static SCM
839gdbscm_type_reference (SCM self)
840{
841 type_smob *t_smob
842 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
843 struct type *type = t_smob->type;
ed3ef339 844
a70b8144 845 try
ed3ef339 846 {
3b224330 847 type = lookup_lvalue_reference_type (type);
ed3ef339 848 }
230d2906 849 catch (const gdb_exception &except)
492d29ea
PA
850 {
851 GDBSCM_HANDLE_GDB_EXCEPTION (except);
852 }
ed3ef339
DE
853
854 return tyscm_scm_from_type (type);
855}
856
857/* (type-target <gdb:type>) -> <gdb:type>
858 Return a <gdb:type> object which represents the target type of SELF. */
859
860static SCM
861gdbscm_type_target (SCM self)
862{
863 type_smob *t_smob
864 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
865 struct type *type = t_smob->type;
866
867 SCM_ASSERT (TYPE_TARGET_TYPE (type), self, SCM_ARG1, FUNC_NAME);
868
869 return tyscm_scm_from_type (TYPE_TARGET_TYPE (type));
870}
871
872/* (type-const <gdb:type>) -> <gdb:type>
873 Return a const-qualified type variant. */
874
875static SCM
876gdbscm_type_const (SCM self)
877{
878 type_smob *t_smob
879 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
880 struct type *type = t_smob->type;
ed3ef339 881
a70b8144 882 try
ed3ef339
DE
883 {
884 type = make_cv_type (1, 0, type, NULL);
885 }
230d2906 886 catch (const gdb_exception &except)
492d29ea
PA
887 {
888 GDBSCM_HANDLE_GDB_EXCEPTION (except);
889 }
ed3ef339
DE
890
891 return tyscm_scm_from_type (type);
892}
893
894/* (type-volatile <gdb:type>) -> <gdb:type>
895 Return a volatile-qualified type variant. */
896
897static SCM
898gdbscm_type_volatile (SCM self)
899{
900 type_smob *t_smob
901 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
902 struct type *type = t_smob->type;
ed3ef339 903
a70b8144 904 try
ed3ef339
DE
905 {
906 type = make_cv_type (0, 1, type, NULL);
907 }
230d2906 908 catch (const gdb_exception &except)
492d29ea
PA
909 {
910 GDBSCM_HANDLE_GDB_EXCEPTION (except);
911 }
ed3ef339
DE
912
913 return tyscm_scm_from_type (type);
914}
915
916/* (type-unqualified <gdb:type>) -> <gdb:type>
917 Return an unqualified type variant. */
918
919static SCM
920gdbscm_type_unqualified (SCM self)
921{
922 type_smob *t_smob
923 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
924 struct type *type = t_smob->type;
ed3ef339 925
a70b8144 926 try
ed3ef339
DE
927 {
928 type = make_cv_type (0, 0, type, NULL);
929 }
230d2906 930 catch (const gdb_exception &except)
492d29ea
PA
931 {
932 GDBSCM_HANDLE_GDB_EXCEPTION (except);
933 }
ed3ef339
DE
934
935 return tyscm_scm_from_type (type);
936}
937\f
938/* Field related accessors of types. */
939
940/* (type-num-fields <gdb:type>) -> integer
941 Return number of fields. */
942
943static SCM
944gdbscm_type_num_fields (SCM self)
945{
946 type_smob *t_smob
947 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
948 struct type *type = t_smob->type;
949
950 type = tyscm_get_composite (type);
951 if (type == NULL)
952 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
953 _(not_composite_error));
954
955 return scm_from_long (TYPE_NFIELDS (type));
956}
957
958/* (type-field <gdb:type> string) -> <gdb:field>
959 Return the <gdb:field> object for the field named by the argument. */
960
961static SCM
962gdbscm_type_field (SCM self, SCM field_scm)
963{
964 type_smob *t_smob
965 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
966 struct type *type = t_smob->type;
ed3ef339
DE
967
968 SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
969 _("string"));
970
971 /* We want just fields of this type, not of base types, so instead of
972 using lookup_struct_elt_type, portions of that function are
973 copied here. */
974
975 type = tyscm_get_composite (type);
976 if (type == NULL)
977 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
978 _(not_composite_error));
979
4c693332
PA
980 {
981 gdb::unique_xmalloc_ptr<char> field = gdbscm_scm_to_c_string (field_scm);
ed3ef339 982
4c693332
PA
983 for (int i = 0; i < TYPE_NFIELDS (type); i++)
984 {
985 const char *t_field_name = TYPE_FIELD_NAME (type, i);
ed3ef339 986
4c693332
PA
987 if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
988 {
989 field.reset (nullptr);
990 return tyscm_make_field_smob (self, i);
991 }
992 }
993 }
ed3ef339
DE
994
995 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, field_scm,
996 _("Unknown field"));
997}
998
999/* (type-has-field? <gdb:type> string) -> boolean
1000 Return boolean indicating if type SELF has FIELD_SCM (a string). */
1001
1002static SCM
1003gdbscm_type_has_field_p (SCM self, SCM field_scm)
1004{
1005 type_smob *t_smob
1006 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1007 struct type *type = t_smob->type;
ed3ef339
DE
1008
1009 SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
1010 _("string"));
1011
1012 /* We want just fields of this type, not of base types, so instead of
1013 using lookup_struct_elt_type, portions of that function are
1014 copied here. */
1015
1016 type = tyscm_get_composite (type);
1017 if (type == NULL)
1018 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
1019 _(not_composite_error));
1020
4c693332
PA
1021 {
1022 gdb::unique_xmalloc_ptr<char> field
1023 = gdbscm_scm_to_c_string (field_scm);
ed3ef339 1024
4c693332
PA
1025 for (int i = 0; i < TYPE_NFIELDS (type); i++)
1026 {
1027 const char *t_field_name = TYPE_FIELD_NAME (type, i);
ed3ef339 1028
4c693332 1029 if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
557e56be 1030 return SCM_BOOL_T;
4c693332
PA
1031 }
1032 }
ed3ef339
DE
1033
1034 return SCM_BOOL_F;
1035}
1036
1037/* (make-field-iterator <gdb:type>) -> <gdb:iterator>
1038 Make a field iterator object. */
1039
1040static SCM
1041gdbscm_make_field_iterator (SCM self)
1042{
1043 type_smob *t_smob
1044 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1045 struct type *type = t_smob->type;
1046 struct type *containing_type;
1047 SCM containing_type_scm;
1048
1049 containing_type = tyscm_get_composite (type);
1050 if (containing_type == NULL)
1051 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
1052 _(not_composite_error));
1053
1054 /* If SELF is a typedef or reference, we want the underlying type,
1055 which is what tyscm_get_composite returns. */
1056 if (containing_type == type)
1057 containing_type_scm = self;
1058 else
1059 containing_type_scm = tyscm_scm_from_type (containing_type);
1060
1061 return gdbscm_make_iterator (containing_type_scm, scm_from_int (0),
1062 tyscm_next_field_x_proc);
1063}
1064
1065/* (type-next-field! <gdb:iterator>) -> <gdb:field>
1066 Return the next field in the iteration through the list of fields of the
1067 type, or (end-of-iteration).
1068 SELF is a <gdb:iterator> object created by gdbscm_make_field_iterator.
1069 This is the next! <gdb:iterator> function, not exported to the user. */
1070
1071static SCM
1072gdbscm_type_next_field_x (SCM self)
1073{
1074 iterator_smob *i_smob;
1075 type_smob *t_smob;
1076 struct type *type;
1077 SCM it_scm, result, progress, object;
798a7429 1078 int field;
ed3ef339
DE
1079
1080 it_scm = itscm_get_iterator_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1081 i_smob = (iterator_smob *) SCM_SMOB_DATA (it_scm);
1082 object = itscm_iterator_smob_object (i_smob);
1083 progress = itscm_iterator_smob_progress (i_smob);
1084
1085 SCM_ASSERT_TYPE (tyscm_is_type (object), object,
1086 SCM_ARG1, FUNC_NAME, type_smob_name);
1087 t_smob = (type_smob *) SCM_SMOB_DATA (object);
1088 type = t_smob->type;
1089
1090 SCM_ASSERT_TYPE (scm_is_signed_integer (progress,
1091 0, TYPE_NFIELDS (type)),
1092 progress, SCM_ARG1, FUNC_NAME, _("integer"));
1093 field = scm_to_int (progress);
1094
1095 if (field < TYPE_NFIELDS (type))
1096 {
1097 result = tyscm_make_field_smob (object, field);
1098 itscm_set_iterator_smob_progress_x (i_smob, scm_from_int (field + 1));
1099 return result;
1100 }
1101
1102 return gdbscm_end_of_iteration ();
1103}
1104\f
1105/* Field smob accessors. */
1106
1107/* (field-name <gdb:field>) -> string
1108 Return the name of this field or #f if there isn't one. */
1109
1110static SCM
1111gdbscm_field_name (SCM self)
1112{
1113 field_smob *f_smob
1114 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1115 struct field *field = tyscm_field_smob_to_field (f_smob);
1116
1117 if (FIELD_NAME (*field))
1118 return gdbscm_scm_from_c_string (FIELD_NAME (*field));
1119 return SCM_BOOL_F;
1120}
1121
1122/* (field-type <gdb:field>) -> <gdb:type>
1123 Return the <gdb:type> object of the field or #f if there isn't one. */
1124
1125static SCM
1126gdbscm_field_type (SCM self)
1127{
1128 field_smob *f_smob
1129 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1130 struct field *field = tyscm_field_smob_to_field (f_smob);
1131
1132 /* A field can have a NULL type in some situations. */
1133 if (FIELD_TYPE (*field))
1134 return tyscm_scm_from_type (FIELD_TYPE (*field));
1135 return SCM_BOOL_F;
1136}
1137
1138/* (field-enumval <gdb:field>) -> integer
1139 For enum values, return its value as an integer. */
1140
1141static SCM
1142gdbscm_field_enumval (SCM self)
1143{
1144 field_smob *f_smob
1145 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1146 struct field *field = tyscm_field_smob_to_field (f_smob);
1147 struct type *type = tyscm_field_smob_containing_type (f_smob);
1148
1149 SCM_ASSERT_TYPE (TYPE_CODE (type) == TYPE_CODE_ENUM,
1150 self, SCM_ARG1, FUNC_NAME, _("enum type"));
1151
1152 return scm_from_long (FIELD_ENUMVAL (*field));
1153}
1154
1155/* (field-bitpos <gdb:field>) -> integer
1156 For bitfields, return its offset in bits. */
1157
1158static SCM
1159gdbscm_field_bitpos (SCM self)
1160{
1161 field_smob *f_smob
1162 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1163 struct field *field = tyscm_field_smob_to_field (f_smob);
1164 struct type *type = tyscm_field_smob_containing_type (f_smob);
1165
1166 SCM_ASSERT_TYPE (TYPE_CODE (type) != TYPE_CODE_ENUM,
1167 self, SCM_ARG1, FUNC_NAME, _("non-enum type"));
1168
1169 return scm_from_long (FIELD_BITPOS (*field));
1170}
1171
1172/* (field-bitsize <gdb:field>) -> integer
1173 Return the size of the field in bits. */
1174
1175static SCM
1176gdbscm_field_bitsize (SCM self)
1177{
1178 field_smob *f_smob
1179 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1180 struct field *field = tyscm_field_smob_to_field (f_smob);
1181
1182 return scm_from_long (FIELD_BITPOS (*field));
1183}
1184
1185/* (field-artificial? <gdb:field>) -> boolean
1186 Return #t if field is artificial. */
1187
1188static SCM
1189gdbscm_field_artificial_p (SCM self)
1190{
1191 field_smob *f_smob
1192 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1193 struct field *field = tyscm_field_smob_to_field (f_smob);
1194
1195 return scm_from_bool (FIELD_ARTIFICIAL (*field));
1196}
1197
1198/* (field-baseclass? <gdb:field>) -> boolean
1199 Return #t if field is a baseclass. */
1200
1201static SCM
1202gdbscm_field_baseclass_p (SCM self)
1203{
1204 field_smob *f_smob
1205 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
ed3ef339
DE
1206 struct type *type = tyscm_field_smob_containing_type (f_smob);
1207
4753d33b 1208 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
ed3ef339
DE
1209 return scm_from_bool (f_smob->field_num < TYPE_N_BASECLASSES (type));
1210 return SCM_BOOL_F;
1211}
1212\f
1213/* Return the type named TYPE_NAME in BLOCK.
1214 Returns NULL if not found.
1215 This routine does not throw an error. */
1216
1217static struct type *
1218tyscm_lookup_typename (const char *type_name, const struct block *block)
1219{
1220 struct type *type = NULL;
ed3ef339 1221
a70b8144 1222 try
ed3ef339 1223 {
61012eef 1224 if (startswith (type_name, "struct "))
ed3ef339 1225 type = lookup_struct (type_name + 7, NULL);
61012eef 1226 else if (startswith (type_name, "union "))
ed3ef339 1227 type = lookup_union (type_name + 6, NULL);
61012eef 1228 else if (startswith (type_name, "enum "))
ed3ef339
DE
1229 type = lookup_enum (type_name + 5, NULL);
1230 else
1231 type = lookup_typename (current_language, get_current_arch (),
1232 type_name, block, 0);
1233 }
230d2906 1234 catch (const gdb_exception &except)
492d29ea
PA
1235 {
1236 return NULL;
1237 }
ed3ef339
DE
1238
1239 return type;
1240}
1241
1242/* (lookup-type name [#:block <gdb:block>]) -> <gdb:type>
1243 TODO: legacy template support left out until needed. */
1244
1245static SCM
1246gdbscm_lookup_type (SCM name_scm, SCM rest)
1247{
1248 SCM keywords[] = { block_keyword, SCM_BOOL_F };
1249 char *name;
1250 SCM block_scm = SCM_BOOL_F;
1251 int block_arg_pos = -1;
1252 const struct block *block = NULL;
1253 struct type *type;
1254
1255 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#O",
1256 name_scm, &name,
1257 rest, &block_arg_pos, &block_scm);
1258
1259 if (block_arg_pos != -1)
1260 {
1261 SCM exception;
1262
1263 block = bkscm_scm_to_block (block_scm, block_arg_pos, FUNC_NAME,
1264 &exception);
1265 if (block == NULL)
1266 {
1267 xfree (name);
1268 gdbscm_throw (exception);
1269 }
1270 }
1271 type = tyscm_lookup_typename (name, block);
1272 xfree (name);
1273
1274 if (type != NULL)
1275 return tyscm_scm_from_type (type);
1276 return SCM_BOOL_F;
1277}
1278\f
1279/* Initialize the Scheme type code. */
1280
1281
1282static const scheme_integer_constant type_integer_constants[] =
1283{
1284#define X(SYM) { #SYM, SYM }
1285 X (TYPE_CODE_BITSTRING),
1286 X (TYPE_CODE_PTR),
1287 X (TYPE_CODE_ARRAY),
1288 X (TYPE_CODE_STRUCT),
1289 X (TYPE_CODE_UNION),
1290 X (TYPE_CODE_ENUM),
1291 X (TYPE_CODE_FLAGS),
1292 X (TYPE_CODE_FUNC),
1293 X (TYPE_CODE_INT),
1294 X (TYPE_CODE_FLT),
1295 X (TYPE_CODE_VOID),
1296 X (TYPE_CODE_SET),
1297 X (TYPE_CODE_RANGE),
1298 X (TYPE_CODE_STRING),
1299 X (TYPE_CODE_ERROR),
1300 X (TYPE_CODE_METHOD),
1301 X (TYPE_CODE_METHODPTR),
1302 X (TYPE_CODE_MEMBERPTR),
1303 X (TYPE_CODE_REF),
1304 X (TYPE_CODE_CHAR),
1305 X (TYPE_CODE_BOOL),
1306 X (TYPE_CODE_COMPLEX),
1307 X (TYPE_CODE_TYPEDEF),
1308 X (TYPE_CODE_NAMESPACE),
1309 X (TYPE_CODE_DECFLOAT),
1310 X (TYPE_CODE_INTERNAL_FUNCTION),
1311#undef X
1312
1313 END_INTEGER_CONSTANTS
1314};
1315
1316static const scheme_function type_functions[] =
1317{
72e02483 1318 { "type?", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_p),
ed3ef339
DE
1319 "\
1320Return #t if the object is a <gdb:type> object." },
1321
72e02483 1322 { "lookup-type", 1, 0, 1, as_a_scm_t_subr (gdbscm_lookup_type),
ed3ef339
DE
1323 "\
1324Return the <gdb:type> object representing string or #f if not found.\n\
1325If block is given then the type is looked for in that block.\n\
1326\n\
1327 Arguments: string [#:block <gdb:block>]" },
1328
72e02483 1329 { "type-code", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_code),
ed3ef339
DE
1330 "\
1331Return the code of the type" },
1332
72e02483 1333 { "type-tag", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_tag),
ed3ef339
DE
1334 "\
1335Return the tag name of the type, or #f if there isn't one." },
1336
72e02483 1337 { "type-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_name),
ed3ef339
DE
1338 "\
1339Return the name of the type as a string, or #f if there isn't one." },
1340
72e02483 1341 { "type-print-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_print_name),
ed3ef339
DE
1342 "\
1343Return the print name of the type as a string." },
1344
72e02483 1345 { "type-sizeof", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_sizeof),
ed3ef339
DE
1346 "\
1347Return the size of the type, in bytes." },
1348
72e02483
PA
1349 { "type-strip-typedefs", 1, 0, 0,
1350 as_a_scm_t_subr (gdbscm_type_strip_typedefs),
ed3ef339
DE
1351 "\
1352Return a type formed by stripping the type of all typedefs." },
1353
72e02483 1354 { "type-array", 2, 1, 0, as_a_scm_t_subr (gdbscm_type_array),
ed3ef339
DE
1355 "\
1356Return a type representing an array of objects of the type.\n\
1357\n\
1358 Arguments: <gdb:type> [low-bound] high-bound\n\
1359 If low-bound is not provided zero is used.\n\
1360 N.B. If only the high-bound parameter is specified, it is not\n\
1361 the array size.\n\
1362 Valid bounds for array indices are [low-bound,high-bound]." },
1363
72e02483 1364 { "type-vector", 2, 1, 0, as_a_scm_t_subr (gdbscm_type_vector),
ed3ef339
DE
1365 "\
1366Return a type representing a vector of objects of the type.\n\
1367Vectors differ from arrays in that if the current language has C-style\n\
1368arrays, vectors don't decay to a pointer to the first element.\n\
1369They are first class values.\n\
1370\n\
1371 Arguments: <gdb:type> [low-bound] high-bound\n\
1372 If low-bound is not provided zero is used.\n\
1373 N.B. If only the high-bound parameter is specified, it is not\n\
1374 the array size.\n\
1375 Valid bounds for array indices are [low-bound,high-bound]." },
1376
72e02483 1377 { "type-pointer", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_pointer),
ed3ef339
DE
1378 "\
1379Return a type of pointer to the type." },
1380
72e02483 1381 { "type-range", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_range),
ed3ef339
DE
1382 "\
1383Return (low high) representing the range for the type." },
1384
72e02483 1385 { "type-reference", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_reference),
ed3ef339
DE
1386 "\
1387Return a type of reference to the type." },
1388
72e02483 1389 { "type-target", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_target),
ed3ef339
DE
1390 "\
1391Return the target type of the type." },
1392
72e02483 1393 { "type-const", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_const),
ed3ef339
DE
1394 "\
1395Return a const variant of the type." },
1396
72e02483 1397 { "type-volatile", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_volatile),
ed3ef339
DE
1398 "\
1399Return a volatile variant of the type." },
1400
72e02483 1401 { "type-unqualified", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_unqualified),
ed3ef339
DE
1402 "\
1403Return a variant of the type without const or volatile attributes." },
1404
72e02483 1405 { "type-num-fields", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_num_fields),
ed3ef339
DE
1406 "\
1407Return the number of fields of the type." },
1408
72e02483 1409 { "type-fields", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_fields),
ed3ef339
DE
1410 "\
1411Return the list of <gdb:field> objects of fields of the type." },
1412
72e02483
PA
1413 { "make-field-iterator", 1, 0, 0,
1414 as_a_scm_t_subr (gdbscm_make_field_iterator),
ed3ef339
DE
1415 "\
1416Return a <gdb:iterator> object for iterating over the fields of the type." },
1417
72e02483 1418 { "type-field", 2, 0, 0, as_a_scm_t_subr (gdbscm_type_field),
ed3ef339
DE
1419 "\
1420Return the field named by string of the type.\n\
1421\n\
1422 Arguments: <gdb:type> string" },
1423
72e02483 1424 { "type-has-field?", 2, 0, 0, as_a_scm_t_subr (gdbscm_type_has_field_p),
ed3ef339
DE
1425 "\
1426Return #t if the type has field named string.\n\
1427\n\
1428 Arguments: <gdb:type> string" },
1429
72e02483 1430 { "field?", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_p),
ed3ef339
DE
1431 "\
1432Return #t if the object is a <gdb:field> object." },
1433
72e02483 1434 { "field-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_name),
ed3ef339
DE
1435 "\
1436Return the name of the field." },
1437
72e02483 1438 { "field-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_type),
ed3ef339
DE
1439 "\
1440Return the type of the field." },
1441
72e02483 1442 { "field-enumval", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_enumval),
ed3ef339
DE
1443 "\
1444Return the enum value represented by the field." },
1445
72e02483 1446 { "field-bitpos", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_bitpos),
ed3ef339
DE
1447 "\
1448Return the offset in bits of the field in its containing type." },
1449
72e02483 1450 { "field-bitsize", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_bitsize),
ed3ef339
DE
1451 "\
1452Return the size of the field in bits." },
1453
72e02483 1454 { "field-artificial?", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_artificial_p),
ed3ef339
DE
1455 "\
1456Return #t if the field is artificial." },
1457
72e02483 1458 { "field-baseclass?", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_baseclass_p),
ed3ef339
DE
1459 "\
1460Return #t if the field is a baseclass." },
1461
1462 END_FUNCTIONS
1463};
1464
1465void
1466gdbscm_initialize_types (void)
1467{
1468 type_smob_tag = gdbscm_make_smob_type (type_smob_name, sizeof (type_smob));
ed3ef339
DE
1469 scm_set_smob_free (type_smob_tag, tyscm_free_type_smob);
1470 scm_set_smob_print (type_smob_tag, tyscm_print_type_smob);
1471 scm_set_smob_equalp (type_smob_tag, tyscm_equal_p_type_smob);
1472
1473 field_smob_tag = gdbscm_make_smob_type (field_smob_name,
1474 sizeof (field_smob));
ed3ef339
DE
1475 scm_set_smob_print (field_smob_tag, tyscm_print_field_smob);
1476
1477 gdbscm_define_integer_constants (type_integer_constants, 1);
1478 gdbscm_define_functions (type_functions, 1);
1479
1480 /* This function is "private". */
1481 tyscm_next_field_x_proc
1482 = scm_c_define_gsubr ("%type-next-field!", 1, 0, 0,
72e02483 1483 as_a_scm_t_subr (gdbscm_type_next_field_x));
ed3ef339
DE
1484 scm_set_procedure_property_x (tyscm_next_field_x_proc,
1485 gdbscm_documentation_symbol,
1486 gdbscm_scm_from_c_string ("\
1487Internal function to assist the type fields iterator."));
1488
1489 block_keyword = scm_from_latin1_keyword ("block");
1490
1491 /* Register an objfile "free" callback so we can properly copy types
1492 associated with the objfile when it's about to be deleted. */
1493 tyscm_objfile_data_key
1494 = register_objfile_data_with_cleanup (save_objfile_types, NULL);
1495
1496 global_types_map = gdbscm_create_eqable_gsmob_ptr_map (tyscm_hash_type_smob,
1497 tyscm_eq_type_smob);
1498}
This page took 0.7177 seconds and 4 git commands to generate.