some more warnings
[suif.git] / html / suif1_65.html
blobc53bb7c235db2643cd400fc75d66d32e68d4d3c0
1 <HTML>
2 <HEAD>
3 <!-- This HTML file has been created by texi2html 1.54
4 from suif1.texi on 28 April 1999 -->
6 <TITLE>The SUIF Version 1 Library - Structure Types</TITLE>
7 <link href="suif1_66.html" rel=Next>
8 <link href="suif1_64.html" rel=Previous>
9 <link href="suif1_toc.html" rel=ToC>
11 </HEAD>
12 <BODY>
13 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_64.html">previous</A>, <A HREF="suif1_66.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
14 <P><HR><P>
17 <H2><A NAME="SEC65" HREF="suif1_toc.html#TOC65">Structure and Union Types</A></H2>
18 <P>
19 <A NAME="IDX470"></A>
20 <A NAME="IDX471"></A>
21 <A NAME="IDX472"></A>
22 <A NAME="IDX473"></A>
24 </P>
25 <P>
26 <A NAME="IDX474"></A>
27 <A NAME="IDX475"></A>
28 <A NAME="IDX476"></A>
29 Structure and union types are defined with the <CODE>TYPE_STRUCT</CODE> and
30 <CODE>TYPE_UNION</CODE> operators and use the <CODE>struct_type</CODE> derived type
31 class. Both of these types include a name and a list of fields. The
32 difference between them is that the fields of a union are all stored at
33 the same offset so that only one field may be used at a time, while the
34 fields of a structure are not allowed to overlap. The <CODE>name</CODE>
35 method returns the name of a structure or union type, which should be
36 distinct from the names of other types within the symbol table where it
37 is defined. The name is automatically entered in the lexicon
38 (see section <A HREF="suif1_102.html#SEC102">Lexicon</A>) when it is set with the <CODE>set_name</CODE> method.
40 </P>
41 <P>
42 <A NAME="IDX477"></A>
43 The <CODE>struct_type</CODE> class contains a field to record the total size
44 of the type in bits. The <CODE>set_size</CODE> method is used to assign to
45 this field. Because structure and union types may be used as array
46 elements, they must be able to tile an array without violating any
47 alignment restrictions. This means that extra padding may need to be
48 added at the end of a structure or union. Consequently, the total size
49 of the type may be greater than the sizes of the fields.
51 </P>
52 <P>
53 <A NAME="IDX478"></A>
54 <A NAME="IDX479"></A>
55 <A NAME="IDX480"></A>
56 <A NAME="IDX481"></A>
57 <A NAME="IDX482"></A>
58 <A NAME="IDX483"></A>
59 <A NAME="IDX484"></A>
60 <A NAME="IDX485"></A>
61 The names, types, and offsets of the fields are stored in
62 dynamically-allocated arrays within a <CODE>struct_type</CODE> node. The
63 <CODE>set_num_fields</CODE> method determines the number of fields and thus
64 the size of these arrays. The number of fields may be changed at any
65 time. If necessary, additional space will be allocated. The
66 <CODE>num_fields</CODE> method returns the current number of fields. The
67 <CODE>field_name</CODE>, <CODE>field_type</CODE>, and <CODE>offset</CODE> methods retrieve
68 the field names, types, and offsets, and the <CODE>set_field_name</CODE>,
69 <CODE>set_field_type</CODE>, and <CODE>set_offset</CODE> methods change their
70 values. The fields are numbered beginning with zero. For structures
71 the fields must be in order of increasing offsets. The field offsets
72 for union types should all be zero. The field names are automatically
73 entered in the lexicon (see section <A HREF="suif1_102.html#SEC102">Lexicon</A>).
75 </P>
76 <P>
77 <A NAME="IDX486"></A>
78 <A NAME="IDX487"></A>
79 The <CODE>find_field_by_name</CODE> method can be used to search for a field
80 with a particular name. If successful, it returns the index of the
81 field; otherwise, it returns a value of <CODE>-1</CODE>. The
82 <CODE>find_field_by_offset</CODE> method can also be used for structure types
83 to find the field at a certain offset. If the specified offset is not
84 exactly at the beginning of a field, <CODE>find_field_by_offset</CODE> returns
85 the index of the field containing it and saves the offset within that
86 field in the <CODE>left</CODE> parameter.
88 </P>
90 <P><HR><P>
91 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_64.html">previous</A>, <A HREF="suif1_66.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
92 </BODY>
93 </HTML>