matchcompiler: don't emmit '!true' or '!false'. Fold to 'false' or 'true'.

This commit is contained in:
Matthias Krüger 2017-04-02 16:30:16 +02:00
parent 92fe210217
commit c65725cb1b
1 changed files with 8 additions and 1 deletions

View File

@ -188,7 +188,14 @@ class MatchCompiler:
gotoNextToken = ' tok = tok ? tok->next() : NULL;\n'
else:
ret += ' if (!tok || !' + self._compileCmd(tok) + ')\n'
negatedTok ="!" + self._compileCmd(tok)
# fold !true => false ; !false => true
# this avoids cppcheck warnings about condition always being true/false
if (negatedTok == "!false"):
negatedTok = "true"
elif (negatedTok == "!true"):
negatedTok = "false"
ret += ' if (!tok || ' + negatedTok + ')\n'
ret += ' ' + returnStatement
if isFindMatch: