Skip to content

Parsing of preceding comment fails #475

@schreiberx

Description

@schreiberx

Using fparser with a preceding comment raises an error:

Reproducer:

FUNCTION tool_datosec(date)

        integer :: tool_datosec

        ! COMMENT
        CHARACTER(len=19),INTENT(in) :: date

END FUNCTION tool_datosec

Error message:

Traceback (most recent call last):
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 2477, in process_declarations
    tsym = self._process_decln(parent, parent.symbol_table,
                               node, visibility_map,
                               statics_list)
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 1756, in _process_decln
    base_type, _ = self._process_type_spec(scope, type_spec)
                   ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 1667, in _process_type_spec
    raise NotImplementedError(
        f"Length or kind attributes not supported on a character "
        f"variable: '{type_spec}'")
NotImplementedError: Length or kind attributes not supported on a character variable: 'CHARACTER(LEN = 19)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/bin/psyclone", line 42, in <module>
    main(sys.argv[1:])
    ~~~~^^^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/generator.py", line 592, in main
    code_transformation_mode(input_file=args.filename,
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
                             recipe_file=args.script,
                             ^^^^^^^^^^^^^^^^^^^^^^^^
                             output_file=args.o,
                             ^^^^^^^^^^^^^^^^^^^
                             line_length=args.limit)
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/generator.py", line 772, in code_transformation_mode
    .psyir_from_file(input_file)
     ~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fortran.py", line 269, in psyir_from_file
    psyir = self._processor.generate_psyir(parse_tree, filename)
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 1116, in generate_psyir
    self.process_nodes(node, [parse_tree])
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 2872, in process_nodes
    psy_child = self._create_child(child, parent)
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 2966, in _create_child
    return handler(child, parent)
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 5689, in _program_handler
    self.process_nodes(file_container, node.children)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 2872, in process_nodes
    psy_child = self._create_child(child, parent)
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 2966, in _create_child
    return handler(child, parent)
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 5431, in _subroutine_handler
    self.process_declarations(routine, decl_list, arg_list)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/martin/workspace/poseidon_REPOS/local_software/env_default_gcc/python_venv/lib/python3.13/site-packages/psyclone/psyir/frontend/fparser2.py", line 2531, in process_declarations
    = '\n'.join(preceding_comments)
      ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, Comment found

Removing ! COMMENT doesn't raise the error anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions