comp.lang.ada
 help / color / mirror / Atom feed
* Instantiating a generic formal procedure with an access procedure value
@ 1999-12-31  0:00 Jeff Carter
  2000-01-03  0:00 ` Tucker Taft
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Carter @ 1999-12-31  0:00 UTC (permalink / raw)


Here's something that I haven't been able to figure out from the ARM.
No doubt I haven't looked in the right place yet.

Suppose I have a package that provides an unprotected structure
(normally this would be a generic package, but that's not important for
this example):

package S_U is
   type Handle is limited private;

   procedure Op (Item : in out Handle; Item : in Integer);

   generic -- Iterate
      with procedure Action
         (Element : in out Integer; Continue : out Boolean);
   procedure Iterate (Over : in out Handle);
private -- S_U
   ...
end S_U;

Suppose I now want to use this package to create a protected structure:

with S_U;
package S is
   type Action_Ptr is access procedure
      (Element : in out Integer; Continue : out Boolean);

   protected type Handle is
      procedure Op (Element : in Integer);
      procedure Iterate (Action : in Action_Ptr);
   private -- Handle
      Data : S_U.Handle;
   end Handle;
end S;

package body S is
   protected body Handle is
      procedure Op (Element : in Integer) is
      begin -- Op
         S_U.Op (Item => Data, Element => Element);
      end Op;

      procedure Iterate (Action : in Action_Ptr) is
         procedure Local is new S_U.Iterate (Action => ???);
         -- What do I use here?
      begin -- Iterate
         Local (Over => Data);
      end Iterate;
   end Handle;
end S;

Neither Action nor Action.all will compile here. The only thing I've
found that will compile is

procedure Iterate (...) is
   procedure Dummy (Element : in out Integer; Continue : out Boolean) is
   begin -- Dummy
      Action (Element => Element, Continue => Continue);
   end Dummy;

   procedure Local is new S_U.Iterate (Action => Dummy);
begin -- Iterate
   Local (Over => Data);
end Iterate;

Hopefully there's a way to avoid this extra procedure call.
--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  1999-12-31  0:00 Instantiating a generic formal procedure with an access procedure value Jeff Carter
@ 2000-01-03  0:00 ` Tucker Taft
  2000-01-04  0:00   ` Jeff Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Tucker Taft @ 2000-01-03  0:00 UTC (permalink / raw)


Jeff Carter wrote:
> 
> Here's something that I haven't been able to figure out from the ARM.
> No doubt I haven't looked in the right place yet.
> 
> Suppose I have a package that provides an unprotected structure
> (normally this would be a generic package, but that's not important for
> this example):
> 
> package S_U is
>    type Handle is limited private;
> 
>    procedure Op (Item : in out Handle; Item : in Integer);

I presume you mean ------------------->>> Element : in Integer <<<

> 
>    generic -- Iterate
>       with procedure Action
>          (Element : in out Integer; Continue : out Boolean);
>    procedure Iterate (Over : in out Handle);
> private -- S_U
>    ...
> end S_U;
> 
> Suppose I now want to use this package to create a protected structure:
> 
> with S_U;
> package S is
>    type Action_Ptr is access procedure
>       (Element : in out Integer; Continue : out Boolean);
> 
>    protected type Handle is
>       procedure Op (Element : in Integer);
>       procedure Iterate (Action : in Action_Ptr);
>    private -- Handle
>       Data : S_U.Handle;
>    end Handle;
> end S;
> 
> package body S is
>    protected body Handle is
>       procedure Op (Element : in Integer) is
>       begin -- Op
>          S_U.Op (Item => Data, Element => Element);
>       end Op;
> 
>       procedure Iterate (Action : in Action_Ptr) is
>          procedure Local is new S_U.Iterate (Action => ???);
>          -- What do I use here?

Action.all is the name of a subprogram.  It happens to have
convention "protected" but that is irrelevant to a generic
formal subprogram, which should accept subprograms of any
convention.

>       begin -- Iterate
>          Local (Over => Data);
>       end Iterate;
>    end Handle;
> end S;
> 
> Neither Action nor Action.all will compile here.

As usual, without the actual source and the actual error message,
it will be hard to determine where the real problem lies.
But it may be a compiler bug...


> ... The only thing I've
> found that will compile is
> 
> procedure Iterate (...) is
>    procedure Dummy (Element : in out Integer; Continue : out Boolean) is
>    begin -- Dummy
>       Action (Element => Element, Continue => Continue);
>    end Dummy;
> 
>    procedure Local is new S_U.Iterate (Action => Dummy);
> begin -- Iterate
>    Local (Over => Data);
> end Iterate;
> 
> Hopefully there's a way to avoid this extra procedure call.

Action.all is the correct thing to use as the actual for a generic
formal subprogram.

> --
> Jeff Carter
-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-03  0:00 ` Tucker Taft
@ 2000-01-04  0:00   ` Jeff Carter
  2000-01-04  0:00     ` Tucker Taft
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Carter @ 2000-01-04  0:00 UTC (permalink / raw)


