Loading...
Searching...
No Matches
Define

Definition

Processing of define and undef preprocessor directives This module implements the core logic for handling macro definition and removal during preprocessing in the fpx Fortran preprocessor. It supports:

The routines are designed to be robust against malformed input and provide clear diagnostics when verbose = .true..

Examples

  1. Define simple object-like macros:
    #define PI 3.141592653589793
    #define DEBUG 1
    #define MAX_SIZE 1024
    ...
  2. Define function-like and variadic macros:
    #define SQR(x) ((x)*(x))
    #define LOG_MSG(level, ...) print *, '[LOG:', level, ']', __VA_ARGS__
    #define CONCAT(a,b) a ## _ ## b
    ...
  3. Undefine a macro:
    #undef DEBUG
    !> Subsequent #ifdef DEBUG will be false
  4. Using from a driver program:
    use fpx_global
    use fpx_logging, only: verbose
    verbose = .true.
    call preprocess('input.F90') ! Will show all macro definitions/undefs
    ...
    logical, public verbose
    Master switch for verbose diagnostic output Default value is .false. (quiet mode)....
    Definition logging.f90:56

Methods

◆ handle_define()

subroutine, public handle_define ( character(*), intent(in) line,
type(macro), dimension(:), intent(inout), allocatable macros,
character(*), intent(in) token )

Process a define directive and register or update a macro Parses the line after #define, distinguishes between object-like and function-like forms, handles variadic ..., extracts parameters correctly, and stores the macro in the active macro table. Existing macros are overwritten. Respects globalundef list – macros listed there are ignored.

Parameters
[in]lineFull source line containing the define
[in,out]macrosCurrent macro table (updated in-place)
[in]tokenUsually 'DEFINE' – keyword matched in uppercase

Remarks

Definition at line 76 of file define.f90.

◆ handle_undef()

subroutine, public handle_undef ( character(*), intent(in) line,
type(macro), dimension(:), intent(inout), allocatable macros,
character(*), intent(in) token )

Process a undef directive and remove a macro from the table Finds the named macro in the current table and removes it. Issues a warning if the macro was not previously defined.

Parameters
[in]lineFull source line containing the undef
[in,out]macrosCurrent macro table (updated in-place)
[in]tokenUsually 'UNDEF' – keyword matched in uppercase

Remarks

Definition at line 211 of file define.f90.