Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend: Fix bug for multi-line pragmas and add short test #221

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loki/frontend/fparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2833,7 +2833,7 @@ def visit_Print_Stmt(self, o, **kwargs):
source=kwargs.get('source'), label=kwargs.get('label'))

# TODO: Deal with line-continuation pragmas!
_re_pragma = re.compile(r'^\s*\!\$(?P<keyword>\w+)\s+(?P<content>.*)', re.IGNORECASE)
_re_pragma = re.compile(r'^\s*\!\$(?P<keyword>\w+)\s*(?P<content>.*)', re.IGNORECASE)

def visit_Comment(self, o, **kwargs):
source = kwargs.get('source', None)
Expand Down
2 changes: 1 addition & 1 deletion loki/frontend/ofp.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def visit_case(self, o, **kwargs):
return as_tuple(value) or None, as_tuple(body)

# TODO: Deal with line-continuation pragmas!
_re_pragma = re.compile(r'^\s*\!\$(?P<keyword>\w+)\s+(?P<content>.*)', re.IGNORECASE)
_re_pragma = re.compile(r'^\s*\!\$(?P<keyword>\w+)\s*(?P<content>.*)', re.IGNORECASE)

def visit_comment(self, o, **kwargs):
match_pragma = self._re_pragma.search(kwargs['source'].string)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_frontends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# (C) Copyright 2018- ECMWF.
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

# pylint: disable=too-many-lines

"""
Verify correct frontend behaviour and correct parsing of certain Fortran
language features.
Expand Down Expand Up @@ -1498,3 +1507,33 @@ def test_frontend_empty_file(frontend, fcode):
source = Sourcefile.from_source(fcode, frontend=frontend)
assert isinstance(source.ir, Section)
assert not source.to_fortran().strip()


@pytest.mark.parametrize('frontend', available_frontends())
def test_pragma_line_continuation(frontend):
"""
Test that multi-line pragmas are parsed and dealt with correctly.
"""
fcode = """
SUBROUTINE TOTO(A,B)

IMPLICIT NONE
REAL, INTENT(IN) :: A
REAL, INTENT(INOUT) :: B

!$ACC PARALLEL LOOP GANG &
!$ACC& PRESENT(ZRDG_LCVQ,ZFLU_QSATS,ZRDG_CVGQ) &
!$ACC& PRIVATE (JBLK) &
!$ACC& VECTOR_LENGTH (YDCPG_OPTS%KLON)

END SUBROUTINE TOTO
"""
routine = Subroutine.from_source(fcode, frontend=frontend)

pragmas = FindNodes(Pragma).visit(routine.body)
assert len(pragmas) == 1
assert pragmas[0].keyword == 'ACC'
assert 'PARALLEL' in pragmas[0].content
assert 'PRESENT' in pragmas[0].content
assert 'PRIVATE' in pragmas[0].content
assert 'VECTOR_LENGTH' in pragmas[0].content
Loading