diff --git a/src/main/python/fobis/ParsedFile.py b/src/main/python/fobis/ParsedFile.py index bb9a76e..9b84236 100644 --- a/src/main/python/fobis/ParsedFile.py +++ b/src/main/python/fobis/ParsedFile.py @@ -297,7 +297,7 @@ def sort_dependencies(self): self.pfile_dep_all.sort(key=operator.attrgetter('order'), reverse=True) return - def parse(self, inc, preprocessor='cpp'): + def parse(self, inc, preprocessor='cpp', preproc=''): """ Parse the file creating its the dependencies list and the list of modules names that self eventually contains. @@ -305,12 +305,34 @@ def parse(self, inc, preprocessor='cpp'): ---------- inc : list list of extensions of included files + preprocessor : str + preprocessor name + preproc : str + preprocessor flags """ self.module_names = [] self.submodule_names = [] self.dependencies = [] - ffile = openReader(self.name) - for line in ffile: + + if self.extension in ['.INC', '.F', '.FOR', '.FPP', '.F77', '.F90', '.F95', '.F03', '.F08']: + preprocessor_exist = False + for path in os.environ["PATH"].split(os.pathsep): + preprocessor_exist = os.path.exists(os.path.join(path, preprocessor)) + if preprocessor_exist: + break + if preprocessor_exist: + if preprocessor == 'cpp': + preprocessor += ' -C -w ' + elif preprocessor == 'fpp': + preprocessor += ' -w ' + source = str(check_output(preprocessor + ' ' + preproc + ' ' + self.name, shell=True, stderr=STDOUT, encoding='UTF-8')) + source = source.replace('\\n', '\n') + else: + source = str(openReader(self.name).read()) + else: + source = str(openReader(self.name).read()) + + for line in source.split('\n'): matching = re.match(__regex_program__, line) if matching: self.program = True @@ -335,30 +357,9 @@ def parse(self, inc, preprocessor='cpp'): if not re.match(__regex_mpifh__, line): dep = Dependency(dtype="include", name=matching.group('name')) self.dependencies.append(dep) - ffile.close() if self.module: self.doctest = Doctest() - - if self.extension in ['.INC', '.F', '.FOR', '.FPP', '.F77', '.F90', '.F95', '.F03', '.F08']: - preprocessor_exist = False - for path in os.environ["PATH"].split(os.pathsep): - preprocessor_exist = os.path.exists(os.path.join(path, preprocessor)) - if preprocessor_exist: - break - if preprocessor_exist: - if preprocessor == 'cpp': - preprocessor += ' -C -w ' - elif preprocessor == 'fpp': - preprocessor += ' -w ' - source = str(check_output(preprocessor + self.name, shell=True, stderr=STDOUT, encoding='UTF-8')) - source = source.replace('\\n', '\n') - else: - source = str(openReader(self.name).read()) - - else: - source = str(openReader(self.name).read()) - self.doctest.parse(source=source) self.doctest.make_volatile_programs() diff --git a/src/main/python/fobis/__pycache__/Compiler.cpython-310.pyc b/src/main/python/fobis/__pycache__/Compiler.cpython-310.pyc index 3a1bc68..7a3c614 100644 Binary files a/src/main/python/fobis/__pycache__/Compiler.cpython-310.pyc and b/src/main/python/fobis/__pycache__/Compiler.cpython-310.pyc differ diff --git a/src/main/python/fobis/__pycache__/ParsedFile.cpython-310.pyc b/src/main/python/fobis/__pycache__/ParsedFile.cpython-310.pyc index a7c552c..17cb355 100644 Binary files a/src/main/python/fobis/__pycache__/ParsedFile.cpython-310.pyc and b/src/main/python/fobis/__pycache__/ParsedFile.cpython-310.pyc differ diff --git a/src/main/python/fobis/__pycache__/cli_parser.cpython-310.pyc b/src/main/python/fobis/__pycache__/cli_parser.cpython-310.pyc index a075a5e..5c0f5ec 100644 Binary files a/src/main/python/fobis/__pycache__/cli_parser.cpython-310.pyc and b/src/main/python/fobis/__pycache__/cli_parser.cpython-310.pyc differ diff --git a/src/main/python/fobis/__pycache__/fobis.cpython-310.pyc b/src/main/python/fobis/__pycache__/fobis.cpython-310.pyc index b3a33f6..0fa0695 100644 Binary files a/src/main/python/fobis/__pycache__/fobis.cpython-310.pyc and b/src/main/python/fobis/__pycache__/fobis.cpython-310.pyc differ diff --git a/src/main/python/fobis/fobis.py b/src/main/python/fobis/fobis.py index 573d27c..6fd3d20 100644 --- a/src/main/python/fobis/fobis.py +++ b/src/main/python/fobis/fobis.py @@ -258,9 +258,9 @@ def parse_files(configuration, src_dir=None, is_doctest=False): all(exc not in os.path.dirname(filename) for exc in configuration.cliargs.exclude_dirs)): pfile = ParsedFile(name=os.path.join(src_dir, filename), is_doctest=is_doctest) if is_doctest: - pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor) + pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor, preproc=configuration.cliargs.preproc) else: - pfile.parse(inc=configuration.cliargs.inc) + pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc) pfiles.append(pfile) else: for root, _, files in os.walk(src_dir): @@ -271,9 +271,9 @@ def parse_files(configuration, src_dir=None, is_doctest=False): filen = os.path.join(root, filename) pfile = ParsedFile(name=filen, is_doctest=is_doctest) if is_doctest: - pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor) + pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor, preproc=configuration.cliargs.preproc) else: - pfile.parse(inc=configuration.cliargs.inc) + pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc) pfiles.append(pfile) return pfiles