* Limited types and generic parameters
@ 1989-02-22 12:27 Mats Weber
1989-02-22 14:58 ` Fred Hosch
0 siblings, 1 reply; 3+ messages in thread
From: Mats Weber @ 1989-02-22 12:27 UTC (permalink / raw)
Question on limited types and generic parameters.
Consider the following piece of Ada code:
generic
type T is limited private;
package GP is
type R is
record
F : T;
end record;
end GP;
package P is new GP(T => INTEGER);
X : P.R := (F => 45); -- *
Y : P.R := (F => 77); -- *
...
X.F := 56;
X := Y; -- *
Are the *-marked assignments correct ? In other words, is P.R a limited
type ?
LRM 7.4.4(2) says: "... a composite type is limited if the type
of any of its subcomponents is limited."
In this case, there are two possible interpretations:
- The declaration of type P.R occurs in the context of the generic
package GP.
- The declaration of type P.R occurs in the context of the instance P.
According to LRM 12.3(9) "For a name that denotes a generic formal type:
The corresponding name denotes the subtype named by the associated
generic actual parameter (the actual subtype)." The second interpretation
seems to be the right one, which would make the type P.R non limited.
What do you think ? (I would like J. Goodenough to see this).
Mats Weber
Swiss Federal Institute of Technology
EPFL DI LITh
1015 Lausanne
Switzerland
e-mail : madmats@elma.epfl.ch
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Limited types and generic parameters
1989-02-22 12:27 Limited types and generic parameters Mats Weber
@ 1989-02-22 14:58 ` Fred Hosch
0 siblings, 0 replies; 3+ messages in thread
From: Fred Hosch @ 1989-02-22 14:58 UTC (permalink / raw)
Without careful scrutiny of the LRM (always a mistake), the only reasonable
semantics seem to be the following.
The generic "entity" is interpreted in its defining environment;
thus, any free variables occuring in the generic are bound in the
context of the generic definition.
The generic instantiation "returns" an entity that is bound in
the instantiating environment; any generic formals are bound to
actuals interpreted in the instantiating environment.
Thus in the example
generic
type T is limited private;
package GP is
type R is
record
F : T;
end record;
end GP;
package P is new GP(T => INTEGER);
P.R.F is of type INTEGER in the instantiating environment.
(At least, that's my state-educated guess.)
Fred Hosch
fred@cs.utexas.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Limited types and generic parameters
@ 1989-02-23 5:51 Karl Nyberg
0 siblings, 0 replies; 3+ messages in thread
From: Karl Nyberg @ 1989-02-23 5:51 UTC (permalink / raw)
[Ed - forwarded]
-- Karl --
Mats Weber asks:
>> Consider the following piece of Ada code:
>>
>> generic
>> type T is limited private;
>> package GP is
>>
>> type R is
>> record
>> F : T;
>> end record;
>>
>> end GP;
>>
>> package P is new GP(T => INTEGER);
>>
>> X : P.R := (F => 45); -- *
>> Y : P.R := (F => 77); -- *
>> Are the *-marked assignments correct ? In other words, is P.R a limited
>> type ?
AI-398 answers a similar question for arrays:
... If the component type of an array type is a generic formal type or if
the designated type of an access type is a generic formal type, the
operations declared for the array and access type in the template depend
on the class of the formal type. If the array and access type
declarations do not occur in the generic formal part, then the operations
declared for these types in a generic instance are determined by the type
denoted by the formal parameter in the instance.
This means that if type R in the example were an array type with component
type T, assignments to an object of type R declared in the template would not
be allowed, but assignments to an object declared elsewhere (or in an
instance) would be okay as long as the actual type is not limited.
The reasoning underlying this interpretation for arrays extends to record
types, although these types were not addressed explicitly in the AI. So, in
short, the assignments in the example are considered legal.
Whether compilers support AI-398 is another question. I don't think any tests
on this point exist in the ACVC suite, and even if they did, the test
objectives on this point are (or were) not consistent with AI-398. But since
AI-398 is an approved commentary, compilers ought to support the kind of
assignments indicated in the question.
There are a number of other, rather subtle, issues raised in AI-398 related to
the effects of type derivation, but AI-398 follows the principal that the
appropriate operations are declared in the instance, even if the operations do
not exist in the template.
John B. Goodenough Goodenough@sei.cmu.edu
Software Engineering Institute 412-268-6391
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1989-02-23 5:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-02-22 12:27 Limited types and generic parameters Mats Weber
1989-02-22 14:58 ` Fred Hosch
-- strict thread matches above, loose matches on Subject: below --
1989-02-23 5:51 Karl Nyberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox