Refactoring, use Token::isUnaryOp and Token::isBinaryOp
This commit is contained in:
parent
435888f82e
commit
93903d96c4
|
@ -235,14 +235,14 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// in c++, a+b might be different to b+a, depending on the type of a and b
|
// in c++, a+b might be different to b+a, depending on the type of a and b
|
||||||
if (cpp && tok1->str() == "+" && tok1->astOperand2()) {
|
if (cpp && tok1->str() == "+" && tok1->isBinaryOp()) {
|
||||||
const ValueType* vt1 = tok1->astOperand1()->valueType();
|
const ValueType* vt1 = tok1->astOperand1()->valueType();
|
||||||
const ValueType* vt2 = tok1->astOperand2()->valueType();
|
const ValueType* vt2 = tok1->astOperand2()->valueType();
|
||||||
if (!(vt1 && (vt1->type >= ValueType::VOID || vt1->pointer) && vt2 && (vt2->type >= ValueType::VOID || vt2->pointer)))
|
if (!(vt1 && (vt1->type >= ValueType::VOID || vt1->pointer) && vt2 && (vt2->type >= ValueType::VOID || vt2->pointer)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool commutative = tok1->astOperand1() && tok1->astOperand2() && Token::Match(tok1, "%or%|%oror%|+|*|&|&&|^|==|!=");
|
const bool commutative = tok1->isBinaryOp() && Token::Match(tok1, "%or%|%oror%|+|*|&|&&|^|==|!=");
|
||||||
bool commutativeEquals = commutative &&
|
bool commutativeEquals = commutative &&
|
||||||
isSameExpression(cpp, macro, tok1->astOperand2(), tok2->astOperand1(), library, pure);
|
isSameExpression(cpp, macro, tok1->astOperand2(), tok2->astOperand1(), library, pure);
|
||||||
commutativeEquals = commutativeEquals &&
|
commutativeEquals = commutativeEquals &&
|
||||||
|
@ -398,9 +398,9 @@ bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * cons
|
||||||
return false;
|
return false;
|
||||||
if (isOppositeCond(true, cpp, tok1, tok2, library, pure))
|
if (isOppositeCond(true, cpp, tok1, tok2, library, pure))
|
||||||
return true;
|
return true;
|
||||||
if (tok1->str() == "-" && !tok1->astOperand2())
|
if (tok1->isUnaryOp("-"))
|
||||||
return isSameExpression(cpp, true, tok1->astOperand1(), tok2, library, pure);
|
return isSameExpression(cpp, true, tok1->astOperand1(), tok2, library, pure);
|
||||||
if (tok2->str() == "-" && !tok2->astOperand2())
|
if (tok2->isUnaryOp("-"))
|
||||||
return isSameExpression(cpp, true, tok2->astOperand1(), tok1, library, pure);
|
return isSameExpression(cpp, true, tok2->astOperand1(), tok1, library, pure);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -733,7 +733,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op)
|
||||||
if (!cpp)
|
if (!cpp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Token::Match(op, "&|>>") || !op->astOperand2())
|
if (!Token::Match(op, "&|>>") || !op->isBinaryOp())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Token::Match(op->astOperand2(), "%name%|.|*|[") && op->str() != op->astOperand2()->str())
|
if (!Token::Match(op->astOperand2(), "%name%|.|*|[") && op->str() != op->astOperand2()->str())
|
||||||
|
|
|
@ -309,8 +309,11 @@ public:
|
||||||
bool isBoolean() const {
|
bool isBoolean() const {
|
||||||
return mTokType == eBoolean;
|
return mTokType == eBoolean;
|
||||||
}
|
}
|
||||||
bool isUnaryOp() const {
|
bool isBinaryOp() const {
|
||||||
return astOperand1() != nullptr && astOperand2() == nullptr;
|
return astOperand1() != nullptr && astOperand2() != nullptr;
|
||||||
|
}
|
||||||
|
bool isUnaryOp(const std::string &s) const {
|
||||||
|
return s == mStr && astOperand1() != nullptr && astOperand2() == nullptr;
|
||||||
}
|
}
|
||||||
bool isUnaryPreOp() const;
|
bool isUnaryPreOp() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue