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, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b3b14d98b684fc86,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-18 04:30:37 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!fr.clara.net!heighliner.fr.clara.net!proxad.net!oleane.net!oleane!jussieu.fr!u-psud.fr!not-for-mail From: Philippe Tarroux Newsgroups: comp.lang.ada Subject: Embedded hierarchy Date: Mon, 18 Dec 2000 13:36:06 +0100 Organization: Universite Paris-Sud, France. Message-ID: <3A3E04B6.C50B6CDC@limsi.fr> NNTP-Posting-Host: mpc128.limsi.u-psud.fr Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F0270765BB3E3E0CA9C37A7A" X-Mailer: Mozilla 4.7 [fr] (WinNT; I) X-Accept-Language: fr-FR,en Xref: supernews.google.com comp.lang.ada:3224 Date: 2000-12-18T13:36:06+01:00 List-Id: Il s'agit d'un message multivolet au format MIME. --------------F0270765BB3E3E0CA9C37A7A Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, I want to define two object hierarchies with one depending on the other: An object type and a structure containing objects (an array of object or something else. It doesn't matter). The constraints are that some operations must be defined for all the extensions of both classes (this is why both types must be tagged). I try to find a way to implement this problem in such a way that major misuse errors will be detected at compile time rather than at run time. Concretely, an implementation could be: The object class: package Obj_Handler is type Obj is abstract tagged null record; function "+"(A, B : Obj) return Obj is abstract; type Obj_A is new Obj with private; type Obj_B is new Obj with private; private function "+"(A, B : Obj_A) return Obj_A; function "+"(A, B : Obj_B) return Obj_B; type Obj_A is new Obj with null record; type Obj_B is new Obj with null record; end Obj_Handler; The map containing objects with Obj_Handler; use Obj_Handler; package Map_Handler is type Map is abstract tagged null record; function Object(M : access Map; I : Integer) return Obj'Class is abstract; type Map_A is new Map with private; type Map_A_Ptr is access Map_A; function Object(M : access Map_A; I : Integer) return Obj'Class; type Map_B is new Map with private; type Map_B_Ptr is access Map_B; function Object(M : access Map_B; I : Integer) return Obj'Class; private type ObjA_Tab is array(Integer range <>) of Obj_A; type ObjB_Tab is array(Integer range <>) of Obj_B; type Map_A is new Map with record Object : ObjA_Tab(1..100); end record; type Map_B is new Map with record Object : ObjB_Tab(1..100); end record; end Map_Handler; and a test program: with Obj_Handler; with Map_Handler; use Obj_Handler; use Map_Handler; procedure Test_Obj is A, B : Map_A_Ptr; C : Map_B_Ptr; X : Obj_A; begin X := Obj_A(Object(A,10))+Obj_A(Object(C,3)); end Test_Obj; which compiles, executes and produces a constraint error during the execution of the assignment X := ... The line is obviously faulty because Object(C,3) returns an Obj'Class which is in fact an Obj_B and not an Obj_A. But this assignation cannot be determined statically. I tried different solutions but it seems that there is no way to avoid the problem above. I thought it was possible to define: function Object(M : access Map; I : Integer) return Obj is abstract; and then overwrite this abstract function as: function Object(M : access Map_A; I : Integer) return Obj_A; but it seems that this last definition does not overwrite the abstract function correctly and I was unable to find a syntax that do it. Why does the compiler not complain about this statement if there is no way to overwrite it? Has somebody a suggestion to implement a better solution to this problem? Many thanks Development environment: gnat 3.12p under Windows NT 4.0 -- Philippe Tarroux LIMSI-CNRS email: tarroux@limsi.fr BP 133 Phone: +(33) 1 69 85 81 23 91470 Orsay cedex - France Fax : +(33) 1 69 85 80 20 --------------F0270765BB3E3E0CA9C37A7A Content-Type: text/x-vcard; charset=us-ascii; name="tarroux.vcf" Content-Transfer-Encoding: 7bit Content-Description: Carte pour Philippe Tarroux Content-Disposition: attachment; filename="tarroux.vcf" begin:vcard n:Tarroux;Philippe tel;fax:+(33) 1 69 85 80 88 tel;work:+(33) 1 69 85 81 23 x-mozilla-html:TRUE org:LIMSI-CNRS adr:;;BP 133;Orsay;;91403;France version:2.1 email;internet:tarroux@limsi.fr fn:Philippe Tarroux end:vcard --------------F0270765BB3E3E0CA9C37A7A--