comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: Dynamic Variant Record Creation
Date: Thu, 18 Mar 2010 12:57:30 +0000 (UTC)
Date: 2010-03-18T12:57:30+00:00	[thread overview]
Message-ID: <Xns9D3F5B219B1D7WarrensBlatherings@85.214.113.135> (raw)
In-Reply-To: hnov3m$t4o$1@tornado.tornevall.net

Jeffrey R. Carter expounded in news:hnov3m$t4o$1@tornado.tornevall.net:

> Warren wrote:
>> 
>> The other way for me to solve this is simply provide
>> a discrimanant that only identifies the few variants. But 
>> to keep to 32-bits, I'd have to find a way to specify the
>> discriminant as 3-bits, which I don't think is possible.
> 
> Looking at what you have, it looks like a design problem to me. You
> have a whole bunch of enumeration values, but you don't have a bunch
> of variants. I'd probably have an enumeration type with 3 values that
> serves as the discriminant. Then have 3 enumeration types, one for
> each variant, that gives the specific information that you're now
> trying to use for the discriminant as well. 

I looked at this closely last night and ended up agreeing
with you (design problem). So I changed it along the 
lines that you suggested:

type Token_Type(Aux : Aux_Kind := No_Aux) is    
    record
        Token :             Token_Kind := No_Token;
        case Aux is
            when SID_Aux =>
                SID :       String_ID;
            when FID_Aux =>
                FID :       Func_ID;
            when No_Aux =>
                null;
        end case;
    end record;

I was also able to get the representation I wanted (yeah):

for Token_Type use
    record
        Aux     at 0    range 0..2;
        Token   at 0    range 3..15;
        SID     at 0    range 16..31;
        FID     at 0    range 16..31;
    end record;

This design allows me to flexible in the auxiliary
information provided. For example, each "token line"
ends with a linefeed token (LEX_LF). However, each
statement has an optional "inline" comment like:

01000 LET OPEN_FLAG = FALSE    $ Mark file as not-opened.

Using the discriminant Aux allowed me to use a SID 
(Aux = SID_Aux) or not ( Aux = No_Aux ) as required:

T := ( Aux => SID_Aux, Token => LEX_LF, SID => ID );

  or

T := ( Aux = No_Aux, Token => LEX_LF );

As you pointed out, when designed this way, I always 
know the static representation required, even though 
the Token member may be variable.

I knew that we'd eventually converge on a solution. 
Thanks everyone.

Warren



  parent reply	other threads:[~2010-03-18 12:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16 17:11 Dynamic Variant Record Creation Warren
2010-03-16 18:31 ` Georg Bauhaus
2010-03-16 18:57 ` Adam Beneschan
2010-03-16 20:01   ` Warren
2010-03-16 20:09     ` Jeffrey R. Carter
2010-03-16 20:24       ` Warren
2010-03-16 20:40         ` Robert A Duff
2010-03-16 20:44           ` Warren
2010-03-16 20:31     ` Robert A Duff
2010-03-16 20:59       ` Warren
2010-03-16 21:55         ` Jeffrey R. Carter
2010-03-17 14:40           ` Warren
2010-03-18 12:57           ` Warren [this message]
2010-03-16 21:58         ` Robert A Duff
2010-03-17 14:22           ` Charmed Snark
2010-03-17 14:49             ` Robert A Duff
2010-03-17 16:30               ` Warren
2010-03-16 21:15       ` Adam Beneschan
2010-03-16 23:24       ` Adam Beneschan
2010-03-16 20:15   ` Robert A Duff
2010-03-16 21:00     ` Warren
2010-03-16 23:39   ` Randy Brukardt
2010-03-16 23:43     ` Randy Brukardt
2010-03-17  0:15     ` Robert A Duff
2010-03-17 14:28       ` Warren
2010-03-18  0:02       ` Randy Brukardt
2010-03-17  4:20     ` Adam Beneschan
2010-03-18  0:13       ` Randy Brukardt
2010-03-18 13:00         ` Warren
replies disabled

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