Frank Heckenbach wrote:
> GPC currently uses a stand-alone preprocessor (gpcpp) that is
> derived from the C preprocessor and shares many of its features.
>
> I plan to integrate it into the compiler which would follow gcc's
> example (not so important, though), maybe make it a little faster
> (not very much, I guess, since preprocessing in general doesn't take
> very long), solve some problems (e.g., the `--needed-option'
> ugliness, mostly on MIPS) and allow for further improvements.
>
> In the same process, I'd like to change some of the more obscure
> aspects, thereby hopefully making the code much simpler and even
> more powerful. This will not affect the BPish features of the
> preprocessor (`{$ifdef}', `{$ifopt}' and `{$i ...}' (include)), and
> the Pascal standards don't have a preprocessor, anyway, so I think
> there are no compatibility concerns (except for
> backward-compatibility to existing GPC versions). I think most the
> features discussed below are known to few people at all and not used
> much.
Well, as much as I welcome Frank's suggestions for the preprocessor,
there really are compatibilty-concerns. CodeWarrior Pascal has
integrated preprocessor support, similar to what Frank suggests. I have
included relevant parts of the CodeWarrior Pascal Compilers Reference
in the text below.
Regards,
Adriaan van Os
---------------
Using Compiler Directives
<taken from the CodeWarrior® Pascal Compilers Reference>
Every compiler directive must be enclosed within comment delimit-
ers ({ and }, or (* and *)) and begins with a dollar sign ($). Only
one directive may be within each pair of comment delimiters.
CodeWarrior Pascal lets you compile sections of your source text
conditionally by means of the $IFC, $ELSEC, and $ENDC and associ-
ated directives. The $IFC directive is controlled by the value of a
compile-time expression. You set such an expression using $SETC.
Sections of source code controlled by these directives may be
nested. The rules covering such nesting are the same as the rules for
IF statements. See the Pascal Language Reference for more informa-
tion about IF statements.
You can form compile-time expressions out of compile-time variables
or constants of type INTEGER or BOOLEAN. The final value of the ex-
pression that controls a $IFC directive must be BOOLEAN. You can
use all the Pascal operators in compile-time expressions except IN
and @. If you use the operator /, the compiler will automatically
change it to DIV.
$DEFINE
{$DEFINE id }
Defines an identifier that may be tested and undefined with other
directives.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
See also $IFDEF, $ELSE, $ENDIF.
$DEFINEC
{$DEFINEC id}
{$DEFINEC id definition}
{$DEFINEC id ( parameters )definition
Defines an item, id. The $DEFINEC directive substitutes every occur-
rence of id in the source code with its definition, definition. The
iden-
tifier, id, is not substituted when it appears in between comment de-
limiters or a string literal.
The definition part of a $DEFINEC directive can be any keyword,
constant value, or statement that is legal in CodeWarrior Pascal.
Multiple statements in the definition must be separated by semi-co-
lons (;).
The item id may have the same name of an already-declared proce-
dure or function if id and the routine don't have the same number of
parameters.
If id is defined with parameters, every occurrence of a parameter is
replace with the corresponding items in id's definition before id is
substituted. Parameters must be enclosed in parentheses in the
$DEFINE directive.
Items defined in the INTERFACE part of a unit are accessible by the
units or the program that use the unit. Items defined in the
IMPLEMENTATION
part of a unit are only accessible within the unit.
An item defined without a definition and without parameters is still
defined but has an empty definition. To remove the definition of an
item defined with $DEFINEC, use the $UNDEFC directive.
Listing 4.2 lists examples of using the $DEFINEC directive.
Listing 4.2 $DEFINEC examples
PROGRAM DefineExamples;
{$DEFINEC EraseMe}
{$DEFINEC two 2}
{$DEFINEC PRINT(a) WriteLn(a);}
begin
WriteLn(two);
EraseMe;
PRINT('Hello, world!');
end.
$ELIF
{$ELIF comp-expr}
This directive is equivalent to the $ELIFC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$ELIFC
{$ELIFC comp-expr}
Marks the beginning of source text that is compiled only if the value
of the comp-expr controlling its corresponding $IFC or $IFNOTC di-
rective is false and its own comp-expr expression is true.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
See also $IFC, $ENDC, $SETC.
$ELSE
{$ELSE}
This directive is equivalent to the $ELSEC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$ELSEC
{$ELSEC}
Marks the beginning of source text that is compiled only if the value
of the comp-expr controlling its corresponding $IFC or $IFNOTC di-
rective is false.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
See also $IFC, $ELIFC, $ENDC, $SETC.
$ENDIF
{$ENDIF}
This directive is equivalent to the $ENDC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$ENDC
{$ENDC}
The $ENDC directive marks the end of a section of conditionally
compiled source text, matching a $IFC or $IFNOTC directive.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
See also: $IFC, $IFNOTC, $ELSEC, $SETC.
$ERROR
{$ERROR comment}
This directive is equivalent to the $ERRORC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$ERRORC
{$ERRORC comment}
Forces a compiler error. A comment, comment, may optionally fol-
low this directive.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
$IF
{$IF comp-expr}
{$IF OPTION(option-name) }
{$IF OPTION option-name }
This directive is equivalent to the {$IFC comp-expr} form of the
$IFC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
See also $IFDEF, $ELSE, $ELIF, $ENDIF.
$IFC
{$IFC comp-expr}
{$IFC DEFINED name}
{$IFC OPTION(option-name) }
{$IFC OPTION option-name }
Compiles subsequent source code until the next $ELSEC or $ENDC
directive, only if the boolean value of comp-expr is true.
You may also write this directive in the form {$IFC DEFINED
name}. This will act like {$IFC false} if name has not yet been de-
clared with a $SETC directive; otherwise, it will act like {$IFC
true}.
You can also write this directive {$IFC OPTION( option-name} to
test the current setting of compiler directives. For example, {$IFC
OPTION (PROF)} acts like {$IFC true} if {$PROF+} had been
specified prior to the $IFC.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
See also $IFNOTC, $ELIFC, $ELSEC, $ENDC, $SETC, $DEFINEC,
$IFDEF
{$IFDEF id}
This directive is equivalent to the {$IFC DEFINED id} form of the
$IFC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
See also $DEFINE, $UNDEF, $IFNDEF, $IF.
$IFOPT
{$IFOPT option-name}
This directive is equivalent to the
$IF OPTION(option-name)
form of the $IF directive.
See also $IF, $ELSE, $ELIF, $ENDIF, Checking Options on
page 98 .
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$IFNDEF
{$IFDEF id }
This directive is equivalent to the {$IFNOTC DEFINED id} form of
the $IFNOTC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
See also $IFDEF.
$IFNOTC
{$IFNOTC DEFINED name}
Compiles subsequent source code until the next $ELSEC or $ENDC
directive, only if the boolean value of comp-expr is true.
This directive will act like {$IFC true} if name has not yet been
declared with a $SETC directive; otherwise, it will act like {$IFC
false}.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
See also: $ELSEC, $ENDC, $IFC, $SETC, $DEFINEC.
$MACRO
{$MACRO id}
{$MACRO id definition}
{$MACRO id ( parameters )definition
This directive is equivalent to the $DEFINEC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$PRAGMA
{$PRAGMA pragma state}
This directive is equivalent to the $PRAGMAC directive.
This is a Turbo Pascal-compatible directive. It may not be used in
the same source code file as other CodeWarrior-compatible direc-
tives.
$PRAGMAC
{$PRAGMA pragma state}
Sets the state of a pragma. See Pragmas on page 60 for more infor-
mation on using pragmas to control how source code is translated
into object code.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
$SETC
{$SETC id := comp-expr}
Declares a compile-time variable named id and assigns it the value
comp-expr.
This directive may not be used with Turbo Pascal-compatible direc-
tives.
See also: $IFC, $ELSEC, $ENDC.
$UNDEFC
{$UNDEFC id}
Undefines an identifier that was defined with the $DEFINEC direc-
tive. Undefining a previously defined item tells the compiler not to
substitute subsequent occurrences of id with its definition.
Use this directive with the $IFC and $IFNOTC directives to control
the compilation of source code.
This is a CodeWarrior Pascal-compatible directive. It may not be
used in the same source code file as other Turbo-compatible direc-
tives.
See also $DEFINEC, $IFC, $IFNOTC.
---------------