3 CDF - Compiler Directing Facility
The Compiler Directing Facility, or CDF, is a means of controlling the compilation of GnuCOBOL programs. CDF provides a mechanism for dynamically setting or resetting certain compiler switches, introducing new source code from one or more source code libraries, making dynamic source code modifications and conditionally processing or ignoring source statements altogether. This is accomplished via a series of special CDF statements and directives that will appear in the program source code.
When the compiler is operating in Fixed Format Mode, all CDF statements must begin in column seven (7) or beyond.
There are two types of supported CDF statements in GnuCOBOL — Text Manipulation Statements and Compiler Directives.
The CDF text manipulation statements COPY and REPLACE are used to introduce new code into programs either with or without changes, or may be used to modify existing statements already in the program. Text manipulation statements are always terminated with a period.
CDF directives, denoted by the presence of a >> character sequence as part of the statement name itself, influence the process of program compilation.
Compiler directives are never terminated with a period.
The compiler command-line option -D offers additional control ( cobc - The GnuCOBOL Compiler).
3.1 >>CALL-CONVENTION
CDF >>CALL-CONVENTION Syntax
>>CALL-CONVENTION { COBOL }
~~~~~~~~~~~~~~~~~ { EXTERN }
{ STDCALL }
{ STATIC }
This directive instructs the compiler how to treat references to program names and may be used to determine other details for interacting with a function or program. There are four options with COBOL being the default.
COBOLThe program name is treated as a COBOL word that maps to the externalised name program to be called, cancelled or referenced in the program-address-identifier, applying the same mapping rules as for a program name for which no
ASphrase is specified. (The is the default.)EXTERNThe program name is treated as an external reference.
STDCALLAllows system standard calling conventions (as opposed to GnuCOBOL calling conventions) to be used when calling a subroutine. The definition of what constitutes “system standard” may vary from operating system to operating system. Use of this requires special knowledge about the linkage requirements of subroutines you are intending to
CALL. Subroutines written in GnuCOBOL do not need this option.STATICCauses the linkage to the subroutine to be performed in such a way as to require the subroutine to be statically-linked with the calling program. Note that this enables static-linking to be used on a subroutine-by-subroutine selective basis. Or in other words - The program name is called as a included element and not dynamically which is the normal default.
3.2 COPY
CDF COPY Statement Syntax
COPY copybook-name
~~~~
[ IN|OF library-name ]
~~ ~~
[ SUPPRESS PRINTING ]
~~~~~~~~
[ REPLACING { Phrase-Clause | String-Clause }... ] .
~~~~~~~~~
CDF COPY Phrase-Clause Syntax
{ ==pseudo-text-1== } BY { ==pseudo-text-2== }
{ identifier-1 } ~~ { identifier-2 }
{ literal-1 } { literal-2 }
{ word-1 } { word-2 }
CDF COPY String-Clause Syntax
[ LEADING|TRAILING ] ==partial-word-1== BY ==partial-word-2==
~~~~~~~ ~~~~~~~~ ~~
COPYstatements are used to import copybooks ( 2.1.6 Copybooks) into a program.COPYstatements may be used anywhere within a COBOL program where the code contained within the copybook would be syntactically valid.The optional
SUPPRESSclause (with or without the optionalPRINTINGreserved word) is valid syntactically but is non-functional. It is supported to facilitate compatibility with source code written for other versions of COBOL.There is no difference between the use of the word
INand the wordOF— use the one you prefer.A period is absolutely mandatory at the end of every
COPYstatement, even if the statement occurs within the scope of another one where a period might appear disruptive, such as within the scope of anIF( 7.8.23 IF) statement. This mandatory period at the end of the statement does not, however, affect the statement scope in which theCOPYoccurs.Both <pseudo-text-2> and <partial-word-2> may be null.
All
COPYstatements are located and the contents of the corresponding copybooks inserted into the program source code before the actual compilation process begins. If a copybook contains aCOPYstatement, the copybook insertion process will be repeated to resolve the embeddedCOPY. This will continue until no unresolvedCOPYstatements remain. At that point, actual program compilation will begin.10.1.6 Locating Copybooks, for the specific rules on how copybooks are located by the compiler.
The optional
REPLACINGclause allows for one or more of either of the following kinds of text replacements to be made:<Phrase-Clause>
Replacement of one or more complete reserved words, user-defined identifiers or literals; the following points apply to this option:
This option cannot be used to replace part of a word, identifier or literal.
Whatever precedes the
BYwill be referred to here as the search string.Single-item search strings can be specified by coding the
<identifier-1>,<literal-1>or<word-1>being replaced.Multiple-item search strings can be specified using the
==<pseudo-text-1>==option. For example, to replace all occurrences ofUPON PRINTER, you would specify==UPON PRINTER==.The replacement string, which follows the
BY, may be specified using any of the four options.If the replacement string is a multiple-item phrase or is to be deleted altogether, you must use the
==<pseudo-text-2>==option. If<pseudo-text-2>is null (in other words, the replacement text is specified as====), all encountered occurrences of the search string will be deleted.
<String-Clause>
Using this, you may replace character sequences that occur at the beginning (see
LEADING) or end (seeTRAILING) of reserved or user-defined words. For example, to change all words of the form “0100-xxxxxx” to “020-xxxxxx”, codeLEADING ==0100-== BY ==020-==. To simply remove all “0100-” prefixes from words, codeLEADING ==0100-== BY ====.
3.3 REPLACE
CDF REPLACE Statement (Format 1) Syntax
REPLACE [ ALSO ] { Phrase-Clause | String-Clause }... .
~~~~~~~ ~~~~
CDF REPLACE Statement (Format 2) Syntax
REPLACE [ LAST ] OFF .
~~~~~~~ ~~~~ ~~~
CDF REPLACE Phrase-Clause Syntax
{ ==pseudo-text-1== } BY { ==pseudo-text-2== }
~~
CDF REPLACE String-Clause Syntax
[ LEADING|TRAILING ] ==partial-word-1== BY ==partial-word-2==
~~~~~~~ ~~~~~~~~ ~~
The
REPLACEstatement provides a mechanism for changing all or part of one or more GnuCOBOL statements.A period is absolutely mandatory at the end of every
REPLACEstatement (either format), even if the statement occurs within the scope of another one where a period might appear disruptive (such as within the scope of anIF( 7.8.23 IF) statement; the period will not, however, affect the statement scope in which theREPLACEoccurs.The following points apply to Format 1 of the
REPLACEstatement:Format 1 of the
REPLACEstatement can be used to make changes to program source code in much the same way as theREPLACINGoption of theCOPYstatement can, via these options:<Phrase-Clause>
Replace one or more complete reserved words, user-defined identifiers or literals; the following points apply to this option:
This option cannot be used to replace part of a word, identifier or literal.
Whatever precedes the
BYwill be referred to here as the search string.Search strings on
REPLACEare always specified using the==<pseudo-text-1>==option. For example, to replace all occurrences ofUPON PRINTER, you would specify==UPON PRINTER==.The replacement string, which follows the
BY, is specified using the==<pseudo-text-2>==option. If<pseudo-text-2>is null (in other words, the replacement text is specified as====), all encountered occurrences of the search string will be deleted.
<String-Clause>
Using this, you may replace character sequences that occur at the beginning (see
LEADING) or end (seeTRAILING) of reserved or user-defined words. For example, to change all words of the form “0100-xxxxxx” to “020-xxxxxx”, codeLEADING ==0100-== BY ==020-==. To simply remove all “0100-” prefixes from words, codeLEADING ==0100-== BY ====.
Once a Format 1
REPLACEstatement is encountered in the currently-compiling source file, Replace Mode becomes active, and the change(s) specified by that statement will be automatically made on all subsequent source statements the compiler reads from the file.Replace Mode remains in-effect — continuing to make source code changes — until another Format 1
REPLACEis encountered, the end of currently compiling program source file is reached or a Format 2REPLACEstatement is encountered.When a Format 1
REPLACEstatement with theALSOkeyword is encountered without Replace Mode being currently active, the effect will be as if theALSOhad not been specified. If Replace Mode already was in effect, the effect will be to “push” the current change specification(s) onto the top of a stack and add the specification(s) of the new statement to those that were already in effect.When a Format 1
REPLACEwithout theALSOkeyword is encountered, any stacked change specification(s), if any, will be discarded and the currently in-effect change specification(s), if any, will be replaced by those of the new statement.When the end of the currently-compiling source file is reached, Replace Mode is deactivated and any stacked replace specifications will be discarded — compilation of the next source file (if any) will begin with Replace Mode inactive and no change specification(s) on the stack.
The following points apply to Format 2 of the
REPLACEstatement:If Replace Mode is currently inactive, the Format 2
REPLACEstatement will be ignored.If Replace Mode is currently active, a
REPLACE OFF.will deactivate Replace Mode and discard any replace specification(s) on the stack. The compiler will henceforth operate as if noREPLACEhad ever been encountered, until such time as another Format 1REPLACEis encountered.If Replace Mode is currently active, a
REPLACE LAST OFF.will replace the current replace specification(s) with those popped off the top of the stack. If there were no replace specification(s) on the stack, the effect will be as if aREPLACE OFF.had been coded.
3.4 >>DEFINE
CDF >>DEFINE Directive Syntax
>>DEFINE [ CONSTANT ] cdf-variable-1 AS { OFF }
~~~~~~~~ ~~~~~~~~ { ~~~ }
{ literal-1 [ OVERRIDE ] }
{ ~~~~~~~~ }
{ PARAMETER [ OVERRIDE ] }
~~~~~~~~~ ~~~~~~~~
Use the >>DEFINE CDF directive to create CDF variables and (optionally) assign them either literal or environment variable values.
The reserved word
ASis optional and may be included, or not, at the discretion of the programmer. The presence or absence of this word has no effect upon the program.CDF variables defined in this way become undefined once an
END PROGRAMorEND FUNCTIONdirective is encountered in the input source.The
>>DEFINECDF directive is one way to create CDF variables that may be processed by other CDF statements such as>>IF( 3.5 >>IF). The>>SETCDF directive ( 3.6 >>SET) provides another way to create them.CDF variable names follow the rules for standard GnuCOBOL user-defined names, and may not duplicate any CDF reserved word. CDF variable names may duplicate COBOL reserved words, provided the
CONSTANToption is not specified, but such names are not recommended.The
CONSTANToption is valid only in conjunction with <literal-1>. WhenCONSTANTis specified, the CDF variable that is created may be used within your regular COBOL code as if it were a literal value. Without this option, the CDF variable may only be referenced on other CDF statements. TheOFFoption is used to create a variable without assigning it any value.The
PARAMETERoption is used to create a variable whose value is that of the environment variable of the same name. Note that this value assignment occurs at compilation time, not program execution time.In the absence of the
OVERRIDEoption, <cdf-variable-1> must not yet have been defined. When theOVERRIDEoption is specified, <cdf-variable-1> will be created with the specified value, if it had not yet been defined. If it had already been defined, it will be redefined with the new value.
3.5 >>IF
CDF >>IF Directive Syntax
>>IF CDF-Conditional-Expression-1
~~~~ [ Program-Source-Lines-1 ]
[ >>ELIF CDF-Conditional-Expression-2
~~~~~~ [ Program-Source-Lines-2 ] ]...
[ >>ELSE
~~~~~~ [ Program-Source-Lines-3 ] ]
>>END-IF
~~~~~~~~
CDF-Conditional-Expression Syntax
{ cdf-variable-1 } IS [ NOT ] { DEFINED }
{ literal-1 } ~~~ { ~~~~~~~ }
{ SET }
{ ~~~ }
{ CDF-RelOp { cdf-variable-2 } }
{ { literal-2 } }
CDF-RelOp Syntax
>= or GREATER THAN OR EQUAL TO
~~~~~~~ ~~ ~~~~~
> or GREATER THAN
~~~~~~~
<= or LESS THAN OR EQUAL TO
~~~~ ~~ ~~~~~
< or LESS THAN
~~~~
= or EQUAL TO
~~~~~
<> or EQUAL TO (with "NOT")
~~~~~
The >>IF CDF directive causes the GnuCOBOL compiler to process or ignore COBOL source statements, CDF text-manipulation statements and CDF directives depending upon the value of one or more conditional expressions based upon CDF variables.
The reserved words
IS,THANandTOare optional and may be omitted. The presence or absence of these words has no effect on the program.Each
>>IFdirective must be terminated by an>>END-IFdirective.There may be any number of
>>ELIFclauses following an>>IF, including zero.There may no more than one
>>ELSEclause following an>>IF. When>>ELSEis used, it must follow the>>IFand all>>ELIFclauses.Only one of the <Program-Source-Lines-n> block of statements that lie within the scope of the
>>IF…>>END-IFmay be processed by the compiler. Which one (if any) that gets processed will be decided as follows:Each <CDF-Conditional-Expression-n> will be evaluated, in turn, in the sequence in which they are coded in the >>IF statement and any
>>ELIFclauses that may be present until one evaluates toTRUE. Once one of them evaluates toTRUE, the <Program-Source-Lines-n> block of code that corresponds to theTRUE<CDF-Conditional-Expression-n> will be one that is processed. All others within the>>IF->>END-IFscope will be ignored.If no <CDF-Conditional-Expression> evaluates to
TRUE, and there is an>>ELSEclause, the <Program-Source-Lines-3> block of statements following the>>ELSEclause will be processed by the compiler and all others within the>>IF->>END-IFscope will be ignored.If no <CDF-Conditional-Expression-n> evaluates to
TRUEand there is no>>ELSEclause, then none of the <Program-Source-Lines-n> block of statements within the>>IF->>END-IFscope will be processed by the compiler.If the <Program-Source-Lines-n>> statement block selected for processing is empty, no error results — there will just be no code generated from the
>>IF->>END-IFstructure.
A <Program-Source-Lines-n> block may contain any valid COBOL or CDF code.
The following points pertain to any <CDF-Conditional-Expression-n>:
The
DEFINEDoption tests for whether <cdf-variable-1> has been defined, but not yet assigned a value (>>DEFINE ... OFF); use theNOToption to test for the variable not being defined.The
SEToption tests for whether <cdf-variable-1> has been given a value, either via a>>SETstatement or via a>>DEFINEwithout theOFFoption.Two CDF variables, two literals or a single CDF variable and a single literal may be compared against each other using a relational operator. Unlike the standard GnuCOBOL
IFstatement ( 7.8.23 IF), multiple comparisons cannot beANDed orORed together; you may nest a second>>IFinside the first, however, to simulate anANDand anORmay be simulated via the>>ELIFoption.The
<>symbol stands forNOT EQUAL TO.
3.6 >>SET
CDF >>SET Directive Syntax
>>SET { [ CONSTANT ] cdf-variable-1 literal-1 ] }
~~~~~ { ~~~~~~~~ }
{ SOURCEFORMAT AS FIXED|FREE|VARIABLE|XOPEN|XCARD|CRT|TERMINAL|COBOLX }
{ ~~~~~~~~~~~~ ~~~~~ ~~~~ ~~~~~~~~ ~~~~~ ~~~~~ ~~~ ~~~~~~~~ ~~~~~~ }
{ NOFOLDCOPYNAME }
{ ~~~~~~~~~~~~~~ }
{ FOLDCOPYNAME AS UPPER|LOWER }
~~~~~~~~~~~~ ~~~~~ ~~~~~
The >>SET CDF directive provides an alternate means of performing the actions of the >>DEFINE and >>SOURCE directives, as well as a means of controlling the compiler’s
-free switch,
-fixed switch and
-ffold-copy switch from within program source code.
The reserved word
ASis optional (only on theSOURCEFORMATandFOLDCOPYNAMEclauses) and may be included, or not, at the discretion of the programmer. The presence or absence of this word has no effect upon the program.CDF variables defined in this way become undefined once an
END PROGRAMorEND FUNCTIONdirective is encountered in the input source.The
FOLDCOPYNAMEoption provides the equivalent of specifying the compiler-ffold-copy=<xxx>switch, where<xxx>is eitherUPPERorLOWER.The
NOFOLDCOPYNAMEoption turns off the effect of either the>>SET FOLDCOPYNAMEstatement or the compiler-ffold-copy=<xxx>switch.If the
CONSTANToption is used, <literal-1> must also be used. This option provides another means of defining constants that may be used anywhere in the program that a literal could be specified.The remaining options of the
>>SETCDF directive provide equivalent functionality to the>>DEFINE[ how ever as this form is no longer in the Cobol standards and is classsed as archaic and wil be so flagged, the use of >>DEFINE should be used for all new programs ], and>>SOURCEdirectives, as follows:>>SET <cdf-variable-1>>>DEFINE <cdf-variable-1> AS OFF>>SET <cdf-variable-1> AS <literal-1>>>DEFINE <cdf-variable-1> AS <literal-1>>>SET CONSTANT <cdf-variable-1> <literal-1>>>DEFINE CONSTANT <cdf-variable-1> <literal-1>>>SET SOURCEFORMAT AS FIXED>>SOURCE FORMAT IS FIXED>>SET SOURCEFORMAT AS FREE>>SOURCE FORMAT IS FREE>>SET SOURCEFORMAT AS VARIABLE>>SOURCE FORMAT IS VARIABLE>>SET SOURCEFORMAT AS XOPEN>>SOURCE FORMAT IS XOPEN>>SET SOURCEFORMAT AS XCARD>>SOURCE FORMAT IS XCARD>>SET SOURCEFORMAT AS CRT>>SOURCE FORMAT IS CRT>>SET SOURCEFORMAT AS TERMINAL>>SOURCE FORMAT IS TERMINAL>>SET SOURCEFORMAT AS COBOLX>>SOURCE FORMAT IS COBOLX>>SET XFD literal-1[See chapter 13]
>>SET Micro-Focus-Directive[to do]
3.7 >>SOURCE
CDF >>SOURCE Directive Syntax
>>SOURCE FORMAT IS { FIXED|FREE|VARIABLE|XOPEN|XCARD|CRT|TERMINAL|COBOLX }
~~~~~~~~ ~~~~~ ~~~~ ~~~~~~~~ ~~~~~ ~~~~~ ~~~ ~~~~~~~~ ~~~~~~
The >>SOURCE CDF directive puts the compiler into FIXED or FREE source-code format mode. This, in effect, provides yet another mechanism for controlling the compiler’s
-free switch and
-fixed switch.
The reserved words
FORMATandISare optional and may be included, or not, at the discretion of the programmer. The presence or absence of these words has no effect upon the program.FIXED : Source code is divided into: columns 1-6, the sequence number area; column 7, the indicator area; columns 8-72, the program-text area; and columns 72-80 as the reference area.
FREE : Source code text area starts in column 1 and continues till the end of line (to a maximum of 255 characters).
VARIABLE : Identical to FIXED format above except that it extends up to column 256 (in MF and some others, it is 252).
XOPEN : X/Open Free-form format. The program-text area may start in column 1 unless an indicator is present, and lines may contain up to 80 characters. Indicator for debugging lines is D instead of D or d.
XCARD : ICOBOL xCard format. Variable format with right margin set at column 255 instead of 250.
CRT : ICOBOL Free-form format (CRT). Similar to the X/Open format above, with lines containing up to 320 characters and single-character debugging line indicators (D or d).
TERMINAL : ACUCOBOL-GT Terminal format. Similar to the CRT format above, with indicator for debugging lines being D instead of D or d. This format is mostly compatible with VAX COBOL terminal source format.
COBOLX : This format is similar to the CRT format above, except that the indicator area is always present in column 1; the program-text area starts in column 2 and extends up to the end of the record. Lines may contain up to 255 characters.
Note that with source formats XOPEN, CRT, TERMINAL, and COBOLX, missing spaces are not inserted within continued alphanumeric literals that are truncated before the right margin
You may switch between the various format modes as desired and it takes effect immediately.
You may also use the
>>SETCDF directive to perform this function.If the compiler is already in the specified mode, this statement will have no effect.
3.8 >>TURN
CDF >>TURN Directive Syntax
>>TURN { exception-name-1 [ file-name-1 ]... }...
~~~~~~
{ OFF }
{ ~~~ }
{ CHECKING ON [ WITH LOCATION ] }
~~~~~~~~ ~~ ~~~~~~~~
The directive will (de-)activate exception checks.
3.9 >>D
CDF >>D Directive Syntax
>>D
~~~
The directive removes all floating debug lines if debug mode not active. Otherwise will ignore the directive part of the line.
3.10 >>DISPLAY
CDF >>DISPLAY Directive Syntax
>>DISPLAY source-text [ VCS = version-string ]
~~~~~~~~~ ~~~
The directive is a v1.0 extension and will display messages during compilation.
3.11 >>PAGE
CDF >>PAGE Directive Syntax
>>PAGE [ comment-text ]
~~~~~~
The PAGE directive specifies page ejection and provides documentation for the source listing.
Comment-Text may contain any character in the computers standard character coded set except for control characters.
Comment-Text is not checked for syntax and only serves as documentation.
if a source listing is being produced a PAGE directive shall cause page ejection followed by listing of the PAGE directive.
If a listing is not being produced the directive will have no effect.
3.12 >>LISTING
CDF >>LISTING Directive Syntax
>>LISTING {ON}
~~~~~~~~~ {OFF}
The directive allows the program listing to be de-(activated).
3.13 >>LEAP-SECONDS
CDF >>LEAP-SECONDS Directive Syntax
>>LEAP-SECONDS
~~~~~~~~~~~~~~
The >>LEAP-SECONDS CDF directive is syntactically recognized but is otherwise non-functional.
Allows for more than 60 seconds per minute.
3.14 $ Directives
CDF $ Directive Syntax
$ (Dollar) Directives - Active.
These directives are active and have the same function as ones starting with >>:
$DEFINE
$DISPLAY ON|OFF
$IF
$ELIF
$ELSE
$ELSE-IF
$END
$SET
It is recommended to use the standard directives only instead of the MF
directives (when possible) as these have a higher chance for being portable.
$ (Dollar) Directives - Not Active.
These are NOT active and will produce a warning message:
$DISPLAY VCS ...
Recognised but otherwise ignored.
@OPTIONS options-text
Additional Micro-Focus directives accepted :
ADDRSV | ADD-RSV literal-1
ADDSYN | ADD-SYN literal-1 = literal-2
ASSIGN "EXTERNAL" | "DYNAMIC"
BOUND
CALLFH literal-1
COMP1 | COMP-1 "BINARY" | "FLOAT"
FOLDCOPYNAME | FOLD-COPY-NAME AS "UPPER" | "LOWER"
MAKESYN | MAKE-SYN
NOBOUND | NO-BOUND
NOFOLDCOPYNAME | NOFOLD-COPY-NAME | NO-FOLD-COPY-NAME
OVERRIDE literal-1 = literal-2
REMOVE literal-1
SOURCEFORMAT | SOURCE-FORMAT "FIXED" | "FREE" | "VARIABLE"
SSRANGE "2"
NOSSRANGE | NO-SSRANGE
Offers support for MF Compiler Directives.