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,8fdcbb4347c7f20a X-Google-Attributes: gid103376,public From: stt@henning.camb.inmet.com (Tucker Taft) Subject: Re: Instantiation of child generics? Date: 1996/07/26 Message-ID: #1/1 X-Deja-AN: 170274312 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: henning.camb.inmet.com references: <4t9itp$imd@goanna.cs.rmit.edu.au> organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-07-26T00:00:00+00:00 List-Id: Dale Stanbrough (dale@goanna.cs.rmit.edu.au) wrote: : ... Also I don't really understand the rules for : instantiaion of child generics. Can anyone explain them? You should think of a child of a generic as a nested generic, which is only visible to those who choose to mention it in a with clause. Since it is conceptually a nested generic, you can only instantiate it once you have already instantiated the enclosing generic. Given your example below, you would first instantiate "queues": with queues; package queue_inst is new queues(Integer); Then you would instantiate the "nested" generic "bounded" as follows: with queue_inst; -- The instance of the enclosing generic with queues.bounded; -- Makes the nested generic visible in all instances package bounded_inst is new queue_inst.bounded(200); If "bounded" had been truly nested, rather than a child, the only difference would be that you would omit the "with queues.bounded;" The effect of "with queues.bounded;" is to "plug" the child "bounded" into its parent generic "queues", meaning that "bounded" becomes visible in all instances of "queues." We struggled during the 9X process with children of generics, since it is certainly a bit counterintuitive that you "with" "queues.bounded" whereas you instantiate "queue_inst.bounded." However, if you think of a "with" clause as having the effect of "plugging" a child into its parent unit, then you should be able to understand why children of generics work the way they do. : e.g. : generic : type element is private; : package queues is : type queue is abstract tagged null record; : : procedure init return queue is abstract; : : procedure enqueue(item:in out queue; item:element) is abstract; : -- etc : end queues; : : : generic : size :natural; : package queues.bounded is : : type queue is new queues.queue with private; : : procedure init return queue is abstract; : : procedure enqueue(item:in out queue; item:element) is abstract; : private : type queue is new queues.queue with null record; -- for now... : end; : How do I instantiate this? : with queues.bounded; : package myQ is new queues.bounded(integer, 5); : : results in Gnat telling me "invalid prefix in selected component "queues"" GNAT is correct; the prefix to "bounded" should be an instantiation of queues, not queues itself. : Also will my (re)use of the identifier "queue" in the packages cause any : problems for me? It seems to compile ok, but i'm concerned that there might : be some nasty visibility issue lurking around the corner... Only if you "with" and "use" both packages. Even then, you can still use a full expanded name where there is a name conflict. : Thanks, : Dale -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA