-- Note that not all aspects are added to the chain of representation
-- items. In such cases, search the list of aspect specifications. First
-- find the declaration node where the aspects reside. This is usually
- -- the parent or the parent of the parent.
+ -- the parent or the parent of the parent, after getting through the
+ -- additional indirection of the N_Defining_Program_Unit_Name if needed.
if No (Parent (Owner)) then
return Empty;
end if;
Decl := Parent (Owner);
+
+ if Nkind (Decl) = N_Defining_Program_Unit_Name then
+ Decl := Parent (Decl);
+ end if;
+
if not Permits_Aspect_Specifications (Decl) then
Decl := Parent (Decl);
Set_Library_Unit (N, Lib_Unit);
Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
Make_Child_Decl_Unit (N);
- Semantics (Lib_Unit);
-- Now that a separate declaration exists, the body
-- of the child unit does not act as spec any longer.
Set_Acts_As_Spec (N, False);
Move_Aspects (From => Unit_Node, To => Unit (Lib_Unit));
+
+ -- Ensure that the generated corresponding spec and
+ -- original body share the same SPARK_Mode pragma or
+ -- aspect. As a result, both have the same SPARK_Mode
+ -- attributes, and the global SPARK_Mode value is
+ -- correctly set for local subprograms.
+
+ Copy_SPARK_Mode_Aspect (Unit (Lib_Unit), To => Unit_Node);
+
Set_Is_Child_Unit (Defining_Entity (Unit_Node));
Set_Debug_Info_Needed (Defining_Entity (Unit (Lib_Unit)));
Set_Comes_From_Source_Default (SCS);
+ Semantics (Lib_Unit);
+
-- Restore Context_Items to the body
Set_Context_Items (N, Context_Items (Lib_Unit));