In article <3870E3F1.906FDFF4@averstar.com>,
  Tucker Taft <stt@averstar.com> wrote:
> Jeff Carter wrote:
> >    procedure Op (Item : in out Handle; Item : in Integer);
>
> I presume you mean ------------------->>> Element : in Integer <<<

Yes, thanks for pointing out that error.

> >       procedure Iterate (Action : in Action_Ptr) is
> >          procedure Local is new S_U.Iterate (Action => ???);
> >          -- What do I use here?
>
> Action.all is the name of a subprogram.  It happens to have
> convention "protected" but that is irrelevant to a generic
> formal subprogram, which should accept subprograms of any
> convention.

I don't see why it should have convention "protected", since Action_Ptr
is defined in the spec of package S and the actual procedure pointed to
by a call to Iterate must be declared at the library level. However,
that should be irrelevant.

> As usual, without the actual source and the actual error message,
> it will be hard to determine where the real problem lies.
> But it may be a compiler bug...
>
> Action.all is the correct thing to use as the actual for a generic
> formal subprogram.

That's what I thought.

Using

type Handle is new Integer;

for the full definition of S_U.Handle (which is irrelevant but
necessary for compilation), and a body of S with Action.all:

package body S is
   protected body Handle is
      procedure Op (Element : in Integer) is
      begin -- Op
         S_U.Op (Item => Data, Element => Element);
      end Op;

      procedure Iterate (Action : in Action_Ptr) is
         procedure Local is new S_U.Iterate (Action => Action.all);
      begin -- Iterate
         Local (Over => Data);
      end Iterate;
   end Handle;
end S;

I get these messages from GNAT 3.11p

s.adb:9:10: instantiation abandoned
s.adb:9:63: missing argument for parameter "Element"
s.adb:11:10: "Local" is undefined


I realize that 3.12p is current, but I lack the bandwidth to download
it right now. It may be a compiler error, and may be corrected in 3.12p
or in compilers from other vendors, but I'd like confirmation that
other compilers do accept this.

