Changeset: 0a62252f782b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0a62252f782b
Modified Files:
testing/exportutils.py
testing/listexports.py.in
testing/malcheck.py
Branch: Oct2014
Log Message:
Code deduplication, and improvements to preprocessing.
diffs (116 lines):
diff --git a/testing/exportutils.py b/testing/exportutils.py
--- a/testing/exportutils.py
+++ b/testing/exportutils.py
@@ -17,6 +17,11 @@ spcre = re.compile(r'\s+')
strre = re.compile(r'([^ *])\*')
comre = re.compile(r',\s*')
+# comments (/* ... */ where ... is as short as possible)
+cmtre = re.compile(r'/\*.*?\*/|//[^\n]*', re.DOTALL)
+
+deepnesting = False
+
# do something a bit like the C preprocessor
#
# we expand function-like macros and remove all ## sequences from the
@@ -26,6 +31,14 @@ comre = re.compile(r',\s*')
#
# we assume that there are no continuation lines in the input
def preprocess(data):
+ # remove C comments
+ res = cmtre.search(data)
+ while res is not None:
+ data = data[:res.start(0)] + ' ' + data[res.end(0):]
+ res = cmtre.search(data, res.start(0))
+ # remove \ <newline> combo's
+ data = data.replace('\\\n', '')
+
defines = {}
ndata = []
for line in data.split('\n'):
@@ -53,7 +66,13 @@ def replace(line, defines, tried):
pat = r'\b%s\b' % name
sep = r'\('
for arg in args:
- pat = pat + sep + r'([^,(]*(?:\([^,(]*\)[^,(]*)*)'
+ # match argument to macro with optionally several levels
+ # of parentheses
+ if deepnesting: # optionally deeply nested parentheses
+ nested =
r'(?:\([^()]*(?:\([^()]*(?:\([^()]*(?:\([^()]*(?:\([^()]*(?:\([^()]*\)[^()]*)*\)[^()]*)*\)[^()]*)*\)[^()]*)*\)[^()]*)*\)[^()]*)*'
+ else:
+ nested = ''
+ pat = pat + sep + r'([^,()]*(?:\([^()]*' + nested + r'\)[^,()]*)*)'
sep = ','
pat += r'\)'
repl = {}
@@ -75,8 +94,15 @@ def replace(line, defines, tried):
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]))
+ if bd[res2.start(0)-1:res2.start(0)] == '#' and \
+ bd[res2.start(0)-2:res2.start(0)] <> '##':
+ # replace #ARG by stringified replacement
+ pos = res2.start(0) + len(repl[arg]) + 1
+ bd = bd[:res2.start(0)-1] + '"' + repl[arg] + '"' +
bd[res2.end(0):]
+ else:
+ pos = res2.start(0) + len(repl[arg])
+ bd = bd[:res2.start(0)] + repl[arg] + bd[res2.end(0):]
+ res2 = r2.search(bd, pos)
bd, changed = replace(bd, defines, tried + [name])
bd = bd.replace('##', '')
line = line[:res.start(0)] + bd + line[res.end(0):]
diff --git a/testing/listexports.py.in b/testing/listexports.py.in
--- a/testing/listexports.py.in
+++ b/testing/listexports.py.in
@@ -40,9 +40,6 @@ skipfiles = ['monet_getopt.h']
srcdir = r'@SOURCE@'
blddir = r'@BUILD@'
-# comments (/* ... */ where ... is as short as possible)
-cmtre = re.compile(r'/\*.*?\*/|//[^\n]*', re.DOTALL)
-
# the export command; note the keyword we look for is a word that ends
# in "export"
expre = re.compile(r'\b[a-zA-Z_0-9]+export\s+(?P<decl>[^;]*;)', re.MULTILINE)
@@ -53,13 +50,6 @@ nmere = re.compile(r'\b(?P<name>[a-zA-Z_
def extract(f):
decls = []
data = open(f).read()
- # remove C comments
- res = cmtre.search(data)
- while res is not None:
- data = data[:res.start(0)] + ' ' + data[res.end(0):]
- res = cmtre.search(data, res.start(0))
- # remove \ <newline> combo's
- data = data.replace('\\\n', '')
data = exportutils.preprocess(data)
diff --git a/testing/malcheck.py b/testing/malcheck.py
--- a/testing/malcheck.py
+++ b/testing/malcheck.py
@@ -10,7 +10,6 @@ patreg = re.compile(r'\bpattern\s+(?P<ma
treg = re.compile(r':(bat\[[^]]*\]|[a-zA-Z_][a-zA-Z_0-9]*)')
-cmtre = re.compile(r'/\*.*?\*/|//[^\n]*', re.DOTALL)
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*[[(;]')
@@ -76,14 +75,6 @@ def process(f):
malpats.append((malf, func, f))
res = patreg.search(data, res.end(0))
elif f.endswith('.h') or f.endswith('.c'):
- # remove C comments
- res = cmtre.search(data)
- while res is not None:
- data = data[:res.start(0)] + ' ' + data[res.end(0):]
- res = cmtre.search(data, res.start(0))
- # remove \ <newline> combo's
- data = data.replace('\\\n', '')
-
data = exportutils.preprocess(data)
res = expre.search(data)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list