aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2011-08-10 22:41:34 +0000
committerRichard Trieu <rtrieu@google.com>2011-08-10 22:41:34 +0000
commit70979d4de873382d0ba13b5bd8fb3ee797384582 (patch)
treef1897ec8949223afb051b4d45e3a2b79d4a05034 /lib/Sema/SemaExpr.cpp
parenta6d1e7623a9b7bd60779275c42827951a892993b (diff)
Refactoring of DiagnoseBitwisePrecedence() in SemaExpr.cpp to reduce code duplication.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp48
1 files changed, 22 insertions, 26 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index f55a6babd8..1f0e518afe 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -7776,32 +7776,28 @@ static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc,
(BinOp::isComparisonOp(rhsopc) || BinOp::isBitwiseOp(rhsopc)))
return;
- if (BinOp::isComparisonOp(lhsopc)) {
- Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
- << SourceRange(lhs->getLocStart(), OpLoc)
- << BinOp::getOpcodeStr(Opc) << BinOp::getOpcodeStr(lhsopc);
- SuggestParentheses(Self, OpLoc,
- Self.PDiag(diag::note_precedence_bitwise_silence)
- << BinOp::getOpcodeStr(lhsopc),
- lhs->getSourceRange());
- SuggestParentheses(Self, OpLoc,
- Self.PDiag(diag::note_precedence_bitwise_first)
- << BinOp::getOpcodeStr(Opc),
- SourceRange(cast<BinOp>(lhs)->getRHS()->getLocStart(), rhs->getLocEnd()));
- } else if (BinOp::isComparisonOp(rhsopc)) {
- Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
- << SourceRange(OpLoc, rhs->getLocEnd())
- << BinOp::getOpcodeStr(Opc) << BinOp::getOpcodeStr(rhsopc);
- SuggestParentheses(Self, OpLoc,
- Self.PDiag(diag::note_precedence_bitwise_silence)
- << BinOp::getOpcodeStr(rhsopc),
- rhs->getSourceRange());
- SuggestParentheses(Self, OpLoc,
- Self.PDiag(diag::note_precedence_bitwise_first)
- << BinOp::getOpcodeStr(Opc),
- SourceRange(lhs->getLocStart(),
- cast<BinOp>(rhs)->getLHS()->getLocStart()));
- }
+ bool isLeftComp = BinOp::isComparisonOp(lhsopc);
+ bool isRightComp = BinOp::isComparisonOp(rhsopc);
+ if (!isLeftComp && !isRightComp) return;
+
+ SourceRange DiagRange = isLeftComp ? SourceRange(lhs->getLocStart(), OpLoc)
+ : SourceRange(OpLoc, rhs->getLocEnd());
+ std::string OpStr = isLeftComp ? BinOp::getOpcodeStr(lhsopc)
+ : BinOp::getOpcodeStr(rhsopc);
+ SourceRange ParensRange = isLeftComp ?
+ SourceRange(cast<BinOp>(lhs)->getRHS()->getLocStart(),
+ rhs->getLocEnd())
+ : SourceRange(lhs->getLocStart(),
+ cast<BinOp>(rhs)->getLHS()->getLocStart());
+
+ Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
+ << DiagRange << BinOp::getOpcodeStr(Opc) << OpStr;
+ SuggestParentheses(Self, OpLoc,
+ Self.PDiag(diag::note_precedence_bitwise_silence) << OpStr,
+ rhs->getSourceRange());
+ SuggestParentheses(Self, OpLoc,
+ Self.PDiag(diag::note_precedence_bitwise_first) << BinOp::getOpcodeStr(Opc),
+ ParensRange);
}
/// \brief It accepts a '&' expr that is inside a '|' one.