* Re: Inheritance question...
1997-03-23 0:00 Inheritance question Marc Bejerano
@ 1997-03-24 0:00 ` Jerome Desquilbet
1997-03-24 0:00 ` Robert A Duff
1997-03-25 0:00 ` Tucker Taft
2 siblings, 0 replies; 4+ messages in thread
From: Jerome Desquilbet @ 1997-03-24 0:00 UTC (permalink / raw)
To: mbejeran
See 3.9.1(3).
Then see 3.10.2 for a discussion on accessibility levels.
In your example, you should declare My_Bar in a package specification.
Hope this helps,
Jerome.
______________________________________________________________________
Jerome Desquilbet jDesquilbet@Rational.COM
' ^
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Inheritance question...
1997-03-23 0:00 Inheritance question Marc Bejerano
1997-03-24 0:00 ` Jerome Desquilbet
@ 1997-03-24 0:00 ` Robert A Duff
1997-03-25 0:00 ` Tucker Taft
2 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 1997-03-24 0:00 UTC (permalink / raw)
In article <33361956.4F30@pacbell.net>,
Marc Bejerano <mbejeran@pacbell.net> wrote:
>when I try to create a descendent type in my main procedure I get:
>
> "type extension at deeper accessibility level than parent"
>
>here's my "simplified" main procedure:
>
>with foo; use foo;
>
>procedure foofoo is
> type my_bar is new bar1 with record
> s: string(1..128);
> end record;
>what am I doing wrong?
Bar1 is declared at library level. My_Bar is declared one level deeper
-- within a procedure. This can cause dangling references, and is
therefore not allowed. You should put My_Bar in a library package, not
inside a procedure. Basically, "deepness" is a count of how many
procedures, functions, block statements, and tasks you're inside --
packages don't count.
The fact that it's the main procedure is irrelevant -- it's still a
procedure. Note that in Ada, code can execute after the main procedure
has returned -- namely, library tasks keep going, and if they got their
hands on an object whose tag was My_Bar'Tag, they could reference stuff
that no longer exists.
- Bob
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Inheritance question...
1997-03-23 0:00 Inheritance question Marc Bejerano
1997-03-24 0:00 ` Jerome Desquilbet
1997-03-24 0:00 ` Robert A Duff
@ 1997-03-25 0:00 ` Tucker Taft
2 siblings, 0 replies; 4+ messages in thread
From: Tucker Taft @ 1997-03-25 0:00 UTC (permalink / raw)
Marc Bejerano (mbejeran@pacbell.net) wrote:
: I have a package called foo...
: package foo is
: type bar is tagged private;
: type bar1 is new bar with private;
: .
: .
: .
: private
: type bar is tagged record
: v: integer;
: end record;
: type bar1 is new bar with record
: vv: character;
: end record;
: end foo;
: when I try to create a descendent type in my main procedure I get:
: "type extension at deeper accessibility level than parent"
This one should be in the FAQ...
: here's my "simplified" main procedure:
: with foo; use foo;
: procedure foofoo is
: type my_bar is new bar1 with record
: s: string(1..128);
: end record;
: begin
: .
: .
: .
: end foofoo;
: what am I doing wrong?
The declarations inside a procedure are at a deeper "accessibility"
level than the declarations outside the procedure. Accessibility
level is essentially the same thing as dynamic nesting level.
Packages don't increase the accessibility level, but functions,
procedures, tasks, and declare-blocks do.
When you extend a tagged type, you must do it at the same accessibility
level as the parent type. Hence, you must move your type extension
into a package, which you "with" from your procedure foofoo.
The reason for this limitation is that a copy of an object of
your type extension "my_bar" might be created in the heap, and then
your procedure foofoo might exit. If you had overridden any
primitive operations on the type, those overridings would
also be "gone" once foofoo exited. The copy of the "my_bar" object
would effectively have dangling references to the primitive operations
declared inside foofoo.
The simplest rule to remember is never declare a tagged type,
including a type extension, inside a function or procedure.
Define types at the package level.
: TIA, Marc
-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Burlington, MA USA
^ permalink raw reply [flat|nested] 4+ messages in thread