]> granicus.if.org Git - clang/commitdiff
Add a new ChooseExpr::isConditionTrue method to unify
authorChris Lattner <sabre@nondot.org>
Thu, 25 Oct 2007 00:29:32 +0000 (00:29 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 25 Oct 2007 00:29:32 +0000 (00:29 +0000)
some code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43322 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
CodeGen/CGExprComplex.cpp
CodeGen/CGExprScalar.cpp
clang.xcodeproj/project.pbxproj
include/clang/AST/Expr.h

index d6960d35e275791851ee100eb56246995deb80da..0c631df5c04f90da9fea94eb8f773f69965ef678 100644 (file)
@@ -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
 //===----------------------------------------------------------------------===//
index f27519c8f5752641223afc83aa3f263875bfde72..aa66bb6dfbf4eb5f037775b054d3c6fa74f890a2 100644 (file)
@@ -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());
 }
 
 //===----------------------------------------------------------------------===//
index 4b45980d7e72b2d744971df47ef49ecd2da36180..0d86ccc02245b25db78f103b85de7bc015ff1414 100644 (file)
@@ -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)
index b086e54ce30adcddc328c186a208d99e0dba4bd0..f2f79456e88d86e92ae82c87c8f3de156f055f91 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index b43d8a42a9009525334a9d7482a1eee964b5e40a..819996ba12ff8f349d7dd70c28f9073cd90cfc24 100644 (file)
@@ -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]; }