Skip to content

Commit

Permalink
fix bug on preprocessing, add missin include
Browse files Browse the repository at this point in the history
  • Loading branch information
szaghi committed Mar 11, 2024
1 parent e779ab7 commit 552be3a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
24 changes: 20 additions & 4 deletions src/main/python/fobis/ParsedFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def apply_styles(graph):
__str_kw_ieee_exceptions__ = r"[Ii][Ee][Ee][Ee]_[Ee][Xx][Cc][Ee][Pp][Tt][Ii][Oo][Nn][Ss]"
__str_kw_ieee_arithmetic__ = r"[Ii][Ee][Ee][Ee]_[Aa][Rr][Ii][Tt][Hh][Mm][Ee][Tt][Ii][Cc]"
__str_kw_ieee_features__ = r"[Ii][Ee][Ee][Ee]_[Ff][Ee][Aa][Tt][Uu][Rr][Ee][Ss]"
__str_kw_openacc__ = r"[Oo][Pp][Ee][Nn][Aa][Cc][Cc]"
__str_kw_omp_lib__ = r"[Oo][Mm][Pp]_[Ll][Ii][Bb]"
__str_kw_module__ = r"[Mm][Oo][Dd][Uu][Ll][Ee]"
__str_kw_submodule__ = r"[Ss][Uu][Bb][Mm][Oo][Dd][Uu][Ll][Ee]"
__str_kw_program__ = r"[Pp][Rr][Oo][Gg][Rr][Aa][Mm]"
Expand Down Expand Up @@ -157,6 +159,14 @@ def apply_styles(graph):
__str_kw_use__ + # keyword "use"
r"\s+" + __str_kw_ieee_features__ + # keyword intrinsic module ieee_features
r"(?P<mod_eol>(.*))")
__str_use_mod_openacc__ = (r"^(\s*)" + # eventual initial white spaces
__str_kw_use__ + # keyword "use"
r"\s+" + r"(.*)" + __str_kw_openacc__ + r".*" + # keyword intrinsic module openacc
r"(?P<mod_eol>(.*))")
__str_use_mod_omp_lib__ = (r"^(\s*)" + # eventual initial white spaces
__str_kw_use__ + # keyword "use"
r"\s+" + r"(.*)" + __str_kw_omp_lib__ + r".*" + # keyword intrinsic module omp_lib
r"(?P<mod_eol>(.*))")
__str_include__ = (r"^(\s*|\#)" + # eventual initial white spaces or "#" character
__str_kw_include__ + # keyword "include"
r"(\s+)" + # 1 or more white spaces
Expand Down Expand Up @@ -196,12 +206,16 @@ def apply_styles(graph):
__regex_use_mod_ieee_exceptions__ = re.compile(__str_use_mod_ieee_exceptions__)
__regex_use_mod_ieee_arithmetic__ = re.compile(__str_use_mod_ieee_arithmetic__)
__regex_use_mod_ieee_features__ = re.compile(__str_use_mod_ieee_features__)
__regex_use_mod_openacc__ = re.compile(__str_use_mod_openacc__)
__regex_use_mod_omp_lib__ = re.compile(__str_use_mod_omp_lib__)
__regex_use_intrinsic_modules__ = [__regex_use_mod_intrinsic__,
__regex_use_mod_iso_fortran_env__,
__regex_use_mod_iso_c_binding__,
__regex_use_mod_ieee_exceptions__,
__regex_use_mod_ieee_arithmetic__,
__regex_use_mod_ieee_features__]
__regex_use_mod_ieee_features__,
__regex_use_mod_openacc__,
__regex_use_mod_omp_lib__]
__regex_mpifh__ = re.compile(__str_mpifh__)

# alternative "open and read"... it should avoid encoding issues with python 2.X vs 3.X
Expand Down Expand Up @@ -297,7 +311,7 @@ def sort_dependencies(self):
self.pfile_dep_all.sort(key=operator.attrgetter('order'), reverse=True)
return

def parse(self, inc, preprocessor='cpp', preproc=''):
def parse(self, inc=['.INC', '.F', '.FOR', '.FPP', '.F77', '.F90', '.F95', '.F03', '.F08'], preprocessor='cpp', preproc='', include=''):
"""
Parse the file creating its the dependencies list and the list of modules names that self eventually contains.
Expand All @@ -309,12 +323,14 @@ def parse(self, inc, preprocessor='cpp', preproc=''):
preprocessor name
preproc : str
preprocessor flags
include : list
include directories
"""
self.module_names = []
self.submodule_names = []
self.dependencies = []

if self.extension in ['.INC', '.F', '.FOR', '.FPP', '.F77', '.F90', '.F95', '.F03', '.F08']:
if self.extension in inc:
preprocessor_exist = False
for path in os.environ["PATH"].split(os.pathsep):
preprocessor_exist = os.path.exists(os.path.join(path, preprocessor))
Expand All @@ -325,7 +341,7 @@ def parse(self, inc, preprocessor='cpp', preproc=''):
preprocessor += ' -C -w '
elif preprocessor == 'fpp':
preprocessor += ' -w '
source = str(check_output(preprocessor + ' ' + preproc + ' ' + self.name, shell=True, stderr=STDOUT, encoding='UTF-8'))
source = str(check_output(preprocessor + ' ' + preproc + ' ' + '-I'.join(include) + ' ' + self.name, shell=True, stderr=STDOUT, encoding='UTF-8'))
source = source.replace('\\n', '\n')
else:
source = str(openReader(self.name).read())
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__/Gcov.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, preproc=configuration.cliargs.preproc)
pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor, preproc=configuration.cliargs.preproc, include=configuration.cliargs.include)
else:
pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc)
pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc, include=configuration.cliargs.include)
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, preproc=configuration.cliargs.preproc)
pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor, preproc=configuration.cliargs.preproc, include=configuration.cliargs.include)
else:
pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc)
pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc, include=configuration.cliargs.include)
pfiles.append(pfile)
return pfiles

Expand Down

0 comments on commit 552be3a

Please sign in to comment.