TOC PREV NEXT INDEX DOC LIST MASTER INDEX



Package Type_Definitions

Package Type_Definitions provides access to Ada type definitions, generic actual-parameter type definitions, constraints, and choices.

Type definitions are defined by the following Ada constructs:

Constraints are defined by the following Ada constructs:

Choices are defined by the following Ada constructs:

For more information, click on a topic:


Resources in Package Type_Definitions

The subprograms in package Type_Definitions fall into several functional groups, as shown below.

To see detailed referenced information, click on the name of a subprogram:
Definition kinds and declarations:

Kind Type_Definition_Declaration

Processing the type, subtype, and derived-type hierarchy:
Base_Type Ground_Type Is_Predefined Last_Constraint Last_Subtype Parent_Subtype Parent_Type Type_Structure

Processing constraints:

Constraint_Kind Discrete_Range_Kind Discriminant_Associations Discriminant_Expression Discriminant_Simple_Names Lower_Bound Range_Attribute Upper_Bound

Processing discrete ranges:

Discrete_Range_Kind Lower_Bound Range_Attribute Upper_Bound Type_Mark


Processing choices:

Choice_Discrete_Range Choice_Kind Choice_Name Choice_Simple_Expression

Processing subtype indications and type marks:
Subtype_Definition_Subtype_Indication Subtype_Constraint Type_Mark
Processing enumeration-type definitions:
Enumeration_Literal_Declarations Enumeration_Literal_Names
Processing integer-type definitions:
Integer_Constraint

Processing real-type definitions:
Fixed_Accuracy_Definition Fixed_Point_Range_Constraint Floating_Accuracy_Definition Floating_Point_Range_Constraint Real_Type_Constraint
Processing array-type definitions:
Component_Subtype_Indication Discrete_Ranges Index_Constraint Index_Subtype_Definitions Is_Constrained_Array


Processing record-type definitions:
Component_Kind Corresponding_Discriminant_Simple_Name Discriminants Implicit_Components Implicit_Variant_Components Is_Discriminated Record_Components Variants Variant_Choices Variant_Components
Processing access-type definitions:
Access_To

Processing task-type definitions:
Task_Type_Declarative_Items


Key Concepts for Package Type_Definitions

Package Type_Definitions provides access to Ada type definitions, generic actual-parameter type definitions, constraints, and choices. Processing is divided into the following categories. To see more information, click on a topic:

Obtaining Definition Kinds and Declarations

Package Type_Definitions allows you to obtain information about all Ada type definitions including all associated constraints and variants.The enumeration Type_Definition_Kinds describes all type definitions. You can obtain the kind of type definition represented by an element with the Kind function.

The Type_Definition_Declaration function returns the type declaration or object definition associated with a type definition. The type declaration is the enclosing element of a type definition; you could also use the Elements.Enclosing_Element function to obtain the declaration.

Processing the Type, Subtype, and Derived-Type Hierarchy

Ada type declarations form a hierarchy. The hierarchy begins with a predefined type, an anonymous type, an array type, a record type, or an enumeration type and proceeds through, possibly multiple levels of, subtype and derived-type
declarations.

ASIS provides facilities to identify each level of the hierarchy and the components used at each level.

This section includes discussions of the following. To see more details, click on a topic:

Predefined Types

Predefined types are those types declared in package Standard (Ada83 LRM 8.6, Ada95 LRM A.1and Annex C). Package Standard must include all Ada predefined types but it can also include other types defined by the compiler vendor. The Ada predefined types are:

Additionally, when package Standard is examined by an ASIS application, it will always include the following three explicit type definitions not available to Ada programs:

These universal declarations are not Declarations.Is_Part-_Of_Implicit.

You can call the Is_Predefined function to determine whether a type definition represents a predefined type (and is defined in package Standard).

Terminology for the Type Hierarchy