Thanks for taking the time to think about this.
--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-04  0:00   ` Jeff Carter
@ 2000-01-04  0:00     ` Tucker Taft
  2000-01-05  0:00       ` Jeff Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Tucker Taft @ 2000-01-04  0:00 UTC (permalink / raw)


Jeff Carter wrote:
> 
> In article <3870E3F1.906FDFF4@averstar.com>,
>   Tucker Taft <stt@averstar.com> wrote:
> > Jeff Carter wrote:
> > >    procedure Op (Item : in out Handle; Item : in Integer);
> >
> > I presume you mean ------------------->>> Element : in Integer <<<
> 
> Yes, thanks for pointing out that error.
> 
> > >       procedure Iterate (Action : in Action_Ptr) is
> > >          procedure Local is new S_U.Iterate (Action => ???);
> > >          -- What do I use here?
> >
> > Action.all is the name of a subprogram.  It happens to have
> > convention "protected" but that is irrelevant to a generic
> > formal subprogram, which should accept subprograms of any
> > convention.
> 
> I don't see why it should have convention "protected", since Action_Ptr
> is defined in the spec of package S and the actual procedure pointed to
> by a call to Iterate must be declared at the library level. However,
> that should be irrelevant.

You're right.  I don't know what made me think that Action was
an access-to-protected subprogram.  I must have been seeing things.

> s.adb:9:10: instantiation abandoned
> s.adb:9:63: missing argument for parameter "Element"
> s.adb:11:10: "Local" is undefined
> 
> I realize that 3.12p is current, but I lack the bandwidth to download
> it right now. It may be a compiler error, and may be corrected in 3.12p
> or in compilers from other vendors, but I'd like confirmation that
> other compilers do accept this.

Your code compiles fine with My Favorite Front End.

This looks like a good old compiler bug.  On the other hand,
it would still help if you included the complete source code,
exactly as it was submitted to GNAT.  For example, I am surprised
GNAT didn't complain about lack of a generic body.
You have included bits and pieces, and it is quite possible that
there was some transcription error when I created a compilable version.

> 
> Thanks for taking the time to think about this.
> --
> Jeff Carter

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-04  0:00     ` Tucker Taft
@ 2000-01-05  0:00       ` Jeff Carter
  2000-01-05  0:00         ` Ed Falis
  2000-01-12  0:00         ` Jeff Carter
  0 siblings, 2 replies; 12+ messages in thread
From: Jeff Carter @ 2000-01-05  0:00 UTC (permalink / raw)


In article <38725A42.2961CEFC@averstar.com>,
  Tucker Taft <stt@averstar.com> wrote:
> Your code compiles fine with My Favorite Front End.

I'm glad to hear that.

>
> This looks like a good old compiler bug.  On the other hand,
> it would still help if you included the complete source code,
> exactly as it was submitted to GNAT.  For example, I am surprised
> GNAT didn't complain about lack of a generic body.

Here's everything, copied and pasted from the actual files submitted to
GNAT:

package S_U is
   type Handle is limited private;

   procedure Op (Item : in out Handle; Element : in Integer);

   generic -- Iterate
      with procedure Action (Element : in out Integer; Continue : out
Boolean);
   procedure Iterate (Over : in out Handle);
private -- S_U
   type Handle is new Integer;
end S_U;

package body S_U is
   procedure Op (Item : in out Handle; Element : in Integer) is
   begin -- Op
      null;
   end Op;

   procedure Iterate (Over : in out Handle) is
      Continue : Boolean;
   begin -- Iterate
      Action (Element => Integer (Over), Continue => Continue);
   end Iterate;
end S_U;

with S_U;
package S is
   type Action_Ptr is access procedure (Element : in out Integer;
Continue : out Boolean);

   protected type Handle is
      procedure Op (Element : in Integer);
      procedure Iterate (Action : in Action_Ptr);
   private -- Handle
      Data : S_U.Handle;
   end Handle;
end S;

package body S is
   protected body Handle is
      procedure Op (Element : in Integer) is
      begin -- Op
         S_U.Op (Item => Data, Element => Element);
      end Op;

      procedure Iterate (Action : in Action_Ptr) is
         procedure Local is new S_U.Iterate (Action => Action.all);
      begin -- Iterate
         Local (Over => Data);
      end Iterate;
   end Handle;
end S;

I hope that helps.

--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-05  0:00       ` Jeff Carter
@ 2000-01-05  0:00         ` Ed Falis
  2000-01-12  0:00         ` Jeff Carter
  1 sibling, 0 replies; 12+ messages in thread
From: Ed Falis @ 2000-01-05  0:00 UTC (permalink / raw)


In article <84u97t$uut$1@nnrp1.deja.com>,
  Jeff Carter <jrcarter001@my-deja.com> wrote:


> Here's everything, copied and pasted from the actual files submitted to
> GNAT:

I checked it with Tuck's favorite front end, and it compiled fine.

