public object VisitWhileStatement(WhileStatementAst whileStatementAst)
        {
            var newCondition = VisitElement(whileStatementAst.Condition);
            var newBody      = VisitElement(whileStatementAst.Body);

            return(new WhileStatementAst(whileStatementAst.Extent, whileStatementAst.Label, newCondition, newBody));
        }
 public virtual StatementAst VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     return(new WhileStatementAst(
                whileStatementAst.Extent,
                whileStatementAst.Label,
                whileStatementAst.Condition?.Rewrite(this, SyntaxKind.Pipeline),
                whileStatementAst.Body?.Rewrite(this, SyntaxKind.StatementBlock)));
 }
        public void ProcessWhileStatement(WhileStatementAst whileStatement)
        {
            Guard.Against.Null(whileStatement, nameof(whileStatement));

            var conditionType = ProcessExpression(whileStatement.ConditionExpression);

            if (!(conditionType == DataType.Bool ||
                  conditionType == DataType.Double ||
                  conditionType == DataType.Long))
            {
                throw new SemanticException(
                          $"While condition should be of bool, double or long type. Provided: {conditionType}");
            }

            var doneLabel = new Instruction("nop");

            var startLabel = new Instruction("nop");

            if (CodeGenerationEnabled)
            {
                CurrentFunction.Builder.Bucket.Add(startLabel);
            }

            // cond-expr
            if (CodeGenerationEnabled)
            {
                CurrentFunction.Builder.Bucket.AddRange(ExpressionBucket.Pop());
            }

            // jump(if false) to done
            if (CodeGenerationEnabled)
            {
                CurrentFunction.Builder.Bucket.Add(new object[] { "br.false", doneLabel });
            }

            // # while-block
            EnterWhileDefination(new Builders.WhileBuilder(CurrentWhile, startLabel, doneLabel));

            ProcessBlockStatement(whileStatement.WhileBlock);

            LeaveWhileDefination();

            // jmp .START
            if (CodeGenerationEnabled)
            {
                CurrentFunction.Builder.Bucket.Add(Instruction.Pack("br", startLabel));
            }

            // .DONE:nop
            if (CodeGenerationEnabled)
            {
                CurrentFunction.Builder.Bucket.Add(doneLabel);
            }
        }
 public static WhileStatementAst Update(
     this WhileStatementAst ast,
     PipelineBaseAst condition = null,
     StatementBlockAst body    = null,
     string label = null)
 {
     return(new WhileStatementAst(
                ast.Extent,
                label ?? ast.Label,
                condition?.Clone() ?? ast.Condition?.Clone(),
                body?.Clone() ?? ast.Body?.Clone()));
 }
Exemple #5
0
        public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst)
        {
            explanations.Add(new Explanation()
            {
                Description     = $"While '{whileStatementAst.Condition.Extent.Text}' evaluates to true, execute the code in the block {{}}.",
                CommandName     = "While loop",
                HelpResult      = HelpTableQuery("about_while"),
                TextToHighlight = "while"
            }.AddDefaults(whileStatementAst, explanations));

            return(AstVisitAction.Continue);
        }
Exemple #6
0
 public override object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     if (whileStatementAst.Label != null)
     {
         script_.Write(":" + whileStatementAst.Label + " ");
     }
     script_.Write("while(");
     VisitElement(whileStatementAst.Condition);
     script_.Write("){");
     VisitElement(whileStatementAst.Body);
     script_.Write("}");
     return(whileStatementAst);
 }
        public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst)
        {
            var body      = VisitSyntaxNode(whileStatementAst.Body);
            var condition = VisitSyntaxNode(whileStatementAst.Condition);

            var block = body as Block;

            if (block == null)
            {
                block = new Block(body);
            }

            _currentNode = new While(condition, block);

            return(AstVisitAction.SkipChildren);
        }
 public object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Exemple #9
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     throw new NotImplementedException(); //VisitWhileStatement(whileStatementAst);
 }
Exemple #10
0
 public override StatementAst VisitWhileStatement(WhileStatementAst whileStatementAst)
 => VisitStatement(base.VisitWhileStatement(whileStatementAst));
Exemple #11
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst ast)
 {
     return(DoNextAction(ast));
 }
 object ICustomAstVisitor.VisitWhileStatement(WhileStatementAst whileStatementAst) => VisitWhileStatement(whileStatementAst);
Exemple #13
0
 public object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     Console.WriteLine("Visited an WhileStatementAst.");
     return(whileStatementAst);
 }
Exemple #14
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst ast)
 {
     return(AstVisitAction.Continue);
 }
Exemple #15
0
 public object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     throw new NotImplementedException();
 }
Exemple #16
0
 public object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     throw new UnexpectedElementException();
 }
 object ICustomAstVisitor.VisitWhileStatement(WhileStatementAst whileStatementAst)
 => ProcessRewriter(VisitWhileStatement, whileStatementAst);
Exemple #18
0
 /// <summary/>
 public virtual AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst) => DefaultVisit(whileStatementAst);
 public object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     return(false);
 }
 public object VisitWhileStatement(WhileStatementAst whileStatementAst) => null;
Exemple #21
0
 // WhileStatementAst Extension Methods
 // New Methods Available:
 // - CreateNodeFromAST(NodeDepth, NodePosition) => Creates a Node
 // - CreateChildNodes ($item in $collection) {} => Creates Child Nodes
 public static WhileNode CreateNodeFromAst(this WhileStatementAst _ast, int _depth, int _position, Node _parent, Tree _tree)
 {
     return(new WhileNode(_ast, _depth, _position, _parent, _tree));
 }
Exemple #22
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     Console.WriteLine("Visited an WhileStatementAst.");
     Console.WriteLine("    " + whileStatementAst.ToString().Replace(Environment.NewLine, Environment.NewLine + "    "));
     return(AstVisitAction.Continue);
 }
 public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     return(Visit(whileStatementAst));
 }
Exemple #24
0
 public virtual object VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     VisitElement(whileStatementAst.Condition);
     VisitElement(whileStatementAst.Body);
     return(whileStatementAst);
 }
 public virtual TResult VisitWhileStatement(WhileStatementAst whileStatementAst) => default(TResult);
Exemple #26
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst)
 {
     return(AstVisitAction.SkipChildren);
 }
Exemple #27
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst ast)
 {
     return(Check(ast));
 }
Exemple #28
0
 public static IEnumerable <Ast> GetChildAst(this WhileStatementAst _ast)
 {
     return(_ast.Body.FindAll(Args => Args is Ast && Args.Parent == _ast.Body, false));
 }
Exemple #29
0
 public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst) => VisitAst(whileStatementAst);