P'Base definition vs. usage in LRM
Capability/request summary
This is a Bug Report + Feature Request rolled into one.
Attribute definition for P'base says:
P'BASE Kind: Type. Prefix: Any prefix P that is appropriate for an object with type or subtype T, or an alias thereof, or that denotes any type or subtype T. Result: The base type of T. Restrictions: This attribute is allowed only as the prefix of the name of another attribute; for example, P'BASE'LEFT.
The restriction is not phrased correctly. If it is meant to be an error, it should state that it is an error.
Restrictions: It is an error if this attribute is as anything other than as the prefix to another attribute; for example, P'BASE'LEFT.
from 5.3.2.1 page 61 of 1076-2019 says This is in a note
NOTE—The rules concerning constrained type declarations mean that a type declaration with a constrained array definition such as:
type T is array (POSITIVE range MIN_BOUND to MAX_BOUND) of ELEMENT;is equivalent to the sequence of declarations
subtype index_subtype is POSITIVE range MIN_BOUND to MAX_BOUND; type array_type is array (index_subtype range <>) of ELEMENT'BASE; subtype T is array_type (index_subtype)element_constraint;where index_subtype and array_type are both anonymous and element_constraint is the constraint that applies to the subtype ELEMENT. Consequently, T is the name of a subtype and all objects declared with this type mark are arrays that have the same index range.
Similarly, a type declaration with an unbounded array definition whose element subtype indication denotes a partially or fully constrained subtype such as
type T is array (INTEGER range <>) of STRING(1 to 10);is equivalent to the sequence of declarations
type array_type is array (INTEGER range <>) of STRING'BASE; subtype T is array_type (open)(1 to 10);
While the note is not normative, it should not be using an attribute in an illegal way.
Proposed Changes
Add an array based version:
A'BASE Kind: Subtype. Prefix: Any prefix A that is appropriate for an array object, or an alias thereof, or that denotes an array subtype. Result: The base type of A.
Or Alternately updated P'Base as
P'BASE Kind: Type. Prefix: Any prefix P that is appropriate for an object with type or subtype T, or an alias thereof, or that denotes any type or subtype T. Result: The base type of T. Restrictions: When the result type T is not an array type, this attribute is allowed only as the prefix of the name of another attribute; for example, P'BASE'LEFT.
Or based on Patrick's suggestion, update P'Base without restrictions:
P'BASE Kind: Type. Prefix: Any prefix P that is appropriate for an object with type or subtype T, or an alias thereof, or that denotes any type or subtype T. Result: The base type of T.
Use Models | Code Examples
function Reverse
( A : type is array(type is range <>) of type is private ) return A'subtype is
variable Result : A'base(A'reverse_range) ;
begin
for i in A'range loop
result(i) := A(i) ;
end loop ;
return Result ;
end function Reverse ; Notes
The above code currently works in one VHDL simulator.