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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Rough proposal to make some generic types static Date: Mon, 21 Jul 2014 23:54:45 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: rFX7cZOSaeuGGZI2vwQTaQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21095 Date: 2014-07-21T23:54:45+03:00 List-Id: Victor Porton wrote: > What in the RM signifies that Enum_Type (below) is not a static scalar > type? I've found: RM 4.9 26/3: "A static scalar subtype is an unconstrained scalar subtype whose type is not a descendant of a formal type, or ..." Why this rule? Can it be relaxed? > We should work on an amendment for a future version of Ada to make > Enum_Type static. > > Is it difficult to implement this? > > Rationale is that the below code is useful in practice. > > gnatmake -q -c -gnatc -u > -P/home/porton/Projects/redland-bindings/ada/test.gpr -XRUNTIME=full > -XMODE=Install rdf-auxilary.adb rdf-auxilary.adb:7:25: non-static > expression used for modular type bound rdf-auxilary.adb:7:38: size > attribute is only static for static scalar type (RM 4.9(7,8)) > > -- rdf.ads > package RDF is > end RDF; > > -- rdf-auxilary.ads > with Interfaces.C; > > package RDF.Auxilary is > > generic > type Enum_Type is (<>); > package Convert_Enum is > function To_C(Argument: Enum_Type) return Interfaces.C.int; > function From_C(Argument: Interfaces.C.int) return Enum_Type; > end; > > end RDF.Auxilary; > > -- rdf-auxilary.adb > with Ada.Unchecked_Conversion; > > package body RDF.Auxilary is > > package body Convert_Enum is > > type Small is mod 2**(Enum_Type'Size); > > function To_C_Internal is > new Ada.Unchecked_Conversion (Source => Enum_Type, Target => > Small); > > function From_C_Internal is > new Ada.Unchecked_Conversion (Source => Small, Target => > Enum_Type); > > function To_C(Argument: Enum_Type) return Interfaces.C.int is > begin > return Interfaces.C.int(To_C_Internal(Argument)); > end; > > function From_C(Argument: Interfaces.C.int) return Enum_Type is > begin > return From_C_Internal(Small(Argument)); > end; > > end; > > end RDF.Auxilary; > > -- Victor Porton - http://portonvictor.org