1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * G I G I *
6 * *
7 * C Header File *
8 * *
9 * Copyright (C) 1992-2018, 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 see *
19 * <http://www.gnu.org/licenses/>. *
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 /* Declare all functions and types used by gigi. */
27
28 /* Given GNAT_ENTITY, a GNAT defining identifier node, which denotes some Ada
29 entity, this routine returns the equivalent GCC tree for that entity
30 (an ..._DECL node) and associates the ..._DECL node with the input GNAT
31 defining identifier.
32
33 If GNAT_ENTITY is a variable or a constant declaration, GNU_EXPR gives its
34 initial value (in GCC tree form). This is optional for variables.
35 For renamed entities, GNU_EXPR gives the object being renamed.
36
37 DEFINITION is true if this call is intended for a definition. This is used
38 for separate compilation where it is necessary to know whether an external
39 declaration or a definition must be created if the GCC equivalent was not
40 created previously. */
41 extern tree gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr,
42 bool definition);
43
44 /* Similar, but if the returned value is a COMPONENT_REF, return the
45 FIELD_DECL. */
46 extern tree gnat_to_gnu_field_decl (Entity_Id gnat_entity);
47
48 /* Similar, but GNAT_ENTITY is assumed to refer to a GNAT type. Return
49 the GCC type corresponding to that entity. */
50 extern tree gnat_to_gnu_type (Entity_Id gnat_entity);
51
52 /* Update the GCC tree previously built for the profiles involving GNU_TYPE,
53 a dummy type which appears in profiles. */
54 extern void update_profiles_with (tree gnu_type);
55
56 /* Start a new statement group chained to the previous group. */
57 extern void start_stmt_group (void);
58
59 /* Add GNU_STMT to the current statement group. If it is an expression with
60 no effects, it is ignored. */
61 extern void add_stmt (tree gnu_stmt);
62
63 /* Similar, but the statement is always added, regardless of side-effects. */
64 extern void add_stmt_force (tree gnu_stmt);
65
66 /* Like add_stmt, but set the location of GNU_STMT to that of GNAT_NODE. */
67 extern void add_stmt_with_node (tree gnu_stmt, Node_Id gnat_node);
68
69 /* Similar, but the statement is always added, regardless of side-effects. */
70 extern void add_stmt_with_node_force (tree gnu_stmt, Node_Id gnat_node);
71
72 /* Return code corresponding to the current code group. It is normally
73 a STATEMENT_LIST, but may also be a BIND_EXPR or TRY_FINALLY_EXPR if
74 BLOCK or cleanups were set. */
75 extern tree end_stmt_group (void);
76
77 /* Set the BLOCK node corresponding to the current code group to GNU_BLOCK. */
78 extern void set_block_for_group (tree);
79
80 /* Add a declaration statement for GNU_DECL to the current statement group.
81 Get the SLOC to be put onto the statement from GNAT_NODE. */
82 extern void add_decl_expr (tree gnu_decl, Node_Id gnat_node);
83
84 /* Mark nodes rooted at T with TREE_VISITED and types as having their
85 sized gimplified. We use this to indicate all variable sizes and
86 positions in global types may not be shared by any subprogram. */
87 extern void mark_visited (tree t);
88
89 /* This macro calls the above function but short-circuits the common
90 case of a constant to save time and also checks for NULL. */
91 #define MARK_VISITED(EXP) \
92 do { \
93 if((EXP) && !CONSTANT_CLASS_P (EXP)) \
94 mark_visited (EXP); \
95 } while (0)
96
97 /* Finalize the processing of From_Limited_With incomplete types. */
98 extern void finalize_from_limited_with (void);
99
100 /* Return the equivalent type to be used for GNAT_ENTITY, if it's a kind
101 of type (such E_Task_Type) that has a different type which Gigi uses
102 for its representation. If the type does not have a special type for
103 its representation, return GNAT_ENTITY. */
104 extern Entity_Id Gigi_Equivalent_Type (Entity_Id gnat_entity);
105
106 /* Given GNAT_ENTITY, elaborate all expressions that are required to
107 be elaborated at the point of its definition, but do nothing else. */
108 extern void elaborate_entity (Entity_Id gnat_entity);
109
110 /* Get the unpadded version of a GNAT type. */
111 extern tree get_unpadded_type (Entity_Id gnat_entity);
112
113 /* Create a record type that contains a SIZE bytes long field of TYPE with a
114 starting bit position so that it is aligned to ALIGN bits, and leaving at
115 least ROOM bytes free before the field. BASE_ALIGN is the alignment the
116 record is guaranteed to get. GNAT_NODE is used for the position of the
117 associated TYPE_DECL. */
118 extern tree make_aligning_type (tree type, unsigned int align, tree size,
119 unsigned int base_align, int room, Node_Id);
120
121 /* TYPE is a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE that is being used
122 as the field type of a packed record if IN_RECORD is true, or as the
123 component type of a packed array if IN_RECORD is false. See if we can
124 rewrite it either as a type that has a non-BLKmode, which we can pack
125 tighter in the packed record case, or as a smaller type with at most
126 MAX_ALIGN alignment if the value is non-zero. If so, return the new
127 type; if not, return the original type. */
128 extern tree make_packable_type (tree type, bool in_record,
129 unsigned int max_align = 0);
130
131 /* Given a type TYPE, return a new type whose size is appropriate for SIZE.
132 If TYPE is the best type, return it. Otherwise, make a new type. We
133 only support new integral and pointer types. FOR_BIASED is true if
134 we are making a biased type. */
135 extern tree make_type_from_size (tree type, tree size_tree, bool for_biased);
136
137 /* Ensure that TYPE has SIZE and ALIGN. Make and return a new padded type
138 if needed. We have already verified that SIZE and ALIGN are large enough.
139 GNAT_ENTITY is used to name the resulting record and to issue a warning.
140 IS_COMPONENT_TYPE is true if this is being done for the component type of
141 an array. IS_USER_TYPE is true if the original type needs to be completed.
142 DEFINITION is true if this type is being defined. SET_RM_SIZE is true if
143 the RM size of the resulting type is to be set to SIZE too; in this case,
144 the padded type is canonicalized before being returned. */
145 extern tree maybe_pad_type (tree type, tree size, unsigned int align,
146 Entity_Id gnat_entity, bool is_component_type,
147 bool is_user_type, bool definition,
148 bool set_rm_size);
149
150 /* Return true if padded TYPE was built with an RM size. */
151 extern bool pad_type_has_rm_size (tree type);
152
153 /* Return a copy of the padded TYPE but with reverse storage order. */
154 extern tree set_reverse_storage_order_on_pad_type (tree type);
155
156 enum alias_set_op
157 {
158 ALIAS_SET_COPY,
159 ALIAS_SET_SUBSET,
160 ALIAS_SET_SUPERSET
161 };
162
163 /* Relate the alias sets of GNU_NEW_TYPE and GNU_OLD_TYPE according to OP.
164 If this is a multi-dimensional array type, do this recursively.
165
166 OP may be
167 - ALIAS_SET_COPY: the new set is made a copy of the old one.
168 - ALIAS_SET_SUPERSET: the new set is made a superset of the old one.
169 - ALIAS_SET_SUBSET: the new set is made a subset of the old one. */
170 extern void relate_alias_sets (tree gnu_new_type, tree gnu_old_type,
171 enum alias_set_op op);
172
173 /* Given GNAT_ENTITY, an object (constant, variable, parameter, exception)
174 and GNU_TYPE, its corresponding GCC type, set Esize and Alignment to the
175 size and alignment used by Gigi. Prefer SIZE over TYPE_SIZE if non-null.
176 BY_REF is true if the object is used by reference. */
177 extern void annotate_object (Entity_Id gnat_entity, tree gnu_type, tree size,
178 bool by_ref);
179
180 /* Return the variant part of RECORD_TYPE, if any. Otherwise return NULL. */
181 extern tree get_variant_part (tree record_type);
182
183 /* Given a type T, a FIELD_DECL F, and a replacement value R, return a new
184 type with all size expressions that contain F updated by replacing F
185 with R. If F is NULL_TREE, always make a new RECORD_TYPE, even if
186 nothing has changed. */
187 extern tree substitute_in_type (tree t, tree f, tree r);
188
189 /* Return the RM size of GNU_TYPE. This is the actual number of bits
190 needed to represent the object. */
191 extern tree rm_size (tree gnu_type);
192
193 /* Return the name to be used for GNAT_ENTITY. If a type, create a
194 fully-qualified name, possibly with type information encoding.
195 Otherwise, return the name. */
196 extern tree get_entity_name (Entity_Id gnat_entity);
197
198 /* Return an identifier representing the external name to be used for
199 GNAT_ENTITY. If SUFFIX is specified, the name is followed by "___"
200 and the specified suffix. */
201 extern tree create_concat_name (Entity_Id gnat_entity, const char *suffix);
202
203 /* Given GNU_NAME, an IDENTIFIER_NODE containing a name and SUFFIX, a
204 string, return a new IDENTIFIER_NODE that is the concatenation of
205 the name followed by "___" and the specified suffix. */
206 extern tree concat_name (tree gnu_name, const char *suffix);
207
208 /* Initialize data structures of the decl.c module. */
209 extern void init_gnat_decl (void);
210
211 /* Destroy data structures of the decl.c module. */
212 extern void destroy_gnat_decl (void);
213
214 /* Highest number in the front-end node table. */
215 extern int max_gnat_nodes;
216
217 /* True when gigi is being called on an analyzed but unexpanded
218 tree, and the only purpose of the call is to properly annotate
219 types with representation information. */
220 extern bool type_annotate_only;
221
222 /* This structure must be kept synchronized with Call_Back_End. */
223 struct File_Info_Type
224 {
225 File_Name_Type File_Name;
226 Instance_Id Instance;
227 Nat Num_Source_Lines;
228 };
229
230 #ifdef __cplusplus
231 extern "C" {
232 #endif
233
234 /* This is the main program of the back-end. It sets up all the table
235 structures and then generates code. */
236 extern void gigi (Node_Id gnat_root,
237 int max_gnat_node,
238 int number_name,
239 struct Node *nodes_ptr,
240 struct Flags *Flags_Ptr,
241 Node_Id *next_node_ptr,
242 Node_Id *prev_node_ptr,
243 struct Elist_Header *elists_ptr,
244 struct Elmt_Item *elmts_ptr,
245 struct String_Entry *strings_ptr,
246 Char_Code *strings_chars_ptr,
247 struct List_Header *list_headers_ptr,
248 Nat number_file,
249 struct File_Info_Type *file_info_ptr,
250 Entity_Id standard_boolean,
251 Entity_Id standard_integer,
252 Entity_Id standard_character,
253 Entity_Id standard_long_long_float,
254 Entity_Id standard_exception_type,
255 Int gigi_operating_mode);
256
257 #ifdef __cplusplus
258 }
259 #endif
260
261 /* GNAT_NODE is the root of some GNAT tree. Return the root of the
262 GCC tree corresponding to that GNAT tree. */
263 extern tree gnat_to_gnu (Node_Id gnat_node);
264
265 /* Similar to gnat_to_gnu, but discard any object that might be created in
266 the course of the translation of GNAT_NODE, which must be an "external"
267 expression in the sense that it will be elaborated elsewhere. */
268 extern tree gnat_to_gnu_external (Node_Id gnat_node);
269
270 /* GNU_STMT is a statement. We generate code for that statement. */
271 extern void gnat_expand_stmt (tree gnu_stmt);
272
273 /* Generate GIMPLE in place for the expression at *EXPR_P. */
274 extern int gnat_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *);
275
276 /* Do the processing for the declaration of a GNAT_ENTITY, a type. If
277 a separate Freeze node exists, delay the bulk of the processing. Otherwise
278 make a GCC type for GNAT_ENTITY and set up the correspondence. */
279 extern void process_type (Entity_Id gnat_entity);
280
281 /* Convert SLOC into LOCUS. Return true if SLOC corresponds to a source code
282 location and false if it doesn't. If CLEAR_COLUMN is true, set the column
283 information to 0. */
284 extern bool Sloc_to_locus (Source_Ptr Sloc, location_t *locus,
285 bool clear_column = false, const_tree decl = 0);
286
287 /* Post an error message. MSG is the error message, properly annotated.
288 NODE is the node at which to post the error and the node to use for the
289 '&' substitution. */
290 extern void post_error (const char *msg, Node_Id node);
291
292 /* Similar to post_error, but NODE is the node at which to post the error and
293 ENT is the node to use for the '&' substitution. */
294 extern void post_error_ne (const char *msg, Node_Id node, Entity_Id ent);
295
296 /* Similar to post_error_ne, but NUM is the number to use for the '^'. */
297 extern void post_error_ne_num (const char *msg, Node_Id node, Entity_Id ent,
298 int num);
299
300 /* Similar to post_error_ne, but T is a GCC tree representing the number to
301 write. If T represents a constant, the text inside curly brackets in
302 MSG will be output (presumably including a '^'). Otherwise it will not
303 be output and the text inside square brackets will be output instead. */
304 extern void post_error_ne_tree (const char *msg, Node_Id node, Entity_Id ent,
305 tree t);
306
307 /* Similar to post_error_ne_tree, but NUM is a second integer to write. */
308 extern void post_error_ne_tree_2 (const char *msg, Node_Id node, Entity_Id ent,
309 tree t, int num);
310
311 /* Return a label to branch to for the exception type in KIND or Empty
312 if none. */
313 extern Entity_Id get_exception_label (char kind);
314
315 /* If nonzero, pretend we are allocating at global level. */
316 extern int force_global;
317
318 /* The default alignment of "double" floating-point types, i.e. floating
319 point types whose size is equal to 64 bits, or 0 if this alignment is
320 not specifically capped. */
321 extern int double_float_alignment;
322
323 /* The default alignment of "double" or larger scalar types, i.e. scalar
324 types whose size is greater or equal to 64 bits, or 0 if this alignment
325 is not specifically capped. */
326 extern int double_scalar_alignment;
327
328 /* True if floating-point arithmetics may use wider intermediate results. */
329 extern bool fp_arith_may_widen;
330
331 /* Data structures used to represent attributes. */
332
333 enum attrib_type
334 {
335 ATTR_MACHINE_ATTRIBUTE,
336 ATTR_LINK_ALIAS,
337 ATTR_LINK_SECTION,
338 ATTR_LINK_CONSTRUCTOR,
339 ATTR_LINK_DESTRUCTOR,
340 ATTR_THREAD_LOCAL_STORAGE,
341 ATTR_WEAK_EXTERNAL
342 };
343
344 struct attrib
345 {
346 struct attrib *next;
347 enum attrib_type type;
348 tree name;
349 tree args;
350 Node_Id error_point;
351 };
352
353 /* Table of machine-independent internal attributes. */
354 extern const struct attribute_spec gnat_internal_attribute_table[];
355
356 /* Define the entries in the standard data array. */
357 enum standard_datatypes
358 {
359 /* The longest floating-point type. */
360 ADT_longest_float_type,
361
362 /* The type of an exception. */
363 ADT_except_type,
364
365 /* Function type declaration -- void T() */
366 ADT_void_ftype,
367
368 /* Type declaration node <==> typedef void *T() */
369 ADT_ptr_void_ftype,
370
371 /* Type declaration node <==> typedef virtual void *T() */
372 ADT_fdesc_type,
373
374 /* Null pointer for above type. */
375 ADT_null_fdesc,
376
377 /* Value 1 in signed bitsizetype. */
378 ADT_sbitsize_one_node,
379
380 /* Value BITS_PER_UNIT in signed bitsizetype. */
381 ADT_sbitsize_unit_node,
382
383 /* Function declaration node for run-time allocation function. */
384 ADT_malloc_decl,
385
386 /* Function declaration node for run-time freeing function. */
387 ADT_free_decl,
388
389 /* Function declaration node for run-time reallocation function. */
390 ADT_realloc_decl,
391
392 /* Function decl node for 64-bit multiplication with overflow checking. */
393 ADT_mulv64_decl,
394
395 /* Identifier for the name of the _Parent field in tagged record types. */
396 ADT_parent_name_id,
397
398 /* Identifier for the name of the Exception_Data type. */
399 ADT_exception_data_name_id,
400
401 /* Types and decls used by the SJLJ exception mechanism. */
402 ADT_jmpbuf_type,
403 ADT_jmpbuf_ptr_type,
404 ADT_get_jmpbuf_decl,
405 ADT_set_jmpbuf_decl,
406 ADT_get_excptr_decl,
407 ADT_not_handled_by_others_decl,
408 ADT_setjmp_decl,
409 ADT_update_setjmp_buf_decl,
410 ADT_raise_nodefer_decl,
411
412 /* Types and decls used by the ZCX exception mechanism. */
413 ADT_reraise_zcx_decl,
414 ADT_set_exception_parameter_decl,
415 ADT_begin_handler_decl,
416 ADT_end_handler_decl,
417 ADT_unhandled_except_decl,
418 ADT_others_decl,
419 ADT_all_others_decl,
420 ADT_unhandled_others_decl,
421
422 ADT_LAST
423 };
424
425 /* Define kind of exception information associated with raise statements. */
426 enum exception_info_kind
427 {
428 /* Simple exception information: file:line. */
429 exception_simple,
430 /* Range exception information: file:line + index, first, last. */
431 exception_range,
432 /* Column exception information: file:line:column. */
433 exception_column
434 };
435
436 /* Define the inline status of a subprogram. */
437 enum inline_status_t
438 {
439 /* Inlining is suppressed for the subprogram. */
440 is_suppressed,
441 /* No inlining is requested for the subprogram. */
442 is_default,
443 /* Inlining is requested for the subprogram. */
444 is_requested,
445 /* Inlining is strongly requested for the subprogram. */
446 is_prescribed,
447 /* Inlining is required for the subprogram. */
448 is_required
449 };
450
451 extern GTY(()) tree gnat_std_decls[(int) ADT_LAST];
452 extern GTY(()) tree gnat_raise_decls[(int) LAST_REASON_CODE + 1];
453 extern GTY(()) tree gnat_raise_decls_ext[(int) LAST_REASON_CODE + 1];
454
455 #define longest_float_type_node gnat_std_decls[(int) ADT_longest_float_type]
456 #define except_type_node gnat_std_decls[(int) ADT_except_type]
457 #define void_ftype gnat_std_decls[(int) ADT_void_ftype]
458 #define ptr_void_ftype gnat_std_decls[(int) ADT_ptr_void_ftype]
459 #define fdesc_type_node gnat_std_decls[(int) ADT_fdesc_type]
460 #define null_fdesc_node gnat_std_decls[(int) ADT_null_fdesc]
461 #define sbitsize_one_node gnat_std_decls[(int) ADT_sbitsize_one_node]
462 #define sbitsize_unit_node gnat_std_decls[(int) ADT_sbitsize_unit_node]
463 #define malloc_decl gnat_std_decls[(int) ADT_malloc_decl]
464 #define free_decl gnat_std_decls[(int) ADT_free_decl]
465 #define realloc_decl gnat_std_decls[(int) ADT_realloc_decl]
466 #define mulv64_decl gnat_std_decls[(int) ADT_mulv64_decl]
467 #define parent_name_id gnat_std_decls[(int) ADT_parent_name_id]
468 #define exception_data_name_id gnat_std_decls[(int) ADT_exception_data_name_id]
469 #define jmpbuf_type gnat_std_decls[(int) ADT_jmpbuf_type]
470 #define jmpbuf_ptr_type gnat_std_decls[(int) ADT_jmpbuf_ptr_type]
471 #define get_jmpbuf_decl gnat_std_decls[(int) ADT_get_jmpbuf_decl]
472 #define set_jmpbuf_decl gnat_std_decls[(int) ADT_set_jmpbuf_decl]
473 #define get_excptr_decl gnat_std_decls[(int) ADT_get_excptr_decl]
474 #define not_handled_by_others_decl \
475 gnat_std_decls[(int) ADT_not_handled_by_others_decl]
476 #define setjmp_decl gnat_std_decls[(int) ADT_setjmp_decl]
477 #define update_setjmp_buf_decl gnat_std_decls[(int) ADT_update_setjmp_buf_decl]
478 #define raise_nodefer_decl gnat_std_decls[(int) ADT_raise_nodefer_decl]
479 #define reraise_zcx_decl gnat_std_decls[(int) ADT_reraise_zcx_decl]
480 #define set_exception_parameter_decl \
481 gnat_std_decls[(int) ADT_set_exception_parameter_decl]
482 #define begin_handler_decl gnat_std_decls[(int) ADT_begin_handler_decl]
483 #define others_decl gnat_std_decls[(int) ADT_others_decl]
484 #define all_others_decl gnat_std_decls[(int) ADT_all_others_decl]
485 #define unhandled_others_decl gnat_std_decls[(int) ADT_unhandled_others_decl]
486 #define end_handler_decl gnat_std_decls[(int) ADT_end_handler_decl]
487 #define unhandled_except_decl gnat_std_decls[(int) ADT_unhandled_except_decl]
488
489 /* Routines expected by the gcc back-end. They must have exactly the same
490 prototype and names as below. */
491
492 /* Return true if we are in the global binding level. */
493 extern bool global_bindings_p (void);
494
495 /* Enter and exit a new binding level. */
496 extern void gnat_pushlevel (void);
497 extern void gnat_poplevel (void);
498 extern void gnat_zaplevel (void);
499
500 /* Set SUPERCONTEXT of the BLOCK for the current binding level to FNDECL
501 and point FNDECL to this BLOCK. */
502 extern void set_current_block_context (tree fndecl);
503
504 /* Set the jmpbuf_decl for the current binding level to DECL. */
505 extern void set_block_jmpbuf_decl (tree decl);
506
507 /* Get the setjmp_decl, if any, for the current binding level. */
508 extern tree get_block_jmpbuf_decl (void);
509
510 /* Record DECL as belonging to the current lexical scope and use GNAT_NODE
511 for location information and flag propagation. */
512 extern void gnat_pushdecl (tree decl, Node_Id gnat_node);
513
514 /* Initialize the GCC support for exception handling. */
515 extern void gnat_init_gcc_eh (void);
516
517 /* Initialize the GCC support for floating-point operations. */
518 extern void gnat_init_gcc_fp (void);
519
520 /* Install the builtin functions we might need. */
521 extern void gnat_install_builtins (void);
522
523 /* Return an integer type with the number of bits of precision given by
524 PRECISION. UNSIGNEDP is nonzero if the type is unsigned; otherwise
525 it is a signed type. */
526 extern tree gnat_type_for_size (unsigned precision, int unsignedp);
527
528 /* Return a data type that has machine mode MODE. UNSIGNEDP selects
529 an unsigned type; otherwise a signed type is returned. */
530 extern tree gnat_type_for_mode (machine_mode mode, int unsignedp);
531
532 /* Perform final processing on global declarations. */
533 extern void gnat_write_global_declarations (void);
534
535 /* Return the signed or unsigned version of TYPE_NODE, a scalar type, the
536 signedness being specified by UNSIGNEDP. */
537 extern tree gnat_signed_or_unsigned_type_for (int unsignedp, tree type_node);
538
539 /* Return 1 if the types T1 and T2 are compatible, i.e. if they can be
540 transparently converted to each other. */
541 extern int gnat_types_compatible_p (tree t1, tree t2);
542
543 /* Return true if EXPR is a useless type conversion. */
544 extern bool gnat_useless_type_conversion (tree expr);
545
546 /* Return true if T, a {FUNCTION,METHOD}_TYPE, has the specified flags. */
547 extern bool fntype_same_flags_p (const_tree, tree, bool, bool, bool);
548
549 /* Create an expression whose value is that of EXPR,
550 converted to type TYPE. The TREE_TYPE of the value
551 is always TYPE. This function implements all reasonable
552 conversions; callers should filter out those that are
553 not permitted by the language being compiled. */
554 extern tree convert (tree type, tree expr);
555
556 /* Create an expression whose value is that of EXPR converted to the common
557 index type, which is sizetype. */
558 extern tree convert_to_index_type (tree expr);
559
560 /* Routines created solely for the tree translator's sake. Their prototypes
561 can be changed as desired. */
562
563 /* Initialize data structures of the utils.c module. */
564 extern void init_gnat_utils (void);
565
566 /* Destroy data structures of the utils.c module. */
567 extern void destroy_gnat_utils (void);
568
569 /* GNAT_ENTITY is a GNAT tree node for a defining identifier.
570 GNU_DECL is the GCC tree which is to be associated with
571 GNAT_ENTITY. Such gnu tree node is always an ..._DECL node.
572 If NO_CHECK is nonzero, the latter check is suppressed.
573 If GNU_DECL is zero, a previous association is to be reset. */
574 extern void save_gnu_tree (Entity_Id gnat_entity, tree gnu_decl,
575 bool no_check);
576
577 /* GNAT_ENTITY is a GNAT tree node for a defining identifier.
578 Return the ..._DECL node that was associated with it. If there is no tree
579 node associated with GNAT_ENTITY, abort. */
580 extern tree get_gnu_tree (Entity_Id gnat_entity);
581
582 /* Return nonzero if a GCC tree has been associated with GNAT_ENTITY. */
583 extern bool present_gnu_tree (Entity_Id gnat_entity);
584
585 /* Make a dummy type corresponding to GNAT_TYPE. */
586 extern tree make_dummy_type (Entity_Id gnat_type);
587
588 /* Return the dummy type that was made for GNAT_TYPE, if any. */
589 extern tree get_dummy_type (Entity_Id gnat_type);
590
591 /* Build dummy fat and thin pointer types whose designated type is specified
592 by GNAT_DESIG_TYPE/GNU_DESIG_TYPE and attach them to the latter. */
593 extern void build_dummy_unc_pointer_types (Entity_Id gnat_desig_type,
594 tree gnu_desig_type);
595
596 /* Record TYPE as a builtin type for Ada. NAME is the name of the type.
597 ARTIFICIAL_P is true if the type was generated by the compiler. */
598 extern void record_builtin_type (const char *name, tree type,
599 bool artificial_p);
600
601 /* Finish constructing the character type CHAR_TYPE. */
602 extern void finish_character_type (tree char_type);
603
604 /* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
605 finish constructing the record type as a fat pointer type. */
606 extern void finish_fat_pointer_type (tree record_type, tree field_list);
607
608 /* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
609 finish constructing the record or union type. If REP_LEVEL is zero, this
610 record has no representation clause and so will be entirely laid out here.
611 If REP_LEVEL is one, this record has a representation clause and has been
612 laid out already; only set the sizes and alignment. If REP_LEVEL is two,
613 this record is derived from a parent record and thus inherits its layout;
614 only make a pass on the fields to finalize them. DEBUG_INFO_P is true if
615 additional debug info needs to be output for this type. */
616 extern void finish_record_type (tree record_type, tree field_list,
617 int rep_level, bool debug_info_p);
618
619 /* Wrap up compilation of RECORD_TYPE, i.e. output additional debug info
620 associated with it. It need not be invoked directly in most cases as
621 finish_record_type takes care of doing so. */
622 extern void rest_of_record_type_compilation (tree record_type);
623
624 /* Append PARALLEL_TYPE on the chain of parallel types for TYPE. */
625 extern void add_parallel_type (tree type, tree parallel_type);
626
627 /* Return a copy of TYPE, but safe to modify in any way. */
628 extern tree copy_type (tree type);
629
630 /* Return a subtype of sizetype with range MIN to MAX and whose
631 TYPE_INDEX_TYPE is INDEX. GNAT_NODE is used for the position
632 of the associated TYPE_DECL. */
633 extern tree create_index_type (tree min, tree max, tree index,
634 Node_Id gnat_node);
635
636 /* Return a subtype of TYPE with range MIN to MAX. If TYPE is NULL,
637 sizetype is used. */
638 extern tree create_range_type (tree type, tree min, tree max);
639
640 /* Return an extra subtype of TYPE with range MIN to MAX. */
641 extern tree create_extra_subtype (tree type, tree min, tree max);
642
643 /* Return a TYPE_DECL node suitable for the TYPE_STUB_DECL field of TYPE.
644 NAME gives the name of the type to be used in the declaration. */
645 extern tree create_type_stub_decl (tree name, tree type);
646
647 /* Return a TYPE_DECL node for TYPE. NAME gives the name of the type to be
648 used in the declaration. ARTIFICIAL_P is true if the declaration was
649 generated by the compiler. DEBUG_INFO_P is true if we need to write
650 debug information about this type. GNAT_NODE is used for the position
651 of the decl. */
652 extern tree create_type_decl (tree name, tree type, bool artificial_p,
653 bool debug_info_p, Node_Id gnat_node);
654
655 /* Return a VAR_DECL or CONST_DECL node.
656
657 NAME gives the name of the variable. ASM_NAME is its assembler name
658 (if provided). TYPE is its data type (a GCC ..._TYPE node). INIT is
659 the GCC tree for an optional initial expression; NULL_TREE if none.
660
661 CONST_FLAG is true if this variable is constant, in which case we might
662 return a CONST_DECL node unless CONST_DECL_ALLOWED_P is false.
663
664 PUBLIC_FLAG is true if this is for a reference to a public entity or for a
665 definition to be made visible outside of the current compilation unit, for
666 instance variable definitions in a package specification.
667
668 EXTERN_FLAG is true when processing an external variable declaration (as
669 opposed to a definition: no storage is to be allocated for the variable).
670
671 STATIC_FLAG is only relevant when not at top level and indicates whether
672 to always allocate storage to the variable.
673
674 VOLATILE_FLAG is true if this variable is declared as volatile.
675
676 ARTIFICIAL_P is true if the variable was generated by the compiler.
677
678 DEBUG_INFO_P is true if we need to write debug information for it.
679
680 ATTR_LIST is the list of attributes to be attached to the variable.
681
682 GNAT_NODE is used for the position of the decl. */
683 extern tree create_var_decl (tree name, tree asm_name, tree type, tree init,
684 bool const_flag, bool public_flag,
685 bool extern_flag, bool static_flag,
686 bool volatile_flag,
687 bool artificial_p, bool debug_info_p,
688 struct attrib *attr_list, Node_Id gnat_node,
689 bool const_decl_allowed_p = true);
690
691 /* Return a FIELD_DECL node. NAME is the field's name, TYPE is its type and
692 RECORD_TYPE is the type of the enclosing record. If SIZE is nonzero, it
693 is the specified size of the field. If POS is nonzero, it is the bit
694 position. PACKED is 1 if the enclosing record is packed, -1 if it has
695 Component_Alignment of Storage_Unit. If ADDRESSABLE is nonzero, it
696 means we are allowed to take the address of the field; if it is negative,
697 we should not make a bitfield, which is used by make_aligning_type. */
698 extern tree create_field_decl (tree name, tree type, tree record_type,
699 tree size, tree pos, int packed,
700 int addressable);
701
702 /* Return a PARM_DECL node with NAME and TYPE. */
703 extern tree create_param_decl (tree name, tree type);
704
705 /* Return a LABEL_DECL with NAME. GNAT_NODE is used for the position of
706 the decl. */
707 extern tree create_label_decl (tree name, Node_Id gnat_node);
708
709 /* Return a FUNCTION_DECL node. NAME is the name of the subprogram, ASM_NAME
710 its assembler name, TYPE its type (a FUNCTION_TYPE node), PARAM_DECL_LIST
711 the list of its parameters (a list of PARM_DECL nodes chained through the
712 DECL_CHAIN field).
713
714 INLINE_STATUS describes the inline flags to be set on the FUNCTION_DECL.
715
716 PUBLIC_FLAG is true if this is for a reference to a public entity or for a
717 definition to be made visible outside of the current compilation unit.
718
719 EXTERN_FLAG is true when processing an external subprogram declaration.
720
721 ARTIFICIAL_P is true if the subprogram was generated by the compiler.
722
723 DEBUG_INFO_P is true if we need to write debug information for it.
724
725 DEFINITION is true if the subprogram is to be considered as a definition.
726
727 ATTR_LIST is the list of attributes to be attached to the subprogram.
728
729 GNAT_NODE is used for the position of the decl. */
730 extern tree create_subprog_decl (tree name, tree asm_name, tree type,
731 tree param_decl_list,
732 enum inline_status_t inline_status,
733 bool public_flag, bool extern_flag,
734 bool artificial_p, bool debug_info_p,
735 bool definition, struct attrib *attr_list,
736 Node_Id gnat_node);
737
738 /* Given a subprogram declaration DECL, its assembler name and its type,
739 finish constructing the subprogram declaration from ASM_NAME and TYPE. */
740 extern void finish_subprog_decl (tree decl, tree asm_name, tree type);
741
742 /* Process the attributes in ATTR_LIST for NODE, which is either a DECL or
743 a TYPE. If IN_PLACE is true, the tree pointed to by NODE should not be
744 changed. GNAT_NODE is used for the position of error messages. */
745 extern void process_attributes (tree *node, struct attrib **attr_list,
746 bool in_place, Node_Id gnat_node);
747
748 /* Set up the framework for generating code for SUBPROG_DECL, a subprogram
749 body. This routine needs to be invoked before processing the declarations
750 appearing in the subprogram. */
751 extern void begin_subprog_body (tree subprog_decl);
752
753 /* Finish translating the current subprogram and set its BODY. */
754 extern void end_subprog_body (tree body);
755
756 /* Wrap up compilation of SUBPROG_DECL, a subprogram body. */
757 extern void rest_of_subprog_body_compilation (tree subprog_decl);
758
759 /* Build a template of type TEMPLATE_TYPE from the array bounds of ARRAY_TYPE.
760 EXPR is an expression that we can use to locate any PLACEHOLDER_EXPRs.
761 Return a constructor for the template. */
762 extern tree build_template (tree template_type, tree array_type, tree expr);
763
764 /* Build a type to be used to represent an aliased object whose nominal type
765 is an unconstrained array. This consists of a RECORD_TYPE containing a
766 field of TEMPLATE_TYPE and a field of OBJECT_TYPE, which is an ARRAY_TYPE.
767 If ARRAY_TYPE is that of an unconstrained array, this is used to represent
768 an arbitrary unconstrained object. Use NAME as the name of the record.
769 DEBUG_INFO_P is true if we need to write debug information for the type. */
770 extern tree build_unc_object_type (tree template_type, tree object_type,
771 tree name, bool debug_info_p);
772
773 /* Same as build_unc_object_type, but taking a thin or fat pointer type
774 instead of the template type. */
775 extern tree build_unc_object_type_from_ptr (tree thin_fat_ptr_type,
776 tree object_type, tree name,
777 bool debug_info_p);
778
779 /* Update anything previously pointing to OLD_TYPE to point to NEW_TYPE. In
780 the normal case this is just two adjustments, but we have more to do
781 if NEW is an UNCONSTRAINED_ARRAY_TYPE. */
782 extern void update_pointer_to (tree old_type, tree new_type);
783
784 /* EXP is an expression for the size of an object. If this size contains
785 discriminant references, replace them with the maximum (if MAX_P) or
786 minimum (if !MAX_P) possible value of the discriminant. */
787 extern tree max_size (tree exp, bool max_p);
788
789 /* Remove all conversions that are done in EXP. This includes converting
790 from a padded type or to a left-justified modular type. If TRUE_ADDRESS
791 is true, always return the address of the containing object even if
792 the address is not bit-aligned. */
793 extern tree remove_conversions (tree exp, bool true_address);
794
795 /* If EXP's type is an UNCONSTRAINED_ARRAY_TYPE, return an expression that
796 refers to the underlying array. If its type has TYPE_CONTAINS_TEMPLATE_P,
797 likewise return an expression pointing to the underlying array. */
798 extern tree maybe_unconstrained_array (tree exp);
799
800 /* Return an expression that does an unchecked conversion of EXPR to TYPE.
801 If NOTRUNC_P is true, truncation operations should be suppressed. */
802 extern tree unchecked_convert (tree type, tree expr, bool notrunc_p);
803
804 /* Return the appropriate GCC tree code for the specified GNAT_TYPE,
805 the latter being a record type as predicated by Is_Record_Type. */
806 extern enum tree_code tree_code_for_record_type (Entity_Id gnat_type);
807
808 /* Return true if GNAT_TYPE is a "double" floating-point type, i.e. whose
809 size is equal to 64 bits, or an array of such a type. Set ALIGN_CLAUSE
810 according to the presence of an alignment clause on the type or, if it
811 is an array, on the component type. */
812 extern bool is_double_float_or_array (Entity_Id gnat_type,
813 bool *align_clause);
814
815 /* Return true if GNAT_TYPE is a "double" or larger scalar type, i.e. whose
816 size is greater or equal to 64 bits, or an array of such a type. Set
817 ALIGN_CLAUSE according to the presence of an alignment clause on the
818 type or, if it is an array, on the component type. */
819 extern bool is_double_scalar_or_array (Entity_Id gnat_type,
820 bool *align_clause);
821
822 /* Return true if GNU_TYPE is suitable as the type of a non-aliased
823 component of an aggregate type. */
824 extern bool type_for_nonaliased_component_p (tree gnu_type);
825
826 /* Return true if TYPE is a smaller form of ORIG_TYPE. */
827 extern bool smaller_form_type_p (tree type, tree orig_type);
828
829 /* Return the base type of TYPE. */
830 extern tree get_base_type (tree type);
831
832 /* EXP is a GCC tree representing an address. See if we can find how
833 strictly the object at that address is aligned. Return that alignment
834 strictly the object at that address is aligned. Return that alignment
835 in bits. If we don't know anything about the alignment, return 0. */
836 extern unsigned int known_alignment (tree exp);
837
838 /* Return true if VALUE is a multiple of FACTOR. FACTOR must be a power
839 of 2. */
840 extern bool value_factor_p (tree value, HOST_WIDE_INT factor);
841
842 /* Build an atomic load for the underlying atomic object in SRC. SYNC is
843 true if the load requires synchronization. */
844 extern tree build_atomic_load (tree src, bool sync);
845
846 /* Build an atomic store from SRC to the underlying atomic object in DEST.
847 SYNC is true if the store requires synchronization. */
848 extern tree build_atomic_store (tree dest, tree src, bool sync);
849
850 /* Build a load-modify-store sequence from SRC to DEST. GNAT_NODE is used for
851 the location of the sequence. Note that, even if the load and the store are
852 both atomic, the sequence itself is not atomic. */
853 extern tree build_load_modify_store (tree dest, tree src, Node_Id gnat_node);
854
855 /* Make a binary operation of kind OP_CODE. RESULT_TYPE is the type
856 desired for the result. Usually the operation is to be performed
857 in that type. For MODIFY_EXPR and ARRAY_REF, RESULT_TYPE may be 0
858 in which case the type to be used will be derived from the operands.
859 Don't fold the result if NO_FOLD is true. */
860 extern tree build_binary_op (enum tree_code op_code, tree result_type,
861 tree left_operand, tree right_operand,
862 bool no_fold=false);
863
864 /* Similar, but make unary operation. */
865 extern tree build_unary_op (enum tree_code op_code, tree result_type,
866 tree operand);
867
868 /* Similar, but for COND_EXPR. */
869 extern tree build_cond_expr (tree result_type, tree condition_operand,
870 tree true_operand, tree false_operand);
871
872 /* Similar, but for COMPOUND_EXPR. */
873 extern tree build_compound_expr (tree result_type, tree stmt_operand,
874 tree expr_operand);
875
876 /* Conveniently construct a function call expression. FNDECL names the
877 function to be called, N is the number of arguments, and the "..."
878 parameters are the argument expressions. Unlike build_call_expr
879 this doesn't fold the call, hence it will always return a CALL_EXPR. */
880 extern tree build_call_n_expr (tree fndecl, int n, ...);
881
882 /* Build a call to a function that raises an exception and passes file name
883 and line number, if requested. MSG says which exception function to call.
884 GNAT_NODE is the node conveying the source location for which the error
885 should be signaled, or Empty in which case the error is signaled for the
886 current location. KIND says which kind of exception node this is for,
887 among N_Raise_{Constraint,Storage,Program}_Error. */
888 extern tree build_call_raise (int msg, Node_Id gnat_node, char kind);
889
890 /* Similar to build_call_raise, with extra information about the column
891 where the check failed. */
892 extern tree build_call_raise_column (int msg, Node_Id gnat_node, char kind);
893
894 /* Similar to build_call_raise_column, for an index or range check exception ,
895 with extra information of the form "INDEX out of range FIRST..LAST". */
896 extern tree build_call_raise_range (int msg, Node_Id gnat_node, char kind,
897 tree index, tree first, tree last);
898
899 /* Return a CONSTRUCTOR of TYPE whose elements are V. This is not the
900 same as build_constructor in the language-independent tree.c. */
901 extern tree gnat_build_constructor (tree type, vec<constructor_elt, va_gc> *v);
902
903 /* Return a COMPONENT_REF to access FIELD in RECORD, or NULL_EXPR and generate
904 a Constraint_Error if the field is not found in the record. Don't fold the
905 result if NO_FOLD is true. */
906 extern tree build_component_ref (tree record, tree field, bool no_fold);
907
908 /* Build a GCC tree to call an allocation or deallocation function.
909 If GNU_OBJ is nonzero, it is an object to deallocate. Otherwise,
910 generate an allocator.
911
912 GNU_SIZE is the number of bytes to allocate and GNU_TYPE is the contained
913 object type, used to determine the to-be-honored address alignment.
914 GNAT_PROC, if present, is a procedure to call and GNAT_POOL is the storage
915 pool to use. If not present, malloc and free are used. GNAT_NODE is used
916 to provide an error location for restriction violation messages. */
917 extern tree build_call_alloc_dealloc (tree gnu_obj, tree gnu_size,
918 tree gnu_type, Entity_Id gnat_proc,
919 Entity_Id gnat_pool, Node_Id gnat_node);
920
921 /* Build a GCC tree to correspond to allocating an object of TYPE whose
922 initial value if INIT, if INIT is nonzero. Convert the expression to
923 RESULT_TYPE, which must be some type of pointer. Return the tree.
924
925 GNAT_PROC and GNAT_POOL optionally give the procedure to call and
926 the storage pool to use. GNAT_NODE is used to provide an error
927 location for restriction violation messages. If IGNORE_INIT_TYPE is
928 true, ignore the type of INIT for the purpose of determining the size;
929 this will cause the maximum size to be allocated if TYPE is of
930 self-referential size. */
931 extern tree build_allocator (tree type, tree init, tree result_type,
932 Entity_Id gnat_proc, Entity_Id gnat_pool,
933 Node_Id gnat_node, bool);
934
935 /* Indicate that we need to take the address of T and that it therefore
936 should not be allocated in a register. Returns true if successful. */
937 extern bool gnat_mark_addressable (tree t);
938
939 /* Save EXP for later use or reuse. This is equivalent to save_expr in tree.c
940 but we know how to handle our own nodes. */
941 extern tree gnat_save_expr (tree exp);
942
943 /* Protect EXP for immediate reuse. This is a variant of gnat_save_expr that
944 is optimized under the assumption that EXP's value doesn't change before
945 its subsequent reuse(s) except through its potential reevaluation. */
946 extern tree gnat_protect_expr (tree exp);
947
948 /* This is equivalent to stabilize_reference in tree.c but we know how to
949 handle our own nodes and we take extra arguments. FORCE says whether to
950 force evaluation of everything in REF. INIT is set to the first arm of
951 a COMPOUND_EXPR present in REF, if any. */
952 extern tree gnat_stabilize_reference (tree ref, bool force, tree *init);
953
954 /* Rewrite reference REF and call FUNC on each expression within REF in the
955 process. DATA is passed unmodified to FUNC. INIT is set to the first
956 arm of a COMPOUND_EXPR present in REF, if any. */
957 typedef tree (*rewrite_fn) (tree, void *);
958 extern tree gnat_rewrite_reference (tree ref, rewrite_fn func, void *data,
959 tree *init);
960
961 /* This is equivalent to get_inner_reference in expr.c but it returns the
962 ultimate containing object only if the reference (lvalue) is constant,
963 i.e. if it doesn't depend on the context in which it is evaluated. */
964 extern tree get_inner_constant_reference (tree exp);
965
966 /* Return true if EXPR is the addition or the subtraction of a constant and,
967 if so, set *ADD to the addend, *CST to the constant and *MINUS_P to true
968 if this is a subtraction. */
969 extern bool is_simple_additive_expression (tree expr, tree *add, tree *cst,
970 bool *minus_p);
971
972 /* If EXPR is an expression that is invariant in the current function, in the
973 sense that it can be evaluated anywhere in the function and any number of
974 times, return EXPR or an equivalent expression. Otherwise return NULL. */
975 extern tree gnat_invariant_expr (tree expr);
976
977 /* Implementation of the builtin_function langhook. */
978 extern tree gnat_builtin_function (tree decl);
979
980 /* Search the chain of currently reachable declarations for a builtin
981 FUNCTION_DECL node corresponding to function NAME (an IDENTIFIER_NODE).
982 Return the first node found, if any, or NULL_TREE otherwise. */
983 extern tree builtin_decl_for (tree name);
984
985 /* GNU_TYPE is a type. Determine if it should be passed by reference by
986 default. */
987 extern bool default_pass_by_ref (tree gnu_type);
988
989 /* GNU_TYPE is the type of a subprogram parameter. Determine from the type
990 if it should be passed by reference. */
991 extern bool must_pass_by_ref (tree gnu_type);
992
993 /* Return the size of the FP mode with precision PREC. */
994 extern int fp_prec_to_size (int prec);
995
996 /* Return the precision of the FP mode with size SIZE. */
997 extern int fp_size_to_prec (int size);
998
999 /* Return whether GNAT_NODE is a defining identifier for a renaming that comes
1000 from the parameter association for the instantiation of a generic. We do
1001 not want to emit source location for them: the code generated for their
1002 initialization is likely to disturb debugging. */
1003 extern bool renaming_from_instantiation_p (Node_Id gnat_node);
1004
1005 /* Try to process all nodes in the deferred context queue. Keep in the queue
1006 the ones that cannot be processed yet, remove the other ones. If FORCE is
1007 true, force the processing for all nodes, use the global context when nodes
1008 don't have a GNU translation. */
1009 extern void process_deferred_decl_context (bool force);
1010
1011 /* Return the innermost scope, starting at GNAT_NODE, we are be interested in
1012 the debug info, or Empty if there is no such scope. If not NULL, set
1013 IS_SUBPROGRAM to whether the returned entity is a subprogram. */
1014 extern Entity_Id get_debug_scope (Node_Id gnat_node, bool *is_subprogram);
1015
1016 /* Return whether EXPR, which is the renamed object in an object renaming
1017 declaration, can be materialized as a reference (REFERENCE_TYPE). This
1018 should be synchronized with Exp_Dbug.Debug_Renaming_Declaration. */
1019 extern bool can_materialize_object_renaming_p (Node_Id expr);
1020
1021 #ifdef __cplusplus
1022 extern "C" {
1023 #endif
1024
1025 /* These functions return the basic data type sizes and related parameters
1026 about the target machine. */
1027 extern Pos get_target_bits_per_unit (void);
1028 extern Pos get_target_bits_per_word (void);
1029 extern Pos get_target_char_size (void);
1030 extern Pos get_target_wchar_t_size (void);
1031 extern Pos get_target_short_size (void);
1032 extern Pos get_target_int_size (void);
1033 extern Pos get_target_long_size (void);
1034 extern Pos get_target_long_long_size (void);
1035 extern Pos get_target_pointer_size (void);
1036 extern Pos get_target_maximum_default_alignment (void);
1037 extern Pos get_target_system_allocator_alignment (void);
1038 extern Pos get_target_maximum_allowed_alignment (void);
1039 extern Pos get_target_maximum_alignment (void);
1040 extern Nat get_target_float_words_be (void);
1041 extern Nat get_target_words_be (void);
1042 extern Nat get_target_bytes_be (void);
1043 extern Nat get_target_bits_be (void);
1044 extern Nat get_target_strict_alignment (void);
1045 extern Nat get_target_double_float_alignment (void);
1046 extern Nat get_target_double_scalar_alignment (void);
1047
1048 /* This function is called by the front-end to enumerate all the supported
1049 modes for the machine, as well as some predefined C types. */
1050 extern void enumerate_modes (void (*f) (const char *, int, int, int, int, int,
1051 int, int));
1052
1053 #ifdef __cplusplus
1054 }
1055 #endif
1056
1057 /* If EXP's type is a VECTOR_TYPE, return EXP converted to the associated
1058 TYPE_REPRESENTATIVE_ARRAY. */
1059
1060 static inline tree
maybe_vector_array(tree exp)1061 maybe_vector_array (tree exp)
1062 {
1063 tree etype = TREE_TYPE (exp);
1064
1065 if (VECTOR_TYPE_P (etype))
1066 exp = convert (TYPE_REPRESENTATIVE_ARRAY (etype), exp);
1067
1068 return exp;
1069 }
1070
1071 /* Return the smallest power of 2 larger than X. */
1072
1073 static inline unsigned HOST_WIDE_INT
ceil_pow2(unsigned HOST_WIDE_INT x)1074 ceil_pow2 (unsigned HOST_WIDE_INT x)
1075 {
1076 return (unsigned HOST_WIDE_INT) 1 << ceil_log2 (x);
1077 }
1078
1079 /* Return true if EXP, a CALL_EXPR, is an atomic load. */
1080
1081 static inline bool
call_is_atomic_load(tree exp)1082 call_is_atomic_load (tree exp)
1083 {
1084 tree fndecl = get_callee_fndecl (exp);
1085
1086 if (!(fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)))
1087 return false;
1088
1089 enum built_in_function code = DECL_FUNCTION_CODE (fndecl);
1090 return BUILT_IN_ATOMIC_LOAD_N <= code && code <= BUILT_IN_ATOMIC_LOAD_16;
1091 }
1092
1093 /* Return true if TYPE is padding a self-referential type. */
1094
1095 static inline bool
type_is_padding_self_referential(tree type)1096 type_is_padding_self_referential (tree type)
1097 {
1098 if (!TYPE_IS_PADDING_P (type))
1099 return false;
1100
1101 return CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type)));
1102 }
1103
1104 /* Return true if a function returning TYPE doesn't return a fixed size. */
1105
1106 static inline bool
return_type_with_variable_size_p(tree type)1107 return_type_with_variable_size_p (tree type)
1108 {
1109 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1110 return true;
1111
1112 /* Return true for an unconstrained type with default discriminant, see
1113 the E_Subprogram_Type case of gnat_to_gnu_entity. */
1114 if (type_is_padding_self_referential (type))
1115 return true;
1116
1117 return false;
1118 }
1119
1120 /* Return the unsigned version of TYPE_NODE, a scalar type. */
1121
1122 static inline tree
gnat_unsigned_type_for(tree type_node)1123 gnat_unsigned_type_for (tree type_node)
1124 {
1125 return gnat_signed_or_unsigned_type_for (1, type_node);
1126 }
1127
1128 /* Return the signed version of TYPE_NODE, a scalar type. */
1129
1130 static inline tree
gnat_signed_type_for(tree type_node)1131 gnat_signed_type_for (tree type_node)
1132 {
1133 return gnat_signed_or_unsigned_type_for (0, type_node);
1134 }
1135
1136 /* Adjust the character type TYPE if need be. */
1137
1138 static inline tree
maybe_character_type(tree type)1139 maybe_character_type (tree type)
1140 {
1141 if (TYPE_STRING_FLAG (type) && !TYPE_UNSIGNED (type))
1142 type = gnat_unsigned_type_for (type);
1143
1144 return type;
1145 }
1146
1147 /* Adjust the character value EXPR if need be. */
1148
1149 static inline tree
maybe_character_value(tree expr)1150 maybe_character_value (tree expr)
1151 {
1152 tree type = TREE_TYPE (expr);
1153
1154 if (TYPE_STRING_FLAG (type) && !TYPE_UNSIGNED (type))
1155 {
1156 type = gnat_unsigned_type_for (type);
1157 expr = convert (type, expr);
1158 }
1159
1160 return expr;
1161 }
1162
1163 /* Return the debug type of TYPE if it exists, otherwise TYPE itself. */
1164
1165 static inline tree
maybe_debug_type(tree type)1166 maybe_debug_type (tree type)
1167 {
1168 if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type) && TYPE_DEBUG_TYPE (type))
1169 type = TYPE_DEBUG_TYPE (type);
1170
1171 return type;
1172 }
1173
1174 /* Like build_qualified_type, but TYPE_QUALS is added to the existing
1175 qualifiers on TYPE. */
1176
1177 static inline tree
change_qualified_type(tree type,int type_quals)1178 change_qualified_type (tree type, int type_quals)
1179 {
1180 /* Qualifiers must be put on the associated array type. */
1181 if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
1182 return type;
1183
1184 return build_qualified_type (type, TYPE_QUALS (type) | type_quals);
1185 }
1186