comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada)
Date: Mon, 19 Nov 2012 16:52:34 -0800 (PST)
Date: 2012-11-19T16:52:34-08:00	[thread overview]
Message-ID: <adc832ae-94f1-43eb-b119-be9767888a19@googlegroups.com> (raw)
In-Reply-To: <k8eh4g$bs8$1@munin.nbi.dk>

On Monday, November 19, 2012 3:59:14 PM UTC-8, Randy Brukardt wrote:

> >with Some_Package;
> 
> >procedure Main is
> >   Message : Some_Package.Message_Type;
> >begin
> >   Message.Print;
> >end Main;
> 
> >
> 
> >Is it possible to create a parameterless access type to the Message.Print 
> 
> >procedure?
> 
> >The following application refuses to compile:
> 
> >with Some_Package;
> >procedure Main is
> >   Message : Some_Package.Message_Type;
> >   Method_Ref : access procedure := Message.Print'Access;
> >begin
> >   Method_Ref;
> >end Main;
> 
> >The error message is: no selector "Print" for type "Message_Type" defined 
> >at some_package.ads:3

> I think this should work; if it doesn't, the error has something to do with 
> conventions. So there is probably a compiler bug here....

> I'm not certain what the convention of this procedure is (it might be 
> defined to be "intrinsic" somewhere, in which case you couldn't take 'Access 
> to it, I can't find such a rule on a quick check of the RM). 

6.3.1(4): The Intrinsic calling convention represents subprograms that are “built in” to the compiler. The default calling convention is Intrinsic for the following: ...

6.3.1(10.1/2) any prefixed view of a subprogram (see 4.1.3).

The AARM gives the reason immediately following:
 
Reason: The profile of a prefixed view is different than the “real” profile of the subprogram (it doesn't have the first parameter), so we don't want to be able to take 'Access of it, as that would require generating a wrapper of some sort. 

> But it surely 
> exists and should not report that "selector "Print" doesn't exist.

Yep, the error message appears to be wrong, but I can sort of understand it.  If the compiler knows that a prefixed view wouldn't be allowed here (as a prefix to 'Access), then since it has to do name resolution (in case Print is overloaded), it might be using a different search routine than it would use if it were processing a procedure call.  Or something like that.  


> In any case, our intent is that one could use this just like any other  
> procedure with the same profile. You can rename it, pass it as a formal 
> subprogram, call it of course, etc. So I would expect 'Access to work as 
> well, unless the RM explicitly says it does not.

I think the necessity of generating a wrapper, possibly a separate wrapper for every appearance of this kind of 'Access, is why the language designers decided not to allow it.  See AI95-252.  It's also why I was suggesting adding a new kind of access type, rather than changing the language to simply allow 'Access.

                            -- Adam



  parent reply	other threads:[~2012-11-20  0:52 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19  9:59 Access type to member procedure of instance (Object Oriented programming in Ada) ake.ragnar.dahlgren
2012-11-19 11:13 ` Georg Bauhaus
2012-11-19 11:39 ` Brian Drummond
2012-11-20 11:43   ` Brian Drummond
2012-11-20 21:57     ` Randy Brukardt
2012-11-19 13:03 ` sbelmont700
2012-11-19 16:18 ` Adam Beneschan
2012-11-19 17:02   ` Peter C. Chapin
2012-11-19 18:23     ` Adam Beneschan
2012-11-19 20:57       ` Peter C. Chapin
2012-11-19 21:26       ` Dmitry A. Kazakov
2012-11-19 22:19         ` Adam Beneschan
2012-11-20 10:12           ` Dmitry A. Kazakov
2012-11-20 21:51             ` Randy Brukardt
2012-11-21  8:24               ` Dmitry A. Kazakov
2012-11-21 22:19                 ` Randy Brukardt
2012-11-20 10:59     ` Brian Drummond
2012-11-19 20:22 ` ake.ragnar.dahlgren
2012-11-20 11:16   ` Brian Drummond
2012-11-19 20:52 ` ake.ragnar.dahlgren
2012-11-19 21:56   ` Dmitry A. Kazakov
2012-11-22  9:49     ` ake.ragnar.dahlgren
2012-11-19 22:13   ` sbelmont700
2012-11-19 23:59 ` Randy Brukardt
2012-11-20  0:05   ` Randy Brukardt
2012-11-20  1:00     ` Adam Beneschan
2012-11-20 21:38       ` Randy Brukardt
2012-11-20 23:43         ` Adam Beneschan
2012-11-21 22:12           ` Randy Brukardt
2012-11-22  1:59             ` Adam Beneschan
2012-11-29  2:43               ` Randy Brukardt
2012-11-20  0:52   ` Adam Beneschan [this message]
2012-11-20 21:34     ` Randy Brukardt
2012-11-20 11:28   ` Brian Drummond
2012-11-20 14:27     ` Georg Bauhaus
2012-11-20 15:52     ` Adam Beneschan
2012-11-22  9:47 ` ake.ragnar.dahlgren
2012-11-22 10:25   ` Dmitry A. Kazakov
2012-12-02 20:42     ` ake.ragnar.dahlgren
2012-12-03 11:21       ` Dmitry A. Kazakov
2012-12-03 20:21         ` ake.ragnar.dahlgren
2012-12-03 22:15           ` Dmitry A. Kazakov
2012-12-25 21:51           ` Gustaf Thorslund
2012-12-26 18:11             ` ake.ragnar.dahlgren
2012-11-22 12:13   ` Brian Drummond
2012-12-03 16:17     ` ake.ragnar.dahlgren
2012-12-03 21:56       ` Brian Drummond
replies disabled

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