summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2021-03-29 17:58:41 +0300
committerPearu Peterson <pearu.peterson@gmail.com>2021-03-31 12:01:49 +0300
commitff3cec0788fb0635b7d39b7f19949cd17c2dc584 (patch)
treef946f9d14706b5c7e2216007a0f6d649a1d55e07
parentfb60eb72d65b3f26509231c0eb63de9fa35491d4 (diff)
downloadnumpy-ff3cec0788fb0635b7d39b7f19949cd17c2dc584.tar.gz
ENH: Support parsing Fortran abstract interface blocks.
-rwxr-xr-xnumpy/f2py/crackfortran.py17
-rw-r--r--numpy/f2py/f90mod_rules.py2
-rwxr-xr-xnumpy/f2py/rules.py2
3 files changed, 12 insertions, 9 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 660cdd206..eb61aa2f2 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -43,7 +43,7 @@ Usage:
'implicit','externals','interfaced','common','sortvars',
'commonvars','note']}
B['block'] = 'interface' | 'function' | 'subroutine' | 'module' |
- 'program' | 'block data' | 'type' | 'pythonmodule'
+ 'program' | 'block data' | 'type' | 'pythonmodule' | 'abstract interface'
B['body'] --- list containing `subblocks' with the same structure as `blocks'
B['parent_block'] --- dictionary of a parent block:
C['body'][<index>]['parent_block'] is C
@@ -138,6 +138,7 @@ TODO:
The above may be solved by creating appropriate preprocessor program, for example.
"""
+import io
import sys
import string
import fileinput
@@ -567,7 +568,7 @@ groupbegins77 = r'program|block\s*data'
beginpattern77 = re.compile(
beforethisafter % ('', groupbegins77, groupbegins77, '.*'), re.I), 'begin'
groupbegins90 = groupbegins77 + \
- r'|module(?!\s*procedure)|python\s*module|interface|type(?!\s*\()'
+ r'|module(?!\s*procedure)|python\s*module|(abstract|)\s*interface|type(?!\s*\()'
beginpattern90 = re.compile(
beforethisafter % ('', groupbegins90, groupbegins90, '.*'), re.I), 'begin'
groupends = (r'end|endprogram|endblockdata|endmodule|endpythonmodule|'
@@ -941,15 +942,17 @@ def analyzeline(m, case, line):
block = block.lower()
if re.match(r'block\s*data', block, re.I):
block = 'block data'
- if re.match(r'python\s*module', block, re.I):
+ elif re.match(r'python\s*module', block, re.I):
block = 'python module'
+ elif re.match(r'abstract\s*interface', block, re.I):
+ block = 'abstract interface'
name, args, result, bind = _resolvenameargspattern(m.group('after'))
if name is None:
if block == 'block data':
name = '_BLOCK_DATA_'
else:
name = ''
- if block not in ['interface', 'block data']:
+ if block not in ['interface', 'block data', 'abstract interface']:
outmess('analyzeline: No name/args pattern found for line.\n')
previous_context = (block, name, groupcounter)
@@ -983,7 +986,7 @@ def analyzeline(m, case, line):
if f77modulename and neededmodule == -1 and groupcounter <= 1:
neededmodule = groupcounter + 2
needmodule = 1
- if block != 'interface':
+ if block not in ['interface', 'abstract interface']:
needinterface = 1
# Create new block(s)
groupcounter = groupcounter + 1
@@ -1023,7 +1026,7 @@ def analyzeline(m, case, line):
groupname[groupcounter] = block
groupcache[groupcounter]['block'] = block
if not name:
- name = 'unknown_' + block
+ name = 'unknown_' + block.replace(' ', '_')
groupcache[groupcounter]['prefix'] = m.group('before')
groupcache[groupcounter]['name'] = rmbadname1(name)
groupcache[groupcounter]['result'] = result
@@ -2088,7 +2091,7 @@ def analyzebody(block, args, tab=''):
else:
as_ = args
b = postcrack(b, as_, tab=tab + '\t')
- if b['block'] == 'interface' and not b['body']:
+ if b['block'] in ['interface', 'abstract interface'] and not b['body']:
if 'f2pyenhancements' not in b:
continue
if b['block'].replace(' ', '') == 'pythonmodule':
diff --git a/numpy/f2py/f90mod_rules.py b/numpy/f2py/f90mod_rules.py
index 122fa8939..e359731ac 100644
--- a/numpy/f2py/f90mod_rules.py
+++ b/numpy/f2py/f90mod_rules.py
@@ -192,7 +192,7 @@ def buildhooks(pymod):
if hasbody(m):
for b in m['body']:
if not isroutine(b):
- print('Skipping', b['block'], b['name'])
+ outmess(f"f90mod_rules.buildhooks: skipping {b['block']} {b['name']}\n")
continue
modobjs.append('%s()' % (b['name']))
b['modulename'] = m['name']
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py
index b9cbc5487..63e47baa2 100755
--- a/numpy/f2py/rules.py
+++ b/numpy/f2py/rules.py
@@ -1163,7 +1163,7 @@ def buildmodule(m, um):
for n in m['interfaced']:
nb = None
for bi in m['body']:
- if not bi['block'] == 'interface':
+ if bi['block'] not in ['interface', 'abstract interface']:
errmess('buildmodule: Expected interface block. Skipping.\n')
continue
for b in bi['body']: