Skip to content

Commit 24028c3

Browse files
marshallwardadcroft
authored andcommitted
makedep: support empty macros and defines
Makedep preprocessor parsing assumed define macros of the form `#define macro(X) some-macro` but did not support empty macros of the form `#define macro(X)`. Preprocessor flag macros were assumed to be of the form `-DMACRO=VALUE`, and did not support empty macros `-DMACRO`. This patch addresses both issues.
1 parent d3073f1 commit 24028c3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

ac/makedep

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ def scan_fortran_file(src_file, defines=None):
389389

390390
cpp_defines = defines if defines is not None else []
391391

392-
cpp_macros = dict([t.split('=') for t in cpp_defines])
392+
cpp_macros = dict(
393+
[t.split('=') if '=' in t else (t, None) for t in cpp_defines]
394+
)
393395
cpp_group_stack = []
394396

395397
with io.open(src_file, 'r', errors='replace') as file:
@@ -454,13 +456,14 @@ def scan_fortran_file(src_file, defines=None):
454456
# Activate a new macro (ignoring the value)
455457
match = re_cpp_define.match(line)
456458
if match:
459+
# TODO: Tokenize this, don't hunt for `(` in `macro`.
457460
tokens = line.strip()[1:].split(maxsplit=2)
458461
macro = tokens[1]
459462
value = tokens[2] if tokens[2:] else None
460463
if '(' in macro:
461464
# TODO: Actual handling of function macros
462465
macro, arg = macro.split('(', maxsplit=1)
463-
value = '(' + arg + value
466+
value = '(' + arg + value if value else '(' + arg
464467
cpp_macros[macro] = value
465468

466469
# Deactivate a macro

0 commit comments

Comments
 (0)