+2013-09-10 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch12.adb (Analyze_Package_Instantiation): If the
+ instantiation is a compilation unit, analyze aspects before
+ analyzing the package declaration for the instance.
+ * sem_ch13.adb (Analyze_Aspect_Specifications): If the
+ corresponding node is a package instantiation, insert generated
+ pragmas at the head of visible declarations.
+ * sem_prag.adb (Analyze_Pragma, case Preelaborate): In an instance
+ do not ignore the pragma if it comes from an aspect specification
+ in the instance, and not from the generic unit.
+ * sprint.adb (Sprint_Node_Actual): For a package declaration that
+ is an instantiation, print aspects after declaration.
+
2013-09-10 Robert Dewar <dewar@adacore.com>
* einfo.adb, sem_prag.adb, rtsfind.ads: Minor reformatting.
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
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);
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;
-- 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))
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);
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;
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 ");
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");