diff options
author | Anders Carlsson <andersca@mac.com> | 2008-07-08 05:13:58 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-07-08 05:13:58 +0000 |
commit | 0a1707c6ba820b1ff85acdecb9ba9f6509e7c9e3 (patch) | |
tree | 702cc8fdd1b92371289957ddf84d9ddd253669b5 /clang/lib/AST/ExprConstant.cpp | |
parent | fc12d2e5f33a8da682097f42390d6ef2e324347b (diff) | |
download | bcm5719-llvm-0a1707c6ba820b1ff85acdecb9ba9f6509e7c9e3.tar.gz bcm5719-llvm-0a1707c6ba820b1ff85acdecb9ba9f6509e7c9e3.zip |
Commit beginnings of int evaluator. Currently not used.
llvm-svn: 53219
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index ea9b106b69d..8b116ae4963 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -14,9 +14,12 @@ #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; } |