Commit 36a66365 by Arnaud Charlet

[multiple changes]

2014-07-29  Hristian Kirtchev  <kirtchev@adacore.com>

	* a-cbmutr.adb (Allocate_Node): Remove the two parameter version.
	(Insert_Child): Add local variable First. Capture the index of the
	first node being created to ensure correct cursor construction
	later on. Use the three parameter version of Allocate_Node
	when creating multiple children as this method allows aspect
	Default_Value to take effect (if applicable).

2014-07-29  Eric Botcazou  <ebotcazou@adacore.com>

	* exp_aggr.adb (Safe_Slice_Assignment): Remove.
	(Expand_Array_Aggregate): For a safe slice assignment, just set
	the target and use the common code path.

From-SVN: r213216
parent e1ea35da
2014-07-29 Hristian Kirtchev <kirtchev@adacore.com>
* a-cbmutr.adb (Allocate_Node): Remove the two parameter version.
(Insert_Child): Add local variable First. Capture the index of the
first node being created to ensure correct cursor construction
later on. Use the three parameter version of Allocate_Node
when creating multiple children as this method allows aspect
Default_Value to take effect (if applicable).
2014-07-29 Eric Botcazou <ebotcazou@adacore.com>
* exp_aggr.adb (Safe_Slice_Assignment): Remove.
(Expand_Array_Aggregate): For a safe slice assignment, just set
the target and use the common code path.
2014-07-29 Robert Dewar <dewar@adacore.com>
* sem_util.adb, sem_util.ads, sem_res.adb, exp_ch6.adb: Invert
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2011-2013, Free Software Foundation, Inc. --
-- Copyright (C) 2011-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
......@@ -96,10 +96,6 @@ package body Ada.Containers.Bounded_Multiway_Trees is
procedure Allocate_Node
(Container : in out Tree;
New_Node : out Count_Type);
procedure Allocate_Node
(Container : in out Tree;
Stream : not null access Root_Stream_Type'Class;
New_Node : out Count_Type);
......@@ -318,15 +314,6 @@ package body Ada.Containers.Bounded_Multiway_Trees is
Allocate_Node (Container, Initialize_Element'Access, New_Node);
end Allocate_Node;
procedure Allocate_Node
(Container : in out Tree;
New_Node : out Count_Type)
is
procedure Initialize_Element (Index : Count_Type) is null;
begin
Allocate_Node (Container, Initialize_Element'Access, New_Node);
end Allocate_Node;
-------------------
-- Ancestor_Find --
-------------------
......@@ -1583,6 +1570,7 @@ package body Ada.Containers.Bounded_Multiway_Trees is
Count : Count_Type := 1)
is
Nodes : Tree_Node_Array renames Container.Nodes;
First : Count_Type;
Last : Count_Type;
New_Item : Element_Type;
......@@ -1634,11 +1622,12 @@ package body Ada.Containers.Bounded_Multiway_Trees is
-- initialized elements at the given position.
Allocate_Node (Container, New_Item, Position.Node);
First := Position.Node;
Nodes (Position.Node).Parent := Parent.Node;
Last := Position.Node;
for J in Count_Type'(2) .. Count loop
Allocate_Node (Container, Nodes (Last).Next);
Allocate_Node (Container, New_Item, Nodes (Last).Next);
Nodes (Nodes (Last).Next).Parent := Parent.Node;
Nodes (Nodes (Last).Next).Prev := Last;
......@@ -1654,7 +1643,7 @@ package body Ada.Containers.Bounded_Multiway_Trees is
Container.Count := Container.Count + Count;
Position.Container := Parent.Container;
Position := Cursor'(Parent.Container, First);
end Insert_Child;
-------------------------
......
......@@ -289,11 +289,6 @@ package body Exp_Aggr is
-- If this transformation is not possible, N is unchanged and False is
-- returned.
function Safe_Slice_Assignment (N : Node_Id) return Boolean;
-- If a slice assignment has an aggregate with a single others_choice,
-- the assignment can be done in place even if bounds are not static,
-- by converting it into a loop over the discrete range of the slice.
function Two_Dim_Packed_Array_Handled (N : Node_Id) return Boolean;
-- If the type of the aggregate is a two-dimensional bit_packed array
-- it may be transformed into an array of bytes with constant values,
......@@ -404,8 +399,8 @@ package body Exp_Aggr is
elsif Restriction_Active (No_Elaboration_Code)
or else Restriction_Active (No_Implicit_Loops)
or else Is_Two_Dim_Packed_Array (Typ)
or else ((Ekind (Current_Scope) = E_Package
and then Static_Elaboration_Desired (Current_Scope)))
or else (Ekind (Current_Scope) = E_Package
and then Static_Elaboration_Desired (Current_Scope))
then
Max_Aggr_Size := 2 ** 24;
......@@ -443,9 +438,7 @@ package body Exp_Aggr is
-- is an object declaration with non-static bounds it will trip gcc;
-- such an aggregate must be expanded into a single assignment.
if Hiv = Lov
and then Nkind (Parent (N)) = N_Object_Declaration
then
if Hiv = Lov and then Nkind (Parent (N)) = N_Object_Declaration then
declare
Index_Type : constant Entity_Id :=
Etype
......@@ -934,7 +927,8 @@ package body Exp_Aggr is
end case;
if Local_Compile_Time_Known_Value (Low)
and then Local_Compile_Time_Known_Value (High)
and then
Local_Compile_Time_Known_Value (High)
then
Is_Empty :=
UI_Gt (Local_Expr_Value (Low), Local_Expr_Value (High));
......@@ -956,7 +950,8 @@ package body Exp_Aggr is
return True;
elsif Local_Compile_Time_Known_Value (L)
and then Local_Compile_Time_Known_Value (H)
and then
Local_Compile_Time_Known_Value (H)
then
return UI_Eq (Local_Expr_Value (L), Local_Expr_Value (H));
end if;
......@@ -1053,9 +1048,7 @@ package body Exp_Aggr is
Expr_Q := Expr;
end if;
if Present (Etype (N))
and then Etype (N) /= Any_Composite
then
if Present (Etype (N)) and then Etype (N) /= Any_Composite then
Comp_Type := Component_Type (Etype (N));
pragma Assert (Comp_Type = Ctype); -- AI-287
......@@ -1070,9 +1063,9 @@ package body Exp_Aggr is
if Present (Expr) then
-- This is a multidimensional array. Recover the component
-- type from the outermost aggregate, because subaggregates
-- do not have an assigned type.
-- This is a multidimensional array. Recover the component type
-- from the outermost aggregate, because subaggregates do not
-- have an assigned type.
declare
P : Node_Id;
......@@ -1621,9 +1614,7 @@ package body Exp_Aggr is
-- entity in the current scope, because it will be needed if build-
-- in-place functions are called in the expanded code.
if Nkind (Parent (N)) = N_Object_Declaration
and then Has_Task (Typ)
then
if Nkind (Parent (N)) = N_Object_Declaration and then Has_Task (Typ) then
Build_Master_Entity (Defining_Identifier (Parent (N)));
end if;
......@@ -2189,9 +2180,7 @@ package body Exp_Aggr is
-- proper scope is the scope of the target rather than the
-- potentially transient current scope.
if Is_Controlled (Typ)
and then Ancestor_Is_Subtype_Mark
then
if Is_Controlled (Typ) and then Ancestor_Is_Subtype_Mark then
Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
Set_Assignment_OK (Ref);
......@@ -2223,8 +2212,8 @@ package body Exp_Aggr is
and then Present (Entity (Expr))
and then Ekind (Entity (Expr)) = E_In_Parameter
and then Present (Discriminal_Link (Entity (Expr)))
and then Scope (Discriminal_Link (Entity (Expr)))
= Base_Type (Etype (N))
and then Scope (Discriminal_Link (Entity (Expr))) =
Base_Type (Etype (N))
then
Rewrite (Expr,
Make_Selected_Component (Loc,
......@@ -2596,9 +2585,7 @@ package body Exp_Aggr is
-- constructor to ensure the proper initialization of the _Tag
-- component.
if Is_CPP_Class (Root_Type (Typ))
and then CPP_Num_Prims (Typ) > 0
then
if Is_CPP_Class (Root_Type (Typ)) and then CPP_Num_Prims (Typ) > 0 then
Invoke_Constructor : declare
CPP_Parent : constant Entity_Id := Enclosing_CPP_Parent (Typ);
......@@ -3581,8 +3568,7 @@ package body Exp_Aggr is
-- See ACATS c460010 for an example.
if Hiv < Lov
or else (not Compile_Time_Known_Value (Blo)
and then Others_Present)
or else (not Compile_Time_Known_Value (Blo) and then Others_Present)
then
return False;
end if;
......@@ -3679,8 +3665,7 @@ package body Exp_Aggr is
or else Restriction_Active (No_Implicit_Loops)
or else
(Ekind (Current_Scope) = E_Package
and then
Static_Elaboration_Desired
and then Static_Elaboration_Desired
(Current_Scope))
or else Is_Preelaborated (P)
or else (Ekind (P) = E_Package_Body
......@@ -3834,9 +3819,7 @@ package body Exp_Aggr is
return;
end if;
if Is_Bit_Packed_Array (Typ)
and then not Handle_Bit_Packed
then
if Is_Bit_Packed_Array (Typ) and then not Handle_Bit_Packed then
return;
end if;
......@@ -4749,8 +4732,7 @@ package body Exp_Aggr is
elsif Nkind (Indx) = N_Function_Call
and then Is_Entity_Name (Name (Indx))
and then
Has_Pragma_Pure_Function (Entity (Name (Indx)))
and then Has_Pragma_Pure_Function (Entity (Name (Indx)))
then
return True;
......@@ -4777,8 +4759,7 @@ package body Exp_Aggr is
elsif Nkind (N) = N_Indexed_Component
and then Safe_Left_Hand_Side (Prefix (N))
and then
Is_Safe_Index (First (Expressions (N)))
and then Is_Safe_Index (First (Expressions (N)))
then
return True;
......@@ -4968,9 +4949,7 @@ package body Exp_Aggr is
-- that Convert_To_Positional succeeded and reanalyzed the rewritten
-- aggregate.
elsif Analyzed (N)
and then N /= Original_Node (N)
then
elsif Analyzed (N) and then N /= Original_Node (N) then
return;
end if;
......@@ -5165,13 +5144,21 @@ package body Exp_Aggr is
end if;
end if;
-- If a slice assignment has an aggregate with a single others_choice,
-- the assignment can be done in place even if bounds are not static,
-- by converting it into a loop over the discrete range of the slice.
elsif Maybe_In_Place_OK
and then Nkind (Name (Parent (N))) = N_Slice
and then Safe_Slice_Assignment (N)
and then Comes_From_Source (N)
and then Is_Others_Aggregate (N)
then
-- Safe_Slice_Assignment rewrites assignment as a loop
Tmp := Name (Parent (N));
return;
-- Set type of aggregate to be type of lhs in assignment, in order
-- to suppress redundant length checks.
Set_Etype (N, Etype (Tmp));
-- Step 5
......@@ -5958,9 +5945,7 @@ package body Exp_Aggr is
-- extension aggregate, the parent expr is replaced by an
-- aggregate formed by selected components of this expr.
if Present (Parent_Expr)
and then Is_Empty_List (Comps)
then
if Present (Parent_Expr) and then Is_Empty_List (Comps) then
Comp := First_Component_Or_Discriminant (Typ);
while Present (Comp) loop
......@@ -6026,8 +6011,10 @@ package body Exp_Aggr is
First_Comp := First (Component_Associations (N));
Parent_Comps := New_List;
while Present (First_Comp)
and then Scope (Original_Record_Component (
Entity (First (Choices (First_Comp))))) /= Base_Typ
and then
Scope (Original_Record_Component
(Entity (First (Choices (First_Comp))))) /=
Base_Typ
loop
Comp := First_Comp;
Next (First_Comp);
......@@ -6035,7 +6022,8 @@ package body Exp_Aggr is
Append (Comp, Parent_Comps);
end loop;
Parent_Aggr := Make_Aggregate (Loc,
Parent_Aggr :=
Make_Aggregate (Loc,
Component_Associations => Parent_Comps);
Set_Etype (Parent_Aggr, Etype (Base_Type (Typ)));
......@@ -6129,8 +6117,7 @@ package body Exp_Aggr is
Expr := Expression (C);
if Present (Expr)
and then
Nkind_In (Expr, N_Aggregate, N_Extension_Aggregate)
and then Nkind_In (Expr, N_Aggregate, N_Extension_Aggregate)
and then Has_Default_Init_Comps (Expr)
then
return True;
......@@ -6156,7 +6143,7 @@ package body Exp_Aggr is
Kind := Nkind (Node);
end if;
if Kind /= N_Aggregate and then Kind /= N_Extension_Aggregate then
if not Nkind_In (Kind, N_Aggregate, N_Extension_Aggregate) then
return False;
else
return Expansion_Delayed (Node);
......@@ -6591,8 +6578,8 @@ package body Exp_Aggr is
and then Number_Discriminants (Bas) /= Number_Discriminants (Par)
and then Nkind (Decl) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Decl)) = N_Record_Definition
and then Present
(Variant_Part (Component_List (Type_Definition (Decl))))
and then
Present (Variant_Part (Component_List (Type_Definition (Decl))))
and then Nkind (N) /= N_Extension_Aggregate
then
......@@ -6614,6 +6601,7 @@ package body Exp_Aggr is
Typ : Entity_Id) return Boolean
is
L1, L2, H1, H2 : Node_Id;
begin
-- No sliding if the type of the object is not established yet, if it is
-- an unconstrained type whose actual subtype comes from the aggregate,
......@@ -6648,70 +6636,6 @@ package body Exp_Aggr is
end if;
end Must_Slide;
---------------------------
-- Safe_Slice_Assignment --
---------------------------
function Safe_Slice_Assignment (N : Node_Id) return Boolean is
Loc : constant Source_Ptr := Sloc (Parent (N));
Pref : constant Node_Id := Prefix (Name (Parent (N)));
Range_Node : constant Node_Id := Discrete_Range (Name (Parent (N)));
Expr : Node_Id;
L_J : Entity_Id;
L_Iter : Node_Id;
L_Body : Node_Id;
Stat : Node_Id;
begin
-- Generate: for J in Range loop Pref (J) := Expr; end loop;
if Comes_From_Source (N)
and then No (Expressions (N))
and then Nkind (First (Choices (First (Component_Associations (N)))))
= N_Others_Choice
then
Expr := Expression (First (Component_Associations (N)));
L_J := Make_Temporary (Loc, 'J');
L_Iter :=
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification
(Loc,
Defining_Identifier => L_J,
Discrete_Subtype_Definition => Relocate_Node (Range_Node)));
L_Body :=
Make_Assignment_Statement (Loc,
Name =>
Make_Indexed_Component (Loc,
Prefix => Relocate_Node (Pref),
Expressions => New_List (New_Occurrence_Of (L_J, Loc))),
Expression => Relocate_Node (Expr));
-- Construct the final loop
Stat :=
Make_Implicit_Loop_Statement
(Node => Parent (N),
Identifier => Empty,
Iteration_Scheme => L_Iter,
Statements => New_List (L_Body));
-- Set type of aggregate to be type of lhs in assignment,
-- to suppress redundant length checks.
Set_Etype (N, Etype (Name (Parent (N))));
Rewrite (Parent (N), Stat);
Analyze (Parent (N));
return True;
else
return False;
end if;
end Safe_Slice_Assignment;
----------------------------------
-- Two_Dim_Packed_Array_Handled --
----------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment