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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,19502ac20a7b16de,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-19 01:45:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!213.200.246.247!not-for-mail From: Vinzent Hoefler Newsgroups: comp.lang.ada Subject: Dynamic discrimants in variant records? Date: Thu, 19 Jun 2003 10:44:21 +0200 Organization: JeLlyFish software Message-ID: NNTP-Posting-Host: 213.200.246.247 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: fu-berlin.de 1056012355 23520677 213.200.246.247 (16 [175126]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:39435 Date: 2003-06-19T10:44:21+02:00 List-Id: Hi, I got the following question for a type with discrimants. Following an excerpt from the current source (more a case study than anything useful yet) with a representation of a memory mapped hardware register: | -- type for a programmable address region register | type Programmable_Address_Region ( | Target : Window_Target :=3D Window_Disabled; | Pg_Sz : Page_Size :=3D Four_Ki_Byte) is | record | case Target is | when Window_Disabled =3D> | null; | when GP_Bus_IO | PCI_Bus =3D> | IO_Attr : Chip_Select_Signal; | Sz_St_Addr_IO : IO_Page; | when GP_Bus_Memory | Boot_CS | Rom_CS_1 | Rom_CS_2 | SD_Ram = =3D> | Mem_Attr : Memory_Attribute; | | case Pg_Sz is | when Four_Ki_Byte =3D> | Sz_St_Addr_4K : Mem_Page_4K; | when Sixty_Four_Ki_Byte =3D> | Sz_St_Addr_64K : Mem_Page_64K; | end case; | end case; | end record; Well, so far so good, I can perfectly define a corresponding type statically. Deciding which of the registers to use for what region of memory statically is probably quite ok for most real world cases, but I really would like to have a little bit more flexibility. As mentioned, the actual (global) variables of this type are memory mapped registers, so the problem occurs when I want to change a region register dynamically (from a 4K granularity to a 64K for instance). In Ada this would be equivalent to just change some of the discrimants (those are really some bits in the register) and so changing the interpretation of the record. AFAICS this is not allowed in Ada, once a variable of a specific type is declared I cannot change its discriminants anymore. Is there any nice Ada-ish way around this? Or IOW, how would someone do that what I want in the most efficient way? Declaring an appropriate type each time and use an unchecked conversion to apply it to the "real" memory mapped register? Vinzent. --=20 There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other is to make it so complicated that there are no obvious deficiencies. -- T. Hoare