static AstNode RemoveUnreachableCode(AstFor forStatement, bool inList)
    {
        if (forStatement.Condition == null ||
            TypeConverter.ToBoolean(forStatement.Condition.ConstValue() ?? AstTrue.Instance))
        {
            return(forStatement);
        }

        var declarations = GetDeclarations(forStatement.Body);

        if (forStatement.Init == null)
        {
            return(declarations ?? Remove);
        }

        var statement = forStatement.Init is AstStatement
            ? forStatement.Init
            : new AstSimpleStatement(forStatement.Init);

        if (declarations == null)
        {
            return(statement);
        }
        var statements = new StructList <AstNode>();

        statements.Add(statement);
        statements.Add(declarations);
        return(inList
            ? SpreadStructList(ref statements)
            : new AstBlock(forStatement)
        {
            Body = statements
        });
    }
示例#2
0
 public void WriteFor(AstFor a)
 {
     Write(a.Source);
     Write(a.OptionalInitializer);
     Write(a.OptionalCondition);
     Write(a.OptionalIncrement);
     Write(a.OptionalBody);
 }