2005-12-26 Anthony Green <green@redhat.com>
[official-gcc.git] / gcc / ada / ada-tree.h
blobbefe25a6de0ffdcf76077b216065933788963a7e
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * A D A - T R E E *
6 * *
7 * C Header File *
8 * *
9 * Copyright (C) 1992-2005 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 2, 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 COPYING. If not, write *
19 * to the Free Software Foundation, 51 Franklin Street, Fifth Floor, *
20 * Boston, MA 02110-1301, USA. *
21 * *
22 * GNAT was originally developed by the GNAT team at New York University. *
23 * Extensive contributions were provided by Ada Core Technologies Inc. *
24 * *
25 ****************************************************************************/
27 /* Ada language-specific GC tree codes. */
28 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
29 enum gnat_tree_code {
30 __DUMMY = LAST_AND_UNUSED_TREE_CODE,
31 #include "ada-tree.def"
32 LAST_GNAT_TREE_CODE
34 #undef DEFTREECODE
36 /* Ada uses the lang_decl and lang_type fields to hold a tree. */
37 union lang_tree_node
38 GTY((desc ("0"),
39 chain_next ("(union lang_tree_node *)TREE_CHAIN (&%h.t)")))
41 union tree_node GTY((tag ("0"))) t;
43 struct lang_decl GTY(()) {tree t; };
44 struct lang_type GTY(()) {tree t; };
46 /* Define macros to get and set the tree in TYPE_ and DECL_LANG_SPECIFIC. */
47 #define GET_TYPE_LANG_SPECIFIC(NODE) \
48 (TYPE_LANG_SPECIFIC (NODE) ? TYPE_LANG_SPECIFIC (NODE)->t : NULL_TREE)
49 #define SET_TYPE_LANG_SPECIFIC(NODE, X) \
50 (TYPE_LANG_SPECIFIC (NODE) \
51 = (TYPE_LANG_SPECIFIC (NODE) \
52 ? TYPE_LANG_SPECIFIC (NODE) : ggc_alloc (sizeof (struct lang_type)))) \
53 ->t = X;
55 #define GET_DECL_LANG_SPECIFIC(NODE) \
56 (DECL_LANG_SPECIFIC (NODE) ? DECL_LANG_SPECIFIC (NODE)->t : NULL_TREE)
57 #define SET_DECL_LANG_SPECIFIC(NODE, VALUE) \
58 (DECL_LANG_SPECIFIC (NODE) \
59 = (DECL_LANG_SPECIFIC (NODE) \
60 ? DECL_LANG_SPECIFIC (NODE) : ggc_alloc (sizeof (struct lang_decl)))) \
61 ->t = VALUE;
63 /* Flags added to GCC type nodes. */
65 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this is a
66 record being used as a fat pointer (only true for RECORD_TYPE). */
67 #define TYPE_IS_FAT_POINTER_P(NODE) \
68 TYPE_LANG_FLAG_0 (RECORD_OR_UNION_CHECK (NODE))
70 #define TYPE_FAT_POINTER_P(NODE) \
71 (TREE_CODE (NODE) == RECORD_TYPE && TYPE_IS_FAT_POINTER_P (NODE))
73 /* For integral types and array types, nonzero if this is a packed array type.
74 Such types should not be extended to a larger size. */
75 #define TYPE_PACKED_ARRAY_TYPE_P(NODE) TYPE_LANG_FLAG_0 (NODE)
77 #define TYPE_IS_PACKED_ARRAY_TYPE_P(NODE) \
78 ((TREE_CODE (NODE) == INTEGER_TYPE || TREE_CODE (NODE) == ARRAY_TYPE) \
79 && TYPE_PACKED_ARRAY_TYPE_P (NODE))
81 /* For INTEGER_TYPE, nonzero if this is a modular type with a modulus that
82 is not equal to two to the power of its mode's size. */
83 #define TYPE_MODULAR_P(NODE) TYPE_LANG_FLAG_1 (INTEGER_TYPE_CHECK (NODE))
85 /* For ARRAY_TYPE, nonzero if this type corresponds to a dimension of
86 an Ada array other than the first. */
87 #define TYPE_MULTI_ARRAY_P(NODE) TYPE_LANG_FLAG_1 (ARRAY_TYPE_CHECK (NODE))
89 /* For FUNCTION_TYPE, nonzero if this denotes a function returning an
90 unconstrained array or record. */
91 #define TYPE_RETURNS_UNCONSTRAINED_P(NODE) \
92 TYPE_LANG_FLAG_1 (FUNCTION_TYPE_CHECK (NODE))
94 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this denotes
95 a justified modular type (will only be true for RECORD_TYPE). */
96 #define TYPE_JUSTIFIED_MODULAR_P(NODE) \
97 TYPE_LANG_FLAG_1 (RECORD_OR_UNION_CHECK (NODE))
99 /* Nonzero in an arithmetic subtype if this is a subtype not known to the
100 front-end. */
101 #define TYPE_EXTRA_SUBTYPE_P(NODE) TYPE_LANG_FLAG_2 (NODE)
103 /* Nonzero for composite types if this is a by-reference type. */
104 #define TYPE_BY_REFERENCE_P(NODE) TYPE_LANG_FLAG_2 (NODE)
106 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this is the
107 type for an object whose type includes its template in addition to
108 its value (only true for RECORD_TYPE). */
109 #define TYPE_CONTAINS_TEMPLATE_P(NODE) \
110 TYPE_LANG_FLAG_3 (RECORD_OR_UNION_CHECK (NODE))
112 /* For INTEGER_TYPE, nonzero if this really represents a VAX
113 floating-point type. */
114 #define TYPE_VAX_FLOATING_POINT_P(NODE) \
115 TYPE_LANG_FLAG_3 (INTEGER_TYPE_CHECK (NODE))
117 /* True if NODE is a thin pointer. */
118 #define TYPE_THIN_POINTER_P(NODE) \
119 (POINTER_TYPE_P (NODE) \
120 && TREE_CODE (TREE_TYPE (NODE)) == RECORD_TYPE \
121 && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (NODE)))
123 /* True if TYPE is either a fat or thin pointer to an unconstrained
124 array. */
125 #define TYPE_FAT_OR_THIN_POINTER_P(NODE) \
126 (TYPE_FAT_POINTER_P (NODE) || TYPE_THIN_POINTER_P (NODE))
128 /* For INTEGER_TYPEs, nonzero if the type has a biased representation. */
129 #define TYPE_BIASED_REPRESENTATION_P(NODE) \
130 TYPE_LANG_FLAG_4 (INTEGER_TYPE_CHECK (NODE))
132 /* For ARRAY_TYPEs, nonzero if the array type has Convention_Fortran. */
133 #define TYPE_CONVENTION_FORTRAN_P(NODE) \
134 TYPE_LANG_FLAG_4 (ARRAY_TYPE_CHECK (NODE))
136 /* For FUNCTION_TYPEs, nonzero if the function returns by reference. */
137 #define TYPE_RETURNS_BY_REF_P(NODE) \
138 TYPE_LANG_FLAG_4 (FUNCTION_TYPE_CHECK (NODE))
140 /* For FUNCTION_TYPEs, nonzero if function returns by being passed a pointer
141 to a place to store its result. */
142 #define TYPE_RETURNS_BY_TARGET_PTR_P(NODE) \
143 TYPE_LANG_FLAG_5 (FUNCTION_TYPE_CHECK (NODE))
145 /* For VOID_TYPE, ENUMERAL_TYPE, UNION_TYPE, and RECORD_TYPE, nonzero if this
146 is a dummy type, made to correspond to a private or incomplete type. */
147 #define TYPE_DUMMY_P(NODE) TYPE_LANG_FLAG_4 (NODE)
149 /* True if TYPE is such a dummy type. */
150 #define TYPE_IS_DUMMY_P(NODE) \
151 ((TREE_CODE (NODE) == VOID_TYPE || TREE_CODE (NODE) == RECORD_TYPE \
152 || TREE_CODE (NODE) == UNION_TYPE || TREE_CODE (NODE) == ENUMERAL_TYPE) \
153 && TYPE_DUMMY_P (NODE))
155 /* For an INTEGER_TYPE, nonzero if TYPE_ACTUAL_BOUNDS is present. */
156 #define TYPE_HAS_ACTUAL_BOUNDS_P(NODE) \
157 TYPE_LANG_FLAG_5 (INTEGER_TYPE_CHECK (NODE))
159 /* For a RECORD_TYPE, nonzero if this was made just to supply needed
160 padding or alignment. */
161 #define TYPE_IS_PADDING_P(NODE) TYPE_LANG_FLAG_5 (RECORD_TYPE_CHECK (NODE))
163 /* For a UNION_TYPE, nonzero if this is an unchecked union. */
164 #define TYPE_UNCHECKED_UNION_P(NODE) TYPE_LANG_FLAG_6 (UNION_TYPE_CHECK (NODE))
166 /* This field is only defined for FUNCTION_TYPE nodes. If the Ada
167 subprogram contains no parameters passed by copy in/copy out then this
168 field is 0. Otherwise it points to a list of nodes used to specify the
169 return values of the out (or in out) parameters that qualify to be passed
170 by copy in copy out. It is a CONSTRUCTOR. For a full description of the
171 cico parameter passing mechanism refer to the routine gnat_to_gnu_entity. */
172 #define TYPE_CI_CO_LIST(NODE) TYPE_LANG_SLOT_1 (FUNCTION_TYPE_CHECK (NODE))
174 /* For an INTEGER_TYPE with TYPE_MODULAR_P, this is the value of the
175 modulus. */
176 #define TYPE_MODULUS(NODE) GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
177 #define SET_TYPE_MODULUS(NODE, X) \
178 SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
180 /* For an INTEGER_TYPE that is the TYPE_DOMAIN of some ARRAY_TYPE, points to
181 the type corresponding to the Ada index type. */
182 #define TYPE_INDEX_TYPE(NODE) \
183 GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
184 #define SET_TYPE_INDEX_TYPE(NODE, X) \
185 SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
187 /* For an INTEGER_TYPE with TYPE_VAX_FLOATING_POINT_P, stores the
188 Digits_Value. */
189 #define TYPE_DIGITS_VALUE(NODE) \
190 GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
191 #define SET_TYPE_DIGITS_VALUE(NODE, X) \
192 SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
194 /* For numeric types, stores the RM_Size of the type. */
195 #define TYPE_RM_SIZE_NUM(NODE) TYPE_LANG_SLOT_1 (NUMERICAL_TYPE_CHECK (NODE))
197 #define TYPE_RM_SIZE(NODE) \
198 (INTEGRAL_TYPE_P (NODE) || TREE_CODE (NODE) == REAL_TYPE \
199 ? TYPE_RM_SIZE_NUM (NODE) : 0)
201 /* For a RECORD_TYPE that is a fat pointer, point to the type for the
202 unconstrained object. Likewise for a RECORD_TYPE that is pointed
203 to by a thin pointer. */
204 #define TYPE_UNCONSTRAINED_ARRAY(NODE) \
205 GET_TYPE_LANG_SPECIFIC (RECORD_TYPE_CHECK (NODE))
206 #define SET_TYPE_UNCONSTRAINED_ARRAY(NODE, X) \
207 SET_TYPE_LANG_SPECIFIC (RECORD_TYPE_CHECK (NODE), X)
209 /* For other RECORD_TYPEs and all UNION_TYPEs and QUAL_UNION_TYPEs, the Ada
210 size of the object. This differs from the GCC size in that it does not
211 include any rounding up to the alignment of the type. */
212 #define TYPE_ADA_SIZE(NODE) \
213 GET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE))
214 #define SET_TYPE_ADA_SIZE(NODE, X) \
215 SET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE), X)
217 /* For an INTEGER_TYPE with TYPE_HAS_ACTUAL_BOUNDS_P or an ARRAY_TYPE, this is
218 the index type that should be used when the actual bounds are required for
219 a template. This is used in the case of packed arrays. */
220 #define TYPE_ACTUAL_BOUNDS(NODE) \
221 GET_TYPE_LANG_SPECIFIC (TREE_CHECK2 (NODE, INTEGER_TYPE, ARRAY_TYPE))
222 #define SET_TYPE_ACTUAL_BOUNDS(NODE, X) \
223 SET_TYPE_LANG_SPECIFIC (TREE_CHECK2 (NODE, INTEGER_TYPE, ARRAY_TYPE), X)
225 /* In an UNCONSTRAINED_ARRAY_TYPE, points to the record containing both
226 the template and object.
228 ??? We also put this on an ENUMERAL_TYPE that's dummy. Technically,
229 this is a conflict on the minval field, but there doesn't seem to be
230 simple fix, so we'll live with this kludge for now. */
231 #define TYPE_OBJECT_RECORD_TYPE(NODE) \
232 (TREE_CHECK2 ((NODE), UNCONSTRAINED_ARRAY_TYPE, ENUMERAL_TYPE)->type.minval)
234 /* Nonzero in a FUNCTION_DECL that represents a stubbed function
235 discriminant. */
236 #define DECL_STUBBED_P(NODE) DECL_LANG_FLAG_0 (FUNCTION_DECL_CHECK (NODE))
238 /* Nonzero if this decl is always used by reference; i.e., an INDIRECT_REF
239 is needed to access the object. */
240 #define DECL_BY_REF_P(NODE) DECL_LANG_FLAG_1 (NODE)
242 /* Nonzero if this decl is a PARM_DECL for an Ada array being passed to a
243 foreign convention subprogram. */
244 #define DECL_BY_COMPONENT_PTR_P(NODE) DECL_LANG_FLAG_2 (PARM_DECL_CHECK (NODE))
246 /* Nonzero in a FIELD_DECL that is a dummy built for some internal reason. */
247 #define DECL_INTERNAL_P(NODE) DECL_LANG_FLAG_3 (FIELD_DECL_CHECK (NODE))
249 /* Nonzero in a FUNCTION_DECL that corresponds to an elaboration procedure. */
250 #define DECL_ELABORATION_PROC_P(NODE) \
251 DECL_LANG_FLAG_3 (FUNCTION_DECL_CHECK (NODE))
253 /* Nonzero if this is a decl for a pointer that points to something which
254 is readonly. Used mostly for fat pointers. */
255 #define DECL_POINTS_TO_READONLY_P(NODE) DECL_LANG_FLAG_4 (NODE)
257 /* Nonzero in a FIELD_DECL if there was a record rep clause. */
258 #define DECL_HAS_REP_P(NODE) DECL_LANG_FLAG_5 (FIELD_DECL_CHECK (NODE))
260 /* Nonzero in a PARM_DECL if we are to pass by descriptor. */
261 #define DECL_BY_DESCRIPTOR_P(NODE) DECL_LANG_FLAG_5 (PARM_DECL_CHECK (NODE))
263 /* Nonzero in a VAR_DECL if it is a pointer renaming a global object. */
264 #define DECL_RENAMING_GLOBAL_P(NODE) DECL_LANG_FLAG_5 (VAR_DECL_CHECK (NODE))
266 /* In a CONST_DECL, points to a VAR_DECL that is allocatable to
267 memory. Used when a scalar constant is aliased or has its
268 address taken. */
269 #define DECL_CONST_CORRESPONDING_VAR(NODE) \
270 GET_DECL_LANG_SPECIFIC (CONST_DECL_CHECK (NODE))
271 #define SET_DECL_CONST_CORRESPONDING_VAR(NODE, X) \
272 SET_DECL_LANG_SPECIFIC (CONST_DECL_CHECK (NODE), X)
274 /* In a FIELD_DECL, points to the FIELD_DECL that was the ultimate
275 source of the decl. */
276 #define DECL_ORIGINAL_FIELD(NODE) \
277 GET_DECL_LANG_SPECIFIC (FIELD_DECL_CHECK (NODE))
278 #define SET_DECL_ORIGINAL_FIELD(NODE, X) \
279 SET_DECL_LANG_SPECIFIC (FIELD_DECL_CHECK (NODE), X)
281 /* In a VAR_DECL, points to the object being renamed if the VAR_DECL is a
282 renaming pointer, otherwise 0. Note that this object is guaranteed to
283 be protected against multiple evaluations. */
284 #define DECL_RENAMED_OBJECT(NODE) \
285 GET_DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE))
286 #define SET_DECL_RENAMED_OBJECT(NODE, X) \
287 SET_DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE), X)
289 /* In a FIELD_DECL corresponding to a discriminant, contains the
290 discriminant number. */
291 #define DECL_DISCRIMINANT_NUMBER(NODE) DECL_INITIAL (FIELD_DECL_CHECK (NODE))
293 /* Define fields and macros for statements.
295 Start by defining which tree codes are used for statements. */
296 #define IS_STMT(NODE) (STATEMENT_CLASS_P (NODE))
297 #define IS_ADA_STMT(NODE) (IS_STMT (NODE) \
298 && TREE_CODE (NODE) >= STMT_STMT)
300 #define STMT_STMT_STMT(NODE) TREE_OPERAND_CHECK_CODE (NODE, STMT_STMT, 0)
301 #define LOOP_STMT_TOP_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 0)
302 #define LOOP_STMT_BOT_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 1)
303 #define LOOP_STMT_UPDATE(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 2)
304 #define LOOP_STMT_BODY(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 3)
305 #define LOOP_STMT_LABEL(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 4)
306 #define EXIT_STMT_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 0)
307 #define EXIT_STMT_LABEL(NODE) TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 1)
308 #define REGION_STMT_BODY(NODE) TREE_OPERAND_CHECK_CODE (NODE, REGION_STMT, 0)
309 #define REGION_STMT_HANDLE(NODE) TREE_OPERAND_CHECK_CODE (NODE, REGION_STMT, 1)
310 #define REGION_STMT_BLOCK(NODE) TREE_OPERAND_CHECK_CODE (NODE, REGION_STMT, 2)
311 #define HANDLER_STMT_ARG(NODE) TREE_OPERAND_CHECK_CODE (NODE, HANDLER_STMT, 0)
312 #define HANDLER_STMT_LIST(NODE) TREE_OPERAND_CHECK_CODE (NODE, HANDLER_STMT, 1)
313 #define HANDLER_STMT_BLOCK(NODE) TREE_OPERAND_CHECK_CODE(NODE, HANDLER_STMT, 2)