17
17
module fpm_source_parsing
18
18
use fpm_error, only: error_t, file_parse_error, fatal_error, file_not_found_error
19
19
use fpm_strings, only: string_t, string_cat, len_trim, split, lower, str_ends_with, fnv_1a, &
20
- is_fortran_name, operator (.in .)
20
+ is_fortran_name, operator (.in .), operator (==)
21
21
use fpm_model, only: srcfile_t, &
22
22
FPM_UNIT_UNKNOWN, FPM_UNIT_PROGRAM, FPM_UNIT_MODULE, &
23
23
FPM_UNIT_SUBMODULE, FPM_UNIT_SUBPROGRAM, &
@@ -46,12 +46,14 @@ module fpm_source_parsing
46
46
! > Case-insensitive check if macro_name is in the macros list
47
47
logical function macro_in_list_ci (macro_name , macros )
48
48
character (* ), intent (in ) :: macro_name
49
- type (string_t), intent (in ) :: macros(:)
49
+ type (string_t), optional , intent (in ) :: macros(:)
50
50
integer :: i
51
51
52
52
macro_in_list_ci = .false.
53
+ if (.not. present (macros)) return
54
+
53
55
do i = 1 , size (macros)
54
- if (lower(trim ( macro_name)) == lower( trim ( macros(i) % s) )) then
56
+ if (string_t( lower(macro_name)) == macros(i)) then
55
57
macro_in_list_ci = .true.
56
58
return
57
59
end if
@@ -138,8 +140,6 @@ subroutine parse_cpp_condition(line, preprocess, is_active, macro_name)
138
140
return
139
141
endif
140
142
141
- is_active = .false.
142
-
143
143
! There are macros: test if active
144
144
if (index (line, ' #ifdef' ) == 1 ) then
145
145
! #ifdef MACRO
@@ -166,6 +166,9 @@ subroutine parse_cpp_condition(line, preprocess, is_active, macro_name)
166
166
else
167
167
is_active = macro_in_list_ci(macro_name, preprocess% macros)
168
168
end if
169
+ else
170
+ ! More complex condition
171
+ is_active = .false.
169
172
end if
170
173
else
171
174
! #if MACRO (simple macro check)
@@ -174,6 +177,8 @@ subroutine parse_cpp_condition(line, preprocess, is_active, macro_name)
174
177
macro_name = trim (adjustl (line(start_pos:end_pos)))
175
178
is_active = macro_in_list_ci(macro_name, preprocess% macros)
176
179
end if
180
+ else
181
+ is_active = .false.
177
182
end if
178
183
179
184
end subroutine parse_cpp_condition
0 commit comments