1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
9 * Copyright (C) 1992-2009, Free Software Foundation, Inc. *
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 along with GCC; see the file COPYING3. If not see *
19 * <http://www.gnu.org/licenses/>. *
21 * GNAT was originally developed by the GNAT team at New York University. *
22 * Extensive contributions were provided by Ada Core Technologies Inc. *
24 ****************************************************************************/
26 /* The resulting tree type. */
27 union GTY((desc ("0"),
28 chain_next ("(union lang_tree_node *)TREE_CHAIN (&%h.generic)")))
31 union tree_node GTY((tag ("0"),
32 desc ("tree_node_structure (&%h)"))) generic;
35 /* Ada uses the lang_decl and lang_type fields to hold a tree. */
36 struct GTY(()) lang_type { tree t; };
37 struct GTY(()) lang_decl { tree t; };
39 /* Macros to get and set the tree in TYPE_LANG_SPECIFIC. */
40 #define GET_TYPE_LANG_SPECIFIC(NODE) \
41 (TYPE_LANG_SPECIFIC (NODE) ? TYPE_LANG_SPECIFIC (NODE)->t : NULL_TREE)
43 #define SET_TYPE_LANG_SPECIFIC(NODE, X) \
46 if (!TYPE_LANG_SPECIFIC (NODE)) \
47 TYPE_LANG_SPECIFIC (NODE) = GGC_NEW (struct lang_type); \
48 TYPE_LANG_SPECIFIC (NODE)->t = tmp; \
51 /* Macros to get and set the tree in DECL_LANG_SPECIFIC. */
52 #define GET_DECL_LANG_SPECIFIC(NODE) \
53 (DECL_LANG_SPECIFIC (NODE) ? DECL_LANG_SPECIFIC (NODE)->t : NULL_TREE)
55 #define SET_DECL_LANG_SPECIFIC(NODE, X) \
58 if (!DECL_LANG_SPECIFIC (NODE)) \
59 DECL_LANG_SPECIFIC (NODE) = GGC_NEW (struct lang_decl); \
60 DECL_LANG_SPECIFIC (NODE)->t = tmp; \
64 /* Flags added to type nodes. */
66 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this is a
67 record being used as a fat pointer (only true for RECORD_TYPE). */
68 #define TYPE_IS_FAT_POINTER_P(NODE) \
69 TYPE_LANG_FLAG_0 (RECORD_OR_UNION_CHECK (NODE))
71 #define TYPE_FAT_POINTER_P(NODE) \
72 (TREE_CODE (NODE) == RECORD_TYPE && TYPE_IS_FAT_POINTER_P (NODE))
74 /* For integral types and array types, nonzero if this is a packed array type
75 used for bit-packed types. Such types should not be extended to a larger
76 size or validated against a specified size. */
77 #define TYPE_PACKED_ARRAY_TYPE_P(NODE) TYPE_LANG_FLAG_0 (NODE)
79 #define TYPE_IS_PACKED_ARRAY_TYPE_P(NODE) \
80 ((TREE_CODE (NODE) == INTEGER_TYPE || TREE_CODE (NODE) == ARRAY_TYPE) \
81 && TYPE_PACKED_ARRAY_TYPE_P (NODE))
83 /* For INTEGER_TYPE, nonzero if this is a modular type with a modulus that
84 is not equal to two to the power of its mode's size. */
85 #define TYPE_MODULAR_P(NODE) TYPE_LANG_FLAG_1 (INTEGER_TYPE_CHECK (NODE))
87 /* For ARRAY_TYPE, nonzero if this type corresponds to a dimension of
88 an Ada array other than the first. */
89 #define TYPE_MULTI_ARRAY_P(NODE) TYPE_LANG_FLAG_1 (ARRAY_TYPE_CHECK (NODE))
91 /* For FUNCTION_TYPE, nonzero if this denotes a function returning an
92 unconstrained array or record. */
93 #define TYPE_RETURNS_UNCONSTRAINED_P(NODE) \
94 TYPE_LANG_FLAG_1 (FUNCTION_TYPE_CHECK (NODE))
96 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this denotes
97 a justified modular type (will only be true for RECORD_TYPE). */
98 #define TYPE_JUSTIFIED_MODULAR_P(NODE) \
99 TYPE_LANG_FLAG_1 (RECORD_OR_UNION_CHECK (NODE))
101 /* Nonzero in an arithmetic subtype if this is a subtype not known to the
103 #define TYPE_EXTRA_SUBTYPE_P(NODE) TYPE_LANG_FLAG_2 (NODE)
105 /* Nonzero for composite types if this is a by-reference type. */
106 #define TYPE_BY_REFERENCE_P(NODE) TYPE_LANG_FLAG_2 (NODE)
108 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this is the
109 type for an object whose type includes its template in addition to
110 its value (only true for RECORD_TYPE). */
111 #define TYPE_CONTAINS_TEMPLATE_P(NODE) \
112 TYPE_LANG_FLAG_3 (RECORD_OR_UNION_CHECK (NODE))
114 /* For INTEGER_TYPE, nonzero if this really represents a VAX
115 floating-point type. */
116 #define TYPE_VAX_FLOATING_POINT_P(NODE) \
117 TYPE_LANG_FLAG_3 (INTEGER_TYPE_CHECK (NODE))
119 /* True if NODE is a thin pointer. */
120 #define TYPE_THIN_POINTER_P(NODE) \
121 (POINTER_TYPE_P (NODE) \
122 && TREE_CODE (TREE_TYPE (NODE)) == RECORD_TYPE \
123 && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (NODE)))
125 /* True if TYPE is either a fat or thin pointer to an unconstrained
127 #define TYPE_FAT_OR_THIN_POINTER_P(NODE) \
128 (TYPE_FAT_POINTER_P (NODE) || TYPE_THIN_POINTER_P (NODE))
130 /* For INTEGER_TYPEs, nonzero if the type has a biased representation. */
131 #define TYPE_BIASED_REPRESENTATION_P(NODE) \
132 TYPE_LANG_FLAG_4 (INTEGER_TYPE_CHECK (NODE))
134 /* For ARRAY_TYPEs, nonzero if the array type has Convention_Fortran. */
135 #define TYPE_CONVENTION_FORTRAN_P(NODE) \
136 TYPE_LANG_FLAG_4 (ARRAY_TYPE_CHECK (NODE))
138 /* For FUNCTION_TYPEs, nonzero if the function returns by reference. */
139 #define TYPE_RETURNS_BY_REF_P(NODE) \
140 TYPE_LANG_FLAG_4 (FUNCTION_TYPE_CHECK (NODE))
142 /* For VOID_TYPE, ENUMERAL_TYPE, UNION_TYPE, and RECORD_TYPE, nonzero if this
143 is a dummy type, made to correspond to a private or incomplete type. */
144 #define TYPE_DUMMY_P(NODE) TYPE_LANG_FLAG_4 (NODE)
146 /* True if TYPE is such a dummy type. */
147 #define TYPE_IS_DUMMY_P(NODE) \
148 ((TREE_CODE (NODE) == VOID_TYPE || TREE_CODE (NODE) == RECORD_TYPE \
149 || TREE_CODE (NODE) == UNION_TYPE || TREE_CODE (NODE) == ENUMERAL_TYPE) \
150 && TYPE_DUMMY_P (NODE))
152 /* For FUNCTION_TYPEs, nonzero if function returns by being passed a pointer
153 to a place to store its result. */
154 #define TYPE_RETURNS_BY_TARGET_PTR_P(NODE) \
155 TYPE_LANG_FLAG_5 (FUNCTION_TYPE_CHECK (NODE))
157 /* For an INTEGER_TYPE, nonzero if TYPE_ACTUAL_BOUNDS is present. */
158 #define TYPE_HAS_ACTUAL_BOUNDS_P(NODE) \
159 TYPE_LANG_FLAG_5 (INTEGER_TYPE_CHECK (NODE))
161 /* For a RECORD_TYPE, nonzero if this was made just to supply needed
162 padding or alignment. */
163 #define TYPE_IS_PADDING_P(NODE) TYPE_LANG_FLAG_5 (RECORD_TYPE_CHECK (NODE))
165 /* True if TYPE can alias any other types. */
166 #define TYPE_UNIVERSAL_ALIASING_P(NODE) TYPE_LANG_FLAG_6 (NODE)
168 /* This field is only defined for FUNCTION_TYPE nodes. If the Ada subprogram
169 contains no parameters passed by copy in/copy out then this field is zero.
170 Otherwise it points to a list of nodes used to specify the return values
171 of the out (or in out) parameters that qualify to be passed by copy in/
172 copy out. For a full description of the copy in/copy out parameter passing
173 mechanism refer to the routine gnat_to_gnu_entity. */
174 #define TYPE_CI_CO_LIST(NODE) TYPE_LANG_SLOT_1 (FUNCTION_TYPE_CHECK (NODE))
176 /* For numerical types, this is the GCC lower bound of the type. The GCC
177 type system is based on the invariant that an object X of a given type
178 cannot hold at run time a value smaller than its lower bound; otherwise
179 the behavior is undefined. The optimizer takes advantage of this and
180 considers that the assertion X >= LB is always true. */
181 #define TYPE_GCC_MIN_VALUE(NODE) (NUMERICAL_TYPE_CHECK (NODE)->type.minval)
183 /* For numerical types, this is the GCC upper bound of the type. The GCC
184 type system is based on the invariant that an object X of a given type
185 cannot hold at run time a value larger than its upper bound; otherwise
186 the behavior is undefined. The optimizer takes advantage of this and
187 considers that the assertion X <= UB is always true. */
188 #define TYPE_GCC_MAX_VALUE(NODE) (NUMERICAL_TYPE_CHECK (NODE)->type.maxval)
190 /* For numerical types, this holds various RM-defined values. */
191 #define TYPE_RM_VALUES(NODE) TYPE_LANG_SLOT_1 (NUMERICAL_TYPE_CHECK (NODE))
193 /* Macros to get and set the individual values in TYPE_RM_VALUES. */
194 #define TYPE_RM_VALUE(NODE, N) \
195 (TYPE_RM_VALUES (NODE) \
196 ? TREE_VEC_ELT (TYPE_RM_VALUES (NODE), (N)) : NULL_TREE)
198 #define SET_TYPE_RM_VALUE(NODE, N, X) \
201 if (!TYPE_RM_VALUES (NODE)) \
202 TYPE_RM_VALUES (NODE) = make_tree_vec (3); \
203 TREE_VEC_ELT (TYPE_RM_VALUES (NODE), (N)) = tmp; \
206 /* For numerical types, this is the RM size of the type, aka its precision.
207 There is a discrepancy between what is called precision here (and more
208 generally throughout gigi) and what is called precision in the GCC type
209 system: in the former case it's TYPE_RM_SIZE whereas it's TYPE_PRECISION
210 in the latter case. They are not identical because of the need to support
213 These values can be outside the range of values allowed by the RM size
214 but they must nevertheless be valid in the GCC type system, otherwise
215 the optimizer can pretend that they simply don't exist. Therefore they
216 must be within the range of values allowed by the precision in the GCC
217 sense, hence TYPE_PRECISION be set to the Esize, not the RM size. */
218 #define TYPE_RM_SIZE(NODE) TYPE_RM_VALUE ((NODE), 0)
219 #define SET_TYPE_RM_SIZE(NODE, X) SET_TYPE_RM_VALUE ((NODE), 0, (X))
221 /* For numerical types, this is the RM lower bound of the type. There is
222 again a discrepancy between this lower bound and the GCC lower bound,
223 again because of the need to support invalid values.
225 These values can be outside the range of values allowed by the RM lower
226 bound but they must nevertheless be valid in the GCC type system, otherwise
227 the optimizer can pretend that they simply don't exist. Therefore they
228 must be within the range of values allowed by the lower bound in the GCC
229 sense, hence the GCC lower bound be set to that of the base type. */
230 #define TYPE_RM_MIN_VALUE(NODE) TYPE_RM_VALUE ((NODE), 1)
231 #define SET_TYPE_RM_MIN_VALUE(NODE, X) SET_TYPE_RM_VALUE ((NODE), 1, (X))
233 /* For numerical types, this is the RM upper bound of the type. There is
234 again a discrepancy between this upper bound and the GCC upper bound,
235 again because of the need to support invalid values.
237 These values can be outside the range of values allowed by the RM upper
238 bound but they must nevertheless be valid in the GCC type system, otherwise
239 the optimizer can pretend that they simply don't exist. Therefore they
240 must be within the range of values allowed by the upper bound in the GCC
241 sense, hence the GCC upper bound be set to that of the base type. */
242 #define TYPE_RM_MAX_VALUE(NODE) TYPE_RM_VALUE ((NODE), 2)
243 #define SET_TYPE_RM_MAX_VALUE(NODE, X) SET_TYPE_RM_VALUE ((NODE), 2, (X))
245 /* For numerical types, this is the lower bound of the type, i.e. the RM lower
246 bound for language-defined types and the GCC lower bound for others. */
247 #undef TYPE_MIN_VALUE
248 #define TYPE_MIN_VALUE(NODE) \
249 (TYPE_RM_MIN_VALUE (NODE) \
250 ? TYPE_RM_MIN_VALUE (NODE) : TYPE_GCC_MIN_VALUE (NODE))
252 /* For numerical types, this is the upper bound of the type, i.e. the RM upper
253 bound for language-defined types and the GCC upper bound for others. */
254 #undef TYPE_MAX_VALUE
255 #define TYPE_MAX_VALUE(NODE) \
256 (TYPE_RM_MAX_VALUE (NODE) \
257 ? TYPE_RM_MAX_VALUE (NODE) : TYPE_GCC_MAX_VALUE (NODE))
259 /* In an UNCONSTRAINED_ARRAY_TYPE, points to the record containing both
260 the template and object.
262 ??? We also put this on an ENUMERAL_TYPE that's dummy. Technically,
263 this is a conflict on the minval field, but there doesn't seem to be
264 simple fix, so we'll live with this kludge for now. */
265 #define TYPE_OBJECT_RECORD_TYPE(NODE) \
266 (TREE_CHECK2 ((NODE), UNCONSTRAINED_ARRAY_TYPE, ENUMERAL_TYPE)->type.minval)
268 /* For an INTEGER_TYPE with TYPE_MODULAR_P, this is the value of the
270 #define TYPE_MODULUS(NODE) GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
271 #define SET_TYPE_MODULUS(NODE, X) \
272 SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
274 /* For an INTEGER_TYPE with TYPE_VAX_FLOATING_POINT_P, this is the
276 #define TYPE_DIGITS_VALUE(NODE) \
277 GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
278 #define SET_TYPE_DIGITS_VALUE(NODE, X) \
279 SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
281 /* For an INTEGER_TYPE that is the TYPE_DOMAIN of some ARRAY_TYPE, this is
282 the type corresponding to the Ada index type. */
283 #define TYPE_INDEX_TYPE(NODE) \
284 GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
285 #define SET_TYPE_INDEX_TYPE(NODE, X) \
286 SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
288 /* For an INTEGER_TYPE with TYPE_HAS_ACTUAL_BOUNDS_P or an ARRAY_TYPE, this is
289 the index type that should be used when the actual bounds are required for
290 a template. This is used in the case of packed arrays. */
291 #define TYPE_ACTUAL_BOUNDS(NODE) \
292 GET_TYPE_LANG_SPECIFIC (TREE_CHECK2 (NODE, INTEGER_TYPE, ARRAY_TYPE))
293 #define SET_TYPE_ACTUAL_BOUNDS(NODE, X) \
294 SET_TYPE_LANG_SPECIFIC (TREE_CHECK2 (NODE, INTEGER_TYPE, ARRAY_TYPE), X)
296 /* For a RECORD_TYPE that is a fat pointer, point to the type for the
297 unconstrained object. Likewise for a RECORD_TYPE that is pointed
298 to by a thin pointer. */
299 #define TYPE_UNCONSTRAINED_ARRAY(NODE) \
300 GET_TYPE_LANG_SPECIFIC (RECORD_TYPE_CHECK (NODE))
301 #define SET_TYPE_UNCONSTRAINED_ARRAY(NODE, X) \
302 SET_TYPE_LANG_SPECIFIC (RECORD_TYPE_CHECK (NODE), X)
304 /* For other RECORD_TYPEs and all UNION_TYPEs and QUAL_UNION_TYPEs, the Ada
305 size of the object. This differs from the GCC size in that it does not
306 include any rounding up to the alignment of the type. */
307 #define TYPE_ADA_SIZE(NODE) \
308 GET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE))
309 #define SET_TYPE_ADA_SIZE(NODE, X) \
310 SET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE), X)
313 /* Flags added to decl nodes. */
315 /* Nonzero in a FUNCTION_DECL that represents a stubbed function
317 #define DECL_STUBBED_P(NODE) DECL_LANG_FLAG_0 (FUNCTION_DECL_CHECK (NODE))
319 /* Nonzero in a VAR_DECL if it is guaranteed to be constant after having
320 been elaborated and TREE_READONLY is not set on it. */
321 #define DECL_READONLY_ONCE_ELAB(NODE) DECL_LANG_FLAG_0 (VAR_DECL_CHECK (NODE))
323 /* Nonzero if this decl is always used by reference; i.e., an INDIRECT_REF
324 is needed to access the object. */
325 #define DECL_BY_REF_P(NODE) DECL_LANG_FLAG_1 (NODE)
327 /* Nonzero in a FIELD_DECL that is a dummy built for some internal reason. */
328 #define DECL_INTERNAL_P(NODE) DECL_LANG_FLAG_3 (FIELD_DECL_CHECK (NODE))
330 /* Nonzero if this decl is a PARM_DECL for an Ada array being passed to a
331 foreign convention subprogram. */
332 #define DECL_BY_COMPONENT_PTR_P(NODE) DECL_LANG_FLAG_3 (PARM_DECL_CHECK (NODE))
334 /* Nonzero in a FUNCTION_DECL that corresponds to an elaboration procedure. */
335 #define DECL_ELABORATION_PROC_P(NODE) \
336 DECL_LANG_FLAG_3 (FUNCTION_DECL_CHECK (NODE))
338 /* Nonzero if this is a decl for a pointer that points to something which
339 is readonly. Used mostly for fat pointers. */
340 #define DECL_POINTS_TO_READONLY_P(NODE) DECL_LANG_FLAG_4 (NODE)
342 /* Nonzero in a PARM_DECL if we are to pass by descriptor. */
343 #define DECL_BY_DESCRIPTOR_P(NODE) DECL_LANG_FLAG_5 (PARM_DECL_CHECK (NODE))
345 /* Nonzero in a VAR_DECL if it is a pointer renaming a global object. */
346 #define DECL_RENAMING_GLOBAL_P(NODE) DECL_LANG_FLAG_5 (VAR_DECL_CHECK (NODE))
348 /* In a FIELD_DECL corresponding to a discriminant, contains the
349 discriminant number. */
350 #define DECL_DISCRIMINANT_NUMBER(NODE) DECL_INITIAL (FIELD_DECL_CHECK (NODE))
352 /* In a CONST_DECL, points to a VAR_DECL that is allocatable to
353 memory. Used when a scalar constant is aliased or has its
355 #define DECL_CONST_CORRESPONDING_VAR(NODE) \
356 GET_DECL_LANG_SPECIFIC (CONST_DECL_CHECK (NODE))
357 #define SET_DECL_CONST_CORRESPONDING_VAR(NODE, X) \
358 SET_DECL_LANG_SPECIFIC (CONST_DECL_CHECK (NODE), X)
360 /* In a FIELD_DECL, points to the FIELD_DECL that was the ultimate
361 source of the decl. */
362 #define DECL_ORIGINAL_FIELD(NODE) \
363 GET_DECL_LANG_SPECIFIC (FIELD_DECL_CHECK (NODE))
364 #define SET_DECL_ORIGINAL_FIELD(NODE, X) \
365 SET_DECL_LANG_SPECIFIC (FIELD_DECL_CHECK (NODE), X)
367 /* In a VAR_DECL, points to the object being renamed if the VAR_DECL is a
368 renaming pointer, otherwise 0. Note that this object is guaranteed to
369 be protected against multiple evaluations. */
370 #define DECL_RENAMED_OBJECT(NODE) \
371 GET_DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE))
372 #define SET_DECL_RENAMED_OBJECT(NODE, X) \
373 SET_DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE), X)
375 /* In a TYPE_DECL, points to the parallel type if any, otherwise 0. */
376 #define DECL_PARALLEL_TYPE(NODE) \
377 GET_DECL_LANG_SPECIFIC (TYPE_DECL_CHECK (NODE))
378 #define SET_DECL_PARALLEL_TYPE(NODE, X) \
379 SET_DECL_LANG_SPECIFIC (TYPE_DECL_CHECK (NODE), X)
381 /* In a FUNCTION_DECL, points to the stub associated with the function
382 if any, otherwise 0. */
383 #define DECL_FUNCTION_STUB(NODE) \
384 GET_DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (NODE))
385 #define SET_DECL_FUNCTION_STUB(NODE, X) \
386 SET_DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (NODE), X)
388 /* In a PARM_DECL, points to the alternate TREE_TYPE. */
389 #define DECL_PARM_ALT_TYPE(NODE) \
390 GET_DECL_LANG_SPECIFIC (PARM_DECL_CHECK (NODE))
391 #define SET_DECL_PARM_ALT_TYPE(NODE, X) \
392 SET_DECL_LANG_SPECIFIC (PARM_DECL_CHECK (NODE), X)
395 /* Fields and macros for statements. */
396 #define IS_ADA_STMT(NODE) \
397 (STATEMENT_CLASS_P (NODE) && TREE_CODE (NODE) >= STMT_STMT)
399 #define STMT_STMT_STMT(NODE) TREE_OPERAND_CHECK_CODE (NODE, STMT_STMT, 0)
400 #define LOOP_STMT_TOP_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 0)
401 #define LOOP_STMT_BOT_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 1)
402 #define LOOP_STMT_UPDATE(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 2)
403 #define LOOP_STMT_BODY(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 3)
404 #define LOOP_STMT_LABEL(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 4)
405 #define EXIT_STMT_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 0)
406 #define EXIT_STMT_LABEL(NODE) TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 1)