Skip to content

Commit 23899f2

Browse files
committed
fix elif preprocessing, I believe
1 parent 54978e6 commit 23899f2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/fpm_source_parsing.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,33 @@ subroutine parse_cpp_condition(lower_line, line, preprocess, is_active, macro_na
191191
macro_name = trim(adjustl(line(start_pos:end_pos)))
192192
is_active = macro_in_list(macro_name, preprocess%macros)
193193
end if
194+
elseif (index(lower_line, '#elif') == 1) then
195+
! #elif defined(MACRO) or #elif !defined(MACRO)
196+
if (index(lower_line, 'defined(') > 0) then
197+
start_pos = index(lower_line, 'defined(') + 8
198+
end_pos = index(lower_line(start_pos:), ')') - 1
199+
200+
start_pos = start_pos + heading_blanks
201+
end_pos = end_pos + heading_blanks
202+
203+
if (end_pos > 0) then
204+
macro_name = line(start_pos:start_pos + end_pos - 1)
205+
if (index(lower_line, '!defined(') > 0) then
206+
is_active = .not. macro_in_list(macro_name, preprocess%macros)
207+
else
208+
is_active = macro_in_list(macro_name, preprocess%macros)
209+
end if
210+
else
211+
is_active = .false.
212+
macro_name = ""
213+
end if
214+
else
215+
! simple form: #elif MACRO
216+
start_pos = 6 + heading_blanks ! skip "#elif "
217+
end_pos = len_trim(lower_line) + heading_blanks
218+
macro_name = trim(adjustl(line(start_pos:end_pos)))
219+
is_active = macro_in_list(macro_name, preprocess%macros)
220+
end if
194221
else
195222
is_active = .false.
196223
end if

0 commit comments

Comments
 (0)