comp.lang.ada
 help / color / mirror / Atom feed
* Where are returned values stored? (follow up to yesterday's question)
@ 2004-05-26 19:46 James Alan Farrell
  2004-05-26 20:44 ` Simon Wright
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: James Alan Farrell @ 2004-05-26 19:46 UTC (permalink / raw)


Hello again,
This is a followup to the question I asked yesterday.  Below is a bit
of code from GNAT's ASIS library.  (I imagine this was written by
people with a lot more expertise in Ada than I have, and that this
code is okay.)

 It has a declarative part in the middle of the code, in which a
variable (Result)  is declared.  The stuff in that variable is
returned.

Now its my understanding that when variables are declared like this,
they are added onto the stack, then when the function returns, they
are popped off again, along with the regular stack frame.  So the
stuff returned goes away.

But, the calling function will need use of that data.  So it cannot go
away.  

So how does that work?  Where is the data placed so that it does not
go away, and how long will it be there so it (or rather pointers to
it) can be passed around to other functions?

(This relates to yesterday's question because  if this works the code
I posted yesterday ought to work)

Thanks again,
James Alan Farrell
GrammaTech


   function Compilation_Units
     (The_Context : in Asis.Context)
      return Asis.Compilation_Unit_List
   is
      Res_Cont_Id    : Context_Id := Get_Cont_Id (The_Context);
      Cont_Tree_Mode : Tree_Mode;
   begin
      Check_Validity (The_Context,
               "Asis.Compilation_Units.Compilation_Units");

      Cont_Tree_Mode := Tree_Processing_Mode (Res_Cont_Id);

      if not (Cont_Tree_Mode = Pre_Created or else
              Cont_Tree_Mode = Incremental)
      then
         Not_Implemented_Yet (Diagnosis =>
                  "Asis.Compilation_Units.Compilation_Units");
      end if;

      Reset_Context (Res_Cont_Id);

      declare
         Result_Len : Natural := Lib_Unit_Decls   (Res_Cont_Id) +
                                 Comp_Unit_Bodies (Res_Cont_Id);
         Result     : Compilation_Unit_List (1 .. Result_Len);
      begin
         for I in 1 .. Result_Len loop
            Result (I) := Get_Comp_Unit
                  (First_Unit_Id + Unit_Id (I) - 1, Res_Cont_Id);
         end loop;
         return Result;
      end;

   exception
      when ASIS_Failed =>
         Add_Call_Information (Outer_Call =>
                     "Asis.Compilation_Units.Compilation_Units");
         raise;
      when others =>
         Raise_ASIS_Failed (Diagnosis =>
                     "Asis.Compilation_Units.Compilation_Units");
   end Compilation_Units;




^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2004-06-09  7:03 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-26 19:46 Where are returned values stored? (follow up to yesterday's question) James Alan Farrell
2004-05-26 20:44 ` Simon Wright
2004-05-27  7:51   ` Dmitry A. Kazakov
2004-05-27  9:39 ` Where are returned values stored? Marius Amado Alves
2004-05-27 17:05   ` Warren W. Gay VE3WWG
2004-05-27 20:24     ` James Alan Farrell
2004-05-28 20:33       ` Warren W. Gay VE3WWG
2004-05-29  7:03         ` Martin Krischik
2004-05-29 13:19           ` Larry Kilgallen
2004-05-30  7:10             ` Martin Krischik
2004-06-02  3:14         ` Robert I. Eachus
2004-05-30 21:17     ` Nick Roberts
2004-05-31 12:58       ` Warren W. Gay VE3WWG
2004-06-02  4:07         ` Robert I. Eachus
2004-06-02 12:42           ` Warren W. Gay VE3WWG
2004-06-03  2:00             ` Nick Roberts
2004-06-03  4:34             ` Robert I. Eachus
2004-06-03 16:06               ` Warren W. Gay VE3WWG
2004-06-03 16:13               ` Nick Roberts
2004-06-07  1:53                 ` Robert I. Eachus
2004-06-07 13:09                   ` Larry Kilgallen
2004-06-09  7:03                     ` Robert I. Eachus
2004-06-05 17:13             ` Simon Wright
2004-05-27 17:11   ` Martin Krischik
2004-05-27 17:07 ` Where are returned values stored? (follow up to yesterday's question) Martin Krischik

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