comp.lang.ada
 help / color / mirror / Atom feed
From: emory!europa.eng.gtefsd.com!howland.reston.ans.net!usc!cs.utexas.edu!uwm.
Subject: Re: compilation order of generic body & instantiation
Date: 25 Feb 93 16:05:20 GMT	[thread overview]
Message-ID: <1993Feb25.110520.28845@sei.cmu.edu> (raw)

In article <C2o4zF.M7o@taurus.cs.nps.navy.mil>, erickson@cs.nps.navy.mil (David
 Erickson) writes:
|> 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
	...
|>   generic
|>     with procedure PROCESS(T: in out BINARY_TREE) is <>;
|>   procedure TRAVERSE(T    : in out BINARY_TREE;
|>                      MODE : TRAVERSAL_TYPE);
	...
|> end BIN_TREE;
|> 
|> package body BIN_TREE is
	...
|>   function PARENT(P, T : BINARY_TREE) return BINARY_TREE is
	...
|>     procedure FIND_PARENT is
|>       new TRAVERSE(PROCESS => TEST_PARENT);
|>   begin       -- PARENT
	...
|>   end PARENT;
|> 
|>   procedure TRAVERSE(T    : in out BINARY_TREE;
|>                      MODE : TRAVERSAL_TYPE) is
	...
|>   begin
	...
|>   end TRAVERSE;
|> end BIN_TREE;
|> 
|> with BIN_TREE;
|> procedure DRIVER is
|>   package MY_TREE is new BIN_TREE(CHARACTER);  -- error occurs here
	...
|> begin
	...
|> end DRIVER;
|> 

First we need to consider whether there are elaboration order problems,
because an instantiation of TRAVERSE occurs textually prior to its body.
Presumably the procedure DRIVER is the main program, so the body of BIN_TREE
will be elaborated before BIN_TREE is instantiated (otherwise, you would need
to put a pragma ELABORATE (BIN_TREE) to ensure BIN_TREE's body is elaborated
in time).  The elaboration of BIN_TREE's body causes the body of TRAVERSE to
be elaborated before the function PARENT is called (since there is no call to
PARENT prior to the elaboration of TRAVERSE), so when PARENT is called the
body of TRAVERSE has been elaborated and the instantiation should proceed
correctly.  My point in discussing elaboration order is that putting the body
of TRAVERSE textually after an instantiation of TRAVERSE always raises the
possibility of elaboration order errors arising, so it's probably not good
style even if it works out this time.

Some implementations require that the body of a generic unit be compiled
before any instantiations of the unit are compiled.  AI-00506 allows such an
assumption for generic units that are compilation units, but does not go so
far as to extend this permission to cases like the above, I think in part
because the ARG didn't consider the above example.  The trend of
thinking at the time of AI-00506's approval was to allow implementations to
make this assumption, so maybe it is too strict to say that Meridian's
compiler is in error on this point.

John B. Goodenough					Goodenough@sei.cmu.edu
Software Engineering Institute				412-268-6391

             reply	other threads:[~1993-02-25 16:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-02-25 16:05 emory!europa.eng.gtefsd.com!howland.reston.ans.net!usc!cs.utexas.edu!uwm. [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-02-24 16:20 compilation order of generic body & instantiation agate!howland.reston.ans.net!newsserver.jvnc.net!netnews.upenn.edu!prijat
1993-02-18 23:52 gate.ready.com!taurus.cs.nps.navy.mil!erickson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox