![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Package Declarations Package Declarations provides access to Ada declarations and specifications. Declarations and specifications are defined by the following Ada constructs:
- Object and number declarations (Ada83 LRM 3.2, Ada95 LRM 3.3)
- Full-type, subtype, incomplete-type, and private-type declarations (Ada83 LRM 3.3.1
, 3.3.2, 3.7.1,
3.8.1, and 7.4, Ada95 LRM 3.2.1, 3.2.2, 3.7, 3.10.1, and 7.3)- Component declarations (Ada83 LRM 3.7, Ada95 LRM 3.8)
- Enumeration-literal specifications (Ada83 LRM 3.5.1, Ada95 LRM 3.5.1)
- For-loop parameter specifications (Ada83 LRM 5.5, Ada95 LRM 5.5)
- Subprogram declarations, bodies, and parameters (Ada83 LRM 6.1, and 6.3, Ada95 LRM 6.1 and 6.3)
- Package specifications and package bodies (Ada83 LRM 7.1, and 7.3, Ada95 LRM 7.1 and 7.2)
- Deferred constant declarations (Ada83 LRM 7.4, Ada95 LRM 7.3)
- Renaming declarations (Ada83 LRM 8.5, Ada95 LRM 8.5)
- Task and task-type specifications and bodies (Ada83 LRM 9.1, Ada95 LRM 9.1)
- Task-entry declarations (Ada83 LRM 9.5, Ada95 LRM 9.5)
- Subunits of compilation units (Ada83 LRM 10.2, Ada95 LRM 10.1.3)
- Exception declarations (Ada83 LRM 11.1, Ada95 LRM 11.1)
- Generic and generic-formal parameter declarations (Ada83 LRM 12.1, Ada95 LRM 12.1)
- Generic instantiations (Ada83 LRM 12.3, Ada95 LRM 12.3)
The package also provides subprograms to traverse the program structure between:
- Types and implicit or derived operators for those types
- Program-unit declarations (subprograms, packages, tasks, and generics) and their associated bodies
- Generic instantiations and their associated generic instances
For more information, click on a topic:
Resources in Package DeclarationsThe subprograms in package Declarations fall into several functional groups, as shown below.
To see detailed referenced information, click on the name of a subprogram:
Determining declaration kinds and names:
Kind Names
Determining declaration origin:
Origin
Processing object and number declarations:
Corresponding_Constant_Declaration Initial_Value Is_Constant Is_Initialized Is_Variable Object_Declaration_Definition Type_Mark
Processing incomplete- and private-type declarations:
Corresponding_Type_Declaration Discriminants Is_Discriminated Is_Limited Is_Private Is_Type_Declaration Type_Declaration_Definition Type_Mark
Processing enumeration literals:
Is_Character_Literal
Processing implicit and derived operations:
Corresponding_Equality_Operator Corresponding_Type Implicit_Attribute_Functions Implicit_Derived_Subprograms Implicit_Predefined_Operators Is_Part_Of_Derived Is_Part_Of_Implicit Subprogram_Derivation Type_Operators
Processing program units:
Corresponding_Body Corresponding_Specification Is_Function Is_Package Is_Procedure Is_Specification Is_Subprogram Is_Task
Processing subprograms:
Is_Operator_Definition Parameters Parameter_Mode_Kind Return_Type Subprogram_Body_Block Type_Mark
Processing package specifications and body blocks:
Package_Body_Block Private_Part_Declarative_Items Visible_Part_Declarative_Items
Processing renaming declarations:
Is_Renaming_Declaration Renamed_Base_Entity Renamed_Entity Type_Mark
Processing task declarations:
Task_Body_Block Task_Declaration_Declarative_Items
Processing task-entry declarations:
Entry_Declarations Family_Index
Processing subunits:
Body_Stub Is_Body_Stub Is_Subunit Subunit
Processing generic package and subprogram specifications:
Corresponding_Generic_Element Enclosing_Generic Generic_Formal_Parameters Generic_Formal_Subprogram_Default Generic_Formal_Subprogram_Default_Kind Is_Generic Is_Generic_Formal Is_Part_Of_Instance Type_Mark
Processing generic instantiations:
Generic_Unit_Name Generic_Parameters Is_Generic_Instantiation
Key Concepts for Package DeclarationsPackage Declarations provides access to Ada declarations and specifications. Processing is divided into the following categories. To see more information, click on a topic:
- "Determining Declaration Kinds and Names"
- "Determining Declaration Origin"
- "Processing Object and Number Declarations"
- "Processing Incomplete- and Private-Type Declarations"
- "Processing Enumeration Literals"
- "Processing Implicit and Derived Operations"
- "Processing Program Units"
- "Processing Subprograms"
- "Processing Package Specifications and Body Blocks"
- "Processing Renaming Declarations"
- "Processing Task Declarations"
- "Processing Task-Entry Declarations"
- "Processing Exception Declarations"
- "Processing Body Stubs and Subunits"
- "Processing Generic Package and Subprogram Specifications"
- "Processing Generic Instantiations"
Determining Declaration Kinds and Names
Package Declarations allows you to obtain information about all declarations and specifications that declare named entities. The Declaration_Kinds enumeration describes all declarations and specifications. You can obtain the kind of declaration represented by an element with the Kind function.
Each kind of declaration defines one or more names. The names are returned in a name list, which is an array of references. You can obtain the name list with the Names function.
The following Ada constructs return a name list with a single entry:
- Full-type, subtype, incomplete-type, and private-type declarations, (Ada83 LRM 3.3.1
, 3.3.2, 3.8.1, and 7.4, Ada95 LRM 3.2.1, 3.2.2, 3.10.1, and 7.3)- Enumeration-literal specifications (Ada83 LRM 3.5.1, Ada95 LRM 3.5.1)
- For-loop parameter specifications (Ada83 LRM 5.5, Ada95 LRM 5.5)
- Subprogram declarations and bodies (Ada83 LRM 6.1, and 6.3, Ada95 LRM 6.1 and 6.3)
- Package specifications and package bodies (Ada83 LRM 7.1, and 7.3, Ada95 LRM 7.1 and 7.2)
- Renaming declarations (Ada83 LRM 8.5, Ada95 LRM 8.5)
- Task and task-type specifications and bodies (Ada83 LRM 9.1, Ada95 LRM 9.1)
- Task-entry declarations (Ada83 LRM 9.5, Ada95 LRM 9.5)
- Subunits of compilation units (Ada83 LRM 10.2, Ada95 LRM 10.1.3)
- Generic declarations (Ada83 LRM 12.1, Ada95 LRM 12.1)
- Generic instantiations (Ada83 LRM 12.3, Ada95 LRM 12.3)
The following Ada constructs can return a name list with multiple entries:
- Object and number declarations (Ada83 LRM 3.2, Ada95 LRM 3.3)
- Component declarations (Ada83 LRM 3.7, Ada95 LRM 3.8)
- Discriminant specifications (Ada83 LRM 3.7.1, Ada95 LRM 3.7)
- Subprogram parameter specifications (Ada83 LRM 6.1, Ada95 LRM 6.1)
- Deferred-constant declarations (Ada83 LRM 7.4, Ada95 LRM 7.3)
- Exception declarations (Ada83 LRM 11.1, Ada95 LRM 11.1)
- Generic-formal object declarations (Ada83 LRM 12.1, Ada95 LRM 12.1)
Determining Declaration Origin
The origin of a declaration can be either explicit or implicit. Explicit declarations are those that appear in the source code. Implicit declarations are those created by Ada when a type or derived type is declared. You can use the Origin function to determine whether the origin of a declaration is explicit or implicit and, if implicit, the method by which it was created.
Processing Object and Number Declarations
Object and number declarations are defined by the following syntax:
object_declaration ::=
identifier_list :
[constant] subtype_indication
[:= expression];
| identifier_list :
[constant] constrained_array_definition
[:= expression];number_declaration ::=
identifier_list : constant :=
universal_static_expression;identifier_list ::= identifier {, identifier}
Ada constant definitions can be deferred. In this case, ASIS can provide information on the basic declaration or the full declaration. Deferred constants are defined by the following syntax:
deferred_constant_declaration ::=
identifier_list : constant type_mark;The components and related information can be obtained by calling the subprograms in the following table
:
Processing Incomplete- and Private-Type
DeclarationsType declaration processing in ASIS is divided between packages Declarations and Type_Definitions. Package Declarations provides subprograms that:
- Determine whether an element represents a type
- Determine whether the type is private or limited private
- Determine whether the type has discriminants
- Obtain the discriminants
- Obtain the definition of a type given the private- or incomplete-type definition
The subprograms in package Type_Definitions allow you to obtain the components of a type definition.
Type declarations are partially 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
full_type_declaration ::=
type identifier [discriminant_part] is
type_definition;Ada83 LRM 3.3.2, Ada95 LRM 3.2.2
subtype_declaration ::=
subtype identifier is subtype_indication;subtype_indication ::= type_mark [constraint]
Ada83 LRM 3.8.1, Ada95 LRM 3.10.1
incomplete_type_declaration ::=
type identifier [discriminant_part];Ada83 LRM 3.7.1, Ada95 LRM 3.7
discriminant_part ::=
(discriminant_specification
{; discriminant_specification})discriminant_specification ::=
identifier_list : type_mark [:= expression]private_type_declaration ::=
type identifier [discriminant_part] is
[limited] private;The components and related information can be obtained by calling the subprograms in the following table.
Processing Enumeration Literals
Enumeration-literal specifications are defined by the following syntax:
Ada83 LRM 3.5.1, Ada95 LRM 3.5.1
enumeration_literal ::=
identifier | character_literalThe components and related information can be obtained by calling the subprograms in the following table:
Information Desired Call to Use
enumeration_literal-
_specification listType_Definitions.Enumeration-
_Literal_Declarations
Whether an enumeration-
_literal is a character-
_literalIs_Character_Literal
Package Type_Definitions contains more subprograms related to enumeration-declaration analysis. See package Type_Definitions, "Processing Enumeration-Type Definitions," for more information.
Processing Implicit and Derived Operations
This section covers the following subjects. For more information, click on a topic:
- "Implicit and Derived Operations"
- "Obtaining Implicit Operations"
- "Obtaining Implicit Attribute Functions"
- "Obtaining Derived Subprograms"
- "Equality Operators"
- "Obtaining a Type Declaration"
Implicit and Derived Operations
When a type is declared, a set of operations for the type is implicitly declared. These implicitly declared operations depend on the class of the type declared. These operations include the basic operations (Ada83 LRM 3.5.5, 3.5.10, 3.6.2, 3.7.4, and 3.8.2, Ada95 LRM 3.5.5, 3.5.10, 3.6.2, 3.8, and 3.10.2), attribute functions (Ada83 LRM 4.1.4, Ada95 LRM 4.1.4), predefined operators (Ada83 LRM 4.5, Ada95 LRM 4.5), and enumeration literals (Ada83 LRM 3.5.1, Ada95 LRM 3.5.1).
Elements that reference the declaration of any of these operations test as Expressions.Is_Implicit. Elements of any portion of these declarations test as Is_Part_Of_Implicit.
The set of operations defined for a type also includes any explicitly defined subprograms that have a parameter or result of the type (Ada83 LRM 3.3.3, Ada95 LRM 3.2.3).
When a derived type is declared, it receives its normal set of implicit operations plus a full set of implicit derived subprograms. There is one derived subprogram for each of the implicit
subprograms.Elements that reference the derived declarations of any of these operations test as Expressions.Is_Derived. Elements of any portion of these declarations test as Is_Part_Of_Derived and Is_Part_Of_Implicit.
Obtaining Implicit Operations
You can use the Implicit_Predefined_Operators function to obtain the list of basic operators defined for a type. The list can include the following operators:
and or xor = /=1
< <= > >= + (unary)
– (unary) & + (binary) – (binary) *
/ mod rem ** abs
not
1 This operator might not be returned depending on how the ASIS implementations deals with the inequality operator. See "Equality Operators" for more information.
Obtaining Implicit Attribute Functions
You can use the Implicit_Attribute_Functions function to obtain the list of attribute functions defined for a type. The list can include the following predefined attributes:
- 'Image
- 'Pos
- 'Pred
- 'Succ
- 'Val
- 'Value
A vendor can provide implementation-defined attributes. Vendors are encouraged to return declarations for these functions. Rational Apex does not contain any implementation-defined attributes.
Obtaining Derived Subprograms
You can use the Implicit_Derived_Subprograms function to obtain the list of all implicitly declared subprograms for a derived type. The list includes all visible implicitly declared subprograms as well as all explicitly declared subprograms that have a parameter or result of the subtype.
You can use the Subprogram_Derivation function to obtain the subprogram declaration from which a derived subprogram was derived. The result of the function can be an implicit derived subprogram or an explicit subprogram.
Equality Operators
You can use the Type_Operators Function to obtain the list of all implicitly declared or programmer-overloaded operators defined for a type. Because of variations in Ada library content, ASIS implementations might not return the inequality operator (/=).
Consider the expression A /= B.
If the ASIS implementation returns the inequality operator:
- The inequality operator will appear in lists returned by the Type_Operators and Implicit_Predefined_Operators functions.
- The element that represents the expression:
- Is an Expressions.Expression_Kinds of A_Function_Call
- Returns an element of A_Function_Declaration from Expressions.Called_Function
- Returns A_Not_Equal_Operator from Expressions.Operator_Kind (when provided with the Expressions.Prefix of the above element)
- References to the inequality subprogram declaration test as Expressions.Is_Implicit.
- The declaration of the inequality subprogram and all its elements test as Is_Part_Of_Implicit.
- The Elements.Enclosing_Element is the associated type
definition.- The Corresponding_Equality_Operator function can be used to obtain the equality operator given the inequality operator or the inequality operator given the equality operator.
If the ASIS implementation does not return the inequality operator:
- The inequality operator will not appear in lists returned by the Type_Operators and Implicit_Predefined_Operators functions.
- The expression becomes not (A = B).
- The elements that represent the not, the equality function call, and the call prefix are Is_Part_Of_Implicit.
- The elements have no text image (see package Text, "Processing Images").
Obtaining a Type Declaration
For a given a subprogram, operator, or attribute function, the Corresponding_Type function returns the type definition from which the entity was implicitly derived.
The returned element often represents a derived type. The function can be called repeatedly to obtain the base type
definition.Processing Program Units
Ada programs are composed of program units. Programs units consist of:
- Subprograms
- Packages
- Tasks
- Generic units
- Generic instantiations
Program units consist of a declaration (a specification) and possibly an implementation (a body), as shown below:
Program Unit Declaration Implementation
Subprogram subprogram_declaration subprogram_body
Package package_specification package_body
Task task_specification task_body
Generic unit generic_specification package_body
subprogram_body
Generic
instantiationgeneric_instantiation package_body1
package_specifica-
tion
subprogram_body
subprogram_speci-
fication
1 When a generic is instantiated, it creates an implicit specification and body instance.
Subprograms can be further categorized as being either procedures or functions.
See the Declaration_Kinds type for a complete list of the kinds of program-unit declarations.
The components and related information can be obtained by calling the subprograms in the following table:
Processing Subprograms
Subprogram specifications are defined by the following syntax:
subprogram_specification ::=
procedure identifier [formal_part]
| function designator [formal_part]
return type_markdesignator ::= identifier | operator_symbol
operator_symbol ::= literal_stringformal_part ::=
(parameter_specification
{; parameter_specification])parameter_specification ::=
identifier_list : mode type_mark
[:= expression];Every subprogram specification must have an associated subprogram body. Subprogram bodies are defined by the following syntax:
subprogram_body ::=
subprogram_specification is
[declarative_part]
begin
sequence_of_statements
[exception
exception_handler
{exception_handler}]
end [designator];The components and related information can be obtained by calling the subprograms in the following table:
The Subprogram_Body_Block function returns a block statement that is the structural equivalent of the package body. The block statement is not part of the code (and is not Is_Part_Of_Implicit); it is an ASIS abstraction that encapsulates the package body.
Processing Package Specifications and Body Blocks
Package specifications are defined by the following syntax:
package_specification ::=
package identifier is
{basic_declarative_item}
[private
{basic_declarative_item}]
end [package_simple_name]Package specifications can have a corresponding package body. The syntax for package bodies is described in package Statements, "Processing Block Statements."
The components of the package specification and any associated package body can be obtained by calling the subprograms in the following table
:
The Package_Body_Block function returns a block statement that is the structural equivalent of the package body. The block statement is not part of the code (and is not Is_Part_Of_Implicit); it is an ASIS abstraction that encapsulates the package body.
Processing Renaming Declarations
Renaming declarations are defined by the following syntax:
renaming_declaration ::=
identifier : type_mark renames
object_name;
| identifier : exception renames
exception_name;
| package identifier renames package_name;
| subprogram_specification renames
subprogram_or_entry_name;The components and related information can be obtained by calling the subprograms in the following table
:
Processing Task Declarations
Task specifications are defined by the following syntax:
task_specification ::=
task [type] identifier [is
{entry_declaration}
{representation_clause}
end [task_simple_name}]Each task specification must have a corresponding task body. The syntax for task bodies is described in package Statements, "Processing Block Statements."
The components and related information can be obtained by calling the subprograms in the following table:
The Task_Body_Block function returns a block statement that is the structural equivalent of the package body. The block statement is not part of the code (and is not Is_Part_Of_Implicit); it is an ASIS abstraction that encapsulates the package body.
Processing Task-Entry Declarations
Task-entry declarations are defined by the following syntax:
entry_declaration ::=
entry identifier [(discrete_range)]
[formal_part];Each entry declaration must have a corresponding accept statement in the task body. The syntax for accept statements is described in package Statements, "Processing Accept Statements."
The components and related information can be obtained by calling the subprograms in the following table:
Information Desired Call to Use
entry_declaration Entry_Declarations
identifier Names
discrete_range Family_Index
formal_part list Parameters
Processing Body Stubs and Subunits
Body stubs and subunits are defined by the following syntax:
Ada83 LRM 10.2, Ada95 LRM 10.1.3
body_stub ::=
subprogram_specification is separate;
| package body package_simple_name
is separate;
| task body task_simple_name is separate;subunit ::=
separate (parent_unit_name) proper bodyThe components and related information can be obtained by calling the subprograms in the following table:
1 Other methods are possible.
Processing Exception Declarations
Exception declarations are defined by the following syntax:
Ada83 LRM 11.1, Ada95 LRM 11.1
exception_declaration ::=
identifier_list : exception;You can obtain the identifier_list with the Names functions.
Processing Generic Package and Subprogram Specifications
Generic package and subprogram specifications are defined by the following syntax:
Ada83 LRM 12.1, Ada95 LRM 12.1
generic_specification ::=
generic_formal_part
subprogram_specification
| generic_formal_part package_specification
generic_formal_part ::= generic
{generic_parameter_declaration}generic_parameter_declaration ::=
identifier_list : [in [out]] type_mark
[:= expression];| type identifier is
generic_type_definition;
| private_type_declaration
| with subprogram_specification [is name];
| with subprogram_specification [is <>];generic_type_definition::=
(<>) | range <> | digits <> | delta <>
| array_type_definition
| access_type_definitionThe components and related information can be obtained by calling the subprograms in the following table:
Processing Generic Instantiations
Generic instantiations are defined by the following syntax:
Ada83 LRM 12.3, Ada95 LRM 12.3
generic_instantiation ::=
package identifier is
new generic_package_name
[generic_actual_part];
| procedure identifier is
new generic_procedure_name
[generic_actual_part];
| function designator is
new generic_function_name
[generic_actual_part];
| function designator is
new generic_function_name
[generic_actual_part];
generic_actual_part ::=
(generic_association {, generic_association})
generic_association ::=
[generic_formal_parameter =>]
generic_actual_parameter
generic_formal_parameter ::=
parameter_simple_name | operator_symbol
generic_actual_parameter ::= expression
| variable_name
| subprogram_name | entry_name | type_markThe components and related information can be obtained by calling the subprograms in the following table
:
Ada defines generics in terms of an explicit specification and body and an implicit instance of the expanded specification and body. There is no explicit textual representation of the instantiated generic, but ASIS analysis can be performed as if such an explicit representation existed.
To analyze the generic specification or body referenced by an instantiation, perform the following steps:
- 1. . Use Generic_Unit_Name to obtain the name of the generic declaration.
- 2. . Use Expressions.Name_Declaration to obtain the generic specification.
- 3. . Use Corresponding_Body to obtain the body of the generic declaration.
- 4. . Use the calls available in package Statements to analyze the body block.
To analyze the implicit instance of the generic specification or body created by an instantiation, perform the following steps:
Rational Software Corporation
http://www.rational.com support@rational.com techpubs@rational.com Copyright © 1993-2001, Rational Software Corporation. All rights reserved. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |