Annotated Ada Reference Manual (Ada 202y Draft 1)Legal Information
Contents   Index   References   Search   Previous   Next 

3.2 Types and Subtypes

Static Semantics

1
A type is characterized by a set of values, and a set of primitive operations which implement the fundamental aspects of its semantics. An object of a given type is a run-time entity that contains (has) a value of the type. 
1.a/5
Term entry: type — defining characteristic of each object and expression of the language, with an associated set of values, and a set of primitive operations that implement the fundamental aspects of its semantics
Note: Types are grouped into categories. Most language-defined categories of types are also classes of types.
1.b/5
Term entry: subtype — type together with optional constraints, null exclusions, and predicates, which constrain the values of the type to the subset that satisfies the implied conditions
2/5
{AI95-00442-01} {AI12-0451-1} Types are grouped into categories of types. There exist several language-defined categories of types (summarized in the NOTE below), reflecting the similarity of their values and primitive operations. [Most categories of types form classes of types.] Elementary types are those whose values are logically indivisible; composite types are those whose values are composed of component values.
2.a/2
Proof: {AI95-00442-01} The formal definition of category and class is found in 3.4
2.b/5
Term entry: class of types — set of types that is closed under derivation, which means that if a given type is in the class, then all types derived from that type are also in the class
Note: The set of types of a class share common properties, such as their primitive operations.
2.c/5
Term entry: category of types — set of types with one or more common properties, such as primitive operations
Note: A category of types that is closed under derivation is also known as a class.
2.d/5
Term entry: elementary type — type that does not have components
2.e/5
Term entry: composite type — type with components, such as an array or record
2.f/5
Term entry: scalar type — either a discrete type or a real type
2.g/5
Term entry: access type — type that has values that designate aliased objects
Note: Access types correspond to “pointer types” or “reference types” in some other languages.
2.h/5
Term entry: discrete type — type that is either an integer type or an enumeration type
2.i/5
Term entry: real type — type that has values that are approximations of the real numbers
Note: Floating point and fixed point types are real types.
2.j/5
Term entry: integer type — type that represents signed or modular integers
Note: A signed integer type has a base range that includes both positive and negative numbers, and has operations that can raise an exception when the result is outside the base range. A modular type has a base range whose lower bound is zero, and has operations with “wraparound” semantics. Modular types subsume what are called “unsigned types” in some other languages.
2.k/5
Term entry: enumeration type — type defined by an enumeration of its values, which can be denoted by identifiers or character literals
2.l/5
Term entry: character type — enumeration type whose values include characters
2.m/5
Term entry: record type — composite type consisting of zero or more named components, possibly of different types
2.n/5
Term entry: record extension — type that extends another type optionally with additional components
2.o/5
Term entry: array type — composite type whose components are all of the same type
2.p/5
Term entry: task type — composite type used to represent active entities which execute concurrently and that can communicate via queued task entries
Note: The top-level task of a partition is called the environment task.
2.q/5
Term entry: protected type — composite type whose components are accessible only through one of its protected operations, which synchronize concurrent access by multiple tasks
2.r/5
Term entry: partial view — view of a type that reveals only some of its properties
Note: The remaining properties are defined by the full view given elsewhere.
2.s/5
Term entry: full view — view of a type that reveals all of its properties
Note: There can be other views of the type that reveal fewer properties.
2.t/5
Term entry: incomplete view — view of a type that reveals minimal properties
Note: The remaining properties are defined by the full view given elsewhere.
2.u/5
Term entry: private type — type that defines a partial view
Note: Private types can be used for defining abstractions that hide unnecessary details from their clients.
2.v/5
Term entry: private extension — type that extends another type, with the additional properties hidden from its clients
2.w/5
Term entry: full type — type that defines a full view
2.x/5
Term entry: incomplete type — type that defines an incomplete view
Note: Incomplete types can be used for defining recursive data structures.
3
The elementary types are the scalar types (discrete and real) and the access types (whose values provide access to objects or subprograms). Discrete types are either integer types or are defined by enumeration of their values (enumeration types). Real types are either floating point types or fixed point types.
4/2
{AI95-00251-01} {AI95-00326-01} The composite types are the record types, record extensions, array types, interface types, task types, and protected types. 
4.a/2
This paragraph was deleted.{AI95-00442-01}
4.1/2
 {AI95-00326-01} There can be multiple views of a type with varying sets of operations. [An incomplete type represents an incomplete view (see 3.10.1) of a type with a very restricted usage, providing support for recursive data structures. A private type or private extension represents a partial view (see 7.3) of a type, providing support for data abstraction. The full view (see 3.2.1) of a type represents its complete definition.] An incomplete or partial view is considered a composite type[, even if the full view is not].
