From 35e564ed09d57b6ceae9022afaa77635b16da53e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 25 Oct 2007 00:29:32 +0000 Subject: [PATCH] Add a new ChooseExpr::isConditionTrue method to unify some code. llvm-svn: 43322 --- clang/AST/Expr.cpp | 8 ++++++++ clang/CodeGen/CGExprComplex.cpp | 6 +----- clang/CodeGen/CGExprScalar.cpp | 6 +----- clang/clang.xcodeproj/project.pbxproj | 1 - clang/include/clang/AST/Expr.h | 4 ++++ 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp index d6960d35e275..0c631df5c04f 100644 --- a/clang/AST/Expr.cpp +++ b/clang/AST/Expr.cpp @@ -894,6 +894,14 @@ ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, RBracloc = RBrac; } + +bool ChooseExpr::isConditionTrue(ASTContext &C) const { + llvm::APSInt CondVal(32); + bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C); + assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst; + return CondVal != 0; +} + //===----------------------------------------------------------------------===// // Child Iterators for iterating over subexpressions/substatements //===----------------------------------------------------------------------===// diff --git a/clang/CodeGen/CGExprComplex.cpp b/clang/CodeGen/CGExprComplex.cpp index f27519c8f575..aa66bb6dfbf4 100644 --- a/clang/CodeGen/CGExprComplex.cpp +++ b/clang/CodeGen/CGExprComplex.cpp @@ -499,12 +499,8 @@ VisitConditionalOperator(const ConditionalOperator *E) { } ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) { - llvm::APSInt CondVal(32); - bool IsConst = E->getCond()->isIntegerConstantExpr(CondVal, CGF.getContext()); - assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst; - // Emit the LHS or RHS as appropriate. - return Visit(CondVal != 0 ? E->getLHS() : E->getRHS()); + return Visit(E->isConditionTrue(CGF.getContext()) ? E->getLHS() :E->getRHS()); } //===----------------------------------------------------------------------===// diff --git a/clang/CodeGen/CGExprScalar.cpp b/clang/CodeGen/CGExprScalar.cpp index 4b45980d7e72..0d86ccc02245 100644 --- a/clang/CodeGen/CGExprScalar.cpp +++ b/clang/CodeGen/CGExprScalar.cpp @@ -903,12 +903,8 @@ VisitConditionalOperator(const ConditionalOperator *E) { } Value *ScalarExprEmitter::VisitChooseExpr(ChooseExpr *E) { - llvm::APSInt CondVal(32); - bool IsConst = E->getCond()->isIntegerConstantExpr(CondVal, CGF.getContext()); - assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst; - // Emit the LHS or RHS as appropriate. - return Visit(CondVal != 0 ? E->getLHS() : E->getRHS()); + return Visit(E->isConditionTrue(CGF.getContext()) ? E->getLHS() : E->getRHS()); } Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) diff --git a/clang/clang.xcodeproj/project.pbxproj b/clang/clang.xcodeproj/project.pbxproj index b086e54ce30a..f2f79456e88d 100644 --- a/clang/clang.xcodeproj/project.pbxproj +++ b/clang/clang.xcodeproj/project.pbxproj @@ -750,7 +750,6 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; - compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; projectDirPath = ""; diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index b43d8a42a900..819996ba12ff 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -961,6 +961,10 @@ public: SubExprs[RHS] = rhs; } + /// isConditionTrue - Return true if the condition is true. This is always + /// statically knowable for a well-formed choosexpr. + bool isConditionTrue(ASTContext &C) const; + Expr *getCond() const { return SubExprs[COND]; } Expr *getLHS() const { return SubExprs[LHS]; } Expr *getRHS() const { return SubExprs[RHS]; }