Simplified some Token::Match patterns
This commit is contained in:
parent
5851b0e6c4
commit
70dfb55f21
|
@ -64,7 +64,7 @@ static bool isConstExpression(const Token *tok, const std::set<std::string> &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::set<std::
|
|||
if (t1 != end1 || t2 != end2)
|
||||
return false;
|
||||
}
|
||||
if (Token::Match(tok1, "++|--") || tok1->isAssignmentOp())
|
||||
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();
|
||||
|
|
|
@ -446,7 +446,7 @@ static void compileTerm(Token *& tok, std::stack<Token*> &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<Token*> &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<Token*> &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<Token*> &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<Token*> &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<Token*> &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<Token *> 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<Token *> operands;
|
||||
Token * const tok1 = tok;
|
||||
compileExpression(tok, operands, 0U);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue