GNATPrep#
GNATPrep is a C-style preprocessor for the GNAT toolchain.
#if <expression> [then]
-- ...
#elsif <expression> [then]
-- ...
#end if;
Valid <expression>
Values
<symbol>
<symbol>'Defined
<symbol> = "<value>"
<symbol> = <symbol>
<symbol> = <integer>
<symbol> > <integer>
<symbol> >= <integer>
<symbol> < <integer>
<symbol> <= <integer>
not <expression>
<expression> and <expression>
<expression> or <expression>
<expression> and then <expression>
<expression> or else <expression>
( <expression> )
- Integers must be non-negative in the range
0 .. 2**31 - 1
. <symbol>’Defined
is onlyTrue
when it has been defined either in a definitions file or a-D
switch.- Combining, for example,
or
andnot
operators requires parentheses.
Example
#if Win32'Defined then
-- Windows-specific code
#elsif POSIX'Defined then
-- POSIX-specific code
#else
-- ...
#end if;
Switch | Description |
---|---|
"-gnatep" |
Specifies the definitions file to use. <Project_Name>'Project_Dir can be used to search from the project file’s directory. "-gnatep=prep.def" |
"-gnateD" |
Defines a symbol for use. |
"-gnateG" |
Generate the preprocessed source. |
"-x" |
Builder switch to when using "gnatep=" to ensure the preprocessor data file is found. |
Definitions#
GNATPrep can either have symbols defined with the -D
switch or use a definitions file that is a simple sequence of:
symbol := value
$symbol
anywhere except for comments and string literals.
They should be ASCII values and their values may be:
- Empty (for null substitution)
- A string literal (using Ada’s syntax)
- Any sequence of characters from the set
{letters, digits, period, underline}
Comments in the same style as Ada may also be in the file.
Data Files#
Data files contain “preprocessor control lines” to control the function for individual files. The general for is
"file.adb" ["definitions_file.prep"] {switches}
and files may be either the file name sans its directory path or
wildcard *
in order to match all files that do not have a data file associated with them. There may not be two lines
that start with either the same file or with an *
.
"file_1.adb" "defs_1.prep" -u
* -c -DVersion=V2
Switch | Description |
---|---|
-b |
Causes both preprocessor lines and the lines deleted by preprocessing to be replaced by blank lines, preserving the line number. This switch is always implied; however, if specified after -c it cancels the effect of -c . |
-c |
Causes both preprocessor lines and the lines deleted by preprocessing to be retained as comments marked with the special string –! . |
-C |
Causes comments to be scanned and preprocessor symbols to be substituted. |
-D |
Define or redefine symbol to have new_value as its value. You can write symbol as either an Ada identifier or any Ada reserved word aside from if , else , elsif , end , and or and then . You can write new_value as a literal string, an Ada identifier or any Ada reserved word. A symbol declared with this switch replaces a symbol with the same name defined in a definition file. -Dsymbol[=new_value] |
-r |
Causes Source_Reference pragma to be generated. |
-s |
Causes a sorted list of symbol names and values to be listed on the standard output file. |
-u |
Causes undefined symbols to be treated as having the value False in the context of a preprocessor test. If you don’t specify this switch, an undefined symbol in a #if or #elsif test is treated as an error. |