matchcompiler: handle %varid%

This commit is contained in:
Daniel Marjamäki 2012-12-14 16:59:37 +01:00
parent d149b9b06c
commit b6786c87b4
1 changed files with 18 additions and 8 deletions

View File

@ -28,13 +28,18 @@ def compileCmd(tok):
return '(tok->isName() && tok->varId()==0U && tok->str() != "delete")' return '(tok->isName() && tok->varId()==0U && tok->str() != "delete")'
elif tok == '%var%': elif tok == '%var%':
return 'tok->isName()' return 'tok->isName()'
elif tok == '%varid%':
return '(tok->isName() && tok->varId()==varid)'
elif (len(tok)>2) and (tok[0]=="%"): elif (len(tok)>2) and (tok[0]=="%"):
print "unhandled:" + tok print "unhandled:" + tok
return '(tok->str()=="'+tok+'")' return '(tok->str()=="'+tok+'")'
def compilePattern(pattern, nr): def compilePattern(pattern, nr, varid):
arg2 = ''
if varid:
arg2 = ', const unsigned int varid'
ret = '// ' + pattern + '\n' ret = '// ' + pattern + '\n'
ret = ret + 'static bool match' + str(nr) + '(const Token *tok) {\n' ret = ret + 'static bool match' + str(nr) + '(const Token *tok'+arg2+') {\n'
tokens = pattern.split(' ') tokens = pattern.split(' ')
gotoNextToken = '' gotoNextToken = ''
for tok in tokens: for tok in tokens:
@ -147,21 +152,26 @@ def convertFile(srcname, destname):
res = parseMatch(line, pos1) res = parseMatch(line, pos1)
if res == None: if res == None:
break break
elif len(res) != 3:
# TODO: handle varid
break
else: else:
assert(len(res)==3 or len(res)==4) # assert that Token::Match has either 2 or 3 arguments
g0 = res[0] g0 = res[0]
arg1 = res[1] arg1 = res[1]
arg2 = res[2] arg2 = res[2]
arg3 = None
if len(res) == 4:
arg3 = res[3]
res = re.match(r'\s*"(.+)"\s*$', arg2) res = re.match(r'\s*"([^"]*)"\s*$', arg2)
if res == None: if res == None:
break # Non-const pattern - bailout break # Non-const pattern - bailout
else: else:
arg2 = res.group(1) arg2 = res.group(1)
line = line[:pos1]+'match'+str(patternNumber)+'('+arg1+')'+line[pos1+len(g0):] a3 = ''
matchfunctions = matchfunctions + compilePattern(arg2, patternNumber) if arg3:
a3 = ',' + arg3
line = line[:pos1]+'match'+str(patternNumber)+'('+arg1+a3+')'+line[pos1+len(g0):]
matchfunctions = matchfunctions + compilePattern(arg2, patternNumber, arg3)
patternNumber = patternNumber + 1 patternNumber = patternNumber + 1
code = code + line code = code + line