Changeset: 4c27ea2bfa34 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4c27ea2bfa34
Added Files:
        testing/exportutils.py
Modified Files:
        clients/Tests/exports.stable.out
        testing/Makefile.ag
        testing/listexports.py.in
Branch: Oct2014
Log Message:

Split off preprocess function into separate module, and fixed it too.


diffs (268 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1476,9 +1476,9 @@ str MANUALcreateSummary(Client cntxt, Ma
 str MANUALhelp(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str MANUALsearch(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str MATHbinary_ATAN2dbl(dbl *res, dbl *a, dbl *b);
-str MATHbinary_ATAN2dbl(dbl *res, dbl *a, dbl *b);
+str MATHbinary_ATAN2flt(flt *res, flt *a, flt *b);
 str MATHbinary_POWdbl(dbl *res, dbl *a, dbl *b);
-str MATHbinary_POWdbl(dbl *res, dbl *a, dbl *b);
+str MATHbinary_POWflt(flt *res, flt *a, flt *b);
 str MATHbinary_ROUNDdbl(dbl *res, dbl *a, int *b);
 str MATHbinary_ROUNDflt(flt *res, flt *a, int *b);
 str MATHpi(dbl *pi);
@@ -1486,45 +1486,45 @@ str MATHrandint(int *res);
 str MATHsqlrandint(int *res, int *seed);
 str MATHsrandint(void *ret, const int *seed);
 str MATHunary_ACOSdbl(dbl *res, dbl *a);
-str MATHunary_ACOSdbl(dbl *res, dbl *a);
+str MATHunary_ACOSflt(flt *res, flt *a);
 str MATHunary_ASINdbl(dbl *res, dbl *a);
-str MATHunary_ASINdbl(dbl *res, dbl *a);
+str MATHunary_ASINflt(flt *res, flt *a);
 str MATHunary_ATANdbl(dbl *res, dbl *a);
-str MATHunary_ATANdbl(dbl *res, dbl *a);
+str MATHunary_ATANflt(flt *res, flt *a);
 str MATHunary_CEILdbl(dbl *res, dbl *a);
-str MATHunary_CEILdbl(dbl *res, dbl *a);
+str MATHunary_CEILflt(flt *res, flt *a);
 str MATHunary_COSHdbl(dbl *res, dbl *a);
-str MATHunary_COSHdbl(dbl *res, dbl *a);
+str MATHunary_COSHflt(flt *res, flt *a);
 str MATHunary_COSdbl(dbl *res, dbl *a);
-str MATHunary_COSdbl(dbl *res, dbl *a);
+str MATHunary_COSflt(flt *res, flt *a);
 str MATHunary_COTdbl(dbl *res, dbl *a);
-str MATHunary_COTdbl(dbl *res, dbl *a);
+str MATHunary_COTflt(flt *res, flt *a);
 str MATHunary_DEGREESdbl(dbl *res, dbl *a);
-str MATHunary_DEGREESdbl(dbl *res, dbl *a);
+str MATHunary_DEGREESflt(flt *res, flt *a);
 str MATHunary_EXPdbl(dbl *res, dbl *a);
-str MATHunary_EXPdbl(dbl *res, dbl *a);
+str MATHunary_EXPflt(flt *res, flt *a);
 str MATHunary_FABSdbl(dbl *res, dbl *a);
 str MATHunary_FINITE(bit *res, dbl *a);
 str MATHunary_FLOORdbl(dbl *res, dbl *a);
-str MATHunary_FLOORdbl(dbl *res, dbl *a);
+str MATHunary_FLOORflt(flt *res, flt *a);
 str MATHunary_ISINF(int *res, dbl *a);
 str MATHunary_ISNAN(bit *res, dbl *a);
 str MATHunary_LOG10dbl(dbl *res, dbl *a);
-str MATHunary_LOG10dbl(dbl *res, dbl *a);
+str MATHunary_LOG10flt(flt *res, flt *a);
 str MATHunary_LOGdbl(dbl *res, dbl *a);
-str MATHunary_LOGdbl(dbl *res, dbl *a);
+str MATHunary_LOGflt(flt *res, flt *a);
 str MATHunary_RADIANSdbl(dbl *res, dbl *a);
-str MATHunary_RADIANSdbl(dbl *res, dbl *a);
+str MATHunary_RADIANSflt(flt *res, flt *a);
 str MATHunary_SINHdbl(dbl *res, dbl *a);
-str MATHunary_SINHdbl(dbl *res, dbl *a);
+str MATHunary_SINHflt(flt *res, flt *a);
 str MATHunary_SINdbl(dbl *res, dbl *a);
-str MATHunary_SINdbl(dbl *res, dbl *a);
+str MATHunary_SINflt(flt *res, flt *a);
 str MATHunary_SQRTdbl(dbl *res, dbl *a);
-str MATHunary_SQRTdbl(dbl *res, dbl *a);
+str MATHunary_SQRTflt(flt *res, flt *a);
 str MATHunary_TANHdbl(dbl *res, dbl *a);
-str MATHunary_TANHdbl(dbl *res, dbl *a);
+str MATHunary_TANHflt(flt *res, flt *a);
 str MATHunary_TANdbl(dbl *res, dbl *a);
-str MATHunary_TANdbl(dbl *res, dbl *a);
+str MATHunary_TANflt(flt *res, flt *a);
 str MATdummy(int *ret, str *grp);
 str MAThasMoreElements(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
 str MATinfo(bat *ret, str *grp, str *elm);
diff --git a/testing/Makefile.ag b/testing/Makefile.ag
--- a/testing/Makefile.ag
+++ b/testing/Makefile.ag
@@ -45,7 +45,7 @@ scripts_py = {
 headers_python = {
        HEADERS = py
        DIR = $(prefix)/$(PYTHON2_LIBDIR)/MonetDBtesting
-       SOURCES = trace.py process.py monet_options.py.in __init__.py 
listexports.py.in
+       SOURCES = trace.py process.py monet_options.py.in __init__.py 
listexports.py.in exportutils.py
 }
 
 scripts_sh = {
diff --git a/testing/exportutils.py b/testing/exportutils.py
new file mode 100644
--- /dev/null
+++ b/testing/exportutils.py
@@ -0,0 +1,74 @@
+import re
+
+# a function-like #define that we expand to also find exports hidden
+# in preprocessor macros
+defre = re.compile(r'^[ \t]*#[ \t]*define[ \t]+'            # #define
+                   r'(?P<name>[a-zA-Z_][a-zA-Z0-9_]*)'      # name being 
defined
+                   r'\((?P<args>[a-zA-Z0-9_, \t]*)\)[ \t]*' # arguments
+                   r'(?P<def>.*)$',                         # macro replacement
+                   re.MULTILINE)
+# line starting with a "#"
+cldef = re.compile(r'^[ \t]*#', re.MULTILINE)
+
+# do something a bit like the C preprocessor
+#
+# we expand function-like macros and remove all ## sequences from the
+# replacement (even when there are no adjacent parameters that were
+# replaced), but this is good enough for our purpose of finding
+# exports that are hidden away in several levels of macro definitions
+#
+# we assume that there are no continuation lines in the input
+def preprocess(data):
+    defines = {}
+    ndata = []
+    for line in data.split('\n'):
+        res = defre.match(line)
+        if res is not None:
+            name, args, body = res.groups()
+            args = tuple(map(lambda x: x.strip(), args.split(',')))
+            if len(args) == 1 and args[0] == '':
+                args = ()       # empty argument list
+            defines[name] = (args, body)
+        else:
+            tried = {}
+            changed = True
+            while changed:
+                changed = False
+                for name, (args, body) in defines.items():
+                    if name in tried:
+                        continue
+                    pat = r'\b%s\b' % name
+                    sep = r'\('
+                    for arg in args:
+                        pat = pat + sep + r'([^,(]*(?:\([^,(]*\)[^,(]*)*)'
+                        sep = ','
+                    pat += r'\)'
+                    repl = {}
+                    r = re.compile(pat)
+                    res = r.search(line)
+                    if res is not None:
+                        tried[name] = True
+                        changed = True
+                    while res is not None:
+                        bd = body
+                        if len(args) > 0:
+                            pars = map(lambda x: x.strip(), res.groups())
+                            pat = r'\b(?:'
+                            sep = ''
+                            for arg, par in zip(args, pars):
+                                repl[arg] = par
+                                pat += sep + arg
+                                sep = '|'
+                            pat += r')\b'
+                            r2 = re.compile(pat)
+                            res2 = r2.search(bd)
+                            while res2 is not None:
+                                arg = res2.group(0)
+                                bd = bd[:res2.start(0)] + repl[arg] + 
bd[res2.end(0):]
+                                res2 = r2.search(bd, res2.start(0) + 
len(repl[arg]))
+                            bd = bd.replace('##', '')
+                        line = line[:res.start(0)] + bd + line[res.end(0):]
+                        res = r.search(line, res.start(0) + len(bd))
+            if not cldef.match(line):
+                ndata.append(line)
+    return '\n'.join(ndata)
diff --git a/testing/listexports.py.in b/testing/listexports.py.in
--- a/testing/listexports.py.in
+++ b/testing/listexports.py.in
@@ -19,6 +19,8 @@ import os
 import sys
 import re
 
+import exportutils
+
 # sets of directories that end up in the same shared object
 dirlist = {
     'gdk': ['gdk', 'common/options', 'common/utils'],
@@ -55,76 +57,6 @@ nmere = re.compile(r'\b(?P<name>[a-zA-Z_
 strre = re.compile(r'([^ *])\*')
 comre = re.compile(r',\s*')
 
-# a function-like #define that we expand to also find exports hidden
-# in preprocessor macros
-defre = re.compile(r'^[ \t]*#[ \t]*define[ \t]+'            # #define
-                   r'(?P<name>[a-zA-Z_][a-zA-Z0-9_]*)'      # name being 
defined
-                   r'\((?P<args>[a-zA-Z0-9_, \t]*)\)[ \t]*' # arguments
-                   r'(?P<def>.*)$',                         # macro replacement
-                   re.MULTILINE)
-# line starting with a "#"
-cldef = re.compile(r'^[ \t]*#', re.MULTILINE)
-
-# do something a bit like the C preprocessor
-# we expand function-like macros and remove all ## sequences from the
-# replacement (even when there are no adjacent parameters that were
-# replaced), but this is good enough for our purpose of finding
-# exports that are hidden away in several levels of macro definitions
-def preprocess(data):
-    defines = {}
-    ndata = []
-    for line in data.split('\n'):
-        # print >> sys.stderr, 'processing',line
-        res = defre.match(line)
-        if res is not None:
-            name, args, body = res.groups()
-            args = tuple(map(lambda x: x.strip(), args.split(',')))
-            if len(args) == 1 and args[0] == '':
-                args = ()       # empty argument list
-            defines[name] = (args, body)
-        else:
-            tried = {}
-            changed = True
-            while changed:
-                changed = False
-                for name, (args, body) in defines.items():
-                    if name in tried:
-                        continue
-                    pat = r'\b%s\b' % name
-                    sep = r'\('
-                    for arg in args:
-                        pat = pat + sep + r'([^,(]*(?:\([^,(]*\)[^,(]*)*)'
-                        sep = ','
-                    pat += r'\)'
-                    repl = {}
-                    r = re.compile(pat)
-                    res = r.search(line)
-                    if res is not None:
-                        tried[name] = True
-                        changed = True
-                    while res is not None:
-                        if len(args) > 0:
-                            pars = map(lambda x: x.strip(), res.groups())
-                            pat = r'\b(?:'
-                            sep = ''
-                            for arg, par in zip(args, pars):
-                                repl[arg] = par
-                                pat += sep + arg
-                                sep = '|'
-                            pat += r')\b'
-                            r2 = re.compile(pat)
-                            res2 = r2.search(body)
-                            while res2 is not None:
-                                arg = res2.group(0)
-                                body = body[:res2.start(0)] + repl[arg] + 
body[res2.end(0):]
-                                res2 = r2.search(body, res2.start(0) + 
len(repl[arg]))
-                            body = body.replace('##', '')
-                        line = line[:res.start(0)] + body + line[res.end(0):]
-                        res = r.search(line, res.start(0) + len(body))
-            if not cldef.match(line):
-                ndata.append(line)
-    return '\n'.join(ndata)
-
 def extract(f):
     decls = []
     data = open(f).read()
@@ -136,7 +68,7 @@ def extract(f):
     # remove \ <newline> combo's
     data = data.replace('\\\n', '')
 
-    data = preprocess(data)
+    data = exportutils.preprocess(data)
 
     res = expre.search(data)
     while res is not None:
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to