Typo in last patch.
[official-gcc.git] / gcc / ada / trans.c
blobb32d4a63f874b85eb32f8ec7312ca264d31c6246
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * T R A N S *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2004, 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, 59 Temple Place - Suite 330, Boston, *
20 * MA 02111-1307, 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 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "tree.h"
32 #include "real.h"
33 #include "flags.h"
34 #include "rtl.h"
35 #include "expr.h"
36 #include "ggc.h"
37 #include "function.h"
38 #include "except.h"
39 #include "debug.h"
40 #include "output.h"
41 #include "ada.h"
42 #include "types.h"
43 #include "atree.h"
44 #include "elists.h"
45 #include "namet.h"
46 #include "nlists.h"
47 #include "snames.h"
48 #include "stringt.h"
49 #include "uintp.h"
50 #include "urealp.h"
51 #include "fe.h"
52 #include "sinfo.h"
53 #include "einfo.h"
54 #include "ada-tree.h"
55 #include "gigi.h"
57 int max_gnat_nodes;
58 int number_names;
59 struct Node *Nodes_Ptr;
60 Node_Id *Next_Node_Ptr;
61 Node_Id *Prev_Node_Ptr;
62 struct Elist_Header *Elists_Ptr;
63 struct Elmt_Item *Elmts_Ptr;
64 struct String_Entry *Strings_Ptr;
65 Char_Code *String_Chars_Ptr;
66 struct List_Header *List_Headers_Ptr;
68 /* Current filename without path. */
69 const char *ref_filename;
71 /* Flag indicating whether file names are discarded in exception messages */
72 int discard_file_names;
74 /* If true, then gigi is being called on an analyzed but unexpanded
75 tree, and the only purpose of the call is to properly annotate
76 types with representation information. */
77 int type_annotate_only;
79 /* List of TREE_LIST nodes representing a block stack. TREE_VALUE
80 of each gives the variable used for the setjmp buffer in the current
81 block, if any. TREE_PURPOSE gives the bottom condition for a loop,
82 if this block is for a loop. The latter is only used to save the tree
83 over GC. */
84 tree gnu_block_stack;
86 /* The current BLOCK_STMT node. TREE_CHAIN points to the previous
87 BLOCK_STMT node. */
88 static GTY(()) tree gnu_block_stmt_node;
90 /* List of unused BLOCK_STMT nodes. */
91 static GTY((deletable)) tree gnu_block_stmt_free_list;
93 /* List of TREE_LIST nodes representing a stack of exception pointer
94 variables. TREE_VALUE is the VAR_DECL that stores the address of
95 the raised exception. Nonzero means we are in an exception
96 handler. Not used in the zero-cost case. */
97 static GTY(()) tree gnu_except_ptr_stack;
99 /* List of TREE_LIST nodes containing pending elaborations lists.
100 used to prevent the elaborations being reclaimed by GC. */
101 static GTY(()) tree gnu_pending_elaboration_lists;
103 /* Map GNAT tree codes to GCC tree codes for simple expressions. */
104 static enum tree_code gnu_codes[Number_Node_Kinds];
106 /* Current node being treated, in case gigi_abort called. */
107 Node_Id error_gnat_node;
109 /* Variable that stores a list of labels to be used as a goto target instead of
110 a return in some functions. See processing for N_Subprogram_Body. */
111 static GTY(()) tree gnu_return_label_stack;
113 static tree tree_transform (Node_Id);
114 static rtx first_nondeleted_insn (rtx);
115 static tree start_block_stmt (void);
116 static tree end_block_stmt (void);
117 static tree build_block_stmt (List_Id);
118 static tree make_expr_stmt_from_rtl (rtx, Node_Id);
119 static void elaborate_all_entities (Node_Id);
120 static void process_freeze_entity (Node_Id);
121 static void process_inlined_subprograms (Node_Id);
122 static void process_decls (List_Id, List_Id, Node_Id, int, int);
123 static tree emit_range_check (tree, Node_Id);
124 static tree emit_index_check (tree, tree, tree, tree);
125 static tree emit_check (tree, tree, int);
126 static tree convert_with_check (Entity_Id, tree, int, int, int);
127 static int addressable_p (tree);
128 static tree assoc_to_constructor (Node_Id, tree);
129 static tree extract_values (tree, tree);
130 static tree pos_to_constructor (Node_Id, tree, Entity_Id);
131 static tree maybe_implicit_deref (tree);
132 static tree gnat_stabilize_reference_1 (tree, int);
133 static int build_unit_elab (Entity_Id, int, tree);
135 /* Constants for +0.5 and -0.5 for float-to-integer rounding. */
136 static REAL_VALUE_TYPE dconstp5;
137 static REAL_VALUE_TYPE dconstmp5;
139 /* This is the main program of the back-end. It sets up all the table
140 structures and then generates code. */
142 void
143 gigi (Node_Id gnat_root,
144 int max_gnat_node,
145 int number_name,
146 struct Node *nodes_ptr,
147 Node_Id *next_node_ptr,
148 Node_Id *prev_node_ptr,
149 struct Elist_Header *elists_ptr,
150 struct Elmt_Item *elmts_ptr,
151 struct String_Entry *strings_ptr,
152 Char_Code *string_chars_ptr,
153 struct List_Header *list_headers_ptr,
154 Int number_units ATTRIBUTE_UNUSED,
155 char *file_info_ptr ATTRIBUTE_UNUSED,
156 Entity_Id standard_integer,
157 Entity_Id standard_long_long_float,
158 Entity_Id standard_exception_type,
159 Int gigi_operating_mode)
161 tree gnu_standard_long_long_float;
162 tree gnu_standard_exception_type;
164 max_gnat_nodes = max_gnat_node;
165 number_names = number_name;
166 Nodes_Ptr = nodes_ptr;
167 Next_Node_Ptr = next_node_ptr;
168 Prev_Node_Ptr = prev_node_ptr;
169 Elists_Ptr = elists_ptr;
170 Elmts_Ptr = elmts_ptr;
171 Strings_Ptr = strings_ptr;
172 String_Chars_Ptr = string_chars_ptr;
173 List_Headers_Ptr = list_headers_ptr;
175 type_annotate_only = (gigi_operating_mode == 1);
177 /* If we are just annotating types, give VOID_TYPE zero sizes to avoid
178 errors. */
179 if (type_annotate_only)
181 TYPE_SIZE (void_type_node) = bitsize_zero_node;
182 TYPE_SIZE_UNIT (void_type_node) = size_zero_node;
185 /* See if we should discard file names in exception messages. */
186 discard_file_names = Debug_Flag_NN;
188 if (Nkind (gnat_root) != N_Compilation_Unit)
189 gigi_abort (301);
191 set_lineno (gnat_root, 0);
193 /* Initialize ourselves. */
194 init_gnat_to_gnu ();
195 init_dummy_type ();
196 init_code_table ();
197 gnat_compute_largest_alignment ();
198 start_block_stmt ();
200 /* Enable GNAT stack checking method if needed */
201 if (!Stack_Check_Probes_On_Target)
202 set_stack_check_libfunc (gen_rtx_SYMBOL_REF (Pmode, "_gnat_stack_check"));
204 /* Save the type we made for integer as the type for Standard.Integer.
205 Then make the rest of the standard types. Note that some of these
206 may be subtypes. */
207 save_gnu_tree (Base_Type (standard_integer),
208 TYPE_NAME (integer_type_node), 0);
210 gnu_except_ptr_stack = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
212 REAL_ARITHMETIC (dconstp5, RDIV_EXPR, dconst1, dconst2);
213 REAL_ARITHMETIC (dconstmp5, RDIV_EXPR, dconstm1, dconst2);
215 gnu_standard_long_long_float
216 = gnat_to_gnu_entity (Base_Type (standard_long_long_float), NULL_TREE, 0);
217 gnu_standard_exception_type
218 = gnat_to_gnu_entity (Base_Type (standard_exception_type), NULL_TREE, 0);
220 init_gigi_decls (gnu_standard_long_long_float, gnu_standard_exception_type);
222 /* Process any Pragma Ident for the main unit. */
223 #ifdef ASM_OUTPUT_IDENT
224 if (Present (Ident_String (Main_Unit)))
225 ASM_OUTPUT_IDENT
226 (asm_out_file,
227 TREE_STRING_POINTER (gnat_to_gnu (Ident_String (Main_Unit))));
228 #endif
230 /* If we are using the GCC exception mechanism, let GCC know. */
231 if (Exception_Mechanism == GCC_ZCX)
232 gnat_init_gcc_eh ();
234 gnat_to_code (gnat_root);
238 /* This function is the driver of the GNAT to GCC tree transformation process.
239 GNAT_NODE is the root of some gnat tree. It generates code for that
240 part of the tree. */
242 void
243 gnat_to_code (Node_Id gnat_node)
245 tree gnu_root;
247 /* Save node number in case error */
248 error_gnat_node = gnat_node;
250 start_block_stmt ();
251 gnu_root = tree_transform (gnat_node);
252 gnat_expand_stmt (end_block_stmt ());
254 /* If we return a statement, generate code for it. */
255 if (IS_STMT (gnu_root))
257 if (TREE_CODE (gnu_root) != NULL_STMT)
258 gnat_expand_stmt (gnu_root);
260 /* This should just generate code, not return a value. If it returns
261 a value, something is wrong. */
262 else if (gnu_root != error_mark_node)
263 gigi_abort (302);
266 /* GNAT_NODE is the root of some GNAT tree. Return the root of the GCC
267 tree corresponding to that GNAT tree. Normally, no code is generated.
268 We just return an equivalent tree which is used elsewhere to generate
269 code. */
271 tree
272 gnat_to_gnu (Node_Id gnat_node)
274 tree gnu_root;
275 bool made_sequence = false;
277 /* We support the use of this on statements now as a transition
278 to full function-at-a-time processing. So we need to see if anything
279 we do generates RTL and returns error_mark_node. */
280 if (!global_bindings_p ())
282 do_pending_stack_adjust ();
283 emit_queue ();
284 start_sequence ();
285 emit_note (NOTE_INSN_DELETED);
286 made_sequence = true;
289 /* Save node number in case error */
290 error_gnat_node = gnat_node;
292 start_block_stmt ();
293 gnu_root = tree_transform (gnat_node);
294 gnat_expand_stmt (end_block_stmt ());
296 if (gnu_root == error_mark_node)
298 if (!made_sequence)
300 if (type_annotate_only)
301 return gnu_root;
302 else
303 gigi_abort (303);
306 do_pending_stack_adjust ();
307 emit_queue ();
308 gnu_root = make_expr_stmt_from_rtl (first_nondeleted_insn (get_insns ()),
309 gnat_node);
310 end_sequence ();
312 else if (made_sequence)
314 rtx insns;
316 do_pending_stack_adjust ();
317 emit_queue ();
318 insns = first_nondeleted_insn (get_insns ());
319 end_sequence ();
321 if (insns)
323 /* If we have a statement, we need to first evaluate any RTL we
324 made in the process of building it and then the statement. */
325 if (IS_STMT (gnu_root))
327 tree gnu_expr_stmt = make_expr_stmt_from_rtl (insns, gnat_node);
329 TREE_CHAIN (gnu_expr_stmt) = gnu_root;
330 gnu_root = build_nt (BLOCK_STMT, gnu_expr_stmt);
331 TREE_TYPE (gnu_root) = void_type_node;
332 TREE_SLOC (gnu_root) = Sloc (gnat_node);
334 else
335 emit_insn (insns);
339 return gnu_root;
342 /* This function is the driver of the GNAT to GCC tree transformation process.
343 It is the entry point of the tree transformer. GNAT_NODE is the root of
344 some GNAT tree. Return the root of the corresponding GCC tree or
345 error_mark_node to signal that there is no GCC tree to return.
347 The latter is the case if only code generation actions have to be performed
348 like in the case of if statements, loops, etc. This routine is wrapped
349 in the above two routines for most purposes. */
351 static tree
352 tree_transform (Node_Id gnat_node)
354 tree gnu_result = error_mark_node; /* Default to no value. */
355 tree gnu_result_type = void_type_node;
356 tree gnu_expr;
357 tree gnu_lhs, gnu_rhs;
358 Node_Id gnat_temp;
359 Entity_Id gnat_temp_type;
361 /* Set input_file_name and lineno from the Sloc in the GNAT tree. */
362 set_lineno (gnat_node, 0);
364 if (IN (Nkind (gnat_node), N_Statement_Other_Than_Procedure_Call)
365 && type_annotate_only)
366 return error_mark_node;
368 /* If this is a Statement and we are at top level, we add the statement
369 as an elaboration for a null tree. That will cause it to be placed
370 in the elaboration procedure. */
371 if (global_bindings_p ()
372 && ((IN (Nkind (gnat_node), N_Statement_Other_Than_Procedure_Call)
373 && Nkind (gnat_node) != N_Null_Statement)
374 || Nkind (gnat_node) == N_Procedure_Call_Statement
375 || Nkind (gnat_node) == N_Label
376 || (Nkind (gnat_node) == N_Handled_Sequence_Of_Statements
377 && (Present (Exception_Handlers (gnat_node))
378 || Present (At_End_Proc (gnat_node))))
379 || ((Nkind (gnat_node) == N_Raise_Constraint_Error
380 || Nkind (gnat_node) == N_Raise_Storage_Error
381 || Nkind (gnat_node) == N_Raise_Program_Error)
382 && (Ekind (Etype (gnat_node)) == E_Void))))
384 add_pending_elaborations (NULL_TREE, make_transform_expr (gnat_node));
386 return error_mark_node;
389 /* If this node is a non-static subexpression and we are only
390 annotating types, make this into a NULL_EXPR for non-VOID types
391 and error_mark_node for void return types. But allow
392 N_Identifier since we use it for lots of things, including
393 getting trees for discriminants. */
395 if (type_annotate_only
396 && IN (Nkind (gnat_node), N_Subexpr)
397 && Nkind (gnat_node) != N_Identifier
398 && ! Compile_Time_Known_Value (gnat_node))
400 gnu_result_type = get_unpadded_type (Etype (gnat_node));
402 if (TREE_CODE (gnu_result_type) == VOID_TYPE)
403 return error_mark_node;
404 else
405 return build1 (NULL_EXPR, gnu_result_type,
406 build_call_raise (CE_Range_Check_Failed));
409 switch (Nkind (gnat_node))
411 /********************************/
412 /* Chapter 2: Lexical Elements: */
413 /********************************/
415 case N_Identifier:
416 case N_Expanded_Name:
417 case N_Operator_Symbol:
418 case N_Defining_Identifier:
420 /* If the Etype of this node does not equal the Etype of the
421 Entity, something is wrong with the entity map, probably in
422 generic instantiation. However, this does not apply to
423 types. Since we sometime have strange Ekind's, just do
424 this test for objects. Also, if the Etype of the Entity is
425 private, the Etype of the N_Identifier is allowed to be the full
426 type and also we consider a packed array type to be the same as
427 the original type. Similarly, a class-wide type is equivalent
428 to a subtype of itself. Finally, if the types are Itypes,
429 one may be a copy of the other, which is also legal. */
431 gnat_temp = (Nkind (gnat_node) == N_Defining_Identifier
432 ? gnat_node : Entity (gnat_node));
433 gnat_temp_type = Etype (gnat_temp);
435 if (Etype (gnat_node) != gnat_temp_type
436 && ! (Is_Packed (gnat_temp_type)
437 && Etype (gnat_node) == Packed_Array_Type (gnat_temp_type))
438 && ! (Is_Class_Wide_Type (Etype (gnat_node)))
439 && ! (IN (Ekind (gnat_temp_type), Private_Kind)
440 && Present (Full_View (gnat_temp_type))
441 && ((Etype (gnat_node) == Full_View (gnat_temp_type))
442 || (Is_Packed (Full_View (gnat_temp_type))
443 && Etype (gnat_node) ==
444 Packed_Array_Type (Full_View (gnat_temp_type)))))
445 && (!Is_Itype (Etype (gnat_node)) || !Is_Itype (gnat_temp_type))
446 && (Ekind (gnat_temp) == E_Variable
447 || Ekind (gnat_temp) == E_Component
448 || Ekind (gnat_temp) == E_Constant
449 || Ekind (gnat_temp) == E_Loop_Parameter
450 || IN (Ekind (gnat_temp), Formal_Kind)))
451 gigi_abort (304);
453 /* If this is a reference to a deferred constant whose partial view
454 is an unconstrained private type, the proper type is on the full
455 view of the constant, not on the full view of the type, which may
456 be unconstrained.
458 This may be a reference to a type, for example in the prefix of the
459 attribute Position, generated for dispatching code (see Make_DT in
460 exp_disp,adb). In that case we need the type itself, not is parent,
461 in particular if it is a derived type */
463 if (Is_Private_Type (gnat_temp_type)
464 && Has_Unknown_Discriminants (gnat_temp_type)
465 && Present (Full_View (gnat_temp))
466 && ! Is_Type (gnat_temp))
468 gnat_temp = Full_View (gnat_temp);
469 gnat_temp_type = Etype (gnat_temp);
470 gnu_result_type = get_unpadded_type (gnat_temp_type);
472 else
474 /* Expand the type of this identitier first, in case it is
475 an enumeral literal, which only get made when the type
476 is expanded. There is no order-of-elaboration issue here.
477 We want to use the Actual_Subtype if it has already been
478 elaborated, otherwise the Etype. Avoid using Actual_Subtype
479 for packed arrays to simplify things. */
480 if ((Ekind (gnat_temp) == E_Constant
481 || Ekind (gnat_temp) == E_Variable || Is_Formal (gnat_temp))
482 && ! (Is_Array_Type (Etype (gnat_temp))
483 && Present (Packed_Array_Type (Etype (gnat_temp))))
484 && Present (Actual_Subtype (gnat_temp))
485 && present_gnu_tree (Actual_Subtype (gnat_temp)))
486 gnat_temp_type = Actual_Subtype (gnat_temp);
487 else
488 gnat_temp_type = Etype (gnat_node);
490 gnu_result_type = get_unpadded_type (gnat_temp_type);
493 gnu_result = gnat_to_gnu_entity (gnat_temp, NULL_TREE, 0);
495 /* If we are in an exception handler, force this variable into memory
496 to ensure optimization does not remove stores that appear
497 redundant but are actually needed in case an exception occurs.
499 ??? Note that we need not do this if the variable is declared within
500 the handler, only if it is referenced in the handler and declared
501 in an enclosing block, but we have no way of testing that
502 right now. */
503 if (TREE_VALUE (gnu_except_ptr_stack) != 0)
505 gnat_mark_addressable (gnu_result);
506 flush_addressof (gnu_result);
509 /* Some objects (such as parameters passed by reference, globals of
510 variable size, and renamed objects) actually represent the address
511 of the object. In that case, we must do the dereference. Likewise,
512 deal with parameters to foreign convention subprograms. Call fold
513 here since GNU_RESULT may be a CONST_DECL. */
514 if (DECL_P (gnu_result)
515 && (DECL_BY_REF_P (gnu_result)
516 || (TREE_CODE (gnu_result) == PARM_DECL
517 && DECL_BY_COMPONENT_PTR_P (gnu_result))))
519 int ro = DECL_POINTS_TO_READONLY_P (gnu_result);
520 tree initial;
522 if (TREE_CODE (gnu_result) == PARM_DECL
523 && DECL_BY_COMPONENT_PTR_P (gnu_result))
524 gnu_result = convert (build_pointer_type (gnu_result_type),
525 gnu_result);
527 /* If the object is constant, we try to do the dereference directly
528 through the DECL_INITIAL. This is actually required in order to
529 get correct aliasing information for renamed objects that are
530 components of non-aliased aggregates, because the type of
531 the renamed object and that of the aggregate don't alias. */
532 if (TREE_READONLY (gnu_result)
533 && DECL_INITIAL (gnu_result)
534 /* Strip possible conversion to reference type. */
535 && (initial = TREE_CODE (DECL_INITIAL (gnu_result)) == NOP_EXPR
536 ? TREE_OPERAND (DECL_INITIAL (gnu_result), 0)
537 : DECL_INITIAL (gnu_result), 1)
538 && TREE_CODE (initial) == ADDR_EXPR
539 && (TREE_CODE (TREE_OPERAND (initial, 0)) == ARRAY_REF
540 || TREE_CODE (TREE_OPERAND (initial, 0)) == COMPONENT_REF))
541 gnu_result = TREE_OPERAND (initial, 0);
542 else
543 gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE,
544 fold (gnu_result));
546 TREE_READONLY (gnu_result) = TREE_STATIC (gnu_result) = ro;
549 /* The GNAT tree has the type of a function as the type of its result.
550 Also use the type of the result if the Etype is a subtype which
551 is nominally unconstrained. But remove any padding from the
552 resulting type. */
553 if (TREE_CODE (TREE_TYPE (gnu_result)) == FUNCTION_TYPE
554 || Is_Constr_Subt_For_UN_Aliased (gnat_temp_type))
556 gnu_result_type = TREE_TYPE (gnu_result);
557 if (TREE_CODE (gnu_result_type) == RECORD_TYPE
558 && TYPE_IS_PADDING_P (gnu_result_type))
559 gnu_result_type = TREE_TYPE (TYPE_FIELDS (gnu_result_type));
562 /* We always want to return the underlying INTEGER_CST for an
563 enumeration literal to avoid the need to call fold in lots
564 of places. But don't do this is the parent will be taking
565 the address of this object. */
566 if (TREE_CODE (gnu_result) == CONST_DECL)
568 gnat_temp = Parent (gnat_node);
569 if (DECL_CONST_CORRESPONDING_VAR (gnu_result) == 0
570 || (Nkind (gnat_temp) != N_Reference
571 && ! (Nkind (gnat_temp) == N_Attribute_Reference
572 && ((Get_Attribute_Id (Attribute_Name (gnat_temp))
573 == Attr_Address)
574 || (Get_Attribute_Id (Attribute_Name (gnat_temp))
575 == Attr_Access)
576 || (Get_Attribute_Id (Attribute_Name (gnat_temp))
577 == Attr_Unchecked_Access)
578 || (Get_Attribute_Id (Attribute_Name (gnat_temp))
579 == Attr_Unrestricted_Access)))))
580 gnu_result = DECL_INITIAL (gnu_result);
582 break;
584 case N_Integer_Literal:
586 tree gnu_type;
588 /* Get the type of the result, looking inside any padding and
589 left-justified modular types. Then get the value in that type. */
590 gnu_type = gnu_result_type = get_unpadded_type (Etype (gnat_node));
592 if (TREE_CODE (gnu_type) == RECORD_TYPE
593 && TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_type))
594 gnu_type = TREE_TYPE (TYPE_FIELDS (gnu_type));
596 gnu_result = UI_To_gnu (Intval (gnat_node), gnu_type);
598 /* If the result overflows (meaning it doesn't fit in its base type),
599 abort. We would like to check that the value is within the range
600 of the subtype, but that causes problems with subtypes whose usage
601 will raise Constraint_Error and with biased representation, so
602 we don't. */
603 if (TREE_CONSTANT_OVERFLOW (gnu_result))
604 gigi_abort (305);
606 break;
608 case N_Character_Literal:
609 /* If a Entity is present, it means that this was one of the
610 literals in a user-defined character type. In that case,
611 just return the value in the CONST_DECL. Otherwise, use the
612 character code. In that case, the base type should be an
613 INTEGER_TYPE, but we won't bother checking for that. */
614 gnu_result_type = get_unpadded_type (Etype (gnat_node));
615 if (Present (Entity (gnat_node)))
616 gnu_result = DECL_INITIAL (get_gnu_tree (Entity (gnat_node)));
617 else
618 gnu_result = convert (gnu_result_type,
619 build_int_2 (Char_Literal_Value (gnat_node), 0));
620 break;
622 case N_Real_Literal:
623 /* If this is of a fixed-point type, the value we want is the
624 value of the corresponding integer. */
625 if (IN (Ekind (Underlying_Type (Etype (gnat_node))), Fixed_Point_Kind))
627 gnu_result_type = get_unpadded_type (Etype (gnat_node));
628 gnu_result = UI_To_gnu (Corresponding_Integer_Value (gnat_node),
629 gnu_result_type);
630 if (TREE_CONSTANT_OVERFLOW (gnu_result))
631 gigi_abort (305);
634 /* We should never see a Vax_Float type literal, since the front end
635 is supposed to transform these using appropriate conversions */
636 else if (Vax_Float (Underlying_Type (Etype (gnat_node))))
637 gigi_abort (334);
639 else
641 Ureal ur_realval = Realval (gnat_node);
643 gnu_result_type = get_unpadded_type (Etype (gnat_node));
645 /* If the real value is zero, so is the result. Otherwise,
646 convert it to a machine number if it isn't already. That
647 forces BASE to 0 or 2 and simplifies the rest of our logic. */
648 if (UR_Is_Zero (ur_realval))
649 gnu_result = convert (gnu_result_type, integer_zero_node);
650 else
652 if (! Is_Machine_Number (gnat_node))
653 ur_realval
654 = Machine (Base_Type (Underlying_Type (Etype (gnat_node))),
655 ur_realval, Round_Even, gnat_node);
657 gnu_result
658 = UI_To_gnu (Numerator (ur_realval), gnu_result_type);
660 /* If we have a base of zero, divide by the denominator.
661 Otherwise, the base must be 2 and we scale the value, which
662 we know can fit in the mantissa of the type (hence the use
663 of that type above). */
664 if (Rbase (ur_realval) == 0)
665 gnu_result
666 = build_binary_op (RDIV_EXPR,
667 get_base_type (gnu_result_type),
668 gnu_result,
669 UI_To_gnu (Denominator (ur_realval),
670 gnu_result_type));
671 else if (Rbase (ur_realval) != 2)
672 gigi_abort (336);
674 else
676 REAL_VALUE_TYPE tmp;
678 real_ldexp (&tmp, &TREE_REAL_CST (gnu_result),
679 - UI_To_Int (Denominator (ur_realval)));
680 gnu_result = build_real (gnu_result_type, tmp);
684 /* Now see if we need to negate the result. Do it this way to
685 properly handle -0. */
686 if (UR_Is_Negative (Realval (gnat_node)))
687 gnu_result
688 = build_unary_op (NEGATE_EXPR, get_base_type (gnu_result_type),
689 gnu_result);
692 break;
694 case N_String_Literal:
695 gnu_result_type = get_unpadded_type (Etype (gnat_node));
696 if (TYPE_PRECISION (TREE_TYPE (gnu_result_type)) == HOST_BITS_PER_CHAR)
698 /* We assume here that all strings are of type standard.string.
699 "Weird" types of string have been converted to an aggregate
700 by the expander. */
701 String_Id gnat_string = Strval (gnat_node);
702 int length = String_Length (gnat_string);
703 char *string = (char *) alloca (length + 1);
704 int i;
706 /* Build the string with the characters in the literal. Note
707 that Ada strings are 1-origin. */
708 for (i = 0; i < length; i++)
709 string[i] = Get_String_Char (gnat_string, i + 1);
711 /* Put a null at the end of the string in case it's in a context
712 where GCC will want to treat it as a C string. */
713 string[i] = 0;
715 gnu_result = build_string (length, string);
717 /* Strings in GCC don't normally have types, but we want
718 this to not be converted to the array type. */
719 TREE_TYPE (gnu_result) = gnu_result_type;
721 else
723 /* Build a list consisting of each character, then make
724 the aggregate. */
725 String_Id gnat_string = Strval (gnat_node);
726 int length = String_Length (gnat_string);
727 int i;
728 tree gnu_list = NULL_TREE;
730 for (i = 0; i < length; i++)
731 gnu_list
732 = tree_cons (NULL_TREE,
733 convert (TREE_TYPE (gnu_result_type),
734 build_int_2 (Get_String_Char (gnat_string,
735 i + 1),
736 0)),
737 gnu_list);
739 gnu_result
740 = gnat_build_constructor (gnu_result_type, nreverse (gnu_list));
742 break;
744 case N_Pragma:
745 if (type_annotate_only)
746 break;
748 /* Check for (and ignore) unrecognized pragma */
749 if (! Is_Pragma_Name (Chars (gnat_node)))
750 break;
752 switch (Get_Pragma_Id (Chars (gnat_node)))
754 case Pragma_Inspection_Point:
755 /* Do nothing at top level: all such variables are already
756 viewable. */
757 if (global_bindings_p ())
758 break;
760 set_lineno (gnat_node, 1);
761 for (gnat_temp = First (Pragma_Argument_Associations (gnat_node));
762 Present (gnat_temp);
763 gnat_temp = Next (gnat_temp))
765 gnu_expr = gnat_to_gnu (Expression (gnat_temp));
766 if (TREE_CODE (gnu_expr) == UNCONSTRAINED_ARRAY_REF)
767 gnu_expr = TREE_OPERAND (gnu_expr, 0);
769 gnu_expr = build1 (USE_EXPR, void_type_node, gnu_expr);
770 TREE_SIDE_EFFECTS (gnu_expr) = 1;
771 expand_expr_stmt (gnu_expr);
773 break;
775 case Pragma_Optimize:
776 switch (Chars (Expression
777 (First (Pragma_Argument_Associations (gnat_node)))))
779 case Name_Time: case Name_Space:
780 if (optimize == 0)
781 post_error ("insufficient -O value?", gnat_node);
782 break;
784 case Name_Off:
785 if (optimize != 0)
786 post_error ("must specify -O0?", gnat_node);
787 break;
789 default:
790 gigi_abort (331);
791 break;
793 break;
795 case Pragma_Reviewable:
796 if (write_symbols == NO_DEBUG)
797 post_error ("must specify -g?", gnat_node);
798 break;
800 break;
802 /**************************************/
803 /* Chapter 3: Declarations and Types: */
804 /**************************************/
806 case N_Subtype_Declaration:
807 case N_Full_Type_Declaration:
808 case N_Incomplete_Type_Declaration:
809 case N_Private_Type_Declaration:
810 case N_Private_Extension_Declaration:
811 case N_Task_Type_Declaration:
812 process_type (Defining_Entity (gnat_node));
813 break;
815 case N_Object_Declaration:
816 case N_Exception_Declaration:
817 gnat_temp = Defining_Entity (gnat_node);
819 /* If we are just annotating types and this object has an unconstrained
820 or task type, don't elaborate it. */
821 if (type_annotate_only
822 && (((Is_Array_Type (Etype (gnat_temp))
823 || Is_Record_Type (Etype (gnat_temp)))
824 && ! Is_Constrained (Etype (gnat_temp)))
825 || Is_Concurrent_Type (Etype (gnat_temp))))
826 break;
828 if (Present (Expression (gnat_node))
829 && ! (Nkind (gnat_node) == N_Object_Declaration
830 && No_Initialization (gnat_node))
831 && (! type_annotate_only
832 || Compile_Time_Known_Value (Expression (gnat_node))))
834 gnu_expr = gnat_to_gnu (Expression (gnat_node));
835 if (Do_Range_Check (Expression (gnat_node)))
836 gnu_expr = emit_range_check (gnu_expr, Etype (gnat_temp));
838 /* If this object has its elaboration delayed, we must force
839 evaluation of GNU_EXPR right now and save it for when the object
840 is frozen. */
841 if (Present (Freeze_Node (gnat_temp)))
843 if ((Is_Public (gnat_temp) || global_bindings_p ())
844 && ! TREE_CONSTANT (gnu_expr))
846 gnu_expr
847 = create_var_decl (create_concat_name (gnat_temp, "init"),
848 NULL_TREE, TREE_TYPE (gnu_expr),
849 gnu_expr, 0, Is_Public (gnat_temp), 0,
850 0, 0);
851 add_decl_stmt (gnu_expr, gnat_temp);
853 else
854 gnu_expr = maybe_variable (gnu_expr, Expression (gnat_node));
856 save_gnu_tree (gnat_node, gnu_expr, 1);
859 else
860 gnu_expr = 0;
862 if (type_annotate_only && gnu_expr != 0
863 && TREE_CODE (gnu_expr) == ERROR_MARK)
864 gnu_expr = 0;
866 if (No (Freeze_Node (gnat_temp)))
867 gnat_to_gnu_entity (gnat_temp, gnu_expr, 1);
868 break;
870 case N_Object_Renaming_Declaration:
872 gnat_temp = Defining_Entity (gnat_node);
874 /* Don't do anything if this renaming is handled by the front end.
875 or if we are just annotating types and this object has a
876 composite or task type, don't elaborate it. */
877 if (! Is_Renaming_Of_Object (gnat_temp)
878 && ! (type_annotate_only
879 && (Is_Array_Type (Etype (gnat_temp))
880 || Is_Record_Type (Etype (gnat_temp))
881 || Is_Concurrent_Type (Etype (gnat_temp)))))
882 gnat_to_gnu_entity (gnat_temp,
883 gnat_to_gnu (Renamed_Object (gnat_temp)), 1);
884 break;
886 case N_Implicit_Label_Declaration:
887 gnat_to_gnu_entity (Defining_Entity (gnat_node), NULL_TREE, 1);
888 break;
890 case N_Exception_Renaming_Declaration:
891 case N_Number_Declaration:
892 case N_Package_Renaming_Declaration:
893 case N_Subprogram_Renaming_Declaration:
894 /* These are fully handled in the front end. */
895 break;
897 /*************************************/
898 /* Chapter 4: Names and Expressions: */
899 /*************************************/
901 case N_Explicit_Dereference:
902 gnu_result = gnat_to_gnu (Prefix (gnat_node));
903 gnu_result_type = get_unpadded_type (Etype (gnat_node));
904 gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result);
905 break;
907 case N_Indexed_Component:
909 tree gnu_array_object = gnat_to_gnu (Prefix (gnat_node));
910 tree gnu_type;
911 int ndim;
912 int i;
913 Node_Id *gnat_expr_array;
915 gnu_array_object = maybe_implicit_deref (gnu_array_object);
916 gnu_array_object = maybe_unconstrained_array (gnu_array_object);
918 /* If we got a padded type, remove it too. */
919 if (TREE_CODE (TREE_TYPE (gnu_array_object)) == RECORD_TYPE
920 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_array_object)))
921 gnu_array_object
922 = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_array_object))),
923 gnu_array_object);
925 gnu_result = gnu_array_object;
927 /* First compute the number of dimensions of the array, then
928 fill the expression array, the order depending on whether
929 this is a Convention_Fortran array or not. */
930 for (ndim = 1, gnu_type = TREE_TYPE (gnu_array_object);
931 TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
932 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type));
933 ndim++, gnu_type = TREE_TYPE (gnu_type))
936 gnat_expr_array = (Node_Id *) alloca (ndim * sizeof (Node_Id));
938 if (TYPE_CONVENTION_FORTRAN_P (TREE_TYPE (gnu_array_object)))
939 for (i = ndim - 1, gnat_temp = First (Expressions (gnat_node));
940 i >= 0;
941 i--, gnat_temp = Next (gnat_temp))
942 gnat_expr_array[i] = gnat_temp;
943 else
944 for (i = 0, gnat_temp = First (Expressions (gnat_node));
945 i < ndim;
946 i++, gnat_temp = Next (gnat_temp))
947 gnat_expr_array[i] = gnat_temp;
949 for (i = 0, gnu_type = TREE_TYPE (gnu_array_object);
950 i < ndim; i++, gnu_type = TREE_TYPE (gnu_type))
952 if (TREE_CODE (gnu_type) != ARRAY_TYPE)
953 gigi_abort (307);
955 gnat_temp = gnat_expr_array[i];
956 gnu_expr = gnat_to_gnu (gnat_temp);
958 if (Do_Range_Check (gnat_temp))
959 gnu_expr
960 = emit_index_check
961 (gnu_array_object, gnu_expr,
962 TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))),
963 TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))));
965 gnu_result = build_binary_op (ARRAY_REF, NULL_TREE,
966 gnu_result, gnu_expr);
970 gnu_result_type = get_unpadded_type (Etype (gnat_node));
971 break;
973 case N_Slice:
975 tree gnu_type;
976 Node_Id gnat_range_node = Discrete_Range (gnat_node);
978 gnu_result = gnat_to_gnu (Prefix (gnat_node));
979 gnu_result_type = get_unpadded_type (Etype (gnat_node));
981 /* Do any implicit dereferences of the prefix and do any needed
982 range check. */
983 gnu_result = maybe_implicit_deref (gnu_result);
984 gnu_result = maybe_unconstrained_array (gnu_result);
985 gnu_type = TREE_TYPE (gnu_result);
986 if (Do_Range_Check (gnat_range_node))
988 /* Get the bounds of the slice. */
989 tree gnu_index_type
990 = TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_result_type));
991 tree gnu_min_expr = TYPE_MIN_VALUE (gnu_index_type);
992 tree gnu_max_expr = TYPE_MAX_VALUE (gnu_index_type);
993 tree gnu_expr_l, gnu_expr_h, gnu_expr_type;
995 /* Check to see that the minimum slice value is in range */
996 gnu_expr_l
997 = emit_index_check
998 (gnu_result, gnu_min_expr,
999 TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))),
1000 TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))));
1002 /* Check to see that the maximum slice value is in range */
1003 gnu_expr_h
1004 = emit_index_check
1005 (gnu_result, gnu_max_expr,
1006 TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))),
1007 TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))));
1009 /* Derive a good type to convert everything too */
1010 gnu_expr_type = get_base_type (TREE_TYPE (gnu_expr_l));
1012 /* Build a compound expression that does the range checks */
1013 gnu_expr
1014 = build_binary_op (COMPOUND_EXPR, gnu_expr_type,
1015 convert (gnu_expr_type, gnu_expr_h),
1016 convert (gnu_expr_type, gnu_expr_l));
1018 /* Build a conditional expression that returns the range checks
1019 expression if the slice range is not null (max >= min) or
1020 returns the min if the slice range is null */
1021 gnu_expr
1022 = fold (build (COND_EXPR, gnu_expr_type,
1023 build_binary_op (GE_EXPR, gnu_expr_type,
1024 convert (gnu_expr_type,
1025 gnu_max_expr),
1026 convert (gnu_expr_type,
1027 gnu_min_expr)),
1028 gnu_expr, gnu_min_expr));
1030 else
1031 gnu_expr = TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_result_type));
1033 gnu_result = build_binary_op (ARRAY_RANGE_REF, gnu_result_type,
1034 gnu_result, gnu_expr);
1036 break;
1038 case N_Selected_Component:
1040 tree gnu_prefix = gnat_to_gnu (Prefix (gnat_node));
1041 Entity_Id gnat_field = Entity (Selector_Name (gnat_node));
1042 Entity_Id gnat_pref_type = Etype (Prefix (gnat_node));
1043 tree gnu_field;
1045 while (IN (Ekind (gnat_pref_type), Incomplete_Or_Private_Kind)
1046 || IN (Ekind (gnat_pref_type), Access_Kind))
1048 if (IN (Ekind (gnat_pref_type), Incomplete_Or_Private_Kind))
1049 gnat_pref_type = Underlying_Type (gnat_pref_type);
1050 else if (IN (Ekind (gnat_pref_type), Access_Kind))
1051 gnat_pref_type = Designated_Type (gnat_pref_type);
1054 gnu_prefix = maybe_implicit_deref (gnu_prefix);
1056 /* For discriminant references in tagged types always substitute the
1057 corresponding discriminant as the actual selected component. */
1059 if (Is_Tagged_Type (gnat_pref_type))
1060 while (Present (Corresponding_Discriminant (gnat_field)))
1061 gnat_field = Corresponding_Discriminant (gnat_field);
1063 /* For discriminant references of untagged types always substitute the
1064 corresponding stored discriminant. */
1066 else if (Present (Corresponding_Discriminant (gnat_field)))
1067 gnat_field = Original_Record_Component (gnat_field);
1069 /* Handle extracting the real or imaginary part of a complex.
1070 The real part is the first field and the imaginary the last. */
1072 if (TREE_CODE (TREE_TYPE (gnu_prefix)) == COMPLEX_TYPE)
1073 gnu_result = build_unary_op (Present (Next_Entity (gnat_field))
1074 ? REALPART_EXPR : IMAGPART_EXPR,
1075 NULL_TREE, gnu_prefix);
1076 else
1078 gnu_field = gnat_to_gnu_entity (gnat_field, NULL_TREE, 0);
1080 /* If there are discriminants, the prefix might be
1081 evaluated more than once, which is a problem if it has
1082 side-effects. */
1083 if (Has_Discriminants (Is_Access_Type (Etype (Prefix (gnat_node)))
1084 ? Designated_Type (Etype
1085 (Prefix (gnat_node)))
1086 : Etype (Prefix (gnat_node))))
1087 gnu_prefix = gnat_stabilize_reference (gnu_prefix, 0);
1089 gnu_result
1090 = build_component_ref (gnu_prefix, NULL_TREE, gnu_field,
1091 (Nkind (Parent (gnat_node))
1092 == N_Attribute_Reference));
1095 if (gnu_result == 0)
1096 gigi_abort (308);
1098 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1100 break;
1102 case N_Attribute_Reference:
1104 /* The attribute designator (like an enumeration value). */
1105 int attribute = Get_Attribute_Id (Attribute_Name (gnat_node));
1106 int prefix_unused = 0;
1107 tree gnu_prefix;
1108 tree gnu_type;
1110 /* The Elab_Spec and Elab_Body attributes are special in that
1111 Prefix is a unit, not an object with a GCC equivalent. Similarly
1112 for Elaborated, since that variable isn't otherwise known. */
1113 if (attribute == Attr_Elab_Body || attribute == Attr_Elab_Spec)
1115 gnu_prefix
1116 = create_subprog_decl
1117 (create_concat_name (Entity (Prefix (gnat_node)),
1118 attribute == Attr_Elab_Body
1119 ? "elabb" : "elabs"),
1120 NULL_TREE, void_ftype, NULL_TREE, 0, 1, 1, 0);
1121 return gnu_prefix;
1124 gnu_prefix = gnat_to_gnu (Prefix (gnat_node));
1125 gnu_type = TREE_TYPE (gnu_prefix);
1127 /* If the input is a NULL_EXPR, make a new one. */
1128 if (TREE_CODE (gnu_prefix) == NULL_EXPR)
1130 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1131 gnu_result = build1 (NULL_EXPR, gnu_result_type,
1132 TREE_OPERAND (gnu_prefix, 0));
1133 break;
1136 switch (attribute)
1138 case Attr_Pos:
1139 case Attr_Val:
1140 /* These are just conversions until since representation
1141 clauses for enumerations are handled in the front end. */
1143 int check_p = Do_Range_Check (First (Expressions (gnat_node)));
1145 gnu_result = gnat_to_gnu (First (Expressions (gnat_node)));
1146 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1147 gnu_result = convert_with_check (Etype (gnat_node), gnu_result,
1148 check_p, check_p, 1);
1150 break;
1152 case Attr_Pred:
1153 case Attr_Succ:
1154 /* These just add or subject the constant 1. Representation
1155 clauses for enumerations are handled in the front-end. */
1156 gnu_expr = gnat_to_gnu (First (Expressions (gnat_node)));
1157 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1159 if (Do_Range_Check (First (Expressions (gnat_node))))
1161 gnu_expr = protect_multiple_eval (gnu_expr);
1162 gnu_expr
1163 = emit_check
1164 (build_binary_op (EQ_EXPR, integer_type_node,
1165 gnu_expr,
1166 attribute == Attr_Pred
1167 ? TYPE_MIN_VALUE (gnu_result_type)
1168 : TYPE_MAX_VALUE (gnu_result_type)),
1169 gnu_expr, CE_Range_Check_Failed);
1172 gnu_result
1173 = build_binary_op (attribute == Attr_Pred
1174 ? MINUS_EXPR : PLUS_EXPR,
1175 gnu_result_type, gnu_expr,
1176 convert (gnu_result_type, integer_one_node));
1177 break;
1179 case Attr_Address:
1180 case Attr_Unrestricted_Access:
1182 /* Conversions don't change something's address but can cause
1183 us to miss the COMPONENT_REF case below, so strip them off. */
1184 gnu_prefix
1185 = remove_conversions (gnu_prefix,
1186 ! Must_Be_Byte_Aligned (gnat_node));
1188 /* If we are taking 'Address of an unconstrained object,
1189 this is the pointer to the underlying array. */
1190 gnu_prefix = maybe_unconstrained_array (gnu_prefix);
1192 /* ... fall through ... */
1194 case Attr_Access:
1195 case Attr_Unchecked_Access:
1196 case Attr_Code_Address:
1198 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1199 gnu_result
1200 = build_unary_op (((attribute == Attr_Address
1201 || attribute == Attr_Unrestricted_Access)
1202 && ! Must_Be_Byte_Aligned (gnat_node))
1203 ? ATTR_ADDR_EXPR : ADDR_EXPR,
1204 gnu_result_type, gnu_prefix);
1206 /* For 'Code_Address, find an inner ADDR_EXPR and mark it
1207 so that we don't try to build a trampoline. */
1208 if (attribute == Attr_Code_Address)
1210 for (gnu_expr = gnu_result;
1211 TREE_CODE (gnu_expr) == NOP_EXPR
1212 || TREE_CODE (gnu_expr) == CONVERT_EXPR;
1213 gnu_expr = TREE_OPERAND (gnu_expr, 0))
1214 TREE_CONSTANT (gnu_expr) = 1;
1217 if (TREE_CODE (gnu_expr) == ADDR_EXPR)
1218 TREE_STATIC (gnu_expr) = TREE_CONSTANT (gnu_expr) = 1;
1221 break;
1223 case Attr_Pool_Address:
1225 tree gnu_obj_type;
1226 tree gnu_ptr = gnu_prefix;
1228 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1230 /* If this is an unconstrained array, we know the object must
1231 have been allocated with the template in front of the object.
1232 So compute the template address.*/
1234 if (TYPE_FAT_POINTER_P (TREE_TYPE (gnu_ptr)))
1235 gnu_ptr
1236 = convert (build_pointer_type
1237 (TYPE_OBJECT_RECORD_TYPE
1238 (TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (gnu_ptr)))),
1239 gnu_ptr);
1241 gnu_obj_type = TREE_TYPE (TREE_TYPE (gnu_ptr));
1242 if (TREE_CODE (gnu_obj_type) == RECORD_TYPE
1243 && TYPE_CONTAINS_TEMPLATE_P (gnu_obj_type))
1245 tree gnu_char_ptr_type = build_pointer_type (char_type_node);
1246 tree gnu_pos = byte_position (TYPE_FIELDS (gnu_obj_type));
1247 tree gnu_byte_offset
1248 = convert (gnu_char_ptr_type,
1249 size_diffop (size_zero_node, gnu_pos));
1251 gnu_ptr = convert (gnu_char_ptr_type, gnu_ptr);
1252 gnu_ptr = build_binary_op (MINUS_EXPR, gnu_char_ptr_type,
1253 gnu_ptr, gnu_byte_offset);
1256 gnu_result = convert (gnu_result_type, gnu_ptr);
1258 break;
1260 case Attr_Size:
1261 case Attr_Object_Size:
1262 case Attr_Value_Size:
1263 case Attr_Max_Size_In_Storage_Elements:
1265 gnu_expr = gnu_prefix;
1267 /* Remove NOPS from gnu_expr and conversions from gnu_prefix.
1268 We only use GNU_EXPR to see if a COMPONENT_REF was involved. */
1269 while (TREE_CODE (gnu_expr) == NOP_EXPR)
1270 gnu_expr = TREE_OPERAND (gnu_expr, 0);
1272 gnu_prefix = remove_conversions (gnu_prefix, 1);
1273 prefix_unused = 1;
1274 gnu_type = TREE_TYPE (gnu_prefix);
1276 /* Replace an unconstrained array type with the type of the
1277 underlying array. We can't do this with a call to
1278 maybe_unconstrained_array since we may have a TYPE_DECL.
1279 For 'Max_Size_In_Storage_Elements, use the record type
1280 that will be used to allocate the object and its template. */
1282 if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
1284 gnu_type = TYPE_OBJECT_RECORD_TYPE (gnu_type);
1285 if (attribute != Attr_Max_Size_In_Storage_Elements)
1286 gnu_type = TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_type)));
1289 /* If we are looking for the size of a field, return the
1290 field size. Otherwise, if the prefix is an object,
1291 or if 'Object_Size or 'Max_Size_In_Storage_Elements has
1292 been specified, the result is the GCC size of the type.
1293 Otherwise, the result is the RM_Size of the type. */
1294 if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
1295 gnu_result = DECL_SIZE (TREE_OPERAND (gnu_prefix, 1));
1296 else if (TREE_CODE (gnu_prefix) != TYPE_DECL
1297 || attribute == Attr_Object_Size
1298 || attribute == Attr_Max_Size_In_Storage_Elements)
1300 /* If this is a padded type, the GCC size isn't relevant
1301 to the programmer. Normally, what we want is the RM_Size,
1302 which was set from the specified size, but if it was not
1303 set, we want the size of the relevant field. Using the MAX
1304 of those two produces the right result in all case. Don't
1305 use the size of the field if it's a self-referential type,
1306 since that's never what's wanted. */
1307 if (TREE_CODE (gnu_type) == RECORD_TYPE
1308 && TYPE_IS_PADDING_P (gnu_type)
1309 && TREE_CODE (gnu_expr) == COMPONENT_REF)
1311 gnu_result = rm_size (gnu_type);
1312 if (! (CONTAINS_PLACEHOLDER_P
1313 (DECL_SIZE (TREE_OPERAND (gnu_expr, 1)))))
1314 gnu_result
1315 = size_binop (MAX_EXPR, gnu_result,
1316 DECL_SIZE (TREE_OPERAND (gnu_expr, 1)));
1318 else
1319 gnu_result = TYPE_SIZE (gnu_type);
1321 else
1322 gnu_result = rm_size (gnu_type);
1324 if (gnu_result == 0)
1325 gigi_abort (325);
1327 /* Deal with a self-referential size by returning the maximum
1328 size for a type and by qualifying the size with
1329 the object for 'Size of an object. */
1331 if (CONTAINS_PLACEHOLDER_P (gnu_result))
1333 if (TREE_CODE (gnu_prefix) != TYPE_DECL)
1334 gnu_result = substitute_placeholder_in_expr (gnu_result,
1335 gnu_expr);
1336 else
1337 gnu_result = max_size (gnu_result, 1);
1340 /* If the type contains a template, subtract the size of the
1341 template. */
1342 if (TREE_CODE (gnu_type) == RECORD_TYPE
1343 && TYPE_CONTAINS_TEMPLATE_P (gnu_type))
1344 gnu_result = size_binop (MINUS_EXPR, gnu_result,
1345 DECL_SIZE (TYPE_FIELDS (gnu_type)));
1347 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1349 /* Always perform division using unsigned arithmetic as the
1350 size cannot be negative, but may be an overflowed positive
1351 value. This provides correct results for sizes up to 512 MB.
1352 ??? Size should be calculated in storage elements directly. */
1354 if (attribute == Attr_Max_Size_In_Storage_Elements)
1355 gnu_result = convert (sizetype,
1356 fold (build (CEIL_DIV_EXPR, bitsizetype,
1357 gnu_result,
1358 bitsize_unit_node)));
1359 break;
1361 case Attr_Alignment:
1362 if (TREE_CODE (gnu_prefix) == COMPONENT_REF
1363 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))
1364 == RECORD_TYPE)
1365 && (TYPE_IS_PADDING_P
1366 (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))))
1367 gnu_prefix = TREE_OPERAND (gnu_prefix, 0);
1369 gnu_type = TREE_TYPE (gnu_prefix);
1370 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1371 prefix_unused = 1;
1373 if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
1374 gnu_result
1375 = size_int (DECL_ALIGN (TREE_OPERAND (gnu_prefix, 1)));
1376 else
1377 gnu_result = size_int (TYPE_ALIGN (gnu_type) / BITS_PER_UNIT);
1378 break;
1380 case Attr_First:
1381 case Attr_Last:
1382 case Attr_Range_Length:
1383 prefix_unused = 1;
1385 if (INTEGRAL_TYPE_P (gnu_type)
1386 || TREE_CODE (gnu_type) == REAL_TYPE)
1388 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1390 if (attribute == Attr_First)
1391 gnu_result = TYPE_MIN_VALUE (gnu_type);
1392 else if (attribute == Attr_Last)
1393 gnu_result = TYPE_MAX_VALUE (gnu_type);
1394 else
1395 gnu_result
1396 = build_binary_op
1397 (MAX_EXPR, get_base_type (gnu_result_type),
1398 build_binary_op
1399 (PLUS_EXPR, get_base_type (gnu_result_type),
1400 build_binary_op (MINUS_EXPR,
1401 get_base_type (gnu_result_type),
1402 convert (gnu_result_type,
1403 TYPE_MAX_VALUE (gnu_type)),
1404 convert (gnu_result_type,
1405 TYPE_MIN_VALUE (gnu_type))),
1406 convert (gnu_result_type, integer_one_node)),
1407 convert (gnu_result_type, integer_zero_node));
1409 break;
1411 /* ... fall through ... */
1412 case Attr_Length:
1414 int Dimension
1415 = (Present (Expressions (gnat_node))
1416 ? UI_To_Int (Intval (First (Expressions (gnat_node))))
1417 : 1);
1419 /* Make sure any implicit dereference gets done. */
1420 gnu_prefix = maybe_implicit_deref (gnu_prefix);
1421 gnu_prefix = maybe_unconstrained_array (gnu_prefix);
1422 gnu_type = TREE_TYPE (gnu_prefix);
1423 prefix_unused = 1;
1424 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1426 if (TYPE_CONVENTION_FORTRAN_P (gnu_type))
1428 int ndim;
1429 tree gnu_type_temp;
1431 for (ndim = 1, gnu_type_temp = gnu_type;
1432 TREE_CODE (TREE_TYPE (gnu_type_temp)) == ARRAY_TYPE
1433 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type_temp));
1434 ndim++, gnu_type_temp = TREE_TYPE (gnu_type_temp))
1437 Dimension = ndim + 1 - Dimension;
1440 for (; Dimension > 1; Dimension--)
1441 gnu_type = TREE_TYPE (gnu_type);
1443 if (TREE_CODE (gnu_type) != ARRAY_TYPE)
1444 gigi_abort (309);
1446 if (attribute == Attr_First)
1447 gnu_result
1448 = TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
1449 else if (attribute == Attr_Last)
1450 gnu_result
1451 = TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
1452 else
1453 /* 'Length or 'Range_Length. */
1455 tree gnu_compute_type
1456 = gnat_signed_or_unsigned_type
1457 (0, get_base_type (gnu_result_type));
1459 gnu_result
1460 = build_binary_op
1461 (MAX_EXPR, gnu_compute_type,
1462 build_binary_op
1463 (PLUS_EXPR, gnu_compute_type,
1464 build_binary_op
1465 (MINUS_EXPR, gnu_compute_type,
1466 convert (gnu_compute_type,
1467 TYPE_MAX_VALUE
1468 (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)))),
1469 convert (gnu_compute_type,
1470 TYPE_MIN_VALUE
1471 (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))))),
1472 convert (gnu_compute_type, integer_one_node)),
1473 convert (gnu_compute_type, integer_zero_node));
1476 /* If this has a PLACEHOLDER_EXPR, qualify it by the object
1477 we are handling. Note that these attributes could not
1478 have been used on an unconstrained array type. */
1479 gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result,
1480 gnu_prefix);
1482 break;
1485 case Attr_Bit_Position:
1486 case Attr_Position:
1487 case Attr_First_Bit:
1488 case Attr_Last_Bit:
1489 case Attr_Bit:
1491 HOST_WIDE_INT bitsize;
1492 HOST_WIDE_INT bitpos;
1493 tree gnu_offset;
1494 tree gnu_field_bitpos;
1495 tree gnu_field_offset;
1496 tree gnu_inner;
1497 enum machine_mode mode;
1498 int unsignedp, volatilep;
1500 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1501 gnu_prefix = remove_conversions (gnu_prefix, 1);
1502 prefix_unused = 1;
1504 /* We can have 'Bit on any object, but if it isn't a
1505 COMPONENT_REF, the result is zero. Do not allow
1506 'Bit on a bare component, though. */
1507 if (attribute == Attr_Bit
1508 && TREE_CODE (gnu_prefix) != COMPONENT_REF
1509 && TREE_CODE (gnu_prefix) != FIELD_DECL)
1511 gnu_result = integer_zero_node;
1512 break;
1515 else if (TREE_CODE (gnu_prefix) != COMPONENT_REF
1516 && ! (attribute == Attr_Bit_Position
1517 && TREE_CODE (gnu_prefix) == FIELD_DECL))
1518 gigi_abort (310);
1520 get_inner_reference (gnu_prefix, &bitsize, &bitpos, &gnu_offset,
1521 &mode, &unsignedp, &volatilep);
1523 if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
1525 gnu_field_bitpos
1526 = bit_position (TREE_OPERAND (gnu_prefix, 1));
1527 gnu_field_offset
1528 = byte_position (TREE_OPERAND (gnu_prefix, 1));
1530 for (gnu_inner = TREE_OPERAND (gnu_prefix, 0);
1531 TREE_CODE (gnu_inner) == COMPONENT_REF
1532 && DECL_INTERNAL_P (TREE_OPERAND (gnu_inner, 1));
1533 gnu_inner = TREE_OPERAND (gnu_inner, 0))
1535 gnu_field_bitpos
1536 = size_binop (PLUS_EXPR, gnu_field_bitpos,
1537 bit_position (TREE_OPERAND (gnu_inner,
1538 1)));
1539 gnu_field_offset
1540 = size_binop (PLUS_EXPR, gnu_field_offset,
1541 byte_position (TREE_OPERAND (gnu_inner,
1542 1)));
1545 else if (TREE_CODE (gnu_prefix) == FIELD_DECL)
1547 gnu_field_bitpos = bit_position (gnu_prefix);
1548 gnu_field_offset = byte_position (gnu_prefix);
1550 else
1552 gnu_field_bitpos = bitsize_zero_node;
1553 gnu_field_offset = size_zero_node;
1556 switch (attribute)
1558 case Attr_Position:
1559 gnu_result = gnu_field_offset;
1560 break;
1562 case Attr_First_Bit:
1563 case Attr_Bit:
1564 gnu_result = size_int (bitpos % BITS_PER_UNIT);
1565 break;
1567 case Attr_Last_Bit:
1568 gnu_result = bitsize_int (bitpos % BITS_PER_UNIT);
1569 gnu_result
1570 = size_binop (PLUS_EXPR, gnu_result,
1571 TYPE_SIZE (TREE_TYPE (gnu_prefix)));
1572 gnu_result = size_binop (MINUS_EXPR, gnu_result,
1573 bitsize_one_node);
1574 break;
1576 case Attr_Bit_Position:
1577 gnu_result = gnu_field_bitpos;
1578 break;
1581 /* If this has a PLACEHOLDER_EXPR, qualify it by the object
1582 we are handling. */
1583 gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result,
1584 gnu_prefix);
1586 break;
1589 case Attr_Min:
1590 case Attr_Max:
1591 gnu_lhs = gnat_to_gnu (First (Expressions (gnat_node)));
1592 gnu_rhs = gnat_to_gnu (Next (First (Expressions (gnat_node))));
1594 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1595 gnu_result = build_binary_op (attribute == Attr_Min
1596 ? MIN_EXPR : MAX_EXPR,
1597 gnu_result_type, gnu_lhs, gnu_rhs);
1598 break;
1600 case Attr_Passed_By_Reference:
1601 gnu_result = size_int (default_pass_by_ref (gnu_type)
1602 || must_pass_by_ref (gnu_type));
1603 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1604 break;
1606 case Attr_Component_Size:
1607 if (TREE_CODE (gnu_prefix) == COMPONENT_REF
1608 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))
1609 == RECORD_TYPE)
1610 && (TYPE_IS_PADDING_P
1611 (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))))
1612 gnu_prefix = TREE_OPERAND (gnu_prefix, 0);
1614 gnu_prefix = maybe_implicit_deref (gnu_prefix);
1615 gnu_type = TREE_TYPE (gnu_prefix);
1617 if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
1618 gnu_type
1619 = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_type))));
1621 while (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
1622 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type)))
1623 gnu_type = TREE_TYPE (gnu_type);
1625 if (TREE_CODE (gnu_type) != ARRAY_TYPE)
1626 gigi_abort (330);
1628 /* Note this size cannot be self-referential. */
1629 gnu_result = TYPE_SIZE (TREE_TYPE (gnu_type));
1630 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1631 prefix_unused = 1;
1632 break;
1634 case Attr_Null_Parameter:
1635 /* This is just a zero cast to the pointer type for
1636 our prefix and dereferenced. */
1637 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1638 gnu_result
1639 = build_unary_op (INDIRECT_REF, NULL_TREE,
1640 convert (build_pointer_type (gnu_result_type),
1641 integer_zero_node));
1642 TREE_PRIVATE (gnu_result) = 1;
1643 break;
1645 case Attr_Mechanism_Code:
1647 int code;
1648 Entity_Id gnat_obj = Entity (Prefix (gnat_node));
1650 prefix_unused = 1;
1651 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1652 if (Present (Expressions (gnat_node)))
1654 int i = UI_To_Int (Intval (First (Expressions (gnat_node))));
1656 for (gnat_obj = First_Formal (gnat_obj); i > 1;
1657 i--, gnat_obj = Next_Formal (gnat_obj))
1661 code = Mechanism (gnat_obj);
1662 if (code == Default)
1663 code = ((present_gnu_tree (gnat_obj)
1664 && (DECL_BY_REF_P (get_gnu_tree (gnat_obj))
1665 || ((TREE_CODE (get_gnu_tree (gnat_obj))
1666 == PARM_DECL)
1667 && (DECL_BY_COMPONENT_PTR_P
1668 (get_gnu_tree (gnat_obj))))))
1669 ? By_Reference : By_Copy);
1670 gnu_result = convert (gnu_result_type, size_int (- code));
1672 break;
1674 default:
1675 /* Say we have an unimplemented attribute. Then set the
1676 value to be returned to be a zero and hope that's something
1677 we can convert to the type of this attribute. */
1679 post_error ("unimplemented attribute", gnat_node);
1680 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1681 gnu_result = integer_zero_node;
1682 break;
1685 /* If this is an attribute where the prefix was unused,
1686 force a use of it if it has a side-effect. But don't do it if
1687 the prefix is just an entity name. However, if an access check
1688 is needed, we must do it. See second example in AARM 11.6(5.e). */
1689 if (prefix_unused && TREE_SIDE_EFFECTS (gnu_prefix)
1690 && ! Is_Entity_Name (Prefix (gnat_node)))
1691 gnu_result = fold (build (COMPOUND_EXPR, TREE_TYPE (gnu_result),
1692 gnu_prefix, gnu_result));
1694 break;
1696 case N_Reference:
1697 /* Like 'Access as far as we are concerned. */
1698 gnu_result = gnat_to_gnu (Prefix (gnat_node));
1699 gnu_result = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_result);
1700 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1701 break;
1703 case N_Aggregate:
1704 case N_Extension_Aggregate:
1706 tree gnu_aggr_type;
1708 /* ??? It is wrong to evaluate the type now, but there doesn't
1709 seem to be any other practical way of doing it. */
1711 gnu_aggr_type = gnu_result_type
1712 = get_unpadded_type (Etype (gnat_node));
1714 if (TREE_CODE (gnu_result_type) == RECORD_TYPE
1715 && TYPE_CONTAINS_TEMPLATE_P (gnu_result_type))
1716 gnu_aggr_type
1717 = TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_result_type)));
1719 if (Null_Record_Present (gnat_node))
1720 gnu_result = gnat_build_constructor (gnu_aggr_type, NULL_TREE);
1722 else if (TREE_CODE (gnu_aggr_type) == RECORD_TYPE)
1723 gnu_result
1724 = assoc_to_constructor (First (Component_Associations (gnat_node)),
1725 gnu_aggr_type);
1726 else if (TREE_CODE (gnu_aggr_type) == UNION_TYPE)
1728 /* The first element is the discrimant, which we ignore. The
1729 next is the field we're building. Convert the expression
1730 to the type of the field and then to the union type. */
1731 Node_Id gnat_assoc
1732 = Next (First (Component_Associations (gnat_node)));
1733 Entity_Id gnat_field = Entity (First (Choices (gnat_assoc)));
1734 tree gnu_field_type
1735 = TREE_TYPE (gnat_to_gnu_entity (gnat_field, NULL_TREE, 0));
1737 gnu_result = convert (gnu_field_type,
1738 gnat_to_gnu (Expression (gnat_assoc)));
1740 else if (TREE_CODE (gnu_aggr_type) == ARRAY_TYPE)
1741 gnu_result = pos_to_constructor (First (Expressions (gnat_node)),
1742 gnu_aggr_type,
1743 Component_Type (Etype (gnat_node)));
1744 else if (TREE_CODE (gnu_aggr_type) == COMPLEX_TYPE)
1745 gnu_result
1746 = build_binary_op
1747 (COMPLEX_EXPR, gnu_aggr_type,
1748 gnat_to_gnu (Expression (First
1749 (Component_Associations (gnat_node)))),
1750 gnat_to_gnu (Expression
1751 (Next
1752 (First (Component_Associations (gnat_node))))));
1753 else
1754 gigi_abort (312);
1756 gnu_result = convert (gnu_result_type, gnu_result);
1758 break;
1760 case N_Null:
1761 gnu_result = null_pointer_node;
1762 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1763 break;
1765 case N_Type_Conversion:
1766 case N_Qualified_Expression:
1767 /* Get the operand expression. */
1768 gnu_result = gnat_to_gnu (Expression (gnat_node));
1769 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1771 gnu_result
1772 = convert_with_check (Etype (gnat_node), gnu_result,
1773 Do_Overflow_Check (gnat_node),
1774 Do_Range_Check (Expression (gnat_node)),
1775 Nkind (gnat_node) == N_Type_Conversion
1776 && Float_Truncate (gnat_node));
1777 break;
1779 case N_Unchecked_Type_Conversion:
1780 gnu_result = gnat_to_gnu (Expression (gnat_node));
1781 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1783 /* If the result is a pointer type, see if we are improperly
1784 converting to a stricter alignment. */
1786 if (STRICT_ALIGNMENT && POINTER_TYPE_P (gnu_result_type)
1787 && IN (Ekind (Etype (gnat_node)), Access_Kind))
1789 unsigned int align = known_alignment (gnu_result);
1790 tree gnu_obj_type = TREE_TYPE (gnu_result_type);
1791 unsigned int oalign = TYPE_ALIGN (gnu_obj_type);
1793 if (align != 0 && align < oalign && ! TYPE_ALIGN_OK (gnu_obj_type))
1794 post_error_ne_tree_2
1795 ("?source alignment (^) < alignment of & (^)",
1796 gnat_node, Designated_Type (Etype (gnat_node)),
1797 size_int (align / BITS_PER_UNIT), oalign / BITS_PER_UNIT);
1800 gnu_result = unchecked_convert (gnu_result_type, gnu_result,
1801 No_Truncation (gnat_node));
1802 break;
1804 case N_In:
1805 case N_Not_In:
1807 tree gnu_object = gnat_to_gnu (Left_Opnd (gnat_node));
1808 Node_Id gnat_range = Right_Opnd (gnat_node);
1809 tree gnu_low;
1810 tree gnu_high;
1812 /* GNAT_RANGE is either an N_Range node or an identifier
1813 denoting a subtype. */
1814 if (Nkind (gnat_range) == N_Range)
1816 gnu_low = gnat_to_gnu (Low_Bound (gnat_range));
1817 gnu_high = gnat_to_gnu (High_Bound (gnat_range));
1819 else if (Nkind (gnat_range) == N_Identifier
1820 || Nkind (gnat_range) == N_Expanded_Name)
1822 tree gnu_range_type = get_unpadded_type (Entity (gnat_range));
1824 gnu_low = TYPE_MIN_VALUE (gnu_range_type);
1825 gnu_high = TYPE_MAX_VALUE (gnu_range_type);
1827 else
1828 gigi_abort (313);
1830 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1832 /* If LOW and HIGH are identical, perform an equality test.
1833 Otherwise, ensure that GNU_OBJECT is only evaluated once
1834 and perform a full range test. */
1835 if (operand_equal_p (gnu_low, gnu_high, 0))
1836 gnu_result = build_binary_op (EQ_EXPR, gnu_result_type,
1837 gnu_object, gnu_low);
1838 else
1840 gnu_object = protect_multiple_eval (gnu_object);
1841 gnu_result
1842 = build_binary_op (TRUTH_ANDIF_EXPR, gnu_result_type,
1843 build_binary_op (GE_EXPR, gnu_result_type,
1844 gnu_object, gnu_low),
1845 build_binary_op (LE_EXPR, gnu_result_type,
1846 gnu_object, gnu_high));
1849 if (Nkind (gnat_node) == N_Not_In)
1850 gnu_result = invert_truthvalue (gnu_result);
1852 break;
1854 case N_Op_Divide:
1855 gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
1856 gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
1857 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1858 gnu_result = build_binary_op (FLOAT_TYPE_P (gnu_result_type)
1859 ? RDIV_EXPR
1860 : (Rounded_Result (gnat_node)
1861 ? ROUND_DIV_EXPR : TRUNC_DIV_EXPR),
1862 gnu_result_type, gnu_lhs, gnu_rhs);
1863 break;
1865 case N_And_Then: case N_Or_Else:
1867 /* Some processing below (e.g. clear_last_expr) requires access to
1868 status fields now maintained in the current function context, so
1869 we'll setup a dummy one if needed. We cannot use global_binding_p,
1870 since it might be true due to force_global and making a dummy
1871 context would kill the current function context. */
1872 bool make_dummy_context = (cfun == 0);
1873 enum tree_code code = gnu_codes[Nkind (gnat_node)];
1874 tree gnu_rhs_side;
1876 if (make_dummy_context)
1877 init_dummy_function_start ();
1879 /* The elaboration of the RHS may generate code. If so,
1880 we need to make sure it gets executed after the LHS. */
1881 gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
1882 clear_last_expr ();
1884 gnu_rhs_side = expand_start_stmt_expr (1 /*has_scope*/);
1885 gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
1886 expand_end_stmt_expr (gnu_rhs_side);
1888 if (make_dummy_context)
1889 expand_dummy_function_end ();
1891 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1893 if (first_nondeleted_insn (RTL_EXPR_SEQUENCE (gnu_rhs_side)))
1894 gnu_rhs = build (COMPOUND_EXPR, gnu_result_type, gnu_rhs_side,
1895 gnu_rhs);
1897 gnu_result = build_binary_op (code, gnu_result_type, gnu_lhs, gnu_rhs);
1899 break;
1901 case N_Op_Or: case N_Op_And: case N_Op_Xor:
1902 /* These can either be operations on booleans or on modular types.
1903 Fall through for boolean types since that's the way GNU_CODES is
1904 set up. */
1905 if (IN (Ekind (Underlying_Type (Etype (gnat_node))),
1906 Modular_Integer_Kind))
1908 enum tree_code code
1909 = (Nkind (gnat_node) == N_Op_Or ? BIT_IOR_EXPR
1910 : Nkind (gnat_node) == N_Op_And ? BIT_AND_EXPR
1911 : BIT_XOR_EXPR);
1913 gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
1914 gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
1915 gnu_result_type = get_unpadded_type (Etype (gnat_node));
1916 gnu_result = build_binary_op (code, gnu_result_type,
1917 gnu_lhs, gnu_rhs);
1918 break;
1921 /* ... fall through ... */
1923 case N_Op_Eq: case N_Op_Ne: case N_Op_Lt:
1924 case N_Op_Le: case N_Op_Gt: case N_Op_Ge:
1925 case N_Op_Add: case N_Op_Subtract: case N_Op_Multiply:
1926 case N_Op_Mod: case N_Op_Rem:
1927 case N_Op_Rotate_Left:
1928 case N_Op_Rotate_Right:
1929 case N_Op_Shift_Left:
1930 case N_Op_Shift_Right:
1931 case N_Op_Shift_Right_Arithmetic:
1933 enum tree_code code = gnu_codes[Nkind (gnat_node)];
1934 tree gnu_type;
1936 gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
1937 gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
1938 gnu_type = gnu_result_type = get_unpadded_type (Etype (gnat_node));
1940 /* If this is a comparison operator, convert any references to
1941 an unconstrained array value into a reference to the
1942 actual array. */
1943 if (TREE_CODE_CLASS (code) == '<')
1945 gnu_lhs = maybe_unconstrained_array (gnu_lhs);
1946 gnu_rhs = maybe_unconstrained_array (gnu_rhs);
1949 /* If the result type is a private type, its full view may be a
1950 numeric subtype. The representation we need is that of its base
1951 type, given that it is the result of an arithmetic operation. */
1952 else if (Is_Private_Type (Etype (gnat_node)))
1953 gnu_type = gnu_result_type
1954 = get_unpadded_type (Base_Type (Full_View (Etype (gnat_node))));
1956 /* If this is a shift whose count is not guaranteed to be correct,
1957 we need to adjust the shift count. */
1958 if (IN (Nkind (gnat_node), N_Op_Shift)
1959 && ! Shift_Count_OK (gnat_node))
1961 tree gnu_count_type = get_base_type (TREE_TYPE (gnu_rhs));
1962 tree gnu_max_shift
1963 = convert (gnu_count_type, TYPE_SIZE (gnu_type));
1965 if (Nkind (gnat_node) == N_Op_Rotate_Left
1966 || Nkind (gnat_node) == N_Op_Rotate_Right)
1967 gnu_rhs = build_binary_op (TRUNC_MOD_EXPR, gnu_count_type,
1968 gnu_rhs, gnu_max_shift);
1969 else if (Nkind (gnat_node) == N_Op_Shift_Right_Arithmetic)
1970 gnu_rhs
1971 = build_binary_op
1972 (MIN_EXPR, gnu_count_type,
1973 build_binary_op (MINUS_EXPR,
1974 gnu_count_type,
1975 gnu_max_shift,
1976 convert (gnu_count_type,
1977 integer_one_node)),
1978 gnu_rhs);
1981 /* For right shifts, the type says what kind of shift to do,
1982 so we may need to choose a different type. */
1983 if (Nkind (gnat_node) == N_Op_Shift_Right
1984 && ! TYPE_UNSIGNED (gnu_type))
1985 gnu_type = gnat_unsigned_type (gnu_type);
1986 else if (Nkind (gnat_node) == N_Op_Shift_Right_Arithmetic
1987 && TYPE_UNSIGNED (gnu_type))
1988 gnu_type = gnat_signed_type (gnu_type);
1990 if (gnu_type != gnu_result_type)
1992 gnu_lhs = convert (gnu_type, gnu_lhs);
1993 gnu_rhs = convert (gnu_type, gnu_rhs);
1996 gnu_result = build_binary_op (code, gnu_type, gnu_lhs, gnu_rhs);
1998 /* If this is a logical shift with the shift count not verified,
1999 we must return zero if it is too large. We cannot compensate
2000 above in this case. */
2001 if ((Nkind (gnat_node) == N_Op_Shift_Left
2002 || Nkind (gnat_node) == N_Op_Shift_Right)
2003 && ! Shift_Count_OK (gnat_node))
2004 gnu_result
2005 = build_cond_expr
2006 (gnu_type,
2007 build_binary_op (GE_EXPR, integer_type_node,
2008 gnu_rhs,
2009 convert (TREE_TYPE (gnu_rhs),
2010 TYPE_SIZE (gnu_type))),
2011 convert (gnu_type, integer_zero_node),
2012 gnu_result);
2014 break;
2016 case N_Conditional_Expression:
2018 tree gnu_cond = gnat_to_gnu (First (Expressions (gnat_node)));
2019 tree gnu_true = gnat_to_gnu (Next (First (Expressions (gnat_node))));
2020 tree gnu_false
2021 = gnat_to_gnu (Next (Next (First (Expressions (gnat_node)))));
2023 gnu_result_type = get_unpadded_type (Etype (gnat_node));
2024 gnu_result = build_cond_expr (gnu_result_type,
2025 gnat_truthvalue_conversion (gnu_cond),
2026 gnu_true, gnu_false);
2028 break;
2030 case N_Op_Plus:
2031 gnu_result = gnat_to_gnu (Right_Opnd (gnat_node));
2032 gnu_result_type = get_unpadded_type (Etype (gnat_node));
2033 break;
2035 case N_Op_Not:
2036 /* This case can apply to a boolean or a modular type.
2037 Fall through for a boolean operand since GNU_CODES is set
2038 up to handle this. */
2039 if (IN (Ekind (Etype (gnat_node)), Modular_Integer_Kind))
2041 gnu_expr = gnat_to_gnu (Right_Opnd (gnat_node));
2042 gnu_result_type = get_unpadded_type (Etype (gnat_node));
2043 gnu_result = build_unary_op (BIT_NOT_EXPR, gnu_result_type,
2044 gnu_expr);
2045 break;
2048 /* ... fall through ... */
2050 case N_Op_Minus: case N_Op_Abs:
2051 gnu_expr = gnat_to_gnu (Right_Opnd (gnat_node));
2053 if (Ekind (Etype (gnat_node)) != E_Private_Type)
2054 gnu_result_type = get_unpadded_type (Etype (gnat_node));
2055 else
2056 gnu_result_type = get_unpadded_type (Base_Type
2057 (Full_View (Etype (gnat_node))));
2059 gnu_result = build_unary_op (gnu_codes[Nkind (gnat_node)],
2060 gnu_result_type, gnu_expr);
2061 break;
2063 case N_Allocator:
2065 tree gnu_init = 0;
2066 tree gnu_type;
2068 gnat_temp = Expression (gnat_node);
2070 /* The Expression operand can either be an N_Identifier or
2071 Expanded_Name, which must represent a type, or a
2072 N_Qualified_Expression, which contains both the object type and an
2073 initial value for the object. */
2074 if (Nkind (gnat_temp) == N_Identifier
2075 || Nkind (gnat_temp) == N_Expanded_Name)
2076 gnu_type = gnat_to_gnu_type (Entity (gnat_temp));
2077 else if (Nkind (gnat_temp) == N_Qualified_Expression)
2079 Entity_Id gnat_desig_type
2080 = Designated_Type (Underlying_Type (Etype (gnat_node)));
2082 gnu_init = gnat_to_gnu (Expression (gnat_temp));
2084 gnu_init = maybe_unconstrained_array (gnu_init);
2085 if (Do_Range_Check (Expression (gnat_temp)))
2086 gnu_init = emit_range_check (gnu_init, gnat_desig_type);
2088 if (Is_Elementary_Type (gnat_desig_type)
2089 || Is_Constrained (gnat_desig_type))
2091 gnu_type = gnat_to_gnu_type (gnat_desig_type);
2092 gnu_init = convert (gnu_type, gnu_init);
2094 else
2096 gnu_type = gnat_to_gnu_type (Etype (Expression (gnat_temp)));
2097 if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
2098 gnu_type = TREE_TYPE (gnu_init);
2100 gnu_init = convert (gnu_type, gnu_init);
2103 else
2104 gigi_abort (315);
2106 gnu_result_type = get_unpadded_type (Etype (gnat_node));
2107 return build_allocator (gnu_type, gnu_init, gnu_result_type,
2108 Procedure_To_Call (gnat_node),
2109 Storage_Pool (gnat_node), gnat_node);
2111 break;
2113 /***************************/
2114 /* Chapter 5: Statements: */
2115 /***************************/
2117 case N_Label:
2118 gnu_result = build_nt (LABEL_STMT, gnat_to_gnu (Identifier (gnat_node)));
2119 break;
2121 case N_Null_Statement:
2122 gnu_result = build_nt (NULL_STMT);
2123 break;
2125 case N_Assignment_Statement:
2126 /* Get the LHS and RHS of the statement and convert any reference to an
2127 unconstrained array into a reference to the underlying array. */
2128 gnu_lhs = maybe_unconstrained_array (gnat_to_gnu (Name (gnat_node)));
2129 gnu_rhs
2130 = maybe_unconstrained_array (gnat_to_gnu (Expression (gnat_node)));
2132 /* If range check is needed, emit code to generate it */
2133 if (Do_Range_Check (Expression (gnat_node)))
2134 gnu_rhs = emit_range_check (gnu_rhs, Etype (Name (gnat_node)));
2136 /* If either side's type has a size that overflows, convert this
2137 into raise of Storage_Error: execution shouldn't have gotten
2138 here anyway. */
2139 if ((TREE_CODE (TYPE_SIZE (TREE_TYPE (gnu_lhs))) == INTEGER_CST
2140 && TREE_OVERFLOW (TYPE_SIZE (TREE_TYPE (gnu_lhs))))
2141 || (TREE_CODE (TYPE_SIZE (TREE_TYPE (gnu_rhs))) == INTEGER_CST
2142 && TREE_OVERFLOW (TYPE_SIZE (TREE_TYPE (gnu_rhs)))))
2143 gnu_result = build_call_raise (SE_Object_Too_Large);
2144 else
2145 gnu_result
2146 = build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_lhs, gnu_rhs);
2148 gnu_result = build_nt (EXPR_STMT, gnu_result);
2149 break;
2151 case N_If_Statement:
2152 gnu_result = NULL_TREE;
2154 /* Make an IF_STMT for each of the "else if" parts. Avoid
2155 non-determinism. */
2156 if (Present (Elsif_Parts (gnat_node)))
2157 for (gnat_temp = First (Elsif_Parts (gnat_node));
2158 Present (gnat_temp); gnat_temp = Next (gnat_temp))
2160 gnu_expr = make_node (IF_STMT);
2162 IF_STMT_COND (gnu_expr) = gnat_to_gnu (Condition (gnat_temp));
2163 IF_STMT_TRUE (gnu_expr)
2164 = build_block_stmt (Then_Statements (gnat_temp));
2165 IF_STMT_ELSE (gnu_expr) = IF_STMT_ELSEIF (gnu_expr) = NULL_TREE;
2166 TREE_SLOC (gnu_expr) = Sloc (Condition (gnat_temp));
2167 TREE_CHAIN (gnu_expr) = gnu_result;
2168 TREE_TYPE (gnu_expr) = void_type_node;
2169 gnu_result = gnu_expr;
2172 /* Now make the IF_STMT. Also avoid non-determinism. */
2173 gnu_expr = make_node (IF_STMT);
2174 IF_STMT_COND (gnu_expr) = gnat_to_gnu (Condition (gnat_node));
2175 IF_STMT_TRUE (gnu_expr) = build_block_stmt (Then_Statements (gnat_node));
2176 IF_STMT_ELSEIF (gnu_expr) = nreverse (gnu_result);
2177 IF_STMT_ELSE (gnu_expr) = build_block_stmt (Else_Statements (gnat_node));
2178 gnu_result = gnu_expr;
2179 break;
2181 case N_Case_Statement:
2183 Node_Id gnat_when;
2184 Node_Id gnat_choice;
2185 tree gnu_label;
2186 Node_Id gnat_statement;
2188 gnu_expr = gnat_to_gnu (Expression (gnat_node));
2189 gnu_expr = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr);
2191 /* The range of values in a case statement is determined by the
2192 rules in RM 5.4(7-9). In almost all cases, this range is
2193 represented by the Etype of the expression. One exception arises
2194 in the case of a simple name that is parenthesized. This still
2195 has the Etype of the name, but since it is not a name, para 7
2196 does not apply, and we need to go to the base type. This is the
2197 only case where parenthesization affects the dynamic semantics
2198 (i.e. the range of possible values at runtime that is covered by
2199 the others alternative.
2201 Another exception is if the subtype of the expression is
2202 non-static. In that case, we also have to use the base type. */
2203 if (Paren_Count (Expression (gnat_node)) != 0
2204 || !Is_OK_Static_Subtype (Underlying_Type
2205 (Etype (Expression (gnat_node)))))
2206 gnu_expr = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr);
2208 set_lineno (gnat_node, 1);
2209 expand_start_case (1, gnu_expr, TREE_TYPE (gnu_expr), "case");
2211 for (gnat_when = First_Non_Pragma (Alternatives (gnat_node));
2212 Present (gnat_when);
2213 gnat_when = Next_Non_Pragma (gnat_when))
2215 /* First compile all the different case choices for the current
2216 WHEN alternative. */
2218 for (gnat_choice = First (Discrete_Choices (gnat_when));
2219 Present (gnat_choice); gnat_choice = Next (gnat_choice))
2221 int error_code;
2223 gnu_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2225 set_lineno (gnat_choice, 1);
2226 switch (Nkind (gnat_choice))
2228 case N_Range:
2229 /* Abort on all errors except range empty, which
2230 means we ignore this alternative. */
2231 error_code
2232 = pushcase_range (gnat_to_gnu (Low_Bound (gnat_choice)),
2233 gnat_to_gnu (High_Bound (gnat_choice)),
2234 convert, gnu_label, 0);
2236 if (error_code != 0 && error_code != 4)
2237 gigi_abort (332);
2238 break;
2240 case N_Subtype_Indication:
2241 error_code
2242 = pushcase_range
2243 (gnat_to_gnu (Low_Bound (Range_Expression
2244 (Constraint (gnat_choice)))),
2245 gnat_to_gnu (High_Bound (Range_Expression
2246 (Constraint (gnat_choice)))),
2247 convert, gnu_label, 0);
2249 if (error_code != 0 && error_code != 4)
2250 gigi_abort (332);
2251 break;
2253 case N_Identifier:
2254 case N_Expanded_Name:
2255 /* This represents either a subtype range or a static value
2256 of some kind; Ekind says which. If a static value,
2257 fall through to the next case. */
2258 if (IN (Ekind (Entity (gnat_choice)), Type_Kind))
2260 tree type = get_unpadded_type (Entity (gnat_choice));
2262 error_code
2263 = pushcase_range (fold (TYPE_MIN_VALUE (type)),
2264 fold (TYPE_MAX_VALUE (type)),
2265 convert, gnu_label, 0);
2267 if (error_code != 0 && error_code != 4)
2268 gigi_abort (332);
2269 break;
2271 /* ... fall through ... */
2272 case N_Character_Literal:
2273 case N_Integer_Literal:
2274 if (pushcase (gnat_to_gnu (gnat_choice), convert,
2275 gnu_label, 0))
2276 gigi_abort (332);
2277 break;
2279 case N_Others_Choice:
2280 if (pushcase (NULL_TREE, convert, gnu_label, 0))
2281 gigi_abort (332);
2282 break;
2284 default:
2285 gigi_abort (316);
2289 /* After compiling the choices attached to the WHEN compile the
2290 body of statements that have to be executed, should the
2291 "WHEN ... =>" be taken. Push a binding level here in case
2292 variables are declared since we want them to be local to this
2293 set of statements instead of the block containing the Case
2294 statement. */
2295 gnat_pushlevel ();
2296 expand_start_bindings (0);
2297 for (gnat_statement = First (Statements (gnat_when));
2298 Present (gnat_statement);
2299 gnat_statement = Next (gnat_statement))
2300 gnat_to_code (gnat_statement);
2302 /* Communicate to GCC that we are done with the current WHEN,
2303 i.e. insert a "break" statement. */
2304 expand_exit_something ();
2305 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
2306 gnat_poplevel ();
2309 expand_end_case (gnu_expr);
2311 break;
2313 case N_Loop_Statement:
2315 /* The loop variable in GCC form, if any. */
2316 tree gnu_loop_var = NULL_TREE;
2317 /* PREINCREMENT_EXPR or PREDECREMENT_EXPR. */
2318 enum tree_code gnu_update = ERROR_MARK;
2319 /* Used if this is a named loop for so EXIT can work. */
2320 struct nesting *loop_id;
2321 /* Condition to continue loop tested at top of loop. */
2322 tree gnu_top_condition = integer_one_node;
2323 /* Similar, but tested at bottom of loop. */
2324 tree gnu_bottom_condition = integer_one_node;
2325 Node_Id gnat_statement;
2326 Node_Id gnat_iter_scheme = Iteration_Scheme (gnat_node);
2327 Node_Id gnat_top_condition = Empty;
2328 int enclosing_if_p = 0;
2330 /* Set the condition that under which the loop should continue.
2331 For "LOOP .... END LOOP;" the condition is always true. */
2332 if (No (gnat_iter_scheme))
2334 /* The case "WHILE condition LOOP ..... END LOOP;" */
2335 else if (Present (Condition (gnat_iter_scheme)))
2336 gnat_top_condition = Condition (gnat_iter_scheme);
2337 else
2339 /* We have an iteration scheme. */
2340 Node_Id gnat_loop_spec
2341 = Loop_Parameter_Specification (gnat_iter_scheme);
2342 Entity_Id gnat_loop_var = Defining_Entity (gnat_loop_spec);
2343 Entity_Id gnat_type = Etype (gnat_loop_var);
2344 tree gnu_type = get_unpadded_type (gnat_type);
2345 tree gnu_low = TYPE_MIN_VALUE (gnu_type);
2346 tree gnu_high = TYPE_MAX_VALUE (gnu_type);
2347 int reversep = Reverse_Present (gnat_loop_spec);
2348 tree gnu_first = reversep ? gnu_high : gnu_low;
2349 tree gnu_last = reversep ? gnu_low : gnu_high;
2350 enum tree_code end_code = reversep ? GE_EXPR : LE_EXPR;
2351 tree gnu_base_type = get_base_type (gnu_type);
2352 tree gnu_limit
2353 = (reversep ? TYPE_MIN_VALUE (gnu_base_type)
2354 : TYPE_MAX_VALUE (gnu_base_type));
2356 /* We know the loop variable will not overflow if GNU_LAST is
2357 a constant and is not equal to GNU_LIMIT. If it might
2358 overflow, we have to move the limit test to the end of
2359 the loop. In that case, we have to test for an
2360 empty loop outside the loop. */
2361 if (TREE_CODE (gnu_last) != INTEGER_CST
2362 || TREE_CODE (gnu_limit) != INTEGER_CST
2363 || tree_int_cst_equal (gnu_last, gnu_limit))
2365 gnu_expr = build_binary_op (LE_EXPR, integer_type_node,
2366 gnu_low, gnu_high);
2367 set_lineno (gnat_loop_spec, 1);
2368 expand_start_cond (gnu_expr, 0);
2369 enclosing_if_p = 1;
2372 /* Open a new nesting level that will surround the loop to declare
2373 the loop index variable. */
2374 gnat_pushlevel ();
2375 expand_start_bindings (0);
2377 /* Declare the loop index and set it to its initial value. */
2378 start_block_stmt ();
2379 gnu_loop_var = gnat_to_gnu_entity (gnat_loop_var, gnu_first, 1);
2380 expand_expr_stmt (end_block_stmt ());
2381 if (DECL_BY_REF_P (gnu_loop_var))
2382 gnu_loop_var = build_unary_op (INDIRECT_REF, NULL_TREE,
2383 gnu_loop_var);
2385 /* The loop variable might be a padded type, so use `convert' to
2386 get a reference to the inner variable if so. */
2387 gnu_loop_var = convert (get_base_type (gnu_type), gnu_loop_var);
2389 /* Set either the top or bottom exit condition as
2390 appropriate depending on whether we know an overflow
2391 cannot occur or not. */
2392 if (enclosing_if_p)
2393 gnu_bottom_condition
2394 = build_binary_op (NE_EXPR, integer_type_node,
2395 gnu_loop_var, gnu_last);
2396 else
2397 gnu_top_condition
2398 = build_binary_op (end_code, integer_type_node,
2399 gnu_loop_var, gnu_last);
2401 gnu_update = reversep ? PREDECREMENT_EXPR : PREINCREMENT_EXPR;
2404 set_lineno (gnat_node, 1);
2405 if (gnu_loop_var)
2406 loop_id = expand_start_loop_continue_elsewhere (1);
2407 else
2408 loop_id = expand_start_loop (1);
2410 /* If the loop was named, have the name point to this loop. In this
2411 case, the association is not a ..._DECL node; in fact, it isn't
2412 a GCC tree node at all. Since this name is referenced inside
2413 the loop, do it before we process the statements of the loop. */
2414 if (Present (Identifier (gnat_node)))
2416 tree gnu_loop_id = make_node (GNAT_LOOP_ID);
2418 TREE_LOOP_ID (gnu_loop_id) = loop_id;
2419 save_gnu_tree (Entity (Identifier (gnat_node)), gnu_loop_id, 1);
2422 set_lineno (gnat_node, 1);
2424 /* We must evaluate the condition after we've entered the
2425 loop so that any expression actions get done in the right
2426 place. */
2427 if (Present (gnat_top_condition))
2428 gnu_top_condition = gnat_to_gnu (gnat_top_condition);
2430 expand_exit_loop_top_cond (0, gnu_top_condition);
2432 /* Make the loop body into its own block, so any allocated
2433 storage will be released every iteration. This is needed
2434 for stack allocation. */
2436 gnat_pushlevel ();
2437 gnu_block_stack
2438 = tree_cons (gnu_bottom_condition, NULL_TREE, gnu_block_stack);
2439 expand_start_bindings (0);
2441 for (gnat_statement = First (Statements (gnat_node));
2442 Present (gnat_statement);
2443 gnat_statement = Next (gnat_statement))
2444 gnat_to_code (gnat_statement);
2446 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
2447 gnat_poplevel ();
2448 gnu_block_stack = TREE_CHAIN (gnu_block_stack);
2450 set_lineno (gnat_node, 1);
2451 expand_exit_loop_if_false (0, gnu_bottom_condition);
2453 if (gnu_loop_var)
2455 expand_loop_continue_here ();
2456 gnu_expr = build_binary_op (gnu_update, TREE_TYPE (gnu_loop_var),
2457 gnu_loop_var,
2458 convert (TREE_TYPE (gnu_loop_var),
2459 integer_one_node));
2460 set_lineno (gnat_iter_scheme, 1);
2461 expand_expr_stmt (gnu_expr);
2464 set_lineno (gnat_node, 1);
2465 expand_end_loop ();
2467 if (gnu_loop_var)
2469 /* Close the nesting level that sourround the loop that was used to
2470 declare the loop index variable. */
2471 set_lineno (gnat_node, 1);
2472 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
2473 gnat_poplevel ();
2476 if (enclosing_if_p)
2478 set_lineno (gnat_node, 1);
2479 expand_end_cond ();
2482 break;
2484 case N_Block_Statement:
2485 gnat_pushlevel ();
2486 gnu_block_stack = tree_cons (NULL_TREE, NULL_TREE, gnu_block_stack);
2487 expand_start_bindings (0);
2488 start_block_stmt ();
2489 process_decls (Declarations (gnat_node), Empty, Empty, 1, 1);
2490 gnat_expand_stmt (end_block_stmt ());
2491 gnat_to_code (Handled_Statement_Sequence (gnat_node));
2492 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
2493 gnat_poplevel ();
2494 gnu_block_stack = TREE_CHAIN (gnu_block_stack);
2495 if (Present (Identifier (gnat_node)))
2496 mark_out_of_scope (Entity (Identifier (gnat_node)));
2497 break;
2499 case N_Exit_Statement:
2501 /* Which loop to exit, NULL if the current loop. */
2502 struct nesting *loop_id = 0;
2503 /* The GCC version of the optional GNAT condition node attached to the
2504 exit statement. Exit the loop if this is false. */
2505 tree gnu_cond = integer_zero_node;
2507 if (Present (Name (gnat_node)))
2508 loop_id
2509 = TREE_LOOP_ID (get_gnu_tree (Entity (Name (gnat_node))));
2511 if (Present (Condition (gnat_node)))
2512 gnu_cond = invert_truthvalue (gnat_truthvalue_conversion
2513 (gnat_to_gnu (Condition (gnat_node))));
2515 set_lineno (gnat_node, 1);
2516 expand_exit_loop_if_false (loop_id, gnu_cond);
2518 break;
2520 case N_Return_Statement:
2522 /* The gnu function type of the subprogram currently processed. */
2523 tree gnu_subprog_type = TREE_TYPE (current_function_decl);
2524 /* The return value from the subprogram. */
2525 tree gnu_ret_val = 0;
2527 /* If we are dealing with a "return;" from an Ada procedure with
2528 parameters passed by copy in copy out, we need to return a record
2529 containing the final values of these parameters. If the list
2530 contains only one entry, return just that entry.
2532 For a full description of the copy in copy out parameter mechanism,
2533 see the part of the gnat_to_gnu_entity routine dealing with the
2534 translation of subprograms.
2536 But if we have a return label defined, convert this into
2537 a branch to that label. */
2539 if (TREE_VALUE (gnu_return_label_stack) != 0)
2541 gnu_result = build_nt (GOTO_STMT,
2542 TREE_VALUE (gnu_return_label_stack));
2543 break;
2546 else if (TYPE_CI_CO_LIST (gnu_subprog_type) != NULL_TREE)
2548 if (list_length (TYPE_CI_CO_LIST (gnu_subprog_type)) == 1)
2549 gnu_ret_val = TREE_VALUE (TYPE_CI_CO_LIST (gnu_subprog_type));
2550 else
2551 gnu_ret_val
2552 = gnat_build_constructor (TREE_TYPE (gnu_subprog_type),
2553 TYPE_CI_CO_LIST (gnu_subprog_type));
2556 /* If the Ada subprogram is a function, we just need to return the
2557 expression. If the subprogram returns an unconstrained
2558 array, we have to allocate a new version of the result and
2559 return it. If we return by reference, return a pointer. */
2561 else if (Present (Expression (gnat_node)))
2563 gnu_ret_val = gnat_to_gnu (Expression (gnat_node));
2565 /* Do not remove the padding from GNU_RET_VAL if the inner
2566 type is self-referential since we want to allocate the fixed
2567 size in that case. */
2568 if (TREE_CODE (gnu_ret_val) == COMPONENT_REF
2569 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_ret_val, 0)))
2570 == RECORD_TYPE)
2571 && (TYPE_IS_PADDING_P
2572 (TREE_TYPE (TREE_OPERAND (gnu_ret_val, 0))))
2573 && (CONTAINS_PLACEHOLDER_P
2574 (TYPE_SIZE (TREE_TYPE (gnu_ret_val)))))
2575 gnu_ret_val = TREE_OPERAND (gnu_ret_val, 0);
2577 if (TYPE_RETURNS_BY_REF_P (gnu_subprog_type)
2578 || By_Ref (gnat_node))
2579 gnu_ret_val = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_ret_val);
2581 else if (TYPE_RETURNS_UNCONSTRAINED_P (gnu_subprog_type))
2583 gnu_ret_val = maybe_unconstrained_array (gnu_ret_val);
2585 /* We have two cases: either the function returns with
2586 depressed stack or not. If not, we allocate on the
2587 secondary stack. If so, we allocate in the stack frame.
2588 if no copy is needed, the front end will set By_Ref,
2589 which we handle in the case above. */
2590 if (TYPE_RETURNS_STACK_DEPRESSED (gnu_subprog_type))
2591 gnu_ret_val
2592 = build_allocator (TREE_TYPE (gnu_ret_val), gnu_ret_val,
2593 TREE_TYPE (gnu_subprog_type), 0, -1,
2594 gnat_node);
2595 else
2596 gnu_ret_val
2597 = build_allocator (TREE_TYPE (gnu_ret_val), gnu_ret_val,
2598 TREE_TYPE (gnu_subprog_type),
2599 Procedure_To_Call (gnat_node),
2600 Storage_Pool (gnat_node), gnat_node);
2604 gnu_result = build_nt (RETURN_STMT, gnu_ret_val);
2606 break;
2608 case N_Goto_Statement:
2609 gnu_result = build_nt (GOTO_STMT, gnat_to_gnu (Name (gnat_node)));
2610 break;
2612 /****************************/
2613 /* Chapter 6: Subprograms: */
2614 /****************************/
2616 case N_Subprogram_Declaration:
2617 /* Unless there is a freeze node, declare the subprogram. We consider
2618 this a "definition" even though we're not generating code for
2619 the subprogram because we will be making the corresponding GCC
2620 node here. */
2622 if (No (Freeze_Node (Defining_Entity (Specification (gnat_node)))))
2623 gnat_to_gnu_entity (Defining_Entity (Specification (gnat_node)),
2624 NULL_TREE, 1);
2626 break;
2628 case N_Abstract_Subprogram_Declaration:
2629 /* This subprogram doesn't exist for code generation purposes, but we
2630 have to elaborate the types of any parameters, unless they are
2631 imported types (nothing to generate in this case). */
2632 for (gnat_temp
2633 = First_Formal (Defining_Entity (Specification (gnat_node)));
2634 Present (gnat_temp);
2635 gnat_temp = Next_Formal_With_Extras (gnat_temp))
2636 if (Is_Itype (Etype (gnat_temp))
2637 && !From_With_Type (Etype (gnat_temp)))
2638 gnat_to_gnu_entity (Etype (gnat_temp), NULL_TREE, 0);
2640 break;
2642 case N_Defining_Program_Unit_Name:
2643 /* For a child unit identifier go up a level to get the
2644 specificaton. We get this when we try to find the spec of
2645 a child unit package that is the compilation unit being compiled. */
2646 gnat_to_code (Parent (gnat_node));
2647 break;
2649 case N_Subprogram_Body:
2651 /* Save debug output mode in case it is reset. */
2652 enum debug_info_type save_write_symbols = write_symbols;
2653 const struct gcc_debug_hooks *const save_debug_hooks = debug_hooks;
2654 /* Definining identifier of a parameter to the subprogram. */
2655 Entity_Id gnat_param;
2656 /* The defining identifier for the subprogram body. Note that if a
2657 specification has appeared before for this body, then the identifier
2658 occurring in that specification will also be a defining identifier
2659 and all the calls to this subprogram will point to that
2660 specification. */
2661 Entity_Id gnat_subprog_id
2662 = (Present (Corresponding_Spec (gnat_node))
2663 ? Corresponding_Spec (gnat_node) : Defining_Entity (gnat_node));
2665 /* The FUNCTION_DECL node corresponding to the subprogram spec. */
2666 tree gnu_subprog_decl;
2667 /* The FUNCTION_TYPE node corresponding to the subprogram spec. */
2668 tree gnu_subprog_type;
2669 tree gnu_cico_list;
2671 /* If this is a generic object or if it has been eliminated,
2672 ignore it. */
2674 if (Ekind (gnat_subprog_id) == E_Generic_Procedure
2675 || Ekind (gnat_subprog_id) == E_Generic_Function
2676 || Is_Eliminated (gnat_subprog_id))
2677 break;
2679 /* If debug information is suppressed for the subprogram,
2680 turn debug mode off for the duration of processing. */
2681 if (!Needs_Debug_Info (gnat_subprog_id))
2683 write_symbols = NO_DEBUG;
2684 debug_hooks = &do_nothing_debug_hooks;
2687 /* If this subprogram acts as its own spec, define it. Otherwise,
2688 just get the already-elaborated tree node. However, if this
2689 subprogram had its elaboration deferred, we will already have
2690 made a tree node for it. So treat it as not being defined in
2691 that case. Such a subprogram cannot have an address clause or
2692 a freeze node, so this test is safe, though it does disable
2693 some otherwise-useful error checking. */
2694 gnu_subprog_decl
2695 = gnat_to_gnu_entity (gnat_subprog_id, NULL_TREE,
2696 Acts_As_Spec (gnat_node)
2697 && ! present_gnu_tree (gnat_subprog_id));
2699 gnu_subprog_type = TREE_TYPE (gnu_subprog_decl);
2701 /* ??? Temporarily do this to avoid GC throwing away outer stuff. */
2702 ggc_push_context ();
2704 /* Set the line number in the decl to correspond to that of
2705 the body so that the line number notes are written
2706 correctly. */
2707 set_lineno (gnat_node, 0);
2708 DECL_SOURCE_LOCATION (gnu_subprog_decl) = input_location;
2710 begin_subprog_body (gnu_subprog_decl);
2712 /* There used to be a second call to set_lineno here, with
2713 write_note_p set, but begin_subprog_body actually already emits the
2714 note we want (via init_function_start).
2716 Emitting a second note here was necessary for -ftest-coverage with
2717 GCC 2.8.1, as the first one was skipped by branch_prob. This is no
2718 longer the case with GCC 3.x, so emitting a second note here would
2719 result in having the first line of the subprogram counted twice by
2720 gcov. */
2722 gnat_pushlevel ();
2723 gnu_block_stack = tree_cons (NULL_TREE, NULL_TREE, gnu_block_stack);
2724 expand_start_bindings (0);
2725 start_block_stmt ();
2727 gnu_cico_list = TYPE_CI_CO_LIST (gnu_subprog_type);
2729 /* If there are OUT parameters, we need to ensure that the
2730 return statement properly copies them out. We do this by
2731 making a new block and converting any inner return into a goto
2732 to a label at the end of the block. */
2734 if (gnu_cico_list != 0)
2736 gnu_return_label_stack
2737 = tree_cons (NULL_TREE,
2738 build_decl (LABEL_DECL, NULL_TREE, NULL_TREE),
2739 gnu_return_label_stack);
2740 gnat_pushlevel ();
2741 expand_start_bindings (0);
2743 else
2744 gnu_return_label_stack
2745 = tree_cons (NULL_TREE, NULL_TREE, gnu_return_label_stack);
2747 /* See if there are any parameters for which we don't yet have
2748 GCC entities. These must be for OUT parameters for which we
2749 will be making VAR_DECL nodes here. Fill them in to
2750 TYPE_CI_CO_LIST, which must contain the empty entry as well.
2751 We can match up the entries because TYPE_CI_CO_LIST is in the
2752 order of the parameters. */
2754 for (gnat_param = First_Formal (gnat_subprog_id);
2755 Present (gnat_param);
2756 gnat_param = Next_Formal_With_Extras (gnat_param))
2757 if (!present_gnu_tree (gnat_param))
2759 /* Skip any entries that have been already filled in; they
2760 must correspond to IN OUT parameters. */
2761 for (; gnu_cico_list != 0 && TREE_VALUE (gnu_cico_list) != 0;
2762 gnu_cico_list = TREE_CHAIN (gnu_cico_list))
2765 /* Do any needed references for padded types. */
2766 TREE_VALUE (gnu_cico_list)
2767 = convert (TREE_TYPE (TREE_PURPOSE (gnu_cico_list)),
2768 gnat_to_gnu_entity (gnat_param, NULL_TREE, 1));
2771 gnat_expand_stmt (end_block_stmt());
2772 start_block_stmt ();
2773 process_decls (Declarations (gnat_node), Empty, Empty, 1, 1);
2774 gnat_expand_stmt (end_block_stmt ());
2776 /* Generate the code of the subprogram itself. A return statement
2777 will be present and any OUT parameters will be handled there. */
2778 gnat_to_code (Handled_Statement_Sequence (gnat_node));
2780 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
2781 gnat_poplevel ();
2782 gnu_block_stack = TREE_CHAIN (gnu_block_stack);
2784 if (TREE_VALUE (gnu_return_label_stack) != 0)
2786 tree gnu_retval;
2788 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
2789 gnat_poplevel ();
2790 expand_label (TREE_VALUE (gnu_return_label_stack));
2792 gnu_cico_list = TYPE_CI_CO_LIST (gnu_subprog_type);
2793 set_lineno (gnat_node, 1);
2794 if (list_length (gnu_cico_list) == 1)
2795 gnu_retval = TREE_VALUE (gnu_cico_list);
2796 else
2797 gnu_retval = gnat_build_constructor (TREE_TYPE (gnu_subprog_type),
2798 gnu_cico_list);
2800 if (DECL_P (gnu_retval) && DECL_BY_REF_P (gnu_retval))
2801 gnu_retval
2802 = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_retval);
2804 expand_return
2805 (build_binary_op (MODIFY_EXPR, NULL_TREE,
2806 DECL_RESULT (current_function_decl),
2807 gnu_retval));
2811 gnu_return_label_stack = TREE_CHAIN (gnu_return_label_stack);
2813 /* Disconnect the trees for parameters that we made variables for
2814 from the GNAT entities since these will become unusable after
2815 we end the function. */
2816 for (gnat_param = First_Formal (gnat_subprog_id);
2817 Present (gnat_param);
2818 gnat_param = Next_Formal_With_Extras (gnat_param))
2819 if (TREE_CODE (get_gnu_tree (gnat_param)) == VAR_DECL)
2820 save_gnu_tree (gnat_param, NULL_TREE, 0);
2822 end_subprog_body ();
2823 mark_out_of_scope (Defining_Unit_Name (Specification (gnat_node)));
2824 write_symbols = save_write_symbols;
2825 debug_hooks = save_debug_hooks;
2826 ggc_pop_context ();
2828 break;
2830 case N_Function_Call:
2831 case N_Procedure_Call_Statement:
2833 /* The GCC node corresponding to the GNAT subprogram name. This can
2834 either be a FUNCTION_DECL node if we are dealing with a standard
2835 subprogram call, or an indirect reference expression (an
2836 INDIRECT_REF node) pointing to a subprogram. */
2837 tree gnu_subprog_node = gnat_to_gnu (Name (gnat_node));
2838 /* The FUNCTION_TYPE node giving the GCC type of the subprogram. */
2839 tree gnu_subprog_type = TREE_TYPE (gnu_subprog_node);
2840 tree gnu_subprog_addr
2841 = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_subprog_node);
2842 Entity_Id gnat_formal;
2843 Node_Id gnat_actual;
2844 tree gnu_actual_list = NULL_TREE;
2845 tree gnu_name_list = NULL_TREE;
2846 tree gnu_before_list = NULL_TREE;
2847 tree gnu_after_list = NULL_TREE;
2848 tree gnu_subprog_call;
2850 switch (Nkind (Name (gnat_node)))
2852 case N_Identifier:
2853 case N_Operator_Symbol:
2854 case N_Expanded_Name:
2855 case N_Attribute_Reference:
2856 if (Is_Eliminated (Entity (Name (gnat_node))))
2857 Eliminate_Error_Msg (gnat_node, Entity (Name (gnat_node)));
2860 if (TREE_CODE (gnu_subprog_type) != FUNCTION_TYPE)
2861 gigi_abort (317);
2863 /* If we are calling a stubbed function, make this into a
2864 raise of Program_Error. Elaborate all our args first. */
2866 if (TREE_CODE (gnu_subprog_node) == FUNCTION_DECL
2867 && DECL_STUBBED_P (gnu_subprog_node))
2869 for (gnat_actual = First_Actual (gnat_node);
2870 Present (gnat_actual);
2871 gnat_actual = Next_Actual (gnat_actual))
2872 expand_expr_stmt (gnat_to_gnu (gnat_actual));
2874 if (Nkind (gnat_node) == N_Function_Call)
2876 gnu_result_type = TREE_TYPE (gnu_subprog_type);
2877 gnu_result
2878 = build1 (NULL_EXPR, gnu_result_type,
2879 build_call_raise (PE_Stubbed_Subprogram_Called));
2881 else
2882 gnu_result
2883 = build_nt (EXPR_STMT,
2884 build_call_raise (PE_Stubbed_Subprogram_Called));
2885 break;
2888 /* The only way we can be making a call via an access type is
2889 if Name is an explicit dereference. In that case, get the
2890 list of formal args from the type the access type is pointing
2891 to. Otherwise, get the formals from entity being called. */
2892 if (Nkind (Name (gnat_node)) == N_Explicit_Dereference)
2893 gnat_formal = First_Formal (Etype (Name (gnat_node)));
2894 else if (Nkind (Name (gnat_node)) == N_Attribute_Reference)
2895 /* Assume here that this must be 'Elab_Body or 'Elab_Spec. */
2896 gnat_formal = 0;
2897 else
2898 gnat_formal = First_Formal (Entity (Name (gnat_node)));
2900 /* Create the list of the actual parameters as GCC expects it, namely
2901 a chain of TREE_LIST nodes in which the TREE_VALUE field of each
2902 node is a parameter-expression and the TREE_PURPOSE field is
2903 null. Skip OUT parameters that are not passed by reference and
2904 don't need to be copied in. */
2906 for (gnat_actual = First_Actual (gnat_node);
2907 Present (gnat_actual);
2908 gnat_formal = Next_Formal_With_Extras (gnat_formal),
2909 gnat_actual = Next_Actual (gnat_actual))
2911 tree gnu_formal_type = gnat_to_gnu_type (Etype (gnat_formal));
2912 /* We treat a conversion between aggregate types as if it
2913 is an unchecked conversion. */
2914 int unchecked_convert_p
2915 = (Nkind (gnat_actual) == N_Unchecked_Type_Conversion
2916 || (Nkind (gnat_actual) == N_Type_Conversion
2917 && Is_Composite_Type (Underlying_Type
2918 (Etype (gnat_formal)))));
2919 Node_Id gnat_name
2920 = unchecked_convert_p ? Expression (gnat_actual) : gnat_actual;
2921 tree gnu_name = gnat_to_gnu (gnat_name);
2922 tree gnu_name_type = gnat_to_gnu_type (Etype (gnat_name));
2923 tree gnu_actual;
2925 /* If it's possible we may need to use this expression twice,
2926 make sure than any side-effects are handled via SAVE_EXPRs.
2927 Likewise if we need to force side-effects before the call.
2928 ??? This is more conservative than we need since we don't
2929 need to do this for pass-by-ref with no conversion.
2930 If we are passing a non-addressable Out or In Out parameter by
2931 reference, pass the address of a copy and set up to copy back
2932 out after the call. */
2934 if (Ekind (gnat_formal) != E_In_Parameter)
2936 gnu_name = gnat_stabilize_reference (gnu_name, 1);
2937 if (! addressable_p (gnu_name)
2938 && present_gnu_tree (gnat_formal)
2939 && (DECL_BY_REF_P (get_gnu_tree (gnat_formal))
2940 || (TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
2941 && (DECL_BY_COMPONENT_PTR_P
2942 (get_gnu_tree (gnat_formal))
2943 || DECL_BY_DESCRIPTOR_P
2944 (get_gnu_tree (gnat_formal))))))
2946 tree gnu_copy = gnu_name;
2947 tree gnu_temp;
2949 /* Remove any unpadding on the actual and make a copy.
2950 But if the actual is a left-justified modular type,
2951 first convert to it. */
2952 if (TREE_CODE (gnu_name) == COMPONENT_REF
2953 && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_name, 0)))
2954 == RECORD_TYPE)
2955 && (TYPE_IS_PADDING_P
2956 (TREE_TYPE (TREE_OPERAND (gnu_name, 0))))))
2957 gnu_name = gnu_copy = TREE_OPERAND (gnu_name, 0);
2958 else if (TREE_CODE (gnu_name_type) == RECORD_TYPE
2959 && (TYPE_LEFT_JUSTIFIED_MODULAR_P
2960 (gnu_name_type)))
2961 gnu_name = convert (gnu_name_type, gnu_name);
2963 gnu_actual = save_expr (gnu_name);
2965 /* Since we're going to take the address of the SAVE_EXPR,
2966 we don't want it to be marked as unchanging.
2967 So set TREE_ADDRESSABLE. */
2968 gnu_temp = skip_simple_arithmetic (gnu_actual);
2969 if (TREE_CODE (gnu_temp) == SAVE_EXPR)
2971 TREE_ADDRESSABLE (gnu_temp) = 1;
2972 TREE_READONLY (gnu_temp) = 0;
2975 /* Set up to move the copy back to the original. */
2976 gnu_temp
2977 = build_nt (EXPR_STMT,
2978 build (MODIFY_EXPR, TREE_TYPE (gnu_copy),
2979 gnu_copy, gnu_actual));
2981 TREE_TYPE (gnu_temp) = void_type_node;
2982 TREE_SLOC (gnu_temp) = Sloc (gnat_actual);
2983 TREE_CHAIN (gnu_temp) = gnu_after_list;
2984 gnu_after_list = gnu_temp;
2988 /* If this was a procedure call, we may not have removed any
2989 padding. So do it here for the part we will use as an
2990 input, if any. */
2991 gnu_actual = gnu_name;
2992 if (Ekind (gnat_formal) != E_Out_Parameter
2993 && TREE_CODE (TREE_TYPE (gnu_actual)) == RECORD_TYPE
2994 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_actual)))
2995 gnu_actual = convert (get_unpadded_type (Etype (gnat_actual)),
2996 gnu_actual);
2998 if (Ekind (gnat_formal) != E_Out_Parameter
2999 && ! unchecked_convert_p
3000 && Do_Range_Check (gnat_actual))
3001 gnu_actual = emit_range_check (gnu_actual, Etype (gnat_formal));
3003 /* Do any needed conversions. We need only check for
3004 unchecked conversion since normal conversions will be handled
3005 by just converting to the formal type. */
3006 if (unchecked_convert_p)
3008 gnu_actual
3009 = unchecked_convert (gnat_to_gnu_type (Etype (gnat_actual)),
3010 gnu_actual,
3011 (Nkind (gnat_actual)
3012 == N_Unchecked_Type_Conversion)
3013 && No_Truncation (gnat_actual));
3015 /* One we've done the unchecked conversion, we still
3016 must ensure that the object is in range of the formal's
3017 type. */
3018 if (Ekind (gnat_formal) != E_Out_Parameter
3019 && Do_Range_Check (gnat_actual))
3020 gnu_actual = emit_range_check (gnu_actual,
3021 Etype (gnat_formal));
3023 else if (TREE_CODE (gnu_actual) != SAVE_EXPR)
3024 /* We may have suppressed a conversion to the Etype of the
3025 actual since the parent is a procedure call. So add the
3026 conversion here. */
3027 gnu_actual = convert (gnat_to_gnu_type (Etype (gnat_actual)),
3028 gnu_actual);
3030 if (TREE_CODE (gnu_actual) != SAVE_EXPR)
3031 gnu_actual = convert (gnu_formal_type, gnu_actual);
3033 /* If we have not saved a GCC object for the formal, it means it
3034 is an OUT parameter not passed by reference and that does not
3035 need to be copied in. Otherwise, look at the PARM_DECL to see
3036 if it is passed by reference. */
3037 if (present_gnu_tree (gnat_formal)
3038 && TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
3039 && DECL_BY_REF_P (get_gnu_tree (gnat_formal)))
3041 if (Ekind (gnat_formal) != E_In_Parameter)
3043 gnu_actual = gnu_name;
3045 /* If we have a padded type, be sure we've removed the
3046 padding. */
3047 if (TREE_CODE (TREE_TYPE (gnu_actual)) == RECORD_TYPE
3048 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_actual))
3049 && TREE_CODE (gnu_actual) != SAVE_EXPR)
3050 gnu_actual
3051 = convert (get_unpadded_type (Etype (gnat_actual)),
3052 gnu_actual);
3055 /* Otherwise, if we have a non-addressable COMPONENT_REF of a
3056 variable-size type see if it's doing a unpadding operation.
3057 If so, remove that operation since we have no way of
3058 allocating the required temporary. */
3059 if (TREE_CODE (gnu_actual) == COMPONENT_REF
3060 && ! TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (gnu_actual)))
3061 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_actual, 0)))
3062 == RECORD_TYPE)
3063 && TYPE_IS_PADDING_P (TREE_TYPE
3064 (TREE_OPERAND (gnu_actual, 0)))
3065 && !addressable_p (gnu_actual))
3066 gnu_actual = TREE_OPERAND (gnu_actual, 0);
3068 /* The symmetry of the paths to the type of an entity is
3069 broken here since arguments don't know that they will
3070 be passed by ref. */
3071 gnu_formal_type = TREE_TYPE (get_gnu_tree (gnat_formal));
3072 gnu_actual = build_unary_op (ADDR_EXPR, gnu_formal_type,
3073 gnu_actual);
3075 else if (present_gnu_tree (gnat_formal)
3076 && TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
3077 && DECL_BY_COMPONENT_PTR_P (get_gnu_tree (gnat_formal)))
3079 gnu_formal_type = TREE_TYPE (get_gnu_tree (gnat_formal));
3080 gnu_actual = maybe_implicit_deref (gnu_actual);
3081 gnu_actual = maybe_unconstrained_array (gnu_actual);
3083 if (TREE_CODE (gnu_formal_type) == RECORD_TYPE
3084 && TYPE_IS_PADDING_P (gnu_formal_type))
3086 gnu_formal_type
3087 = TREE_TYPE (TYPE_FIELDS (gnu_formal_type));
3088 gnu_actual = convert (gnu_formal_type, gnu_actual);
3091 /* Take the address of the object and convert to the
3092 proper pointer type. We'd like to actually compute
3093 the address of the beginning of the array using
3094 an ADDR_EXPR of an ARRAY_REF, but there's a possibility
3095 that the ARRAY_REF might return a constant and we'd
3096 be getting the wrong address. Neither approach is
3097 exactly correct, but this is the most likely to work
3098 in all cases. */
3099 gnu_actual = convert (gnu_formal_type,
3100 build_unary_op (ADDR_EXPR, NULL_TREE,
3101 gnu_actual));
3103 else if (present_gnu_tree (gnat_formal)
3104 && TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
3105 && DECL_BY_DESCRIPTOR_P (get_gnu_tree (gnat_formal)))
3107 /* If arg is 'Null_Parameter, pass zero descriptor. */
3108 if ((TREE_CODE (gnu_actual) == INDIRECT_REF
3109 || TREE_CODE (gnu_actual) == UNCONSTRAINED_ARRAY_REF)
3110 && TREE_PRIVATE (gnu_actual))
3111 gnu_actual
3112 = convert (DECL_ARG_TYPE (get_gnu_tree (gnat_formal)),
3113 integer_zero_node);
3114 else
3115 gnu_actual
3116 = build_unary_op (ADDR_EXPR, NULL_TREE,
3117 fill_vms_descriptor (gnu_actual,
3118 gnat_formal));
3120 else
3122 tree gnu_actual_size = TYPE_SIZE (TREE_TYPE (gnu_actual));
3124 if (Ekind (gnat_formal) != E_In_Parameter)
3125 gnu_name_list
3126 = chainon (gnu_name_list,
3127 build_tree_list (NULL_TREE, gnu_name));
3129 if (! present_gnu_tree (gnat_formal)
3130 || TREE_CODE (get_gnu_tree (gnat_formal)) != PARM_DECL)
3131 continue;
3133 /* If this is 'Null_Parameter, pass a zero even though we are
3134 dereferencing it. */
3135 else if (TREE_CODE (gnu_actual) == INDIRECT_REF
3136 && TREE_PRIVATE (gnu_actual)
3137 && host_integerp (gnu_actual_size, 1)
3138 && 0 >= compare_tree_int (gnu_actual_size,
3139 BITS_PER_WORD))
3140 gnu_actual
3141 = unchecked_convert
3142 (DECL_ARG_TYPE (get_gnu_tree (gnat_formal)),
3143 convert (gnat_type_for_size
3144 (tree_low_cst (gnu_actual_size, 1), 1),
3145 integer_zero_node), 0);
3146 else
3147 gnu_actual
3148 = convert (TYPE_MAIN_VARIANT
3149 (DECL_ARG_TYPE (get_gnu_tree (gnat_formal))),
3150 gnu_actual);
3153 gnu_actual_list
3154 = chainon (gnu_actual_list,
3155 build_tree_list (NULL_TREE, gnu_actual));
3158 gnu_subprog_call = build (CALL_EXPR, TREE_TYPE (gnu_subprog_type),
3159 gnu_subprog_addr, gnu_actual_list,
3160 NULL_TREE);
3161 TREE_SIDE_EFFECTS (gnu_subprog_call) = 1;
3163 /* If it is a function call, the result is the call expression. */
3164 if (Nkind (gnat_node) == N_Function_Call)
3166 gnu_result = gnu_subprog_call;
3168 /* If the function returns an unconstrained array or by reference,
3169 we have to de-dereference the pointer. */
3170 if (TYPE_RETURNS_UNCONSTRAINED_P (gnu_subprog_type)
3171 || TYPE_RETURNS_BY_REF_P (gnu_subprog_type))
3172 gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE,
3173 gnu_result);
3175 gnu_result_type = get_unpadded_type (Etype (gnat_node));
3176 break;
3179 /* If this is the case where the GNAT tree contains a procedure call
3180 but the Ada procedure has copy in copy out parameters, the special
3181 parameter passing mechanism must be used. */
3182 else if (TYPE_CI_CO_LIST (gnu_subprog_type) != NULL_TREE)
3184 /* List of FIELD_DECLs associated with the PARM_DECLs of the copy
3185 in copy out parameters. */
3186 tree scalar_return_list = TYPE_CI_CO_LIST (gnu_subprog_type);
3187 int length = list_length (scalar_return_list);
3189 if (length > 1)
3191 tree gnu_name;
3193 gnu_subprog_call = protect_multiple_eval (gnu_subprog_call);
3195 /* If any of the names had side-effects, ensure they are
3196 all evaluated before the call. */
3197 for (gnu_name = gnu_name_list; gnu_name;
3198 gnu_name = TREE_CHAIN (gnu_name))
3199 if (TREE_SIDE_EFFECTS (TREE_VALUE (gnu_name)))
3200 gnu_subprog_call
3201 = build (COMPOUND_EXPR, TREE_TYPE (gnu_subprog_call),
3202 TREE_VALUE (gnu_name), gnu_subprog_call);
3205 if (Nkind (Name (gnat_node)) == N_Explicit_Dereference)
3206 gnat_formal = First_Formal (Etype (Name (gnat_node)));
3207 else
3208 gnat_formal = First_Formal (Entity (Name (gnat_node)));
3210 for (gnat_actual = First_Actual (gnat_node);
3211 Present (gnat_actual);
3212 gnat_formal = Next_Formal_With_Extras (gnat_formal),
3213 gnat_actual = Next_Actual (gnat_actual))
3214 /* If we are dealing with a copy in copy out parameter, we must
3215 retrieve its value from the record returned in the function
3216 call. */
3217 if (! (present_gnu_tree (gnat_formal)
3218 && TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
3219 && (DECL_BY_REF_P (get_gnu_tree (gnat_formal))
3220 || ((TREE_CODE (get_gnu_tree (gnat_formal))
3221 == PARM_DECL)
3222 && ((DECL_BY_COMPONENT_PTR_P
3223 (get_gnu_tree (gnat_formal))
3224 || (DECL_BY_DESCRIPTOR_P
3225 (get_gnu_tree (gnat_formal))))))))
3226 && Ekind (gnat_formal) != E_In_Parameter)
3228 /* Get the value to assign to this OUT or IN OUT
3229 parameter. It is either the result of the function if
3230 there is only a single such parameter or the appropriate
3231 field from the record returned. */
3232 tree gnu_result
3233 = length == 1 ? gnu_subprog_call
3234 : build_component_ref
3235 (gnu_subprog_call, NULL_TREE,
3236 TREE_PURPOSE (scalar_return_list), 0);
3237 int unchecked_conversion
3238 = Nkind (gnat_actual) == N_Unchecked_Type_Conversion;
3239 /* If the actual is a conversion, get the inner expression,
3240 which will be the real destination, and convert the
3241 result to the type of the actual parameter. */
3242 tree gnu_actual
3243 = maybe_unconstrained_array (TREE_VALUE (gnu_name_list));
3245 /* If the result is a padded type, remove the padding. */
3246 if (TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
3247 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_result)))
3248 gnu_result
3249 = convert (TREE_TYPE (TYPE_FIELDS
3250 (TREE_TYPE (gnu_result))),
3251 gnu_result);
3253 /* If the result is a type conversion, do it. */
3254 if (Nkind (gnat_actual) == N_Type_Conversion)
3255 gnu_result
3256 = convert_with_check
3257 (Etype (Expression (gnat_actual)), gnu_result,
3258 Do_Overflow_Check (gnat_actual),
3259 Do_Range_Check (Expression (gnat_actual)),
3260 Float_Truncate (gnat_actual));
3262 else if (unchecked_conversion)
3263 gnu_result
3264 = unchecked_convert (TREE_TYPE (gnu_actual), gnu_result,
3265 No_Truncation (gnat_actual));
3266 else
3268 if (Do_Range_Check (gnat_actual))
3269 gnu_result = emit_range_check (gnu_result,
3270 Etype (gnat_actual));
3272 if (! (! TREE_CONSTANT (TYPE_SIZE
3273 (TREE_TYPE (gnu_actual)))
3274 && TREE_CONSTANT (TYPE_SIZE
3275 (TREE_TYPE (gnu_result)))))
3276 gnu_result = convert (TREE_TYPE (gnu_actual),
3277 gnu_result);
3280 gnu_result
3281 = build_nt (EXPR_STMT,
3282 build_binary_op (MODIFY_EXPR, NULL_TREE,
3283 gnu_actual, gnu_result));
3284 TREE_TYPE (gnu_result) = void_type_node;
3285 TREE_SLOC (gnu_result) = Sloc (gnat_actual);
3286 TREE_CHAIN (gnu_result) = gnu_before_list;
3287 gnu_before_list = gnu_result;
3288 scalar_return_list = TREE_CHAIN (scalar_return_list);
3289 gnu_name_list = TREE_CHAIN (gnu_name_list);
3292 else
3294 gnu_before_list = build_nt (EXPR_STMT, gnu_subprog_call);
3295 TREE_TYPE (gnu_before_list) = void_type_node;
3296 TREE_SLOC (gnu_before_list) = Sloc (gnat_node);
3299 gnu_result = chainon (nreverse (gnu_before_list),
3300 nreverse (gnu_after_list));
3301 if (TREE_CHAIN (gnu_result))
3302 gnu_result = build_nt (BLOCK_STMT, gnu_result);
3304 break;
3306 /*************************/
3307 /* Chapter 7: Packages: */
3308 /*************************/
3310 case N_Package_Declaration:
3311 gnat_to_code (Specification (gnat_node));
3312 break;
3314 case N_Package_Specification:
3316 start_block_stmt ();
3317 process_decls (Visible_Declarations (gnat_node),
3318 Private_Declarations (gnat_node), Empty, 1, 1);
3319 gnat_expand_stmt (end_block_stmt ());
3320 break;
3322 case N_Package_Body:
3324 /* If this is the body of a generic package - do nothing */
3325 if (Ekind (Corresponding_Spec (gnat_node)) == E_Generic_Package)
3326 break;
3328 start_block_stmt ();
3329 process_decls (Declarations (gnat_node), Empty, Empty, 1, 1);
3330 gnat_expand_stmt (end_block_stmt ());
3332 if (Present (Handled_Statement_Sequence (gnat_node)))
3334 gnu_block_stack = tree_cons (NULL_TREE, NULL_TREE, gnu_block_stack);
3335 gnat_to_code (Handled_Statement_Sequence (gnat_node));
3336 gnu_block_stack = TREE_CHAIN (gnu_block_stack);
3338 break;
3340 /*********************************/
3341 /* Chapter 8: Visibility Rules: */
3342 /*********************************/
3344 case N_Use_Package_Clause:
3345 case N_Use_Type_Clause:
3346 /* Nothing to do here - but these may appear in list of declarations */
3347 break;
3349 /***********************/
3350 /* Chapter 9: Tasks: */
3351 /***********************/
3353 case N_Protected_Type_Declaration:
3354 break;
3356 case N_Single_Task_Declaration:
3357 gnat_to_gnu_entity (Defining_Entity (gnat_node), NULL_TREE, 1);
3358 break;
3360 /***********************************************************/
3361 /* Chapter 10: Program Structure and Compilation Issues: */
3362 /***********************************************************/
3364 case N_Compilation_Unit:
3366 /* For a body, first process the spec if there is one. */
3367 if (Nkind (Unit (gnat_node)) == N_Package_Body
3368 || (Nkind (Unit (gnat_node)) == N_Subprogram_Body
3369 && ! Acts_As_Spec (gnat_node)))
3370 gnat_to_code (Library_Unit (gnat_node));
3372 process_inlined_subprograms (gnat_node);
3374 if (type_annotate_only && gnat_node == Cunit (Main_Unit))
3376 elaborate_all_entities (gnat_node);
3378 if (Nkind (Unit (gnat_node)) == N_Subprogram_Declaration
3379 || Nkind (Unit (gnat_node)) == N_Generic_Package_Declaration
3380 || Nkind (Unit (gnat_node)) == N_Generic_Subprogram_Declaration)
3381 break;
3384 start_block_stmt();
3385 process_decls (Declarations (Aux_Decls_Node (gnat_node)),
3386 Empty, Empty, 1, 1);
3387 gnat_expand_stmt (end_block_stmt ());
3389 gnat_to_code (Unit (gnat_node));
3391 /* Process any pragmas following the unit. */
3392 if (Present (Pragmas_After (Aux_Decls_Node (gnat_node))))
3393 for (gnat_temp = First (Pragmas_After (Aux_Decls_Node (gnat_node)));
3394 gnat_temp; gnat_temp = Next (gnat_temp))
3395 gnat_to_code (gnat_temp);
3397 /* Put all the Actions into the elaboration routine if we already had
3398 elaborations. This will happen anyway if they are statements, but we
3399 want to force declarations there too due to order-of-elaboration
3400 issues. Most should have Is_Statically_Allocated set. If we
3401 have had no elaborations, we have no order-of-elaboration issue and
3402 don't want to create elaborations here. */
3403 if (Is_Non_Empty_List (Actions (Aux_Decls_Node (gnat_node))))
3404 for (gnat_temp = First (Actions (Aux_Decls_Node (gnat_node)));
3405 Present (gnat_temp); gnat_temp = Next (gnat_temp))
3407 if (pending_elaborations_p ())
3408 add_pending_elaborations (NULL_TREE,
3409 make_transform_expr (gnat_temp));
3410 else
3411 gnat_to_code (gnat_temp);
3414 /* Generate elaboration code for this unit, if necessary, and
3415 say whether we did or not. */
3416 Set_Has_No_Elaboration_Code
3417 (gnat_node,
3418 build_unit_elab
3419 (Defining_Entity (Unit (gnat_node)),
3420 Nkind (Unit (gnat_node)) == N_Package_Body
3421 || Nkind (Unit (gnat_node)) == N_Subprogram_Body,
3422 get_pending_elaborations ()));
3424 break;
3426 case N_Subprogram_Body_Stub:
3427 case N_Package_Body_Stub:
3428 case N_Protected_Body_Stub:
3429 case N_Task_Body_Stub:
3430 /* Simply process whatever unit is being inserted. */
3431 gnat_to_code (Unit (Library_Unit (gnat_node)));
3432 break;
3434 case N_Subunit:
3435 gnat_to_code (Proper_Body (gnat_node));
3436 break;
3438 /***************************/
3439 /* Chapter 11: Exceptions: */
3440 /***************************/
3442 case N_Handled_Sequence_Of_Statements:
3444 /* The GCC exception handling mechanism can handle both ZCX and SJLJ
3445 schemes and we have our own SJLJ mechanism. To call the GCC
3446 mechanism, we first call expand_eh_region_start if there is at least
3447 one handler associated with the region. We then generate code for
3448 the region and call expand_start_all_catch to announce that the
3449 associated handlers are going to be generated.
3451 For each handler we call expand_start_catch, generate code for the
3452 handler, and then call expand_end_catch.
3454 After all the handlers, we call expand_end_all_catch.
3456 Here we deal with the region level calls and the
3457 N_Exception_Handler branch deals with the handler level calls
3458 (start_catch/end_catch).
3460 ??? The region level calls down there have been specifically put in
3461 place for a ZCX context and currently the order in which things are
3462 emitted (region/handlers) is different from the SJLJ case. Instead of
3463 putting other calls with different conditions at other places for the
3464 SJLJ case, it seems cleaner to reorder things for the SJLJ case and
3465 generalize the condition to make it not ZCX specific. */
3467 /* If there is an At_End procedure attached to this node, and the eh
3468 mechanism is GNAT oriented (SJLJ or ZCX with front end tables), we
3469 must have at least a corresponding At_End handler, unless the
3470 No_Exception_Handlers restriction is set. */
3471 if (! type_annotate_only
3472 && Exception_Mechanism != GCC_ZCX
3473 && Present (At_End_Proc (gnat_node))
3474 && ! Present (Exception_Handlers (gnat_node))
3475 && ! No_Exception_Handlers_Set())
3476 gigi_abort (335);
3479 /* Need a binding level that we can exit for this sequence if there is
3480 at least one exception handler for this block (since each handler
3481 needs an identified exit point) or there is an At_End procedure
3482 attached to this node (in order to have an attachment point for a
3483 GCC cleanup). */
3484 bool exitable_binding_for_block
3485 = (! type_annotate_only
3486 && (Present (Exception_Handlers (gnat_node))
3487 || Present (At_End_Proc (gnat_node))));
3489 /* Make a binding level that we can exit if we need one. */
3490 if (exitable_binding_for_block)
3492 gnat_pushlevel ();
3493 expand_start_bindings (1);
3496 /* If we are to call a function when exiting this block, expand a GCC
3497 cleanup to take care. We have made a binding level for this cleanup
3498 above. */
3499 if (Present (At_End_Proc (gnat_node)))
3501 tree gnu_cleanup_call
3502 = build_call_0_expr (gnat_to_gnu (At_End_Proc (gnat_node)));
3504 tree gnu_cleanup_decl
3505 = create_var_decl (get_identifier ("CLEANUP"), NULL_TREE,
3506 integer_type_node, NULL_TREE, 0, 0, 0, 0,
3509 start_block_stmt ();
3510 add_decl_stmt (gnu_cleanup_decl, gnat_node);
3511 gnat_expand_stmt (end_block_stmt ());
3512 expand_decl_cleanup (gnu_cleanup_decl, gnu_cleanup_call);
3515 /* Now we generate the code for this block, with a different layout
3516 for GNAT SJLJ and for GCC or front end ZCX. The handlers come first
3517 in the GNAT SJLJ case, while they come after the handled sequence
3518 in the other cases. */
3520 /* First deal with possible handlers for the GNAT SJLJ scheme. */
3521 if (! type_annotate_only
3522 && Exception_Mechanism == Setjmp_Longjmp
3523 && Present (Exception_Handlers (gnat_node)))
3525 /* We already have a fresh binding level at hand. Declare a
3526 variable to save the old __gnat_jmpbuf value and a variable for
3527 our jmpbuf. Call setjmp and handle each of the possible
3528 exceptions if it returns one. */
3530 tree gnu_jmpsave_decl
3531 = create_var_decl (get_identifier ("JMPBUF_SAVE"), NULL_TREE,
3532 jmpbuf_ptr_type,
3533 build_call_0_expr (get_jmpbuf_decl),
3534 0, 0, 0, 0, 0);
3536 tree gnu_jmpbuf_decl
3537 = create_var_decl (get_identifier ("JMP_BUF"),
3538 NULL_TREE, jmpbuf_type,
3539 NULL_TREE, 0, 0, 0, 0,
3542 start_block_stmt ();
3543 add_decl_stmt (gnu_jmpsave_decl, gnat_node);
3544 add_decl_stmt (gnu_jmpbuf_decl, gnat_node);
3545 gnat_expand_stmt (end_block_stmt ());
3547 TREE_VALUE (gnu_block_stack) = gnu_jmpbuf_decl;
3549 /* When we exit this block, restore the saved value. */
3550 expand_decl_cleanup (gnu_jmpsave_decl,
3551 build_call_1_expr (set_jmpbuf_decl,
3552 gnu_jmpsave_decl));
3554 /* Call setjmp and handle exceptions if it returns one. */
3555 set_lineno (gnat_node, 1);
3556 expand_start_cond
3557 (build_call_1_expr (setjmp_decl,
3558 build_unary_op (ADDR_EXPR, NULL_TREE,
3559 gnu_jmpbuf_decl)),
3562 /* Restore our incoming longjmp value before we do anything. */
3563 expand_expr_stmt
3564 (build_call_1_expr (set_jmpbuf_decl, gnu_jmpsave_decl));
3566 /* Make a binding level for the exception handling declarations
3567 and code. Don't assign it an exit label, since this is the
3568 outer block we want to exit at the end of each handler. */
3569 gnat_pushlevel ();
3570 expand_start_bindings (0);
3572 gnu_except_ptr_stack
3573 = tree_cons (NULL_TREE,
3574 create_var_decl
3575 (get_identifier ("EXCEPT_PTR"), NULL_TREE,
3576 build_pointer_type (except_type_node),
3577 build_call_0_expr (get_excptr_decl),
3578 0, 0, 0, 0, 0),
3579 gnu_except_ptr_stack);
3580 start_block_stmt ();
3581 add_decl_stmt (TREE_VALUE (gnu_except_ptr_stack), gnat_node);
3582 gnat_expand_stmt (end_block_stmt ());
3584 /* Generate code for each handler. The N_Exception_Handler case
3585 below does the real work. We ignore the dummy exception handler
3586 for the identifier case, as this is used only by the front
3587 end. */
3588 for (gnat_temp = First_Non_Pragma (Exception_Handlers (gnat_node));
3589 Present (gnat_temp);
3590 gnat_temp = Next_Non_Pragma (gnat_temp))
3591 gnat_to_code (gnat_temp);
3593 /* If none of the exception handlers did anything, re-raise
3594 but do not defer abortion. */
3595 set_lineno (gnat_node, 1);
3596 expand_expr_stmt
3597 (build_call_1_expr (raise_nodefer_decl,
3598 TREE_VALUE (gnu_except_ptr_stack)));
3600 gnu_except_ptr_stack = TREE_CHAIN (gnu_except_ptr_stack);
3602 /* End the binding level dedicated to the exception handlers. */
3603 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
3604 gnat_poplevel ();
3606 /* End the "if" on setjmp. Note that we have arranged things so
3607 control never returns here. */
3608 expand_end_cond ();
3610 /* This is now immediately before the body proper. Set our jmp_buf
3611 as the current buffer. */
3612 expand_expr_stmt
3613 (build_call_1_expr (set_jmpbuf_decl,
3614 build_unary_op (ADDR_EXPR, NULL_TREE,
3615 gnu_jmpbuf_decl)));
3618 /* Now comes the processing for the sequence body. */
3620 /* If we use the back-end eh support, tell the back-end we are
3621 starting a new exception region. */
3622 if (! type_annotate_only
3623 && Exception_Mechanism == GCC_ZCX
3624 && Present (Exception_Handlers (gnat_node)))
3625 expand_eh_region_start ();
3627 /* Generate code and declarations for the prefix of this block,
3628 if any. */
3629 start_block_stmt ();
3630 if (Present (First_Real_Statement (gnat_node)))
3631 process_decls (Statements (gnat_node), Empty,
3632 First_Real_Statement (gnat_node), 1, 1);
3633 gnat_expand_stmt (end_block_stmt ());
3635 /* Generate code for each statement in the block. */
3636 for (gnat_temp = (Present (First_Real_Statement (gnat_node))
3637 ? First_Real_Statement (gnat_node)
3638 : First (Statements (gnat_node)));
3639 Present (gnat_temp);
3640 gnat_temp = Next (gnat_temp))
3641 gnat_to_code (gnat_temp);
3643 /* Exit the binding level we made, if any. */
3644 if (exitable_binding_for_block)
3645 expand_exit_something ();
3647 /* Compile the handlers for front end ZCX or back-end supported
3648 exceptions. */
3649 if (! type_annotate_only
3650 && Exception_Mechanism != Setjmp_Longjmp
3651 && Present (Exception_Handlers (gnat_node)))
3653 if (Exception_Mechanism == GCC_ZCX)
3654 expand_start_all_catch ();
3656 for (gnat_temp = First_Non_Pragma (Exception_Handlers (gnat_node));
3657 Present (gnat_temp);
3658 gnat_temp = Next_Non_Pragma (gnat_temp))
3659 gnat_to_code (gnat_temp);
3661 if (Exception_Mechanism == GCC_ZCX)
3662 expand_end_all_catch ();
3665 /* Close the binding level we made, if any. */
3666 if (exitable_binding_for_block)
3668 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
3669 gnat_poplevel ();
3673 break;
3675 case N_Exception_Handler:
3676 if (Exception_Mechanism == Setjmp_Longjmp)
3678 /* Unless this is "Others" or the special "Non-Ada" exception
3679 for Ada, make an "if" statement to select the proper
3680 exceptions. For "Others", exclude exceptions where
3681 Handled_By_Others is nonzero unless the All_Others flag is set.
3682 For "Non-ada", accept an exception if "Lang" is 'V'. */
3683 tree gnu_choice = integer_zero_node;
3685 for (gnat_temp = First (Exception_Choices (gnat_node));
3686 gnat_temp; gnat_temp = Next (gnat_temp))
3688 tree this_choice;
3690 if (Nkind (gnat_temp) == N_Others_Choice)
3692 if (All_Others (gnat_temp))
3693 this_choice = integer_one_node;
3694 else
3695 this_choice
3696 = build_binary_op
3697 (EQ_EXPR, integer_type_node,
3698 convert
3699 (integer_type_node,
3700 build_component_ref
3701 (build_unary_op
3702 (INDIRECT_REF, NULL_TREE,
3703 TREE_VALUE (gnu_except_ptr_stack)),
3704 get_identifier ("not_handled_by_others"), NULL_TREE,
3705 0)),
3706 integer_zero_node);
3709 else if (Nkind (gnat_temp) == N_Identifier
3710 || Nkind (gnat_temp) == N_Expanded_Name)
3712 Entity_Id gnat_ex_id = Entity (gnat_temp);
3714 /* Exception may be a renaming. Recover original exception
3715 which is the one elaborated and registered. */
3716 if (Present (Renamed_Object (gnat_ex_id)))
3717 gnat_ex_id = Renamed_Object (gnat_ex_id);
3719 gnu_expr = gnat_to_gnu_entity (gnat_ex_id, NULL_TREE, 0);
3721 this_choice
3722 = build_binary_op
3723 (EQ_EXPR, integer_type_node,
3724 TREE_VALUE (gnu_except_ptr_stack),
3725 convert
3726 (TREE_TYPE (TREE_VALUE (gnu_except_ptr_stack)),
3727 build_unary_op (ADDR_EXPR, NULL_TREE, gnu_expr)));
3729 /* If this is the distinguished exception "Non_Ada_Error"
3730 (and we are in VMS mode), also allow a non-Ada
3731 exception (a VMS condition) to match. */
3732 if (Is_Non_Ada_Error (Entity (gnat_temp)))
3734 tree gnu_comp
3735 = build_component_ref
3736 (build_unary_op
3737 (INDIRECT_REF, NULL_TREE,
3738 TREE_VALUE (gnu_except_ptr_stack)),
3739 get_identifier ("lang"), NULL_TREE, 0);
3741 this_choice
3742 = build_binary_op
3743 (TRUTH_ORIF_EXPR, integer_type_node,
3744 build_binary_op
3745 (EQ_EXPR, integer_type_node, gnu_comp,
3746 convert (TREE_TYPE (gnu_comp),
3747 build_int_2 ('V', 0))),
3748 this_choice);
3751 else
3752 gigi_abort (318);
3754 gnu_choice = build_binary_op (TRUTH_ORIF_EXPR, integer_type_node,
3755 gnu_choice, this_choice);
3758 set_lineno (gnat_node, 1);
3760 expand_start_cond (gnu_choice, 0);
3763 /* Tell the back end that we start an exception handler if necessary. */
3764 if (Exception_Mechanism == GCC_ZCX)
3766 /* We build a TREE_LIST of nodes representing what exception
3767 types this handler is able to catch, with special cases
3768 for others and all others cases.
3770 Each exception type is actually identified by a pointer to the
3771 exception id, with special value zero for "others" and one for
3772 "all others". Beware that these special values are known and used
3773 by the personality routine to identify the corresponding specific
3774 kinds of handlers.
3776 ??? For initial time frame reasons, the others and all_others
3777 cases have been handled using specific type trees, but this
3778 somehow hides information to the back-end, which expects NULL to
3779 be passed for catch all and end_cleanup to be used for cleanups.
3781 Care should be taken to ensure that the control flow impact of
3782 such clauses is rendered in some way. lang_eh_type_covers is
3783 doing the trick currently. */
3785 tree gnu_expr, gnu_etype;
3786 tree gnu_etypes_list = NULL_TREE;
3788 for (gnat_temp = First (Exception_Choices (gnat_node));
3789 gnat_temp; gnat_temp = Next (gnat_temp))
3791 if (Nkind (gnat_temp) == N_Others_Choice)
3792 gnu_etype
3793 = All_Others (gnat_temp) ? integer_one_node
3794 : integer_zero_node;
3795 else if (Nkind (gnat_temp) == N_Identifier
3796 || Nkind (gnat_temp) == N_Expanded_Name)
3798 Entity_Id gnat_ex_id = Entity (gnat_temp);
3800 /* Exception may be a renaming. Recover original exception
3801 which is the one elaborated and registered. */
3802 if (Present (Renamed_Object (gnat_ex_id)))
3803 gnat_ex_id = Renamed_Object (gnat_ex_id);
3805 gnu_expr = gnat_to_gnu_entity (gnat_ex_id, NULL_TREE, 0);
3807 gnu_etype
3808 = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_expr);
3810 /* The Non_Ada_Error case for VMS exceptions is handled
3811 by the personality routine. */
3813 else
3814 gigi_abort (337);
3816 /* The GCC interface expects NULL to be passed for catch all
3817 handlers, so it would be quite tempting to set gnu_etypes_list
3818 to NULL if gnu_etype is integer_zero_node. It would not work,
3819 however, because GCC's notion of "catch all" is stronger than
3820 our notion of "others". Until we correctly use the cleanup
3821 interface as well, the doing tht would prevent the "all
3822 others" handlers from beeing seen, because nothing can be
3823 caught beyond a catch all from GCC's point of view. */
3824 gnu_etypes_list
3825 = tree_cons (NULL_TREE, gnu_etype, gnu_etypes_list);
3829 expand_start_catch (gnu_etypes_list);
3831 gnat_pushlevel ();
3832 expand_start_bindings (0);
3835 /* Expand a call to the begin_handler hook at the beginning of the
3836 handler, and arrange for a call to the end_handler hook to
3837 occur on every possible exit path.
3839 The hooks expect a pointer to the low level occurrence. This
3840 is required for our stack management scheme because a raise
3841 inside the handler pushes a new occurrence on top of the
3842 stack, which means that this top does not necessarily match
3843 the occurrence this handler was dealing with.
3845 The EXC_PTR_EXPR object references the exception occurrence
3846 beeing propagated. Upon handler entry, this is the exception
3847 for which the handler is triggered. This might not be the case
3848 upon handler exit, however, as we might have a new occurrence
3849 propagated by the handler's body, and the end_handler hook
3850 called as a cleanup in this context.
3852 We use a local variable to retrieve the incoming value at
3853 handler entry time, and reuse it to feed the end_handler
3854 hook's argument at exit time. */
3855 tree gnu_current_exc_ptr
3856 = build (EXC_PTR_EXPR, ptr_type_node);
3857 tree gnu_incoming_exc_ptr
3858 = create_var_decl (get_identifier ("EXPTR"), NULL_TREE,
3859 ptr_type_node, gnu_current_exc_ptr,
3860 0, 0, 0, 0, 0);
3862 start_block_stmt ();
3863 add_decl_stmt (gnu_incoming_exc_ptr, gnat_node);
3864 gnat_expand_stmt (end_block_stmt ());
3865 expand_expr_stmt
3866 (build_call_1_expr (begin_handler_decl, gnu_incoming_exc_ptr));
3867 expand_decl_cleanup
3868 (0, build_call_1_expr (end_handler_decl, gnu_incoming_exc_ptr));
3872 for (gnat_temp = First (Statements (gnat_node));
3873 gnat_temp; gnat_temp = Next (gnat_temp))
3874 gnat_to_code (gnat_temp);
3876 if (Exception_Mechanism == GCC_ZCX)
3878 /* Tell the back end that we're done with the current handler. */
3879 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
3880 gnat_poplevel ();
3881 expand_end_catch ();
3883 else
3884 /* At the end of the handler, exit the block. We made this block in
3885 N_Handled_Sequence_Of_Statements. */
3886 expand_exit_something ();
3888 if (Exception_Mechanism == Setjmp_Longjmp)
3889 expand_end_cond ();
3891 break;
3893 /*******************************/
3894 /* Chapter 12: Generic Units: */
3895 /*******************************/
3897 case N_Generic_Function_Renaming_Declaration:
3898 case N_Generic_Package_Renaming_Declaration:
3899 case N_Generic_Procedure_Renaming_Declaration:
3900 case N_Generic_Package_Declaration:
3901 case N_Generic_Subprogram_Declaration:
3902 case N_Package_Instantiation:
3903 case N_Procedure_Instantiation:
3904 case N_Function_Instantiation:
3905 /* These nodes can appear on a declaration list but there is nothing to
3906 to be done with them. */
3907 break;
3909 /***************************************************/
3910 /* Chapter 13: Representation Clauses and */
3911 /* Implementation-Dependent Features: */
3912 /***************************************************/
3914 case N_Attribute_Definition_Clause:
3916 /* The only one we need deal with is for 'Address. For the others, SEM
3917 puts the information elsewhere. We need only deal with 'Address
3918 if the object has a Freeze_Node (which it never will currently). */
3919 if (Get_Attribute_Id (Chars (gnat_node)) != Attr_Address
3920 || No (Freeze_Node (Entity (Name (gnat_node)))))
3921 break;
3923 /* Get the value to use as the address and save it as the
3924 equivalent for GNAT_TEMP. When the object is frozen,
3925 gnat_to_gnu_entity will do the right thing. */
3926 gnu_expr = gnat_to_gnu (Expression (gnat_node));
3927 save_gnu_tree (Entity (Name (gnat_node)), gnu_expr, 1);
3928 break;
3930 case N_Enumeration_Representation_Clause:
3931 case N_Record_Representation_Clause:
3932 case N_At_Clause:
3933 /* We do nothing with these. SEM puts the information elsewhere. */
3934 break;
3936 case N_Code_Statement:
3937 if (! type_annotate_only)
3939 tree gnu_template = gnat_to_gnu (Asm_Template (gnat_node));
3940 tree gnu_input_list = 0, gnu_output_list = 0, gnu_orig_out_list = 0;
3941 tree gnu_clobber_list = 0;
3942 char *clobber;
3944 /* First process inputs, then outputs, then clobbers. */
3945 Setup_Asm_Inputs (gnat_node);
3946 while (Present (gnat_temp = Asm_Input_Value ()))
3948 tree gnu_value = gnat_to_gnu (gnat_temp);
3949 tree gnu_constr = build_tree_list (NULL_TREE, gnat_to_gnu
3950 (Asm_Input_Constraint ()));
3952 gnu_input_list
3953 = tree_cons (gnu_constr, gnu_value, gnu_input_list);
3954 Next_Asm_Input ();
3957 Setup_Asm_Outputs (gnat_node);
3958 while (Present (gnat_temp = Asm_Output_Variable ()))
3960 tree gnu_value = gnat_to_gnu (gnat_temp);
3961 tree gnu_constr = build_tree_list (NULL_TREE, gnat_to_gnu
3962 (Asm_Output_Constraint ()));
3964 gnu_orig_out_list
3965 = tree_cons (gnu_constr, gnu_value, gnu_orig_out_list);
3966 gnu_output_list
3967 = tree_cons (gnu_constr, gnu_value, gnu_output_list);
3968 Next_Asm_Output ();
3971 Clobber_Setup (gnat_node);
3972 while ((clobber = Clobber_Get_Next ()) != 0)
3973 gnu_clobber_list
3974 = tree_cons (NULL_TREE,
3975 build_string (strlen (clobber) + 1, clobber),
3976 gnu_clobber_list);
3978 gnu_input_list = nreverse (gnu_input_list);
3979 gnu_output_list = nreverse (gnu_output_list);
3980 gnu_orig_out_list = nreverse (gnu_orig_out_list);
3981 gnu_result = build_nt (ASM_STMT, gnu_template, gnu_output_list,
3982 gnu_orig_out_list, gnu_input_list,
3983 gnu_clobber_list);
3984 TREE_THIS_VOLATILE (gnu_result) = Is_Asm_Volatile (gnat_node);
3986 break;
3988 /***************************************************/
3989 /* Added Nodes */
3990 /***************************************************/
3992 case N_Freeze_Entity:
3993 process_freeze_entity (gnat_node);
3994 start_block_stmt ();
3995 process_decls (Actions (gnat_node), Empty, Empty, 1, 1);
3996 gnat_expand_stmt (end_block_stmt ());
3997 break;
3999 case N_Itype_Reference:
4000 if (! present_gnu_tree (Itype (gnat_node)))
4001 process_type (Itype (gnat_node));
4002 break;
4004 case N_Free_Statement:
4005 if (! type_annotate_only)
4007 tree gnu_ptr = gnat_to_gnu (Expression (gnat_node));
4008 tree gnu_obj_type;
4009 tree gnu_obj_size;
4010 int align;
4012 /* If this is a thin pointer, we must dereference it to create
4013 a fat pointer, then go back below to a thin pointer. The
4014 reason for this is that we need a fat pointer someplace in
4015 order to properly compute the size. */
4016 if (TYPE_THIN_POINTER_P (TREE_TYPE (gnu_ptr)))
4017 gnu_ptr = build_unary_op (ADDR_EXPR, NULL_TREE,
4018 build_unary_op (INDIRECT_REF, NULL_TREE,
4019 gnu_ptr));
4021 /* If this is an unconstrained array, we know the object must
4022 have been allocated with the template in front of the object.
4023 So pass the template address, but get the total size. Do this
4024 by converting to a thin pointer. */
4025 if (TYPE_FAT_POINTER_P (TREE_TYPE (gnu_ptr)))
4026 gnu_ptr
4027 = convert (build_pointer_type
4028 (TYPE_OBJECT_RECORD_TYPE
4029 (TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (gnu_ptr)))),
4030 gnu_ptr);
4032 gnu_obj_type = TREE_TYPE (TREE_TYPE (gnu_ptr));
4033 gnu_obj_size = TYPE_SIZE_UNIT (gnu_obj_type);
4034 align = TYPE_ALIGN (gnu_obj_type);
4036 if (TREE_CODE (gnu_obj_type) == RECORD_TYPE
4037 && TYPE_CONTAINS_TEMPLATE_P (gnu_obj_type))
4039 tree gnu_char_ptr_type = build_pointer_type (char_type_node);
4040 tree gnu_pos = byte_position (TYPE_FIELDS (gnu_obj_type));
4041 tree gnu_byte_offset
4042 = convert (gnu_char_ptr_type,
4043 size_diffop (size_zero_node, gnu_pos));
4045 gnu_ptr = convert (gnu_char_ptr_type, gnu_ptr);
4046 gnu_ptr = build_binary_op (MINUS_EXPR, gnu_char_ptr_type,
4047 gnu_ptr, gnu_byte_offset);
4050 gnu_result
4051 = build_nt (EXPR_STMT,
4052 build_call_alloc_dealloc
4053 (gnu_ptr, gnu_obj_size, align,
4054 Procedure_To_Call (gnat_node),
4055 Storage_Pool (gnat_node), gnat_node));
4057 break;
4059 case N_Raise_Constraint_Error:
4060 case N_Raise_Program_Error:
4061 case N_Raise_Storage_Error:
4063 if (type_annotate_only)
4064 break;
4066 gnu_result_type = get_unpadded_type (Etype (gnat_node));
4067 gnu_result = build_call_raise (UI_To_Int (Reason (gnat_node)));
4069 /* If the type is VOID, this is a statement, so we need to
4070 generate the code for the call. Handle a Condition, if there
4071 is one. */
4072 if (TREE_CODE (gnu_result_type) == VOID_TYPE)
4074 gnu_result = build_nt (EXPR_STMT, gnu_result);
4075 TREE_TYPE (gnu_result) = void_type_node;
4076 TREE_SLOC (gnu_result) = Sloc (gnat_node);
4078 if (Present (Condition (gnat_node)))
4079 gnu_result = build_nt (IF_STMT,
4080 gnat_to_gnu (Condition (gnat_node)),
4081 gnu_result, NULL_TREE, NULL_TREE);
4083 else
4084 gnu_result = build1 (NULL_EXPR, gnu_result_type, gnu_result);
4085 break;
4087 case N_Validate_Unchecked_Conversion:
4088 /* If the result is a pointer type, see if we are either converting
4089 from a non-pointer or from a pointer to a type with a different
4090 alias set and warn if so. If the result defined in the same unit as
4091 this unchecked convertion, we can allow this because we can know to
4092 make that type have alias set 0. */
4094 tree gnu_source_type = gnat_to_gnu_type (Source_Type (gnat_node));
4095 tree gnu_target_type = gnat_to_gnu_type (Target_Type (gnat_node));
4097 if (POINTER_TYPE_P (gnu_target_type)
4098 && !In_Same_Source_Unit (Target_Type (gnat_node), gnat_node)
4099 && get_alias_set (TREE_TYPE (gnu_target_type)) != 0
4100 && !No_Strict_Aliasing (Underlying_Type (Target_Type (gnat_node)))
4101 && (!POINTER_TYPE_P (gnu_source_type)
4102 || (get_alias_set (TREE_TYPE (gnu_source_type))
4103 != get_alias_set (TREE_TYPE (gnu_target_type)))))
4105 post_error_ne
4106 ("?possible aliasing problem for type&",
4107 gnat_node, Target_Type (gnat_node));
4108 post_error
4109 ("\\?use -fno-strict-aliasing switch for references",
4110 gnat_node);
4111 post_error_ne
4112 ("\\?or use `pragma No_Strict_Aliasing (&);`",
4113 gnat_node, Target_Type (gnat_node));
4116 break;
4118 case N_Raise_Statement:
4119 case N_Function_Specification:
4120 case N_Procedure_Specification:
4121 case N_Op_Concat:
4122 case N_Component_Association:
4123 case N_Task_Body:
4124 default:
4125 if (! type_annotate_only)
4126 gigi_abort (321);
4129 /* If the result is a statement, set needed flags and return it. */
4130 if (IS_STMT (gnu_result))
4132 TREE_TYPE (gnu_result) = void_type_node;
4133 TREE_THIS_VOLATILE (gnu_result) = TREE_SIDE_EFFECTS (gnu_result) = 1;
4134 TREE_SLOC (gnu_result) = Sloc (gnat_node);
4135 return gnu_result;
4138 /* If the result is a constant that overflows, raise constraint error. */
4139 else if (TREE_CODE (gnu_result) == INTEGER_CST
4140 && TREE_CONSTANT_OVERFLOW (gnu_result))
4142 post_error ("Constraint_Error will be raised at run-time?", gnat_node);
4144 gnu_result
4145 = build1 (NULL_EXPR, gnu_result_type,
4146 build_call_raise (CE_Overflow_Check_Failed));
4149 /* If our result has side-effects and is of an unconstrained type,
4150 make a SAVE_EXPR so that we can be sure it will only be referenced
4151 once. Note we must do this before any conversions. */
4152 if (TREE_SIDE_EFFECTS (gnu_result)
4153 && (TREE_CODE (gnu_result_type) == UNCONSTRAINED_ARRAY_TYPE
4154 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_result_type))))
4155 gnu_result = gnat_stabilize_reference (gnu_result, 0);
4157 /* Now convert the result to the proper type. If the type is void or if
4158 we have no result, return error_mark_node to show we have no result.
4159 If the type of the result is correct or if we have a label (which doesn't
4160 have any well-defined type), return our result. Also don't do the
4161 conversion if the "desired" type involves a PLACEHOLDER_EXPR in its size
4162 since those are the cases where the front end may have the type wrong due
4163 to "instantiating" the unconstrained record with discriminant values
4164 or if this is a FIELD_DECL. If this is the Name of an assignment
4165 statement or a parameter of a procedure call, return what we have since
4166 the RHS has to be converted to our type there in that case, unless
4167 GNU_RESULT_TYPE has a simpler size. Similarly, if the two types are
4168 record types with the same name, the expression type has integral mode,
4169 and GNU_RESULT_TYPE BLKmode, don't convert. This will be the case when
4170 we are converting from a packable type to its actual type and we need
4171 those conversions to be NOPs in order for assignments into these types to
4172 work properly if the inner object is a bitfield and hence can't have
4173 its address taken. Finally, don't convert integral types that are the
4174 operand of an unchecked conversion since we need to ignore those
4175 conversions (for 'Valid). Otherwise, convert the result to the proper
4176 type. */
4178 if (Present (Parent (gnat_node))
4179 && ((Nkind (Parent (gnat_node)) == N_Assignment_Statement
4180 && Name (Parent (gnat_node)) == gnat_node)
4181 || (Nkind (Parent (gnat_node)) == N_Procedure_Call_Statement
4182 && Name (Parent (gnat_node)) != gnat_node)
4183 || (Nkind (Parent (gnat_node)) == N_Unchecked_Type_Conversion
4184 && ! AGGREGATE_TYPE_P (gnu_result_type)
4185 && ! AGGREGATE_TYPE_P (TREE_TYPE (gnu_result)))
4186 || Nkind (Parent (gnat_node)) == N_Parameter_Association)
4187 && ! (TYPE_SIZE (gnu_result_type) != 0
4188 && TYPE_SIZE (TREE_TYPE (gnu_result)) != 0
4189 && (AGGREGATE_TYPE_P (gnu_result_type)
4190 == AGGREGATE_TYPE_P (TREE_TYPE (gnu_result)))
4191 && ((TREE_CODE (TYPE_SIZE (gnu_result_type)) == INTEGER_CST
4192 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (gnu_result)))
4193 != INTEGER_CST))
4194 || (TREE_CODE (TYPE_SIZE (gnu_result_type)) != INTEGER_CST
4195 && ! CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_result_type))
4196 && (CONTAINS_PLACEHOLDER_P
4197 (TYPE_SIZE (TREE_TYPE (gnu_result))))))
4198 && ! (TREE_CODE (gnu_result_type) == RECORD_TYPE
4199 && TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_result_type))))
4201 /* In this case remove padding only if the inner object is of
4202 self-referential size: in that case it must be an object of
4203 unconstrained type with a default discriminant. In other cases,
4204 we want to avoid copying too much data. */
4205 if (TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
4206 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_result))
4207 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE
4208 (TREE_TYPE (TYPE_FIELDS
4209 (TREE_TYPE (gnu_result))))))
4210 gnu_result = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))),
4211 gnu_result);
4214 else if (TREE_CODE (gnu_result) == LABEL_DECL
4215 || TREE_CODE (gnu_result) == FIELD_DECL
4216 || TREE_CODE (gnu_result) == ERROR_MARK
4217 || (TYPE_SIZE (gnu_result_type) != 0
4218 && TREE_CODE (TYPE_SIZE (gnu_result_type)) != INTEGER_CST
4219 && TREE_CODE (gnu_result) != INDIRECT_REF
4220 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_result_type)))
4221 || ((TYPE_NAME (gnu_result_type)
4222 == TYPE_NAME (TREE_TYPE (gnu_result)))
4223 && TREE_CODE (gnu_result_type) == RECORD_TYPE
4224 && TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
4225 && TYPE_MODE (gnu_result_type) == BLKmode
4226 && (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (gnu_result)))
4227 == MODE_INT)))
4229 /* Remove any padding record, but do nothing more in this case. */
4230 if (TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
4231 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_result)))
4232 gnu_result = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))),
4233 gnu_result);
4236 else if (gnu_result == error_mark_node
4237 || gnu_result_type == void_type_node)
4238 gnu_result = error_mark_node;
4239 else if (gnu_result_type != TREE_TYPE (gnu_result))
4240 gnu_result = convert (gnu_result_type, gnu_result);
4242 /* We don't need any NOP_EXPR or NON_LVALUE_EXPR on GNU_RESULT. */
4243 while ((TREE_CODE (gnu_result) == NOP_EXPR
4244 || TREE_CODE (gnu_result) == NON_LVALUE_EXPR)
4245 && TREE_TYPE (TREE_OPERAND (gnu_result, 0)) == TREE_TYPE (gnu_result))
4246 gnu_result = TREE_OPERAND (gnu_result, 0);
4248 return gnu_result;
4251 /* INSN is a list of insns. Return the first rtl in the list that isn't
4252 an INSN_NOTE_DELETED. */
4254 static rtx
4255 first_nondeleted_insn (rtx insns)
4257 for (; insns && GET_CODE (insns) == NOTE
4258 && NOTE_LINE_NUMBER (insns) == NOTE_INSN_DELETED;
4259 insns = NEXT_INSN (insns))
4262 return insns;
4265 /* Push the BLOCK_STMT stack and allocate a new BLOCK_STMT. */
4267 static tree
4268 start_block_stmt ()
4270 tree gnu_block_stmt;
4272 /* First see if we can get one from the free list. */
4273 if (gnu_block_stmt_free_list)
4275 gnu_block_stmt = gnu_block_stmt_free_list;
4276 gnu_block_stmt_free_list = TREE_CHAIN (gnu_block_stmt_free_list);
4278 else
4280 gnu_block_stmt = make_node (BLOCK_STMT);
4281 TREE_TYPE (gnu_block_stmt) = void_type_node;
4284 BLOCK_STMT_LIST (gnu_block_stmt) = 0;
4285 TREE_CHAIN (gnu_block_stmt) = gnu_block_stmt_node;
4286 gnu_block_stmt_node = gnu_block_stmt;
4288 return gnu_block_stmt;
4291 /* Add GNU_STMT to the current BLOCK_STMT node. We add them backwards
4292 order and the reverse in end_block_stmt. */
4294 void
4295 add_stmt (tree gnu_stmt)
4297 if (TREE_CODE_CLASS (TREE_CODE (gnu_stmt)) != 's')
4298 gigi_abort (340);
4300 if (TREE_CODE (gnu_stmt) != NULL_STMT)
4302 TREE_CHAIN (gnu_stmt) = BLOCK_STMT_LIST (gnu_block_stmt_node);
4303 BLOCK_STMT_LIST (gnu_block_stmt_node) = gnu_stmt;
4306 /* If this is a DECL_STMT for a variable with DECL_INIT_BY_ASSIGN_P set,
4307 generate the assignment statement too. */
4308 if (TREE_CODE (gnu_stmt) == DECL_STMT
4309 && TREE_CODE (DECL_STMT_VAR (gnu_stmt)) == VAR_DECL
4310 && DECL_INIT_BY_ASSIGN_P (DECL_STMT_VAR (gnu_stmt)))
4312 tree gnu_decl = DECL_STMT_VAR (gnu_stmt);
4313 tree gnu_lhs = gnu_decl;
4314 tree gnu_assign_stmt;
4316 /* If decl has a padded type, convert it to the unpadded type so the
4317 assignment is done properly. */
4318 if (TREE_CODE (TREE_TYPE (gnu_lhs)) == RECORD_TYPE
4319 && TYPE_IS_PADDING_P (TREE_TYPE (gnu_lhs)))
4320 gnu_lhs
4321 = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_lhs))), gnu_lhs);
4323 gnu_assign_stmt
4324 = build_nt (EXPR_STMT,
4325 build_binary_op (MODIFY_EXPR, NULL_TREE,
4326 gnu_lhs, DECL_INITIAL (gnu_decl)));
4327 DECL_INITIAL (gnu_decl) = 0;
4328 DECL_INIT_BY_ASSIGN_P (gnu_decl) = 0;
4330 TREE_SLOC (gnu_assign_stmt) = TREE_SLOC (gnu_stmt);
4331 TREE_TYPE (gnu_assign_stmt) = void_type_node;
4332 add_stmt (gnu_assign_stmt);
4336 /* Add a declaration statement for GNU_DECL to the current BLOCK_STMT node.
4337 Get SLOC from Entity_Id. */
4339 void
4340 add_decl_stmt (tree gnu_decl, Entity_Id gnat_entity)
4342 tree gnu_stmt;
4344 /* If this is a variable that Gigi is to ignore, we may have been given
4345 an ERROR_MARK. So test for it. We also might have been given a
4346 reference for a renaming. So only do something for a decl. */
4347 if (!DECL_P (gnu_decl))
4348 return;
4350 gnu_stmt = build_nt (DECL_STMT, gnu_decl);
4351 TREE_TYPE (gnu_stmt) = void_type_node;
4352 TREE_SLOC (gnu_stmt) = Sloc (gnat_entity);
4353 add_stmt (gnu_stmt);
4356 /* Return the BLOCK_STMT that corresponds to the statement that add_stmt
4357 has been emitting or just a single statement if only one. */
4359 static tree
4360 end_block_stmt ()
4362 tree gnu_block_stmt = gnu_block_stmt_node;
4363 tree gnu_retval = gnu_block_stmt;
4365 gnu_block_stmt_node = TREE_CHAIN (gnu_block_stmt);
4366 TREE_CHAIN (gnu_block_stmt) = 0;
4368 /* If we have only one statement, return it and free this node. Otherwise,
4369 finish setting up this node and return it. If we have no statements,
4370 return a NULL_STMT. */
4371 if (BLOCK_STMT_LIST (gnu_block_stmt) == 0)
4373 gnu_retval = build_nt (NULL_STMT);
4374 TREE_TYPE (gnu_retval) = void_type_node;
4376 else if (TREE_CHAIN (BLOCK_STMT_LIST (gnu_block_stmt)) == 0)
4377 gnu_retval = BLOCK_STMT_LIST (gnu_block_stmt);
4378 else
4380 BLOCK_STMT_LIST (gnu_block_stmt)
4381 = nreverse (BLOCK_STMT_LIST (gnu_block_stmt));
4382 TREE_SLOC (gnu_block_stmt)
4383 = TREE_SLOC (BLOCK_STMT_LIST (gnu_block_stmt));
4386 if (gnu_retval != gnu_block_stmt)
4388 TREE_CHAIN (gnu_block_stmt) = gnu_block_stmt_free_list;
4389 gnu_block_stmt_free_list = gnu_block_stmt;
4392 return gnu_retval;
4395 /* Build a BLOCK_STMT from GNAT_LIST, a possibly-empty list of statements. */
4397 static tree
4398 build_block_stmt (List_Id gnat_list)
4400 tree gnu_result = NULL_TREE;
4401 Node_Id gnat_node;
4403 if (No (gnat_list) || Is_Empty_List (gnat_list))
4404 return NULL_TREE;
4406 start_block_stmt ();
4408 for (gnat_node = First (gnat_list);
4409 Present (gnat_node);
4410 gnat_node = Next (gnat_node))
4411 add_stmt (gnat_to_gnu (gnat_node));
4413 gnu_result = end_block_stmt ();
4414 return TREE_CODE (gnu_result) == NULL_STMT ? NULL_TREE : gnu_result;
4417 /* Build an EXPR_STMT to evaluate INSNS. Use Sloc from GNAT_NODE. */
4419 static tree
4420 make_expr_stmt_from_rtl (rtx insns, Node_Id gnat_node)
4422 tree gnu_result = make_node (RTL_EXPR);
4424 TREE_TYPE (gnu_result) = void_type_node;
4425 RTL_EXPR_RTL (gnu_result) = RTL_EXPR_ALT_RTL (gnu_result) = const0_rtx;
4426 RTL_EXPR_SEQUENCE (gnu_result) = insns;
4427 rtl_expr_chain = tree_cons (NULL_TREE, gnu_result, rtl_expr_chain);
4429 gnu_result = build_nt (EXPR_STMT, gnu_result);
4430 TREE_SLOC (gnu_result) = Sloc (gnat_node);
4431 TREE_TYPE (gnu_result) = void_type_node;
4433 return gnu_result;
4436 /* GNU_STMT is a statement. We generate code for that statement. */
4438 void
4439 gnat_expand_stmt (tree gnu_stmt)
4441 tree gnu_elmt, gnu_elmt_2;
4443 if (TREE_SLOC (gnu_stmt))
4444 set_lineno_from_sloc (TREE_SLOC (gnu_stmt), 1);
4446 switch (TREE_CODE (gnu_stmt))
4448 case EXPR_STMT:
4449 expand_expr_stmt (EXPR_STMT_EXPR (gnu_stmt));
4450 break;
4452 case NULL_STMT:
4453 break;
4455 case DECL_STMT:
4456 if (TREE_CODE (DECL_STMT_VAR (gnu_stmt)) == TYPE_DECL)
4457 force_type_save_exprs (TREE_TYPE (DECL_STMT_VAR (gnu_stmt)));
4458 else
4460 expand_decl (DECL_STMT_VAR (gnu_stmt));
4461 if (DECL_CONTEXT (DECL_STMT_VAR (gnu_stmt)))
4462 expand_decl_init (DECL_STMT_VAR (gnu_stmt));
4464 if (TREE_ADDRESSABLE (DECL_STMT_VAR (gnu_stmt)))
4466 put_var_into_stack (DECL_STMT_VAR (gnu_stmt), true);
4467 flush_addressof (DECL_STMT_VAR (gnu_stmt));
4470 break;
4472 case BLOCK_STMT:
4473 for (gnu_elmt = BLOCK_STMT_LIST (gnu_stmt); gnu_elmt;
4474 gnu_elmt = TREE_CHAIN (gnu_elmt))
4475 gnat_expand_stmt (gnu_elmt);
4476 break;
4478 case IF_STMT:
4479 expand_start_cond (IF_STMT_COND (gnu_stmt), 0);
4481 if (IF_STMT_TRUE (gnu_stmt))
4482 gnat_expand_stmt (IF_STMT_TRUE (gnu_stmt));
4484 for (gnu_elmt = IF_STMT_ELSEIF (gnu_stmt); gnu_elmt;
4485 gnu_elmt = TREE_CHAIN (gnu_elmt))
4487 expand_start_else ();
4488 set_lineno_from_sloc (TREE_SLOC (gnu_elmt), 1);
4489 expand_elseif (IF_STMT_COND (gnu_elmt));
4490 if (IF_STMT_TRUE (gnu_elmt))
4491 gnat_expand_stmt (IF_STMT_TRUE (gnu_elmt));
4494 if (IF_STMT_ELSE (gnu_stmt))
4496 expand_start_else ();
4497 gnat_expand_stmt (IF_STMT_ELSE (gnu_stmt));
4500 expand_end_cond ();
4501 break;
4503 case GOTO_STMT:
4504 TREE_USED (GOTO_STMT_LABEL (gnu_stmt)) = 1;
4505 expand_goto (GOTO_STMT_LABEL (gnu_stmt));
4506 break;
4508 case LABEL_STMT:
4509 expand_label (LABEL_STMT_LABEL (gnu_stmt));
4510 break;
4512 case RETURN_STMT:
4513 if (RETURN_STMT_EXPR (gnu_stmt))
4514 expand_return (build_binary_op (MODIFY_EXPR, NULL_TREE,
4515 DECL_RESULT (current_function_decl),
4516 RETURN_STMT_EXPR (gnu_stmt)));
4517 else
4518 expand_null_return ();
4519 break;
4521 case ASM_STMT:
4522 expand_asm_operands (ASM_STMT_TEMPLATE (gnu_stmt),
4523 ASM_STMT_OUTPUT (gnu_stmt),
4524 ASM_STMT_INPUT (gnu_stmt),
4525 ASM_STMT_CLOBBER (gnu_stmt),
4526 TREE_THIS_VOLATILE (gnu_stmt), input_location);
4528 /* Copy all the intermediate outputs into the specified outputs. */
4529 for ((gnu_elmt = ASM_STMT_OUTPUT (gnu_stmt),
4530 gnu_elmt_2 = ASM_STMT_ORIG_OUT (gnu_stmt));
4531 gnu_elmt;
4532 (gnu_elmt = TREE_CHAIN (gnu_elmt),
4533 gnu_elmt_2 = TREE_CHAIN (gnu_elmt_2)))
4534 if (TREE_VALUE (gnu_elmt) != TREE_VALUE (gnu_elmt_2))
4536 expand_expr_stmt
4537 (build_binary_op (MODIFY_EXPR, NULL_TREE,
4538 TREE_VALUE (gnu_elmt_2),
4539 TREE_VALUE (gnu_elmt)));
4540 free_temp_slots ();
4542 break;
4544 default:
4545 abort ();
4549 /* Force references to each of the entities in packages GNAT_NODE with's
4550 so that the debugging information for all of them are identical
4551 in all clients. Operate recursively on anything it with's, but check
4552 that we aren't elaborating something more than once. */
4554 /* The reason for this routine's existence is two-fold.
4555 First, with some debugging formats, notably MDEBUG on SGI
4556 IRIX, the linker will remove duplicate debugging information if two
4557 clients have identical debugguing information. With the normal scheme
4558 of elaboration, this does not usually occur, since entities in with'ed
4559 packages are elaborated on demand, and if clients have different usage
4560 patterns, the normal case, then the order and selection of entities
4561 will differ. In most cases however, it seems that linkers do not know
4562 how to eliminate duplicate debugging information, even if it is
4563 identical, so the use of this routine would increase the total amount
4564 of debugging information in the final executable.
4566 Second, this routine is called in type_annotate mode, to compute DDA
4567 information for types in withed units, for ASIS use */
4569 static void
4570 elaborate_all_entities (Node_Id gnat_node)
4572 Entity_Id gnat_with_clause, gnat_entity;
4574 /* Process each unit only once. As we trace the context of all relevant
4575 units transitively, including generic bodies, we may encounter the
4576 same generic unit repeatedly */
4578 if (!present_gnu_tree (gnat_node))
4579 save_gnu_tree (gnat_node, integer_zero_node, 1);
4581 /* Save entities in all context units. A body may have an implicit_with
4582 on its own spec, if the context includes a child unit, so don't save
4583 the spec twice. */
4585 for (gnat_with_clause = First (Context_Items (gnat_node));
4586 Present (gnat_with_clause);
4587 gnat_with_clause = Next (gnat_with_clause))
4588 if (Nkind (gnat_with_clause) == N_With_Clause
4589 && ! present_gnu_tree (Library_Unit (gnat_with_clause))
4590 && Library_Unit (gnat_with_clause) != Library_Unit (Cunit (Main_Unit)))
4592 elaborate_all_entities (Library_Unit (gnat_with_clause));
4594 if (Ekind (Entity (Name (gnat_with_clause))) == E_Package)
4596 for (gnat_entity = First_Entity (Entity (Name (gnat_with_clause)));
4597 Present (gnat_entity);
4598 gnat_entity = Next_Entity (gnat_entity))
4599 if (Is_Public (gnat_entity)
4600 && Convention (gnat_entity) != Convention_Intrinsic
4601 && Ekind (gnat_entity) != E_Package
4602 && Ekind (gnat_entity) != E_Package_Body
4603 && Ekind (gnat_entity) != E_Operator
4604 && ! (IN (Ekind (gnat_entity), Type_Kind)
4605 && ! Is_Frozen (gnat_entity))
4606 && ! ((Ekind (gnat_entity) == E_Procedure
4607 || Ekind (gnat_entity) == E_Function)
4608 && Is_Intrinsic_Subprogram (gnat_entity))
4609 && ! IN (Ekind (gnat_entity), Named_Kind)
4610 && ! IN (Ekind (gnat_entity), Generic_Unit_Kind))
4611 gnat_to_gnu_entity (gnat_entity, NULL_TREE, 0);
4613 else if (Ekind (Entity (Name (gnat_with_clause))) == E_Generic_Package)
4615 Node_Id gnat_body
4616 = Corresponding_Body (Unit (Library_Unit (gnat_with_clause)));
4618 /* Retrieve compilation unit node of generic body. */
4619 while (Present (gnat_body)
4620 && Nkind (gnat_body) != N_Compilation_Unit)
4621 gnat_body = Parent (gnat_body);
4623 /* If body is available, elaborate its context. */
4624 if (Present (gnat_body))
4625 elaborate_all_entities (gnat_body);
4629 if (Nkind (Unit (gnat_node)) == N_Package_Body && type_annotate_only)
4630 elaborate_all_entities (Library_Unit (gnat_node));
4633 /* Do the processing of N_Freeze_Entity, GNAT_NODE. */
4635 static void
4636 process_freeze_entity (Node_Id gnat_node)
4638 Entity_Id gnat_entity = Entity (gnat_node);
4639 tree gnu_old;
4640 tree gnu_new;
4641 tree gnu_init
4642 = (Nkind (Declaration_Node (gnat_entity)) == N_Object_Declaration
4643 && present_gnu_tree (Declaration_Node (gnat_entity)))
4644 ? get_gnu_tree (Declaration_Node (gnat_entity)) : NULL_TREE;
4646 /* If this is a package, need to generate code for the package. */
4647 if (Ekind (gnat_entity) == E_Package)
4649 insert_code_for
4650 (Parent (Corresponding_Body
4651 (Parent (Declaration_Node (gnat_entity)))));
4652 return;
4655 /* Check for old definition after the above call. This Freeze_Node
4656 might be for one its Itypes. */
4657 gnu_old
4658 = present_gnu_tree (gnat_entity) ? get_gnu_tree (gnat_entity) : 0;
4660 /* If this entity has an Address representation clause, GNU_OLD is the
4661 address, so discard it here. */
4662 if (Present (Address_Clause (gnat_entity)))
4663 gnu_old = 0;
4665 /* Don't do anything for class-wide types they are always
4666 transformed into their root type. */
4667 if (Ekind (gnat_entity) == E_Class_Wide_Type
4668 || (Ekind (gnat_entity) == E_Class_Wide_Subtype
4669 && Present (Equivalent_Type (gnat_entity))))
4670 return;
4672 /* Don't do anything for subprograms that may have been elaborated before
4673 their freeze nodes. This can happen, for example because of an inner call
4674 in an instance body. */
4675 if (gnu_old != 0
4676 && TREE_CODE (gnu_old) == FUNCTION_DECL
4677 && (Ekind (gnat_entity) == E_Function
4678 || Ekind (gnat_entity) == E_Procedure))
4679 return;
4681 /* If we have a non-dummy type old tree, we have nothing to do. Unless
4682 this is the public view of a private type whose full view was not
4683 delayed, this node was never delayed as it should have been.
4684 Also allow this to happen for concurrent types since we may have
4685 frozen both the Corresponding_Record_Type and this type. */
4686 if (gnu_old != 0
4687 && ! (TREE_CODE (gnu_old) == TYPE_DECL
4688 && TYPE_IS_DUMMY_P (TREE_TYPE (gnu_old))))
4690 if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
4691 && Present (Full_View (gnat_entity))
4692 && No (Freeze_Node (Full_View (gnat_entity))))
4693 return;
4694 else if (Is_Concurrent_Type (gnat_entity))
4695 return;
4696 else
4697 gigi_abort (320);
4700 /* Reset the saved tree, if any, and elaborate the object or type for real.
4701 If there is a full declaration, elaborate it and copy the type to
4702 GNAT_ENTITY. Likewise if this is the record subtype corresponding to
4703 a class wide type or subtype. */
4704 if (gnu_old != 0)
4706 save_gnu_tree (gnat_entity, NULL_TREE, 0);
4707 if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
4708 && Present (Full_View (gnat_entity))
4709 && present_gnu_tree (Full_View (gnat_entity)))
4710 save_gnu_tree (Full_View (gnat_entity), NULL_TREE, 0);
4711 if (Present (Class_Wide_Type (gnat_entity))
4712 && Class_Wide_Type (gnat_entity) != gnat_entity)
4713 save_gnu_tree (Class_Wide_Type (gnat_entity), NULL_TREE, 0);
4716 if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
4717 && Present (Full_View (gnat_entity)))
4719 gnu_new = gnat_to_gnu_entity (Full_View (gnat_entity), NULL_TREE, 1);
4721 /* The above call may have defined this entity (the simplest example
4722 of this is when we have a private enumeral type since the bounds
4723 will have the public view. */
4724 if (! present_gnu_tree (gnat_entity))
4725 save_gnu_tree (gnat_entity, gnu_new, 0);
4726 if (Present (Class_Wide_Type (gnat_entity))
4727 && Class_Wide_Type (gnat_entity) != gnat_entity)
4728 save_gnu_tree (Class_Wide_Type (gnat_entity), gnu_new, 0);
4730 else
4731 gnu_new = gnat_to_gnu_entity (gnat_entity, gnu_init, 1);
4733 /* If we've made any pointers to the old version of this type, we
4734 have to update them. */
4735 if (gnu_old != 0)
4736 update_pointer_to (TYPE_MAIN_VARIANT (TREE_TYPE (gnu_old)),
4737 TREE_TYPE (gnu_new));
4740 /* Process the list of inlined subprograms of GNAT_NODE, which is an
4741 N_Compilation_Unit. */
4743 static void
4744 process_inlined_subprograms (Node_Id gnat_node)
4746 Entity_Id gnat_entity;
4747 Node_Id gnat_body;
4749 /* If we can inline, generate RTL for all the inlined subprograms.
4750 Define the entity first so we set DECL_EXTERNAL. */
4751 if (optimize > 0 && ! flag_no_inline)
4752 for (gnat_entity = First_Inlined_Subprogram (gnat_node);
4753 Present (gnat_entity);
4754 gnat_entity = Next_Inlined_Subprogram (gnat_entity))
4756 gnat_body = Parent (Declaration_Node (gnat_entity));
4758 if (Nkind (gnat_body) != N_Subprogram_Body)
4760 /* ??? This really should always be Present. */
4761 if (No (Corresponding_Body (gnat_body)))
4762 continue;
4764 gnat_body
4765 = Parent (Declaration_Node (Corresponding_Body (gnat_body)));
4768 if (Present (gnat_body))
4770 gnat_to_gnu_entity (gnat_entity, NULL_TREE, 0);
4771 gnat_to_code (gnat_body);
4776 /* Elaborate decls in the lists GNAT_DECLS and GNAT_DECLS2, if present.
4777 We make two passes, one to elaborate anything other than bodies (but
4778 we declare a function if there was no spec). The second pass
4779 elaborates the bodies.
4781 GNAT_END_LIST gives the element in the list past the end. Normally,
4782 this is Empty, but can be First_Real_Statement for a
4783 Handled_Sequence_Of_Statements.
4785 We make a complete pass through both lists if PASS1P is true, then make
4786 the second pass over both lists if PASS2P is true. The lists usually
4787 correspond to the public and private parts of a package. */
4789 static void
4790 process_decls (List_Id gnat_decls, List_Id gnat_decls2,
4791 Node_Id gnat_end_list, int pass1p, int pass2p)
4793 List_Id gnat_decl_array[2];
4794 Node_Id gnat_decl;
4795 int i;
4797 gnat_decl_array[0] = gnat_decls, gnat_decl_array[1] = gnat_decls2;
4799 if (pass1p)
4800 for (i = 0; i <= 1; i++)
4801 if (Present (gnat_decl_array[i]))
4802 for (gnat_decl = First (gnat_decl_array[i]);
4803 gnat_decl != gnat_end_list; gnat_decl = Next (gnat_decl))
4805 set_lineno (gnat_decl, 0);
4807 /* For package specs, we recurse inside the declarations,
4808 thus taking the two pass approach inside the boundary. */
4809 if (Nkind (gnat_decl) == N_Package_Declaration
4810 && (Nkind (Specification (gnat_decl)
4811 == N_Package_Specification)))
4812 process_decls (Visible_Declarations (Specification (gnat_decl)),
4813 Private_Declarations (Specification (gnat_decl)),
4814 Empty, 1, 0);
4816 /* Similarly for any declarations in the actions of a
4817 freeze node. */
4818 else if (Nkind (gnat_decl) == N_Freeze_Entity)
4820 start_block_stmt ();
4821 process_freeze_entity (gnat_decl);
4822 gnat_expand_stmt (end_block_stmt ());
4823 process_decls (Actions (gnat_decl), Empty, Empty, 1, 0);
4826 /* Package bodies with freeze nodes get their elaboration deferred
4827 until the freeze node, but the code must be placed in the right
4828 place, so record the code position now. */
4829 else if (Nkind (gnat_decl) == N_Package_Body
4830 && Present (Freeze_Node (Corresponding_Spec (gnat_decl))))
4831 record_code_position (gnat_decl);
4833 else if (Nkind (gnat_decl) == N_Package_Body_Stub
4834 && Present (Library_Unit (gnat_decl))
4835 && Present (Freeze_Node
4836 (Corresponding_Spec
4837 (Proper_Body (Unit
4838 (Library_Unit (gnat_decl)))))))
4839 record_code_position
4840 (Proper_Body (Unit (Library_Unit (gnat_decl))));
4842 /* We defer most subprogram bodies to the second pass. */
4843 else if (Nkind (gnat_decl) == N_Subprogram_Body)
4845 if (Acts_As_Spec (gnat_decl))
4847 Node_Id gnat_subprog_id = Defining_Entity (gnat_decl);
4849 if (Ekind (gnat_subprog_id) != E_Generic_Procedure
4850 && Ekind (gnat_subprog_id) != E_Generic_Function)
4851 gnat_to_gnu_entity (gnat_subprog_id, NULL_TREE, 1);
4854 /* For bodies and stubs that act as their own specs, the entity
4855 itself must be elaborated in the first pass, because it may
4856 be used in other declarations. */
4857 else if (Nkind (gnat_decl) == N_Subprogram_Body_Stub)
4859 Node_Id gnat_subprog_id =
4860 Defining_Entity (Specification (gnat_decl));
4862 if (Ekind (gnat_subprog_id) != E_Subprogram_Body
4863 && Ekind (gnat_subprog_id) != E_Generic_Procedure
4864 && Ekind (gnat_subprog_id) != E_Generic_Function)
4865 gnat_to_gnu_entity (gnat_subprog_id, NULL_TREE, 1);
4868 /* Concurrent stubs stand for the corresponding subprogram bodies,
4869 which are deferred like other bodies. */
4870 else if (Nkind (gnat_decl) == N_Task_Body_Stub
4871 || Nkind (gnat_decl) == N_Protected_Body_Stub)
4874 else
4876 start_block_stmt ();
4877 gnat_to_code (gnat_decl);
4878 gnat_expand_stmt (end_block_stmt ());
4882 /* Here we elaborate everything we deferred above except for package bodies,
4883 which are elaborated at their freeze nodes. Note that we must also
4884 go inside things (package specs and freeze nodes) the first pass did. */
4885 if (pass2p)
4886 for (i = 0; i <= 1; i++)
4887 if (Present (gnat_decl_array[i]))
4888 for (gnat_decl = First (gnat_decl_array[i]);
4889 gnat_decl != gnat_end_list; gnat_decl = Next (gnat_decl))
4891 if (Nkind (gnat_decl) == N_Subprogram_Body
4892 || Nkind (gnat_decl) == N_Subprogram_Body_Stub
4893 || Nkind (gnat_decl) == N_Task_Body_Stub
4894 || Nkind (gnat_decl) == N_Protected_Body_Stub)
4895 gnat_to_code (gnat_decl);
4897 else if (Nkind (gnat_decl) == N_Package_Declaration
4898 && (Nkind (Specification (gnat_decl)
4899 == N_Package_Specification)))
4900 process_decls (Visible_Declarations (Specification (gnat_decl)),
4901 Private_Declarations (Specification (gnat_decl)),
4902 Empty, 0, 1);
4904 else if (Nkind (gnat_decl) == N_Freeze_Entity)
4905 process_decls (Actions (gnat_decl), Empty, Empty, 0, 1);
4909 /* Emit code for a range check. GNU_EXPR is the expression to be checked,
4910 GNAT_RANGE_TYPE the gnat type or subtype containing the bounds against
4911 which we have to check. */
4913 static tree
4914 emit_range_check (tree gnu_expr, Entity_Id gnat_range_type)
4916 tree gnu_range_type = get_unpadded_type (gnat_range_type);
4917 tree gnu_low = TYPE_MIN_VALUE (gnu_range_type);
4918 tree gnu_high = TYPE_MAX_VALUE (gnu_range_type);
4919 tree gnu_compare_type = get_base_type (TREE_TYPE (gnu_expr));
4921 /* If GNU_EXPR has an integral type that is narrower than GNU_RANGE_TYPE,
4922 we can't do anything since we might be truncating the bounds. No
4923 check is needed in this case. */
4924 if (INTEGRAL_TYPE_P (TREE_TYPE (gnu_expr))
4925 && (TYPE_PRECISION (gnu_compare_type)
4926 < TYPE_PRECISION (get_base_type (gnu_range_type))))
4927 return gnu_expr;
4929 /* Checked expressions must be evaluated only once. */
4930 gnu_expr = protect_multiple_eval (gnu_expr);
4932 /* There's no good type to use here, so we might as well use
4933 integer_type_node. Note that the form of the check is
4934 (not (expr >= lo)) or (not (expr >= hi))
4935 the reason for this slightly convoluted form is that NaN's
4936 are not considered to be in range in the float case. */
4937 return emit_check
4938 (build_binary_op (TRUTH_ORIF_EXPR, integer_type_node,
4939 invert_truthvalue
4940 (build_binary_op (GE_EXPR, integer_type_node,
4941 convert (gnu_compare_type, gnu_expr),
4942 convert (gnu_compare_type, gnu_low))),
4943 invert_truthvalue
4944 (build_binary_op (LE_EXPR, integer_type_node,
4945 convert (gnu_compare_type, gnu_expr),
4946 convert (gnu_compare_type,
4947 gnu_high)))),
4948 gnu_expr, CE_Range_Check_Failed);
4951 /* Emit code for an index check. GNU_ARRAY_OBJECT is the array object
4952 which we are about to index, GNU_EXPR is the index expression to be
4953 checked, GNU_LOW and GNU_HIGH are the lower and upper bounds
4954 against which GNU_EXPR has to be checked. Note that for index
4955 checking we cannot use the emit_range_check function (although very
4956 similar code needs to be generated in both cases) since for index
4957 checking the array type against which we are checking the indeces
4958 may be unconstrained and consequently we need to retrieve the
4959 actual index bounds from the array object itself
4960 (GNU_ARRAY_OBJECT). The place where we need to do that is in
4961 subprograms having unconstrained array formal parameters */
4963 static tree
4964 emit_index_check (tree gnu_array_object,
4965 tree gnu_expr,
4966 tree gnu_low,
4967 tree gnu_high)
4969 tree gnu_expr_check;
4971 /* Checked expressions must be evaluated only once. */
4972 gnu_expr = protect_multiple_eval (gnu_expr);
4974 /* Must do this computation in the base type in case the expression's
4975 type is an unsigned subtypes. */
4976 gnu_expr_check = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr);
4978 /* If GNU_LOW or GNU_HIGH are a PLACEHOLDER_EXPR, qualify them by
4979 the object we are handling. */
4980 gnu_low = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_low, gnu_array_object);
4981 gnu_high = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_high, gnu_array_object);
4983 /* There's no good type to use here, so we might as well use
4984 integer_type_node. */
4985 return emit_check
4986 (build_binary_op (TRUTH_ORIF_EXPR, integer_type_node,
4987 build_binary_op (LT_EXPR, integer_type_node,
4988 gnu_expr_check,
4989 convert (TREE_TYPE (gnu_expr_check),
4990 gnu_low)),
4991 build_binary_op (GT_EXPR, integer_type_node,
4992 gnu_expr_check,
4993 convert (TREE_TYPE (gnu_expr_check),
4994 gnu_high))),
4995 gnu_expr, CE_Index_Check_Failed);
4998 /* Given GNU_COND which contains the condition corresponding to an access,
4999 discriminant or range check, of value GNU_EXPR, build a COND_EXPR
5000 that returns GNU_EXPR if GNU_COND is false and raises a
5001 CONSTRAINT_ERROR if GNU_COND is true. REASON is the code that says
5002 why the exception was raised. */
5004 static tree
5005 emit_check (tree gnu_cond, tree gnu_expr, int reason)
5007 tree gnu_call;
5008 tree gnu_result;
5010 gnu_call = build_call_raise (reason);
5012 /* Use an outer COMPOUND_EXPR to make sure that GNU_EXPR will get evaluated
5013 in front of the comparison in case it ends up being a SAVE_EXPR. Put the
5014 whole thing inside its own SAVE_EXPR so the inner SAVE_EXPR doesn't leak
5015 out. */
5016 gnu_result = fold (build (COND_EXPR, TREE_TYPE (gnu_expr), gnu_cond,
5017 build (COMPOUND_EXPR, TREE_TYPE (gnu_expr),
5018 gnu_call, gnu_expr),
5019 gnu_expr));
5021 /* If GNU_EXPR has side effects, make the outer COMPOUND_EXPR and
5022 protect it. Otherwise, show GNU_RESULT has no side effects: we
5023 don't need to evaluate it just for the check. */
5024 if (TREE_SIDE_EFFECTS (gnu_expr))
5025 gnu_result
5026 = build (COMPOUND_EXPR, TREE_TYPE (gnu_expr), gnu_expr, gnu_result);
5027 else
5028 TREE_SIDE_EFFECTS (gnu_result) = 0;
5030 /* ??? Unfortunately, if we don't put a SAVE_EXPR around this whole thing,
5031 we will repeatedly do the test. It would be nice if GCC was able
5032 to optimize this and only do it once. */
5033 return save_expr (gnu_result);
5036 /* Return an expression that converts GNU_EXPR to GNAT_TYPE, doing
5037 overflow checks if OVERFLOW_P is nonzero and range checks if
5038 RANGE_P is nonzero. GNAT_TYPE is known to be an integral type.
5039 If TRUNCATE_P is nonzero, do a float to integer conversion with
5040 truncation; otherwise round. */
5042 static tree
5043 convert_with_check (Entity_Id gnat_type,
5044 tree gnu_expr,
5045 int overflow_p,
5046 int range_p,
5047 int truncate_p)
5049 tree gnu_type = get_unpadded_type (gnat_type);
5050 tree gnu_in_type = TREE_TYPE (gnu_expr);
5051 tree gnu_in_basetype = get_base_type (gnu_in_type);
5052 tree gnu_base_type = get_base_type (gnu_type);
5053 tree gnu_ada_base_type = get_ada_base_type (gnu_type);
5054 tree gnu_result = gnu_expr;
5056 /* If we are not doing any checks, the output is an integral type, and
5057 the input is not a floating type, just do the conversion. This
5058 shortcut is required to avoid problems with packed array types
5059 and simplifies code in all cases anyway. */
5060 if (! range_p && ! overflow_p && INTEGRAL_TYPE_P (gnu_base_type)
5061 && ! FLOAT_TYPE_P (gnu_in_type))
5062 return convert (gnu_type, gnu_expr);
5064 /* First convert the expression to its base type. This
5065 will never generate code, but makes the tests below much simpler.
5066 But don't do this if converting from an integer type to an unconstrained
5067 array type since then we need to get the bounds from the original
5068 (unpacked) type. */
5069 if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE)
5070 gnu_result = convert (gnu_in_basetype, gnu_result);
5072 /* If overflow checks are requested, we need to be sure the result will
5073 fit in the output base type. But don't do this if the input
5074 is integer and the output floating-point. */
5075 if (overflow_p
5076 && ! (FLOAT_TYPE_P (gnu_base_type) && INTEGRAL_TYPE_P (gnu_in_basetype)))
5078 /* Ensure GNU_EXPR only gets evaluated once. */
5079 tree gnu_input = protect_multiple_eval (gnu_result);
5080 tree gnu_cond = integer_zero_node;
5081 tree gnu_in_lb = TYPE_MIN_VALUE (gnu_in_basetype);
5082 tree gnu_in_ub = TYPE_MAX_VALUE (gnu_in_basetype);
5083 tree gnu_out_lb = TYPE_MIN_VALUE (gnu_base_type);
5084 tree gnu_out_ub = TYPE_MAX_VALUE (gnu_base_type);
5086 /* Convert the lower bounds to signed types, so we're sure we're
5087 comparing them properly. Likewise, convert the upper bounds
5088 to unsigned types. */
5089 if (INTEGRAL_TYPE_P (gnu_in_basetype) && TYPE_UNSIGNED (gnu_in_basetype))
5090 gnu_in_lb = convert (gnat_signed_type (gnu_in_basetype), gnu_in_lb);
5092 if (INTEGRAL_TYPE_P (gnu_in_basetype)
5093 && !TYPE_UNSIGNED (gnu_in_basetype))
5094 gnu_in_ub = convert (gnat_unsigned_type (gnu_in_basetype), gnu_in_ub);
5096 if (INTEGRAL_TYPE_P (gnu_base_type) && TYPE_UNSIGNED (gnu_base_type))
5097 gnu_out_lb = convert (gnat_signed_type (gnu_base_type), gnu_out_lb);
5099 if (INTEGRAL_TYPE_P (gnu_base_type) && !TYPE_UNSIGNED (gnu_base_type))
5100 gnu_out_ub = convert (gnat_unsigned_type (gnu_base_type), gnu_out_ub);
5102 /* Check each bound separately and only if the result bound
5103 is tighter than the bound on the input type. Note that all the
5104 types are base types, so the bounds must be constant. Also,
5105 the comparison is done in the base type of the input, which
5106 always has the proper signedness. First check for input
5107 integer (which means output integer), output float (which means
5108 both float), or mixed, in which case we always compare.
5109 Note that we have to do the comparison which would *fail* in the
5110 case of an error since if it's an FP comparison and one of the
5111 values is a NaN or Inf, the comparison will fail. */
5112 if (INTEGRAL_TYPE_P (gnu_in_basetype)
5113 ? tree_int_cst_lt (gnu_in_lb, gnu_out_lb)
5114 : (FLOAT_TYPE_P (gnu_base_type)
5115 ? REAL_VALUES_LESS (TREE_REAL_CST (gnu_in_lb),
5116 TREE_REAL_CST (gnu_out_lb))
5117 : 1))
5118 gnu_cond
5119 = invert_truthvalue
5120 (build_binary_op (GE_EXPR, integer_type_node,
5121 gnu_input, convert (gnu_in_basetype,
5122 gnu_out_lb)));
5124 if (INTEGRAL_TYPE_P (gnu_in_basetype)
5125 ? tree_int_cst_lt (gnu_out_ub, gnu_in_ub)
5126 : (FLOAT_TYPE_P (gnu_base_type)
5127 ? REAL_VALUES_LESS (TREE_REAL_CST (gnu_out_ub),
5128 TREE_REAL_CST (gnu_in_lb))
5129 : 1))
5130 gnu_cond
5131 = build_binary_op (TRUTH_ORIF_EXPR, integer_type_node, gnu_cond,
5132 invert_truthvalue
5133 (build_binary_op (LE_EXPR, integer_type_node,
5134 gnu_input,
5135 convert (gnu_in_basetype,
5136 gnu_out_ub))));
5138 if (! integer_zerop (gnu_cond))
5139 gnu_result = emit_check (gnu_cond, gnu_input,
5140 CE_Overflow_Check_Failed);
5143 /* Now convert to the result base type. If this is a non-truncating
5144 float-to-integer conversion, round. */
5145 if (INTEGRAL_TYPE_P (gnu_ada_base_type) && FLOAT_TYPE_P (gnu_in_basetype)
5146 && ! truncate_p)
5148 tree gnu_point_5 = build_real (gnu_in_basetype, dconstp5);
5149 tree gnu_minus_point_5 = build_real (gnu_in_basetype, dconstmp5);
5150 tree gnu_zero = convert (gnu_in_basetype, integer_zero_node);
5151 tree gnu_saved_result = save_expr (gnu_result);
5152 tree gnu_comp = build (GE_EXPR, integer_type_node,
5153 gnu_saved_result, gnu_zero);
5154 tree gnu_adjust = build (COND_EXPR, gnu_in_basetype, gnu_comp,
5155 gnu_point_5, gnu_minus_point_5);
5157 gnu_result
5158 = build (PLUS_EXPR, gnu_in_basetype, gnu_saved_result, gnu_adjust);
5161 if (TREE_CODE (gnu_ada_base_type) == INTEGER_TYPE
5162 && TYPE_HAS_ACTUAL_BOUNDS_P (gnu_ada_base_type)
5163 && TREE_CODE (gnu_result) == UNCONSTRAINED_ARRAY_REF)
5164 gnu_result = unchecked_convert (gnu_ada_base_type, gnu_result, 0);
5165 else
5166 gnu_result = convert (gnu_ada_base_type, gnu_result);
5168 /* Finally, do the range check if requested. Note that if the
5169 result type is a modular type, the range check is actually
5170 an overflow check. */
5172 if (range_p
5173 || (TREE_CODE (gnu_base_type) == INTEGER_TYPE
5174 && TYPE_MODULAR_P (gnu_base_type) && overflow_p))
5175 gnu_result = emit_range_check (gnu_result, gnat_type);
5177 return convert (gnu_type, gnu_result);
5180 /* Return 1 if GNU_EXPR can be directly addressed. This is the case unless
5181 it is an expression involving computation or if it involves a bitfield
5182 reference. This returns the same as gnat_mark_addressable in most
5183 cases. */
5185 static int
5186 addressable_p (tree gnu_expr)
5188 switch (TREE_CODE (gnu_expr))
5190 case VAR_DECL:
5191 case PARM_DECL:
5192 case FUNCTION_DECL:
5193 case RESULT_DECL:
5194 /* All DECLs are addressable: if they are in a register, we can force
5195 them to memory. */
5196 return 1;
5198 case UNCONSTRAINED_ARRAY_REF:
5199 case INDIRECT_REF:
5200 case CONSTRUCTOR:
5201 case NULL_EXPR:
5202 case SAVE_EXPR:
5203 return 1;
5205 case COMPONENT_REF:
5206 return (! DECL_BIT_FIELD (TREE_OPERAND (gnu_expr, 1))
5207 && (! DECL_NONADDRESSABLE_P (TREE_OPERAND (gnu_expr, 1))
5208 || ! flag_strict_aliasing)
5209 && addressable_p (TREE_OPERAND (gnu_expr, 0)));
5211 case ARRAY_REF: case ARRAY_RANGE_REF:
5212 case REALPART_EXPR: case IMAGPART_EXPR:
5213 case NOP_EXPR:
5214 return addressable_p (TREE_OPERAND (gnu_expr, 0));
5216 case CONVERT_EXPR:
5217 return (AGGREGATE_TYPE_P (TREE_TYPE (gnu_expr))
5218 && addressable_p (TREE_OPERAND (gnu_expr, 0)));
5220 case VIEW_CONVERT_EXPR:
5222 /* This is addressable if we can avoid a copy. */
5223 tree type = TREE_TYPE (gnu_expr);
5224 tree inner_type = TREE_TYPE (TREE_OPERAND (gnu_expr, 0));
5226 return (((TYPE_MODE (type) == TYPE_MODE (inner_type)
5227 && (TYPE_ALIGN (type) <= TYPE_ALIGN (inner_type)
5228 || TYPE_ALIGN (inner_type) >= BIGGEST_ALIGNMENT))
5229 || ((TYPE_MODE (type) == BLKmode
5230 || TYPE_MODE (inner_type) == BLKmode)
5231 && (TYPE_ALIGN (type) <= TYPE_ALIGN (inner_type)
5232 || TYPE_ALIGN (inner_type) >= BIGGEST_ALIGNMENT
5233 || TYPE_ALIGN_OK (type)
5234 || TYPE_ALIGN_OK (inner_type))))
5235 && addressable_p (TREE_OPERAND (gnu_expr, 0)));
5238 default:
5239 return 0;
5243 /* Do the processing for the declaration of a GNAT_ENTITY, a type. If
5244 a separate Freeze node exists, delay the bulk of the processing. Otherwise
5245 make a GCC type for GNAT_ENTITY and set up the correspondance. */
5247 void
5248 process_type (Entity_Id gnat_entity)
5250 tree gnu_old
5251 = present_gnu_tree (gnat_entity) ? get_gnu_tree (gnat_entity) : 0;
5252 tree gnu_new;
5254 /* If we are to delay elaboration of this type, just do any
5255 elaborations needed for expressions within the declaration and
5256 make a dummy type entry for this node and its Full_View (if
5257 any) in case something points to it. Don't do this if it
5258 has already been done (the only way that can happen is if
5259 the private completion is also delayed). */
5260 if (Present (Freeze_Node (gnat_entity))
5261 || (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
5262 && Present (Full_View (gnat_entity))
5263 && Freeze_Node (Full_View (gnat_entity))
5264 && ! present_gnu_tree (Full_View (gnat_entity))))
5266 elaborate_entity (gnat_entity);
5268 if (gnu_old == 0)
5270 tree gnu_decl = create_type_decl (get_entity_name (gnat_entity),
5271 make_dummy_type (gnat_entity),
5272 0, 0, 0);
5274 save_gnu_tree (gnat_entity, gnu_decl, 0);
5275 if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
5276 && Present (Full_View (gnat_entity)))
5277 save_gnu_tree (Full_View (gnat_entity), gnu_decl, 0);
5280 return;
5283 /* If we saved away a dummy type for this node it means that this
5284 made the type that corresponds to the full type of an incomplete
5285 type. Clear that type for now and then update the type in the
5286 pointers. */
5287 if (gnu_old != 0)
5289 if (TREE_CODE (gnu_old) != TYPE_DECL
5290 || ! TYPE_IS_DUMMY_P (TREE_TYPE (gnu_old)))
5292 /* If this was a withed access type, this is not an error
5293 and merely indicates we've already elaborated the type
5294 already. */
5295 if (Is_Type (gnat_entity) && From_With_Type (gnat_entity))
5296 return;
5298 gigi_abort (323);
5301 save_gnu_tree (gnat_entity, NULL_TREE, 0);
5304 /* Now fully elaborate the type. */
5305 start_block_stmt ();
5306 gnu_new = gnat_to_gnu_entity (gnat_entity, NULL_TREE, 1);
5307 if (TREE_CODE (gnu_new) != TYPE_DECL)
5308 gigi_abort (324);
5310 /* If we have an old type and we've made pointers to this type,
5311 update those pointers. */
5312 if (gnu_old != 0)
5313 update_pointer_to (TYPE_MAIN_VARIANT (TREE_TYPE (gnu_old)),
5314 TREE_TYPE (gnu_new));
5316 /* If this is a record type corresponding to a task or protected type
5317 that is a completion of an incomplete type, perform a similar update
5318 on the type. */
5319 /* ??? Including protected types here is a guess. */
5321 if (IN (Ekind (gnat_entity), Record_Kind)
5322 && Is_Concurrent_Record_Type (gnat_entity)
5323 && present_gnu_tree (Corresponding_Concurrent_Type (gnat_entity)))
5325 tree gnu_task_old
5326 = get_gnu_tree (Corresponding_Concurrent_Type (gnat_entity));
5328 save_gnu_tree (Corresponding_Concurrent_Type (gnat_entity),
5329 NULL_TREE, 0);
5330 save_gnu_tree (Corresponding_Concurrent_Type (gnat_entity),
5331 gnu_new, 0);
5333 update_pointer_to (TYPE_MAIN_VARIANT (TREE_TYPE (gnu_task_old)),
5334 TREE_TYPE (gnu_new));
5337 gnat_expand_stmt (end_block_stmt ());
5340 /* GNAT_ASSOC is the front of the Component_Associations of an N_Aggregate.
5341 GNU_TYPE is the GCC type of the corresponding record.
5343 Return a CONSTRUCTOR to build the record. */
5345 static tree
5346 assoc_to_constructor (Node_Id gnat_assoc, tree gnu_type)
5348 tree gnu_field, gnu_list, gnu_result;
5350 /* We test for GNU_FIELD being empty in the case where a variant
5351 was the last thing since we don't take things off GNAT_ASSOC in
5352 that case. We check GNAT_ASSOC in case we have a variant, but it
5353 has no fields. */
5355 for (gnu_list = NULL_TREE; Present (gnat_assoc);
5356 gnat_assoc = Next (gnat_assoc))
5358 Node_Id gnat_field = First (Choices (gnat_assoc));
5359 tree gnu_field = gnat_to_gnu_entity (Entity (gnat_field), NULL_TREE, 0);
5360 tree gnu_expr = gnat_to_gnu (Expression (gnat_assoc));
5362 /* The expander is supposed to put a single component selector name
5363 in every record component association */
5364 if (Next (gnat_field))
5365 gigi_abort (328);
5367 /* Before assigning a value in an aggregate make sure range checks
5368 are done if required. Then convert to the type of the field. */
5369 if (Do_Range_Check (Expression (gnat_assoc)))
5370 gnu_expr = emit_range_check (gnu_expr, Etype (gnat_field));
5372 gnu_expr = convert (TREE_TYPE (gnu_field), gnu_expr);
5374 /* Add the field and expression to the list. */
5375 gnu_list = tree_cons (gnu_field, gnu_expr, gnu_list);
5378 gnu_result = extract_values (gnu_list, gnu_type);
5380 /* Verify every enty in GNU_LIST was used. */
5381 for (gnu_field = gnu_list; gnu_field; gnu_field = TREE_CHAIN (gnu_field))
5382 if (! TREE_ADDRESSABLE (gnu_field))
5383 gigi_abort (311);
5385 return gnu_result;
5388 /* Builds a possibly nested constructor for array aggregates. GNAT_EXPR
5389 is the first element of an array aggregate. It may itself be an
5390 aggregate (an array or record aggregate). GNU_ARRAY_TYPE is the gnu type
5391 corresponding to the array aggregate. GNAT_COMPONENT_TYPE is the type
5392 of the array component. It is needed for range checking. */
5394 static tree
5395 pos_to_constructor (Node_Id gnat_expr,
5396 tree gnu_array_type,
5397 Entity_Id gnat_component_type)
5399 tree gnu_expr;
5400 tree gnu_expr_list = NULL_TREE;
5402 for ( ; Present (gnat_expr); gnat_expr = Next (gnat_expr))
5404 /* If the expression is itself an array aggregate then first build the
5405 innermost constructor if it is part of our array (multi-dimensional
5406 case). */
5408 if (Nkind (gnat_expr) == N_Aggregate
5409 && TREE_CODE (TREE_TYPE (gnu_array_type)) == ARRAY_TYPE
5410 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_array_type)))
5411 gnu_expr = pos_to_constructor (First (Expressions (gnat_expr)),
5412 TREE_TYPE (gnu_array_type),
5413 gnat_component_type);
5414 else
5416 gnu_expr = gnat_to_gnu (gnat_expr);
5418 /* before assigning the element to the array make sure it is
5419 in range */
5420 if (Do_Range_Check (gnat_expr))
5421 gnu_expr = emit_range_check (gnu_expr, gnat_component_type);
5424 gnu_expr_list
5425 = tree_cons (NULL_TREE, convert (TREE_TYPE (gnu_array_type), gnu_expr),
5426 gnu_expr_list);
5429 return gnat_build_constructor (gnu_array_type, nreverse (gnu_expr_list));
5432 /* Subroutine of assoc_to_constructor: VALUES is a list of field associations,
5433 some of which are from RECORD_TYPE. Return a CONSTRUCTOR consisting
5434 of the associations that are from RECORD_TYPE. If we see an internal
5435 record, make a recursive call to fill it in as well. */
5437 static tree
5438 extract_values (tree values, tree record_type)
5440 tree result = NULL_TREE;
5441 tree field, tem;
5443 for (field = TYPE_FIELDS (record_type); field; field = TREE_CHAIN (field))
5445 tree value = 0;
5447 /* _Parent is an internal field, but may have values in the aggregate,
5448 so check for values first. */
5449 if ((tem = purpose_member (field, values)) != 0)
5451 value = TREE_VALUE (tem);
5452 TREE_ADDRESSABLE (tem) = 1;
5455 else if (DECL_INTERNAL_P (field))
5457 value = extract_values (values, TREE_TYPE (field));
5458 if (TREE_CODE (value) == CONSTRUCTOR
5459 && CONSTRUCTOR_ELTS (value) == 0)
5460 value = 0;
5462 else
5463 /* If we have a record subtype, the names will match, but not the
5464 actual FIELD_DECLs. */
5465 for (tem = values; tem; tem = TREE_CHAIN (tem))
5466 if (DECL_NAME (TREE_PURPOSE (tem)) == DECL_NAME (field))
5468 value = convert (TREE_TYPE (field), TREE_VALUE (tem));
5469 TREE_ADDRESSABLE (tem) = 1;
5472 if (value == 0)
5473 continue;
5475 result = tree_cons (field, value, result);
5478 return gnat_build_constructor (record_type, nreverse (result));
5481 /* EXP is to be treated as an array or record. Handle the cases when it is
5482 an access object and perform the required dereferences. */
5484 static tree
5485 maybe_implicit_deref (tree exp)
5487 /* If the type is a pointer, dereference it. */
5489 if (POINTER_TYPE_P (TREE_TYPE (exp)) || TYPE_FAT_POINTER_P (TREE_TYPE (exp)))
5490 exp = build_unary_op (INDIRECT_REF, NULL_TREE, exp);
5492 /* If we got a padded type, remove it too. */
5493 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
5494 && TYPE_IS_PADDING_P (TREE_TYPE (exp)))
5495 exp = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (exp))), exp);
5497 return exp;
5500 /* Protect EXP from multiple evaluation. This may make a SAVE_EXPR. */
5502 tree
5503 protect_multiple_eval (tree exp)
5505 tree type = TREE_TYPE (exp);
5507 /* If this has no side effects, we don't need to do anything. */
5508 if (! TREE_SIDE_EFFECTS (exp))
5509 return exp;
5511 /* If it is a conversion, protect what's inside the conversion.
5512 Similarly, if we're indirectly referencing something, we only
5513 actually need to protect the address since the data itself can't
5514 change in these situations. */
5515 else if (TREE_CODE (exp) == NON_LVALUE_EXPR
5516 || TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
5517 || TREE_CODE (exp) == VIEW_CONVERT_EXPR
5518 || TREE_CODE (exp) == INDIRECT_REF
5519 || TREE_CODE (exp) == UNCONSTRAINED_ARRAY_REF)
5520 return build1 (TREE_CODE (exp), type,
5521 protect_multiple_eval (TREE_OPERAND (exp, 0)));
5523 /* If EXP is a fat pointer or something that can be placed into a register,
5524 just make a SAVE_EXPR. */
5525 if (TYPE_FAT_POINTER_P (type) || TYPE_MODE (type) != BLKmode)
5526 return save_expr (exp);
5528 /* Otherwise, dereference, protect the address, and re-reference. */
5529 else
5530 return
5531 build_unary_op (INDIRECT_REF, type,
5532 save_expr (build_unary_op (ADDR_EXPR,
5533 build_reference_type (type),
5534 exp)));
5537 /* This is equivalent to stabilize_reference in GCC's tree.c, but we know
5538 how to handle our new nodes and we take an extra argument that says
5539 whether to force evaluation of everything. */
5541 tree
5542 gnat_stabilize_reference (tree ref, int force)
5544 tree type = TREE_TYPE (ref);
5545 enum tree_code code = TREE_CODE (ref);
5546 tree result;
5548 switch (code)
5550 case VAR_DECL:
5551 case PARM_DECL:
5552 case RESULT_DECL:
5553 /* No action is needed in this case. */
5554 return ref;
5556 case NOP_EXPR:
5557 case CONVERT_EXPR:
5558 case FLOAT_EXPR:
5559 case FIX_TRUNC_EXPR:
5560 case FIX_FLOOR_EXPR:
5561 case FIX_ROUND_EXPR:
5562 case FIX_CEIL_EXPR:
5563 case VIEW_CONVERT_EXPR:
5564 case ADDR_EXPR:
5565 result
5566 = build1 (code, type,
5567 gnat_stabilize_reference (TREE_OPERAND (ref, 0), force));
5568 break;
5570 case INDIRECT_REF:
5571 case UNCONSTRAINED_ARRAY_REF:
5572 result = build1 (code, type,
5573 gnat_stabilize_reference_1 (TREE_OPERAND (ref, 0),
5574 force));
5575 break;
5577 case COMPONENT_REF:
5578 result = build (COMPONENT_REF, type,
5579 gnat_stabilize_reference (TREE_OPERAND (ref, 0),
5580 force),
5581 TREE_OPERAND (ref, 1));
5582 break;
5584 case BIT_FIELD_REF:
5585 result = build (BIT_FIELD_REF, type,
5586 gnat_stabilize_reference (TREE_OPERAND (ref, 0), force),
5587 gnat_stabilize_reference_1 (TREE_OPERAND (ref, 1),
5588 force),
5589 gnat_stabilize_reference_1 (TREE_OPERAND (ref, 2),
5590 force));
5591 break;
5593 case ARRAY_REF:
5594 result = build (ARRAY_REF, type,
5595 gnat_stabilize_reference (TREE_OPERAND (ref, 0), force),
5596 gnat_stabilize_reference_1 (TREE_OPERAND (ref, 1),
5597 force));
5598 break;
5600 case ARRAY_RANGE_REF:
5601 result = build (ARRAY_RANGE_REF, type,
5602 gnat_stabilize_reference (TREE_OPERAND (ref, 0), force),
5603 gnat_stabilize_reference_1 (TREE_OPERAND (ref, 1),
5604 force));
5605 break;
5607 case COMPOUND_EXPR:
5608 result = build (COMPOUND_EXPR, type,
5609 gnat_stabilize_reference_1 (TREE_OPERAND (ref, 0),
5610 force),
5611 gnat_stabilize_reference (TREE_OPERAND (ref, 1),
5612 force));
5613 break;
5615 case RTL_EXPR:
5616 result = build1 (INDIRECT_REF, type,
5617 save_expr (build1 (ADDR_EXPR,
5618 build_reference_type (type), ref)));
5619 break;
5621 /* If arg isn't a kind of lvalue we recognize, make no change.
5622 Caller should recognize the error for an invalid lvalue. */
5623 default:
5624 return ref;
5626 case ERROR_MARK:
5627 return error_mark_node;
5630 TREE_READONLY (result) = TREE_READONLY (ref);
5631 return result;
5634 /* Similar to stabilize_reference_1 in tree.c, but supports an extra
5635 arg to force a SAVE_EXPR for everything. */
5637 static tree
5638 gnat_stabilize_reference_1 (tree e, int force)
5640 enum tree_code code = TREE_CODE (e);
5641 tree type = TREE_TYPE (e);
5642 tree result;
5644 /* We cannot ignore const expressions because it might be a reference
5645 to a const array but whose index contains side-effects. But we can
5646 ignore things that are actual constant or that already have been
5647 handled by this function. */
5649 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
5650 return e;
5652 switch (TREE_CODE_CLASS (code))
5654 case 'x':
5655 case 't':
5656 case 'd':
5657 case '<':
5658 case 's':
5659 case 'e':
5660 case 'r':
5661 if (TREE_SIDE_EFFECTS (e) || force)
5662 return save_expr (e);
5663 return e;
5665 case 'c':
5666 /* Constants need no processing. In fact, we should never reach
5667 here. */
5668 return e;
5670 case '2':
5671 /* Recursively stabilize each operand. */
5672 result = build (code, type,
5673 gnat_stabilize_reference_1 (TREE_OPERAND (e, 0), force),
5674 gnat_stabilize_reference_1 (TREE_OPERAND (e, 1), force));
5675 break;
5677 case '1':
5678 /* Recursively stabilize each operand. */
5679 result = build1 (code, type,
5680 gnat_stabilize_reference_1 (TREE_OPERAND (e, 0),
5681 force));
5682 break;
5684 default:
5685 abort ();
5688 TREE_READONLY (result) = TREE_READONLY (e);
5689 return result;
5692 /* GNAT_UNIT is the Defining_Identifier for some package or subprogram,
5693 either a spec or a body, BODY_P says which. If needed, make a function
5694 to be the elaboration routine for that object and perform the elaborations
5695 in GNU_ELAB_LIST.
5697 Return 1 if we didn't need an elaboration function, zero otherwise. */
5699 static int
5700 build_unit_elab (Entity_Id gnat_unit, int body_p, tree gnu_elab_list)
5702 tree gnu_decl;
5703 rtx insn;
5704 int result = 1;
5706 /* If we have nothing to do, return. */
5707 if (gnu_elab_list == 0)
5708 return 1;
5710 /* Prevent the elaboration list from being reclaimed by the GC. */
5711 gnu_pending_elaboration_lists = chainon (gnu_pending_elaboration_lists,
5712 gnu_elab_list);
5714 /* Set our file and line number to that of the object and set up the
5715 elaboration routine. */
5716 gnu_decl = create_subprog_decl (create_concat_name (gnat_unit,
5717 body_p ?
5718 "elabb" : "elabs"),
5719 NULL_TREE, void_ftype, NULL_TREE, 0, 1, 0,
5721 DECL_ELABORATION_PROC_P (gnu_decl) = 1;
5723 begin_subprog_body (gnu_decl);
5724 set_lineno (gnat_unit, 1);
5725 gnat_pushlevel ();
5726 gnu_block_stack = tree_cons (NULL_TREE, NULL_TREE, gnu_block_stack);
5727 expand_start_bindings (0);
5729 /* Emit the assignments for the elaborations we have to do. If there
5730 is no destination, this is just a call to execute some statement
5731 that was placed within the declarative region. But first save a
5732 pointer so we can see if any insns were generated. */
5734 insn = get_last_insn ();
5736 for (; gnu_elab_list; gnu_elab_list = TREE_CHAIN (gnu_elab_list))
5737 if (TREE_PURPOSE (gnu_elab_list) == NULL_TREE)
5739 if (TREE_VALUE (gnu_elab_list) != 0)
5740 expand_expr_stmt (TREE_VALUE (gnu_elab_list));
5742 else
5744 tree lhs = TREE_PURPOSE (gnu_elab_list);
5746 input_location = DECL_SOURCE_LOCATION (lhs);
5748 /* If LHS has a padded type, convert it to the unpadded type
5749 so the assignment is done properly. */
5750 if (TREE_CODE (TREE_TYPE (lhs)) == RECORD_TYPE
5751 && TYPE_IS_PADDING_P (TREE_TYPE (lhs)))
5752 lhs = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (lhs))), lhs);
5754 emit_line_note (input_location);
5755 expand_expr_stmt (build_binary_op (MODIFY_EXPR, NULL_TREE,
5756 TREE_PURPOSE (gnu_elab_list),
5757 TREE_VALUE (gnu_elab_list)));
5760 /* See if any non-NOTE insns were generated. */
5761 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
5762 if (GET_RTX_CLASS (GET_CODE (insn)) == RTX_INSN)
5764 result = 0;
5765 break;
5768 expand_end_bindings (NULL_TREE, block_has_vars (), -1);
5769 gnat_poplevel ();
5770 gnu_block_stack = TREE_CHAIN (gnu_block_stack);
5771 end_subprog_body ();
5773 /* We are finished with the elaboration list it can now be discarded. */
5774 gnu_pending_elaboration_lists = TREE_CHAIN (gnu_pending_elaboration_lists);
5776 /* If there were no insns, we don't need an elab routine. It would
5777 be nice to not output this one, but there's no good way to do that. */
5778 return result;
5781 extern char *__gnat_to_canonical_file_spec (char *);
5783 /* Determine the input_filename and the input_line from the source location
5784 (Sloc) of GNAT_NODE node. Set the global variable input_filename and
5785 input_line. If WRITE_NOTE_P is true, emit a line number note. */
5787 void
5788 set_lineno (Node_Id gnat_node, int write_note_p)
5790 Source_Ptr source_location = Sloc (gnat_node);
5792 set_lineno_from_sloc (source_location, write_note_p);
5795 /* Likewise, but passed a Sloc. */
5797 void
5798 set_lineno_from_sloc (Source_Ptr source_location, int write_note_p)
5800 /* If node not from source code, ignore. */
5801 if (source_location < 0)
5802 return;
5804 /* Use the identifier table to make a hashed, permanent copy of the filename,
5805 since the name table gets reallocated after Gigi returns but before all
5806 the debugging information is output. The __gnat_to_canonical_file_spec
5807 call translates filenames from pragmas Source_Reference that contain host
5808 style syntax not understood by gdb. */
5809 input_filename
5810 = IDENTIFIER_POINTER
5811 (get_identifier
5812 (__gnat_to_canonical_file_spec
5813 (Get_Name_String
5814 (Full_Debug_Name (Get_Source_File_Index (source_location))))));
5816 /* ref_filename is the reference file name as given by sinput (i.e no
5817 directory) */
5818 ref_filename
5819 = IDENTIFIER_POINTER
5820 (get_identifier
5821 (Get_Name_String
5822 (Debug_Source_Name (Get_Source_File_Index (source_location)))));;
5823 input_line = Get_Logical_Line_Number (source_location);
5825 if (! global_bindings_p () && write_note_p)
5826 emit_line_note (input_location);
5829 /* Post an error message. MSG is the error message, properly annotated.
5830 NODE is the node at which to post the error and the node to use for the
5831 "&" substitution. */
5833 void
5834 post_error (const char *msg, Node_Id node)
5836 String_Template temp;
5837 Fat_Pointer fp;
5839 temp.Low_Bound = 1, temp.High_Bound = strlen (msg);
5840 fp.Array = msg, fp.Bounds = &temp;
5841 if (Present (node))
5842 Error_Msg_N (fp, node);
5845 /* Similar, but NODE is the node at which to post the error and ENT
5846 is the node to use for the "&" substitution. */
5848 void
5849 post_error_ne (const char *msg, Node_Id node, Entity_Id ent)
5851 String_Template temp;
5852 Fat_Pointer fp;
5854 temp.Low_Bound = 1, temp.High_Bound = strlen (msg);
5855 fp.Array = msg, fp.Bounds = &temp;
5856 if (Present (node))
5857 Error_Msg_NE (fp, node, ent);
5860 /* Similar, but NODE is the node at which to post the error, ENT is the node
5861 to use for the "&" substitution, and N is the number to use for the ^. */
5863 void
5864 post_error_ne_num (const char *msg, Node_Id node, Entity_Id ent, int n)
5866 String_Template temp;
5867 Fat_Pointer fp;
5869 temp.Low_Bound = 1, temp.High_Bound = strlen (msg);
5870 fp.Array = msg, fp.Bounds = &temp;
5871 Error_Msg_Uint_1 = UI_From_Int (n);
5873 if (Present (node))
5874 Error_Msg_NE (fp, node, ent);
5877 /* Similar to post_error_ne_num, but T is a GCC tree representing the
5878 number to write. If the tree represents a constant that fits within
5879 a host integer, the text inside curly brackets in MSG will be output
5880 (presumably including a '^'). Otherwise that text will not be output
5881 and the text inside square brackets will be output instead. */
5883 void
5884 post_error_ne_tree (const char *msg, Node_Id node, Entity_Id ent, tree t)
5886 char *newmsg = alloca (strlen (msg) + 1);
5887 String_Template temp = {1, 0};
5888 Fat_Pointer fp;
5889 char start_yes, end_yes, start_no, end_no;
5890 const char *p;
5891 char *q;
5893 fp.Array = newmsg, fp.Bounds = &temp;
5895 if (host_integerp (t, 1)
5896 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_INT
5898 compare_tree_int
5899 (t, (((unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_INT - 1)) - 1)) < 0
5900 #endif
5903 Error_Msg_Uint_1 = UI_From_Int (tree_low_cst (t, 1));
5904 start_yes = '{', end_yes = '}', start_no = '[', end_no = ']';
5906 else
5907 start_yes = '[', end_yes = ']', start_no = '{', end_no = '}';
5909 for (p = msg, q = newmsg; *p != 0; p++)
5911 if (*p == start_yes)
5912 for (p++; *p != end_yes; p++)
5913 *q++ = *p;
5914 else if (*p == start_no)
5915 for (p++; *p != end_no; p++)
5917 else
5918 *q++ = *p;
5921 *q = 0;
5923 temp.High_Bound = strlen (newmsg);
5924 if (Present (node))
5925 Error_Msg_NE (fp, node, ent);
5928 /* Similar to post_error_ne_tree, except that NUM is a second
5929 integer to write in the message. */
5931 void
5932 post_error_ne_tree_2 (const char *msg,
5933 Node_Id node,
5934 Entity_Id ent,
5935 tree t,
5936 int num)
5938 Error_Msg_Uint_2 = UI_From_Int (num);
5939 post_error_ne_tree (msg, node, ent, t);
5942 /* Set the node for a second '&' in the error message. */
5944 void
5945 set_second_error_entity (Entity_Id e)
5947 Error_Msg_Node_2 = e;
5950 /* Signal abort, with "Gigi abort" as the error label, and error_gnat_node
5951 as the relevant node that provides the location info for the error */
5953 void
5954 gigi_abort (int code)
5956 String_Template temp = {1, 10};
5957 Fat_Pointer fp;
5959 fp.Array = "Gigi abort", fp.Bounds = &temp;
5961 Current_Error_Node = error_gnat_node;
5962 Compiler_Abort (fp, code);
5965 /* Initialize the table that maps GNAT codes to GCC codes for simple
5966 binary and unary operations. */
5968 void
5969 init_code_table (void)
5971 gnu_codes[N_And_Then] = TRUTH_ANDIF_EXPR;
5972 gnu_codes[N_Or_Else] = TRUTH_ORIF_EXPR;
5974 gnu_codes[N_Op_And] = TRUTH_AND_EXPR;
5975 gnu_codes[N_Op_Or] = TRUTH_OR_EXPR;
5976 gnu_codes[N_Op_Xor] = TRUTH_XOR_EXPR;
5977 gnu_codes[N_Op_Eq] = EQ_EXPR;
5978 gnu_codes[N_Op_Ne] = NE_EXPR;
5979 gnu_codes[N_Op_Lt] = LT_EXPR;
5980 gnu_codes[N_Op_Le] = LE_EXPR;
5981 gnu_codes[N_Op_Gt] = GT_EXPR;
5982 gnu_codes[N_Op_Ge] = GE_EXPR;
5983 gnu_codes[N_Op_Add] = PLUS_EXPR;
5984 gnu_codes[N_Op_Subtract] = MINUS_EXPR;
5985 gnu_codes[N_Op_Multiply] = MULT_EXPR;
5986 gnu_codes[N_Op_Mod] = FLOOR_MOD_EXPR;
5987 gnu_codes[N_Op_Rem] = TRUNC_MOD_EXPR;
5988 gnu_codes[N_Op_Minus] = NEGATE_EXPR;
5989 gnu_codes[N_Op_Abs] = ABS_EXPR;
5990 gnu_codes[N_Op_Not] = TRUTH_NOT_EXPR;
5991 gnu_codes[N_Op_Rotate_Left] = LROTATE_EXPR;
5992 gnu_codes[N_Op_Rotate_Right] = RROTATE_EXPR;
5993 gnu_codes[N_Op_Shift_Left] = LSHIFT_EXPR;
5994 gnu_codes[N_Op_Shift_Right] = RSHIFT_EXPR;
5995 gnu_codes[N_Op_Shift_Right_Arithmetic] = RSHIFT_EXPR;
5998 #include "gt-ada-trans.h"