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,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e044473b43baaf18 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-25 13:59:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!news-mue1.dfn.de!news-ham1.dfn.de!news.uni-hamburg.de!cs.tu-berlin.de!not-for-mail From: Stephan Heinemann Newsgroups: comp.lang.ada Subject: Re: automatic tag conversion? Date: 25 May 2003 20:59:31 GMT Organization: Technische Universitaet Berlin, Deutschland Message-ID: References: NNTP-Posting-Host: fiesta.cs.tu-berlin.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.cs.tu-berlin.de 1053896371 18052 130.149.17.4 (25 May 2003 20:59:31 GMT) X-Complaints-To: news@cs.tu-berlin.de NNTP-Posting-Date: 25 May 2003 20:59:31 GMT User-Agent: tin/1.4.6-20020816 ("Aerials") (UNIX) (SunOS/5.8 (sun4u)) Xref: archiver1.google.com comp.lang.ada:37768 Date: 2003-05-25T20:59:31+00:00 List-Id: Georg, first of all, you are quite right: I should have used the term "derived type" instead of "subtype". Further I did not explain what the problem really is forcing you to write a lot of code - sorry for that. I actually was not talking about tagged types, access to tagged types or even class-wide types but about access to all class-wide types with a given type-identifier. The problem for which I do not have a good solution until now is the following: I am using generic sets like this one: generic type Element is private; package CNAda.Utils.Sets is type Set is private; type LookProcedure is access procedure (e: in Element); type MapProcedure is access procedure (e: in out Element); procedure empty(s: in out Set); procedure insert(e: in Element; s: in out Set); procedure remove(e: in Element; s: in out Set); procedure look(lookp: in LookProcedure; s: in Set); procedure map(mapp: in MapProcedure; s: in Set); private type SetElement is record content: Element; prev: Set; next: Set; end record; type Set is access SetElement; end CNAda.Utils.Sets; I use the following for instantiation of this package. type Node is abstract new Component with private; type NodeClassAccess is access all Node'Class; package NodeClassAccessSets is new CNAda.Utils.Sets(NodeClassAccess); NodeClassAccessSets.Set is a component within another tagged (record) type - a Net. There are various derived types of Node like Transition, Place and further Operation, Socket, Port and so on.... I want to apply a LookProcedure on the set for example to print all elements of this set. There is a primitive operation print defined on the types within the hierarchy: procedure print(n: access Node) is abstract; procedure print(t: access Transition); procedure print(p: access Place); ...and so on. I want the system to dispatch to the most special variant of the procedure for the apropriate derived type like: NodeClassAccessSets.look(print'Access, s); It is clearly possible to pass in a NodeClassAccess variable with any derived *ClassAccess value into a print procedure defined as above even if the print procedure was not overridden by the new derived type. The system would always dispatch the most special case, am I right? But my compiler (gnat 3.13p) does not accept the last statement saying: cnada-cnets-components.adb:43:38: expected type "LookProcedure" defined at cnada-utils-sets.ads:8, instance at cnada-cnets-components.ads:94 cnada-cnets-components.adb:43:38: found type access to "print" defined at line 43 So I changed the print procedures to: procedure print(n: in NodeClassAccess); procedure print(t: in TransitionClassAccess); procedure print(p: in PlaceClassAccess); Now the problematic statement compiles. The first procedure cannot be abstract anymore because it is the procedure passed as the LookProcedure. Now the problem is the following: Always the procedure for the approprate local pointer type of the passed in actual parameter is taken now. (1) If I passed in a TransitionClassAccess actual parameter with a derived *ClassAccess value the procedure of the former is taken. (2) Further I could not pass in a derived *ClassAccess actual parameter without having defined a more special print procedure. (1) forces me to always use the exact *ClassAccess variable for which I want to apply a procedure. Further it forces me to implement the procedure for NodeClassAccess which can be used as type for the passed in actual parameter (having to ask 'Tag for what is the appropriate procedure because Node is still abstract and shall be - that was the problem of my former posting). (2) forces me to always overide the procedure I want to use. There will be procedures for which the appropriate variant is much more important than for print and it would be much less work. What can I do to get out of this mess? Thanks, Stephan