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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c469fdacc2f3302b,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!188.40.43.213.MISMATCH!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: Dynamic Variant Record Creation Date: Tue, 16 Mar 2010 17:11:04 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: Injection-Date: Tue, 16 Mar 2010 17:11:04 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="9f8M0iN5t54V+4DF/iqO8g"; logging-data="19157"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PZ9sKy+MS/dHhbtrdAZhyWJxfxtBND2Q=" User-Agent: Xnews/5.04.25 X-Face: &6@]C2>ZS=NM|HE-^zWuryN#Z/2_.s9E|G&~DRi|sav9{E}XQJb*\_>=a5"q]\%A;5}LKP][1mA{gZ,Q!j Cancel-Lock: sha1:NdjP4zfCCWdtcHPmlfWE0HCDeao= Xref: g2news2.google.com comp.lang.ada:10563 Date: 2010-03-16T17:11:04+00:00 List-Id: I am trying to solve a lexer Ada design problem, using a variant record (Token_Unit) definition: type Token_Type is ( LEX_000, LEX_BINARY, LEX_SECTION, '!', '"', '#', '$', ...etc.. '^', '_', '`', LEX_SFUN3, LEX_SFUN2, LEX_SFUN1, LEX_SFUNN, LEX_FUN3, LEX_FUN2, LEX_FUN1, LEX_FUNN, ...etc... LEX_EOF ); type Token_Unit(Token : Token_Type := LEX_EOF) is record case Token is when LEX_SFUN3 | LEX_SFUN2 | LEX_SFUN1 | LEX_SFUNN | LEX_FUN3 | LEX_FUN2 | LEX_FUN1 | LEX_FUNN => Func : Func_Type; when LEX_IDENT | LEX_SIDENT | LEX_LNUMBER | LEX_NUMBER | LEX_HEX | LEX_STRLIT | LEX_INLREM | LEX_FLOAT | LEX_REM => ID : String_ID; when others => null; end case; end record; procedure Get_Token(Object : in out Lexer; Token : out Token_Unit) is procedure Emit_Token(T : Token_Type) is T : Token_Type := Token_Type'Val(Character'Pos(Ch)); begin Token := ( Token => T ); end; ... end; In the above, I need to create a Token_Unit from a single character (there is no "id" in this case). The values of operator characters are carefully coordinated in the Token_Type using a representation clause (just FYI). But the issue is this: *.adb:339:33: value for discriminant "token" must be static *.adb:339:33: "T" is not static constant or named number (RM 4.9(5)) I could put a huge case statement in, but I'd prefer not to. Is there a better way to handle the dynamic creation of a variant record? I have other scenarios involving a Func_Type and String_ID as well, which suffer from the same "must be static" problem. I should also mention that I am trying to keep the Token_Unit to 32-bits, for efficiency. If it were possible to divide up the Token_Type (16-bits) into 13-bits and use a different descriminant of 3 bits, that would work also if the total size remained 32. The String_ID portion (or Func_Type) are both 16-bit. Warren