To discuss type definitions, the LRM defines the terms base type, parent type, and parent subtype. To this list ASIS adds the term ground type. The relationship between these terms and type definitions is described in the following table:
Term
Definition
Base type
A subtype is a type with an optional constraint; a value is said to belong to a subtype of a given type if it belongs to the type and satisfies the constraint; the given type is called the base type of the subtype (Ada83 LRM 3.3(4), Ada95 LRM 3.2). The base type is often the same as the type mark from the subtype indication of a subtype declaration or a derived-type definition.
Parent subtype
The subtype indication that occurs after the reserved word new in a derived-type definition defines the parent subtype (Ada83 LRM 3.4(3), Ada95 LRM 3.4.
Parent type
A derived-type definition defines a new (base) type whose characteristics are derived from those of a parent type (Ada83 LRM 3.4(1), Ada95 LRM 3.4). The parent type is the base type of the parent subtype.
Ground type
The predefined type that forms the base of a declaration hierarchy is the ground type. The predefined type either exists in package Standard or is an enumeration, record, or array.

Examples of Type Definitions

The following examples illustrate the relationships between the various types:

A derived-type definition defines a new base type whose characteristics are derived from those of a parent subtype. The related type values for Number are:
Base Type
Parent Type
Parent Subtype
Ground Type
Number
Integer
Integer range 0 .. 10
Integer

A subtype indication defines a subtype of the base type as defined by the type mark. The related type values for Day_Number are:
Base Type
Parent Type
Parent Subtype
Ground Type
Number
N/A
N/A
Integer

Examples of Type Definitions (continued)

The subtype indication after the reserved word new defines the parent subtype. The parent type is the base type of the parent subtype. The related type values for Week_Day are:
Base Type
Parent Type
Parent Subtype
Ground Type
Week_Day
Number
Day_Number range 1 .. 7
Integer

Hierarchy Traversal Functions

ASIS provides the following functions related to the described types:
Information Desired
Call to Use
Base type
Base_Type
Parent type
Parent_Type
Parent subtype
Parent_Subtype
Ground type
Ground_Type

Subtype Indications

Subtype indications are partially defined by the following syntax:

Ada83 LRM 3.2.2, Ada95 LRM 3.3.2  

subtype_indication ::= type_mark [constraint]

Subtype indications appear in the following constructs:

You can call the Last_Subtype function to return the type or subtype definition of the type mark. The element returned can be a subtype declaration or a type declaration.

You can call the Last_Constraint function to return the last type or subtype definition of the type mark that imposed a constraint. This function differs from the Last_Subtype function in that multiple definitions may be unwound until one is found that includes a constraint or until the base type is encountered.

Types and Representation Clauses

In the case of enumeration and record definitions, a representation clause (Ada83 LRM 13.3, and 13.4, Ada95 LRM 13.4 and 13.5.1) can be specified. ASIS provides the Type_Structure function to unwind recursive derivations and subtype definitions until a derived-type definition with a representation or a type that has not been derived is reached.

The operation of the Type_Structure function differs from the Ground_Type function only for enumeration types, record types, and array types.

Processing Constraints

Subtype constraints are partially defined by the following syntax:

Ada83 LRM 3.3.2, Ada95 LRM 3.2.2

 constraint ::=
   range_constraint
  | floating_point_constraint
  | fixed_point_constraint
  | index_constraint
  | discriminant_constraint

You can use the Constraint_Kind function to determine the kind of constraint represented by an element.

Constraint processing is described in the following sections. For more information, click on a topic:

Processing Index and Range Constraints

Range constraints are partially defined by the following syntax:

Ada83 LRM 3.5, Ada95 LRM 3.5

 range_constraint ::= range range

 range ::= range_attribute
  | simple_expressions .. simple_expression

Range constraints appear in the following definitions:

Ada83 LRM 3.5.7, Ada95 LRM 3.5.7

 floating_point_constraint ::=
  floating_accuracy_definition
    [range_constraint]

Ada83 LRM 3.5.9, Ada95 LRM 3.5.9

 fixed_point_constraint ::=
  fixed_accuracy_definition
    [range_constraint]

Index constraints are defined by the following syntax:

Ada83 LRM 3.6, Ada95 LRM 3.6

 index_constraint ::=
  (discrete_range {, discrete_range})

The components and related information can be obtained by calling the subprograms in the following table
Information Desired
Call to Use
range_attribute1
Range_Attribute
simple_expression (lower bound)
Lower_Bound
simple_expression (upper bound)
Upper_Bound
The kind of range (or discrete-_range) represented
Discrete_Range_Kind
1 The element kind returned is An_Expression with an expression kinds of An_Attribute; the attribute is always 'Range.

:

Processing Discriminant Constraints

Discriminant constraints are defined by the following syntax:

Ada83 LRM 3.7.2, Ada95 LRM 3.7.1

 discriminant_constraint ::=
  (discriminant_association
   {, discriminant_association})

 discriminant_association ::=
  [discriminant_simple_name
   {| discriminant_simple_name} =>]
     expression

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
discriminant-_constraints
Discriminant_Associations
discriminant_simple-_name
Discriminant_Simple_Names
expression
Discriminant_Expression

Processing Discrete Ranges

Discrete ranges are defined by the following syntax:

Ada83 LRM 3.6, Ada95 LRM 3.6
 discrete_range ::=
  discrete_subtype_indication | range

Discrete ranges appear in the following syntactic items:

Ada83 LRM 3.6, Ada95 LRM 3.6
 index_constraint ::=
  (discrete_range {, discrete_range})

Ada83 LRM 3.7.3, Ada95 LRM 3.8.1
 choice ::= simple_expression
  | discrete_range
  | others
  | component_simple_name

Ada83 LRM 4.1.2, Ada95 LRM 4.1.2 
slice ::= prefix(discrete_range)

Ada83 LRM 5.5, Ada95 LRM 5.5 
loop_parameter_specification ::=
  identifier in [reverse] discrete_range

Ada83 LRM 9.5, Ada95 LRM 9.5
 entry_declaration ::=
  entry identifier [(discrete_range)]
   [formal_part];

The static range of a record representation clause is also treated as a discrete range by ASIS:

Ada83 LRM 13.4, Ada95 LRM 13.5.1 
component_clause ::=
  component_name at static_simple_expression
   range static_range;

Processing Discrete Ranges (continued)

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
discrete_subtype-
_indication

Type_Mark
range
See "Processing Index and Range Constraints"

Processing Choices

Choices are partially defined by the following syntax:

Ada83 LRM 3.7.3, Ada95 LRM 3.8.1
 choice ::= simple_expression
  | discrete_range
  | others
  | component_simple_name

Ada83 LRM 11.2, Ada95 LRM 11.2
exception_choice ::= exception_name | others

Choices appear in:

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
simple_expression
Choice_Simple_Expression
discrete_range
Choice_Discrete_Range
component_simple_name
Choice_Name
exception_simple_name
Choice_Name
The kind of choice represented
Choice_Kind

Processing Subtype Declarations and Type Marks

Subtype declarations are defined by the following syntax:

Ada83 LRM 3.3.2, Ada95 LRM 3.2.2
 subtype_declaration ::=
  subtype identifier is subtype_indication;

 subtype_indication ::= type_mark [constraint]

 type_mark ::= type_name | subtype_name

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
identifier
Declarations.Names
subtype_indication
Subtype_Definition_Subtype-_Indication
type_mark
Type_Mark
constraint
Subtype_Constraint

Processing Type Declarations

Type declarations are defined by the following syntax:

Ada83 LRM 3.3.1, Ada95 LRM 3.2.1
 type_declaration ::= full_type_declaration
  | incomplete_type_declaration
  | private_type_declaration

The processing of full-type declarations is described below. The processing of incomplete- and private-type declarations is described in package Declarations, "Processing Incomplete- and Private-Type Declarations".

Full-type declarations are partially defined by the following syntax:

Ada83 LRM 3.3.1, Ada95 LRM 3.2.1
 full_type_declaration ::=
  type identifier [discriminant_part] is
    type_definition;

The discriminant part of a full-type declaration is partially defined by the following syntax:

Ada83 LRM 3.7.1, Ada95 LRM 3.7
 discriminant_part ::=
  (discriminant_specification
   {; discriminant_specification})

 discriminant_specification ::=
  identifier_list : type_mark [:= expression]

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
identifier
Declarations.Names
discriminant_part
Discriminants
type_definition
Declarations.Type_Declaration-_Definition
identifier_list
Declarations.Names
type_mark
Type_Mark
expression
Declarations.Initial_Value
Whether the type declaration contains a discriminant-_part
Is_Discriminated
Whether a discriminant-_specification contains an expression
Declarations.Is_Initialized

Processing Type Definitions

Type definitions are partially defined by the following syntax:

Ada83 LRM 3.3.1, Ada95 LRM 3.2.1 
type_definition ::=
   enumeration_type_definition
  | integer_type_definition
  | real_type_definition
  | array_type_definition
  | record_type_definition
  | access_type_definition
  | derived_type_definition

Each of the above type definitions is described in the following sections. For more information, click on a topic:

Processing Enumeration-Type Definitions

Enumeration-type definitions are defined by the following syntax:

Ada83 LRM 3.5.1, Ada95 LRM 3.5.1  enumeration_type_definition ::=
  (enumeration_literal_specification
   {, enumeration_literal_specification})

 enumeration_literal_specification ::=
  enumeration_literal

 enumeration_literal ::=
  identifier | character_literal

You can use the Enumeration_Literal_Names function to obtain a list of An_Entity_Name_Definitions. The elements in the list represent each value in the enumeration. Each element has an Expression_Kinds of An_Enumeration_Literal or A_Character-_Literal.

Processing Enumeration-Type Definitions (continued)

You can use the Enumeration_Literal_Declarations function to return a list of An_Enumeration_Literal_Specification elements. Each element corresponds to an enumeration-literal specification from the enumeration-type definition and is a function of the form:

Passing the An_Enumeration_Literal_Specification element to Declarations.Return_Type returns A_Simple_Name of the function.

Passing An_Enumeration_Literal_Specification element to the Declarations.Names function returns a single-entry name list. For each enumeration literal, the element represented by the name-list value is the same element returned by the Enumeration_Literal_Names function.

The Elements.Enclosing_Element of An_Enumeration_Literal-_Specification is the enumeration-type definition.

Processing Integer-Subtype Definitions

Integer-subtype definitions are defined by the following syntax:

Ada83 LRM 3.5.4, Ada95 LRM 3.5.4  
integer_type_definition ::= range_constraint

You can use the Integer_Constraint function to return the range constraint for an integer-type definition.

Processing Real-Subtype Definitions

Real-subtype definitions are defined by the following syntax:

Ada83 LRM 3.5.6, Ada95 LRM 3.5.6
 real_type_definition ::=
   floating_point_constraint
  | fixed_point_constraint

Ada83 LRM 3.5.7, Ada95 LRM 3.5.7
 floating_point_constraint ::=
  floating_accuracy_definition
    [range_constraint]

 floating_accuracy_definition ::=
  digits static_simple_expression

Ada83 LRM 3.5.9, Ada95 LRM 3.5.9
 fixed_point_constraint ::=
  fixed_accuracy_definition
    [range_constraint]

 fixed_accuracy_definition ::=
  delta static_simple_expression

Processing Real-Subtype Definitions (continued)

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
range_constraint
Real_Type_Constraint
static_simple_expres-sion (of a floating-
_accuracy_definition
)

Floating_Accuracy_Definition
static_simple_expres-sion (of a fixed-_accuracy_definition)
Fixed_Accuracy_Definition
range_constraint (of a floating_accuracy-_definition)
Floating_Point_Range-_Constraint
range_constraint (of a fixed_accuracy-
_definition
)

Fixed_Point_Range_Constraint

Processing Array-Type Definitions

Array-type definitions are partially defined by the following syntax:

Ada83 LRM 3.6, Ada95 LRM 3.6
 array_type_definition ::=
   unconstrained_array_definition
  | constrained_array_definition

 unconstrained_array_definition ::=
  array(index_subtype_definition
   {, index_subtype_definition}) of
     component_subtype_indication

 constrained_array_definition ::=
  array index_constraint of
   component_subtype_indication

 index_constraint ::=
  (discrete_range {, discrete_range})

Processing Array-Type Definitions (continued)

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
index_subtype_defini-tion list
Index_Subtype_Definitions
component_subtype-
_indication

Component_Subtype_Indication
index_constraint
Index_Constraint
discrete_range list
Discrete_Ranges
Whether an element represents a constrained_array-_definition or an unconstrained_array-_definition
Is_Constrained_Array

Processing Record-Type Definitions

Record-type definitions are defined by the following syntax:

Ada83 LRM 3.7, Ada95 LRM 3.7
 record_type_definition ::=
  record
   component_list
  end record

 component_list ::=
   component_declaration
    {component_declaration}
  | {component_declaration} variant_part
  | null;

 component_declaration ::= identifier_list :
  component_subtype_definition [:= expression];

 component_subtype_definition ::=
  subtype_indication

Record variant parts are partially defined by the following syntax:

Ada83 LRM 3.7.3, Ada95 LRM 3.8.1 
variant_part ::=
  case discriminant_simple_name is
   variant
   {variant}
  end case;

 variant ::=
  when choice {| choice} =>
   component_list

Processing Record-Type Definitions (continued)

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
component_list
Record_Components
identifier_list
Declarations.Names
component_subtype-_definition
Type_Mark
expression
Declarations.Initial_Value
variant list
Variants
choice list
Variant_Choices
component_list
Variant_Components
What kind of component is represented
Component_Kind
Whether a component-_declaration contains an expression
Declarations.Is_Initialized

Ada allows implementation-dependent components to be placed in the component list within the record or variant parts of the record. These implementation-dependent components are not returned by the Record_Components or Variant_Components function; you can obtain them with the Implicit_Components and Implicit_Variant_Components functions.

Processing Access-Type Definitions

Access-type definitions are defined by the following syntax:

Ada83 LRM 3.8, Ada95 LRM 3.10
 access_type_definition ::=
  access subtype_indication

You can use the Access_To function to obtain the subtype indication for an access-type definition.

Processing Derived-Type Definitions

Derived-type definitions are defined by the following syntax:

Ada83 LRM 3.4, Ada95 LRM 3.4
 derived_type_definition ::=
  new subtype_indication

You can use the Parent_Subtype function to obtain the subtype indication for a derived-type definition.

When a type is derived, operations and possibly subtypes of the type are also derived. To obtain the derived operations see package Declarations, "Processing Implicit and Derived Operations." To see how the derived subtypes are represented, see "Considerations for Derived-Subtype Definitions."

Considerations for Derived-Subtype Definitions

When a derived type is declared, Ada implicitly declares certain operations for that type. These include:

See package Declarations, "Processing Implicit and Derived Operations," for how to obtain the declarations of these implicitly declared operations.

When one of these implicit operations is declared, Ada replaces the parent type in the specification of the subprogram with the derived type. Any subtype of the parent type is likewise replaced by a subtype of the derived type with a similar constraint (as for the transformation of a constraint of the parent subtype into the corresponding constraint of the derived subtype). Any expression of the parent type is made to be the operand of a type conversion that yields a result of the derived type (Ada83 LRM 3.4(13), Ada95 LRM 3.4).

For more details, see "ASIS's Representation of Derived Subtypes."

ASIS's Representation of Derived Subtypes

These implicitly generated derived subtypes are implicitly represented by ASIS. They are given the name of the derived type, followed by a forward slash (/), and then by the name of the derivable subtype. For example, the name D/C represents a subtype created when the derived type D was declared and its base type contained the derivable subtype C.

Similar substitutions are made in any constraints applied to the derivable subtype.

If a constraint does not appear on a derivable subtype declaration, a derived subtype is not created. ASIS instead converts references to the derived subtype to references to the derived type.

For more information, click on a topic:

Derived Subtype Definition Example

Package One declares C as a derived subtype of A as follows:

In package Two, a new type D is explicity derived from One.A as follows:

In package Two, the implicit subtype declaration for C has the form:

Note that the 'Range attribute expression has been replaced by a dotted range. An equivalent declaration of C using A'First .. A'Last instead of A'Range produces the same derived subtype declaration.

Properties of Implicit Subtype Declarations

Implicit subtype declarations, except for unconstrained-record types, have the following properties:

Additional considerations apply to other types as described in:

Floating-Point Type Considerations

A floating-point type definition always contains a digits accuracy definition within its constraint. The derived subtype uses the same digits value.

In package Two, the implicit subtype declaration has the form:

Fixed-Point Type Considerations

A fixed-point type definition always contains a delta accuracy definition within its constraint. The derived subtype uses the same delta value.

In package Two, the implicit subtype declaration has the form:

Unconstrained-Array Type Considerations

The type replacements performed on derived subtypes of unconstrained arrays take place on the index subtype definitions. For example:

In package Two, the implicit subtype declaration for C has the form:

Unconstrained Record-Type Considerations

Subtypes of unconstrained record-types can also be derived and special considerations are required for the discriminant associations and their expressions. For example:

In package Two, the implicit subtype declaration for C has the form:

The Elements.Enclosing_Element is the A_Type_Definition element of the derived type that caused the subprogram derivation to occur.

The Elements.Enclosing_Element of each discriminant specification and expression is always the original A_Discriminant_Constraint from the derivable subtype.

The discriminant specifications and the expressions present in the derived subtype are shared with those in the derivable subtype. These shared elements are not Declarations.Is_Part_Of_Implicit; all other elements are Is_Part_Of_Implicit.

Processing Task-Type Specifications

Task-type declarations are defined by the following syntax:

Ada83 LRM 9.1, Ada95 LRM 9.1
 task_specification ::=
  task [type] identifier [is
   {entry_declaration}
   {representation_clause}
  end [task_simple_name}]

The components can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
identifier
Declarations.Names
entry_declaration and representation_clause list
Task_Type_Declarative_Items


Rational Software Corporation  http://www.rational.com
support@rational.com
techpubs@rational.com
Copyright © 1993-2001, Rational Software Corporation. All rights reserved.
TOC PREV NEXT INDEX DOC LIST MASTER INDEX TECHNOTES APEX TIPS