Skip to content

Commit

Permalink
fix bug on module-dependency creation with preprocessing conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
szaghi committed Feb 24, 2024
1 parent 770f887 commit e779ab7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
49 changes: 25 additions & 24 deletions src/main/python/fobis/ParsedFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,42 @@ 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.
Parameters
----------
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
Expand All @@ -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()

Expand Down
Binary file modified src/main/python/fobis/__pycache__/Compiler.cpython-310.pyc
Binary file not shown.
Binary file modified src/main/python/fobis/__pycache__/ParsedFile.cpython-310.pyc
Binary file not shown.
Binary file modified src/main/python/fobis/__pycache__/cli_parser.cpython-310.pyc
Binary file not shown.
Binary file modified src/main/python/fobis/__pycache__/fobis.cpython-310.pyc
Binary file not shown.
8 changes: 4 additions & 4 deletions src/main/python/fobis/fobis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit e779ab7

Please sign in to comment.