[Numpy-svn] r3267 - in trunk/numpy/f2py/lib: . parser

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Oct 6 00:57:24 EDT 2006


Author: pearu
Date: 2006-10-05 23:57:17 -0500 (Thu, 05 Oct 2006)
New Revision: 3267

Modified:
   trunk/numpy/f2py/lib/main.py
   trunk/numpy/f2py/lib/parser/base_classes.py
   trunk/numpy/f2py/lib/parser/typedecl_statements.py
   trunk/numpy/f2py/lib/py_wrap_subprogram.py
Log:
F2PY G3: fixed bugs, started adding features.

Modified: trunk/numpy/f2py/lib/main.py
===================================================================
--- trunk/numpy/f2py/lib/main.py	2006-10-05 23:36:47 UTC (rev 3266)
+++ trunk/numpy/f2py/lib/main.py	2006-10-06 04:57:17 UTC (rev 3267)
@@ -131,7 +131,7 @@
     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 @@
     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 @@
             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 @@
         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()

Modified: trunk/numpy/f2py/lib/parser/base_classes.py
===================================================================
--- trunk/numpy/f2py/lib/parser/base_classes.py	2006-10-05 23:36:47 UTC (rev 3266)
+++ trunk/numpy/f2py/lib/parser/base_classes.py	2006-10-06 04:57:17 UTC (rev 3267)
@@ -229,6 +229,39 @@
                         '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 @@
     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)

Modified: trunk/numpy/f2py/lib/parser/typedecl_statements.py
===================================================================
--- trunk/numpy/f2py/lib/parser/typedecl_statements.py	2006-10-05 23:36:47 UTC (rev 3266)
+++ trunk/numpy/f2py/lib/parser/typedecl_statements.py	2006-10-06 04:57:17 UTC (rev 3267)
@@ -512,12 +512,13 @@
             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 @@
             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 = [ \

Modified: trunk/numpy/f2py/lib/py_wrap_subprogram.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-05 23:36:47 UTC (rev 3266)
+++ trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-06 04:57:17 UTC (rev 3267)
@@ -41,7 +41,7 @@
   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 @@
                 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 @@
         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




More information about the Numpy-svn mailing list