public override void OnReturnStatement(ReturnStatement node)
{
EmitDebugInfo(node);
var retOpCode = _tryBlock > 0 ? OpCodes.Leave : OpCodes.Br;
var label = _returnLabel;
var expression = node.Expression;
if (expression != null)
{
++_returnStatements;
LoadExpressionWithType(_returnType, expression);
if (retOpCode == OpCodes.Leave)
{
//`leave' clears the stack, so we have to store return value temporarily
//we can use a default value holder for that since it won't be read afterwards
//of course this is necessary only if return type is not void
LocalBuilder temp = GetDefaultValueHolder(_returnType);
_il.Emit(OpCodes.Stloc, temp);
label = _leaveLabel;
_hasLeaveWithStoredValue = true;
}
}
else if (_returnType != TypeSystemServices.VoidType)
{
_returnImplicit = true;
label = _implicitLabel;
}
if (_method.Body.LastStatement != node)
_il.Emit(retOpCode, label);
else if (null != expression)
_returnStatements = -1; //instruct epilogue to branch last ret only if necessary
}