Loading...
Searching...
No Matches
global.f90
Go to the documentation of this file.
1!> @file
2!! @defgroup group_global Global
3!! Central global configuration and shared state for the fpx Fortran preprocessor
4!! This module defines a single global instance `global` of type `global_settings`
5!! that holds all persistent, user-configurable state used across the entire preprocessing session:
6!!
7!! - `macros(:)` : Dynamic table of all defined macros (object-like and function-like)
8!! - `undef(:)` : List of symbols explicitly undefined via `#undef`
9!! - `includedir(:)` : User-specified include search directories for `#include <...>`
10!! - `expand_macros` : Master switch to enable/disable macro expansion (default: .true.)
11!! - `exclude_comments` : When .true., strip C-style /*...*/ and Fortran ! comments from output
12!!
13!! The design uses a single public variable `global` so that all fpx modules can access
14!! and modify the same configuration without passing arguments everywhere.
15!! This is safe in single-threaded use (typical for preprocessing) and allows easy
16!! customization from driver programs or interactive sessions.
17!! <h2 class="groupheader">Examples</h2>
18!!
19!! 1. Add custom include paths before preprocessing:
20!! @code{.f90}
21!!
22!! global%includedir = [ './include', '/usr/local/include/fortran', '../common' ]
23!! call preprocess('main.F90', 'main.f90')
24!! !#include <file.h> will search these directories
25!! @endcode
26!!
27!! 2. Predefine common macros (e.g. for conditional compilation):
28!! @code{.f90}
29!!
30!! call add(global%macros, macro('DEBUG', '1'))
31!! call add(global%macros, macro('MPI_VERSION', '3'))
32!! call add(global%macros, macro('USE_OPENMP', '1'))
33!!
34!! call preprocess('src/app.F90')
35!! !> Code can now use #ifdef DEBUG, #if MPI_VERSION >= 3, etc.
36!! @endcode
37!!
38!! 3. Disable macro expansion temporarily (pass-through mode):
39!! @code{.f90}
40!! global%expand_macros = .false. ! Only handle #include and conditionals
41!! call preprocess('raw_source.F90', 'clean.F90')
42!! ...
43!! @endcode
44!!
45!! 4. Strip all comments from final output:
46!! @code{.f90}
47!! global%exclude_comments = .true.
48!! call preprocess('messy.F90', 'clean_no_comments.f90')
49!! ...
50!! @endcode
51module fpx_global
52 use fpx_constants
53 use fpx_string
54 use fpx_logging
55 use fpx_macro
56
57 implicit none; private
58
59 !> Global preprocessor configuration and shared runtime state
60 !! All components of fpx read from and write to this single instance.
61 !! Users can safely modify its public components at any time.
62 !! <h2 class="groupheader">Examples</h2>
63 !! @code{.f90}
64 !! use fpx_global
65 !!
66 !! call add(global%macros, macro('__LFORTRAN__','1'))
67 !! call add(global%macros, macro('__VERSION__'))
68 !! call add(global%macros, macro('__LFORTRAN_MAJOR__'))
69 !! call add(global%macros, macro('__LFORTRAN_MINOR__'))
70 !! call add(global%macros, macro('__LFORTRAN_PATCHLEVEL__'))
71 !! @endcode
72 !! <h2 class="groupheader">Remarks</h2>
73 !! @par
74 !! The global settings are accessed through the global variable
75 !! @ref global
76 !! @ingroup group_global
77 type, public :: global_settings
78 private
79 type(macro), allocatable, public :: macros(:) !< List of global macros
80 type(string), allocatable, public :: undef(:) !< List of undefined macros
81 type(string), allocatable, public :: includedir(:) !< List of include directories
82 logical, public :: expand_macros = .true. !< Boolean controlling the macro expansion. The macros are expanded by default.
83 logical, public :: exlude_comments = .false. !< Boolean controlling the inclusion/exclusion of comments. The comments are kept by default.
84 logical, public :: implicit_continuation = .false. !< Boolean controlling implicit continuation line.
85 logical, public :: line_break = .false. !< Boolean controlling line break with double backslash.
86 logical, public :: extra_macros = .false. !< Boolean controlling extra (non-standard macro definitions: __FILENAME__, __TIMESTAMP__).
87 end type
88
89 !> @brief The single global instance used throughout fpx
90 !! Initialized automatically with sensible defaults values.
91 !! @ingroup group_global
92 type(global_settings), public :: global
93
94end module
type(global_settings), public global
The single global instance used throughout fpx Initialized automatically with sensible defaults value...
Definition global.f90:92
character(:) function, allocatable, public expand_macros(line, macros, stitch)
Core recursive macro expander (handles function-like, variadic, #, ##)
Definition macro.f90:309
Global preprocessor configuration and shared runtime state All components of fpx read from and write ...
Definition global.f90:77
Derived type representing a single preprocessor macro Extends string with macro-specific fields: rep...
Definition macro.f90:103
Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character ar...
Definition string.f90:107