Skip to content

Preprocessor directives causing syntax error #3038

Description

@JonElsey

When trying to parse ukca_mode_tracer_maps_mod, I get the following error.

Traceback (most recent call last):
  File "/home/jelsey/NG-ARCH/transformer/psyclone_ve/bin/psyclone", line 42, in <module>
    main(sys.argv[1:])
  File "/home/jelsey/NG-ARCH/cemac_ngarch_tools/psyclone/src/psyclone/generator.py", line 592, in main
    code_transformation_mode(input_file=args.filename,
  File "/home/jelsey/NG-ARCH/cemac_ngarch_tools/psyclone/src/psyclone/generator.py", line 772, in code_transformation_mode
    .psyir_from_file(input_file)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jelsey/NG-ARCH/cemac_ngarch_tools/psyclone/src/psyclone/psyir/frontend/fortran.py", line 255, in psyir_from_file
    parse_tree = self._parser(reader)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/jelsey/NG-ARCH/transformer/psyclone_ve/lib/python3.12/site-packages/fparser/two/Fortran2003.py", line 275, in __new__
    raise FortranSyntaxError(string, "")
fparser.two.utils.FortranSyntaxError: at line 175
>>>END DO\n

The code that it is tripping up on looks like:

! Construct the number and component mass index arrays
! by looping over all entries in the all_tracers array
DO i=1,n_tracers
! (Slow) Workaround for NAG Fortran vn7.0 internal compiler error.
! Fixed in vn7.1
#if defined(NAG_FORTRAN) && (NAG_FORTRAN == 7000000)
tracer_belongs = .FALSE.
DO j=1,nmodes
IF ( mode_names(j) == all_tracers_names(i)(1:7) ) THEN
tracer_belongs = .TRUE.
END IF
END DO   
IF ( tracer_belongs ) THEN
#else
IF ( ANY(mode_names(:) == all_tracers_names(i)(1:7)) ) THEN
#endif

<code> 

END DO    ! this is the line it detects the syntax error on

The code compiles fine, but PSyclone passthrough doesn't work.
I've set up a branch that refactors this bit of code (which now works fine), but I just wanted to flag it as something that PSyclone didn't know how to handle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No 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