From 70dfb55f214ec73d8a8a13d3330a6fe26fbdf93e Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 11 May 2014 13:37:53 +0200 Subject: [PATCH] Simplified some Token::Match patterns --- lib/checkother.cpp | 4 ++-- lib/tokenlist.cpp | 16 ++++++++-------- lib/valueflow.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2ff2c14bc..0e7ffdb35 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -64,7 +64,7 @@ static bool isConstExpression(const Token *tok, const std::set &con else if (tok->function() && !tok->function()->isConst) return false; } - if (Token::Match(tok, "++|--")) + if (tok->type() == Token::eIncDecOp) return false; // bailout when we see ({..}) if (tok->str() == "{") @@ -114,7 +114,7 @@ bool isSameExpression(const Token *tok1, const Token *tok2, const std::setisAssignmentOp()) + if (tok1->type() == Token::eIncDecOp || tok1->isAssignmentOp()) return false; if (tok1->str() == "(" && tok1->previous() && !tok1->previous()->isName()) { // cast => assert that the casts are equal const Token *t1 = tok1->next(); diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 75faaa6e5..82ecdb135 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -446,7 +446,7 @@ static void compileTerm(Token *& tok, std::stack &op, unsigned int depth compileUnaryOp(tok, compileExpression, op, depth); } else if (tok->isName()) { const bool templatefunc = Token::Match(tok, "%var% <") && Token::simpleMatch(tok->linkAt(1), "> ("); - if (!Token::Match(tok->previous(), ".|::") && Token::Match(tok->next(), "++|--")) { // post increment / decrement + if (!Token::Match(tok->previous(), ".|::") && tok->next() && tok->next()->type() == Token::eIncDecOp) { // post increment / decrement tok = tok->next(); tok->astOperand1(tok->previous()); op.push(tok); @@ -487,7 +487,7 @@ static void compileTerm(Token *& tok, std::stack &op, unsigned int depth prev = tok1; if (Token::Match(tok, "]|)")) { tok = tok->next(); - if (depth==1U && Token::Match(tok,"++|--") && op.empty()) { + if (depth == 1U && tok && tok->type() == Token::eIncDecOp && op.empty()) { tok->astOperand1(tok->previous()->link()); tok = tok->next(); } @@ -495,7 +495,7 @@ static void compileTerm(Token *& tok, std::stack &op, unsigned int depth } op.push(par); } - } else if (Token::Match(tok, "++|--")) { + } else if (tok->type() == Token::eIncDecOp) { bool pre = false; if (Token::Match(tok->next(), "%var%|(")) pre = true; @@ -564,7 +564,7 @@ static void compileScope(Token *&tok, std::stack &op, unsigned int depth compileBinOp(tok, compileTerm, op, depth); else compileUnaryOp(tok, compileDot, op, depth); - if (depth==1U && Token::Match(tok,"++|--")) + if (depth == 1U && tok && tok->type() == Token::eIncDecOp) compileTerm(tok,op,depth); } else break; } @@ -576,7 +576,7 @@ static void compileDot(Token *&tok, std::stack &op, unsigned int depth) while (tok) { if (tok->str() == ".") { compileBinOp(tok, compileScope, op, depth); - if (depth==1U && Token::Match(tok,"++|--")) + if (depth == 1U && tok && tok->type() == Token::eIncDecOp) compileTerm(tok,op,depth); } else break; } @@ -588,7 +588,7 @@ static void compileBrackets(Token *&tok, std::stack &op, unsigned int de while (tok) { if (tok->str() == ".") { // compile dot and brackets from left to right. Example: "a.b[c]" compileBinOp(tok, compileScope, op, depth); - if (depth==1U && Token::Match(tok,"++|--")) + if (depth == 1U && tok && tok->type() == Token::eIncDecOp) compileTerm(tok,op,depth); } else if (tok->str() == "[") { compileBinOp(tok, compileDot, op, depth); @@ -751,7 +751,7 @@ static Token * createAstAtToken(Token *tok) tok2 = tok2->link(); if (!tok2) break; - } else if (Token::Match(tok2, "%var% %op%|(|[|.|=|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) { + } else if (Token::Match(tok2, "%var% %op%|(|[|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) { init1 = tok2; std::stack operands; compileExpression(tok2, operands, 0U); @@ -807,7 +807,7 @@ static Token * createAstAtToken(Token *tok) if (Token::Match(tok, "%type% <") && Token::Match(tok->linkAt(1), "> !!(")) return tok->linkAt(1); - if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%var% %op%|(|[|.|=|::") || Token::Match(tok->previous(), "[;{}] %cop%|( !!{")) { + if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%var% %op%|(|[|.|::") || Token::Match(tok->previous(), "[;{}] %cop%|( !!{")) { std::stack operands; Token * const tok1 = tok; compileExpression(tok, operands, 0U); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ea202f344..168870275 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -196,7 +196,7 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign const Token *parent = tok->astParent(); while (parent && parent->str() == ".") parent = parent->astParent(); - if (Token::Match(parent, "++|--")) + if (parent && parent->type() == Token::eIncDecOp) return true; } }