summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-10-06 04:57:17 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-10-06 04:57:17 +0000
commit2c406001966f201617c463633dc1ab67d396d0c0 (patch)
tree43c026ed7f23302a040895da8276db38fa4a3df9
parent30cdb1624fe86b26b480b4c262ae1c8a24ab35d8 (diff)
downloadnumpy-2c406001966f201617c463633dc1ab67d396d0c0.tar.gz
F2PY G3: fixed bugs, started adding features.
-rw-r--r--numpy/f2py/lib/main.py8
-rw-r--r--numpy/f2py/lib/parser/base_classes.py37
-rw-r--r--numpy/f2py/lib/parser/typedecl_statements.py17
-rw-r--r--numpy/f2py/lib/py_wrap_subprogram.py7
4 files changed, 55 insertions, 14 deletions
diff --git a/numpy/f2py/lib/main.py b/numpy/f2py/lib/main.py
index 66a4ac049..fc265ae32 100644
--- a/numpy/f2py/lib/main.py
+++ b/numpy/f2py/lib/main.py
@@ -131,7 +131,7 @@ def dump_signature(sys_argv):
only_names = []
skip_names = []
options = []
- for word in sys_argv[1:]:
+ for word in sys_argv:
if word=='': pass
elif word=='only:': flag = 'only'
elif word=='skip:': flag = 'skip'
@@ -146,7 +146,7 @@ def dump_signature(sys_argv):
output_stream.write('''! -*- f90 -*-
! Note: the context of this file is case sensitive.
''')
- output_stream.write('PYTHON MODULE %s\n' % (module_name))
+ output_stream.write('PYTHON MODULE %s\n' % (modulename))
output_stream.write(' INTERFACE\n\n')
for filename in file_names:
if not os.path.isfile(filename):
@@ -154,6 +154,8 @@ def dump_signature(sys_argv):
continue
sys.stderr.write('Parsing %r..\n' % (filename))
block = parse(filename)
+ if block is None:
+ sys.exit(1)
output_stream.write('! File: %s, source mode = %r\n' % (filename, block.reader.mode))
if block.content and isinstance(block.content[0],PythonModule):
for subblock in block.content[0].content[0].content:
@@ -163,7 +165,7 @@ def dump_signature(sys_argv):
else:
output_stream.write(block.topyf(' ')+'\n')
output_stream.write(' END INTERFACE\n')
- output_stream.write('END PYTHON MODULE %s\n' % (module_name))
+ output_stream.write('END PYTHON MODULE %s\n' % (modulename))
if signature_output not in ['stdout','stderr']:
output_stream.close()
diff --git a/numpy/f2py/lib/parser/base_classes.py b/numpy/f2py/lib/parser/base_classes.py
index 76a26b666..e79584ca5 100644
--- a/numpy/f2py/lib/parser/base_classes.py
+++ b/numpy/f2py/lib/parser/base_classes.py
@@ -229,6 +229,39 @@ class Variable:
'POINTER', 'PROTECTED', 'SAVE', 'TARGET', 'VALUE',
'VOLATILE', 'REQUIRED']
+ def is_intent_in(self):
+ if not self.intent: return True
+ if 'HIDE' in self.intent: return False
+ if 'INPLACE' in self.intent: return False
+ if 'IN' in self.intent: return True
+ if 'OUT' in self.intent: return False
+ if 'INOUT' in self.intent: return False
+ if 'OUTIN' in self.intent: return False
+ return True
+
+ def is_intent_inout(self):
+ if 'INOUT' in self.intent:
+ if 'IN' in self.intent or 'HIDE' in self.intent or 'INPLACE' in self.intent:
+ self.warning('INOUT ignored in INPUT(%s)' % (', '.join(self.intent)))
+ return False
+ return True
+ return False
+
+ def is_intent_hide(self):
+ if 'HIDE' in self.intent: return True
+ if 'OUT' in self.intent:
+ return 'IN' not in self.intent and 'INPLACE' not in self.intent and 'INOUT' not in self.intent
+ return False
+
+ def is_intent_inplace(self): return 'INPLACE' in self.intent
+ def is_intent_out(self): return 'OUT' in self.intent
+ def is_intent_c(self): return 'C' in self.intent
+ def is_intent_cache(self): return 'CACHE' in self.intent
+ def is_intent_copy(self): return 'COPY' in self.intent
+ def is_intent_overwrite(self): return 'OVERWRITE' in self.intent
+ def is_intent_callback(self): return 'CALLBACK' in self.intent
+ def is_intent_aux(self): return 'AUX' in self.intent
+
def is_private(self):
if 'PUBLIC' in self.attributes: return False
if 'PRIVATE' in self.attributes: return True
@@ -242,8 +275,8 @@ class Variable:
def is_external(self): return 'EXTERNAL' in self.attributes
def is_intrinsic(self): return 'INTRINSIC' in self.attributes
def is_parameter(self): return 'PARAMETER' in self.attributes
- def is_optional(self): return 'OPTIONAL' in self.attributes
- def is_required(self): return 'REQUIRED' in self.attributes
+ def is_optional(self): return 'OPTIONAL' in self.attributes and 'REQUIRED' not in self.attributes and not self.is_intent_hide()
+ def is_required(self): return self.is_optional() and not self.is_intent_hide()
def is_pointer(self): return 'POINTER' in self.attributes
def is_array(self): return not not (self.bounds or self.dimension)
diff --git a/numpy/f2py/lib/parser/typedecl_statements.py b/numpy/f2py/lib/parser/typedecl_statements.py
index d656dafbf..7e5a23ba5 100644
--- a/numpy/f2py/lib/parser/typedecl_statements.py
+++ b/numpy/f2py/lib/parser/typedecl_statements.py
@@ -512,12 +512,13 @@ class Implicit(Statement):
for spec in split_comma(item[i+1:-1].strip(), self.item):
if '-' in spec:
s,e = spec.lower().split('-')
- assert s in self.letters and e in self.letters
+ s = s.strip()
+ e = e.strip()
+ assert s in self.letters and e in self.letters,`s,e`
else:
- e = s = spec.lower()
- assert s in self.letters
+ e = s = spec.lower().strip()
+ assert s in self.letters,`s,e`
specs.append((s,e))
- self.specs = specs
tspec = item[:i].rstrip()
stmt = None
for cls in declaration_type_spec:
@@ -557,10 +558,10 @@ class Implicit(Statement):
self.warning('overriding previously set IMPLICIT NONE')
self.parent.a.implicit_rules = implicit_rules = {}
for stmt,specs in self.items:
- s,e = specs
- for l in string.lowercase[string.lowercase.index(s.lower()):\
- string.lowercase.index(e.lower())+1]:
- implicit_rules[l] = stmt
+ for s,e in specs:
+ for l in string.lowercase[string.lowercase.index(s.lower()):\
+ string.lowercase.index(e.lower())+1]:
+ implicit_rules[l] = stmt
return
intrinsic_type_spec = [ \
diff --git a/numpy/f2py/lib/py_wrap_subprogram.py b/numpy/f2py/lib/py_wrap_subprogram.py
index 3044b5a6b..32853512d 100644
--- a/numpy/f2py/lib/py_wrap_subprogram.py
+++ b/numpy/f2py/lib/py_wrap_subprogram.py
@@ -41,7 +41,7 @@ static PyObject* %(cname)s(PyObject *capi_self, PyObject *capi_args, PyObject *c
if (f2py_success) {
%(pyobjfrom_list)s
capi_buildvalue = Py_BuildValue("%(return_format_elist)s"
- %(return_obj_list)s);
+ %(return_obj_clist)s);
%(clean_pyobjfrom_list)s
}
%(clean_call_list)s
@@ -92,6 +92,9 @@ static PyObject* %(cname)s(PyObject *capi_self, PyObject *capi_args, PyObject *c
args_f.append('&'+argname)
else:
args_f.append(argname)
+ if var.is_intent_out(): # and is_scalar
+ self.return_format_list.append('O&')
+ self.return_obj_list.append('\npyobj_from_%s, &%s' % (ctype, argname))
WrapperCPPMacro(parent, 'F_FUNC')
self.call_list.append('%s_f(%s);' % (name,', '.join(args_f)))
@@ -99,6 +102,8 @@ static PyObject* %(cname)s(PyObject *capi_self, PyObject *capi_args, PyObject *c
self.clean_pyobjfrom_list.reverse()
self.clean_call_list.reverse()
self.clean_frompyobj_list.reverse()
+
if self.return_obj_list: self.return_obj_list.insert(0,'')
+
parent.apply_templates(self)
return