Beispiel #1
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));
        }
Beispiel #2
0
        /// <summary>
        /// Parser for EachStatement
        /// </summary>
        /// <returns>Parsed EachStatement</returns>
        public EachStatement ParseEachStatement()
        {
            EachStatement eachStatement = new EachStatement();

            //Skip each token
            NextToken("each", "each (identifier : expression) Statement", "each");

            //Skip ( token
            NextToken("(", "each (identifier : expression) Statement", '(');

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            eachStatement.SetIdentifier(CurrentToken.GetValue().ToString());

            //Skip : token
            NextToken(":", "each (identifier : expression) Statement", ':');

            //Parse expression
            eachStatement.SetExpression(expressionParser.ParseExpression());

            //Skip ) token
            NextToken(")", "each (identifier : expression) Statement", ')');

            //Parse statement
            eachStatement.SetStatement(ParseStatement());

            return(eachStatement);
        }
Beispiel #3
0
        /// <summary>
        /// Interpret EachStatement
        /// </summary>
        /// <param name="statement">EachStatement to interpret</param>
        public override void Visit(EachStatement statement)
        {
            //If no root element, create one
            if (Root == null)
            {
                XHTMLElement newRoot = new XHTMLElement("html", null, true);
                Root    = newRoot;
                Current = Root;
            }

            Expression expr = statement.GetExpression();

            //Different looping with different expression types
            if (expr is ListExpression)
            {   //Iterate through list
                ListExpression listExpression = (ListExpression)expr;

                //Iterate through list with expression
                XHTMLElement temp = Current;
                foreach (Expression currentExpr in listExpression.GetExpressions())
                {
                    Current = temp;

                    //New scope
                    SymbolTable = new SymbolTable(SymbolTable);

                    //Define variable and interpret statement with this scope
                    SymbolTable.AddVariableDefinition(statement.GetIdentifier(), currentExpr);
                    statement.GetStatement().AcceptVisitor(this);

                    //Return to parent scope
                    SymbolTable = SymbolTable.GetParentSymbolTable();
                }
            }
            else if (expr is FieldExpression)
            {   //Get expression in referenced record
                Expression expression = GetExpression((FieldExpression)expr);

                //Visit each for expression
                EachStatement eachStatement = new EachStatement();
                eachStatement.SetExpression(expression);
                eachStatement.SetStatement(statement.GetStatement());
                eachStatement.SetIdentifier(statement.GetIdentifier());
                Visit(eachStatement);
            }
            else if (expr is VarExpression)
            {   //Get expression of variable
                Expression expression = SymbolTable.GetVariableDefinition(((VarExpression)expr).GetVariableIdentifier());

                //Visit each for expression
                EachStatement eachStatement = new EachStatement();
                eachStatement.SetExpression(expression);
                eachStatement.SetStatement(statement.GetStatement());
                eachStatement.SetIdentifier(statement.GetIdentifier());
                Visit(eachStatement);
            }
        }
        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;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Visit EachStatement
        /// </summary>
        /// <param name="statement">EachStatement to check</param>
        public override void Visit(EachStatement statement)
        {
            CreateChildSymbolTable();

            //Store variable of Each = IdCon : Expression
            SymbolTable.AddVariableDefinition(statement.GetIdentifier(), statement.GetExpression());

            //Visit statement
            statement.GetStatement().AcceptVisitor(this);

            MoveToParentSymbolTable();
        }
Beispiel #6
0
 public virtual void Visit(EachStatement statement)
 {
     VisitSubNodes(statement);
 }