4.b/3
Proof: {AI05-0299-1} The real definitions of the views are in the referenced subclauses. 
5/2
{AI95-00326-01} Certain composite types (and views thereof) have special components called discriminants whose values affect the presence, constraints, or initialization of other components. Discriminants can be thought of as parameters of the type.
6/2
{AI95-00366-01} The term subcomponent is used in this Reference Manual in place of the term component to indicate either a component, or a component of another subcomponent. Where other subcomponents are excluded, the term component is used instead. Similarly, a part of an object or value is used to mean the whole object or value, or any set of its subcomponents. The terms component, subcomponent, and part are also applied to a type meaning the component, subcomponent, or part of objects and values of the type.
6.a
Discussion: The definition of “part” here is designed to simplify rules elsewhere. By design, the intuitive meaning of “part” will convey the correct result to the casual reader, while this formalistic definition will answer the concern of the compiler-writer.
6.b
We use the term “part” when talking about the parent part, ancestor part, or extension part of a type extension. In contexts such as these, the part might represent an empty set of subcomponents (e.g. in a null record extension, or a nonnull extension of a null record). We also use “part” when specifying rules such as those that apply to an object with a “controlled part” meaning that it applies if the object as a whole is controlled, or any subcomponent is. 
7/2
{AI95-00231-01} The set of possible values for an object of a given type can be subjected to a condition that is called a constraint (the case of a null constraint that specifies no restriction is also included)[; the rules for which values satisfy a given kind of constraint are given in 3.5 for range_constraints, 3.6.1 for index_constraints, and 3.7.1 for discriminant_constraints]. The set of possible values for an object of an access type can also be subjected to a condition that excludes the null value (see 3.10).
7.a/5
Ramification: {AI12-0140-1} “Null constraint” includes the cases of no explicit constraint, as well as unknown discriminants and unconstrained array type declarations (which are explicit ways to declare no constraint). 
8/5
{AI95-00231-01} {AI95-00415-01} {AI12-0445-1} A subtype of a given type is a combination of the type, a constraint on values of the type, and certain attributes specific to the subtype. The given type is called the type of the subtype. Similarly, the associated constraint is called the constraint of the subtype. The set of values of a subtype consists of the values of its type that satisfy its constraint and any exclusion of the null value. Such values belong to the subtype. The other values of the type are outside the subtype.
8.a
Discussion: We make a strong distinction between a type and its subtypes. In particular, a type is not a subtype of itself. There is no constraint associated with a type (not even a null one), and type-related attributes are distinct from subtype-specific attributes. 
8.b
Discussion: We no longer use the term "base type." All types were "base types" anyway in Ada 83, so the term was redundant, and occasionally confusing. In the RM95 we say simply "the type of the subtype" instead of "the base type of the subtype." 
8.c
Ramification: The value subset for a subtype might be empty, and need not be a proper subset. 
8.d/2
To be honest: {AI95-00442-01} Any name of a category of types (such as “discrete”, “real”, or “limited”) is also used to qualify its subtypes, as well as its objects, values, declarations, and definitions, such as an “integer type declaration” or an “integer value”. In addition, if a term such as “parent subtype” or “index subtype” is defined, then the corresponding term for the type of the subtype is “parent type” or “index type”. 
8.e
Discussion: We use these corresponding terms without explicitly defining them, when the meaning is obvious.
9
A subtype is called an unconstrained subtype if its type has unknown discriminants, or if its type allows range, index, or discriminant constraints, but the subtype does not impose such a constraint; otherwise, the subtype is called a constrained subtype (since it has no unconstrained characteristics). 
9.a
Discussion: In an earlier version of Ada 9X, "constrained" meant "has a nonnull constraint." However, we changed to this definition since we kept having to special case composite non-array/nondiscriminated types. It also corresponds better to the (now obsolescent) attribute 'Constrained.
9.b
For scalar types, “constrained” means “has a nonnull constraint”. For composite types, in implementation terms, “constrained” means that the size of all objects of the subtype is the same, assuming a typical implementation model.
9.c
Class-wide subtypes are always unconstrained.
10/2
NOTE   {AI95-00442-01} Any set of types can be called a “category” of types, and any set of types that is closed under derivation (see 3.4) can be called a “class” of types. However, only certain categories and classes are used in the description of the rules of the language — generally those that have their own particular set of primitive operations (see 3.2.3), or that correspond to a set of types that are matched by a given kind of generic formal type (see 12.5). The following are examples of “interesting” language-defined classes: elementary, scalar, discrete, enumeration, character, boolean, integer, signed integer, modular, real, floating point, fixed point, ordinary fixed point, decimal fixed point, numeric, access, access-to-object, access-to-subprogram, composite, array, string, (untagged) record, tagged, task, protected, nonlimited. Special syntax is provided to define types in each of these classes. In addition to these classes, the following are examples of “interesting” language-defined categories: abstract, incomplete, interface, limited, private, record. 
10.a
Discussion: A value is a run-time entity with a given type which can be assigned to an object of an appropriate subtype of the type. An operation is a program entity that operates on zero or more operands to produce an effect, or yield a result, or both. 
10.b/2
Ramification: {AI95-00442-01} Note that a type's category (and class) depends on the place of the reference — a private type is composite outside and possibly elementary inside. It's really the view that is elementary or composite. Note that although private types are composite, there are some properties that depend on the corresponding full view — for example, parameter passing modes, and the constraint checks that apply in various places.
10.c/2
{AI95-00345-01} {AI95-00442-01} Every property of types forms a category, but not every property of types represents a class. For example, the set of all abstract types does not form a class, because this set is not closed under derivation. Similarly, the set of all interface types does not form a class.
10.d/2
{AI95-00442-01} The set of limited types does not form a class (since nonlimited types can inherit from limited interfaces), but the set of nonlimited types does. The set of tagged record types and the set of tagged private types do not form a class (because each of them can be extended to create a type of the other category); that implies that the set of record types and the set of private types also do not form a class (even though untagged record types and untagged private types do form a class). In all of these cases, we can talk about the category of the type; for instance, we can talk about the “category of limited types”.
10.e/2
{AI95-00442-01} Normatively, the language-defined classes are those that are defined to be inherited on derivation by 3.4; other properties either aren't interesting or form categories, not classes.
11/2
{AI95-00442-01} These language-defined categories are organized like this: 
12/2
{AI95-00345-01} all types
   elementary
      scalar
         discrete
            enumeration
               character
               boolean
               other enumeration
            integer
               signed integer
               modular integer
         real
            floating point
            fixed point
               ordinary fixed point
               decimal fixed point
      access
         access-to-object
         access-to-subprogram
   composite
      untagged
         array
            string
            other array
         record
         task
         protected
      tagged (including interfaces)
         nonlimited tagged record
         limited tagged
            limited tagged record
            synchronized tagged
               tagged task
               tagged protected
