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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,cb04cee6116c8ced X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,CP1252 Path: g2news1.google.com!postnews.google.com!d37g2000yqa.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Re: Package's private parts and protected types Date: Tue, 9 Feb 2010 21:12:04 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <7ff3810f-3ee3-4f39-a54c-933ad7d0655c@36g2000yqu.googlegroups.com> <1v2la97s2yyvd.1rcy0ana8mver.dlg@40tude.net> <3bb38996-47f7-4f30-8255-f011501404b5@b10g2000yqa.googlegroups.com> <4e959c35-34d1-49fb-b1eb-5b298e42610f@z19g2000yqk.googlegroups.com> NNTP-Posting-Host: 86.75.149.66 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1265778724 15648 127.0.0.1 (10 Feb 2010 05:12:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 10 Feb 2010 05:12:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d37g2000yqa.googlegroups.com; posting-host=86.75.149.66; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9067 Date: 2010-02-09T21:12:04-08:00 List-Id: On 10 f=E9v, 00:29, Robert A Duff wrote: > I don't understand the problem. =A0The following should work. > Doesn't it do what you want? =A0Type T exports Public, > but hides Hidden. =A0No heap allocation. > > =A0package P is > =A0 =A0 type T is synchronized interface; > =A0 =A0 function Create return T'Class; > > =A0 =A0 procedure Public (X : in out T) is abstract; > > =A0private > > =A0 =A0 protected type T2 is new T with > =A0 =A0 =A0 =A0overriding entry Public; > =A0 =A0 =A0 =A0entry Hidden; > =A0 =A0 end T2; > > =A0end P; > > =A0package body P is > =A0 =A0 function Create return T'Class is > =A0 =A0 begin > =A0 =A0 =A0 =A0return Result : T2 do > =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0end return; > =A0 =A0 end Create; > > =A0 =A0 protected body T2 is > =A0 =A0 =A0 =A0entry Public when ... is > =A0 =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0end Public; > > =A0 =A0 =A0 =A0entry Hidden when ... is > =A0 =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0end Hidden; > =A0 =A0 end T2; > > =A0end P; > > =A0with P; use P; > =A0procedure Main is > > =A0 =A0 X : T'Class :=3D Create; > > =A0begin > =A0 =A0 Public (X); > =A0end Main; > > - Bob This was exactly what I've tried, except that I used something like =93 return Result : T'Class :=3D ... do =94 instead of =93 return Result : T2 d= o =94, which is not legal, as stated by the ARM : [ARM 6.5(5.2/2)] If the result subtype of the function is defined by a subtype_mark, the return_subtype_indication shall be a subtype_indication. Ok for this one, but later it's going wrong : Remainder of [ARM 6.5(5.2/2)] The type of the subtype_indication shall be the result type of the function. But T2, in the return statement, is not T'Class, in the function return type indication. And indeed, when I've tried your way, GNAT complained =93 wrong type for return_subtype_indication =94 So it must be T'Class in the return statement, and as by both [ARM 6.5(5.d/2)] Discussion: We know that if the result type is class wide, then there must be an expression of the return statement. and [ARM 6.5(5.5/2)] If the result subtype of the function is limited, then the expression of the return statement (if any) shall be an aggregate, a function call (or equivalent use of an operator), or a qualified_expression or parenthesized expression whose operand is one of these. an initialization is required (otherwise the concret type of the object would be unknown). I was failing there, as there is no kind of extention aggregate for a protected type (it's not a record, although tagged). But I've finally solved the trick : see next reply to Randy. On 10 f=E9v, 00:29, Robert A Duff wrote: > I don't understand the problem. =A0The following should work. > Doesn't it do what you want? =A0Type T exports Public, > but hides Hidden. =A0No heap allocation. > > =A0package P is > =A0 =A0 type T is synchronized interface; > =A0 =A0 function Create return T'Class; > > =A0 =A0 procedure Public (X : in out T) is abstract; > > =A0private > > =A0 =A0 protected type T2 is new T with > =A0 =A0 =A0 =A0overriding entry Public; > =A0 =A0 =A0 =A0entry Hidden; > =A0 =A0 end T2; > > =A0end P; > > =A0package body P is > =A0 =A0 function Create return T'Class is > =A0 =A0 begin > =A0 =A0 =A0 =A0return Result : T2 do > =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0end return; > =A0 =A0 end Create; > > =A0 =A0 protected body T2 is > =A0 =A0 =A0 =A0entry Public when ... is > =A0 =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0end Public; > > =A0 =A0 =A0 =A0entry Hidden when ... is > =A0 =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0 ... > =A0 =A0 =A0 =A0end Hidden; > =A0 =A0 end T2; > > =A0end P; > > =A0with P; use P; > =A0procedure Main is > > =A0 =A0 X : T'Class :=3D Create; > > =A0begin > =A0 =A0 Public (X); > =A0end Main; > > - Bob This was exactly what I've tried, except that I used something like =93 return Result : T'Class :=3D ... do =94 instead of =93 return Result : T2 d= o =94, which is not legal, as stated by the ARM : [ARM 6.5(5.2/2)] If the result subtype of the function is defined by a subtype_mark, the return_subtype_indication shall be a subtype_indication. Ok for this one, but later it's going wrong : Remainder of [ARM 6.5(5.2/2)] The type of the subtype_indication shall be the result type of the function. But T2, in the return statement, is not T'Class, in the function return type indication. And indeed, when I've tried your way, GNAT complained =93 wrong type for return_subtype_indication =94 So it must be T'Class in the return statement, and as by both [ARM 6.5(5.d/2)] Discussion: We know that if the result type is class wide, then there must be an expression of the return statement. and [ARM 6.5(5.5/2)] If the result subtype of the function is limited, then the expression of the return statement (if any) shall be an aggregate, a function call (or equivalent use of an operator), or a qualified_expression or parenthesized expression whose operand is one of these. an initialization is required (otherwise the concret type of the object would be unknown). I was failing there, as there is no kind of extention aggregate for a protected type (it's not a record, although tagged). But I've finally solved the trick : see next, in the reply to Randy On 10 f=E9v, 03:39, "Randy Brukardt" wrote: > I don't buy this at all. The exact types to create can be selected by man= y > means (presumably by the parameters). You can use a dispatching construct= or > function in the concrete types, using the factory pattern > (Generic_Dispatching_Constructor), and roughly organized as Bob noted. What confused me, was I meet with initialization of a class wide type whose initializer was to of a protected type, as explained in the reply to Robert/Bob. I could finally solve it, using a function, instead of an aggregate. > Note that you have this problem with *any* constructor of any tagged type= if > you have any interest at all in allowing future extensions. While tagged record and tagged protected is not fully the same, as this example shows. Well, finally the previous assertion is canceled, and there is indeed a nice and clean way to do things with a synchronized interface type. Thanks to the one who suggested this path.