Skip to content

Commit

Permalink
Frontend: Remove OFP symbol and use Frontend.OFP internally
Browse files Browse the repository at this point in the history
This should make it unavailable to all tests, but keep the basic
functionality intact.
  • Loading branch information
mlange05 committed Oct 17, 2024
1 parent dc50ef5 commit 0bdbe01
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion loki/frontend/ofp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from loki.frontend.source import extract_source, extract_source_from_range
from loki.frontend.preprocessing import sanitize_registry
from loki.frontend.util import OFP, sanitize_ir
from loki.frontend.util import sanitize_ir, Frontend

from loki import ir
from loki.ir import (
Expand All @@ -47,6 +47,9 @@
__all__ = ['HAVE_OFP', 'parse_ofp_file', 'parse_ofp_source', 'parse_ofp_ast']


OFP = Frontend.OFP


@Timer(logger=debug, text=lambda s: f'[Loki::OFP] Executed parse_ofp_file in {s:.2f}s')
@disk_cached(argname='filename', suffix='ofpast')
def parse_ofp_file(filename):
Expand Down
5 changes: 4 additions & 1 deletion loki/frontend/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
from loki.config import config
from loki.tools import as_tuple, gettempdir, filehash
from loki.ir import VariableDeclaration, Intrinsic, FindNodes
from loki.frontend.util import OMNI, OFP, FP, REGEX
from loki.frontend.util import OMNI, FP, REGEX, Frontend


__all__ = ['preprocess_cpp', 'sanitize_input', 'sanitize_registry', 'PPRule']


OFP = Frontend.OFP


def preprocess_cpp(source, filepath=None, includes=None, defines=None):
"""
Invoke an external C-preprocessor to sanitize input files.
Expand Down
9 changes: 4 additions & 5 deletions loki/frontend/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


__all__ = [
'Frontend', 'OFP', 'OMNI', 'FP', 'REGEX', 'available_frontends',
'Frontend', 'OMNI', 'FP', 'REGEX', 'available_frontends',
'read_file', 'InlineCommentTransformer',
'ClusterCommentTransformer', 'CombineMultilinePragmasTransformer',
'sanitize_ir'
Expand All @@ -50,7 +50,6 @@ def __str__(self):
return self.name.lower() # pylint: disable=no-member

OMNI = Frontend.OMNI
OFP = Frontend.OFP
FP = Frontend.FP
REGEX = Frontend.REGEX

Expand Down Expand Up @@ -113,7 +112,7 @@ def my_test(frontend):
# Build the list of parameters
params = []
for f in Frontend:
if f == OFP:
if f == Frontend.OFP:
continue # OFP is now deprecated!
if f in skip:
params += [pytest.param(f, marks=pytest.mark.skip(reason=skip[f]))]
Expand Down Expand Up @@ -383,10 +382,10 @@ def sanitize_ir(_ir, frontend, pp_registry=None, pp_info=None):
# Revert OMNI's array dimension expansion from `a(n)` => `arr(1:n)`
_ir = RangeIndexTransformer(invalidate_source=False).visit(_ir)

if frontend in (OMNI, OFP):
if frontend in (OMNI, Frontend.OFP):
_ir = inline_labels(_ir)

if frontend in (FP, OFP):
if frontend in (FP, Frontend.OFP):
_ir = CombineMultilinePragmasTransformer(inplace=True, invalidate_source=False).visit(_ir)
_ir = RemoveDuplicateVariableDeclarationsForExternalProcedures(inplace=True, invalidate_source=False).visit(_ir)

Expand Down
5 changes: 4 additions & 1 deletion loki/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from loki.backend.fgen import fgen
from loki.backend.cufgen import cufgen
from loki.frontend import (
Frontend, OMNI, OFP, FP, REGEX, sanitize_input, Source, read_file, preprocess_cpp,
Frontend, OMNI, FP, REGEX, sanitize_input, Source, read_file, preprocess_cpp,
parse_omni_source, parse_ofp_source, parse_fparser_source,
parse_omni_ast, parse_ofp_ast, parse_fparser_ast, parse_regex_source,
RegexParserClass
Expand All @@ -32,6 +32,9 @@
__all__ = ['Sourcefile']


OFP = Frontend.OFP


class Sourcefile:
"""
Class to handle and manipulate source files, storing :any:`Module` and
Expand Down

0 comments on commit 0bdbe01

Please sign in to comment.