OSDN Git Service

2007-04-20 Eric Botcazou <ebotcazou@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / ada-tree.h
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-2007, 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  ****************************************************************************/
26
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
33 };
34 #undef DEFTREECODE
35
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 *)GENERIC_NEXT (&%h.t)")))
40
41 {
42   union tree_node GTY((tag ("0"))) t;
43 };
44 struct lang_decl GTY(()) {tree t; };
45 struct lang_type GTY(()) {tree t; };
46
47 /* Define macros to get and set the tree in TYPE_ and DECL_LANG_SPECIFIC.  */
48 #define GET_TYPE_LANG_SPECIFIC(NODE) \
49   (TYPE_LANG_SPECIFIC (NODE) ? TYPE_LANG_SPECIFIC (NODE)->t : NULL_TREE)
50 #define SET_TYPE_LANG_SPECIFIC(NODE, X) \
51  (TYPE_LANG_SPECIFIC (NODE)                     \
52   = (TYPE_LANG_SPECIFIC (NODE)                  \
53      ? TYPE_LANG_SPECIFIC (NODE) : ggc_alloc (sizeof (struct lang_type))))   \
54  ->t = X;
55
56 #define GET_DECL_LANG_SPECIFIC(NODE) \
57   (DECL_LANG_SPECIFIC (NODE) ? DECL_LANG_SPECIFIC (NODE)->t : NULL_TREE)
58 #define SET_DECL_LANG_SPECIFIC(NODE, VALUE)     \
59  (DECL_LANG_SPECIFIC (NODE)                     \
60   = (DECL_LANG_SPECIFIC (NODE)                  \
61      ? DECL_LANG_SPECIFIC (NODE) : ggc_alloc (sizeof (struct lang_decl))))   \
62  ->t = VALUE;
63
64 /* Flags added to GCC type nodes.  */
65
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))
70
71 #define TYPE_FAT_POINTER_P(NODE)  \
72   (TREE_CODE (NODE) == RECORD_TYPE && TYPE_IS_FAT_POINTER_P (NODE))
73
74 /* For integral types and array types, nonzero if this is a packed array type.
75    Such types should not be extended to a larger size.  */
76 #define TYPE_PACKED_ARRAY_TYPE_P(NODE) TYPE_LANG_FLAG_0 (NODE)
77
78 #define TYPE_IS_PACKED_ARRAY_TYPE_P(NODE) \
79   ((TREE_CODE (NODE) == INTEGER_TYPE || TREE_CODE (NODE) == ARRAY_TYPE) \
80    && TYPE_PACKED_ARRAY_TYPE_P (NODE))
81
82 /* For INTEGER_TYPE, nonzero if this is a modular type with a modulus that
83    is not equal to two to the power of its mode's size.  */
84 #define TYPE_MODULAR_P(NODE) TYPE_LANG_FLAG_1 (INTEGER_TYPE_CHECK (NODE))
85
86 /* For ARRAY_TYPE, nonzero if this type corresponds to a dimension of
87    an Ada array other than the first.  */
88 #define TYPE_MULTI_ARRAY_P(NODE)  TYPE_LANG_FLAG_1 (ARRAY_TYPE_CHECK (NODE))
89
90 /* For FUNCTION_TYPE, nonzero if this denotes a function returning an
91    unconstrained array or record.  */
92 #define TYPE_RETURNS_UNCONSTRAINED_P(NODE) \
93   TYPE_LANG_FLAG_1 (FUNCTION_TYPE_CHECK (NODE))
94
95 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this denotes
96    a justified modular type (will only be true for RECORD_TYPE).  */
97 #define TYPE_JUSTIFIED_MODULAR_P(NODE) \
98   TYPE_LANG_FLAG_1 (RECORD_OR_UNION_CHECK (NODE))
99
100 /* Nonzero in an arithmetic subtype if this is a subtype not known to the
101    front-end.  */
102 #define TYPE_EXTRA_SUBTYPE_P(NODE) TYPE_LANG_FLAG_2 (NODE)
103
104 /* Nonzero for composite types if this is a by-reference type.  */
105 #define TYPE_BY_REFERENCE_P(NODE) TYPE_LANG_FLAG_2 (NODE)
106
107 /* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this is the
108    type for an object whose type includes its template in addition to
109    its value (only true for RECORD_TYPE).  */
110 #define TYPE_CONTAINS_TEMPLATE_P(NODE) \
111   TYPE_LANG_FLAG_3 (RECORD_OR_UNION_CHECK (NODE))
112
113 /* For INTEGER_TYPE, nonzero if this really represents a VAX
114    floating-point type.  */
115 #define TYPE_VAX_FLOATING_POINT_P(NODE)  \
116   TYPE_LANG_FLAG_3 (INTEGER_TYPE_CHECK (NODE))
117
118 /* True if NODE is a thin pointer.  */
119 #define TYPE_THIN_POINTER_P(NODE)                       \
120   (POINTER_TYPE_P (NODE)                                \
121    && TREE_CODE (TREE_TYPE (NODE)) == RECORD_TYPE       \
122    && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (NODE)))
123
124 /* True if TYPE is either a fat or thin pointer to an unconstrained
125    array.  */
126 #define TYPE_FAT_OR_THIN_POINTER_P(NODE) \
127   (TYPE_FAT_POINTER_P (NODE) || TYPE_THIN_POINTER_P (NODE))
128
129 /* For INTEGER_TYPEs, nonzero if the type has a biased representation.  */
130 #define TYPE_BIASED_REPRESENTATION_P(NODE) \
131   TYPE_LANG_FLAG_4 (INTEGER_TYPE_CHECK (NODE))
132
133 /* For ARRAY_TYPEs, nonzero if the array type has Convention_Fortran.  */
134 #define TYPE_CONVENTION_FORTRAN_P(NODE) \
135   TYPE_LANG_FLAG_4 (ARRAY_TYPE_CHECK (NODE))
136
137 /* For FUNCTION_TYPEs, nonzero if the function returns by reference.  */
138 #define TYPE_RETURNS_BY_REF_P(NODE) \
139   TYPE_LANG_FLAG_4 (FUNCTION_TYPE_CHECK (NODE))
140
141 /* For FUNCTION_TYPEs, nonzero if function returns by being passed a pointer
142    to a place to store its result.  */
143 #define TYPE_RETURNS_BY_TARGET_PTR_P(NODE) \
144   TYPE_LANG_FLAG_5 (FUNCTION_TYPE_CHECK (NODE))
145
146 /* For VOID_TYPE, ENUMERAL_TYPE, UNION_TYPE, and RECORD_TYPE, nonzero if this
147    is a dummy type, made to correspond to a private or incomplete type.  */
148 #define TYPE_DUMMY_P(NODE) TYPE_LANG_FLAG_4 (NODE)
149
150 /* True if TYPE is such a dummy type.  */
151 #define TYPE_IS_DUMMY_P(NODE) \
152   ((TREE_CODE (NODE) == VOID_TYPE || TREE_CODE (NODE) == RECORD_TYPE    \
153     || TREE_CODE (NODE) == UNION_TYPE || TREE_CODE (NODE) == ENUMERAL_TYPE) \
154    && TYPE_DUMMY_P (NODE))
155
156 /* For an INTEGER_TYPE, nonzero if TYPE_ACTUAL_BOUNDS is present.  */
157 #define TYPE_HAS_ACTUAL_BOUNDS_P(NODE) \
158   TYPE_LANG_FLAG_5 (INTEGER_TYPE_CHECK (NODE))
159
160 /* For a RECORD_TYPE, nonzero if this was made just to supply needed
161    padding or alignment.  */
162 #define TYPE_IS_PADDING_P(NODE) TYPE_LANG_FLAG_5 (RECORD_TYPE_CHECK (NODE))
163
164 /* True if TYPE can alias any other types.  */
165 #define TYPE_UNIVERSAL_ALIASING_P(NODE) TYPE_LANG_FLAG_6 (NODE)
166
167 /* This field is only defined for FUNCTION_TYPE nodes. If the Ada
168    subprogram contains no parameters passed by copy in/copy out then this
169    field is 0. Otherwise it points to a list of nodes used to specify the
170    return values of the out (or in out) parameters that qualify to be passed
171    by copy in copy out.  It is a CONSTRUCTOR.  For a full description of the
172    cico parameter passing mechanism refer to the routine gnat_to_gnu_entity. */
173 #define TYPE_CI_CO_LIST(NODE)  TYPE_LANG_SLOT_1 (FUNCTION_TYPE_CHECK (NODE))
174
175 /* For an INTEGER_TYPE with TYPE_MODULAR_P, this is the value of the
176    modulus. */
177 #define TYPE_MODULUS(NODE) GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
178 #define SET_TYPE_MODULUS(NODE, X)  \
179   SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
180
181 /* For an INTEGER_TYPE that is the TYPE_DOMAIN of some ARRAY_TYPE, points to
182    the type corresponding to the Ada index type.  */
183 #define TYPE_INDEX_TYPE(NODE) \
184   GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
185 #define SET_TYPE_INDEX_TYPE(NODE, X) \
186   SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
187
188 /* For an INTEGER_TYPE with TYPE_VAX_FLOATING_POINT_P, stores the
189    Digits_Value.  */
190 #define TYPE_DIGITS_VALUE(NODE) \
191   GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
192 #define SET_TYPE_DIGITS_VALUE(NODE, X)  \
193   SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
194
195 /* For numeric types, stores the RM_Size of the type.  */
196 #define TYPE_RM_SIZE_NUM(NODE)  TYPE_LANG_SLOT_1 (NUMERICAL_TYPE_CHECK (NODE))
197
198 #define TYPE_RM_SIZE(NODE)                                      \
199   (INTEGRAL_TYPE_P (NODE) || TREE_CODE (NODE) == REAL_TYPE      \
200    ? TYPE_RM_SIZE_NUM (NODE) : 0)
201
202 /* For a RECORD_TYPE that is a fat pointer, point to the type for the
203    unconstrained object.  Likewise for a RECORD_TYPE that is pointed
204    to by a thin pointer.  */
205 #define TYPE_UNCONSTRAINED_ARRAY(NODE)  \
206   GET_TYPE_LANG_SPECIFIC (RECORD_TYPE_CHECK (NODE))
207 #define SET_TYPE_UNCONSTRAINED_ARRAY(NODE, X)  \
208   SET_TYPE_LANG_SPECIFIC (RECORD_TYPE_CHECK (NODE), X)
209
210 /* For other RECORD_TYPEs and all UNION_TYPEs and QUAL_UNION_TYPEs, the Ada
211    size of the object.  This differs from the GCC size in that it does not
212    include any rounding up to the alignment of the type.  */
213 #define TYPE_ADA_SIZE(NODE)   \
214   GET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE))
215 #define SET_TYPE_ADA_SIZE(NODE, X) \
216   SET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE), X)
217
218 /* For an INTEGER_TYPE with TYPE_HAS_ACTUAL_BOUNDS_P or an ARRAY_TYPE, this is
219    the index type that should be used when the actual bounds are required for
220    a template.  This is used in the case of packed arrays.  */
221 #define TYPE_ACTUAL_BOUNDS(NODE)   \
222   GET_TYPE_LANG_SPECIFIC (TREE_CHECK2 (NODE, INTEGER_TYPE, ARRAY_TYPE))
223 #define SET_TYPE_ACTUAL_BOUNDS(NODE, X) \
224   SET_TYPE_LANG_SPECIFIC (TREE_CHECK2 (NODE, INTEGER_TYPE, ARRAY_TYPE), X)
225
226 /* In an UNCONSTRAINED_ARRAY_TYPE, points to the record containing both
227    the template and object.
228
229    ??? We also put this on an ENUMERAL_TYPE that's dummy.  Technically,
230    this is a conflict on the minval field, but there doesn't seem to be
231    simple fix, so we'll live with this kludge for now.  */
232 #define TYPE_OBJECT_RECORD_TYPE(NODE) \
233   (TREE_CHECK2 ((NODE), UNCONSTRAINED_ARRAY_TYPE, ENUMERAL_TYPE)->type.minval)
234
235 /* Nonzero in a FUNCTION_DECL that represents a stubbed function
236    discriminant.  */
237 #define DECL_STUBBED_P(NODE) DECL_LANG_FLAG_0 (FUNCTION_DECL_CHECK (NODE))
238
239 /* Nonzero in a VAR_DECL if it is guaranteed to be constant after having
240    been elaborated and TREE_READONLY is not set on it.  */
241 #define DECL_READONLY_ONCE_ELAB(NODE) DECL_LANG_FLAG_0 (VAR_DECL_CHECK (NODE))
242
243 /* Nonzero if this decl is always used by reference; i.e., an INDIRECT_REF
244    is needed to access the object.  */
245 #define DECL_BY_REF_P(NODE) DECL_LANG_FLAG_1 (NODE)
246
247 /* Nonzero if this decl is a PARM_DECL for an Ada array being passed to a
248    foreign convention subprogram.  */
249 #define DECL_BY_COMPONENT_PTR_P(NODE) DECL_LANG_FLAG_2 (PARM_DECL_CHECK (NODE))
250
251 /* Nonzero in a FIELD_DECL that is a dummy built for some internal reason.  */
252 #define DECL_INTERNAL_P(NODE) DECL_LANG_FLAG_3 (FIELD_DECL_CHECK (NODE))
253
254 /* Nonzero in a FUNCTION_DECL that corresponds to an elaboration procedure.  */
255 #define DECL_ELABORATION_PROC_P(NODE) \
256   DECL_LANG_FLAG_3 (FUNCTION_DECL_CHECK (NODE))
257
258 /* Nonzero if this is a decl for a pointer that points to something which
259    is readonly.  Used mostly for fat pointers.  */
260 #define DECL_POINTS_TO_READONLY_P(NODE) DECL_LANG_FLAG_4 (NODE)
261
262 /* Nonzero in a FIELD_DECL if there was a record rep clause.  */
263 #define DECL_HAS_REP_P(NODE) DECL_LANG_FLAG_5 (FIELD_DECL_CHECK (NODE))
264
265 /* Nonzero in a PARM_DECL if we are to pass by descriptor.  */
266 #define DECL_BY_DESCRIPTOR_P(NODE) DECL_LANG_FLAG_5 (PARM_DECL_CHECK (NODE))
267
268 /* Nonzero in a VAR_DECL if it is a pointer renaming a global object.  */
269 #define DECL_RENAMING_GLOBAL_P(NODE) DECL_LANG_FLAG_5 (VAR_DECL_CHECK (NODE))
270
271 /* In a CONST_DECL, points to a VAR_DECL that is allocatable to
272    memory.  Used when a scalar constant is aliased or has its
273    address taken.  */
274 #define DECL_CONST_CORRESPONDING_VAR(NODE) \
275   GET_DECL_LANG_SPECIFIC (CONST_DECL_CHECK (NODE))
276 #define SET_DECL_CONST_CORRESPONDING_VAR(NODE, X) \
277   SET_DECL_LANG_SPECIFIC (CONST_DECL_CHECK (NODE), X)
278
279 /* In a FIELD_DECL, points to the FIELD_DECL that was the ultimate
280    source of the decl.  */
281 #define DECL_ORIGINAL_FIELD(NODE) \
282   GET_DECL_LANG_SPECIFIC (FIELD_DECL_CHECK (NODE))
283 #define SET_DECL_ORIGINAL_FIELD(NODE, X) \
284   SET_DECL_LANG_SPECIFIC (FIELD_DECL_CHECK (NODE), X)
285
286 /* In a VAR_DECL, points to the object being renamed if the VAR_DECL is a
287    renaming pointer, otherwise 0.  Note that this object is guaranteed to
288    be protected against multiple evaluations.  */
289 #define DECL_RENAMED_OBJECT(NODE) \
290   GET_DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE))
291 #define SET_DECL_RENAMED_OBJECT(NODE, X) \
292   SET_DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE), X)
293
294 /* In a FUNCTION_DECL, points to the stub associated with the function
295    if any, otherwise 0.  */
296 #define DECL_FUNCTION_STUB(NODE) \
297   GET_DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (NODE))
298 #define SET_DECL_FUNCTION_STUB(NODE, X) \
299   SET_DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (NODE), X)
300
301 /* In a FIELD_DECL corresponding to a discriminant, contains the
302    discriminant number.  */
303 #define DECL_DISCRIMINANT_NUMBER(NODE) DECL_INITIAL (FIELD_DECL_CHECK (NODE))
304
305 /* Define fields and macros for statements.
306
307    Start by defining which tree codes are used for statements.  */
308 #define IS_STMT(NODE)           (STATEMENT_CLASS_P (NODE))
309 #define IS_ADA_STMT(NODE)       (IS_STMT (NODE)                         \
310                                  && TREE_CODE (NODE) >= STMT_STMT)
311
312 #define STMT_STMT_STMT(NODE)    TREE_OPERAND_CHECK_CODE (NODE, STMT_STMT, 0)
313 #define LOOP_STMT_TOP_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 0)
314 #define LOOP_STMT_BOT_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 1)
315 #define LOOP_STMT_UPDATE(NODE)  TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 2)
316 #define LOOP_STMT_BODY(NODE)    TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 3)
317 #define LOOP_STMT_LABEL(NODE)   TREE_OPERAND_CHECK_CODE (NODE, LOOP_STMT, 4)
318 #define EXIT_STMT_COND(NODE)    TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 0)
319 #define EXIT_STMT_LABEL(NODE)   TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 1)
320 #define REGION_STMT_BODY(NODE)  TREE_OPERAND_CHECK_CODE (NODE, REGION_STMT, 0)
321 #define REGION_STMT_HANDLE(NODE) TREE_OPERAND_CHECK_CODE (NODE, REGION_STMT, 1)
322 #define REGION_STMT_BLOCK(NODE) TREE_OPERAND_CHECK_CODE (NODE, REGION_STMT, 2)
323 #define HANDLER_STMT_ARG(NODE) TREE_OPERAND_CHECK_CODE (NODE, HANDLER_STMT, 0)
324 #define HANDLER_STMT_LIST(NODE) TREE_OPERAND_CHECK_CODE (NODE, HANDLER_STMT, 1)
325 #define HANDLER_STMT_BLOCK(NODE) TREE_OPERAND_CHECK_CODE(NODE, HANDLER_STMT, 2)