* [Q]: Formal generic derived tagged type arguments (long)
@ 1996-03-19 0:00 Jonas Nygren
0 siblings, 0 replies; only message in thread
From: Jonas Nygren @ 1996-03-19 0:00 UTC (permalink / raw)
I have come to a state of great confusion regarding generics and
then mainly with how formal generic derived tagged types are supposed
to work.
The message is long with lots of detail together with questions which I do
not know how I should formulate better. If you want a go on, my question
here it comes:
Assume the following packages:
generic
type Item is private;
package Gen_Containers is
type Container is abstract tagged null record;
procedure Push_Back (C : in out Container; Value : Item) is abstract;
end Gen_Containers;
generic
with package Containers is new Gen_Containers(<>);
package Gen_Vector is
type Vector is new Containers.Container with private;
subtype Item is Containers.Item;
procedure Push_Back (V : in out Vector; Value : Item);
private
-- add private stuff
end Gen_Vectors;
package body Gen_Vectors is end; -- some implementation of Gen_Vectors
generic
with package Containers is new Gen_Containers(<>);
type Container is abstract new Containers.Container with private; -- line discussed in RM
package Gen_Adaptors is
type Adaptor is new Container with null record;
subtype Item is Containers.Item;
procedure Push (A : in out Adaptor; I : Item);
-- anything more needed here ??
end Gen_Adaptors;
package body Gen_Adaptors is
procedure Push (A : in out Adaptor; I : Item) is
begin
Push_Back(Adaptor'Class(A)); -- or should it be Push_Back(A); ??
end Push;
end Gen_Adaptors;
So how do I complete the declaration of Gen_Adaptors so that I later can
instantiate an Adaptors package in the following way:
package Containers is new Gen_Containers(Integer);
package Vectors is new Gen_Vectors(Containers);
package Adaptors is new Gen_Adaptors(Containers, Vectors.Vector);
The Adaptors should then use the supplied Vectors.Vector for their implementation.
For code similar to this, Gnat (an internal Act version) reports that Push_Back is
abstract in Gen_Adaptors. I don't understand why.
I have tried to read the RM but it is not easy. Below follows some questions
I have with regard to the writing on this topic.
Greatfull for any help,
Jonas Nygren
-------- Questions on RM text
Looking in the RM I find (12.5.1 Formal Private and Derived Types):
(18)
The presence of the reserved word abstract determines whether the actual
type may be abstract.
?? May be or must be - if 'abstract' is present and the actual argument is non-abstract
what are the consequences for the derived type Adaptor? Will Adaptor become non-abstract
(unless explicitly declared abstract of course) an if so what subprograms must be implemented
for Adaptor.
(19)
A formal private or derived type is a private or derived type, respectively.
A formal derived tagged type is a private extension. A formal private or
derived type is abstract if the reserved word abstract appears in its declaration.
?? What exactly does 'is a private or derived type' and 'is a private extension' imply?
Does it imply that the subtype Container together with its operations are
not visible outside of Gen_Adaptors?
(20)
If the ancestor type is a composite type that is not an array type, the formal
type inherits components from the ancestor type (including discriminants if a new
discriminant_part is not specified), as for a derived type defined by a
derived_type_definition (see 3.4).
?? Does this mean that Adaptor inherits the subprograms defined for Containers.Container?
(21)
For a formal derived type, the predefined operators and inherited user-defined
subprograms are determined by the ancestor type, and are implicitly declared at
the earliest place, if any, within the immediate scope of the formal type, where
the corresponding primitive subprogram of the ancestor is visible (see 7.3.1).
?? What does the above mean to me - what can I do, what must I do.
In an instance, the copy of such an implicit declaration declares a view of
the corresponding primitive subprogram of the ancestor, even if this primitive
has been overridden for the actual type.
?? Does this mean that I have an abstract subprogram inherited from Containers.Container
that need to be implemented. If so, to what type does this abstract subprogram belong to.
In the case of a formal private extension,
?? Yes this is what I have in Gen_Adaptors!
however, the tag of the formal type is that of the actual type, so if the tag in a
call is statically determined to be that of the formal type, the body executed will
be that corresponding to the actual type.
?? What does this mean to my example? Does it mean that if I call Push_Back(Adaptor'Class(A))
this call will automagically lead to the execution of Gen_Vectors.Push_Back, if I passed
Gen_Vectors as the actual argument. Or should the call be Push_Back(A).
-------------------------------------------------------
-- Jonas Nygren
-- ehsjony@ehs.ericsson.se
-------------------------------------------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1996-03-19 0:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-19 0:00 [Q]: Formal generic derived tagged type arguments (long) Jonas Nygren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox