Ejemplo n.º 1
0
        public void Visit(EachStatement eachStatement)
        {
            using (Scope.Push(_mainType))
            {
                var iterationArg = VisitChild(eachStatement.IterationVariable);
                var tableArg = VisitChild(eachStatement.TableReference);
                var rowType = iterationArg.Scope.CodeDomReference;

                CodeMemberMethod method = new CodeMemberMethod();
                method.Name = "Each_" + iterationArg.MethodIdentifier;
                method.Attributes = MemberAttributes.Private;
                GenerateCallStatement(method.Statements, eachStatement.Line.Line);

                var progressInc = new CodeAssignStatement(new CodePropertyReferenceExpression(null, "TotalOperations"),
                    new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(null, "TotalOperations"),
                    CodeBinaryOperatorType.Add,
                    new CodePropertyReferenceExpression(tableArg.CodeExpression, "RowCount"))
                    );

                method.Statements.Add(progressInc);
                method.Statements.Add(
                new CodeVariableDeclarationStatement(new CodeTypeReference("IEnumerator", rowType),
                    "x",
                new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(tableArg.CodeExpression, "GetCopyEnumerator",
                        null)))
                        );

                var loop = new CodeIterationStatement();
                loop.InitStatement = new CodeSnippetStatement();
                loop.IncrementStatement = new CodeSnippetStatement();
                loop.TestExpression = new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(new CodeTypeReferenceExpression("x"), "MoveNext",
                    null));

                var rowReference = VisitChild(new TableVariableRowReference() { Id = eachStatement.IterationVariable.Variable, Line = eachStatement.IterationVariable.Line });
                loop.Statements.Add(new CodeAssignStatement(rowReference.CodeExpression, new CodePropertyReferenceExpression(new CodeTypeReferenceExpression("x"), "Current")));

                var blockArgs = VisitChild(eachStatement.Block, new CodeDomArg() { Tag = true });
                loop.Statements.AddRange(blockArgs.ParentStatements);
                CallOnProgress(loop.Statements, false);

                method.Statements.Add(loop);
                var methodcall = new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(null, method.Name));

                _mainType.Type.Members.Add(method);
                _codeStack.Peek().ParentStatements.Add(methodcall);
                _codeStack.Peek().CodeExpression = methodcall;
            }
        }
Ejemplo n.º 2
0
        public void Visit(EachStatement eachStatement, CommonTree tree)
        {
            Parent(tree).Children.Add(eachStatement);
            SetLine(eachStatement, tree);

            eachStatement.IterationVariable = new VariableDeclarationStatement() { Variable = tree.GetChild(0).Text };
            SetLine(eachStatement.IterationVariable, tree.GetChild(0));

            var rowGetter = new TableVariableRowGetter() { Id = tree.GetChild(1).Text };
            SetLine(rowGetter, tree.GetChild(1));
            eachStatement.IterationVariable.Children.Add(rowGetter);

            eachStatement.TableReference = new TableVariableReference() { Id = tree.GetChild(1).Text };
            SetLine(eachStatement.TableReference, tree.GetChild(1));

            Visit(tree.GetChild(2));
        }