void ExprCompiler::visit(IfExpr& expr, int dest) { // Compile the condition. compile(expr.condition(), dest); // Leave a space for the test and jump instruction. int jumpToElse = startJump(expr); // Compile the then arm. compile(expr.thenArm(), dest); // Leave a space for the then arm to jump over the else arm. int jumpPastElse = startJump(expr); // Compile the else arm. endJump(jumpToElse, OP_JUMP_IF_FALSE, dest); if (!expr.elseArm().isNull()) { compile(expr.elseArm(), dest); } else { // A missing 'else' arm is implicitly 'nothing'. write(expr, OP_BUILT_IN, BUILT_IN_NOTHING, dest); } endJump(jumpPastElse, OP_JUMP, 1); }
void Resolver::visit(IfExpr& expr, int dummy) { Scope ifScope(this); // Resolve the condition. resolve(expr.condition()); // Resolve the then arm. Scope thenScope(this); resolve(expr.thenArm()); thenScope.end(); if (!expr.elseArm().isNull()) { Scope elseScope(this); resolve(expr.elseArm()); elseScope.end(); } ifScope.end(); }
Expr* IfExpr::clone() { IfExpr* ret = new IfExpr(*this); ret->cloneArgs(); return ret; }