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,e044473b43baaf18 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-24 10:39:55 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news-FFM2.ecrc.net!eusc.inter.net!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: automatic tag conversion? Date: Sat, 24 May 2003 17:39:54 +0000 (UTC) Organization: GMUGHDU Message-ID: References: NNTP-Posting-Host: d2-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1053797994 26311 134.91.1.15 (24 May 2003 17:39:54 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Sat, 24 May 2003 17:39:54 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/831)) Xref: archiver1.google.com comp.lang.ada:37734 Date: 2003-05-24T17:39:54+00:00 List-Id: Stephan Heinemann wrote: : Stephan Heinemann wrote: : :> t: Tag; :> subvar: Subtype; :> ... :> t := supervar'Tag; :> subvar := t'convert(supervar); -- convert(t, supervar) :> polymorphic(subvar); : : Of course I don't know what the concrete Subtype is and I don't wanna : know. Therefore the code snippet is wrong. I meant: If I understand your wording correctly (in Ada, a subtype is different from a derived type (subtypes add value constraints, they do not extend)), it might be simpler. I hope i don't tell matters of course, as I might have missed the intent of your question. Consider this small hierarchy. package R is -- a tagged type type T is tagged record null; end record; function About(it: T) return String; type Switch_State is (on, off); -- an ad hoc Boolean type, used in the derived type TT -- a derived type, extended version of T (what you have called -- a subtype, I believe) type TT is new T with record toggle: Switch_State; end record; function About(it: TT) return String; end R; Then, for a variable to be able to represent objects of any type in this hierarchy, it must either be class-wide, or it must be an access type (pointer, or reference). I have tried to make this distintion in the following snippet: with R; use R; procedure U is VV: TT; -- an instance of extended type TT begin objects: -- as opposed to object pointers declare Current: T := T(VV); -- upward conversion, some VV-components gone! begin -- therefore, the next line doesn't compile, because -- it would mean a downward conversion (with missing -- TT-components): VV := TT(Current); -- however, these do compile, because there is a match for every -- component needed in a TT instance. VV := (Current with toggle => on); VV := TT'(Current with toggle => on); end objects; object_pointers: declare type Poly is access T'class; -- Poly values may refer to T-objects or to TT-objects a_tt: Poly := new TT; a_t: Poly := new T; begin -- attempts to copy assumed TT values into vv vv := TT(a_tt.all); vv := TT(a_t.all); -- tag check will fail at run time end object_pointers; class_wide: -- (this is probably a very incomplete overview) declare any1: T'class := TT'(toggle => off); any2: T'Class := T'(null record) begin any1 := any2; -- run time exception (objects copied, not pointers) VV := TT(any1); end class_wide; end U; HTH, georg