private int DetectUnreachableCode(Block block, Statement limit)
{
bool unreachable = false;
int idx = 0;
foreach (Statement stmt in block.Statements)
{
//HACK: __switch__ builtin function is hard to detect/handle
// within this context, let's ignore whatever is after __switch__
if (stmt is ExpressionStatement)
{
MethodInvocationExpression mie = (stmt as ExpressionStatement).Expression as MethodInvocationExpression;
if (null != mie && TypeSystem.BuiltinFunction.Switch == mie.Target.Entity)
return -1;//ignore followings
}
if (unreachable && stmt is LabelStatement)
return -1;
if (stmt == limit)
{
unreachable = true;
}
else if (unreachable)
{
Warnings.Add(
CompilerWarningFactory.UnreachableCodeDetected(stmt) );
return idx;
}
idx++;
}
return -1;
}