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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ac5c3bc59168d76 X-Google-Attributes: gid103376,public From: Jonas Nygren Subject: Re: Subprogram Renaming Date: 1996/04/12 Message-ID: <316E12F2.37BC@ehs.ericsson.se>#1/1 X-Deja-AN: 147073732 references: <316AEA8D.7600@csehp3.mdc.com> <4kgde6$q8t@watnews1.watson.ibm.com> <4kjhg2$139s@watnews1.watson.ibm.com> content-type: text/plain; charset=us-ascii organization: Ericsson Hewlett-Packard Telecommunications AB mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.0GoldB1 (WinNT; I) Date: 1996-04-12T00:00:00+00:00 List-Id: Norman H. Cohen wrote: > > In article <4kgde6$q8t@watnews1.watson.ibm.com>, I wrote: > > |> This capability is especially > |> useful when a subprogram is implemented using generic instantiation. > > Renaming-as-body is also useful in conjunction with derived subprograms. > Here's a variation on my previous example: I have been experimenting with such a construct for some months but always encountered some new problem. My example code is similar to Normans but instead of Integer_Dequeues I have Generic_Dequeues and Generic_Stacks. My problem is how to handle a subprogram with the same name for Dequeue_Type and Stack_Type, e.g. Remove_All. I never managed to figure out how to handle the renaming. Perhaps somebody here can help me. I intersperse the added code in Normans example below. Of course I could introduce a dummy type with the common names marked to distinguish them from the intended name. Deque_Type and Stack_Type then derives from this 'dummy type'. Another note: As mentioned above my code uses generics while Norman's does not. Is there a catch? I encountered a problem with Gnat where it worked without generics but not with. I have reported it but have not heard anything from ACT (I am not on support contract :-). Is there Ada legal problems with adding generics to these example packages? /jonas > > package Integer_Dequeues is > type Dequeue_Type is private; > procedure Add_To_Front (Dequeue: in out Dequeue_Type; Item: in Integer); > procedure Add_To_Back (Dequeue: in out Dequeue_Type; Item: in Integer); > procedure Remove_From_Front > (Dequeue: in out Dequeue_Type; Item: out Integer); > procedure Remove_From_Back > (Dequeue: in out Dequeue_Type; Item: out Integer); procedure Remove_All (Dequeue: in out Dequeue_Type); > private > type Dequeue_Type is ...; > end Integer_Dequeues; > > with Integer_Dequeues; > package Integer_Stacks is > type Stack_Type is private; > procedure Push (Stack: in out Stack_Type; Item: in Integer); > procedure Pop (Stack: in out Stack_Type; Item: out Integer); procedure Remove_All (Stack: in out Stack_Type); > private > use Integer_Dequeues; > type Stack_Type is new Dequeue_Type; > procedure Push (Stack: in out Stack_Type; Item: in Integer) > renames Add_To_Front; > procedure Pop (Stack: in out Stack_Type; Item: out Integer) > renames Remove_From_Front; procedure Remove_All (Stack: in out Stack_Type) renames Remove_All; -- Does not work, -- Gnat e.g. creates a recursive call (reported) > end Integer_Stacks; > > The subprograms being renamed are the inherited subprograms > > procedure Remove_From_Front > (Dequeue: in out Stack_Type; Item: out Integer); > > procedure Remove_From_Back > (Dequeue: in out Stack_Type; Item: out Integer); > > implicitly declared after the derived-type declaration in the private > part. > > Because a renaming declaration acting as a subprogram declaration is > allowed in the package declaration, Integer_Stacks does not even need a > package body! > > -- > Norman H. Cohen ncohen@watson.ibm.com -- ------------------------------------------------------- -- Jonas Nygren -- ehsjony@ehs.ericsson.se -------------------------------------------------------