Skip to content

MAINT: Update END statements parsing for recent Fortran standards.#18415

Merged
mattip merged 1 commit intonumpy:masterfrom
pearu:gh-2763
Feb 15, 2021
Merged

MAINT: Update END statements parsing for recent Fortran standards.#18415
mattip merged 1 commit intonumpy:masterfrom
pearu:gh-2763

Conversation

@pearu
Copy link
Contributor

@pearu pearu commented Feb 15, 2021

Closes #2763

While f2py is able to recover from parsing unknown end statements, this update avoids triggering the recovery process.
So, this PR does not deserve a separate test as the constructs in the ifdefs do not change the f2py wrapping outcome.

@mattip
Copy link
Member

mattip commented Feb 15, 2021

It would be nice to add some tests that use the new keywords associate block critical enum team, even if to make sure the words are not mispelled. I don't understand why tests would not be needed.

@pearu
Copy link
Contributor Author

pearu commented Feb 15, 2021

It would be nice to add some tests that use the new keywords associate block critical enum team, even if to make sure the words are not mispelled. I don't understand why tests would not be needed.

The corresponding statements have no influence on f2py output, they are just ignored. Even when misspelled they are ignored but with a "Mismatch of blocks encountered" warning. Technically, f2py does not implement Fortran parser and so it does not have to be exact in details that it never uses. In fact, in this particular case, there is nothing to test: with or without this PR f2py produces a correctly working code. So, adding the corresponding tests would just add maintenance burden to numpy, waste CI resources, and slow down f2py development, IMHO.

Sometimes such tests would not be even possible when the Fortran compiler used for testing does not implement the features of the latest Fortran standard but f2py can be still used in wrapping such codes.

@mattip
Copy link
Member

mattip commented Feb 15, 2021

I am confused. If "with or without this PR f2py produces correctly working code", then why do we need it? The original issue starts with "f2py break with functions/subroutines containing associate construct." So does it break or not?

@pearu
Copy link
Contributor Author

pearu commented Feb 15, 2021

No, it does not break.

The PR is needed for updating a piece of f2py to newer Fortran standards that did not exist at the time of creating f2py. The PR is maintenance PR, not a new-feature or a bug-fix PR.

@mattip
Copy link
Member

mattip commented Feb 15, 2021

I guess this is to handle code like this (from here)

program associateTest

  implicit none
  integer :: a=1,b=1
  someName: associate( x => a*b )
    print *, x                ! yields: 1
    a=10
    print *, x                ! yields: 1
  end associate someName

end program associateTest

So should the regex also allow an optional name fragment after end associate?

@pearu
Copy link
Contributor Author

pearu commented Feb 15, 2021

Yes, the relevant regular expressions also allow optional names after end <blockname>, see

endifpattern = re.compile(

As said before, those end statements are ignored by f2py, see

elif pat[1] == 'endif':

but they are relevant for processing other end statements correctly.

@mattip mattip merged commit 0026112 into numpy:master Feb 15, 2021
@mattip
Copy link
Member

mattip commented Feb 15, 2021

Thanks @pearu

@pearu pearu deleted the gh-2763 branch February 16, 2021 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

f2py with "associate" <-> "end associate"

2 participants