]> granicus.if.org Git - clang/commitdiff
Commit beginnings of int evaluator. Currently not used.
authorAnders Carlsson <andersca@mac.com>
Tue, 8 Jul 2008 05:13:58 +0000 (05:13 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 8 Jul 2008 05:13:58 +0000 (05:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53219 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp

index ea9b106b69d9eaf02aad1ce2801a28807e43255a..8b116ae4963f0b9b67a27f7230b0903dbf784573 100644 (file)
 #include "clang/AST/APValue.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/STmtVisitor.h"
+#include "llvm/Support/Compiler.h"
 
 using namespace clang;
 
+#define USE_NEW_EVALUATOR 0
 
 static bool CalcFakeICEVal(const Expr* Expr,
                            llvm::APSInt& Result,
@@ -47,14 +50,51 @@ static bool CalcFakeICEVal(const Expr* Expr,
   return false;
 }
 
+namespace {
+class VISIBILITY_HIDDEN IntExprEvaluator
+  : public StmtVisitor<IntExprEvaluator, APValue> {
+  ASTContext &Ctx;
+
+  IntExprEvaluator(ASTContext &ctx)
+    : Ctx(ctx) {}
+
+public:
+  static bool Evaluate(const Expr* E, APValue& Result, ASTContext &Ctx) {
+    Result = IntExprEvaluator(Ctx).Visit(const_cast<Expr*>(E));
+    return Result.isSInt();
+  }
+    
+  //===--------------------------------------------------------------------===//
+  //                            Visitor Methods
+  //===--------------------------------------------------------------------===//
+  APValue VisitStmt(Stmt *S) {
+    // FIXME: Remove this when we support more expressions.
+    printf("Unhandled statement\n");
+    S->dump();  
+    return APValue();
+  }
+  
+  APValue VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr()); }
+
+};    
+}
+  
 bool Expr::tryEvaluate(APValue& Result, ASTContext &Ctx) const
 {
   llvm::APSInt sInt(1);
   
+#if USE_NEW_EVALUATOR
+  if (getType()->isIntegerType())
+    return IntExprEvaluator::Evaluate(this, Result, Ctx);
+  else
+    return false;
+    
+#else
   if (CalcFakeICEVal(this, sInt, Ctx)) {
     Result = APValue(sInt);
     return true;
   }
+#endif
   
   return false;
 }