5. Embedded QUEL for Ada : Ada Variables and Data Types : Compilation Units and the Scope of Variables : The Package Specification
 
Share this page                  
The Package Specification
The syntax for an EQUEL/Ada package specification is:
package package_name is
              
[declarations]
end [package_name];
Syntax Notes:
1. Package_names on the package and end statements are not processed and are not compared for equivalence, as required by Ada.
2. You cannot qualify objects in the package specification with any package names.
3. Variables declared in package specifications are global to the parent scope of the specification. This is true even for objects declared in the private section.
When EQUEL reads a package specification, no matter whether it is declared in the same file or included by means of the EQUEL include statement, the contents of the package become visible immediately afterwards. EQUEL behaves as though there were the implicit Ada statements:
with package_name; use package_name;
The use of the EQUEL include statement actually generates the Ada with and use clauses, using the file name as the package name. The preprocessor generates these statements and assumes global visibility of package specification contents, because it does not read Ada library units. This restriction indicates that two package specifications declared at the same scope level cannot declare two objects with the same name. Note that when a package specification is nested in another compilation unit or package specification, it does not create a new scope level. The following example will generate an error because of the redeclaration of the object "ptr":
## package Stack is
## stack_max: constant := 50;
## ptr: Integer range 1..stack_max;
## stack_arr: array(1..stack_max) of Integer;
## end Stack;

## package Employees is
## ename_arr: array(1..1000) of String(1..20);
## ptr: Integer range 1..1000;
## end Employees;
If a package specification declares several types and variables that will be used with various subprograms and package bodies, you should put the specification in a file by itself and use the EQUEL include statement. The include statement will re-read the original text file and behave as though you had issued the appropriate Ada with and use clauses. For more information on the EQUEL include statement, see Include File Processing.
If you do not use the EQUEL include statement, you must explicitly issue the Ada with and use clauses. The following example declares two variables inside a package specification. In a single file are two procedures, which must both be preceded by the with and use clauses:
## package Vars is
## var1: Integer;
## var2: String(1..3);
## end Vars37
## with Vars; use Vars; -- Explicit Ada visibility clauses
## procedure Read_Vars is
## begin                -- EQUEL Statements that retrieve var1 and var2
## end Read_Vars;

with Vars; use Vars;    -- Explicit Ada visibility clauses

## procedure Write_Vars is
## begin                -- EQUEL Statements that append var1 and var2
## end Write_Vars;