TOC PREV NEXT INDEX DOC LIST MASTER INDEX



Package Declarations

Package Declarations provides access to Ada declarations and specifications. Declarations and specifications are defined by the following Ada constructs:

The package also provides subprograms to traverse the program structure between:

For more information, click on a topic:


Resources in Package Declarations

The 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 Declarations

Package 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

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:

The following Ada constructs can return a name list with multiple entries:

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:

Ada83 LRM 3.2, Ada95 LRM 3.3  

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:

Ada83 LRM 7.4, Ada95 LRM 7.3 

deferred_constant_declaration ::=
  identifier_list : constant type_mark;

The components and related information can be obtained by calling the subprograms in the following table
Information Desired
Call to Use
identifier_list
Names
expression
Initial_Value
universal_static-
_expression

Initial_Value
subtype_indication
Object_Declaration_Definition
constrained_array-
_definition

Object_Declaration_Definition
type_mark
Type_Mark
Whether an object is a variable
Is_Variable
Whether an object is a constant
Is_Constant
Whether the object declaration includes an initial value
expression

Is_Initialized
The full declaration of a deferred constant
Corresponding_Constant-
_Declaration

The constant declaration of a deferred constant
Corresponding_Constant-
_Declaration

:

Processing Incomplete- and Private-Type
Declarations

Type declaration processing in ASIS is divided between packages Declarations and Type_Definitions. Package Declarations provides subprograms that:

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]

Ada83 LRM 7.4, Ada95 LRM 7.3

 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.
Information Desired
Call to Use
identifier
Names
discriminant_part list
Discriminants
identifier_list
Names
full_type_declaration
Type_Declaration_Definition
subtype_declaration
Type_Declaration_Definition
type_mark
Type_Mark
expression
Initial_Value
Whether an element is a type_declaration
Is_Type_Declaration
Whether a type_declaration is a private-type declaration
Is_Private
Whether a type_declaration is a limited private-type declaration
Is_Limited
Whether a discriminant-
_part exists on a type-
_declaration

Is_Discriminated
Whether a discriminant-
_specification includes a default expression

Is_Initialized
The corresponding type definition of a private or incomplete type
Corresponding_Type_Declaration

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_literal

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

Type_Definitions.Enumeration-
_Literal_Declarations

Whether an enumeration-
_literal is a character-
_literal

Is_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

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:

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:

If the ASIS implementation does not return the inequality operator:

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:

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
instantiation

generic_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:
Information Desired
Call to Use
Whether an element is a
specification

Is_Specification
Whether an element is a subprogram_declaration or subprogram_body
Is_Subprogram
Whether an element is a procedure subprogram_declaration or procedure subprogram_body
Is_Procedure
Whether an element is a function subprogram_declaration or procedure subprogram_body
Is_Function
Whether an element is a
package_specification or package_body

Is_Package
Whether an element is a task_specification or task_body
Is_Task
Whether an element is a
generic_specification or the subprogram_body or
package_body of a
generic_specification

Is_Generic

Information Desired
Call to Use
Whether an element is a generic_instantiation
Is_Generic_Instantiation
The body corresponding to a subprogram_declaration, package_specification, task_specification, or generic_instantiation
Corresponding_Body
The specification corresponding to a subprogram_body, package_body, task_body, or generic_body
Corresponding_Specification

Processing Subprograms

Subprogram specifications are defined by the following syntax:

Ada83 LRM 6.1, Ada95 LRM 6.1 

subprogram_specification ::=
   procedure identifier [formal_part]
  | function designator [formal_part]
    return type_mark

 designator ::= identifier | operator_symbol

 operator_symbol ::= literal_string

 formal_part ::=
  (parameter_specification
   {; parameter_specification])

 parameter_specification ::=
  identifier_list : mode type_mark
   [:= expression];

 mode ::= [in] | in out | out

Every subprogram specification must have an associated subprogram body. Subprogram bodies are defined by the following syntax:

Ada83 LRM 6.3, Ada95 LRM 6.3

 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:
Information Desired
Call to Use
subprogram_declaration
Compilation_Units.Unit-
_Declaration

identifier
designator

Names
formal_part list
Parameters
type_mark of the function subprogram_specification
Return_Type
identifier_list
Names
mode
Parameter_Mode_Kind
type_mark (of the formal-
_part)

