Widen Proc_Decl (R1214) for Fortran 2008 initial-proc-target#502
Open
perazz wants to merge 3 commits intostfc:masterfrom
Open
Widen Proc_Decl (R1214) for Fortran 2008 initial-proc-target#502perazz wants to merge 3 commits intostfc:masterfrom
perazz wants to merge 3 commits intostfc:masterfrom
Conversation
The Fortran 2003 rule R1214 only accepts null-init on the right-hand
side of `=>`:
R1214 proc-decl is procedure-entity-name [ => null-init ]
Fortran 2008 keeps the rule number but widens the body so that
proc-pointer-init can be either null-init or an initial-proc-target
(a procedure-name):
R1214 proc-decl is procedure-entity-name
[ => proc-pointer-init ]
R1216 proc-pointer-init is null-init
or initial-proc-target
R1217 initial-proc-target is procedure-name
(J3/10-007r1 §12.4.3.6; C1219 unchanged - `=>` requires the POINTER
attribute.)
Without an override, declarations such as
procedure(cb), pointer, nopass :: eval => dummy
raise FortranSyntaxError under std='f2008' even though gfortran
-std=f2008 accepts them.
Add an F2008 Proc_Decl class in Fortran2008/proc_decl_r1214.py that
subclasses the F2003 Proc_Decl and extends its match() to fall back
to an initial-proc-target (matched as a Name) when the null-init
branch fails. Register the new class in Fortran2008/__init__.py and
add a test module covering null-init regression, initial-proc-target
parsing (both the rule in isolation and inside a full module), and
an explicit check that the same initial-proc-target form is still
rejected under std='f2003'.
Replace the PR #XXX placeholder for the R1214 widening with the real PR number (stfc#502) now that the PR has been opened against stfc/fparser:master.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #502 +/- ##
==========================================
+ Coverage 92.21% 92.22% +0.01%
==========================================
Files 87 88 +1
Lines 13832 13853 +21
==========================================
+ Hits 12755 12776 +21
Misses 1077 1077 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adds a dedicated test exercising the if not string: return None guard in the F2008 Proc_Decl.match method, which was previously uncovered and blocked PR coverage checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Proc_Decl.match()insrc/fparser/two/Fortran2003.py(R1214) hardcodes the right-hand side of=>asNull_Init. That is correct for Fortran 2003 but too narrow for Fortran 2008: F2008 widened the R1214 ruleso the right-hand side can also be an
initial-proc-target(R1216) (a procedure-name).Fortran2008/has no override yet, so any declaration likeraises
FortranSyntaxErrorunderstd='f2008', even thoughgfortran -std=f2008compiles and runs it without complaint.Standard reference
From §12.4.3.6 of the Fortran 2008 standard (ISO/IEC 1539-1:2010), publicly available as J3 working document
10-007r1:
F2003 R1214 was
procedure-entity-name [ => null-init ]- same rule number, narrower body. C1219 is unchanged between standards.Change
Proc_Declinsrc/fparser/two/Fortran2008/proc_decl_r1214.py, subclassingFortran2003.Proc_Decl.match()calls the F2003 match first (which handlesnull-init), and on failure falls back toBinaryOpBase.match(Procedure_Entity_Name, "=>", Name, string)for the F2008initial-proc-targetbranch. The RHS is matched as a bareName, consistent with how fparser treats other name-bearing rules(a stricter implementation would introduce a dedicated
Initial_Proc_Targetclass enforcing C1220; this is a deliberate minimal-viable choice and can be tightened later without changing the tree shape).src/fparser/two/Fortran2008/__init__.pyalongside the existing R12xx entries.Tests
New module
src/fparser/two/tests/fortran2008/test_proc_decl_r1214.pywith 12 cases covering:null-initbranch (regression guard),initial-proc-targetbranch (parametrised over several names),NoMatchError,std='f2008',FortranSyntaxErrorcheck confirming the widened form is still rejected understd='f2003'(the F2003 grammar is unchanged).