示例#1
0
        //this method returns -1 if it doesn't detect unreachable code
        //else it returns the index of the first unreachable in block.Statements
        private int DetectUnreachableCode(Block block, Statement limit)
        {
            var unreachable = false;
            var idx         = 0;

            foreach (var stmt in block.Statements)
            {
                //HACK: __switch__ builtin function is hard to detect/handle
                //		within this context, let's ignore whatever is after __switch__
                if (IsSwitchBuiltin(stmt))
                {
                    return(-1);                   //ignore followings
                }
                if (unreachable && stmt is LabelStatement)
                {
                    return(-1);
                }

                if (stmt == limit)
                {
                    unreachable = true;
                }
                else if (unreachable)
                {
                    if (!stmt.IsSynthetic)
                    {
                        Warnings.Add(CompilerWarningFactory.UnreachableCodeDetected(stmt));
                    }
                    return(idx);
                }

                idx++;
            }
            return(-1);
        }
示例#2
0
        //this method returns -1 if it doesn't detect unreachable code
        //else it returns the index of the first unreachable in block.Statements
        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__
                ExpressionStatement est = stmt as ExpressionStatement;
                if (null != est)
                {
                    MethodInvocationExpression mie = est.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);
        }