From: Yoav Tzruya <tzruya@math.tau.ac.il>
Subject: Re: trouble with gnat generic dispatching
Date: 1996/04/13
Date: 1996-04-13T00:00:00+00:00 [thread overview]
Message-ID: <316FF5A1.7847@math.tau.ac.il> (raw)
In-Reply-To: dewar.829137107@schonberg
[-- Attachment #1: Type: text/plain, Size: 1482 bytes --]
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...
[-- Attachment #2: abstract_sets.ads --]
[-- Type: text/plain, Size: 1989 bytes --]
----------------------------------------------------------------------------
-- 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;
[-- Attachment #3: convert.ads --]
[-- Type: text/plain, Size: 267 bytes --]
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);
[-- Attachment #4: convert.adb --]
[-- Type: text/plain, Size: 599 bytes --]
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;
prev parent reply other threads:[~1996-04-13 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-04-10 0:00 trouble with gnat generic dispatching Yoav Tzruya
1996-04-10 0:00 ` Robert Dewar
1996-04-10 0:00 ` David Weller
1996-04-13 0:00 ` Yoav Tzruya [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox