Previous Topic: Use of external source members to hold preprocessor directivesNext Topic: General Considerations for the Compile Preprocessor


Integration with CA 2E using EXCUSRSRC

Prior to this rewrite of the compile preprocessor, Y* directives specified in EXCUSRSRC were automatically inserted into the generated source of functions which call the EXCUSRSRC function prior to any Z* directives (i.e. as pre-compilation commands). In addition, the RPGIV generator allowed users to specify X* directives in EXCUSRSRC, which were automatically inserted into the generated source of functions which call the EXCUSRSRC function as Y* directives after any Z* directives (i.e. as post-compilation commands).

The following should be noted when including compile preprocessor directives in EXCUSRSRC within CA 2E

  1. All generators have now been standardized for backwards-compatibility so that any standalone X* directives in EXCUSRSRC will be converted into Y* directives that are inserted into the generated source of functions which call the EXCUSRSRC function after any Z* directives (i.e. as post-compilation commands). Standalone Y* directives continue to be inserted into the source before any Z* directives (i.e. as pre-compilation commands). This only applies to existing stand-alone X* compile preprocessor directives.
  2. To use the new compile preprocessor directive types (X* and P*), they must be in a block surrounded by directives which begin with '/*', e.g.:

/*
compile preprocessor directives
/*

The /* directives can contain directives, e.g. '/* Start of preprocessor block' but will not be generated into the source. Only a single /* directive should start and end the preprocessor directive block.

Directives within a preprocessor directive block are copied into the final source member prior to any Z* directives, until a Z* directive is found in the preprocessor directive block. If a non-blank Z* directive is found, it is inserted into the source with the default Z* directives generated into all 2E functions. If a blank Z* directive is found, it will not be generated into the source, but it will be used to delimit pre- and post-compilation commands (see the section on "Separation of pre- and post-compilation commands" for more details). All subsequent preprocessor directives are inserted into the final source member after any Z* directives.

  1. Any P* (exit program call) directives will be ignored if they are found outside a preprocessor block. P* directives are only valid within a preprocessor directive block.

    For instance, if an EXCUSRSRC function contains the following code:

/* Start of preprocessor directive block
Y* SNDMSG MSG('About to compile...') TOUSR(*REQUESTER)
X* QRPGSRC,DOCSRC1
P* QGPL/PREPROCRPG
Z* USRPRF(*OWNER)
P* QGPL/PSTPROCRPG
X* QRPGSRC,DOCSRC2
Y* SNDMSG MSG('Compilation completed!') TOUSR(*REQUESTER)
/* End of preprocessor directive block

Then the final code that would be seen in the source of a function that calls this EXCUSRSRC would be as follows:

...
Y* SNDMSG MSG('About to compile...') TOUSR(*REQUESTER)
X* QRPGLESRC,DOCSRC1
P* QGPL/PREPROCRPG
Z* <default-2E-compile-overrides>
Z* USRPRF(*OWNER)
P* QGPL/PSTPROCRPG
X* QRPGLESRC,DOCSRC2
Y* SNDMSG MSG('Compilation completed!') TOUSR(*REQUESTER)
...

The first three directives of the EXCUSRSRC (not including the starting '/*' directive) have been inserted into the source. Next come the default Z* directives that are generated for 2E functions, followed by the Z* directive from the preprocessor directive block. Finally, the last three directives in the preprocessor block (not including the ending '/*' directive) are inserted into the source.