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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e2abde523cb162f X-Google-Attributes: gid103376,public From: Yoav Tzruya Subject: Re: trouble with gnat generic dispatching Date: 1996/04/13 Message-ID: <316FF5A1.7847@math.tau.ac.il> X-Deja-AN: 147326042 references: <316B909E.27E0@math.tau.ac.il> content-type: multipart/mixed; boundary="------------CCB11A16FD4" organization: Tel-Aviv University Computation Center mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.01Gold (Win95; I) Date: 1996-04-13T00:00:00+00:00 List-Id: This is a multi-part message in MIME format. --------------CCB11A16FD4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Robert Dewar wrote: > > Yoav posted a large program and one problem mentioned is that controlled > types can only be declared at the library level. THis is correct, GNAT > is giving you a correct diagnostic. Controlled types are tagged types, > and tagged types must be extended at the same level as their parents. > > As for the other "problem", no idea! Please post short concise examples, > CLA is not the place to post large chunks of code and ask "what's wrong?" > > You might also want to follow the GNAT directions and send GNAT > questions to report@gnat.com, although there too, you need to make > an effort to provide a concise example of your question rather than > just dumping your whole program! I've taken Robert's reply into consideration and since he gave me the answer for the controlled problem I now post a small spec-only example for the compile time error of gnat regarding dispatching of abstract routine. in the following example , I try to define an ADT , set, which can be implemented in various ways and a routine , convert, to convert between two such implementations. The problem is that gnat does not know how to dispatch the 'unit' function call in 'convert' body. any ideas ? I guess the problem is that the signature of the routine (except the returned type) does not contain any derivation of the set class. But I think that the compiler can deduce which routine to call by the type expected by the unit routine to return . So here it is... --------------CCB11A16FD4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="abstract_sets.ads" ---------------------------------------------------------------------------- -- PACKAGE: -- Abstract_Sets -- AUTHOR: -- Yoav Tzruya -- EXPRTED TYPES: -- Set - A generic (on set_element) controlled set of elements -- EXPORTED PROCEDURES: -- Empty - return an empty set -- Unit - return a set of one element -- Union - unify two sets into one (no duplicates of course) -- Intersection - the intersection of two sets. -- Take - take an arbitrary element out of the set. -- EXPORTED EXCEPTIONS: -- set_is_empty_exception - may be raised by the Take procedure when -- trying to take an element out of the empty set. ---------------------------------------------------------------------------- -- ** SPECIFICATION IMPORTS ** with Ada.Finalization; generic -- the generic element of the set type Set_Element is private; package Abstract_Sets is -- ** EXPORTED EXCEPTIONS ** set_is_empty_exception : exception; -- ** EXPORTED TYPES ** type Set is abstract new Ada.Finalization.Controlled with private; -- ** EXPORTED SUBPROGRAMS ** function Empty return Set is abstract; -- empty set function Unit ( Element : in Set_Element) return Set is abstract; -- build set with 1 element function Union ( Left : in Set; Right : in Set) return Set is abstract; function Intersection ( Left : in Set; Right : in Set) return Set is abstract; procedure Take ( From : in out Set; Element : out Set_Element) is abstract; private type Set is abstract new Ada.Finalization.Controlled with null record; end Abstract_Sets; --------------CCB11A16FD4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="convert.ads" with abstract_sets; generic with package abstract_set_handling is new abstract_sets(<>); use abstract_set_handling; -- to enable spec as in class procedure convert ( from : in set'class; to : out set'class); --------------CCB11A16FD4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="convert.adb" procedure convert ( from : in set'class; to : out set'class) is temp : set'class := from; elem : set_element; begin -- convert to := empty; while temp /= empty loop take( from => temp, element => elem); -- gnat bug here-not knowing how to dispatch the unit routine to:=union( left => to, right => abstract_set_handling.unit(element => elem)); end loop; end convert; --------------CCB11A16FD4--