From: Craig Topper Date: Sun, 13 Dec 2015 05:41:37 +0000 (+0000) Subject: [Sema] Write some checks for groups of BinaryOperatorKinds in terms of the predicates... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3c545040f62bc405dd0fa7cae8bb57726ff533f;p=clang [Sema] Write some checks for groups of BinaryOperatorKinds in terms of the predicates already available in BinaryOperator. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255449 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 58fc4e1ead..c24a5c3c64 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -3034,7 +3034,10 @@ public: /// predicates to categorize the respective opcodes. bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } - bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } + static bool isMultiplicativeOp(Opcode Opc) { + return Opc >= BO_Mul && Opc <= BO_Rem; + } + bool isMultiplicativeOp() const { return isMultiplicativeOp(getOpcode()); } static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2852020e42..1b3f8dab3f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6523,7 +6523,9 @@ static void SuggestParentheses(Sema &Self, SourceLocation Loc, } static bool IsArithmeticOp(BinaryOperatorKind Opc) { - return Opc >= BO_Mul && Opc <= BO_Shr; + return BinaryOperator::isAdditiveOp(Opc) || + BinaryOperator::isMultiplicativeOp(Opc) || + BinaryOperator::isShiftOp(Opc); } /// IsArithmeticBinaryExpr - Returns true if E is an arithmetic binary @@ -6569,10 +6571,6 @@ static bool IsArithmeticBinaryExpr(Expr *E, BinaryOperatorKind *Opcode, return false; } -static bool IsLogicOp(BinaryOperatorKind Opc) { - return (Opc >= BO_LT && Opc <= BO_NE) || (Opc >= BO_LAnd && Opc <= BO_LOr); -} - /// ExprLooksBoolean - Returns true if E looks boolean, i.e. it has boolean type /// or is a logical expression such as (x==y) which has int type, but is /// commonly interpreted as boolean. @@ -6582,7 +6580,7 @@ static bool ExprLooksBoolean(Expr *E) { if (E->getType()->isBooleanType()) return true; if (BinaryOperator *OP = dyn_cast(E)) - return IsLogicOp(OP->getOpcode()); + return OP->isComparisonOp() || OP->isLogicalOp(); if (UnaryOperator *OP = dyn_cast(E)) return OP->getOpcode() == UO_LNot; if (E->getType()->isPointerType())