Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

3.8 Record Types -- TOC

A record object is a composite object consisting of named components. The value of a record object is a composite value consisting of the values of the components.
       record_type_definition ::= [[abstract] tagged] [limited] record_definition
       record_definition ::=
           end record
         | null record
       component_list ::=
             component_item {component_item}
          | {component_item} variant_part
          |  null;
       component_item ::= component_declaration | representation_clause
       component_declaration ::=
          defining_identifier_list : component_definition [:= default_expression];
Name Resolution Rules
The expected type for the default_expression, if any, in a component_declaration is the type of the component.
Legality Rules
A default_expression is not permitted if the component is of a limited type.
Each component_declaration declares a component of the record type. Besides components declared by component_declarations, the components of a record type include any components declared by discriminant_specifications of the record type declaration. The identifiers of all components of a record type shall be distinct.
Within a type_declaration, a name that denotes a component, protected subprogram, or entry of the type is allowed only in the following cases:
If the name of the current instance of a type (see 8.6) is used to define the constraint of a component, then it shall appear as a direct_name that is the prefix of an attribute_reference whose result is of an access type, and the attribute_reference shall appear alone.
Static Semantics
The component_definition of a component_declaration defines the (nominal) subtype of the component. If the reserved word aliased appears in the component_definition, then the component is aliased (see 3.10).
If the component_list of a record type is defined by the reserved word null and there are no discriminants, then the record type has no components and all records of the type are null records. A record_definition of null record is equivalent to record null; end record.
Dynamic Semantics
The elaboration of a record_type_definition creates the record type and its first subtype, and consists of the elaboration of the record_definition. The elaboration of a record_definition consists of the elaboration of its component_list, if any.
The elaboration of a component_list consists of the elaboration of the component_items and variant_part, if any, in the order in which they appear. The elaboration of a component_declaration consists of the elaboration of the component_definition.
Within the definition of a composite type, if a component_definition or discrete_subtype_definition (see 9.5.2) includes a name that denotes a discriminant of the type, or that is an attribute_reference whose prefix denotes the current instance of the type, the expression containing the name is called a per-object expression, and the constraint being defined is called a per-object constraint. For the elaboration of a component_definition of a component_declaration, if the constraint of the subtype_indication is not a per-object constraint, then the subtype_indication is elaborated. On the other hand, if the constraint is a per-object constraint, then the elaboration consists of the evaluation of any included expression that is not part of a per-object expression.

Examples of record type declarations:
       type Date is
             Day   : Integer range 1 .. 31;
             Month : Month_Name;
             Year  : Integer range 0 .. 4000;
          end record;
       type Complex is
             Re : Real := 0.0;
             Im : Real := 0.0;
          end record;
Examples of record variables:
       Tomorrow, Yesterday : Date;
       A, B, C : Complex;
       -- both components of A, B, and C are implicitly initialized to zero


  1. Variant Parts and Discrete Choices

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe --
Copyright statement
Page last generated: 95-03-12