Ada Reference Manual (Ada 2022)Legal Information
Contents   Index   References   Search   Previous   Next 

4.1.4 Attributes

1
An attribute is a characteristic of an entity that can be queried via an attribute_reference or a range_attribute_reference.

Syntax

2/5
attribute_reference ::= 
    prefix'attribute_designator
  | reduction_attribute_reference
3/2
attribute_designator ::= 
    identifier[(static_expression)]
  | Access | Delta | Digits | Mod
4
range_attribute_reference ::= prefix'range_attribute_designator
5
range_attribute_designator ::= Range[(static_expression)]

Name Resolution Rules

6/5
In an attribute_reference that is not a reduction_attribute_reference, if the attribute_designator is for an attribute defined for (at least some) objects of an access type, then the prefix is never interpreted as an implicit_dereference; otherwise (and for all range_attribute_references and reduction_attribute_references), if there is a prefix and the type of the name within the prefix is of an access type, the prefix is interpreted as an implicit_dereference. Similarly, if the attribute_designator is for an attribute defined for (at least some) functions, then the prefix is never interpreted as a parameterless function_call; otherwise (and for all range_attribute_references and reduction_attribute_references), if there is a prefix and the prefix consists of a name that denotes a function, it is interpreted as a parameterless function_call.
7
The expression, if any, in an attribute_designator or range_attribute_designator is expected to be of any integer type. 

Legality Rules

8
The expression, if any, in an attribute_designator or range_attribute_designator shall be static. 

Static Semantics

9/4
An attribute_reference denotes a value, an object, a subprogram, or some other kind of program entity. Unless explicitly specified otherwise, for an attribute_reference that denotes a value or an object, if its type is scalar, then its nominal subtype is the base subtype of the type; if its type is tagged, its nominal subtype is the first subtype of the type; otherwise, its nominal subtype is a subtype of the type without any constraint, null_exclusion, or predicate. Similarly, unless explicitly specified otherwise, for an attribute_reference that denotes a function, when its result type is scalar, its result subtype is the base subtype of the type, when its result type is tagged, the result subtype is the first subtype of the type, and when the result type is some other type, the result subtype is a subtype of the type without any constraint, null_exclusion, or predicate. 
10
A range_attribute_reference X'Range(N) is equivalent to the range X'First(N) .. X'Last(N), except that the prefix is only evaluated once. Similarly, X'Range is equivalent to X'First .. X'Last, except that the prefix is only evaluated once.

Dynamic Semantics

11/5
The evaluation of a range_attribute_reference or an attribute_reference that is not a reduction_attribute_reference consists of the evaluation of the prefix. The evaluation of a reduction_attribute_reference is defined in 4.5.10

Implementation Permissions

12/5
An implementation may provide implementation-defined attributes; the identifier for such an implementation-defined attribute shall differ from those of the language-defined attributes. 
13/5
An implementation may extend the definition of a language-defined attribute by accepting uses of that attribute that would otherwise be illegal in the following cases:
14/5
in order to support compatibility with a previous edition of of this Reference Manual; or
15/5
in the case of a language-defined attribute whose prefix is required by this document to be a floating point subtype, an implementation may accept an attribute_reference whose prefix is a fixed point subtype; the semantics of such an attribute_reference are implementation defined. 
16
NOTE 1   Attributes are defined throughout this document, and are summarized in K.2.
17/5
NOTE 2   By the general rules given above, there is no expected type or profile for the name in a prefix of an attribute_reference (or a range_attribute_reference), which means that no context can be used to resolve the name. However, by the rules given in 3.10.2 for the case of the Access attribute, the expected type for the attribute_reference will be a single access type, and the resolution of the name can make use of the designated type or profile of this access type.

Examples

18
Examples of attributes:
19
Color'First        -- minimum value of the enumeration type Color    (see 3.5.1)
Rainbow'Base'First -- same as Color'First                            (see 3.5.1)
Real'Digits        -- precision of the type Real                     (see 3.5.7)
Board'Last(2)      -- upper bound of the second dimension of Board   (see 3.6.1)
Board'Range(1)     -- index range of the first dimension of Board    (see 3.6.1)
Pool(K)'Terminated -- True if task Pool(K) is terminated             (see 9.1)
Date'Size          -- number of bits for records of type Date        (see 3.8)
Message'Address    -- address of the record variable Message
                   --                                                (see 3.7.1)

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe