comp.lang.ada
 help / color / mirror / Atom feed
From: Stephan Heinemann <zombie@cs.tu-berlin.de>
Subject: Re: automatic tag conversion?
Date: 25 May 2003 20:59:31 GMT
Date: 2003-05-25T20:59:31+00:00	[thread overview]
Message-ID: <bararj$hk4$1@news.cs.tu-berlin.de> (raw)
In-Reply-To: baoapa$pm7$1@a1-hrz.uni-duisburg.de

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



  reply	other threads:[~2003-05-25 20:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-23 23:04 automatic tag conversion? Stephan Heinemann
2003-05-23 23:57 ` Stephan Heinemann
2003-05-24 17:39   ` Georg Bauhaus
2003-05-25 20:59     ` Stephan Heinemann [this message]
2003-05-26  8:29       ` Dmitry A. Kazakov
2003-05-26 18:16         ` Georg Bauhaus
2003-05-26 18:27           ` Georg Bauhaus
2003-05-26 20:49             ` Stephan Heinemann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox