Noting that you're using the separate
keyword I'm going to venture that your question is not about child units, but nested units.
Try the following:
Testing.adb
With
Ada.Text_IO,
Parent;
Procedure Testing is
Begin
Ada.Text_IO.Put_Line("Starting Test:");
Parent.Nested.Test_Procedure;
Ada.Text_IO.Put_Line("Testing complete.");
End Test;
Parent.ads
Package Parent is
Package Nested is
Procedure Test_Procedure;
End Nested;
End Parent;
Parent.adb
Package Body Parent is
Package Body Nested is separate;
End Parent;
Parent-Nested.adb
(Note: you may have to use something slightly different for the file-name, I'm using GNAT with the default settings for "dot replacement".)
with Ada.Text_IO;
separate (Parent)
package body Nested is
Procedure Test_Procedure is
Message : Constant string:= ASCII.HT &
"Hello from the separate, nested test-procedure.";
begin
Ada.Text_IO.Put_Line( Message );
end Test_Procedure;
End Nested;
You should be able to compile and the output should be three lines as follows:
Starting Test:
Hello from the separate, nested test-procedure.
Testing complete.
The problem here stems from a slight misunderstanding regarding the differences between nested and child packages. Both are accessed with the same method of dot-delimited-qualification: Parent
.Nested
and Parent
.Child
.
The subtle difference is that child-packages are always a separately compiled unit (in GNAT they are always in a different file, this is an implementation restriction due to how they [don't] implement the Library.. but some Ada compilers can put different compilation_units into the same file) -- but a nested-package must be compiled at the same time that its enclosing unit is compiled unless it is specifically tagged as separate
.
In order to preserve the current nested structure and still use separates you can use the following method with a single Auxiliary package holding all the specs for the packages.
Parent.ads
Package Parent is
-- Here's the magic of renaming. --'
Package Nested renames Auxiliary.Delegate;
End Parent;
Auxiliary.ads
Package Auxiliary is
Package Delegate is
Procedure Test_Procedure;
End Delegate;
End Auxiliary;
Auxiliary.adb
package body Auxiliary is
Package Body Delegate is separate;
end Auxiliary;
Auxiliary-Delegate.adb
(Note: you may have to use something slightly different for the file-name, I'm using GNAT with the default settings for "dot replacement".)
with Ada.Text_IO;
separate (Auxiliary)
package body Delegate is
Procedure Test_Procedure is
Message : Constant string:= ASCII.HT &
"Hello from the separate, nested test-procedure.";
begin
Ada.Text_IO.Put_Line( Message );
end Test_Procedure;
End Delegate;