[cfe-commits] r59421 - /cfe/trunk/lib/AST/ExprConstant.cpp

Nuno Lopes nunoplopes at sapo.pt
Sun Nov 16 11:28:32 PST 2008


Author: nlopes
Date: Sun Nov 16 13:28:31 2008
New Revision: 59421

URL: http://llvm.org/viewvc/llvm-project?rev=59421&view=rev
Log:
make IntExprEvaluator fold the ?: operator

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=59421&r1=59420&r2=59421&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 16 13:28:31 2008
@@ -397,6 +397,7 @@
   bool VisitCallExpr(const CallExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
+  bool VisitConditionalOperator(const ConditionalOperator *E);
 
   bool VisitCastExpr(CastExpr* E) {
     return HandleCast(E->getLocStart(), E->getSubExpr(), E->getType());
@@ -725,6 +726,14 @@
   return true;
 }
 
+bool IntExprEvaluator::VisitConditionalOperator(const ConditionalOperator *E) {
+  llvm::APSInt Cond(32);
+  if (!EvaluateInteger(E->getCond(), Cond, Info))
+    return false;
+
+  return Visit(Cond != 0 ? E->getTrueExpr() : E->getFalseExpr());
+}
+
 /// VisitSizeAlignOfExpr - Evaluate a sizeof or alignof with a result as the
 /// expression's type.
 bool IntExprEvaluator::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {





More information about the cfe-commits mailing list