comp.lang.ada
 help / color / mirror / Atom feed
* meaning of "current instance"
@ 1999-11-11  0:00 Matthew Heaney
  1999-11-11  0:00 ` tmoran
  1999-11-11  0:00 ` Robert A Duff
  0 siblings, 2 replies; 22+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


I have some code below that I thought had a bug (um, I mean "error"), 
but now I'm not so sure.

Suppose I have this:

  type T is tagged private;
...
  function Init (O : access T'Class)

  type T is
    tagged record
      I : Integer := Init (T'Access);
    end record;

If I have an object of type T:

declare
  O1 : T;
begin

then it's clear that the "current instance" to which T'Access refers has
type T.

But now suppose I derive from T:

  type NT is new T with null record;

and declare an instance of type NT:

declare
  O2 : NT;
begin

Object O2 (like O1) has a component I, which is initialized with the
"current instance."  But what is the type of the "current instance"
here, passed to Init?


--STX
with Ada.Text_IO;  use Ada.Text_IO;

package body P.C is

  function Do_Init (O : access NT) return Integer is
  begin
    Put_Line ("P.C.Do_Init");
    return 1;
  end;

end P.C;
package P.C is

  type NT is new T with null record;

private

  function Do_Init (O : access NT) return Integer;

end P.C;
with Ada.Text_IO;  use Ada.Text_IO;

package body P is

  procedure Put (O : in T'Class) is
  begin
    Put_Line ("I is" & Integer'Image (O.I));
  end;

  function Init (O : access T'Class) return Integer is
  begin
    Put_Line ("P.Init");
    return Do_Init (O);
  end;


  function Do_Init (O : access T) return Integer is
  begin
    Put_Line ("P.Do_Init");
    return 0;
  end;


end P;
package P is

  type T is tagged limited private;

  procedure Put (O : in T'Class);

private

  function Init (O : access T'Class) return Integer;

  function Do_Init (O : access T) return Integer;

  type T is
    tagged limited record
      I : Integer := Init (T'Access);
    end record;

end P;
with P;   use P;
with P.C; use P.C;

procedure Test_P is
  OT : T;
  ON : NT;
begin
  Put (OT);
  Put (ON);
end;




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

end of thread, other threads:[~1999-11-15  0:00 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-11  0:00 meaning of "current instance" Matthew Heaney
1999-11-11  0:00 ` tmoran
1999-11-11  0:00   ` Matthew Heaney
1999-11-12  0:00     ` tmoran
1999-11-11  0:00       ` Matthew Heaney
1999-11-12  0:00         ` tmoran
1999-11-12  0:00           ` Matthew Heaney
1999-11-12  0:00             ` tmoran
1999-11-12  0:00               ` Matthew Heaney
1999-11-13  0:00             ` Robert A Duff
1999-11-13  0:00           ` Nick Roberts
1999-11-13  0:00             ` Robert A Duff
1999-11-14  0:00               ` tmoran
1999-11-13  0:00                 ` Matthew Heaney
1999-11-15  0:00                   ` John English
1999-11-15  0:00                     ` Matthew Heaney
1999-11-11  0:00 ` Robert A Duff
1999-11-11  0:00   ` Matthew Heaney
1999-11-11  0:00     ` Tucker Taft
1999-11-15  0:00   ` Tucker Taft
1999-11-15  0:00     ` tmoran
1999-11-15  0:00       ` Tucker Taft

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