From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Parent/child dependencies and internal library units Date: Wed, 23 Jul 2014 17:47:55 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="f008dfb2a20cab2735f9b6a28e892fd7"; logging-data="28714"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WbOLbhyn/N4OC0/G5jCoLV/qFwGWErp0=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:94pgsNd9Q51t5QJIOsn2nqChpTo= sha1:4H8I2NQ56CiDkKvA8t+v2mMXZPI= Xref: news.eternal-september.org comp.lang.ada:21159 Date: 2014-07-23T17:47:55+01:00 List-Id: Victor Porton writes: > I noticed that child units depend on their parents. > > As such making parent dependent on a child makes a dependency loop. > > Before noting this feature of Ada language, I thought parent units could be > implemented based on their child units, but that does not work, because > making parents dependent on children is a circular dependency. > > So, my question: > > What is a good way to create "internal" or "implementation" units for a > unit? Should I create a *.Internal.* hierarchy of packages? I dare say there are uses which could make this not work (possibly involving initialisation of objects in specs via function calls, leading to access-before-elaboration) but you can make a parent body depend on a child spec. If the implementation is meant to be hidden from users outside the parent, consider using private child packages. package Hierarchy is procedure Tell; end Hierarchy; private package Hierarchy.Internal is procedure Tell; end Hierarchy.Internal; with Ada.Text_IO; package body Hierarchy.Internal is procedure Tell is begin Ada.Text_IO.Put_Line ("Hierarchy.Internal"); end Tell; end Hierarchy.Internal; with Ada.Text_IO; with Hierarchy.Internal; package body Hierarchy is procedure Tell is begin Ada.Text_IO.Put_Line ("Hierarchy"); Internal.Tell; end Tell; end Hierarchy; procedure Hierarchy.Main is begin Tell; -- this is Hierarchy.Tell end Hierarchy.Main;