- Ed


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-12  0:00         ` Jeff Carter
@ 2000-01-12  0:00           ` Simon Wright
  2000-01-13  0:00             ` Jeff Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Wright @ 2000-01-12  0:00 UTC (permalink / raw)


Jeff Carter <jrcarter001@my-deja.com> writes:

> This issue is still unresolved. We know that Tucker Taft's favorite
> front end accepts this code, but that GNAT 3.11p does not.

pogner[12]$ PATH=/opt/gnu/bin:$PATH gnatmake -g -O2 -v s

GNATMAKE 3.12a2 (19990629) Copyright 1995-1999 Free Software Foundation, Inc.
  "s.ali" being checked ...
  -> "s.ali" missing.
gcc -c -g -O2 s.adb
s.adb:10:10: instantiation abandoned
s.adb:10:63: missing argument for parameter "Element"
s.adb:12:10: "Local" is undefined
gnatmake: "s.adb" compilation error

(I expect 3.12p will do the same)




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-05  0:00       ` Jeff Carter
  2000-01-05  0:00         ` Ed Falis
@ 2000-01-12  0:00         ` Jeff Carter
  2000-01-12  0:00           ` Simon Wright
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Carter @ 2000-01-12  0:00 UTC (permalink / raw)


This issue is still unresolved. We know that Tucker Taft's favorite
front end accepts this code, but that GNAT 3.11p does not.

In cases such as this, I have learned to expect a posting from Robert
Dewar pointing out that 3.11 has been replaced by 3.12, often with a
statement that 3.12p handles this correctly. However, that has not
happened for this.

I would like to know how GNAT 3.12 handles this case. It would take
over an hour for me to download 3.12p, and I am not able to do so now.
I would appreciate hearing from anyone with 3.12 what results it gives
on this code.

If GNAT 3.12 continues to reject this, which is correct?

In article <84u97t$uut$1@nnrp1.deja.com>,
  Jeff Carter <jrcarter001@my-deja.com> wrote:
> In article <38725A42.2961CEFC@averstar.com>,
>   Tucker Taft <stt@averstar.com> wrote:
> > Your code compiles fine with My Favorite Front End.
>
> I'm glad to hear that.
>
> >
> > This looks like a good old compiler bug.  On the other hand,
> > it would still help if you included the complete source code,
> > exactly as it was submitted to GNAT.  For example, I am surprised
> > GNAT didn't complain about lack of a generic body.
>
> Here's everything, copied and pasted from the actual files submitted
to
> GNAT:
>
> package S_U is
>    type Handle is limited private;
>
>    procedure Op (Item : in out Handle; Element : in Integer);
>
>    generic -- Iterate
>       with procedure Action (Element : in out Integer; Continue : out
> Boolean);
>    procedure Iterate (Over : in out Handle);
> private -- S_U
>    type Handle is new Integer;
> end S_U;
>
> package body S_U is
>    procedure Op (Item : in out Handle; Element : in Integer) is
>    begin -- Op
>       null;
>    end Op;
>
>    procedure Iterate (Over : in out Handle) is
>       Continue : Boolean;
>    begin -- Iterate
>       Action (Element => Integer (Over), Continue => Continue);
>    end Iterate;
> end S_U;
>
> with S_U;
> package S is
>    type Action_Ptr is access procedure (Element : in out Integer;
> Continue : out Boolean);
>
>    protected type Handle is
>       procedure Op (Element : in Integer);
>       procedure Iterate (Action : in Action_Ptr);
>    private -- Handle
>       Data : S_U.Handle;
>    end Handle;
> end S;
>
> package body S is
>    protected body Handle is
>       procedure Op (Element : in Integer) is
>       begin -- Op
>          S_U.Op (Item => Data, Element => Element);
>       end Op;
>
>       procedure Iterate (Action : in Action_Ptr) is
>          procedure Local is new S_U.Iterate (Action => Action.all);
>       begin -- Iterate
>          Local (Over => Data);
>       end Iterate;
>    end Handle;
> end S;
>
> I hope that helps.
>
> --
> Jeff Carter
> "Now go away or I shall taunt you a second time."
> -- Monty Python and the Holy Grail
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-12  0:00           ` Simon Wright
@ 2000-01-13  0:00             ` Jeff Carter
  2000-01-13  0:00               ` Tucker Taft
  2000-01-13  0:00               ` Simon Wright
  0 siblings, 2 replies; 12+ messages in thread
From: Jeff Carter @ 2000-01-13  0:00 UTC (permalink / raw)


In article <x7vpuv7t2zb.fsf@pogner.demon.co.uk>,
  Simon Wright <simon@pogner.demon.co.uk> wrote:
> Jeff Carter <jrcarter001@my-deja.com> writes:
>
> > This issue is still unresolved. We know that Tucker Taft's favorite
> > front end accepts this code, but that GNAT 3.11p does not.
>
> pogner[12]$ PATH=/opt/gnu/bin:$PATH gnatmake -g -O2 -v s
>
> GNATMAKE 3.12a2 (19990629) Copyright 1995-1999 Free Software
Foundation, Inc.
>   "s.ali" being checked ...
>   -> "s.ali" missing.
> gcc -c -g -O2 s.adb
> s.adb:10:10: instantiation abandoned
> s.adb:10:63: missing argument for parameter "Element"
> s.adb:12:10: "Local" is undefined
> gnatmake: "s.adb" compilation error
>
> (I expect 3.12p will do the same)
>
I suspect you're right. Thanks for testing this.

OK, Tucker Taft's favorite front end accepts the instantiation, but
GNAT does not. Now hopefully the language lawyers and compiler
implementers will answer (or argue) the question: Which is correct?

--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-13  0:00             ` Jeff Carter
  2000-01-13  0:00               ` Tucker Taft
@ 2000-01-13  0:00               ` Simon Wright
  1 sibling, 0 replies; 12+ messages in thread
