3.1 Declarations
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
The language defines several kinds of named entities that are declared by declarations. The entity's name is defined by the declaration, usually by a defining_identifier
, but sometimes by a defining_character_literal
or defining_operator_symbol
. There are also entities that are not directly declared; some of these are elements of other entities, or are allocated dynamically. Such entities can be denoted using indexed_component
, selected_component
, or dereference name
s (see 4.1).
There are several forms of declaration. A basic_declaration
is a form of declaration defined as follows.
Syntax
3/3basic_declaration
::=
type_declaration
| subtype_declaration
| object_declaration
| number_declaration
| subprogram_declaration
| abstract_subprogram_declaration
| null_procedure_declaration
| expression_function_declaration
| package_declaration
| renaming_declaration
| exception_declaration
| generic_declaration
| generic_instantiation
4defining_identifier
::=
identifier
Static Semantics
5A declaration is a language construct that associates a name with (a view of) an entity. A declaration may appear explicitly in the program text (an explicit declaration), or may be supposed to occur at a given place in the text as a consequence of the semantics of another construct (an implicit declaration).
Each of the following is defined to be a declaration: any basic_declaration
; an enumeration_literal_specification
; a discriminant_specification
; a component_declaration
; a defining_identifier
of an iterated_component_association
; a loop_parameter_specification
; a defining_identifier
of a chunk_specification
; an iterator_specification
; a defining_identifier
of an iterator_parameter_specification
; a parameter_specification
; a subprogram_body
; an extended_return_object_declaration
; an entry_declaration
; an entry_index_specification
; a choice_parameter_specification
; a generic_formal_parameter_declaration
.
basic_declaration
is expanded out) contains all syntactic categories that end in "_declaration" or "_specification", except for program unit _specifications. Moreover, it contains subprogram_body
. A subprogram_body
is a declaration, whether or not it completes a previous declaration. This is a bit strange, subprogram_body
is not part of the syntax of basic_declaration
or library_unit_declaration
. A renaming-as-body is considered a declaration. An accept_statement
is not considered a declaration. Completions are sometimes declarations, and sometimes not. All declarations contain a definition for a view of an entity. A view consists of an identification of the entity (the entity of the view), plus view-specific characteristics that affect the use of the entity through that view (such as mode of access to an object, formal parameter names and defaults for a subprogram, or visibility to components of a type). In most cases, a declaration also contains the definition for the entity itself (a renaming_declaration
is an example of a declaration that does not define a new entity, but instead defines a view of an existing entity (see 8.5)).
When it is clear from context, the term object is used in place of view of an object. Similarly, the terms type and subtype are used in place of view of a type and view of a subtype, respectively.
For each declaration, the language rules define a certain region of text called the scope of the declaration (see 8.2). Most declarations associate an identifier
with a declared entity. Within its scope, and only there, there are places where it is possible to use the identifier
to refer to the declaration, the view it defines, and the associated entity; these places are defined by the visibility rules (see 8.3). At such places the identifier
is said to be a name of the entity (the direct_name
or selector_name
); the name is said to denote the declaration, the view, and the associated entity (see 8.6). The declaration is said to declare the name, the view, and in most cases, the entity itself.
As an alternative to an identifier
, an enumeration literal can be declared with a character_literal
as its name (see 3.5.1), and a function can be declared with an operator_symbol
as its name (see 6.1).
The syntax rules use the terms defining_identifier
, defining_character_literal
, and defining_operator_symbol
for the defining occurrence of a name; these are collectively called defining names. The terms direct_name
and selector_name
are used for usage occurrences of identifier
s, character_literal
s, and operator_symbol
s. These are collectively called usage names.
identifier
, character_literal
, and operator_symbol
are used directly in contexts where the normal visibility rules do not apply (such as the identifier
that appears after the end of a task_body
). Analogous conventions apply to the use of designator
, which is the collective term for identifier
and operator_symbol
. Dynamic Semantics
13The process by which a construct achieves its run-time effect is called execution. This process is also called elaboration for declarations and evaluation for expressions. One of the terms execution, elaboration, or evaluation is defined by this Reference Manual for each construct that has a run-time effect.
subtype_indication
s are elaborated, and range
s are evaluated.statement
s, which are executable, but neither elaborable nor evaluable. We considered using the term "execution" only for nonelaborable, nonevaluable constructs, and defining the term "action" to mean what we have defined "execution" to mean. We rejected this idea because we thought three terms that mean the same thing was enough — four would be overkill. Thus, the term "action" is used only informally in the standard (except where it is defined as part of a larger term, such as "protected action"). name
prefix
; range
; entry_index_specification
; and possibly discrete_range
. The last one is curious — RM83 uses the term “evaluation of a discrete_range
”, but never defines it. One might presume that the evaluation of a discrete_range
consists of the evaluation of the range
or the subtype_indication
, depending on what it is. But subtype_indication
s are not evaluated; they are elaborated.declaration
(if they include a trailing semicolon) or entity_specification
(if not).Wording Changes from Ada 83
defining_identifier
is new. It is used for the defining occurrence of an identifier
. Usage occurrences use the direct_name
or selector_name
syntactic categories. Each occurrence of an identifier
(or simple_name
), character_literal
, or operator_symbol
in the Ada 83 syntax rules is handled as follows in Ada 95: - It becomes a
defining_identifier
,defining_character_literal
, ordefining_operator_symbol
(or some syntactic category composed of these), to indicate a defining occurrence; 16.f/3 - It becomes a
direct_name
, in usage occurrences where the usage is required (in Clause 8) to be directly visible; 16.g/3 - It becomes a
selector_name
, in usage occurrences where the usage is required (in Clause 8) to be visible but not necessarily directly visible; 16.h - It remains an
identifier
,character_literal
, oroperator_symbol
, in cases where the visibility rules do not apply (such as thedesignator
that appears after the end of asubprogram_body
).
package_body
uses defining_identifier
after the reserved word body, as opposed to direct_name
.selector_name
s.selector_name
, not just at places where a selector_name
was actually used. Thus, the places where a declaration is directly visible are a subset of the places where it is visible. See Clause 8 for details.)_specification
s that declare (views of) objects, such as parameter_specification
s. In Ada 83, these are referred to as a “form of declaration”, but it is not entirely clear that they are considered simply “declarations”.declarative_part
s, declarative_item
s and compilation_unit
s, but "elaboration" is defined elsewhere for various other constructs. To make matters worse, Ada 95 has a different set of elaborable constructs. Instead of correcting the list, it is more maintainable to refer to the term "elaborable," which is defined in a distributed manner.declarative_part
is doing the task creation.