[Numpy-svn] r5874 - in branches/clean_math_config/numpy: core/src distutils

numpy-svn@scip... numpy-svn@scip...
Sun Sep 28 18:35:18 CDT 2008


Author: charris
Date: 2008-09-28 18:35:15 -0500 (Sun, 28 Sep 2008)
New Revision: 5874

Modified:
   branches/clean_math_config/numpy/core/src/arraytypes.inc.src
   branches/clean_math_config/numpy/distutils/conv_template.py
Log:
Enhance code_generator to allow continuation lines.
Small clarification in arraytypes.inc.src.
Practice merging ;)


Modified: branches/clean_math_config/numpy/core/src/arraytypes.inc.src
===================================================================
--- branches/clean_math_config/numpy/core/src/arraytypes.inc.src	2008-09-28 22:58:24 UTC (rev 5873)
+++ branches/clean_math_config/numpy/core/src/arraytypes.inc.src	2008-09-28 23:35:15 UTC (rev 5874)
@@ -664,7 +664,7 @@
 #from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#
 #totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#
 #fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#
-#incr= ip++*169,ip+=2*39#
+#incr= (ip++)*169,(ip+=2)*39#
 */
 static void
 @from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n,

Modified: branches/clean_math_config/numpy/distutils/conv_template.py
===================================================================
--- branches/clean_math_config/numpy/distutils/conv_template.py	2008-09-28 22:58:24 UTC (rev 5873)
+++ branches/clean_math_config/numpy/distutils/conv_template.py	2008-09-28 23:35:15 UTC (rev 5874)
@@ -128,19 +128,22 @@
     numrep = obj.group(2)
     return ','.join([torep]*int(numrep))
 
-parenrep = re.compile(r"[(]([^)]*?)[)]\*(\d+)")
+parenrep = re.compile(r"[(]([^)]*)[)]\*(\d+)")
 plainrep = re.compile(r"([^*]+)\*(\d+)")
-def conv(astr):
+def parse_values(astr):
     # replaces all occurrences of '(a,b,c)*4' in astr
-    #  with 'a,b,c,a,b,c,a,b,c,a,b,c'. The result is
+    # with 'a,b,c,a,b,c,a,b,c,a,b,c'. Empty braces generate
+    # empty values, i.e., ()*4 yields ',,,'. The result is
     # split at ',' and a list of values returned.
-    astr = parenrep.sub(paren_repl,astr)
+    astr = parenrep.sub(paren_repl, astr)
     # replaces occurences of xxx*3 with xxx, xxx, xxx
     astr = ','.join([plainrep.sub(paren_repl,x.strip())
                      for x in astr.split(',')])
     return astr.split(',')
 
-named_re = re.compile(r"#\s*([\w]*)\s*=\s*([^#]*)#")
+
+stripast = re.compile(r"\n\s*\*?")
+named_re = re.compile(r"#\s*(\w*)\s*=([^#]*)#")
 def parse_loop_header(loophead) :
     """Find all named replacements in the header
 
@@ -149,23 +152,29 @@
     value is the replacement string.
 
     """
+    # Strip out '\n' and leading '*', if any, in continuation lines.
+    # This should not effect code previous to this change as
+    # continuation lines were not allowed.
+    loophead = stripast.sub("", loophead)
     # parse out the names and lists of values
     names = []
     reps = named_re.findall(loophead)
     nsub = None
     for rep in reps:
-        name = rep[0].strip()
-        vals = conv(rep[1])
+        name = rep[0]
+        vals = parse_values(rep[1])
         size = len(vals)
         if nsub is None :
             nsub = size
         elif nsub != size :
-            msg = "Mismatch in number: %s - %s" % (name, vals)
+            msg = "Mismatch in number of values:\n%s = %s" % (name, vals)
             raise ValueError, msg
         names.append((name,vals))
 
     # generate list of dictionaries, one for each template iteration
     dlist = []
+    if nsub is None :
+        raise ValueError, "No substitution variables found"
     for i in range(nsub) :
         tmp = {}
         for name,vals in names :
@@ -183,8 +192,8 @@
         try :
             val = env[name]
         except KeyError, e :
-            msg = '%s: %s'%(lineno, e)
-            raise KeyError, msg
+            msg = 'line %d: %s'%(line, e)
+            raise ValueError, msg
         return val
 
     code = [lineno]
@@ -203,7 +212,7 @@
             try :
                 envlist = parse_loop_header(head)
             except ValueError, e :
-                msg = "%s: %s" % (lineno, e)
+                msg = "line %d: %s" % (newline, e)
                 raise ValueError, msg
             for newenv in envlist :
                 newenv.update(env)
@@ -249,7 +258,10 @@
 def process_file(source):
     lines = resolve_includes(source)
     sourcefile = os.path.normcase(source).replace("\\","\\\\")
-    code = process_str(''.join(lines))
+    try:
+        code = process_str(''.join(lines))
+    except ValueError, e:
+        raise ValueError, '"%s", %s' % (sourcefile, e)
     return '#line 1 "%s"\n%s' % (sourcefile, code)
 
 
@@ -284,5 +296,8 @@
         outfile = open(newname,'w')
 
     allstr = fid.read()
-    writestr = process_str(allstr)
+    try:
+        writestr = process_str(allstr)
+    except ValueError, e:
+        raise ValueError, "file %s, %s" % (file, e)
     outfile.write(writestr)



More information about the Numpy-svn mailing list