diff options
author | Javier Miranda <miranda@adacore.com> | 2016-07-06 13:14:25 +0000 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2016-07-06 15:14:25 +0200 |
commit | 136236bd31f5244bba8fa063c7d159c07422c018 (patch) | |
tree | 07aa09f80817cdabd6d94d2c53f2f2947e11a1e3 /gcc | |
parent | 9df9988191cbf8562a4e422ff3ea1198fad42e46 (diff) | |
download | gcc-136236bd31f5244bba8fa063c7d159c07422c018.zip gcc-136236bd31f5244bba8fa063c7d159c07422c018.tar.gz gcc-136236bd31f5244bba8fa063c7d159c07422c018.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/ada/freeze.adb | 12 | ||||
-rw-r--r-- | gcc/ada/sem_ch12.adb | 39 | ||||
-rw-r--r-- | gcc/ada/sem_ch13.adb | 16 | ||||
-rw-r--r-- | gcc/ada/sem_ch7.adb | 25 |
5 files changed, 90 insertions, 15 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 764ba8d..8e8a370 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,16 @@ +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> * exp_aggr.adb Remove with and use clauses for Exp_Ch11 and Inline. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 3d6dd18..12f60a0 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -4945,6 +4945,12 @@ package body Freeze is Ghost_Mode := Save_Ghost_Mode; 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 -- 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. @@ -5054,12 +5060,6 @@ package body Freeze is return No_List; end if; end; - - elsif Ekind (E) = E_Generic_Package then - Result := Freeze_Generic_Entities (E); - - Ghost_Mode := Save_Ghost_Mode; - return Result; end if; -- Add checks to detect proper initialization of scalars that may appear diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index d600d27..d79a845 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -14860,14 +14860,41 @@ package body Sem_Ch12 is -- The node did not undergo a transformation 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 Nkind (Parent (N)) = N_Selected_Component + and then Nkind_In (Parent (Aux_N2), N_Integer_Literal, + 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))); - -- 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. + -- Common case - Set_Original_Discriminant - (N, Original_Discriminant (Get_Associated_Node (N))); - Reset_Entity (N); + 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 + (N, Original_Discriminant (Get_Associated_Node (N))); + end if; + + Reset_Entity (N); + end; -- The analysis of the generic copy transformed the identifier -- into another construct. Propagate the changes to the template. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index ccb3233..aad9f68 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -10789,10 +10789,20 @@ package body Sem_Ch13 is -- the subtype name in the saved expression so that they will not cause -- 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 not Non_Generic_Case then + 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 - if Non_Generic_Case - and then Has_Delayed_Aspects (E) + elsif Has_Delayed_Aspects (E) and then Scope (E) = Current_Scope then -- Retrieve the visibility to the discriminants in order to properly diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index eeb7a75..4a3b2de0 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -39,6 +39,7 @@ with Exp_Ch7; use Exp_Ch7; with Exp_Disp; use Exp_Disp; with Exp_Dist; use Exp_Dist; with Exp_Dbug; use Exp_Dbug; +with Freeze; use Freeze; with Ghost; use Ghost; with Lib; use Lib; with Lib.Xref; use Lib.Xref; @@ -1502,7 +1503,20 @@ package body Sem_Ch7 is declare Orig_Spec : constant Node_Id := Specification (Orig_Decl); Save_Priv : constant List_Id := Private_Declarations (Orig_Spec); + 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); Save_Global_References (Orig_Decl); Set_Private_Declarations (Orig_Spec, Save_Priv); @@ -1690,6 +1704,17 @@ package body Sem_Ch7 is Generic_Formal_Declarations (Orig_Decl); 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_Generic_Formal_Declarations (Orig_Decl, Empty_List); Save_Global_References (Orig_Decl); |