diff --git a/changelog b/changelog index a2bb3d4635..844f8bed61 100644 --- a/changelog +++ b/changelog @@ -18,6 +18,9 @@ 6) PR #2820 for #2773. Adds support for the Vernier timing library. + 7) PR #2840 for #2839. Raise error in FortranReader if ignore_directives + is True but ignore_comments is True. + release 3.0.0 6th of December 2024 1) PR #2477 for #2463. Add support for Fortran Namelist statements. diff --git a/psyclone.pdf b/psyclone.pdf index 6f629ea05c..55cef3573e 100644 Binary files a/psyclone.pdf and b/psyclone.pdf differ diff --git a/src/psyclone/psyir/frontend/fortran.py b/src/psyclone/psyir/frontend/fortran.py index 481690b9dd..98285bbd6d 100644 --- a/src/psyclone/psyir/frontend/fortran.py +++ b/src/psyclone/psyir/frontend/fortran.py @@ -72,6 +72,9 @@ class FortranReader(): for more precise control it also accepts a list of module names. Defaults to False. + :raises ValueError: If ignore_directives is set to False but + ignore_comments is set to True. + ''' # Save parser object across instances to reduce the initialisation time _parser = None @@ -83,6 +86,11 @@ def __init__(self, free_form: bool = True, ignore_comments: bool = True, if not self._parser: self._parser = ParserFactory().create(std="f2008") self._free_form = free_form + if ignore_comments and not ignore_directives: + raise ValueError( + "Setting ignore_directives to False in the FortranReader will" + " only have an effect if ignore_comments is also set to False." + ) self._ignore_comments = ignore_comments self._processor = Fparser2Reader(ignore_directives, last_comments_as_codeblocks, diff --git a/src/psyclone/tests/psyir/frontend/fortran_test.py b/src/psyclone/tests/psyir/frontend/fortran_test.py index 9c81ae7905..e7c708c749 100644 --- a/src/psyclone/tests/psyir/frontend/fortran_test.py +++ b/src/psyclone/tests/psyir/frontend/fortran_test.py @@ -275,3 +275,12 @@ def test_fortran_psyir_from_file(fortran_reader, tmpdir_factory): assert node.preceding_comment == "Comment on assignment" else: assert node.preceding_comment == "" + + # Check that the following combination raises an error + with pytest.raises(ValueError) as err: + FortranReader(ignore_comments=True, ignore_directives=False) + msg = ( + "Setting ignore_directives to False in the FortranReader will" + " only have an effect if ignore_comments is also set to False." + ) + assert msg in str(err.value)