13/2
{AI95-00345-01} {AI95-00442-01} There are other categories, such as “numeric” and “discriminated”, which represent other categorization dimensions, but do not fit into the above strictly hierarchical picture. 
13.a.1/2
Discussion: {AI95-00345-01} {AI95-00442-01} Note that this is also true for some categories mentioned in the chart. The category “task” includes both untagged tasks and tagged tasks. Similarly for “protected”, “limited”, and “nonlimited” (note that limited and nonlimited are not shown for untagged composite types). 

Wording Changes from Ada 83

13.a/3
{AI05-0299-1} This subclause now precedes the subclauses on objects and named numbers, to cut down on the number of forward references.
13.b
We have dropped the term "base type" in favor of simply "type" (all types in Ada 83 were "base types" so it wasn't clear when it was appropriate/necessary to say "base type"). Given a subtype S of a type T, we call T the "type of the subtype S." 

Wording Changes from Ada 95

13.c/2
{AI95-00231-01} Added a mention of null exclusions when we're talking about constraints (these are not constraints, but they are similar).
13.d/2
{AI95-00251-01} Defined an interface type to be a composite type.
13.e/2
{AI95-00326-01} Revised the wording so that it is clear that an incomplete view is similar to a partial view in terms of the language.
13.f/2
{AI95-00366-01} Added a definition of component of a type, subcomponent of a type, and part of a type. These are commonly used in the standard, but they were not previously defined.
13.g/3
{AI95-00442-01} {AI05-0299-1} Reworded most of this subclause to use category rather than class, since so many interesting properties are not, strictly speaking, classes. Moreover, there was no normative description of exactly which properties formed classes, and which did not. The real definition of class, along with a list of properties, is now in 3.4

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