Match compiler: Check varid on first use like Token::Match does
This commit is contained in:
parent
5d5efdf99f
commit
4b386986fc
|
@ -49,19 +49,22 @@ def compilePattern(matchStrs, pattern, nr, varid):
|
||||||
arg2 = ', const unsigned int varid'
|
arg2 = ', const unsigned int varid'
|
||||||
ret = '// ' + pattern + '\n'
|
ret = '// ' + pattern + '\n'
|
||||||
ret += 'static bool match' + str(nr) + '(const Token *tok'+arg2+') {\n'
|
ret += 'static bool match' + str(nr) + '(const Token *tok'+arg2+') {\n'
|
||||||
if varid:
|
|
||||||
# if varid is provided, check that it's non-zero
|
|
||||||
ret += ' if (varid==0U)\n'
|
|
||||||
ret += ' throw InternalError(tok, "Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers");\n'
|
|
||||||
|
|
||||||
tokens = pattern.split(' ')
|
tokens = pattern.split(' ')
|
||||||
gotoNextToken = ''
|
gotoNextToken = ''
|
||||||
|
checked_varid = False
|
||||||
for tok in tokens:
|
for tok in tokens:
|
||||||
if tok == '':
|
if tok == '':
|
||||||
continue
|
continue
|
||||||
ret += gotoNextToken
|
ret += gotoNextToken
|
||||||
gotoNextToken = ' tok = tok->next();\n'
|
gotoNextToken = ' tok = tok->next();\n'
|
||||||
|
|
||||||
|
# if varid is provided, check that it's non-zero on first use
|
||||||
|
if varid and tok.find('%varid%') != -1 and checked_varid == False:
|
||||||
|
ret += ' if (varid==0U)\n'
|
||||||
|
ret += ' throw InternalError(tok, "Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers");\n'
|
||||||
|
checked_varid = True
|
||||||
|
|
||||||
# [abc]
|
# [abc]
|
||||||
if (len(tok) > 2) and (tok[0] == '[') and (tok[-1] == ']'):
|
if (len(tok) > 2) and (tok[0] == '[') and (tok[-1] == ']'):
|
||||||
ret += ' if (!tok || tok->str().size()!=1U || !strchr("'+tok[1:-1]+'", tok->str()[0]))\n'
|
ret += ' if (!tok || tok->str().size()!=1U || !strchr("'+tok[1:-1]+'", tok->str()[0]))\n'
|
||||||
|
|
Loading…
Reference in New Issue