Mercurial > hg > CbC > CbC_gcc
comparison gcc/ada/exp_ch4.adb @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
4 -- -- | 4 -- -- |
5 -- E X P _ C H 4 -- | 5 -- E X P _ C H 4 -- |
6 -- -- | 6 -- -- |
7 -- B o d y -- | 7 -- B o d y -- |
8 -- -- | 8 -- -- |
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- | 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- |
10 -- -- | 10 -- -- |
11 -- GNAT is free software; you can redistribute it and/or modify it under -- | 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- -- | 12 -- terms of the GNU General Public License as published by the Free Soft- -- |
13 -- ware Foundation; either version 3, or (at your option) any later ver- -- | 13 -- ware Foundation; either version 3, or (at your option) any later ver- -- |
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- | 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
628 | 628 |
629 -- Finalize the object if applicable. Generate: | 629 -- Finalize the object if applicable. Generate: |
630 | 630 |
631 -- [Deep_]Finalize (Obj_Ref.all); | 631 -- [Deep_]Finalize (Obj_Ref.all); |
632 | 632 |
633 if Needs_Finalization (DesigT) then | 633 if Needs_Finalization (DesigT) |
634 and then not No_Heap_Finalization (PtrT) | |
635 then | |
634 Fin_Call := | 636 Fin_Call := |
635 Make_Final_Call | 637 Make_Final_Call |
636 (Obj_Ref => | 638 (Obj_Ref => |
637 Make_Explicit_Dereference (Loc, New_Copy (Obj_Ref)), | 639 Make_Explicit_Dereference (Loc, New_Copy (Obj_Ref)), |
638 Typ => DesigT); | 640 Typ => DesigT); |
2331 Rhs : Node_Id; | 2333 Rhs : Node_Id; |
2332 Bodies : List_Id) return Node_Id | 2334 Bodies : List_Id) return Node_Id |
2333 is | 2335 is |
2334 Loc : constant Source_Ptr := Sloc (Nod); | 2336 Loc : constant Source_Ptr := Sloc (Nod); |
2335 Full_Type : Entity_Id; | 2337 Full_Type : Entity_Id; |
2336 Prim : Elmt_Id; | |
2337 Eq_Op : Entity_Id; | 2338 Eq_Op : Entity_Id; |
2338 | 2339 |
2339 function Find_Primitive_Eq return Node_Id; | 2340 function Find_Primitive_Eq return Node_Id; |
2340 -- AI05-0123: Locate primitive equality for type if it exists, and | 2341 -- AI05-0123: Locate primitive equality for type if it exists, and |
2341 -- build the corresponding call. If operation is abstract, replace | 2342 -- build the corresponding call. If operation is abstract, replace |
2424 then | 2425 then |
2425 return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs); | 2426 return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs); |
2426 | 2427 |
2427 -- For composite component types, and floating-point types, use the | 2428 -- For composite component types, and floating-point types, use the |
2428 -- expansion. This deals with tagged component types (where we use | 2429 -- expansion. This deals with tagged component types (where we use |
2429 -- the applicable equality routine) and floating-point, (where we | 2430 -- the applicable equality routine) and floating-point (where we |
2430 -- need to worry about negative zeroes), and also the case of any | 2431 -- need to worry about negative zeroes), and also the case of any |
2431 -- composite type recursively containing such fields. | 2432 -- composite type recursively containing such fields. |
2432 | 2433 |
2433 else | 2434 else |
2434 return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Full_Type); | 2435 declare |
2436 Comp_Typ : Entity_Id; | |
2437 Hi : Node_Id; | |
2438 Indx : Node_Id; | |
2439 Ityp : Entity_Id; | |
2440 Lo : Node_Id; | |
2441 | |
2442 begin | |
2443 -- Do the comparison in the type (or its full view) and not in | |
2444 -- its unconstrained base type, because the latter operation is | |
2445 -- more complex and would also require an unchecked conversion. | |
2446 | |
2447 if Is_Private_Type (Typ) then | |
2448 Comp_Typ := Underlying_Type (Typ); | |
2449 else | |
2450 Comp_Typ := Typ; | |
2451 end if; | |
2452 | |
2453 -- Except for the case where the bounds of the type depend on a | |
2454 -- discriminant, or else we would run into scoping issues. | |
2455 | |
2456 Indx := First_Index (Comp_Typ); | |
2457 while Present (Indx) loop | |
2458 Ityp := Etype (Indx); | |
2459 | |
2460 Lo := Type_Low_Bound (Ityp); | |
2461 Hi := Type_High_Bound (Ityp); | |
2462 | |
2463 if (Nkind (Lo) = N_Identifier | |
2464 and then Ekind (Entity (Lo)) = E_Discriminant) | |
2465 or else | |
2466 (Nkind (Hi) = N_Identifier | |
2467 and then Ekind (Entity (Hi)) = E_Discriminant) | |
2468 then | |
2469 Comp_Typ := Full_Type; | |
2470 exit; | |
2471 end if; | |
2472 | |
2473 Next_Index (Indx); | |
2474 end loop; | |
2475 | |
2476 return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Comp_Typ); | |
2477 end; | |
2435 end if; | 2478 end if; |
2436 | 2479 |
2437 -- Case of tagged record types | 2480 -- Case of tagged record types |
2438 | 2481 |
2439 elsif Is_Tagged_Type (Full_Type) then | 2482 elsif Is_Tagged_Type (Full_Type) then |
2440 | 2483 Eq_Op := Find_Primitive_Eq (Typ); |
2441 -- Call the primitive operation "=" of this type | 2484 pragma Assert (Present (Eq_Op)); |
2442 | |
2443 if Is_Class_Wide_Type (Full_Type) then | |
2444 Full_Type := Root_Type (Full_Type); | |
2445 end if; | |
2446 | |
2447 -- If this is derived from an untagged private type completed with a | |
2448 -- tagged type, it does not have a full view, so we use the primitive | |
2449 -- operations of the private type. This check should no longer be | |
2450 -- necessary when these types receive their full views ??? | |
2451 | |
2452 if Is_Private_Type (Typ) | |
2453 and then not Is_Tagged_Type (Typ) | |
2454 and then not Is_Controlled (Typ) | |
2455 and then Is_Derived_Type (Typ) | |
2456 and then No (Full_View (Typ)) | |
2457 then | |
2458 Prim := First_Elmt (Collect_Primitive_Operations (Typ)); | |
2459 else | |
2460 Prim := First_Elmt (Primitive_Operations (Full_Type)); | |
2461 end if; | |
2462 | |
2463 loop | |
2464 Eq_Op := Node (Prim); | |
2465 exit when Chars (Eq_Op) = Name_Op_Eq | |
2466 and then Etype (First_Formal (Eq_Op)) = | |
2467 Etype (Next_Formal (First_Formal (Eq_Op))) | |
2468 and then Base_Type (Etype (Eq_Op)) = Standard_Boolean; | |
2469 Next_Elmt (Prim); | |
2470 pragma Assert (Present (Prim)); | |
2471 end loop; | |
2472 | |
2473 Eq_Op := Node (Prim); | |
2474 | 2485 |
2475 return | 2486 return |
2476 Make_Function_Call (Loc, | 2487 Make_Function_Call (Loc, |
2477 Name => New_Occurrence_Of (Eq_Op, Loc), | 2488 Name => New_Occurrence_Of (Eq_Op, Loc), |
2478 Parameter_Associations => | 2489 Parameter_Associations => |
2762 -- A tree node representing the high bound of the last operand. This | 2773 -- A tree node representing the high bound of the last operand. This |
2763 -- need only be set if the result could be null. It is used for the | 2774 -- need only be set if the result could be null. It is used for the |
2764 -- special case of setting the right high bound for a null result. | 2775 -- special case of setting the right high bound for a null result. |
2765 -- This is of type Ityp. | 2776 -- This is of type Ityp. |
2766 | 2777 |
2767 High_Bound : Node_Id; | 2778 High_Bound : Node_Id := Empty; |
2768 -- A tree node representing the high bound of the result (of type Ityp) | 2779 -- A tree node representing the high bound of the result (of type Ityp) |
2769 | 2780 |
2770 Result : Node_Id; | 2781 Result : Node_Id; |
2771 -- Result of the concatenation (of type Ityp) | 2782 -- Result of the concatenation (of type Ityp) |
2772 | 2783 |
4015 Cond_Expr : constant Node_Id := New_Op_Node (N_Op_Lt, Loc); | 4026 Cond_Expr : constant Node_Id := New_Op_Node (N_Op_Lt, Loc); |
4016 Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc); | 4027 Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc); |
4017 Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract, | 4028 Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract, |
4018 Loc); | 4029 Loc); |
4019 begin | 4030 begin |
4031 -- To prevent spurious visibility issues, convert all | |
4032 -- operands to Standard.Unsigned. | |
4033 | |
4020 Set_Left_Opnd (Cond_Expr, | 4034 Set_Left_Opnd (Cond_Expr, |
4021 New_Copy_Tree (Left_Opnd (N))); | 4035 Unchecked_Convert_To (Standard_Unsigned, |
4036 New_Copy_Tree (Left_Opnd (N)))); | |
4022 Set_Right_Opnd (Cond_Expr, | 4037 Set_Right_Opnd (Cond_Expr, |
4023 Make_Integer_Literal (Loc, Mod_Minus_Right)); | 4038 Make_Integer_Literal (Loc, Mod_Minus_Right)); |
4024 Append_To (Exprs, Cond_Expr); | 4039 Append_To (Exprs, Cond_Expr); |
4025 | 4040 |
4026 Set_Left_Opnd (Then_Expr, | 4041 Set_Left_Opnd (Then_Expr, |
4050 | 4065 |
4051 procedure Expand_Modular_Op is | 4066 procedure Expand_Modular_Op is |
4052 Op_Expr : constant Node_Id := New_Op_Node (Nkind (N), Loc); | 4067 Op_Expr : constant Node_Id := New_Op_Node (Nkind (N), Loc); |
4053 Mod_Expr : constant Node_Id := New_Op_Node (N_Op_Mod, Loc); | 4068 Mod_Expr : constant Node_Id := New_Op_Node (N_Op_Mod, Loc); |
4054 | 4069 |
4070 Target_Type : Entity_Id; | |
4071 | |
4055 begin | 4072 begin |
4056 -- Convert nonbinary modular type operands into integer values. Thus | 4073 -- Convert nonbinary modular type operands into integer values. Thus |
4057 -- we avoid never-ending loops expanding them, and we also ensure | 4074 -- we avoid never-ending loops expanding them, and we also ensure |
4058 -- the back end never receives nonbinary modular type expressions. | 4075 -- the back end never receives nonbinary modular type expressions. |
4059 | 4076 |
4060 if Nkind_In (Nkind (N), N_Op_And, N_Op_Or) then | 4077 if Nkind_In (Nkind (N), N_Op_And, N_Op_Or, N_Op_Xor) then |
4061 Set_Left_Opnd (Op_Expr, | 4078 Set_Left_Opnd (Op_Expr, |
4062 Unchecked_Convert_To (Standard_Unsigned, | 4079 Unchecked_Convert_To (Standard_Unsigned, |
4063 New_Copy_Tree (Left_Opnd (N)))); | 4080 New_Copy_Tree (Left_Opnd (N)))); |
4064 Set_Right_Opnd (Op_Expr, | 4081 Set_Right_Opnd (Op_Expr, |
4065 Unchecked_Convert_To (Standard_Unsigned, | 4082 Unchecked_Convert_To (Standard_Unsigned, |
4066 New_Copy_Tree (Right_Opnd (N)))); | 4083 New_Copy_Tree (Right_Opnd (N)))); |
4067 Set_Left_Opnd (Mod_Expr, | 4084 Set_Left_Opnd (Mod_Expr, |
4068 Unchecked_Convert_To (Standard_Integer, Op_Expr)); | 4085 Unchecked_Convert_To (Standard_Integer, Op_Expr)); |
4069 | 4086 |
4070 else | 4087 else |
4088 -- If the modulus of the type is larger than Integer'Last | |
4089 -- use a larger type for the operands, to prevent spurious | |
4090 -- constraint errors on large legal literals of the type. | |
4091 | |
4092 if Modulus (Etype (N)) > UI_From_Int (Int (Integer'Last)) then | |
4093 Target_Type := Standard_Long_Integer; | |
4094 else | |
4095 Target_Type := Standard_Integer; | |
4096 end if; | |
4097 | |
4071 Set_Left_Opnd (Op_Expr, | 4098 Set_Left_Opnd (Op_Expr, |
4072 Unchecked_Convert_To (Standard_Integer, | 4099 Unchecked_Convert_To (Target_Type, |
4073 New_Copy_Tree (Left_Opnd (N)))); | 4100 New_Copy_Tree (Left_Opnd (N)))); |
4074 Set_Right_Opnd (Op_Expr, | 4101 Set_Right_Opnd (Op_Expr, |
4075 Unchecked_Convert_To (Standard_Integer, | 4102 Unchecked_Convert_To (Target_Type, |
4076 New_Copy_Tree (Right_Opnd (N)))); | 4103 New_Copy_Tree (Right_Opnd (N)))); |
4077 | 4104 |
4078 -- Link this node to the tree to analyze it | 4105 -- Link this node to the tree to analyze it |
4079 | 4106 |
4080 -- If the parent node is an expression with actions we link it to | 4107 -- If the parent node is an expression with actions we link it to |
4138 Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc); | 4165 Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc); |
4139 Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract, | 4166 Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract, |
4140 Loc); | 4167 Loc); |
4141 begin | 4168 begin |
4142 Set_Left_Opnd (Cond_Expr, | 4169 Set_Left_Opnd (Cond_Expr, |
4143 New_Copy_Tree (Left_Opnd (N))); | 4170 Unchecked_Convert_To (Standard_Unsigned, |
4171 New_Copy_Tree (Left_Opnd (N)))); | |
4144 Set_Right_Opnd (Cond_Expr, | 4172 Set_Right_Opnd (Cond_Expr, |
4145 Make_Integer_Literal (Loc, Intval (Right_Opnd (N)))); | 4173 Make_Integer_Literal (Loc, Intval (Right_Opnd (N)))); |
4146 Append_To (Exprs, Cond_Expr); | 4174 Append_To (Exprs, Cond_Expr); |
4147 | 4175 |
4148 Set_Left_Opnd (Then_Expr, | 4176 Set_Left_Opnd (Then_Expr, |
4168 end Expand_Modular_Subtraction; | 4196 end Expand_Modular_Subtraction; |
4169 | 4197 |
4170 -- Start of processing for Expand_Nonbinary_Modular_Op | 4198 -- Start of processing for Expand_Nonbinary_Modular_Op |
4171 | 4199 |
4172 begin | 4200 begin |
4173 -- No action needed if we are not generating C code for a nonbinary | 4201 -- No action needed if front-end expansion is not required or if we |
4174 -- modular operand. | 4202 -- have a binary modular operand. |
4175 | 4203 |
4176 if not Modify_Tree_For_C | 4204 if not Expand_Nonbinary_Modular_Ops |
4177 or else not Non_Binary_Modulus (Typ) | 4205 or else not Non_Binary_Modulus (Typ) |
4178 then | 4206 then |
4179 return; | 4207 return; |
4180 end if; | 4208 end if; |
4181 | 4209 |
4399 | 4427 |
4400 if Present (Pool) then | 4428 if Present (Pool) then |
4401 Set_Storage_Pool (N, Pool); | 4429 Set_Storage_Pool (N, Pool); |
4402 | 4430 |
4403 if Is_RTE (Pool, RE_SS_Pool) then | 4431 if Is_RTE (Pool, RE_SS_Pool) then |
4432 Check_Restriction (No_Secondary_Stack, N); | |
4404 Set_Procedure_To_Call (N, RTE (RE_SS_Allocate)); | 4433 Set_Procedure_To_Call (N, RTE (RE_SS_Allocate)); |
4405 | 4434 |
4406 -- In the case of an allocator for a simple storage pool, locate | 4435 -- In the case of an allocator for a simple storage pool, locate |
4407 -- and save a reference to the pool type's Allocate routine. | 4436 -- and save a reference to the pool type's Allocate routine. |
4408 | 4437 |
4543 Make_Integer_Literal (Loc, Uint_7 * (Uint_2 ** 29))), | 4572 Make_Integer_Literal (Loc, Uint_7 * (Uint_2 ** 29))), |
4544 Reason => SE_Object_Too_Large)); | 4573 Reason => SE_Object_Too_Large)); |
4545 end if; | 4574 end if; |
4546 end if; | 4575 end if; |
4547 | 4576 |
4548 -- If no storage pool has been specified and we have the restriction | 4577 -- If no storage pool has been specified, or the storage pool |
4578 -- is System.Pool_Global.Global_Pool_Object, and the restriction | |
4549 -- No_Standard_Allocators_After_Elaboration is present, then generate | 4579 -- No_Standard_Allocators_After_Elaboration is present, then generate |
4550 -- a call to Elaboration_Allocators.Check_Standard_Allocator. | 4580 -- a call to Elaboration_Allocators.Check_Standard_Allocator. |
4551 | 4581 |
4552 if Nkind (N) = N_Allocator | 4582 if Nkind (N) = N_Allocator |
4553 and then No (Storage_Pool (N)) | 4583 and then (No (Storage_Pool (N)) |
4584 or else Is_RTE (Storage_Pool (N), RE_Global_Pool_Object)) | |
4554 and then Restriction_Active (No_Standard_Allocators_After_Elaboration) | 4585 and then Restriction_Active (No_Standard_Allocators_After_Elaboration) |
4555 then | 4586 then |
4556 Insert_Action (N, | 4587 Insert_Action (N, |
4557 Make_Procedure_Call_Statement (Loc, | 4588 Make_Procedure_Call_Statement (Loc, |
4558 Name => | 4589 Name => |
4591 -- that tasks get activated (see Exp_Ch9.Build_Task_Allocate_Block | 4622 -- that tasks get activated (see Exp_Ch9.Build_Task_Allocate_Block |
4592 -- for details). In addition, if the type T is a task type, then the | 4623 -- for details). In addition, if the type T is a task type, then the |
4593 -- first argument to Init must be converted to the task record type. | 4624 -- first argument to Init must be converted to the task record type. |
4594 | 4625 |
4595 declare | 4626 declare |
4596 T : constant Entity_Id := Entity (Expression (N)); | 4627 T : constant Entity_Id := Etype (Expression (N)); |
4597 Args : List_Id; | 4628 Args : List_Id; |
4598 Decls : List_Id; | 4629 Decls : List_Id; |
4599 Decl : Node_Id; | 4630 Decl : Node_Id; |
4600 Discr : Elmt_Id; | 4631 Discr : Elmt_Id; |
4601 Init : Entity_Id; | 4632 Init : Entity_Id; |
4613 if Present (Finalization_Master (PtrT)) then | 4644 if Present (Finalization_Master (PtrT)) then |
4614 Build_Allocate_Deallocate_Proc | 4645 Build_Allocate_Deallocate_Proc |
4615 (N => N, | 4646 (N => N, |
4616 Is_Allocate => True); | 4647 Is_Allocate => True); |
4617 end if; | 4648 end if; |
4649 | |
4650 -- Optimize the default allocation of an array object when pragma | |
4651 -- Initialize_Scalars or Normalize_Scalars is in effect. Construct an | |
4652 -- in-place initialization aggregate which may be convert into a fast | |
4653 -- memset by the backend. | |
4654 | |
4655 elsif Init_Or_Norm_Scalars | |
4656 and then Is_Array_Type (T) | |
4657 | |
4658 -- The array must lack atomic components because they are treated | |
4659 -- as non-static, and as a result the backend will not initialize | |
4660 -- the memory in one go. | |
4661 | |
4662 and then not Has_Atomic_Components (T) | |
4663 | |
4664 -- The array must not be packed because the invalid values in | |
4665 -- System.Scalar_Values are multiples of Storage_Unit. | |
4666 | |
4667 and then not Is_Packed (T) | |
4668 | |
4669 -- The array must have static non-empty ranges, otherwise the | |
4670 -- backend cannot initialize the memory in one go. | |
4671 | |
4672 and then Has_Static_Non_Empty_Array_Bounds (T) | |
4673 | |
4674 -- The optimization is only relevant for arrays of scalar types | |
4675 | |
4676 and then Is_Scalar_Type (Component_Type (T)) | |
4677 | |
4678 -- Similar to regular array initialization using a type init proc, | |
4679 -- predicate checks are not performed because the initialization | |
4680 -- values are intentionally invalid, and may violate the predicate. | |
4681 | |
4682 and then not Has_Predicates (Component_Type (T)) | |
4683 | |
4684 -- The component type must have a single initialization value | |
4685 | |
4686 and then Needs_Simple_Initialization | |
4687 (Typ => Component_Type (T), | |
4688 Consider_IS => True) | |
4689 then | |
4690 Set_Analyzed (N); | |
4691 Temp := Make_Temporary (Loc, 'P'); | |
4692 | |
4693 -- Generate: | |
4694 -- Temp : Ptr_Typ := new ...; | |
4695 | |
4696 Insert_Action | |
4697 (Assoc_Node => N, | |
4698 Ins_Action => | |
4699 Make_Object_Declaration (Loc, | |
4700 Defining_Identifier => Temp, | |
4701 Object_Definition => New_Occurrence_Of (PtrT, Loc), | |
4702 Expression => Relocate_Node (N)), | |
4703 Suppress => All_Checks); | |
4704 | |
4705 -- Generate: | |
4706 -- Temp.all := (others => ...); | |
4707 | |
4708 Insert_Action | |
4709 (Assoc_Node => N, | |
4710 Ins_Action => | |
4711 Make_Assignment_Statement (Loc, | |
4712 Name => | |
4713 Make_Explicit_Dereference (Loc, | |
4714 Prefix => New_Occurrence_Of (Temp, Loc)), | |
4715 Expression => | |
4716 Get_Simple_Init_Val | |
4717 (Typ => T, | |
4718 N => N, | |
4719 Size => Esize (Component_Type (T)))), | |
4720 Suppress => All_Checks); | |
4721 | |
4722 Rewrite (N, New_Occurrence_Of (Temp, Loc)); | |
4723 Analyze_And_Resolve (N, PtrT); | |
4618 | 4724 |
4619 -- Case of no initialization procedure present | 4725 -- Case of no initialization procedure present |
4620 | 4726 |
4621 elsif not Has_Non_Null_Base_Init_Proc (T) then | 4727 elsif not Has_Non_Null_Base_Init_Proc (T) then |
4622 | 4728 |
4796 | 4902 |
4797 -- Add discriminants if discriminated type | 4903 -- Add discriminants if discriminated type |
4798 | 4904 |
4799 declare | 4905 declare |
4800 Dis : Boolean := False; | 4906 Dis : Boolean := False; |
4801 Typ : Entity_Id; | 4907 Typ : Entity_Id := Empty; |
4802 | 4908 |
4803 begin | 4909 begin |
4804 if Has_Discriminants (T) then | 4910 if Has_Discriminants (T) then |
4805 Dis := True; | 4911 Dis := True; |
4806 Typ := T; | 4912 Typ := T; |
5336 begin | 5442 begin |
5337 if Nkind (Act) = N_Object_Declaration | 5443 if Nkind (Act) = N_Object_Declaration |
5338 and then Is_Finalizable_Transient (Act, N) | 5444 and then Is_Finalizable_Transient (Act, N) |
5339 then | 5445 then |
5340 Process_Transient_In_Expression (Act, N, Acts); | 5446 Process_Transient_In_Expression (Act, N, Acts); |
5341 return Abandon; | 5447 return Skip; |
5342 | 5448 |
5343 -- Avoid processing temporary function results multiple times when | 5449 -- Avoid processing temporary function results multiple times when |
5344 -- dealing with nested expression_with_actions. | 5450 -- dealing with nested expression_with_actions. |
5345 | 5451 |
5346 elsif Nkind (Act) = N_Expression_With_Actions then | 5452 elsif Nkind (Act) = N_Expression_With_Actions then |
6011 | 6117 |
6012 -- Kill warnings in instances, since they may be cases where we | 6118 -- Kill warnings in instances, since they may be cases where we |
6013 -- have a test in the generic that makes sense with some types | 6119 -- have a test in the generic that makes sense with some types |
6014 -- and not with other types. | 6120 -- and not with other types. |
6015 | 6121 |
6016 and then not In_Instance | 6122 -- Similarly, do not rewrite membership as a validity check if |
6123 -- within the predicate function for the type. | |
6124 | |
6017 then | 6125 then |
6018 Substitute_Valid_Check; | 6126 if In_Instance |
6019 goto Leave; | 6127 or else (Ekind (Current_Scope) = E_Function |
6128 and then Is_Predicate_Function (Current_Scope)) | |
6129 then | |
6130 null; | |
6131 | |
6132 else | |
6133 Substitute_Valid_Check; | |
6134 goto Leave; | |
6135 end if; | |
6020 end if; | 6136 end if; |
6021 | 6137 |
6022 -- If we have an explicit range, do a bit of optimization based on | 6138 -- If we have an explicit range, do a bit of optimization based on |
6023 -- range analysis (we may be able to kill one or both checks). | 6139 -- range analysis (we may be able to kill one or both checks). |
6024 | 6140 |
6825 return; | 6941 return; |
6826 end if; | 6942 end if; |
6827 | 6943 |
6828 -- Deal with software overflow checking | 6944 -- Deal with software overflow checking |
6829 | 6945 |
6830 if not Backend_Overflow_Checks_On_Target | 6946 if Is_Signed_Integer_Type (Etype (N)) |
6831 and then Is_Signed_Integer_Type (Etype (N)) | |
6832 and then Do_Overflow_Check (N) | 6947 and then Do_Overflow_Check (N) |
6833 then | 6948 then |
6834 -- The only case to worry about is when the argument is equal to the | 6949 -- The only case to worry about is when the argument is equal to the |
6835 -- largest negative number, so what we do is to insert the check: | 6950 -- largest negative number, so what we do is to insert the check: |
6836 | 6951 |
6847 Make_Attribute_Reference (Loc, | 6962 Make_Attribute_Reference (Loc, |
6848 Prefix => | 6963 Prefix => |
6849 New_Occurrence_Of (Base_Type (Etype (Expr)), Loc), | 6964 New_Occurrence_Of (Base_Type (Etype (Expr)), Loc), |
6850 Attribute_Name => Name_First)), | 6965 Attribute_Name => Name_First)), |
6851 Reason => CE_Overflow_Check_Failed)); | 6966 Reason => CE_Overflow_Check_Failed)); |
6967 | |
6968 Set_Do_Overflow_Check (N, False); | |
6852 end if; | 6969 end if; |
6853 end Expand_N_Op_Abs; | 6970 end Expand_N_Op_Abs; |
6854 | 6971 |
6855 --------------------- | 6972 --------------------- |
6856 -- Expand_N_Op_Add -- | 6973 -- Expand_N_Op_Add -- |
6895 | 7012 |
6896 -- Overflow checks for floating-point if -gnateF mode active | 7013 -- Overflow checks for floating-point if -gnateF mode active |
6897 | 7014 |
6898 Check_Float_Op_Overflow (N); | 7015 Check_Float_Op_Overflow (N); |
6899 | 7016 |
6900 -- When generating C code, convert nonbinary modular additions into code | 7017 Expand_Nonbinary_Modular_Op (N); |
6901 -- that relies on the front-end expansion of operator Mod. | |
6902 | |
6903 if Modify_Tree_For_C then | |
6904 Expand_Nonbinary_Modular_Op (N); | |
6905 end if; | |
6906 end Expand_N_Op_Add; | 7018 end Expand_N_Op_Add; |
6907 | 7019 |
6908 --------------------- | 7020 --------------------- |
6909 -- Expand_N_Op_And -- | 7021 -- Expand_N_Op_And -- |
6910 --------------------- | 7022 --------------------- |
6926 | 7038 |
6927 elsif Is_Intrinsic_Subprogram (Entity (N)) then | 7039 elsif Is_Intrinsic_Subprogram (Entity (N)) then |
6928 Expand_Intrinsic_Call (N, Entity (N)); | 7040 Expand_Intrinsic_Call (N, Entity (N)); |
6929 end if; | 7041 end if; |
6930 | 7042 |
6931 -- When generating C code, convert nonbinary modular operators into code | 7043 Expand_Nonbinary_Modular_Op (N); |
6932 -- that relies on the front-end expansion of operator Mod. | |
6933 | |
6934 if Modify_Tree_For_C then | |
6935 Expand_Nonbinary_Modular_Op (N); | |
6936 end if; | |
6937 end Expand_N_Op_And; | 7044 end Expand_N_Op_And; |
6938 | 7045 |
6939 ------------------------ | 7046 ------------------------ |
6940 -- Expand_N_Op_Concat -- | 7047 -- Expand_N_Op_Concat -- |
6941 ------------------------ | 7048 ------------------------ |
7174 | 7281 |
7175 -- Overflow checks for floating-point if -gnateF mode active | 7282 -- Overflow checks for floating-point if -gnateF mode active |
7176 | 7283 |
7177 Check_Float_Op_Overflow (N); | 7284 Check_Float_Op_Overflow (N); |
7178 | 7285 |
7179 -- When generating C code, convert nonbinary modular divisions into code | 7286 Expand_Nonbinary_Modular_Op (N); |
7180 -- that relies on the front-end expansion of operator Mod. | |
7181 | |
7182 if Modify_Tree_For_C then | |
7183 Expand_Nonbinary_Modular_Op (N); | |
7184 end if; | |
7185 end Expand_N_Op_Divide; | 7287 end Expand_N_Op_Divide; |
7186 | 7288 |
7187 -------------------- | 7289 -------------------- |
7188 -- Expand_N_Op_Eq -- | 7290 -- Expand_N_Op_Eq -- |
7189 -------------------- | 7291 -------------------- |
7740 | 7842 |
7741 if Restriction_Active (No_Dispatching_Calls) then | 7843 if Restriction_Active (No_Dispatching_Calls) then |
7742 return; | 7844 return; |
7743 end if; | 7845 end if; |
7744 | 7846 |
7745 -- If this is derived from an untagged private type completed with | 7847 -- If this is an untagged private type completed with a derivation |
7746 -- a tagged type, it does not have a full view, so we use the | 7848 -- of an untagged private type whose full view is a tagged type, |
7747 -- primitive operations of the private type. This check should no | 7849 -- we use the primitive operations of the private type (since it |
7748 -- longer be necessary when these types get their full views??? | 7850 -- does not have a full view, and also because its equality |
7749 | 7851 -- primitive may have been overridden in its untagged full view). |
7750 if Is_Private_Type (A_Typ) | 7852 |
7751 and then not Is_Tagged_Type (A_Typ) | 7853 if Inherits_From_Tagged_Full_View (A_Typ) then |
7752 and then Is_Derived_Type (A_Typ) | 7854 |
7753 and then No (Full_View (A_Typ)) | |
7754 then | |
7755 -- Search for equality operation, checking that the operands | 7855 -- Search for equality operation, checking that the operands |
7756 -- have the same type. Note that we must find a matching entry, | 7856 -- have the same type. Note that we must find a matching entry, |
7757 -- or something is very wrong. | 7857 -- or something is very wrong. |
7758 | 7858 |
7759 Prim := First_Elmt (Collect_Primitive_Operations (A_Typ)); | 7859 Prim := First_Elmt (Collect_Primitive_Operations (A_Typ)); |
8683 Right_Opnd => Right_Opnd (N))); | 8783 Right_Opnd => Right_Opnd (N))); |
8684 | 8784 |
8685 Analyze_And_Resolve (N, Typ); | 8785 Analyze_And_Resolve (N, Typ); |
8686 end if; | 8786 end if; |
8687 | 8787 |
8688 -- When generating C code, convert nonbinary modular minus into code | 8788 Expand_Nonbinary_Modular_Op (N); |
8689 -- that relies on the front-end expansion of operator Mod. | |
8690 | |
8691 if Modify_Tree_For_C then | |
8692 Expand_Nonbinary_Modular_Op (N); | |
8693 end if; | |
8694 end Expand_N_Op_Minus; | 8789 end Expand_N_Op_Minus; |
8695 | 8790 |
8696 --------------------- | 8791 --------------------- |
8697 -- Expand_N_Op_Mod -- | 8792 -- Expand_N_Op_Mod -- |
8698 --------------------- | 8793 --------------------- |
9166 | 9261 |
9167 -- Overflow checks for floating-point if -gnateF mode active | 9262 -- Overflow checks for floating-point if -gnateF mode active |
9168 | 9263 |
9169 Check_Float_Op_Overflow (N); | 9264 Check_Float_Op_Overflow (N); |
9170 | 9265 |
9171 -- When generating C code, convert nonbinary modular multiplications | 9266 Expand_Nonbinary_Modular_Op (N); |
9172 -- into code that relies on the front-end expansion of operator Mod. | |
9173 | |
9174 if Modify_Tree_For_C then | |
9175 Expand_Nonbinary_Modular_Op (N); | |
9176 end if; | |
9177 end Expand_N_Op_Multiply; | 9267 end Expand_N_Op_Multiply; |
9178 | 9268 |
9179 -------------------- | 9269 -------------------- |
9180 -- Expand_N_Op_Ne -- | 9270 -- Expand_N_Op_Ne -- |
9181 -------------------- | 9271 -------------------- |
9483 | 9573 |
9484 elsif Is_Intrinsic_Subprogram (Entity (N)) then | 9574 elsif Is_Intrinsic_Subprogram (Entity (N)) then |
9485 Expand_Intrinsic_Call (N, Entity (N)); | 9575 Expand_Intrinsic_Call (N, Entity (N)); |
9486 end if; | 9576 end if; |
9487 | 9577 |
9488 -- When generating C code, convert nonbinary modular operators into code | 9578 Expand_Nonbinary_Modular_Op (N); |
9489 -- that relies on the front-end expansion of operator Mod. | |
9490 | |
9491 if Modify_Tree_For_C then | |
9492 Expand_Nonbinary_Modular_Op (N); | |
9493 end if; | |
9494 end Expand_N_Op_Or; | 9579 end Expand_N_Op_Or; |
9495 | 9580 |
9496 ---------------------- | 9581 ---------------------- |
9497 -- Expand_N_Op_Plus -- | 9582 -- Expand_N_Op_Plus -- |
9498 ---------------------- | 9583 ---------------------- |
9922 | 10007 |
9923 -- Overflow checks for floating-point if -gnateF mode active | 10008 -- Overflow checks for floating-point if -gnateF mode active |
9924 | 10009 |
9925 Check_Float_Op_Overflow (N); | 10010 Check_Float_Op_Overflow (N); |
9926 | 10011 |
9927 -- When generating C code, convert nonbinary modular subtractions into | 10012 Expand_Nonbinary_Modular_Op (N); |
9928 -- code that relies on the front-end expansion of operator Mod. | |
9929 | |
9930 if Modify_Tree_For_C then | |
9931 Expand_Nonbinary_Modular_Op (N); | |
9932 end if; | |
9933 end Expand_N_Op_Subtract; | 10013 end Expand_N_Op_Subtract; |
9934 | 10014 |
9935 --------------------- | 10015 --------------------- |
9936 -- Expand_N_Op_Xor -- | 10016 -- Expand_N_Op_Xor -- |
9937 --------------------- | 10017 --------------------- |
9951 Set_Etype (N, Standard_Boolean); | 10031 Set_Etype (N, Standard_Boolean); |
9952 Adjust_Result_Type (N, Typ); | 10032 Adjust_Result_Type (N, Typ); |
9953 | 10033 |
9954 elsif Is_Intrinsic_Subprogram (Entity (N)) then | 10034 elsif Is_Intrinsic_Subprogram (Entity (N)) then |
9955 Expand_Intrinsic_Call (N, Entity (N)); | 10035 Expand_Intrinsic_Call (N, Entity (N)); |
9956 | 10036 end if; |
9957 end if; | 10037 |
10038 Expand_Nonbinary_Modular_Op (N); | |
9958 end Expand_N_Op_Xor; | 10039 end Expand_N_Op_Xor; |
9959 | 10040 |
9960 ---------------------- | 10041 ---------------------- |
9961 -- Expand_N_Or_Else -- | 10042 -- Expand_N_Or_Else -- |
9962 ---------------------- | 10043 ---------------------- |
10745 Disc_O := First_Discriminant (Operand_Type); | 10826 Disc_O := First_Discriminant (Operand_Type); |
10746 Disc_S := First_Stored_Discriminant (Operand_Type); | 10827 Disc_S := First_Stored_Discriminant (Operand_Type); |
10747 | 10828 |
10748 if Present (Stored) then | 10829 if Present (Stored) then |
10749 Elmt := First_Elmt (Stored); | 10830 Elmt := First_Elmt (Stored); |
10831 else | |
10832 Elmt := No_Elmt; -- init to avoid warning | |
10750 end if; | 10833 end if; |
10751 | 10834 |
10752 Cons := New_List; | 10835 Cons := New_List; |
10753 while Present (Disc_T) loop | 10836 while Present (Disc_T) loop |
10754 if Present (Disc_O) | 10837 if Present (Disc_O) |
10882 procedure Real_Range_Check is | 10965 procedure Real_Range_Check is |
10883 Btyp : constant Entity_Id := Base_Type (Target_Type); | 10966 Btyp : constant Entity_Id := Base_Type (Target_Type); |
10884 Lo : constant Node_Id := Type_Low_Bound (Target_Type); | 10967 Lo : constant Node_Id := Type_Low_Bound (Target_Type); |
10885 Hi : constant Node_Id := Type_High_Bound (Target_Type); | 10968 Hi : constant Node_Id := Type_High_Bound (Target_Type); |
10886 Xtyp : constant Entity_Id := Etype (Operand); | 10969 Xtyp : constant Entity_Id := Etype (Operand); |
10887 Conv : Node_Id; | 10970 |
10888 Tnn : Entity_Id; | 10971 Conv : Node_Id; |
10972 Hi_Arg : Node_Id; | |
10973 Hi_Val : Node_Id; | |
10974 Lo_Arg : Node_Id; | |
10975 Lo_Val : Node_Id; | |
10976 Tnn : Entity_Id; | |
10889 | 10977 |
10890 begin | 10978 begin |
10891 -- Nothing to do if conversion was rewritten | 10979 -- Nothing to do if conversion was rewritten |
10892 | 10980 |
10893 if Nkind (N) /= N_Type_Conversion then | 10981 if Nkind (N) /= N_Type_Conversion then |
10986 Enable_Overflow_Check (Conv); | 11074 Enable_Overflow_Check (Conv); |
10987 end if; | 11075 end if; |
10988 | 11076 |
10989 Tnn := Make_Temporary (Loc, 'T', Conv); | 11077 Tnn := Make_Temporary (Loc, 'T', Conv); |
10990 | 11078 |
11079 -- For a conversion from Float to Fixed where the bounds of the | |
11080 -- fixed-point type are static, we can obtain a more accurate | |
11081 -- fixed-point value by converting the result of the floating- | |
11082 -- point expression to an appropriate integer type, and then | |
11083 -- performing an unchecked conversion to the target fixed-point | |
11084 -- type. The range check can then use the corresponding integer | |
11085 -- value of the bounds instead of requiring further conversions. | |
11086 -- This preserves the identity: | |
11087 | |
11088 -- Fix_Val = Fixed_Type (Float_Type (Fix_Val)) | |
11089 | |
11090 -- which used to fail when Fix_Val was a bound of the type and | |
11091 -- the 'Small was not a representable number. | |
11092 -- This transformation requires an integer type large enough to | |
11093 -- accommodate a fixed-point value. This will not be the case | |
11094 -- in systems where Duration is larger than Long_Integer. | |
11095 | |
11096 if Is_Ordinary_Fixed_Point_Type (Target_Type) | |
11097 and then Is_Floating_Point_Type (Operand_Type) | |
11098 and then RM_Size (Base_Type (Target_Type)) <= | |
11099 RM_Size (Standard_Long_Integer) | |
11100 and then Nkind (Lo) = N_Real_Literal | |
11101 and then Nkind (Hi) = N_Real_Literal | |
11102 then | |
11103 -- Find the integer type of the right size to perform an unchecked | |
11104 -- conversion to the target fixed-point type. | |
11105 | |
11106 declare | |
11107 Bfx_Type : constant Entity_Id := Base_Type (Target_Type); | |
11108 Expr_Id : constant Entity_Id := | |
11109 Make_Temporary (Loc, 'T', Conv); | |
11110 Int_Type : Entity_Id; | |
11111 | |
11112 begin | |
11113 if RM_Size (Bfx_Type) > RM_Size (Standard_Integer) then | |
11114 Int_Type := Standard_Long_Integer; | |
11115 | |
11116 elsif RM_Size (Bfx_Type) > RM_Size (Standard_Short_Integer) then | |
11117 Int_Type := Standard_Integer; | |
11118 | |
11119 else | |
11120 Int_Type := Standard_Short_Integer; | |
11121 end if; | |
11122 | |
11123 -- Generate a temporary with the integer value. Required in the | |
11124 -- CCG compiler to ensure that runtime checks reference this | |
11125 -- integer expression (instead of the resulting fixed-point | |
11126 -- value) because fixed-point values are handled by means of | |
11127 -- unsigned integer types). | |
11128 | |
11129 Insert_Action (N, | |
11130 Make_Object_Declaration (Loc, | |
11131 Defining_Identifier => Expr_Id, | |
11132 Object_Definition => New_Occurrence_Of (Int_Type, Loc), | |
11133 Constant_Present => True, | |
11134 Expression => | |
11135 Convert_To (Int_Type, Expression (Conv)))); | |
11136 | |
11137 -- Create integer objects for range checking of result. | |
11138 | |
11139 Lo_Arg := | |
11140 Unchecked_Convert_To | |
11141 (Int_Type, New_Occurrence_Of (Expr_Id, Loc)); | |
11142 | |
11143 Lo_Val := | |
11144 Make_Integer_Literal (Loc, Corresponding_Integer_Value (Lo)); | |
11145 | |
11146 Hi_Arg := | |
11147 Unchecked_Convert_To | |
11148 (Int_Type, New_Occurrence_Of (Expr_Id, Loc)); | |
11149 | |
11150 Hi_Val := | |
11151 Make_Integer_Literal (Loc, Corresponding_Integer_Value (Hi)); | |
11152 | |
11153 -- Rewrite conversion as an integer conversion of the | |
11154 -- original floating-point expression, followed by an | |
11155 -- unchecked conversion to the target fixed-point type. | |
11156 | |
11157 Conv := | |
11158 Make_Unchecked_Type_Conversion (Loc, | |
11159 Subtype_Mark => New_Occurrence_Of (Target_Type, Loc), | |
11160 Expression => New_Occurrence_Of (Expr_Id, Loc)); | |
11161 end; | |
11162 | |
11163 -- All other conversions | |
11164 | |
11165 else | |
11166 Lo_Arg := New_Occurrence_Of (Tnn, Loc); | |
11167 Lo_Val := | |
11168 Make_Attribute_Reference (Loc, | |
11169 Prefix => New_Occurrence_Of (Target_Type, Loc), | |
11170 Attribute_Name => Name_First); | |
11171 | |
11172 Hi_Arg := New_Occurrence_Of (Tnn, Loc); | |
11173 Hi_Val := | |
11174 Make_Attribute_Reference (Loc, | |
11175 Prefix => New_Occurrence_Of (Target_Type, Loc), | |
11176 Attribute_Name => Name_Last); | |
11177 end if; | |
11178 | |
11179 -- Build code for range checking | |
11180 | |
10991 Insert_Actions (N, New_List ( | 11181 Insert_Actions (N, New_List ( |
10992 Make_Object_Declaration (Loc, | 11182 Make_Object_Declaration (Loc, |
10993 Defining_Identifier => Tnn, | 11183 Defining_Identifier => Tnn, |
10994 Object_Definition => New_Occurrence_Of (Btyp, Loc), | 11184 Object_Definition => New_Occurrence_Of (Btyp, Loc), |
10995 Constant_Present => True, | 11185 Constant_Present => True, |
10996 Expression => Conv), | 11186 Expression => Conv), |
10997 | 11187 |
10998 Make_Raise_Constraint_Error (Loc, | 11188 Make_Raise_Constraint_Error (Loc, |
10999 Condition => | 11189 Condition => |
11000 Make_Or_Else (Loc, | 11190 Make_Or_Else (Loc, |
11001 Left_Opnd => | 11191 Left_Opnd => |
11002 Make_Op_Lt (Loc, | 11192 Make_Op_Lt (Loc, |
11003 Left_Opnd => New_Occurrence_Of (Tnn, Loc), | 11193 Left_Opnd => Lo_Arg, |
11004 Right_Opnd => | 11194 Right_Opnd => Lo_Val), |
11005 Make_Attribute_Reference (Loc, | |
11006 Attribute_Name => Name_First, | |
11007 Prefix => | |
11008 New_Occurrence_Of (Target_Type, Loc))), | |
11009 | 11195 |
11010 Right_Opnd => | 11196 Right_Opnd => |
11011 Make_Op_Gt (Loc, | 11197 Make_Op_Gt (Loc, |
11012 Left_Opnd => New_Occurrence_Of (Tnn, Loc), | 11198 Left_Opnd => Hi_Arg, |
11013 Right_Opnd => | 11199 Right_Opnd => Hi_Val)), |
11014 Make_Attribute_Reference (Loc, | 11200 Reason => CE_Range_Check_Failed))); |
11015 Attribute_Name => Name_Last, | |
11016 Prefix => | |
11017 New_Occurrence_Of (Target_Type, Loc)))), | |
11018 Reason => CE_Range_Check_Failed))); | |
11019 | 11201 |
11020 Rewrite (N, New_Occurrence_Of (Tnn, Loc)); | 11202 Rewrite (N, New_Occurrence_Of (Tnn, Loc)); |
11021 Analyze_And_Resolve (N, Btyp); | 11203 Analyze_And_Resolve (N, Btyp); |
11022 end Real_Range_Check; | 11204 end Real_Range_Check; |
11023 | 11205 |
11024 ----------------------------- | 11206 ----------------------------- |
11025 -- Has_Extra_Accessibility -- | 11207 -- Has_Extra_Accessibility -- |
11026 ----------------------------- | 11208 ----------------------------- |
11027 | 11209 |
11028 -- Returns true for a formal of an anonymous access type or for | 11210 -- Returns true for a formal of an anonymous access type or for an Ada |
11029 -- an Ada 2012-style stand-alone object of an anonymous access type. | 11211 -- 2012-style stand-alone object of an anonymous access type. |
11030 | 11212 |
11031 function Has_Extra_Accessibility (Id : Entity_Id) return Boolean is | 11213 function Has_Extra_Accessibility (Id : Entity_Id) return Boolean is |
11032 begin | 11214 begin |
11033 if Is_Formal (Id) or else Ekind_In (Id, E_Constant, E_Variable) then | 11215 if Is_Formal (Id) or else Ekind_In (Id, E_Constant, E_Variable) then |
11034 return Present (Effective_Extra_Accessibility (Id)); | 11216 return Present (Effective_Extra_Accessibility (Id)); |
11275 -- of an instantiation). | 11457 -- of an instantiation). |
11276 | 11458 |
11277 elsif In_Instance_Body | 11459 elsif In_Instance_Body |
11278 and then Ekind (Operand_Type) = E_Anonymous_Access_Type | 11460 and then Ekind (Operand_Type) = E_Anonymous_Access_Type |
11279 and then Nkind (Operand) = N_Selected_Component | 11461 and then Nkind (Operand) = N_Selected_Component |
11462 and then Ekind (Entity (Selector_Name (Operand))) = E_Discriminant | |
11280 and then Object_Access_Level (Operand) > | 11463 and then Object_Access_Level (Operand) > |
11281 Type_Access_Level (Target_Type) | 11464 Type_Access_Level (Target_Type) |
11282 then | 11465 then |
11283 Raise_Accessibility_Error; | 11466 Raise_Accessibility_Error; |
11284 goto Done; | 11467 goto Done; |
11521 Real_Range_Check; | 11704 Real_Range_Check; |
11522 | 11705 |
11523 elsif Is_Integer_Type (Etype (N)) then | 11706 elsif Is_Integer_Type (Etype (N)) then |
11524 Expand_Convert_Fixed_To_Integer (N); | 11707 Expand_Convert_Fixed_To_Integer (N); |
11525 | 11708 |
11709 -- The result of the conversion might need a range check, | |
11710 -- so do not assume that the result is in bounds. | |
11711 | |
11712 Set_Etype (N, Base_Type (Target_Type)); | |
11713 | |
11526 else | 11714 else |
11527 pragma Assert (Is_Floating_Point_Type (Etype (N))); | 11715 pragma Assert (Is_Floating_Point_Type (Etype (N))); |
11528 Expand_Convert_Fixed_To_Float (N); | 11716 Expand_Convert_Fixed_To_Float (N); |
11529 Real_Range_Check; | 11717 Real_Range_Check; |
11530 end if; | 11718 end if; |
11986 | 12174 |
11987 begin | 12175 begin |
11988 -- Generates the following code: (assuming that Typ has one Discr and | 12176 -- Generates the following code: (assuming that Typ has one Discr and |
11989 -- component C2 is also a record) | 12177 -- component C2 is also a record) |
11990 | 12178 |
11991 -- True | 12179 -- Lhs.Discr1 = Rhs.Discr1 |
11992 -- and then Lhs.Discr1 = Rhs.Discr1 | 12180 -- and then Lhs.C1 = Rhs.C1 |
11993 -- and then Lhs.C1 = Rhs.C1 | 12181 -- and then Lhs.C2.C1=Rhs.C2.C1 and then ... Lhs.C2.Cn=Rhs.C2.Cn |
11994 -- and then Lhs.C2.C1=Rhs.C2.C1 and then ... Lhs.C2.Cn=Rhs.C2.Cn | 12182 -- and then ... |
11995 -- and then ... | 12183 -- and then Lhs.Cmpn = Rhs.Cmpn |
11996 -- and then Lhs.Cmpn = Rhs.Cmpn | |
11997 | 12184 |
11998 Result := New_Occurrence_Of (Standard_True, Loc); | 12185 Result := New_Occurrence_Of (Standard_True, Loc); |
11999 C := Element_To_Compare (First_Entity (Typ)); | 12186 C := Element_To_Compare (First_Entity (Typ)); |
12000 while Present (C) loop | 12187 while Present (C) loop |
12001 declare | 12188 declare |
12003 New_Rhs : Node_Id; | 12190 New_Rhs : Node_Id; |
12004 Check : Node_Id; | 12191 Check : Node_Id; |
12005 | 12192 |
12006 begin | 12193 begin |
12007 if First_Time then | 12194 if First_Time then |
12008 First_Time := False; | |
12009 New_Lhs := Lhs; | 12195 New_Lhs := Lhs; |
12010 New_Rhs := Rhs; | 12196 New_Rhs := Rhs; |
12011 else | 12197 else |
12012 New_Lhs := New_Copy_Tree (Lhs); | 12198 New_Lhs := New_Copy_Tree (Lhs); |
12013 New_Rhs := New_Copy_Tree (Rhs); | 12199 New_Rhs := New_Copy_Tree (Rhs); |
12031 if Nkind (Check) = N_Raise_Program_Error then | 12217 if Nkind (Check) = N_Raise_Program_Error then |
12032 Result := Check; | 12218 Result := Check; |
12033 Set_Etype (Result, Standard_Boolean); | 12219 Set_Etype (Result, Standard_Boolean); |
12034 exit; | 12220 exit; |
12035 else | 12221 else |
12036 Result := | 12222 if First_Time then |
12037 Make_And_Then (Loc, | 12223 Result := Check; |
12038 Left_Opnd => Result, | 12224 |
12039 Right_Opnd => Check); | 12225 -- Generate logical "and" for CodePeer to simplify the |
12226 -- generated code and analysis. | |
12227 | |
12228 elsif CodePeer_Mode then | |
12229 Result := | |
12230 Make_Op_And (Loc, | |
12231 Left_Opnd => Result, | |
12232 Right_Opnd => Check); | |
12233 | |
12234 else | |
12235 Result := | |
12236 Make_And_Then (Loc, | |
12237 Left_Opnd => Result, | |
12238 Right_Opnd => Check); | |
12239 end if; | |
12040 end if; | 12240 end if; |
12041 end; | 12241 end; |
12042 | 12242 |
12243 First_Time := False; | |
12043 C := Element_To_Compare (Next_Entity (C)); | 12244 C := Element_To_Compare (Next_Entity (C)); |
12044 end loop; | 12245 end loop; |
12045 | 12246 |
12046 return Result; | 12247 return Result; |
12047 end Expand_Record_Equality; | 12248 end Expand_Record_Equality; |
12063 -- Make_Cond -- | 12264 -- Make_Cond -- |
12064 --------------- | 12265 --------------- |
12065 | 12266 |
12066 function Make_Cond (Alt : Node_Id) return Node_Id is | 12267 function Make_Cond (Alt : Node_Id) return Node_Id is |
12067 Cond : Node_Id; | 12268 Cond : Node_Id; |
12068 L : constant Node_Id := New_Copy (Lop); | 12269 L : constant Node_Id := New_Copy_Tree (Lop); |
12069 R : constant Node_Id := Relocate_Node (Alt); | 12270 R : constant Node_Id := Relocate_Node (Alt); |
12070 | 12271 |
12071 begin | 12272 begin |
12072 if (Is_Entity_Name (Alt) and then Is_Type (Entity (Alt))) | 12273 if (Is_Entity_Name (Alt) and then Is_Type (Entity (Alt))) |
12073 or else Nkind (Alt) = N_Range | 12274 or else Nkind (Alt) = N_Range |
12362 and then Nkind (Parent (Sel_Comp)) = N_Selected_Component | 12563 and then Nkind (Parent (Sel_Comp)) = N_Selected_Component |
12363 loop | 12564 loop |
12364 Sel_Comp := Parent (Sel_Comp); | 12565 Sel_Comp := Parent (Sel_Comp); |
12365 end loop; | 12566 end loop; |
12366 | 12567 |
12367 return Ekind (Entity (Prefix (Sel_Comp))) in Formal_Kind; | 12568 return Is_Formal (Entity (Prefix (Sel_Comp))); |
12368 end Prefix_Is_Formal_Parameter; | 12569 end Prefix_Is_Formal_Parameter; |
12369 | 12570 |
12370 -- Start of processing for Has_Inferable_Discriminants | 12571 -- Start of processing for Has_Inferable_Discriminants |
12371 | 12572 |
12372 begin | 12573 begin |
13107 -- True for comparison operand of zero | 13308 -- True for comparison operand of zero |
13108 | 13309 |
13109 Comp : Node_Id; | 13310 Comp : Node_Id; |
13110 -- Comparison operand, set only if Is_Zero is false | 13311 -- Comparison operand, set only if Is_Zero is false |
13111 | 13312 |
13112 Ent : Entity_Id; | 13313 Ent : Entity_Id := Empty; |
13113 -- Entity whose length is being compared | 13314 -- Entity whose length is being compared |
13114 | 13315 |
13115 Index : Node_Id; | 13316 Index : Node_Id := Empty; |
13116 -- Integer_Literal node for length attribute expression, or Empty | 13317 -- Integer_Literal node for length attribute expression, or Empty |
13117 -- if there is no such expression present. | 13318 -- if there is no such expression present. |
13118 | 13319 |
13119 Ityp : Entity_Id; | 13320 Ityp : Entity_Id; |
13120 -- Type of array index to which 'Length is applied | 13321 -- Type of array index to which 'Length is applied |
13835 Make_Selected_Component (Loc, | 14036 Make_Selected_Component (Loc, |
13836 Prefix => Relocate_Node (Left), | 14037 Prefix => Relocate_Node (Left), |
13837 Selector_Name => | 14038 Selector_Name => |
13838 New_Occurrence_Of (First_Tag_Component (Left_Type), Loc)); | 14039 New_Occurrence_Of (First_Tag_Component (Left_Type), Loc)); |
13839 | 14040 |
13840 if Is_Class_Wide_Type (Right_Type) then | 14041 if Is_Class_Wide_Type (Right_Type) or else Is_Interface (Left_Type) then |
13841 | 14042 |
13842 -- No need to issue a run-time check if we statically know that the | 14043 -- No need to issue a run-time check if we statically know that the |
13843 -- result of this membership test is always true. For example, | 14044 -- result of this membership test is always true. For example, |
13844 -- considering the following declarations: | 14045 -- considering the following declarations: |
13845 | 14046 |