From 1b1695163da37e9a3f8894f83858dba6e735ebc9 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Thu, 1 Oct 2015 18:44:06 -0500 Subject: [PATCH] Manage include path for Fortran preproc --- loopy/frontend/fortran/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/loopy/frontend/fortran/__init__.py b/loopy/frontend/fortran/__init__.py index 1cd7aa6f3..f2bbb2882 100644 --- a/loopy/frontend/fortran/__init__.py +++ b/loopy/frontend/fortran/__init__.py @@ -25,7 +25,7 @@ THE SOFTWARE. from loopy.diagnostic import LoopyError -def c_preprocess(source, defines=None, filename="<floopy source>"): +def c_preprocess(source, defines=None, filename=None, include_paths=None): """ :arg source: a string, possibly containing C preprocessor constructs :arg defines: a list of strings as they might occur after a @@ -38,10 +38,22 @@ def c_preprocess(source, defines=None, filename="<floopy source>"): except ImportError: raise LoopyError("Using the C preprocessor requires PLY to be installed") + input_dirname = None + if filename is None: + filename = "<floopy source>" + else: + from os.path import dirname + input_dirname = dirname(filename) + lexer = lex.lex(cpp) from ply.cpp import Preprocessor p = Preprocessor(lexer) + if input_dirname is not None: + p.add_path(input_dirname) + if include_paths: + for inc_path in include_paths: + p.add_path(inc_path) if defines: for d in defines: -- GitLab