Changeset: a0a3744f4c30 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a0a3744f4c30
Added Files:
        clients/Tests/melcheck.sh
        clients/Tests/melcheck.timeout
Removed Files:
        clients/Tests/malcheck.sh
        clients/Tests/malcheck.timeout
        testing/malcheck.py
Modified Files:
        clients/Tests/All
        testing/CMakeLists.txt
        testing/exportutils.py
Branch: Jan2022
Log Message:

Updated melcheck, removed malcheck.


diffs (truncated from 460 to 300 lines):

diff --git a/clients/Tests/All b/clients/Tests/All
--- a/clients/Tests/All
+++ b/clients/Tests/All
@@ -1,5 +1,5 @@
 exports
 
HAVE_HGE&HAVE_FITS&HAVE_GEOM&HAVE_LIBR&HAVE_LIBPY3&HAVE_NETCDF&HAVE_SHP&NOT_WIN32?MAL-signatures-hge
 
!HAVE_HGE&HAVE_FITS&HAVE_GEOM&HAVE_LIBR&HAVE_LIBPY3&HAVE_NETCDF&HAVE_SHP&NOT_WIN32?MAL-signatures
-#MERCURIAL?malcheck
+MERCURIAL?melcheck
 mclient-uri
diff --git a/clients/Tests/malcheck.sh b/clients/Tests/melcheck.sh
rename from clients/Tests/malcheck.sh
rename to clients/Tests/melcheck.sh
--- a/clients/Tests/malcheck.sh
+++ b/clients/Tests/melcheck.sh
@@ -1,3 +1,3 @@
 #!/bin/sh
 cd $TSTSRCBASE
-hg -q files -I '{monetdb5,sql,geom}/**.{[ch],mal}' -X '**/Tests/**' | python 
-c 'import MonetDBtesting.malcheck'
+hg -q files -I '{monetdb5,sql,geom}/**.[ch]' -X '**/Tests/**' | python -c 
'import MonetDBtesting.melcheck'
diff --git a/clients/Tests/malcheck.timeout b/clients/Tests/melcheck.timeout
rename from clients/Tests/malcheck.timeout
rename to clients/Tests/melcheck.timeout
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -125,7 +125,7 @@ if(PYTHON3_LIBDIR)
     __init__.py
     ${CMAKE_CURRENT_BINARY_DIR}/listexports.py
     exportutils.py
-    malcheck.py
+    melcheck.py
     sqllogictest.py
     explain.py
     mapicursor.py
diff --git a/testing/exportutils.py b/testing/exportutils.py
--- a/testing/exportutils.py
+++ b/testing/exportutils.py
@@ -7,26 +7,24 @@
 import re
 import os
 
-# macro definition
-macrore = re.compile(r'\s*#\s*define\s+'            # #define
-                     r'(?P<name>\w+)'               # name being defined
-                     r'(?:\((?P<args>[^)]*)\))?\s*' # optional arguments
-                     r'(?P<repl>.*)')               # replacement
-# include file
-inclre = re.compile(r'\s*#\s*include\s+"(?P<file>[^"]*)"')
+macrore = r'^[ \t]*#[ \t]*define[ \t]+(?P<name>\w+)(?:\((?P<args>[^()]*)\))?[ 
\t]*(?P<repl>.*)'
+includere = r'^[ \t]*#[ \t]*include[ \t]+"(?P<file>[^"]*)".*'
+ifre = r'^[ \t]*#[ \t]*if(def)?.*\b'
+elifre = r'^[ \t]*#[ \t]*elif\b.*'
+elsere = r'^[ \t]*#[ \t]*else\b.*'
+endifre = r'^[ \t]*#[ \t]*endif\b.*'
+undefre = r'^[ \t]*#[ \t]*undef[ \t]+(?P<uname>\w+).*'
+linere = 
r'^[^()\n]*(?:\([^()]*(?:\([^()]*(?:\([^()]*\)[^()]*)*\)[^()]*)*\)[^()\n]*)*$'
+
+searchre = 
re.compile(r'(?P<define>'+macrore+r')|(?P<include>'+includere+r')|(?P<if>'+ifre+r')|(?P<elif>'+elifre+r')|(?P<else>'+elsere+r')|(?P<endif>'+endifre+r')|(?P<undef>'+undefre+')|(?P<line>'+linere+r')',
 re.M)
+
 # comments (/* ... */ where ... is as short as possible)
-cmtre = re.compile(r'/\*[^*]*(\*(?=[^/])[^*]*)*\*/|//.*')
+commentre = re.compile(r'/\*[^*]*(\*(?=[^/])[^*]*)*\*/|//.*')
 # horizontal white space
 horspcre = re.compile(r'[ \t]+')
+
 # identifier
 identre = re.compile(r'\b(?P<ident>[a-zA-Z_]\w*)\b')
