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