Search code examples
adaada95

Is is possible to have a child package as a separate compilation unit in Ada


I have a main package with a normal spec and body file. I am trying to create child packages of the parent, but want them in a separate compilation file(s). I can easily get it done if it is just a package body, or if it is a subprogram/proc/func. However, I can't get it to let me make a child spec file.

The reason I am doing this is because I want to have information in a child that is available to other children of the same parent. I know I can do this by just including the spec portion in the parent, but that is making my parent file pretty big.

Is this even possible, or do I have no choice but to make another root unit? Or just leave everything spec wise in the parent?

I tried:

in parent: package Child1 is separate; (also tried Parent.Child1 but that gave compiles errors

in child:

separate(Parent)

package Parent.Child1 is
....
end Parent.Child1;

Ideas? Just not possible?

Update: I am compiling with Green Hills Multi Compiler. Ada95 language version, non-OO project.


Solution

  • Yes, this is totally fine. You can have your parent and child packages in separate files:

    parent.ads

    package Parent is
    -- ...
    end Parent;
    

    parent-child.ads

    package Parent.Child is
    -- ...
    end Parent.Child;
    

    parent-other.ads:

    limited with Parent.Child; --Need Ada 2005
    package Parent.Other is
    -- ...
    end Parent.Other;
    

    The parent.child package and the parent.other package have access to definitions in parent (with some limitations).

    Notice how parent.other "withs" parent.child so that it has access to the definitions in parent.child.

    I have an example of how it can be done. Also, here is an example from wikibooks.