Commit 9a64ba93 authored by Nils Goroll's avatar Nils Goroll

vmodtool: enforce function and argument names be valid c symbols

parent fb5779c6
......@@ -310,6 +310,8 @@ def arg(txt):
return a, s
def nmlegal(nm):
return re.match('^[a-zA-Z0-9_]+$', nm)
# XXX cant have ( or ) in an argument default value
class prototype(object):
......@@ -332,6 +334,8 @@ class prototype(object):
i = s.find("(")
assert i > 0
self.name = prefix + s[:i].strip()
if not nmlegal(self.cname()):
err("%s(): Illegal name\n" % self.name, warn=False)
s = s[i:].strip()
assert s[0] == "("
assert s[-1] == ")"
......@@ -340,10 +344,14 @@ class prototype(object):
names = {}
while len(s) > 0:
a, s = arg(s)
if a.nm is not None and a.nm in names:
err("%s(): duplicate argument name '%s'\n" % (self.name, a.nm),
warn=False)
names[a.nm] = True
if a.nm is not None:
if not nmlegal(a.nm):
err("%s(): illegal argument name '%s'\n"
% (self.name, a.nm), warn=False)
if a.nm in names:
err("%s(): duplicate argument name '%s'\n"
% (self.name, a.nm), warn=False)
names[a.nm] = True
self.args.append(a)
s = s.lstrip()
if len(s) == 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment