Version 1.2 of si99s/si99-0045-1.txt

Unformatted version of si99s/si99-0045-1.txt version 1.2
Other versions for file si99s/si99-0045-1.txt

!standard 17.1          09-02-21 SI99-0045-1/02
!class binding interpretation 08-10-21
!status work item 08-10-21
!status received 08-10-21
!priority Low
!difficulty Easy
!qualifier Omission
!subject The meaning of Corresponding_Expression_Type
!summary
If Corresponding_Expression_Type is applied to an expression that has the type of Something'Base, the declaration of the type Something is returned.
If Corresponding_Expression_Type is applied to an expression that has any other anonymous type, Nil_Element is returned.
!question
Corresponding_Expression_Type (17.1) insists on not "unwinding" subtypes. What should be returned by Corresponding_Expression_Type(Var), if the declaration of Var is as follows:
Var : Integer range 1..10;
There is no declaration for the subtype of Var.
More generally, an expression has a type, but no subtype. There should be an explanation about what is returned. Presumably: - For a variable or a constant: the subtype used in the declaration (but
see above)
- For a function call: the subtype used in the function declaration - For named number, a numeric literal: perhaps Nil? Universal types have no
declaration.
!recommendation
(See summary.)
!wording
Replace the wording of 17.1 as follows:
function Corresponding_Expression_Type (Expression : in Asis.Expression) return Asis.Declaration;
Expression specifies the expression to query.
Returns the declaration for the subtype named by the subtype mark in the definition of the nominal subtype of the expression. If the subtype mark in the definition is a Base attribute reference, the declaration of the prefix of the attribute is returned.
Returns a Nil_Element if the expression is of an anonymous or classwide type, or is a named number, numeric literal, null literal, aggregate, or attribute reference.
Returns a Nil_Element if the expression denotes an entity that does not have a type, such as a package or an exception.
NOTE:
This query does not "unwind" subtypes or derived types to get to the first subtype or parent subtype declarations, but it does ignore explicit constraints or null exclusions in the definition of the nominal subtype. For example, for the following program text:
type Int is range -5_000 .. 5_000; type My_Int is new Int; type Good_Int is new My_Int; Var: Good_Int range -2_000 .. 2_000;
for Corresponding_Expression_Type of an expression denoting Var, the declaration for Good_Int should be returned. No further "unwinding" should occur. The declaration for either My_Int or Int should not be returned.
!discussion
This is a very strange function, as it would lose some constraints (or return Nil for things that have perfectly useful values). It would be useful to give you the type, but it doesn't do that. What does it do for anonymous arrays?
We don't want to change the meaning of this function, because it would be hard to find bugs caused by such a change. We make a special case for 'Base, returning the prefix type (Integer'Base would return Integer).
However, for other anonymous types, it would not make sense to return some type that is part of the definition. For instance, for anonymous access types, this would lose the fact that it is an access type. So we just return nil_element. If the actual type is important, the semantic subsystem should be used.
Note that the case of a class-wide type is already defined as returning a Nil_Element.
Note that a single task or protected object has an anonymous type: this is consistent with the previous definition (but without the stupid explanation of being "limited on purpose").
!appendix

****************************************************************

Questions? Ask the ACAA Technical Agent