From 4b386986fc11f22aa2b814112c22fd51fa63228b Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Fri, 4 Jan 2013 01:14:52 +0100 Subject: [PATCH] Match compiler: Check varid on first use like Token::Match does --- tools/matchcompiler.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py index f13f20a2c..599076dbe 100755 --- a/tools/matchcompiler.py +++ b/tools/matchcompiler.py @@ -49,19 +49,22 @@ def compilePattern(matchStrs, pattern, nr, varid): arg2 = ', const unsigned int varid' ret = '// ' + pattern + '\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(' ') gotoNextToken = '' + checked_varid = False for tok in tokens: if tok == '': continue ret += gotoNextToken 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] 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'