]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/atree.h
[Ada] Variable-sized node types
[thirdparty/gcc.git] / gcc / ada / atree.h
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * A T R E E *
6 * *
7 * C Header File *
8 * *
9 * Copyright (C) 1992-2021, Free Software Foundation, Inc. *
10 * *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 3, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING3. If not, go to *
19 * http://www.gnu.org/licenses for a complete copy of the license. *
20 * *
21 * GNAT was originally developed by the GNAT team at New York University. *
22 * Extensive contributions were provided by Ada Core Technologies Inc. *
23 * *
24 ****************************************************************************/
25
26 /* This is the C header that corresponds to the Ada package specification for
27 Atree. It also contains the implementation of inlined functions from the
28 package body for Atree. It was created manually from atree.ads and
29 atree.adb and must be kept synchronized with changes in these files.
30
31 Note that only routines for reading the tree are included, since the tree
32 transformer is not supposed to modify the tree in any way. */
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define Parent atree__parent
39 extern Node_Id Parent (Node_Id);
40
41 #define Original_Node atree__original_node
42 extern Node_Id Original_Node (Node_Id);
43
44 /* Type used for union of Node_Id, List_Id, Elist_Id. */
45 typedef Int Tree_Id;
46
47 /* These two functions can only be used for Node_Id and List_Id values and
48 they work in the C version because Empty = No_List = 0. */
49
50 static Boolean No (Tree_Id);
51 static Boolean Present (Tree_Id);
52
53 INLINE Boolean
54 No (Tree_Id N)
55 {
56 return N == Empty;
57 }
58
59 INLINE Boolean
60 Present (Tree_Id N)
61 {
62 return !No (N);
63 }
64
65 extern Node_Id Parent (Tree_Id);
66
67 #define Current_Error_Node atree__current_error_node
68 extern Node_Id Current_Error_Node;
69
70 // The following code corresponds to the Get_n_Bit_Field functions (for
71 // various n) in package Atree. The low-level getters in sinfo.h call
72 // these even-lower-level getters.
73
74 extern Field_Offset *Node_Offsets_Ptr;
75 extern slot* Slots_Ptr;
76
77 static Union_Id Get_1_Bit_Field(Node_Id N, Field_Offset Offset);
78 static Union_Id Get_2_Bit_Field(Node_Id N, Field_Offset Offset);
79 static Union_Id Get_4_Bit_Field(Node_Id N, Field_Offset Offset);
80 static Union_Id Get_8_Bit_Field(Node_Id N, Field_Offset Offset);
81 static Union_Id Get_32_Bit_Field(Node_Id N, Field_Offset Offset);
82 static Union_Id Get_32_Bit_Field_With_Default
83 (Node_Id N, Field_Offset Offset, Union_Id Default_Value);
84
85 INLINE Union_Id
86 Get_1_Bit_Field(Node_Id N, Field_Offset Offset)
87 {
88 const Field_Offset L = 32;
89 slot_1_bit slot = (Slots_Ptr + (Node_Offsets_Ptr[N] + Offset/L))->slot_1;
90
91 switch (Offset%L)
92 {
93 case 0: return slot.f0;
94 case 1: return slot.f1;
95 case 2: return slot.f2;
96 case 3: return slot.f3;
97 case 4: return slot.f4;
98 case 5: return slot.f5;
99 case 6: return slot.f6;
100 case 7: return slot.f7;
101 case 8: return slot.f8;
102 case 9: return slot.f9;
103 case 10: return slot.f10;
104 case 11: return slot.f11;
105 case 12: return slot.f12;
106 case 13: return slot.f13;
107 case 14: return slot.f14;
108 case 15: return slot.f15;
109 case 16: return slot.f16;
110 case 17: return slot.f17;
111 case 18: return slot.f18;
112 case 19: return slot.f19;
113 case 20: return slot.f20;
114 case 21: return slot.f21;
115 case 22: return slot.f22;
116 case 23: return slot.f23;
117 case 24: return slot.f24;
118 case 25: return slot.f25;
119 case 26: return slot.f26;
120 case 27: return slot.f27;
121 case 28: return slot.f28;
122 case 29: return slot.f29;
123 case 30: return slot.f30;
124 case 31: return slot.f31;
125 default: gcc_assert(false);
126 }
127 }
128
129 INLINE Union_Id
130 Get_2_Bit_Field(Node_Id N, Field_Offset Offset)
131 {
132 const Field_Offset L = 16;
133 slot_2_bit slot = (Slots_Ptr + (Node_Offsets_Ptr[N] + Offset/L))->slot_2;
134
135 switch (Offset%L)
136 {
137 case 0: return slot.f0;
138 case 1: return slot.f1;
139 case 2: return slot.f2;
140 case 3: return slot.f3;
141 case 4: return slot.f4;
142 case 5: return slot.f5;
143 case 6: return slot.f6;
144 case 7: return slot.f7;
145 case 8: return slot.f8;
146 case 9: return slot.f9;
147 case 10: return slot.f10;
148 case 11: return slot.f11;
149 case 12: return slot.f12;
150 case 13: return slot.f13;
151 case 14: return slot.f14;
152 case 15: return slot.f15;
153 default: gcc_assert(false);
154 }
155 }
156
157 INLINE Union_Id
158 Get_4_Bit_Field(Node_Id N, Field_Offset Offset)
159 {
160 const Field_Offset L = 8;
161 slot_4_bit slot = (Slots_Ptr + (Node_Offsets_Ptr[N] + Offset/L))->slot_4;
162
163 switch (Offset%L)
164 {
165 case 0: return slot.f0;
166 case 1: return slot.f1;
167 case 2: return slot.f2;
168 case 3: return slot.f3;
169 case 4: return slot.f4;
170 case 5: return slot.f5;
171 case 6: return slot.f6;
172 case 7: return slot.f7;
173 default: gcc_assert(false);
174 }
175 }
176
177 INLINE Union_Id
178 Get_8_Bit_Field(Node_Id N, Field_Offset Offset)
179 {
180 const Field_Offset L = 4;
181 slot_8_bit slot = (Slots_Ptr + (Node_Offsets_Ptr[N] + Offset/L))->slot_8;
182
183 switch (Offset%L)
184 {
185 case 0: return slot.f0;
186 case 1: return slot.f1;
187 case 2: return slot.f2;
188 case 3: return slot.f3;
189 default: gcc_assert(false);
190 }
191 }
192
193 INLINE Union_Id
194 Get_32_Bit_Field(Node_Id N, Field_Offset Offset)
195 {
196 const Field_Offset L = 1;
197 slot_32_bit slot = (Slots_Ptr + (Node_Offsets_Ptr[N] + Offset/L))->slot_32;
198 return slot;
199 }
200
201 INLINE Union_Id
202 Get_32_Bit_Field_With_Default(Node_Id N, Field_Offset Offset, Union_Id Default_Value)
203 {
204 const Field_Offset L = 1;
205 slot_32_bit slot = (Slots_Ptr + (Node_Offsets_Ptr[N] + Offset/L))->slot_32;
206
207 if (slot == Empty)
208 {
209 return Default_Value;
210 }
211
212 return slot;
213 }
214
215 #ifdef __cplusplus
216 }
217 #endif