From c4e22b86278f59af25cbb9a6a02b416c7f555f57 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sun, 2 Jun 2013 00:05:26 +0200 Subject: [PATCH] More exception handling ... --- src/AST/CodeGenVisitor.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/AST/CodeGenVisitor.cpp b/src/AST/CodeGenVisitor.cpp index f8488db..a3eabaf 100644 --- a/src/AST/CodeGenVisitor.cpp +++ b/src/AST/CodeGenVisitor.cpp @@ -79,7 +79,11 @@ void CodeGenVisitor::visit(ConstantExpression* e) { } void CodeGenVisitor::visit(ExpressionStatement* e) { + value_ = 0; e->getExpr()->accept(this); + if (!value_) { + throw "error evaluating expression"; + } } void CodeGenVisitor::visit(ForStatement* e) @@ -87,7 +91,11 @@ void CodeGenVisitor::visit(ForStatement* e) value_ = 0; e->getInit()->accept(this); + value_ = 0; e->getCond()->accept(this); + if (!value_) { + throw "error evaluating expression"; + } llvm::Function* f = builder_->GetInsertBlock()->getParent(); llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f); @@ -97,20 +105,14 @@ void CodeGenVisitor::visit(ForStatement* e) value_ = 0; e->getStmt()->accept(this); - if (value_ == 0) { - // throw err - } value_ = 0; e->getStep()->accept(this); - if (value_ == 0) { - // throw err - } value_ = 0; e->getCond()->accept(this); - if (value_ == 0) { - // throw err + if (!value_) { + throw "error evaluating expression"; } llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);