← WebFortran Preprocessor
As of version 0.6, WebFortran's Command Line Interface includes a simple preprocessor similar to those provided by other Fortran and C compilers. Unlike some other preprocessors, this system will accept strings passed with either single or double quotes, similar to the Fortran language itself. For example, the following #define directives are equivalent:
#define MYNAME "Margaux"
#define MYNAME 'Margaux'
This structure allows the embedding of quotes within a string simply by using the opposite set:
#define QUOTATION '"Good morning," Henry said.'
Supported Directives
WebFortran only supports the following directives:
Directive | Description |
---|---|
#define LABEL [value] | Define LABEL in the preprocessor, optionally to the value passed |
#else | Paired with an #if, #ifdef, or #ifndef, perform processing using the opposite of the condition |
#endif | Paired with an #if, #ifdef, #ifndef, and/or #else, close the condition and proceed with processing based on any earlier conditions |
#error [message] | Immediately raise an error during preprocessing, printing the message if specified |
#if EXPRESSION | If EXPRESSION resolves as true, process the contents until an #else or #endif are encountered (See below for EXPRESSION details) |
#ifdef LABEL | If LABEL is defined, process the contents until an #else or #endif are encountered |
#ifndef LABEL | If LABEL is defined, do not process the contents until an #else or #endif are encountered |
#include "FILE" | Open the specified file at the filename FILE based on any compiler flags dictating search locations and include its contents in the current file, continuing with preprocessing said FILE's contents as well |
#undef LABEL | Undefine LABEL in the preprocessor |
Predefined Values
WebFortran, by default, defines the following:
Label | Description |
---|---|
__FILE__ | The current file name (without path) being preprocessed |
__GFORTRAN__ | Because WebFortran relies on a GNU Fortran backend, this label is defined, though not set to a sensible value |
__LINE__ | The current line number in the file being preprocessed |
__WEBFORTRAN__ | Indicates the WebFortran compiler is being used |
Expressions
The #if directive can resolve simple expressions revolving around "defined" state of macros. These expressions can combine logical operators and parentheses with the defined(LABEL) operation for more complex barriers. For example, to check if both __WEBFORTRAN__ and WINDOWS are defined, one would write:
#if defined(__WEBFORTRAN__) && defined(WINDOWS)
Because WebFortran is a Fortran compiler first and foremost, it will also accept Fortran-style logical operators:
#if defined(__WEBFORTRAN__) .and. defined(WINDOWS)
The following operators are supported:
Operator | Description |
---|---|
!, .not. | Logical NOT |
&&, .and. | Logical AND |
||, .or. | Logical OR |
true, .true. | Resolves to true in an expression, but nowhere else in the preprocessor |
false, .false. | Resolves to false in an expression, but nowhere else in the preprocessor |
At this time, WebFortran does not support any arithmetic, numeric comaprisons, or macro replacement within expressions.
Limitations
The WebFortran preprocessor will not follow Fortran INCLUDE statements when processing source files, though it does follow #include directives. The INCLUDE statement is part of the Fortran language, which is always processed after the preprocessor.
All preprocessing is handled locally before passing the processed source to the server's compiler. Users should therefore not assume that the entire GNU C preprocessor is available.
Functional macros, which would accept arguments and generate replacement code, are not supported at this time.
Any defined LABEL encountered during preprocessing that reside inside comments or strings are ignored.