From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,FROM_ADDR_WS autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 18 Feb 93 23:52:27 GMT From: gate.ready.com!taurus.cs.nps.navy.mil!erickson@decwrl.dec.com (David Eri ckson) Subject: compilation order of generic body & instantiation Message-ID: List-Id: I ran into a compilation problem that I don't understand: the package below compiles, but if I attempt to instantiate it in a procedure ("driver"), the compiler (Meridian Sparc Ada) will produce an error listing at the point of instantiation. The error is: "driver.a", 3: identifier not found "binary_tree" [LRM 4.1/3] If the compilation order is changed (the original order is package spec, body and driver) to spec, driver then body, the compilation produces no errors, but the linking stage produces: bamp: "driver" must be recompiled [LRM 10.3/2] bamp: "driver" has unresolved generic instantiations bamp: the body of "driver" must be compiled [LRM 10.3/2] I found that if I move the definition of TRAVERSE so that it comes prior to function PARENT (which includes an instantiation of TRAVERSE), the error goes away. So what is the cause of the problem? Does Ada require that the body of a generic procedure come before an instantiation? Or is this a bug in the Meridian compiler? I tried compiling the same program using Verdix Ada, and had no problems with either ordering of TRAVERSE and PARENT. generic type ATOM is private; package BIN_TREE is type BINARY_TREE is private; type TRAVERSAL_TYPE is (PRE_ORDER, IN_ORDER, POST_ORDER); TREE_ERROR: exception; function EMPTY(T : BINARY_TREE) return BOOLEAN; function PARENT(P, T : BINARY_TREE) return BINARY_TREE; generic with procedure PROCESS(T: in out BINARY_TREE) is <>; procedure TRAVERSE(T : in out BINARY_TREE; MODE : TRAVERSAL_TYPE); private type NODE; type BINARY_TREE is access NODE; end BIN_TREE; package body BIN_TREE is type NODE is record A: ATOM; L,R: BINARY_TREE; end record; function EMPTY(T : BINARY_TREE) return BOOLEAN is begin return T = null; end EMPTY; function PARENT(P, T : BINARY_TREE) return BINARY_TREE is -- Returns the position in T of P's parent (or null if P is not in -- T). Precondition: P /= T and P is non-empty. ROOT : BINARY_TREE := T; -- local copy of T used as in out parameter RESULT : BINARY_TREE; procedure TEST_PARENT(T : in out BINARY_TREE) is -- uses non-local P and RESULT (which are declared in PARENT) in -- order to conform to the specifications for PROCESS. Likewise, -- T is in out begin if (T.L = P) or (T.R = P) then RESULT := T; end if; end TEST_PARENT; procedure FIND_PARENT is new TRAVERSE(PROCESS => TEST_PARENT); -- FIND_PARENT does a traverse, and sets non-local variable RESULT begin -- PARENT if P = ROOT or EMPTY(P) then raise TREE_ERROR; else FIND_PARENT(ROOT, PRE_ORDER); return RESULT; end if; end PARENT; procedure TRAVERSE(T : in out BINARY_TREE; MODE : TRAVERSAL_TYPE) is -- visits every node in T in preorder, inorder or postorder. -- T is an in out parameter, since Process requires an in out -- parameter. begin if not EMPTY(T) then if MODE = PRE_ORDER then PROCESS(T); TRAVERSE(T.L, MODE); TRAVERSE(T.R, MODE); elsif MODE = IN_ORDER then TRAVERSE(T.L, MODE); PROCESS(T); TRAVERSE(T.R, MODE); else TRAVERSE(T.L, MODE); TRAVERSE(T.R, MODE); PROCESS(T); end if; end if; end TRAVERSE; end BIN_TREE; with BIN_TREE; procedure DRIVER is package MY_TREE is new BIN_TREE(CHARACTER); -- error occurs here use MY_TREE; T: BINARY_TREE; begin if EMPTY(T) then return; end if; end DRIVER;