1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-1998, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 -- This program provides a simple preprocessing capability for Ada programs.
29 -- It is designed for use with GNAT, but is not dependent on any special
32 -- To call gnatprep use
34 -- gnatprep infile outfile [deffile] [-c] [-b] [-r] [-s] [-u]
39 -- infile is the full name of the input file, which is an Ada source
40 -- file containing preprocessor directives.
42 -- outfile is the full name of the output file, which is an Ada source
43 -- in standard Ada form. When used with GNAT, this file name will
44 -- normally have an ads or adb suffix.
46 -- deffile is the full name of a text file containing definitions of
47 -- symbols to be referenced by the preprocessor. This argument is optional
49 -- The -c switch, causes both preprocessor lines and the lines deleted
50 -- by preprocessing to be retained in the output source as comments marked
51 -- with the special string "--! ". This option will result in line numbers
52 -- being preserved in the output file.
54 -- The -b switch causes both preprocessor lines and the lines deleted by
55 -- preprocessing to be replaced by blank lines in the output source file,
56 -- thus preserving line numbers in the output file.
58 -- The -r switch causes a Source_Reference pragma to be generated that
59 -- references the original input file, so that error messages will use
60 -- the file name of this original file.
62 -- The -u switch causes gnatprep to treat any undefined symbol that it
63 -- encounters as having the value False. Otherwise an undefined symbol
66 -- The -s switch causes a sorted list of symbol names and values to be
67 -- listed on the standard output file.
69 -- The -D switch causes symbol 'symbol' to be associated with 'value'.
70 -- This symbols can then be referenced by the preprocessor
72 -- Note: if neither -b nor -c is present, then preprocessor lines and
73 -- deleted lines are completely removed from the output, unless -r is
74 -- specified, in which case -b is assumed.
76 -- The definitions file contains lines of the form
80 -- where symbol is an identifier, following normal Ada (case-insensitive)
81 -- rules for its syntax, and value is one of the following:
83 -- Empty, corresponding to a null substitution
85 -- A string literal using normal Ada syntax
87 -- Any sequence of characters from the set
88 -- (letters, digits, period, underline)
90 -- Comment lines may also appear in the definitions file, starting with
91 -- the usual --, and comments may be added to the definitions lines.
93 -- The input text may contain preprocessor conditional inclusion lines,
94 -- and also general symbol substitution sequences.
96 -- The preprocessor conditional inclusion commands have the form
98 -- #if <expression> [then]
100 -- #elsif <expression> [then]
102 -- #elsif <expression> [then]
109 -- Where expression is defined by the following grammar :
110 -- expression ::= <symbol>
111 -- expression ::= <symbol> = "<value>"
112 -- expression ::= <symbol> = <symbol>
113 -- expression ::= <symbol> 'Defined
114 -- expression ::= not <expression>
115 -- expression ::= <expression> and <expression>
116 -- expression ::= <expression> or <expression>
117 -- expression ::= <expression> and then <expression>
118 -- expression ::= <expression> or else <expression>
119 -- expression ::= ( <expression> )
121 -- For these Boolean tests, the symbol must have either the value True or
122 -- False. If the value is True, then the corresponding lines are included,
123 -- and if the value is False, they are excluded. It is an error to
124 -- reference a symbol not defined in the symbol definitions file, or
125 -- to reference a symbol that has a value other than True or False.
127 -- The use of the not operator inverts the sense of this logical test, so
128 -- that the lines are included only if the symbol is not defined.
130 -- The THEN keyword is optional as shown
132 -- Spaces or tabs may appear between the # and the keyword. The keywords
133 -- and the symbols are case insensitive as in normal Ada code. Comments
134 -- may be used on a preprocessor line, but other than that, no other
135 -- tokens may appear on a preprocessor line.
137 -- Any number of #elsif clauses can be present, including none at all.
139 -- The #else is optional, as in Ada.
141 -- The # marking the start of a preprocessor line must be the first
142 -- non-blank character on the line, i.e. it must be preceded only by
143 -- spaces or horizontal tabs.
145 -- Symbol substitution is obtained by using the sequence
149 -- anywhere within a source line, except in a comment. The identifier
150 -- following the $ must match one of the symbols defined in the symbol
151 -- definition file, and the result is to substitute the value of the
152 -- symbol in place of $symbol in the output file.