void EmitLogicalOperator(BinaryExpression node, OpCode brForValueType, OpCode brForRefType)
{
var type = GetExpressionType(node);
Visit(node.Left);
var lhsType = PopType();
if (lhsType != null && lhsType.IsValueType && !type.IsValueType)
{
// if boxing, first evaluate the value
// as it is and then box it...
Label evalRhs = _il.DefineLabel();
Label end = _il.DefineLabel();
Dup();
EmitToBoolIfNeeded(node.Left); // may need to convert decimal to bool
_il.Emit(brForValueType, evalRhs);
EmitCastIfNeeded(type, lhsType);
_il.Emit(OpCodes.Br_S, end);
_il.MarkLabel(evalRhs);
_il.Emit(OpCodes.Pop);
LoadExpressionWithType(type, node.Right);
_il.MarkLabel(end);
}
else
{
Label end = _il.DefineLabel();
EmitCastIfNeeded(type, lhsType);
Dup();
EmitToBoolIfNeeded(node.Left);
_il.Emit(brForRefType, end);
_il.Emit(OpCodes.Pop);
LoadExpressionWithType(type, node.Right);
_il.MarkLabel(end);
}
PushType(type);
}