Previous: Form of Definitions File, Up: Preprocessing Using gnatprep
gnatprep
The input text may contain preprocessor conditional inclusion lines, as well as general symbol substitution sequences.
The preprocessor conditional inclusion commands have the form
#if expression [then] lines #elsif expression [then] lines #elsif expression [then] lines ... #else lines #end if; |
In this example, expression is defined by the following grammar:
expression ::= <symbol> expression ::= <symbol> = "<value>" expression ::= <symbol> = <symbol> expression ::= <symbol> 'Defined expression ::= not expression expression ::= expression and expression expression ::= expression or expression expression ::= expression and then expression expression ::= expression or else expression expression ::= ( expression )
For the first test (expression ::= <symbol>) the symbol must have
either the value true or false, that is to say the right-hand of the
symbol definition must be one of the (case-insensitive) literals
True
or False
. If the value is true, then the
corresponding lines are included, and if the value is false, they are
excluded.
The test (expression ::= <symbol> 'Defined
) is true only if
the symbol has been defined in the definition file or by a -D
switch on the command line. Otherwise, the test is false.
The equality tests are case insensitive, as are all the preprocessor lines.
If the symbol referenced is not defined in the symbol definitions file,
then the effect depends on whether or not switch -u
is specified. If so, then the symbol is treated as if it had the value
false and the test fails. If this switch is not specified, then
it is an error to reference an undefined symbol. It is also an error to
reference a symbol that is defined with a value other than True
or False
.
The use of the not
operator inverts the sense of this logical test, so
that the lines are included only if the symbol is not defined.
The then
keyword is optional as shown
The #
must be the first non-blank character on a line, but
otherwise the format is free form. Spaces or tabs may appear between
the #
and the keyword. The keywords and the symbols are case
insensitive as in normal Ada code. Comments may be used on a
preprocessor line, but other than that, no other tokens may appear on a
preprocessor line. Any number of elsif
clauses can be present,
including none at all. The else
is optional, as in Ada.
The #
marking the start of a preprocessor line must be the first
non-blank character on the line, i.e. it must be preceded only by
spaces or horizontal tabs.
Symbol substitution outside of preprocessor lines is obtained by using the sequence
$symbol
anywhere within a source line, except in a comment or within a
string literal. The identifier
following the $
must match one of the symbols defined in the symbol
definition file, and the result is to substitute the value of the
symbol in place of $symbol
in the output file.
Note that although the substitution of strings within a string literal
is not possible, it is possible to have a symbol whose defined value is
a string literal. So instead of setting XYZ to hello
and writing:
Header : String := "$XYZ";
you should set XYZ to "hello"
and write:
Header : String := $XYZ;
and then the substitution will occur as desired.