コード例 #1
0
ファイル: JWriter.cs プロジェクト: wangchengqun/Cs2Java
 public void VisitsForStatement(JForStatement node)
 {
     Write("for");
     Write("(");
     if (node.Initializers != null)
     {
         VisitEachJoin(ExtractExpressions(node.Initializers), WriteComma);
     }
     Write(";");
     if (node.Condition != null)
     {
         Visit(node.Condition);
     }
     Write(";");
     if (node.Iterators != null)
     {
         var exps = ExtractExpressions(node.Iterators);
         VisitEachJoin(exps, WriteComma);
     }
     Write(")");
     if (OpenBraceInNewLine)
     {
         InnerWriter.WriteLine();
     }
     IndentVisitIfNeeded(node.Statement);
 }
コード例 #2
0
        public JNode VisitForStatement(ForStatement node)
        {
            var node2 = new JForStatement
            {
                Condition = VisitExpression(node.Condition),
                Statement = VisitStatement(node.EmbeddedStatement),
            };

            if (node.Iterators != null)
            {
                node2.Iterators = VisitStatements(node.Iterators);
            }
            if (node.Initializers != null)
            {
                node2.Initializers = VisitStatements(node.Initializers);
            }
            return(node2);
        }
コード例 #3
0
        public JNode VisitForeachStatement_old(ForeachStatement node)
        {
            if (node.InExpression != null)
            {
                var expRes       = node.InExpression.Resolve();
                var et           = expRes.Type.GetDefinitionOrArrayType(Compiler);
                var iteratorType = expRes.Type;
                //var et = node.expression.entity_typeref.GetEntityType();
                if (et != null)
                {
                    var jta = JMeta.GetJsTypeAttribute(et);
                    if (jta != null && jta.NativeEnumerator)
                    {
                        var node2 = new JForInStatement
                        {
                            Initializer = J.Var(node.VariableName, node.Resolve().Type.JAccess()),
                            Member      = VisitExpression(node.InExpression),
                            Statement   = VisitStatement(node.EmbeddedStatement)
                        };
                        return(node2);
                    }
                    else if (jta != null && jta.NativeArrayEnumerator)
                    {
                        VariableIteratorCounter++;
                        var iteratorName    = "$i" + VariableIteratorCounter;
                        var lengthCacheName = "$l" + VariableIteratorCounter;
                        var exp2            = VisitExpression(node.InExpression);
                        var target          = exp2;
                        var targetCacheName = "$t" + VariableIteratorCounter;
                        if (exp2 is JMemberExpression || ((JMemberExpression)exp2).PreviousMember != null)//is not simple name
                        {
                            target = J.Member(targetCacheName);
                        }
                        var itemAccess = target.IndexerAccess(J.Member(iteratorName));
                        var node2      = new JForStatement();

                        node2.Condition = J.Member(iteratorName).LessThan(J.Member(lengthCacheName));
                        node2.Iterators = new List <JStatement> {
                            J.Member(iteratorName).PlusPlus().Statement(), J.Member(node.VariableName).Assign(itemAccess).Statement()
                        };
                        if (target != exp2)//use target caching
                        {
                            node2.Initializers = new List <JStatement> {
                                J.Var(iteratorName, iteratorType.JAccess(), J.Value(0)).AndVar(targetCacheName, exp2).AndVar(lengthCacheName, target.Member("length")).AndVar(node.VariableName, itemAccess).Statement()
                            };
                        }
                        else
                        {
                            node2.Initializers = new List <JStatement> {
                                J.Var(iteratorName, iteratorType.JAccess(), J.Value(0)).AndVar(lengthCacheName, exp2.Member("length")).AndVar(node.VariableName, itemAccess).Statement()
                            };
                        }
                        node2.Statement = VisitStatement(node.EmbeddedStatement);
                        return(node2);
                    }
                }
            }

            var iteratorName2 = "$it" + VariableIteratorCounter;

            VariableIteratorCounter++;
            var    node3               = J.Var(iteratorName2, node.Resolve().Type.JAccess(), VisitExpression(node.InExpression).Member("GetEnumerator").Invoke()).Statement();
            var    whileNode           = J.While(J.Member(iteratorName2).Member("MoveNext").Invoke());
            var    getCurrentStatement = J.Var(node.VariableName, node.Resolve().Type.JAccess(), J.Member(iteratorName2).Member("get_Current").Invoke()).Statement();
            var    jsStatement         = VisitStatement(node.EmbeddedStatement);
            JBlock block;

            if (jsStatement is JBlock)
            {
                block = (JBlock)jsStatement;
            }
            else
            {
                block = J.Block().Add(jsStatement);
            }
            block.Statements.Insert(0, getCurrentStatement);
            whileNode.Statement = block;

            var block2 = J.Block().Add(node3).Add(whileNode);

            return(block2);
        }
コード例 #4
0
ファイル: JWriter.cs プロジェクト: wangchengqun/Cs2Java
 public void VisitForStatement(JForStatement node)
 {
     throw new NotImplementedException();
 }