[cfe-commits] r43322 - in /cfe/trunk: AST/Expr.cpp CodeGen/CGExprComplex.cpp CodeGen/CGExprScalar.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Expr.h

Chris Lattner sabre at nondot.org
Wed Oct 24 17:29:32 PDT 2007


Author: lattner
Date: Wed Oct 24 19:29:32 2007
New Revision: 43322

URL: http://llvm.org/viewvc/llvm-project?rev=43322&view=rev
Log:
Add a new ChooseExpr::isConditionTrue method to unify
some code.

Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/CodeGen/CGExprComplex.cpp
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=43322&r1=43321&r2=43322&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Wed Oct 24 19:29:32 2007
@@ -894,6 +894,14 @@
   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
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprComplex.cpp?rev=43322&r1=43321&r2=43322&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/CodeGen/CGExprComplex.cpp Wed Oct 24 19:29:32 2007
@@ -499,12 +499,8 @@
 }
 
 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());
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=43322&r1=43321&r2=43322&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Wed Oct 24 19:29:32 2007
@@ -903,12 +903,8 @@
 }
 
 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)

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43322&r1=43321&r2=43322&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Wed Oct 24 19:29:32 2007
@@ -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 = "";

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=43322&r1=43321&r2=43322&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Oct 24 19:29:32 2007
@@ -961,6 +961,10 @@
       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]; }





More information about the cfe-commits mailing list