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> 2014-07-29 Robert Dewar <dewar@adacore.com>
* sem_util.adb, sem_util.ads, sem_res.adb, exp_ch6.adb: Invert * sem_util.adb, sem_util.ads, sem_res.adb, exp_ch6.adb: Invert
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- 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 -- -- 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- -- -- 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 ...@@ -96,10 +96,6 @@ package body Ada.Containers.Bounded_Multiway_Trees is
procedure Allocate_Node procedure Allocate_Node
(Container : in out Tree; (Container : in out Tree;
New_Node : out Count_Type);
procedure Allocate_Node
(Container : in out Tree;
Stream : not null access Root_Stream_Type'Class; Stream : not null access Root_Stream_Type'Class;
New_Node : out Count_Type); New_Node : out Count_Type);
...@@ -318,15 +314,6 @@ package body Ada.Containers.Bounded_Multiway_Trees is ...@@ -318,15 +314,6 @@ package body Ada.Containers.Bounded_Multiway_Trees is
Allocate_Node (Container, Initialize_Element'Access, New_Node); Allocate_Node (Container, Initialize_Element'Access, New_Node);
end Allocate_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 -- -- Ancestor_Find --
------------------- -------------------
...@@ -1583,6 +1570,7 @@ package body Ada.Containers.Bounded_Multiway_Trees is ...@@ -1583,6 +1570,7 @@ package body Ada.Containers.Bounded_Multiway_Trees is
Count : Count_Type := 1) Count : Count_Type := 1)
is is
Nodes : Tree_Node_Array renames Container.Nodes; Nodes : Tree_Node_Array renames Container.Nodes;
First : Count_Type;
Last : Count_Type; Last : Count_Type;
New_Item : Element_Type; New_Item : Element_Type;
...@@ -1634,11 +1622,12 @@ package body Ada.Containers.Bounded_Multiway_Trees is ...@@ -1634,11 +1622,12 @@ package body Ada.Containers.Bounded_Multiway_Trees is
-- initialized elements at the given position. -- initialized elements at the given position.
Allocate_Node (Container, New_Item, Position.Node); Allocate_Node (Container, New_Item, Position.Node);
First := Position.Node;
Nodes (Position.Node).Parent := Parent.Node; Nodes (Position.Node).Parent := Parent.Node;
Last := Position.Node; Last := Position.Node;
for J in Count_Type'(2) .. Count loop 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).Parent := Parent.Node;
Nodes (Nodes (Last).Next).Prev := Last; Nodes (Nodes (Last).Next).Prev := Last;
...@@ -1654,7 +1643,7 @@ package body Ada.Containers.Bounded_Multiway_Trees is ...@@ -1654,7 +1643,7 @@ package body Ada.Containers.Bounded_Multiway_Trees is
Container.Count := Container.Count + Count; Container.Count := Container.Count + Count;
Position.Container := Parent.Container; Position := Cursor'(Parent.Container, First);
end Insert_Child; end Insert_Child;
------------------------- -------------------------
......
...@@ -289,11 +289,6 @@ package body Exp_Aggr is ...@@ -289,11 +289,6 @@ package body Exp_Aggr is
-- If this transformation is not possible, N is unchanged and False is -- If this transformation is not possible, N is unchanged and False is
-- returned. -- 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; function Two_Dim_Packed_Array_Handled (N : Node_Id) return Boolean;
-- If the type of the aggregate is a two-dimensional bit_packed array -- 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, -- it may be transformed into an array of bytes with constant values,
...@@ -404,8 +399,8 @@ package body Exp_Aggr is ...@@ -404,8 +399,8 @@ package body Exp_Aggr is
elsif Restriction_Active (No_Elaboration_Code) elsif Restriction_Active (No_Elaboration_Code)
or else Restriction_Active (No_Implicit_Loops) or else Restriction_Active (No_Implicit_Loops)
or else Is_Two_Dim_Packed_Array (Typ) or else Is_Two_Dim_Packed_Array (Typ)
or else ((Ekind (Current_Scope) = E_Package or else (Ekind (Current_Scope) = E_Package
and then Static_Elaboration_Desired (Current_Scope))) and then Static_Elaboration_Desired (Current_Scope))
then then
Max_Aggr_Size := 2 ** 24; Max_Aggr_Size := 2 ** 24;
...@@ -443,9 +438,7 @@ package body Exp_Aggr is ...@@ -443,9 +438,7 @@ package body Exp_Aggr is
-- is an object declaration with non-static bounds it will trip gcc; -- is an object declaration with non-static bounds it will trip gcc;
-- such an aggregate must be expanded into a single assignment. -- such an aggregate must be expanded into a single assignment.
if Hiv = Lov if Hiv = Lov and then Nkind (Parent (N)) = N_Object_Declaration then
and then Nkind (Parent (N)) = N_Object_Declaration
then
declare declare
Index_Type : constant Entity_Id := Index_Type : constant Entity_Id :=
Etype Etype
...@@ -934,7 +927,8 @@ package body Exp_Aggr is ...@@ -934,7 +927,8 @@ package body Exp_Aggr is
end case; end case;
if Local_Compile_Time_Known_Value (Low) if Local_Compile_Time_Known_Value (Low)
and then Local_Compile_Time_Known_Value (High) and then
Local_Compile_Time_Known_Value (High)
then then
Is_Empty := Is_Empty :=
UI_Gt (Local_Expr_Value (Low), Local_Expr_Value (High)); UI_Gt (Local_Expr_Value (Low), Local_Expr_Value (High));
...@@ -956,7 +950,8 @@ package body Exp_Aggr is ...@@ -956,7 +950,8 @@ package body Exp_Aggr is
return True; return True;
elsif Local_Compile_Time_Known_Value (L) elsif Local_Compile_Time_Known_Value (L)
and then Local_Compile_Time_Known_Value (H) and then
Local_Compile_Time_Known_Value (H)
then then
return UI_Eq (Local_Expr_Value (L), Local_Expr_Value (H)); return UI_Eq (Local_Expr_Value (L), Local_Expr_Value (H));
end if; end if;
...@@ -1053,9 +1048,7 @@ package body Exp_Aggr is ...@@ -1053,9 +1048,7 @@ package body Exp_Aggr is
Expr_Q := Expr; Expr_Q := Expr;
end if; end if;
if Present (Etype (N)) if Present (Etype (N)) and then Etype (N) /= Any_Composite then
and then Etype (N) /= Any_Composite
then
Comp_Type := Component_Type (Etype (N)); Comp_Type := Component_Type (Etype (N));
pragma Assert (Comp_Type = Ctype); -- AI-287 pragma Assert (Comp_Type = Ctype); -- AI-287
...@@ -1070,9 +1063,9 @@ package body Exp_Aggr is ...@@ -1070,9 +1063,9 @@ package body Exp_Aggr is
if Present (Expr) then if Present (Expr) then
-- This is a multidimensional array. Recover the component -- This is a multidimensional array. Recover the component type
-- type from the outermost aggregate, because subaggregates -- from the outermost aggregate, because subaggregates do not
-- do not have an assigned type. -- have an assigned type.
declare declare
P : Node_Id; P : Node_Id;
...@@ -1621,9 +1614,7 @@ package body Exp_Aggr is ...@@ -1621,9 +1614,7 @@ package body Exp_Aggr is
-- entity in the current scope, because it will be needed if build- -- entity in the current scope, because it will be needed if build-
-- in-place functions are called in the expanded code. -- in-place functions are called in the expanded code.
if Nkind (Parent (N)) = N_Object_Declaration if Nkind (Parent (N)) = N_Object_Declaration and then Has_Task (Typ) then
and then Has_Task (Typ)
then
Build_Master_Entity (Defining_Identifier (Parent (N))); Build_Master_Entity (Defining_Identifier (Parent (N)));
end if; end if;
...@@ -2189,9 +2180,7 @@ package body Exp_Aggr is ...@@ -2189,9 +2180,7 @@ package body Exp_Aggr is
-- proper scope is the scope of the target rather than the -- proper scope is the scope of the target rather than the
-- potentially transient current scope. -- potentially transient current scope.
if Is_Controlled (Typ) if Is_Controlled (Typ) and then Ancestor_Is_Subtype_Mark then
and then Ancestor_Is_Subtype_Mark
then
Ref := Convert_To (Init_Typ, New_Copy_Tree (Target)); Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
Set_Assignment_OK (Ref); Set_Assignment_OK (Ref);
...@@ -2223,8 +2212,8 @@ package body Exp_Aggr is ...@@ -2223,8 +2212,8 @@ package body Exp_Aggr is
and then Present (Entity (Expr)) and then Present (Entity (Expr))
and then Ekind (Entity (Expr)) = E_In_Parameter and then Ekind (Entity (Expr)) = E_In_Parameter
and then Present (Discriminal_Link (Entity (Expr))) and then Present (Discriminal_Link (Entity (Expr)))
and then Scope (Discriminal_Link (Entity (Expr))) and then Scope (Discriminal_Link (Entity (Expr))) =
= Base_Type (Etype (N)) Base_Type (Etype (N))
then then
Rewrite (Expr, Rewrite (Expr,
Make_Selected_Component (Loc, Make_Selected_Component (Loc,
...@@ -2596,9 +2585,7 @@ package body Exp_Aggr is ...@@ -2596,9 +2585,7 @@ package body Exp_Aggr is
-- constructor to ensure the proper initialization of the _Tag -- constructor to ensure the proper initialization of the _Tag
-- component. -- component.
if Is_CPP_Class (Root_Type (Typ)) if Is_CPP_Class (Root_Type (Typ)) and then CPP_Num_Prims (Typ) > 0 then
and then CPP_Num_Prims (Typ) > 0
then
Invoke_Constructor : declare Invoke_Constructor : declare
CPP_Parent : constant Entity_Id := Enclosing_CPP_Parent (Typ); CPP_Parent : constant Entity_Id := Enclosing_CPP_Parent (Typ);
...@@ -3581,8 +3568,7 @@ package body Exp_Aggr is ...@@ -3581,8 +3568,7 @@ package body Exp_Aggr is
-- See ACATS c460010 for an example. -- See ACATS c460010 for an example.
if Hiv < Lov if Hiv < Lov
or else (not Compile_Time_Known_Value (Blo) or else (not Compile_Time_Known_Value (Blo) and then Others_Present)
and then Others_Present)
then then
return False; return False;
end if; end if;
...@@ -3679,8 +3665,7 @@ package body Exp_Aggr is ...@@ -3679,8 +3665,7 @@ package body Exp_Aggr is
or else Restriction_Active (No_Implicit_Loops) or else Restriction_Active (No_Implicit_Loops)
or else or else
(Ekind (Current_Scope) = E_Package (Ekind (Current_Scope) = E_Package
and then and then Static_Elaboration_Desired
Static_Elaboration_Desired
(Current_Scope)) (Current_Scope))
or else Is_Preelaborated (P) or else Is_Preelaborated (P)
or else (Ekind (P) = E_Package_Body or else (Ekind (P) = E_Package_Body
...@@ -3834,9 +3819,7 @@ package body Exp_Aggr is ...@@ -3834,9 +3819,7 @@ package body Exp_Aggr is
return; return;
end if; end if;
if Is_Bit_Packed_Array (Typ) if Is_Bit_Packed_Array (Typ) and then not Handle_Bit_Packed then
and then not Handle_Bit_Packed
then
return; return;
end if; end if;
...@@ -4749,8 +4732,7 @@ package body Exp_Aggr is ...@@ -4749,8 +4732,7 @@ package body Exp_Aggr is
elsif Nkind (Indx) = N_Function_Call elsif Nkind (Indx) = N_Function_Call
and then Is_Entity_Name (Name (Indx)) and then Is_Entity_Name (Name (Indx))
and then and then Has_Pragma_Pure_Function (Entity (Name (Indx)))
Has_Pragma_Pure_Function (Entity (Name (Indx)))
then then
return True; return True;
...@@ -4777,8 +4759,7 @@ package body Exp_Aggr is ...@@ -4777,8 +4759,7 @@ package body Exp_Aggr is
elsif Nkind (N) = N_Indexed_Component elsif Nkind (N) = N_Indexed_Component
and then Safe_Left_Hand_Side (Prefix (N)) and then Safe_Left_Hand_Side (Prefix (N))
and then and then Is_Safe_Index (First (Expressions (N)))
Is_Safe_Index (First (Expressions (N)))
then then
return True; return True;
...@@ -4968,9 +4949,7 @@ package body Exp_Aggr is ...@@ -4968,9 +4949,7 @@ package body Exp_Aggr is
-- that Convert_To_Positional succeeded and reanalyzed the rewritten -- that Convert_To_Positional succeeded and reanalyzed the rewritten
-- aggregate. -- aggregate.
elsif Analyzed (N) elsif Analyzed (N) and then N /= Original_Node (N) then
and then N /= Original_Node (N)
then
return; return;
end if; end if;
...@@ -5165,13 +5144,21 @@ package body Exp_Aggr is ...@@ -5165,13 +5144,21 @@ package body Exp_Aggr is
end if; end if;
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 elsif Maybe_In_Place_OK
and then Nkind (Name (Parent (N))) = N_Slice 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 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 -- Step 5
...@@ -5958,9 +5945,7 @@ package body Exp_Aggr is ...@@ -5958,9 +5945,7 @@ package body Exp_Aggr is
-- extension aggregate, the parent expr is replaced by an -- extension aggregate, the parent expr is replaced by an
-- aggregate formed by selected components of this expr. -- aggregate formed by selected components of this expr.
if Present (Parent_Expr) if Present (Parent_Expr) and then Is_Empty_List (Comps) then
and then Is_Empty_List (Comps)
then
Comp := First_Component_Or_Discriminant (Typ); Comp := First_Component_Or_Discriminant (Typ);
while Present (Comp) loop while Present (Comp) loop
...@@ -6026,8 +6011,10 @@ package body Exp_Aggr is ...@@ -6026,8 +6011,10 @@ package body Exp_Aggr is
First_Comp := First (Component_Associations (N)); First_Comp := First (Component_Associations (N));
Parent_Comps := New_List; Parent_Comps := New_List;
while Present (First_Comp) while Present (First_Comp)
and then Scope (Original_Record_Component ( and then
Entity (First (Choices (First_Comp))))) /= Base_Typ Scope (Original_Record_Component
(Entity (First (Choices (First_Comp))))) /=
Base_Typ
loop loop
Comp := First_Comp; Comp := First_Comp;
Next (First_Comp); Next (First_Comp);
...@@ -6035,7 +6022,8 @@ package body Exp_Aggr is ...@@ -6035,7 +6022,8 @@ package body Exp_Aggr is
Append (Comp, Parent_Comps); Append (Comp, Parent_Comps);
end loop; end loop;
Parent_Aggr := Make_Aggregate (Loc, Parent_Aggr :=
Make_Aggregate (Loc,
Component_Associations => Parent_Comps); Component_Associations => Parent_Comps);
Set_Etype (Parent_Aggr, Etype (Base_Type (Typ))); Set_Etype (Parent_Aggr, Etype (Base_Type (Typ)));
...@@ -6129,8 +6117,7 @@ package body Exp_Aggr is ...@@ -6129,8 +6117,7 @@ package body Exp_Aggr is
Expr := Expression (C); Expr := Expression (C);
if Present (Expr) if Present (Expr)
and then and then Nkind_In (Expr, N_Aggregate, N_Extension_Aggregate)
Nkind_In (Expr, N_Aggregate, N_Extension_Aggregate)
and then Has_Default_Init_Comps (Expr) and then Has_Default_Init_Comps (Expr)
then then
return True; return True;
...@@ -6156,7 +6143,7 @@ package body Exp_Aggr is ...@@ -6156,7 +6143,7 @@ package body Exp_Aggr is
Kind := Nkind (Node); Kind := Nkind (Node);
end if; 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; return False;
else else
return Expansion_Delayed (Node); return Expansion_Delayed (Node);
...@@ -6591,8 +6578,8 @@ package body Exp_Aggr is ...@@ -6591,8 +6578,8 @@ package body Exp_Aggr is
and then Number_Discriminants (Bas) /= Number_Discriminants (Par) and then Number_Discriminants (Bas) /= Number_Discriminants (Par)
and then Nkind (Decl) = N_Full_Type_Declaration and then Nkind (Decl) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Decl)) = N_Record_Definition and then Nkind (Type_Definition (Decl)) = N_Record_Definition
and then Present and then
(Variant_Part (Component_List (Type_Definition (Decl)))) Present (Variant_Part (Component_List (Type_Definition (Decl))))
and then Nkind (N) /= N_Extension_Aggregate and then Nkind (N) /= N_Extension_Aggregate
then then
...@@ -6614,6 +6601,7 @@ package body Exp_Aggr is ...@@ -6614,6 +6601,7 @@ package body Exp_Aggr is
Typ : Entity_Id) return Boolean Typ : Entity_Id) return Boolean
is is
L1, L2, H1, H2 : Node_Id; L1, L2, H1, H2 : Node_Id;
begin begin
-- No sliding if the type of the object is not established yet, if it is -- 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, -- an unconstrained type whose actual subtype comes from the aggregate,
...@@ -6648,70 +6636,6 @@ package body Exp_Aggr is ...@@ -6648,70 +6636,6 @@ package body Exp_Aggr is
end if; end if;
end Must_Slide; 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 -- -- 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