+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.
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.
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
-- 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.
-- 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
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;
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);
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);