public virtual void Visit(RppLogicalBinOp node) { }
public override void Visit(RppLogicalBinOp node) { // _targetLabel doesn't contain value if logical op is not used from 'if' or 'while' // e.g. k = i > 5 && k < 0 var targetLabel = _targetLabel ?? _body.DefineLabel(); if (node.Op == "&&") { if (_onTrue) { Label test_end = _body.DefineLabel(); EmitBranchableAndJumpOnResult(node.Left, test_end, false); EmitBranchableAndJumpOnResult(node.Right, targetLabel, true); _body.MarkLabel(test_end); } else { EmitBranchableAndJumpOnResult(node.Left, targetLabel, false); EmitBranchableAndJumpOnResult(node.Right, targetLabel, false); } } else if (node.Op == "||") { if (_onTrue) { EmitBranchableAndJumpOnResult(node.Left, targetLabel, true); EmitBranchableAndJumpOnResult(node.Right, targetLabel, true); } else { Label test_end = _body.DefineLabel(); EmitBranchableAndJumpOnResult(node.Left, test_end, true); EmitBranchableAndJumpOnResult(node.Right, targetLabel, false); _body.MarkLabel(test_end); } } else { throw new NotImplementedException(); } // Create epilogue only is target label wasn't defined, so we return a bool if (!_targetLabel.HasValue) { Label endLabel = _body.DefineLabel(); _body.Emit(OpCodes.Ldc_I4_1); _body.Emit(OpCodes.Br_S, endLabel); _body.MarkLabel(targetLabel); _body.Emit(OpCodes.Ldc_I4_0); _body.MarkLabel(endLabel); } }
public override void Visit(RppLogicalBinOp node) { node.Left.Accept(this); node.Right.Accept(this); }