From: Victor Porton <porton@narod.ru>
Subject: Re: Rough proposal to make some generic types static
Date: Mon, 21 Jul 2014 23:54:45 +0300
Date: 2014-07-21T23:54:45+03:00 [thread overview]
Message-ID: <lqjumj$smj$1@speranza.aioe.org> (raw)
In-Reply-To: lqju32$r3i$1@speranza.aioe.org
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
next prev parent reply other threads:[~2014-07-21 20:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-21 20:44 Rough proposal to make some generic types static Victor Porton
2014-07-21 20:54 ` Victor Porton [this message]
2014-07-21 21:28 ` Niklas Holsti
2014-07-21 21:32 ` Victor Porton
2014-07-21 21:43 ` Niklas Holsti
2014-07-21 23:10 ` Randy Brukardt
2014-07-21 21:39 ` Adam Beneschan
2014-07-21 21:44 ` Victor Porton
2014-07-21 21:54 ` Adam Beneschan
2014-07-21 21:58 ` Victor Porton
2014-07-22 0:20 ` Randy Brukardt
2014-07-23 21:36 ` Robert A Duff
2014-07-21 22:06 ` Shark8
2014-07-21 23:12 ` Randy Brukardt
2014-07-22 9:53 ` AdaMagica
2014-07-22 21:10 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox