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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,95951b04da65eda7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.74.102 with SMTP id s6mr3910792pav.21.1351004317887; Tue, 23 Oct 2012 07:58:37 -0700 (PDT) Received: by 10.68.229.231 with SMTP id st7mr3719257pbc.2.1351004317871; Tue, 23 Oct 2012 07:58:37 -0700 (PDT) Path: s9ni23372pbb.0!nntp.google.com!kr7no8410698pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 23 Oct 2012 07:58:37 -0700 (PDT) In-Reply-To: <858vazhfuv.fsf@stephe-leake.org> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <858vazhfuv.fsf@stephe-leake.org> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4be3f29b-d2f2-4cd4-b7d3-78063b7779b1@googlegroups.com> Subject: Re: generic instantion as overriding primitive operation? From: Adam Beneschan Injection-Date: Tue, 23 Oct 2012 14:58:37 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-10-23T07:58:37-07:00 List-Id: On Sunday, October 21, 2012 10:52:57 AM UTC-7, Stephen Leake wrote: > The syntax for generic_instantiation allows an overriding_indicator: >=20 > generic_instantiation ::=3D=20 > [overriding_indicator] > procedure defining_program_unit_name is > new generic_procedure_name [generic_actual_part] > [aspect_specification]; >=20 > So I'm trying to construct an example of that, as a test for the Ada > mode 5.0 indentation engine. >=20 > So far I have: >=20 > package Ada_Mode.Nominal is > type Parent_Type_1 is tagged null record; > procedure Procedure_1a (Item : in out Parent_Type_1); > function Function_2a (Param : in Parent_Type_1) return Float; > end Ada_Mode.Nominal; >=20 > generic > package Ada_Mode.Generic_Parent is >=20 > -- These match some of the primitive operations of=20 > -- Ada_Mode.Nominal.Parent_Type_1. >=20 >=20 > generic > type Tagged_Type is abstract tagged limited private; > function Gen_Function_2a (Item : in Tagged_Type) return Float; >=20 > generic > type Tagged_Type is abstract tagged limited private; > procedure Gen_Procedure_1b (Item : in out Tagged_Type);=20 >=20 > end Ada_Mode.Generic_Parent; >=20 >=20 >=20 > with Ada_Mode.Generic_Parent; > with Ada_Mode.Nominal; > package Ada_Mode.Generic_Instantiation is >=20 > package Instance is new Ada_Mode.Generic_Parent; >=20 > type Child_Type_1 is new Ada_Mode.Nominal.Parent_Type_1 with null reco= rd; >=20 > overriding > procedure Procedure_1b is new Instance.Gen_Procedure_1b (Child_Type_1)= ; >=20 > type Child_Type_2 is new Ada_Mode.Nominal.Parent_Type_1 with null reco= rd; >=20 > overriding > function Function_2a is new Instance.Gen_Function_2a (Child_Type_2); >=20 > end Ada_Mode.Generic_Instantiation; >=20 > But GNAT 7.0.1 doesn't like this; it says: >=20 > ada_mode-generic_instantiation.ads:32:04: warning: no primitive operation= s for "Child_Type_1" after this line > ada_mode-generic_instantiation.ads:32:14: this primitive operation is dec= lared too late >=20 > where 'line 32' is the line declaring Procedure_1b >=20 > Can anyone rearrange this to make it compile? Or is this a compiler bug? >=20 > Does anyone have any real examples of this? The compiler is correct. A generic instantiation freezes all identifiers u= sed in the instantiation; thus, you can't use Child_Type_1 as an actual par= ameter to a generic subprogram instantiation if the resulting subprogram wi= ll be a primitive operation, since the primitive operation would be declare= d after the type is frozen.=20 On top of that, even without that rule, your program would be illegal becau= se you're creating a new Procedure_1b and saying it's "overriding" but ther= e's no Procedure_1b anywhere else in your program. I'm assuming this is a = typo. Here's a way to create a generic instantiation with an "overriding" indicat= or legally: with Ada_Mode.Generic_Parent; with Ada_Mode.Nominal; package Ada_Mode.Generic_Instantiation is type Child_Type_1 is new Ada_Mode.Nominal.Parent_Type_1 with null record= ; generic procedure Gen_Procedure (Item : in out Child_Type_1); overriding procedure Procedure_1a is new Gen_Procedure; end Ada_Mode.Generic_Instantiation; It may not be terribly useful in practice (and I'm not even sure you can cr= eate an example that won't raise Program_Error due to a violation of elabor= ation rules). But if your goal is to create a legal program that has "over= riding" on a generic instantiation to test your indentation engine, this sh= ould serve. (Then again, if all you're doing is testing an indentation eng= ine, I don't know why you'd care whether the program will compile or not.) -- Adam