===================================================================
@@ -15144,16 +15144,22 @@
Ent := Find_Lib_Unit_Name;
Check_Duplicate_Pragma (Ent);
- -- This filters out pragmas inside generic parent then
- -- show up inside instantiation
+ -- This filters out pragmas inside generic parents that show up
+ -- inside instantiations. Pragmas that come from aspects in the
+ -- unit are not ignored.
- if Present (Ent)
- and then not (Pk = N_Package_Specification
- and then Present (Generic_Parent (Pa)))
- then
- if not Debug_Flag_U then
- Set_Is_Preelaborated (Ent);
- Set_Suppress_Elaboration_Warnings (Ent);
+ if Present (Ent) then
+ if Pk = N_Package_Specification
+ and then Present (Generic_Parent (Pa))
+ and then not From_Aspect_Specification (N)
+ then
+ null;
+
+ else
+ if not Debug_Flag_U then
+ Set_Is_Preelaborated (Ent);
+ Set_Suppress_Elaboration_Warnings (Ent);
+ end if;
end if;
end if;
end Preelaborate;
===================================================================
@@ -3912,6 +3912,7 @@
if Nkind (Parent (N)) /= N_Compilation_Unit then
Mark_Rewrite_Insertion (Act_Decl);
Insert_Before (N, Act_Decl);
+
Analyze (Act_Decl);
-- For an instantiation that is a compilation unit, place
@@ -3940,6 +3941,15 @@
Set_Unit (Parent (N), Act_Decl);
Set_Parent_Spec (Act_Decl, Parent_Spec (N));
Set_Package_Instantiation (Act_Decl_Id, N);
+
+ -- Process aspect specifications of the instance node, if any, to
+ -- take into account categorization pragmas before analyzing the
+ -- instance.
+
+ if Has_Aspects (N) then
+ Analyze_Aspect_Specifications (N, Act_Decl_Id);
+ end if;
+
Analyze (Act_Decl);
Set_Unit (Parent (N), N);
Set_Body_Required (Parent (N), False);
@@ -4043,7 +4053,7 @@
end if;
<<Leave>>
- if Has_Aspects (N) then
+ if Has_Aspects (N) and then Nkind (Parent (N)) /= N_Compilation_Unit then
Analyze_Aspect_Specifications (N, Act_Decl_Id);
end if;
===================================================================
@@ -2479,6 +2479,18 @@
Sprint_Node_Sloc (Specification (Node));
Write_Char (';');
+ -- If this is an instantiation, get the aspects from the original
+ -- instantiation node.
+
+ if Is_Generic_Instance (Defining_Entity (Node))
+ and then Has_Aspects (
+ Package_Instantiation (Defining_Entity (Node)))
+ then
+ Sprint_Aspect_Specifications
+ (Package_Instantiation (Defining_Entity (Node)),
+ Semicolon => True);
+ end if;
+
when N_Package_Instantiation =>
Extra_Blank_Line;
Write_Indent_Str_Sloc ("package ");
@@ -2499,12 +2511,27 @@
Write_Str_With_Col_Check_Sloc ("package ");
Sprint_Node (Defining_Unit_Name (Node));
- if Nkind_In (Parent (Node), N_Package_Declaration,
- N_Generic_Package_Declaration)
+ if Nkind (Parent (Node)) = N_Generic_Package_Declaration
and then Has_Aspects (Parent (Node))
then
Sprint_Aspect_Specifications
(Parent (Node), Semicolon => False);
+
+ -- An instantiation is rewritten as a package declaration, but
+ -- the aspects belong to the instantiation node.
+
+ elsif Nkind (Parent (Node)) = N_Package_Declaration then
+ declare
+ Pack : constant Entity_Id := Defining_Entity (Node);
+
+ begin
+ if not Is_Generic_Instance (Pack) then
+ if Has_Aspects (Parent (Node)) then
+ Sprint_Aspect_Specifications
+ (Parent (Node), Semicolon => False);
+ end if;
+ end if;
+ end;
end if;
Write_Str (" is");
===================================================================
@@ -2112,7 +2112,8 @@
-- node (no delay is required here) except for aspects on a
-- subprogram body (see below) and a generic package, for which
-- we need to introduce the pragma before building the generic
- -- copy (see sem_ch12).
+ -- copy (see sem_ch12), and for package instantiations, where
+ -- the library unit pragmas are better handled early.
elsif Nkind (Parent (N)) = N_Compilation_Unit
and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
@@ -2161,6 +2162,18 @@
Prepend (Aitem,
Visible_Declarations (Specification (N)));
+ elsif Nkind (N) = N_Package_Instantiation then
+ declare
+ Spec : constant Node_Id :=
+ Specification (Instance_Spec (N));
+ begin
+ if No (Visible_Declarations (Spec)) then
+ Set_Visible_Declarations (Spec, New_List);
+ end if;
+
+ Prepend (Aitem, Visible_Declarations (Spec));
+ end;
+
else
if No (Pragmas_After (Aux)) then
Set_Pragmas_After (Aux, New_List);