Commit 136236bd by Javier Miranda Committed by Arnaud Charlet

sem_ch7.adb (Analyze_Package_Specification): Insert its freezing nodes after the last declaration.

2016-07-06  Javier Miranda  <miranda@adacore.com>

	* sem_ch7.adb (Analyze_Package_Specification): Insert its
	freezing nodes after the last declaration. Needed to ensure
	that global entities referenced in aspects of frozen types are
	properly handled.
	* freeze.adb (Freeze_Entity): Minor code reorganization to ensure
	that freezing nodes of generic packages are handled.
	* sem_ch13.adb (Freeze_Entity_Checks): Handle N_Freeze_Generic nodes.
	* sem_ch12.adb (Save_References_In_Identifier): Handle selected
	components which denote a named number that is constant folded
	in the analyzed copy of the tree.

From-SVN: r238047
parent 9df99881
2016-07-06 Javier Miranda <miranda@adacore.com>
* sem_ch7.adb (Analyze_Package_Specification): Insert its
freezing nodes after the last declaration. Needed to ensure
that global entities referenced in aspects of frozen types are
properly handled.
* freeze.adb (Freeze_Entity): Minor code reorganization to ensure
that freezing nodes of generic packages are handled.
* sem_ch13.adb (Freeze_Entity_Checks): Handle N_Freeze_Generic nodes.
* sem_ch12.adb (Save_References_In_Identifier): Handle selected
components which denote a named number that is constant folded
in the analyzed copy of the tree.
2016-07-06 Hristian Kirtchev <kirtchev@adacore.com> 2016-07-06 Hristian Kirtchev <kirtchev@adacore.com>
* exp_aggr.adb Remove with and use clauses for Exp_Ch11 and Inline. * exp_aggr.adb Remove with and use clauses for Exp_Ch11 and Inline.
......
...@@ -4945,6 +4945,12 @@ package body Freeze is ...@@ -4945,6 +4945,12 @@ package body Freeze is
Ghost_Mode := Save_Ghost_Mode; Ghost_Mode := Save_Ghost_Mode;
return No_List; return No_List;
elsif Ekind (E) = E_Generic_Package then
Result := Freeze_Generic_Entities (E);
Ghost_Mode := Save_Ghost_Mode;
return Result;
-- It is improper to freeze an external entity within a generic because -- It is improper to freeze an external entity within a generic because
-- its freeze node will appear in a non-valid context. The entity will -- its freeze node will appear in a non-valid context. The entity will
-- be frozen in the proper scope after the current generic is analyzed. -- be frozen in the proper scope after the current generic is analyzed.
...@@ -5054,12 +5060,6 @@ package body Freeze is ...@@ -5054,12 +5060,6 @@ package body Freeze is
return No_List; return No_List;
end if; end if;
end; end;
elsif Ekind (E) = E_Generic_Package then
Result := Freeze_Generic_Entities (E);
Ghost_Mode := Save_Ghost_Mode;
return Result;
end if; end if;
-- Add checks to detect proper initialization of scalars that may appear -- Add checks to detect proper initialization of scalars that may appear
......
...@@ -14860,14 +14860,41 @@ package body Sem_Ch12 is ...@@ -14860,14 +14860,41 @@ package body Sem_Ch12 is
-- The node did not undergo a transformation -- The node did not undergo a transformation
if Nkind (N) = Nkind (Get_Associated_Node (N)) then if Nkind (N) = Nkind (Get_Associated_Node (N)) then
declare
Aux_N2 : constant Node_Id := Get_Associated_Node (N);
Orig_N2_Parent : constant Node_Id :=
Original_Node (Parent (Aux_N2));
begin
-- The parent of this identifier is a selected component
-- which denotes a named number that was constant folded.
-- Preserve the original name for ASIS and link the parent
-- with its expanded name. The constant folding will be
-- repeated in the instance.
-- If this is a discriminant reference, always save it. It is if Nkind (Parent (N)) = N_Selected_Component
-- used in the instance to find the corresponding discriminant and then Nkind_In (Parent (Aux_N2), N_Integer_Literal,
-- positionally rather than by name. N_Real_Literal)
and then Is_Entity_Name (Orig_N2_Parent)
and then Ekind (Entity (Orig_N2_Parent)) in Named_Kind
and then Is_Global (Entity (Orig_N2_Parent))
then
N2 := Aux_N2;
Set_Associated_Node (Parent (N),
Original_Node (Parent (N2)));
-- Common case
else
-- If this is a discriminant reference, always save it.
-- It is used in the instance to find the corresponding
-- discriminant positionally rather than by name.
Set_Original_Discriminant Set_Original_Discriminant
(N, Original_Discriminant (Get_Associated_Node (N))); (N, Original_Discriminant (Get_Associated_Node (N)));
end if;
Reset_Entity (N); Reset_Entity (N);
end;
-- The analysis of the generic copy transformed the identifier -- The analysis of the generic copy transformed the identifier
-- into another construct. Propagate the changes to the template. -- into another construct. Propagate the changes to the template.
......
...@@ -10789,10 +10789,20 @@ package body Sem_Ch13 is ...@@ -10789,10 +10789,20 @@ package body Sem_Ch13 is
-- the subtype name in the saved expression so that they will not cause -- the subtype name in the saved expression so that they will not cause
-- trouble in the preanalysis. -- trouble in the preanalysis.
-- This is also not needed in the generic case -- Case 1: Generic case. For freezing nodes of types defined in generics
-- we must perform the analysis of its aspects; needed to ensure that
-- they have the minimum decoration needed by ASIS.
if Non_Generic_Case if not Non_Generic_Case then
and then Has_Delayed_Aspects (E) if Has_Delayed_Aspects (E) then
Push_Scope (Scope (E));
Analyze_Aspects_At_Freeze_Point (E);
Pop_Scope;
end if;
-- Case 2: Non-generic case
elsif Has_Delayed_Aspects (E)
and then Scope (E) = Current_Scope and then Scope (E) = Current_Scope
then then
-- Retrieve the visibility to the discriminants in order to properly -- Retrieve the visibility to the discriminants in order to properly
......
...@@ -39,6 +39,7 @@ with Exp_Ch7; use Exp_Ch7; ...@@ -39,6 +39,7 @@ with Exp_Ch7; use Exp_Ch7;
with Exp_Disp; use Exp_Disp; with Exp_Disp; use Exp_Disp;
with Exp_Dist; use Exp_Dist; with Exp_Dist; use Exp_Dist;
with Exp_Dbug; use Exp_Dbug; with Exp_Dbug; use Exp_Dbug;
with Freeze; use Freeze;
with Ghost; use Ghost; with Ghost; use Ghost;
with Lib; use Lib; with Lib; use Lib;
with Lib.Xref; use Lib.Xref; with Lib.Xref; use Lib.Xref;
...@@ -1502,7 +1503,20 @@ package body Sem_Ch7 is ...@@ -1502,7 +1503,20 @@ package body Sem_Ch7 is
declare declare
Orig_Spec : constant Node_Id := Specification (Orig_Decl); Orig_Spec : constant Node_Id := Specification (Orig_Decl);
Save_Priv : constant List_Id := Private_Declarations (Orig_Spec); Save_Priv : constant List_Id := Private_Declarations (Orig_Spec);
begin begin
-- Insert the freezing nodes after the visible declarations to
-- ensure that we analyze its aspects; needed to ensure that
-- global entities referenced in the aspects are properly handled.
if Ada_Version >= Ada_2012
and then Is_Non_Empty_List (Vis_Decls)
and then Is_Empty_List (Priv_Decls)
then
Insert_List_After_And_Analyze
(Last (Vis_Decls), Freeze_Entity (Id, Last (Vis_Decls)));
end if;
Set_Private_Declarations (Orig_Spec, Empty_List); Set_Private_Declarations (Orig_Spec, Empty_List);
Save_Global_References (Orig_Decl); Save_Global_References (Orig_Decl);
Set_Private_Declarations (Orig_Spec, Save_Priv); Set_Private_Declarations (Orig_Spec, Save_Priv);
...@@ -1690,6 +1704,17 @@ package body Sem_Ch7 is ...@@ -1690,6 +1704,17 @@ package body Sem_Ch7 is
Generic_Formal_Declarations (Orig_Decl); Generic_Formal_Declarations (Orig_Decl);
begin begin
-- Insert the freezing nodes after the private declarations to
-- ensure that we analyze its aspects; needed to ensure that
-- global entities referenced in the aspects are properly handled.
if Ada_Version >= Ada_2012
and then Is_Non_Empty_List (Priv_Decls)
then
Insert_List_After_And_Analyze
(Last (Priv_Decls), Freeze_Entity (Id, Last (Priv_Decls)));
end if;
Set_Visible_Declarations (Orig_Spec, Empty_List); Set_Visible_Declarations (Orig_Spec, Empty_List);
Set_Generic_Formal_Declarations (Orig_Decl, Empty_List); Set_Generic_Formal_Declarations (Orig_Decl, Empty_List);
Save_Global_References (Orig_Decl); Save_Global_References (Orig_Decl);
......
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