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.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.software-eng:276 comp.lang.ada:1045 Path: utzoo!yunexus!geac!daveb From: daveb@geac.UUCP (David Collier-Brown) Newsgroups: comp.software-eng,comp.lang.ada Subject: Re: Writing upgradable data structures Summary: Forwarded by permission of author. Message-ID: <2417@geac.UUCP> Date: 8 Mar 88 13:39:14 GMT Article-I.D.: geac.2417 Posted: Tue Mar 8 08:39:14 1988 References: <2307@geac.UUCP> <2767@enea.se> Reply-To: daveb@geac.UUCP (David Collier-Brown) Followup-To: comp.software-eng Organization: The Geac Ada Department. List-Id: Date: Fri, 4 Mar 88 23:33 EST From: Barry Margolin Subject: Re: Writing upgradable data structures To: David Collier-Brown In-Reply-To: <8803011228.AA18007@geac.UUCP> Message-Id: <19880305043329.6.BARMAR@OCCAM.THINK.COM> While I was in the Multics group at Honeywell we did some investigation of implementing a Multics followon in Ada. I thought the same thing regarding versioned structures, but I was convinced by some more experienced Ada people that we could do this using variant records. When you upgrade the structure you add a new variant. This does require recompiling users of the structure, but it doesn't force old, stable programs to be recoded unless they want to take advantage of the new structure's features. >from dave: > Would you consider posting a variant of this? The requirement that > one update is an important one, and should be faced by the Ada > community. Here's an example, but the idea is pretty simple. If you want to post it to comp.software-eng (I don't think it is appropriate for comp.lang.c, and I don't subscribe to comp.software-eng), feel free. type THING is record VERSION: constant (THING_VERSION_1, THING_VERSION_2, THING_VERSION_3, ...); -- first, the components common to all versions PART1: ; PART2: ; case VERSION of -- No THING_VERSION_1 case, because it only has the common parts when THING_VERSION_2 => PART3: ; PART4: ; when THING_VERSION_3 => PART3: ; PART4: ; PART5: ; PART6: ; when ... end case; end record; Unfortunately, Ada requires you to repeat the common prefixes in each version. One thing I thought of was to use type THING is record VERSION: constant (THING_VERSION_1, THING_VERSION_2, THING_VERSION_3, ...); -- first, the components common to all versions PART1: ; PART2: ; case VERSION of -- No THING_VERSION_1 case, because it only has the common parts when THING_VERSION_2 => PART3: ; PART4: ; when THING_VERSION_3 => COMMON: THING (VERSION => THING_VERSION_2); PART5: ; PART6: ; ... when THING_VERSION_n => COMMON: THING (VERSION => THING_VERSION_n-1); PARTm-1: ; PARTm: ; end case; end record; First of all, I don't know whether Ada allows recursive type declarations like this; if it doesn't, the above becomes: type THING_V1 is record PART1: ; PART2: ; end record; type THING_V2 is record COMMON: THING_V1; PART3: ; PART4: ; end record; ... type THING_Vn is record COMMON: THING_Vn-1; PARTm-1: ; PARTm: ; type THING is record VERSION: constant (THING_VERSION_1, THING_VERSION_2, THING_VERSION_3, ...); case VERSION of when THING_VERSION_1 => CONTENTS: THING_V1; when THING_VERSION_2 => CONTENTS: THING_V2; ... when THING_VERSION_n => CONTENTS: THING_Vn; end case; end record; A problem with this, though, is that I think Ada requires the program to specify all levels of a structure in a reference to a component, so a program that wants to access PART1 of a THING must use X.CONTENTS.PART1 if it is a version 1 THING, but X.CONTENTS.CONTENTS.CONTENTS.PART1 if it is a version 3 THING. PL/I permits the program to leave out structure qualifiers if the reference is unambiguous. I don't subscribe to comp.software-eng, so if anyone has any comments on this, reply via mail. -- Barry Margolin Thinking Machines Corp. barmar@think.com uunet!think!barmar