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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56dbd715fa74735a,start X-Google-Attributes: gid103376,public From: adam@irvine.com Subject: Mutually dependent private types Date: 1998/05/21 Message-ID: <6k25ra$6j7$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 355340564 X-Http-User-Agent: Mozilla/3.0 (X11; I; Linux 2.0.18 i586) Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu May 21 21:20:42 1998 GMT Newsgroups: comp.lang.ada Date: 1998-05-21T00:00:00+00:00 List-Id: I've run into another problem trying to get something implemented in Ada 95. This problem seems superficially similar to John Volan's with-ing problem, but I don't think it's quite the same. (1) If I want to have two private types in two separate packages whose *implementations* are mutually dependent on each other, this is easy to do, if we're willing to make the private types accesses: package P1 is type T1 is private; private type T1_Info; type T1 is access T1_Info; end P1; package P2 is type T2 is private; private type T2_Info; type T2 is access T2_Info; end P2; and this will work since it's legal for P1's package body to depend on P2 and P2's package body to depend on P1. The definitions of P1.T1_Info and P2.T2_Info would contain references to the other package's type. (2) Another mutual-dependency situation is this: Suppose I want to have two types T1 and T2 in two different packages, and I want to provide operations on T1 that take T2 as a parameter, and operations on T2 that take T1 as a parameter. You can't do this by declaring T1 and T1's operations in the same package and do the same for T2, since then the two package specs would have to be mutually dependent. However, you can solve this problem by separating the type definition from the operations in two separate packages (preferably using child units): package P1 is type T1 is ... end P1; package P2 is type T2 is ... end P2; with P2; package P1.Operations is procedure Some_Operation (X : T1; Y : P2.T2); end P1.Operations; with P1; package P2.Operations is procedure Some_Operation (X : T2; Y : P1.T1); end P2.Operations; Actually, you don't have to do this for both packages; you can solve the problem by splitting the operations in just one of the packages. (3) But what happens if you want to do both (1) and (2)? Now the whole thing seems to break down. If you try to do both of the above, something like: package P1 is type T1 is private; private type T1_Info; type T1 is access T1_Info; end P1; with P2; package P1.Operations is procedure Some_Operation (X : T1; Y : P2.T2); end P1.Operations; you can't, because the body of Some_Operation cannot do anything useful with X, since the definition of T1_Info is not visible to it. I've been trying to come up with some way around this problem; for example, I thought about putting some routines in the private part of P1 that P1.Operations could access to give it information about T1_Info, or by setting up another private child package to declare actual type info, but I couldn't quite get anything to work. Does anyone know of a good way to accomplish this, without using Unchecked_Conversion? (It's pretty easy to come up with a solution using Unchecked_Conversion.) I might be missing something obvious here due to my incomplete knowledge of Ada 95. P.S. I believe this would also be solved by Tucker Taft's "with type" proposed language extension. -- thanks, Adam -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading