Loading...
Searching...
No Matches
diagnostics.f90
Go to the documentation of this file.
1!> @file
2!! @defgroup group_diagnostics Diagnostics
3!! Processing of #warning and #error preprocessor directives
4!! This module implements the core logic for handling messages (either as
5!! warning or errors).
6!!
7!! <h2 class="groupheader">Examples</h2>
8!!
9!! 1. Break preprocessing on error:
10!! @code{.f90}
11!! #ifdef __vax__
12!! #error "VAX not supported"
13!! #endif
14!! ...
15!! @endcode
16!!
17!! 2. Warn version mismatch:
18!! @code{.f90}
19!! #if __STDF__ > 1
20!! #warning "The version of the Fortran language is greater than 1"
21!! #endif
22!! ...
23!! @endcode
24module fpx_diagnostics
25 use, intrinsic :: iso_fortran_env, only: stdout => output_unit
26 use fpx_logging
27 use fpx_macro
28 use fpx_global
29 use fpx_string
30
31 implicit none; private
32
33 public :: handle_error, &
35
36contains
37
38 !> Process a #error directive. It causes the preprocessor to report a
39 !! fatal error that stops the preprocessor. The string forming the rest
40 !! of the line following ‘#error’ is printed in the standard error.
41 !!
42 !! @param[in] line Full source line containing the #define
43 !! @param[inout] macros Current macro table (updated in-place)
44 !! @param[in] token Usually 'DEFINE' – keyword matched in uppercase
45 !!
46 !! @b Remarks
47 !! @ingroup group_diagnostics
48 subroutine handle_error(line, macros, token)
49 character(*), intent(in) :: line
50 type(macro), allocatable, intent(inout) :: macros(:)
51 character(*), intent(in) :: token
52 !private
53 integer :: pos
54
55 pos = index(uppercase(line), token) + len(token)
56 error stop trim(adjustl(line(pos + 1:)))
57 end subroutine
58
59 !> Process a #warning directive. It causes the preprocessor to report a
60 !! warning that does not stop the preprocessor. The string forming the rest
61 !! of the line following ‘#warning’ is printed in the standard output.
62 !! @param[in] line Full source line containing the #undef
63 !! @param[inout] macros Current macro table (updated in-place)
64 !! @param[in] token Usually 'UNDEF' – keyword matched in uppercase
65 !!
66 !! @b Remarks
67 !! @ingroup group_diagnostics
68 subroutine handle_warning(line, macros, token)
69 character(*), intent(in) :: line
70 type(macro), allocatable, intent(inout) :: macros(:)
71 character(*), intent(in) :: token
72 !private
73 integer :: pos
74
75 pos = index(uppercase(line), token) + len(token)
76 write(stdout, '(A)') trim(adjustl(line(pos + 1:)))
77 end subroutine
78end module
subroutine, public handle_error(line, macros, token)
Process a error directive. It causes the preprocessor to report a fatal error that stops the preproce...
subroutine, public handle_warning(line, macros, token)
Process a warning directive. It causes the preprocessor to report a warning that does not stop the pr...
pure character(len_trim(str)) function, public uppercase(str)
Convert string to upper case (respects contents of quotes).
Definition string.f90:583
Return the length of a string.
Definition string.f90:130
Return the trimmed string.
Definition string.f90:146
Derived type representing a single preprocessor macro Extends string with macro-specific fields: rep...
Definition macro.f90:103