Type_Mark
expression
Initial_Value
subprogram_body
Subprogram_Body_Block
declarative_part
Statements.Declarative_Items
sequence_of_statements
Statements.Block_Body-
_Statements

exception_handler list
Statements.Block_Exception-
_Handlers

Whether the designator represents an identifier or an
operator_symbol

Is_Operator_Definition
Whether a parameter-
_specification includes a default expression

Is_Initialized

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:

Ada83 LRM 7.1, Ada95 LRM 7.1 

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
Information Desired
Call to Use
package_specification
Compilation_Units.Unit-
_Declaration

identifier
package_simple_name

Names
basic_declarative_item (visible) list
Visible_Part_Declarative_Items
basic_declarative_item (private)list
Private_Part_Declarative_Items
package_body
Package_Body_Block
Whether an element represents a package_specification
Kind
Whether an element represents a package_body
Kind
:

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:

Ada83 LRM 8.5, Ada95 LRM 8.5 

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
Information Desired
Call to Use
object_name
exception_name
package_name
subprogram_or_entry_name

Renamed_Entity
identifier (type mark)
identifier (exception name)
identifier (package name)
subprogram_specification

Renamed_Base_Entity
type_mark
Type_Mark
Whether an element represents a renaming_declaration
Is_Renaming_Declaration
:

Processing Task Declarations

Task specifications 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}]

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:
Information Desired
Call to Use
task_specification
Compilation_Units.Unit-
_Declaration

identifier
task_simple_name

Names
entry_declaration and representation_clause list
Task_Declaration_Declarative-
_Items

task_body
Task_Body_Block

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:

Ada83 LRM 9.5, Ada95 LRM 9.5

 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 body

The components and related information can be obtained by calling the subprograms in the following table:
Information Desired
Call to Use
body_stub
Body_Stub
subprogram_specification
See "Processing Subprograms"
package_simple_name
task_simple_name

Names
subunit
Subunit
parent_unit_name
Compilation_Units.Enclosing_Compilation_Unitfollowed by Compilation_Units.Subunit-
_Parent
and then Compilation_Units.Name1
proper_body
Package_Body_Block Subprogram_Body_Block Task_Body_Block
Whether a declaration represents a body_stub
Is_Body_Stub
Whether a declaration represents a subunit
Is_Subunit
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_definition

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

Generic_Formal_Parameters
identifier_list
Names
mode (in, out, in out) of a generic_parameter_declaration identifier
Parameter_Mode_Kind
type_mark
Type_Mark
expression
Initial_Value
generic_type_definition
Type_Declaration_Definition
type_definition
Type_Declaration_Definition
name
Generic_Formal-
_Subprogram_Default

The default kind
(is name or is <>) of a
subprogram_specification

Generic_Formal-
_Subprogram_Default_Kind

Whether an element is a generic specification or generic body
Is_Generic
Whether an element is a generic_parameter_declaration
Is_Generic_Formal
The element that represents the generic specification given any element in the specification
Enclosing_Generic

Information Desired
Call to Use
The element that represents the generic body given any element in the body
Enclosing_Generic
Whether a generic_parameter_declaration identifier has a default value
Is_Initialized
Whether a generic_parameter_declaration is a type
declaration

Is_Type_Declaration
Whether a generic_parameter_declaration is a private type declaration
Is_Private
Whether the generic_parameter_declaration is a subprogram_specification
Is_Subprogram Is_Procedure Is_Function

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_mark

The components and related information can be obtained by calling the subprograms in the following table
Information Desired
Call to Use
identifier
designator

Names
generic_package_name
generic_procedure_name
generic_function_name

Generic_Unit_Name
generic_association list
Generic_Parameters
generic_formal_parameter
Statements.Formal_Parameter
parameter_simple_name
operator_symbol

Names
generic_actual_parameter
Statements.Actual_Parameter
Whether an element represents a generic instantiation
Is_Generic_Instantiation
The expanded generic specification for a generic_instantiation
Corresponding_Specification
The expanded generic body for a generic_instantiation
Corresponding_Body
:

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:

1. . Use Corresponding_Specification to obtain the implicit expanded specification or the instantiation.

2. . Use Corresponding_Body to obtain the implicit body of the instantiation.

3. . Use the calls available in package Statements to analyze the body block.


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