From: Simon Wright @ 2000-01-13  0:00 UTC (permalink / raw)


Jeff Carter <jrcarter001@my-deja.com> writes:

> OK, Tucker Taft's favorite front end accepts the instantiation, but
> GNAT does not. Now hopefully the language lawyers and compiler
> implementers will answer (or argue) the question: Which is correct?

If I were you I'd send the report along to report@gnat.com
anyway.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-13  0:00             ` Jeff Carter
@ 2000-01-13  0:00               ` Tucker Taft
  2000-01-14  0:00                 ` Jeff Carter
  2000-01-13  0:00               ` Simon Wright
  1 sibling, 1 reply; 12+ messages in thread
From: Tucker Taft @ 2000-01-13  0:00 UTC (permalink / raw)


Jeff Carter wrote:

> ...
> OK, Tucker Taft's favorite front end accepts the instantiation, but
> GNAT does not. Now hopefully the language lawyers and compiler
> implementers will answer (or argue) the question: Which is correct?

The instantiation is certainly legal.  The GNAT error message
doesn't even make sense, so you can be pretty sure that it is
just a GNAT bug.  Send a report to the appropriate GNAT bug list.

> --
> Jeff Carter

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Instantiating a generic formal procedure with an access procedure value
  2000-01-13  0:00               ` Tucker Taft
@ 2000-01-14  0:00                 ` Jeff Carter
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Carter @ 2000-01-14  0:00 UTC (permalink / raw)


In article <387E2D6D.1CE5FD75@averstar.com>,
  Tucker Taft <stt@averstar.com> wrote:
> The instantiation is certainly legal.  The GNAT error message
> doesn't even make sense, so you can be pretty sure that it is
> just a GNAT bug.  Send a report to the appropriate GNAT bug list.

If STT says it's legal, it rarely isn't. However, I can argue this 2
ways:

1. An explicit dereference is a name, and the actual for a generic
formal procedure must be a procedure or entry name, so this is legal.

2. Instantiation occurs at compile time, but the evaluation of an
explicit dereference occurs at run time, so this is illegal. ARM 4.1
(13) may apply here.

This is why I asked for comments on its legality. I guess I'll prepare
an error report for GNAT.
--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2000-01-14  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-31  0:00 Instantiating a generic formal procedure with an access procedure value Jeff Carter
2000-01-03  0:00 ` Tucker Taft
2000-01-04  0:00   ` Jeff Carter
2000-01-04  0:00     ` Tucker Taft
2000-01-05  0:00       ` Jeff Carter
2000-01-05  0:00         ` Ed Falis
2000-01-12  0:00         ` Jeff Carter
2000-01-12  0:00           ` Simon Wright
2000-01-13  0:00             ` Jeff Carter
2000-01-13  0:00               ` Tucker Taft
2000-01-14  0:00                 ` Jeff Carter
2000-01-13  0:00               ` Simon Wright

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