public virtual void VisitStatementFor(StatementFor node, TContext context)
 {
     this.Visit(node.Init, context);
     this.Visit(node.Condition, context);
     this.Visit(node.Increment, context);
     this.Visit(node.Body, context);
 }
 public override void VisitStatementFor(StatementFor node, CloningAstVisitorContext context)
 {
     context.Result = new StatementFor()
     {
         Init      = this.CloneNode(node.Init, context),
         Condition = this.CloneNode(node.Condition, context),
         Body      = this.CloneNode(node.Body, context),
         Increment = this.CloneNode(node.Increment, context)
     };
 }
Example #3
0
 public override void VisitStatementFor(StatementFor node, SemanticModelBuilderContext context)
 {
     this.Visit(node.Init, context);
     this.Visit(node.Condition, context);
     this.Visit(node.Increment, context);
     if (node.Body != null)
     {
         context.EnterNewScope(node.Body);
         this.Visit(node.Body, context);
         context.ExitScope();
     }
 }
 public override void VisitStatementFor(StatementFor node, AstPrinterContext context)
 {
     context.Write("for (");
     this.Visit(node.Init, context);
     context.Write("; ");
     this.Visit(node.Condition, context);
     context.Write("; ");
     this.Visit(node.Increment, context);
     context.Write(")");
     context.StartNewLine();
     this.Visit(node.Body, context);
 }
        public override AstNode VisitIteration_statement([NotNull] GLSL_ES300Parser.Iteration_statementContext context)
        {
            if (context.While() != null)
            {
                var w = new StatementWhile();
                if (context.condition().fully_specified_type() != null)
                {
                    throw new NotSupportedException($"Expression is not supported as condition for 'while' loop: {context.condition().GetText()}");
                }

                w.Condition = (Expression)this.Visit(context.condition().expression());
                w.Body      = (Statement)this.Visit(context.statement());
                return(w);
            }

            if (context.Do() != null)
            {
                var d = new StatementDo();
                d.Body      = (Statement)this.Visit(context.statement());
                d.Condition = (Expression)this.Visit(context.expression());
                return(d);
            }

            var f    = new StatementFor();
            var init = context.for_init_statement();

            f.Init = init.expression_statement() != null ? (Statement)this.Visit(init.expression_statement()) : (Statement)this.Visit(init.declaration_statement());
            var rest      = context.for_rest_statement();
            var condition = rest.condition();

            if (condition != null)
            {
                if (condition.fully_specified_type() != null)
                {
                    throw new NotSupportedException($"Expression is not supported as condition for 'for' loop: {condition.GetText()}");
                }

                f.Condition = (Expression)this.Visit(condition.expression());
            }

            var incr = rest.expression();

            if (incr != null)
            {
                f.Increment = (Expression)this.Visit(incr);
            }

            f.Body = (Statement)this.Visit(context.statement());

            return(f);
        }