[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP Pascal for OpenVMS
Language Reference Manual


Previous Contents Index

Table 10-9 Attributes on Data Items
Class Data Item
  Variable Formal
Parameter
Pointer
Base
Type


Component1
Function
Result
Various
Items
2
Alignment Yes 3 Yes 4 Yes 4 Yes 5 Yes No
Allocation Yes 6 No No No No No
Hidden Yes No Yes No No No
Key No No No Yes 7 No No
List No Yes 8 No No No No
Parameter
passing
No Yes 9 No No No No
Pos No No No Yes 7 No No
Read-only Yes Yes Yes Yes No No
Size Yes 6 Yes 10 Yes Yes 11 Yes No
Truncate No Yes No No No No
Unsafe 6 Yes Yes 9 Yes Yes Yes Yes
Value Yes 12 No No No No No
Visibility 6 Yes No No No No No
Volatile Yes Yes Yes Yes Yes No
Write-only Yes Yes Yes Yes No No

1Component of a record, array, VARYING OF CHAR string, or file (includes conformant parameters).
2Index of an array, tag field of a variant record (when no tag identifier is present), base type of a set, formal discriminant.
3Variables of nonstatic types must be at least byte aligned.
4UNALIGNED not allowed.
5Not allowed on components of files or VARYING OF CHAR strings.
6Not allowed on variables of nonstatic types.
7Allowed only on record fields (including the tag field of a variant record).
8Procedure parameters and conformant parameters are allowed only on EXTERNAL routines.
9Not allowed on conformant VARYING parameters; not allowed on schematic parameters.
10Not allowed on conformant parameters; not allowed on schematic parameters.
11Not allowed on components of files or VARYING OF CHAR strings, or on structured types with file components.
12Not allowed on variables larger than INTEGER or structured variables.


Chapter 11
Directives

Your source code can contain embedded directives, which will be evaluated at compile time. These directives can appear in any column and do not have to be on a line by themselves. You can use directives to control your compilation, and to extract immediate information at compile time.

The directives implemented in HP Pascal are shown in the following table:

Directives Section
%INCLUDE 11.1
%DICTIONARY 11.2
%TITLE and %SUBTITLE 11.3
%IF, %ELSE, %ELIF, and %ENDIF 11.4
%DEFINED 11.5
%ERROR, %WARN, %INFO, and %MESSAGE 11.6
%ARCH_NAME, %SYSTEM_NAME, and %SYSTEM_VERSION 11.7
%DATE, %TIME, and %COMPILER_VERSION 11.8
%LINE, %FILE, %ROUTINE, %MODULE, and %IDENT 11.9

11.1 %INCLUDE

%INCLUDE inserts the contents of a file at the location of the directive in the code and has the following form:


%INCLUDE 'file-spec [[/[[NO]]LIST]]'

file-spec

environment specific (default)

The name of the file to be included.

/[[NO]]LIST

/LIST (default)

The /LIST qualifier indicates that the included file should be printed in the listing of the program if a listing is being generated.

If you do not specify the /LIST qualifier, the default is determined by the use of compilation switches. Use of this parameter overrides compilation switches.

This directive can appear anywhere that a comment is legal.

In the following example, the %INCLUDE directive specifies the file CONDEF.PAS, which contains constant definitions:

In the Program:


PROGRAM Student_Courses( INPUT, OUTPUT, Sched );
CONST
   %INCLUDE 'CONDEF.PAS/LIST'
TYPE
   Schedules = RECORD
      Year    : ( Fr, So, Jr, Sr );
      Name    : PACKED ARRAY[1..30] OF CHAR;
      Parents : PACKED ARRAY[1..40] OF CHAR;
      College : ( Arts, Engineering, Architecture,
                  Agriculture, Hotel );
      END;

File CONDEF.PAS:


Max_Class = 300;
N_Profs   = 140;
Frosh     = 3000;

The main program Student_Courses is compiled as though it were written as follows:


PROGRAM Student_Courses( INPUT, OUTPUT, Sched );
CONST
   Max_Class = 300;
   N_Profs   = 140;
   Frosh     = 3000;
TYPE
   Schedules = RECORD
      Year    : ( Fr, So, Jr, Sr );
      Name    : PACKED ARRAY[1..30] OF CHAR;
      Parents : PACKED ARRAY[1..40] OF CHAR;
      College : ( Arts, Engineering, Architecture,
                 Agriculture, Hotel );
      END;

You can use the %INCLUDE directive in another included file; however, two files cannot attempt to include each other.

A file included at the outermost level of a program is said to be included at the first level. A file included by a first-level file is said to be included at the second level, and so on. In general, a program may not include any files beyond the fifth level; it may not include any files beyond the fourth level if you have included a %DICTIONARY directive in the fourth level. Nesting levels may be further restricted by the number of files you are allowed to have open at one time.

Figure 11-1 shows the legal levels of included files.

Figure 11-1 %INCLUDE File Levels


For More Information:

  • On the Oracle CDD/Repository (CDD) ( Section 11.2)
  • On default file specifications and on including text libraries (HP Pascal for OpenVMS User Manual)

11.2 %DICTIONARY

%DICTIONARY allows access to data definitions stored in the Oracle CDD/Repository (CDD), which is a product that must be purchased separately and may not be available on your environment; the directive has the following form:


%DICTIONARY 'cdd-path-name [[/[[NO]]LIST]] '

cdd-path-name

A character string that represents the full or relative path name of a CDD record description to be extracted. The resulting path name must conform to the rules for forming CDD path names.

A full path name is one that begins with CDD$TOP and specifies the names of all its descendants; it is a complete path to the record definition. Descendant names are separated from each other by a period.

A relative path name begins with any generation other than CDD$TOP, and specifies the names of the descendants after that point. You can create a relative path by establishing a default directory with a logical name.

/[[NO]]LIST

/LIST (default)

Indicates that the included declarations should be printed in the listing of the program if a listing is being generated. If not specified, the default is determined by compilation switches. Use of this parameter overrides compilation switches.

For More Information:

  • On using the Oracle CDD/Repository with HP Pascal (HP Pascal for OpenVMS User Manual)

11.3 %TITLE and %SUBTITLE

%TITLE and %SUBTITLE allow you to specify a compile-time string expression for the listing title and subtitle lines; they have the following form:


   %TITLE 'character string'
   %SUBTITLE 'character string'

The compiler listing header includes the %TITLE and %SUBTITLE strings in the title and subtitle sections. If you do not specify these directives, HP Pascal fills the %TITLE field with blanks and the first %SUBTITLE field with 'source listing'. If a specified character string is too long to fit in the predefined title and subtitle sections, the string will be truncated on the right without warning.

If a %TITLE directive appears on the first line of a page, it sets the title area for the current page and any following pages until the compiler encounters another %TITLE directive. If the %TITLE directive does not appear on the first line of a page, then the title area is not set until the next page.

The %SUBTITLE directive affects only the subtitle area in the source listing section. If a %SUBTITLE directive appears on the first or second line of a page, then the subtitle area is set for the current page. If the %SUBTITLE directive does not appear in the first two lines of a page, then the subtitle area is not set until the next page.

On OpenVMS VAX systems, if either of these directives is used and if a listing is being generated, HP Pascal generates a table of contents page by default. It appears first in the listing, preceding the source listing section. To disable the table of contents option, you must use a compilation switch.

For More Information:

  • On creating listings and on using compilation switches (HP Pascal for OpenVMS User Manual)

11.4 %IF, %ELSE, %ELIF, and %ENDIF

The %IF family of directives is used to conditionally compile specified sections of source code. These directives are useful if you need to compile the same source code for various configurations or environments.

The %IF directive family has the following syntax:


   %IF compile-time-expression
   %THEN
      Pascal tokens . . .
   [%ELIF compile-time-expression
   %THEN
      Pascal tokens
      . . . ] . . .
   [%ELSE
      Pascal tokens . . . ]
   %ENDIF

A %IF directive can have zero or more %ELIF parts and zero or one %ELSE parts.

%IF directives can be nested up to 32 deep.

Note that skipped sections of source code must still be valid HP Pascal tokens. The skipped tokens are not processed semantically by the compiler except for control expressions of nested %IF directives. All control expressions are semantically processed to ensure they result in a Boolean result. %INCLUDE and %DICTIONARY directives encountered while skipping tokens do not attempt to open the file name or access the dictionary path. Instead, they return the token TRUE.

In the following example, the state of a flag (Debug_Flag) is checked for true or false. The value of an integer variable (I) will then be set to either 12 or 1, depending on the state of the flag:


CONST
    Debug_Flag := true; { or false }
VAR
    I : integer;

I := %IF Debug_Flag %THEN 12 %ELSE 1 %ENDIF;
%IF Debug_Flag
%THEN
    writeln('Debug: the value of I is ',i:2);
%ENDIF

In the following example selected code will be compiled only if the specific configuration is selected.


TYPE
  Configs = (Config1, Config2, Config3);
CONST
  Config = Config1; { or Config2 or Config3 }

%IF Config = Config1
%THEN
    { Code for Config1... }

%ELIF Config = Config2
%THEN
    { Code for Config2... }

%ELSE Config = Config3
    { Code for Config3...}

%ENDIF

Note that the compile-time expression for the %IF statement is the same compile-time expression that can be used anywhere in HP Pascal. You can use any operator or builtin routine in a %IF control expression, as you can in any constant expression.

One use of %IF is to compile for various configurations or environments (as shown in the preceding example).

Rather than defining a constant in the Pascal source as shown in the examples here, you might want to define the constant from the command line with the /CONSTANT qualifier. See the description of the /CONSTANT qualifier for more information.

11.5 %DEFINED

%DEFINED takes a name and returns TRUE if a name has a meaning in the current scope; otherwise, it returns FALSE. This is shown in the following example:


%IF %DEFINED(X)
%THEN
   writeln(x);
%ENDIF

11.6 %ERROR, %WARN, %INFO, and %MESSAGE

These directives will accept one or more string expressions, and at compile time will produce an error message, warning message, informational message, or terminal-only output (respectively).

The syntax is as follows:


   %ERROR    ( string-expression, . . . )
   %WARN     ( string-expression, . . . )
   %INFO     ( string-expression, . . . )
   %MESSAGE  ( string-expression, . . . )

The following is an example of %ERROR:


TYPE
  Some_Type = ...;

%IF SIZE(Some_Type) > 8
%THEN
   %ERROR ('We do not handle types greater than 8 bytes')
%ENDIF

The following is an example of %WARN:


%IF Config = Config1
%THEN
     { Code for Config1... }

%ELIF (Config = Config2) or (Config = Config3)
%THEN
     { Code for Config2/Config3... }

%ELSE
   %WARN ('Config not supported, defaulting to generic')
     { Code for generic config... }
%ENDIF

The following is an example of %INFO:



%IF Debug_Mode
%THEN
  %INFO('Building application with debug code inserted')
%ENDIF

The following is an example of %MESSAGE:


  %IF DEBUG_MODE %THEN %MESSAGE ('Debug-mode is enabled') %ENDIF


Previous Next Contents Index