Go to the first, previous, next, last section, table of contents.


3.7.1 Discriminant Constraints

  1. A discriminant_constraint specifies the values of the discriminants for a given discriminated type.

    Syntax

  2. discriminant_constraint ::=
       (discriminant_association {, discriminant_association})
    
  3. discriminant_association ::=
       [discriminant_selector_name
         {| discriminant_selector_name} =>] expression
    
    1. A discriminant_association is said to be named if it has one or more discriminant_selector_names; it is otherwise said to be positional. In a discriminant_constraint, any positional associations shall precede any named associations.

Name Resolution Rules

  1. Each selector_name of a named discriminant_association shall resolve to denote a discriminant of the subtype being constrained; the discriminants so named are the associated discriminants of the named association. For a positional association, the associated discriminant is the one whose discriminant_specification occurred in the corresponding position in the known_discriminant_part that defined the discriminants of the subtype being constrained.
  2. The expected type for the expression in a discriminant_association is that of the associated discriminant(s).

    Legality Rules

  3. A discriminant_constraint is only allowed in a subtype_indication whose subtype_mark denotes either an unconstrained discriminated subtype, or an unconstrained access subtype whose designated subtype is an unconstrained discriminated subtype.
  4. A named discriminant_association with more than one selector_name is allowed only if the named discriminants are all of the same type. A discriminant_constraint shall provide exactly one value for each discriminant of the subtype being constrained.
  5. The expression associated with an access discriminant shall be of a type convertible to the anonymous access type.

    Dynamic Semantics

  6. A discriminant_constraint is compatible with an unconstrained discriminated subtype if each discriminant value belongs to the subtype of the corresponding discriminant.
  7. A composite value satisfies a discriminant constraint if and only if each discriminant of the composite value has the value imposed by the discriminant constraint.
  8. For the elaboration of a discriminant_constraint, the expressions in the discriminant_associations are evaluated in an arbitrary order and converted to the type of the associated discriminant (which might raise Constraint_Error -- See section 4.6 Type Conversions.); the expression of a named association is evaluated (and converted) once for each associated discriminant. The result of each evaluation and conversion is the value imposed by the constraint for the associated discriminant.

    NOTES

  9. (54) The rules of the language ensure that a discriminant of an object always has a value, either from explicit or implicit initialization.

    Examples

  10. Examples (using types declared above in clause See section 3.7 Discriminants.):
  11. Large   : Buffer(200);  --  constrained, always 200 characters
                            --   (explicit discriminant value)
    Message : Buffer;       --  unconstrained, initially 100 characters
                            --   (default discriminant value)
    Basis   : Square(5);    --  constrained, always 5 by 5
    Illegal : Square;       --  illegal, a Square has to be constrained
    


Go to the first, previous, next, last section, table of contents.