-# undef
-undefre = re.compile(r'\s*#\s*undef\s+(?P<name>\w+)')
-ifre = re.compile(r'\s*#\s*if') # #if or #ifdef
-elifre = re.compile(r'\s*#\s*elif')
-elsere = re.compile(r'\s*#\s*else')
-endifre = re.compile(r'\s*#\s*endif')
-
 nested = r'' # 
r'(?:\([^()]*(?:\([^()]*(?:\([^()]*(?:\([^()]*(?:\([^()]*(?:\([^()]*\)[^()]*)*\)[^()]*)*\)[^()]*)*\)[^()]*)*\)[^()]*)*\)[^()]*)*'
 
 def process(line, funmac, macros, infunmac=False):
@@ -82,10 +80,9 @@ def process(line, funmac, macros, infunm
 def readfile(f, funmac=None, macros=None, files=None, printdef=False, 
include=False):
     data = open(f).read()
     dirname, f = os.path.split(f)
-    data = cmtre.sub(' ', data)
+    data = commentre.sub(' ', data)
     data = data.replace('\\\n', '')
     data = horspcre.sub(' ', data)
-    data = data.splitlines()
     if funmac is None:
         funmac = {}
     if macros is None:
@@ -95,30 +92,27 @@ def readfile(f, funmac=None, macros=None
     files.add(f)
     ndata = []
     skip = []
-    for line in data:
-        if endifre.match(line) is not None:
+    res = searchre.search(data, 0)
+    while res is not None and res.start(0) < len(data):
+        line = res.group()
+        if res.group('endif'):
             if printdef:
                 ndata.append(line)
             if skip:
                 del skip[-1]
-            continue
-        if ifre.match(line) is not None:
+        elif res.group('if'):
             if printdef:
                 ndata.append(line)
             skip.append(False)
-            continue
-        if elifre.match(line) or elsere.match(line):
+        elif res.group('elif') or res.group('else'):
             if printdef:
                 ndata.append(line)
             if include and skip:
                 skip[-1] = True
-            continue
-        if skip and skip[-1]:
+        elif skip and skip[-1]:
             if printdef:
                 ndata.append(line)
-            continue
-        res = macrore.match(line)
-        if res is not None:
+        elif res.group('define'):
             if printdef:
                 ndata.append(line)
             name = res.group('name')
@@ -129,29 +123,25 @@ def readfile(f, funmac=None, macros=None
                 if len(args) == 1 and args[0] == '':
                     args = ()   # empty argument list
                 funmac[name] = (args, repl)
-                continue
-            if include:
+            elif include:
                 macros[name] = repl
-            continue
-        res = inclre.match(line)
-        if res is not None:
+        elif res.group('include'):
             fn = res.group('file')
             if include and '/' not in fn and 
os.path.exists(os.path.join(dirname, fn)) and fn not in files:
                 incdata = readfile(os.path.join(dirname, fn), funmac, macros, 
files, printdef, include)
                 ndata.extend(incdata)
-                continue
-            ndata.append(line)
-            continue
-        res = undefre.match(line)
-        if res is not None:
-            name = res.group('name')
+            else:
+                ndata.append(line)
+        elif res.group('undef'):
+            name = res.group('uname')
             if name in macros:
                 del macros[name]
             if name in funmac:
                 del funmac[name]
-            continue
-        line = process(line, funmac, macros)
-        ndata.append(line)
+        elif res.group('line'):
+            line = process(line, funmac, macros)
+            ndata.append(line)
+        res = searchre.search(data, res.end(0) + 1)
     files.remove(f)
     return ndata
 
diff --git a/testing/malcheck.py b/testing/malcheck.py
deleted file mode 100644
--- a/testing/malcheck.py
+++ /dev/null
@@ -1,286 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0.  If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-# Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
-
-import re, sys
-
-try:
-    import exportutils
-except ImportError:
-    from MonetDBtesting import exportutils
-
-# MAL function: optional module with function name
-malfre = 
r'(?P<malf>(?:[a-zA-Z_][a-zA-Z_0-9]*\.)?(?:[a-zA-Z_][a-zA-Z_0-9]*|[-+/*<>%=!]+))\s*(?:{[^}]*}\s*)?'
-# MAL address declaration
-addrre = r'address\s+(?P<func>[a-zA-Z_][a-zA-Z_0-9]*)'
-
-# recognize MAL "command" declarations
-comreg = re.compile(r'\bcommand\s+' + malfre + 
r'\(\s*(?P<args>[^()]*)\)\s*(?P<rets>\([^()]*\)|:\s*bat\[[^]]*\]|:\s*[a-zA-Z_][a-zA-Z_0-9]*|)\s+'
 + addrre + r'\b')
-
-# recognize MAL "pattern" declarations
-patreg = re.compile(r'\bpattern\s+' + malfre + 
r'\(\s*(?P<args>[^()]*)\)\s*(?P<rets>\([^()]*\)|:\s*bat\[[^]]*\](?:\.\.\.)?|:\s*[a-zA-Z_][a-zA-Z_0-9]*(?:\.\.\.)?|)\s+'
 + addrre + r'\b')
-
-atmreg = 
re.compile(r'\batom\s+(?P<atom>[a-zA-Z_][a-zA-Z0-9_]*)(?:\s*[:=]\s*(?P<base>[a-zA-Z_][a-zA-Z0-9_]*))?\s*;')
-
-treg = re.compile(r':\s*(bat\[[^]]*\]|[a-zA-Z_][a-zA-Z_0-9]*)')
-
-expre = re.compile(r'\b[a-zA-Z_0-9]+export\s+(?P<decl>[^;]*;)', re.MULTILINE)
-nmere = re.compile(r'\b(?P<name>[a-zA-Z_][a-zA-Z_0-9]*)\s*[\[\(;]')
-
-freg = 
re.compile(r'(?P<rtype>(?:const\s+)?\w+(?:\s*\*)*)\s*\b(?P<name>\w+)\((?P<args>[^()]*)\)')
-creg = re.compile(r'\bconst\b')
-sreg = re.compile(r'\bchar\s*\*')
-areg = re.compile(r'\w+')
-argreg = re.compile(r'\s*\w+$')
-
-mappings = {
-    'zrule': 'rule',
-    'timezone': 'tzone',
-    'streams': 'Stream',
-    'bstream': 'Bstream',
-    'any_1': 'void',
-    'any_2': 'void',
-    'any_3': 'void',
-    'any_4': 'void',
-    'any': 'void',
-    'blob': 'blob',
-}
-cmappings = {
-    'blob': 'blob',
-}
-atomfunctypes = {
-    # MAL name: (return type, (argument...))
-    # where each argument is (type, const)
-    'cmp': ('int', (('void *', True), ('void *', True))),
-    'del': ('void', (('Heap *', False), ('var_t *', False))),
-    'fix': ('int', (('void *', True),)),
-    'fromstr': ('ssize_t', (('char *', True), ('size_t *', False), ('void **', 
False), ('bool', False))),
-    'hash': ('BUN', (('void *', True),)),
-    'heap': ('void', (('Heap *', False), ('size_t', False))),
-    'length': ('size_t', (('void *', True),)),
-    'nequal': ('int', (('void *', True), ('void *', True))),
-    'null': ('const void *', (('void', False),)),
-    'put': ('var_t', (('Heap *', False), ('var_t *', False), ('void *', 
True))),
-    'read': ('void *', (('void *', False), ('stream *', False), ('size_t', 
False))),
-    'storage': ('long', (('void', False),)),
-    'tostr': ('ssize_t', (('char **', False), ('size_t *', False), ('void *', 
True), ('bool', False))),
-    'unfix': ('int', (('void *', True),)),
-    'write': ('gdk_return', (('void *', True), ('stream *', False), ('size_t', 
False))),
-    }
-
-defre = re.compile(r'^[ \t]*#[ \t]*define[ 
\t]+(?P<name>[a-zA-Z_][a-zA-Z0-9_]*)\((?P<args>[a-zA-Z0-9_, \t]*)\)[ 
\t]*(?P<def>.*)$', re.MULTILINE)
-
-cldef = re.compile(r'^[ \t]*#', re.MULTILINE)
-
-malfuncs = []
-malpats = []
-atomfuncs = []
-decls = {}
-odecls = {}
-pdecls = {}
-
-def process(f):
-    if f.endswith('.mal'):
-        data = open(f).read()
-        data = re.sub(r'[ \t]*#.*', '', data) # remove comments
-        for res in comreg.finditer(data):
-            malf, args, rets, func = res.groups()
-            if malf not in atomfunctypes or args.strip():
-                rtypes = []
-                atypes = []
-                if not rets:
-                    rets = ':void'
-                for tres in treg.finditer(rets):
-                    typ = tres.group(1)
-                    if typ.startswith('bat['):
-                        typ = 'bat'
-                    rtypes.append(mappings.get(typ, typ))
-                for tres in treg.finditer(args):
-                    typ = tres.group(1)
-                    if typ.startswith('bat['):
-                        typ = 'bat'
-                    atypes.append(mappings.get(typ, typ))
-                malfuncs.append((tuple(rtypes), tuple(atypes), malf, func, f))
-            elif args.strip():
-                print('atom function %s should be declared without arguments 
in %s' % (malf, f))
-            else:
-                if rets:
-                    print('atom function %s should be declared without return 
type in %s' % (malf, f))
-                atom = None
-                base = None
-                for ares in atmreg.finditer(data, 0, res.start(0)):
-                    atom = ares.group('atom')
-                    base = ares.group('base')
-                if not atom:
-                    print('atom function %s declared without known atom name 
in %s' % (malf, f))
-                    continue
-                atomfuncs.append((malf, atom, base, func, f))
-        for res in patreg.finditer(data):
-            malf, args, rets, func = res.groups()
-            malpats.append((malf, func, f))
-    elif f.endswith('.h') or f.endswith('.c'):
-        data = exportutils.preprocess(f)
-
-        for res in expre.finditer(data):
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to