Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
 
Annotated Ada Reference Manual (Ada 2022)Legal Information
Contents   Index   References   Search   Previous   Next 

3.2.1 Type Declarations

1
A type_declaration declares a type and its first subtype. 

Syntax

2
type_declaration ::=  full_type_declaration
   | incomplete_type_declaration
   | private_type_declaration
   | private_extension_declaration
3/3
{AI05-0183-1} full_type_declaration ::= 
     type defining_identifier [known_discriminant_partis type_definition
        [aspect_specification];
   | task_type_declaration
   | protected_type_declaration
4/2
{AI95-00251-01} type_definition ::= 
     enumeration_type_definition | integer_type_definition
   | real_type_definition | array_type_definition
   | record_type_definition | access_type_definition
   | derived_type_definition | interface_type_definition

Legality Rules

5
A given type shall not have a subcomponent whose type is the given type itself. 

Static Semantics

6/5
{AI12-0449-1} The defining_identifier of a type_declaration denotes the first subtype of the type. The known_discriminant_part, if any, defines the discriminants of the type (see 3.7 3.7, “Discriminants). The remainder of the type_declaration defines the remaining characteristics of (the view of) the type.
7/2
{AI95-00230-01} A type defined by a type_declaration is a named type; such a type has one or more nameable subtypes. Certain other forms of declaration also include type definitions as part of the declaration for an object. The type defined by such a declaration is anonymous — it has no nameable subtypes. For explanatory purposes, this document sometimes refers to an anonymous type by a pseudo-name, written in italics, and uses such pseudo-names at places where the syntax normally requires an identifier. For a named type whose first subtype is T, this document sometimes refers to the type of T as simply “the type T”. 
7.a/2
Ramification: {AI95-00230-01} The only user-defined types that can be anonymous in the above sense are array, access, task, and protected types. An anonymous array, task, or protected type can be defined as part of an object_declaration. An anonymous access type can be defined as part of numerous other constructs.
8/2
{AI95-00230-01} {AI95-00326-01} A named type that is declared by a full_type_declaration, or an anonymous type that is defined by an access_definition or as part of declaring an object of the type, is called a full type. The declaration of a full type also declares the full view of the type. The type_definition, task_definition, protected_definition, or access_definition that defines a full type is called a full type definition. [Types declared by other forms of type_declaration are not separate types; they are partial or incomplete views of some full type.] 
8.a
To be honest: Class-wide, universal, and root numeric types are full types. 
8.b/2
Reason: {AI95-00230-01} We need to mention access_definition separately, as it may occur in renames, which do not declare objects.
9/5
{AI12-0449-1} The definition of a type implicitly declares certain predefined operators that operate on the type, according to what classes the type belongs, as specified in 4.5 4.5, “Operators and Expression Evaluation.
9.a
Discussion: We no longer talk about the implicit declaration of basic operations. These are treated like an if_statement — they don't need to be declared, but are still applicable to only certain classes of types.
10
The predefined types [(for example the types Boolean, Wide_Character, Integer, root_integer, and universal_integer)] are the types that are defined in [a predefined library package called] Standard[; this package also includes the [(implicit)] declarations of their predefined operators]. [The package Standard is described in A.1.] 
10.a
Ramification: We use the term “predefined” to refer to entities declared in the visible part of Standard, to implicitly declared operators of a type whose semantics are defined by the language, to Standard itself, and to the “predefined environment”. We do not use this term to refer to library packages other than Standard. For example Text_IO is a language-defined package, not a predefined package, and Text_IO.Put_Line is not a predefined operation. 

Dynamic Semantics

11
The elaboration of a full_type_declaration consists of the elaboration of the full type definition. Each elaboration of a full type definition creates a distinct type and its first subtype. 
11.a
Reason: The creation is associated with the type definition, rather than the type declaration, because there are types that are created by full type definitions that are not immediately contained within a type declaration (e.g. an array object declaration, a singleton task declaration, etc.). 
11.b
Ramification: Any implicit declarations that occur immediately following the full type definition are elaborated where they (implicitly) occur. 

Examples

12
Examples of type definitions: 
13
(White, Red, Yellow, Green, Blue, Brown, Black)
range 1 .. 72
array(1 .. 10) of Integer
14
Examples of type declarations: 
15
type Color  is (White, Red, Yellow, Green, Blue, Brown, Black);
type Column is range 1 .. 72;
type Table  is array(1 .. 10) of Integer;
16
NOTE   Each of the above examples declares a named type. The identifier given denotes the first subtype of the type. Other named subtypes of the type can be declared with subtype_declarations (see 3.2.2). Although names do not directly denote types, a phrase like “the type Column” is sometimes used in this document to refer to the type of Column, where Column denotes the first subtype of the type. For an example of the definition of an anonymous type, see the declaration of the array Color_Table in 3.3.1; its type is anonymous — it has no nameable subtypes. 

Wording Changes from Ada 83

16.a
The syntactic category full_type_declaration now includes task and protected type declarations.
16.b
We have generalized the concept of first-named subtype (now called simply “first subtype”) to cover all kinds of types, for uniformity of description elsewhere. RM83 defined first-named subtype in Section 13. We define first subtype here, because it is now a more fundamental concept. We renamed the term, because in Ada 95 some first subtypes have no name.
16.c/2
{AI95-00230-01} We no longer elaborate discriminant_parts, because there is nothing to do, and it was complex to say that you only wanted to elaborate it once for a private or incomplete type. This is also consistent with the fact that subprogram specifications are not elaborated (neither in Ada 83 nor in Ada 95). Note, however, that an access_definition appearing in a discriminant_part is elaborated at the full_type_declaration (for a nonlimited type) or when an object with such a discriminant is created (for a limited type). 

Wording Changes from Ada 95

16.d/2
{AI95-00230-01} Added wording so that anonymous access types are always full types, even if they appear in renames.
16.e/2
{AI95-00251-01} Added interface types (see 3.9.4) to the syntax.
16.f/2
{AI95-00326-01} Added a definition of full view, so that all types have a well-defined full view. 

Extensions to Ada 2005

16.g/3
{AI05-0183-1} An optional aspect_specification can be used in a full_type_declaration. This is described in 13.1.1

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