Ejemplo n.º 1
0
        public object VisitIfStatement(IfStatementAst ifStmtAst)
        {
            Block next  = new Block();
            int   count = ifStmtAst.Clauses.Count;

            for (int i = 0; i < count; i++)
            {
                Tuple <PipelineBaseAst, StatementBlockAst> tuple = ifStmtAst.Clauses[i];
                bool  flag   = (i == (count - 1)) && (ifStmtAst.ElseClause == null);
                Block block2 = new Block();
                Block block3 = flag ? next : new Block();
                tuple.Item1.Accept(this);
                this._currentBlock.FlowsTo(block2);
                this._currentBlock.FlowsTo(block3);
                this._currentBlock = block2;
                tuple.Item2.Accept(this);
                this._currentBlock.FlowsTo(next);
                this._currentBlock = block3;
            }
            if (ifStmtAst.ElseClause != null)
            {
                ifStmtAst.ElseClause.Accept(this);
                this._currentBlock.FlowsTo(next);
            }
            this._currentBlock = next;
            return(null);
        }
Ejemplo n.º 2
0
    public System.Object VisitIfStatement(System.Management.Automation.Language.IfStatementAst ifStmtAst)
    {
        IScriptExtent mappedExtent = MapExtent(ifStmtAst.Extent);

        LinkedList <Tuple <PipelineBaseAst, StatementBlockAst> > mappedClauses = new LinkedList <Tuple <PipelineBaseAst, StatementBlockAst> >();

        foreach (Tuple <PipelineBaseAst, StatementBlockAst> c in ifStmtAst.Clauses)
        {
            mappedClauses.AddLast(
                new Tuple <PipelineBaseAst, StatementBlockAst>(
                    _VisitPipelineBase(c.Item1),
                    (StatementBlockAst)VisitStatementBlock(c.Item2)
                    )
                );
        }
        StatementBlockAst mappedElseClause = ifStmtAst.ElseClause != null ? (StatementBlockAst)VisitStatementBlock(ifStmtAst.ElseClause) : null;

        return(new IfStatementAst(mappedExtent, mappedClauses, mappedElseClause));
    }
        /// <summary>
        /// Visit if statement
        /// </summary>
        /// <param name="ifStmtAst"></param>
        /// <returns></returns>
        public object VisitIfStatement(IfStatementAst ifStmtAst)
        {
            if (ifStmtAst == null) return null;

            Block afterStmt = new Block();

            if (ifStmtAst.ElseClause == null)
            {
                // There is no else, flow can go straight to afterStmt.
                _currentBlock.FlowsTo(afterStmt);
            }

            int clauseCount = ifStmtAst.Clauses.Count;
            for (int i = 0; i < clauseCount; i++)
            {
                var clause = ifStmtAst.Clauses[i];
                bool isLastClause = (i == (clauseCount - 1) && ifStmtAst.ElseClause == null);
                Block clauseBlock = new Block();
                Block nextBlock = isLastClause ? afterStmt : new Block();

                clause.Item1.Visit(this);

                _currentBlock.FlowsTo(clauseBlock);
                _currentBlock.FlowsTo(nextBlock);
                _currentBlock = clauseBlock;

                clause.Item2.Visit(this);

                _currentBlock.FlowsTo(afterStmt);
                _currentBlock = nextBlock;
            }

            if (ifStmtAst.ElseClause != null)
            {
                ifStmtAst.ElseClause.Visit(this);
                _currentBlock.FlowsTo(afterStmt);
            }

            _currentBlock = afterStmt;
            return null;
        }
Ejemplo n.º 4
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ast) { return CheckParent(ast); }
Ejemplo n.º 5
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(false);
 }
Ejemplo n.º 6
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Ejemplo n.º 7
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ast)
 {
     return(Check(ast));
 }
Ejemplo n.º 8
0
        public override AstVisitAction VisitIfStatement(IfStatementAst ifStatementAst)
        {
            ////    8.3 The if statement
            ////        The pipeline controlling expressions must have type bool or be implicitly convertible to that
            ////        type. The else-clause is optional. There may be zero or more elseif-clauses.
            ////
            ////        If the top-level pipeline tests True, then its statement-block is executed and execution of
            ////        the statement terminates. Otherwise, if an elseif-clause is present, if its pipeline tests
            ////        True, then its statement-block is executed and execution of the statement terminates.
            ////        Otherwise, if an else-clause is present, its statement-block is executed.

            foreach (var clause in ifStatementAst.Clauses)
            {
                var condition = EvaluateAst(clause.Item1);

                // null is false
                if (condition == null) continue;

                else if (condition is IList && ((IList)condition).Count == 0) continue;

                else if (condition is PSObject)
                {
                    var baseObject = ((PSObject)condition).BaseObject;

                    if (baseObject is bool && ((bool)baseObject) == false) continue;
                }

                else throw new NotImplementedException(clause.Item1.ToString());

                this._pipelineCommandRuntime.WriteObject(EvaluateAst(clause.Item2));
                return AstVisitAction.SkipChildren;
            }

            if (ifStatementAst.ElseClause != null)
            {
                // iterating over a statement list should be its own method.
                foreach (var statement in ifStatementAst.ElseClause.Statements)
                {
                    this._pipelineCommandRuntime.WriteObject(EvaluateAst(statement));
                }
            }

            return AstVisitAction.SkipChildren;
        }
 public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(AstVisitAction.Continue);
 }
 public object VisitIfStatement(IfStatementAst ifStmtAst) { throw new UnexpectedElementException(); }
Ejemplo n.º 11
0
        public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
        {
            // If statements are accepted if their conditions and bodies are accepted.

            return AstVisitAction.Continue;
        }
Ejemplo n.º 12
0
 /// <summary/>
 public virtual AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst) => DefaultVisit(ifStmtAst);
Ejemplo n.º 13
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     int count = ifStmtAst.Clauses.Count;
     Tuple<BlockExpression, Expression>[] tupleArray = new Tuple<BlockExpression, Expression>[count];
     for (int i = 0; i < count; i++)
     {
         Tuple<PipelineBaseAst, StatementBlockAst> tuple = ifStmtAst.Clauses[i];
         BlockExpression expression = Expression.Block(this.UpdatePosition(tuple.Item1), this.CaptureStatementResults(tuple.Item1, CaptureAstContext.Condition, null).Convert(typeof(bool)));
         Expression expression2 = this.Compile(tuple.Item2);
         tupleArray[i] = Tuple.Create<BlockExpression, Expression>(expression, expression2);
     }
     Expression ifFalse = null;
     if (ifStmtAst.ElseClause != null)
     {
         ifFalse = this.Compile(ifStmtAst.ElseClause);
     }
     Expression expression4 = null;
     for (int j = count - 1; j >= 0; j--)
     {
         BlockExpression test = tupleArray[j].Item1;
         Expression ifTrue = tupleArray[j].Item2;
         if (ifFalse != null)
         {
             expression4 = ifFalse = Expression.IfThenElse(test, ifTrue, ifFalse);
         }
         else
         {
             expression4 = ifFalse = Expression.IfThen(test, ifTrue);
         }
     }
     return expression4;
 }
Ejemplo n.º 14
0
 // We skip a bunch of random statements because we can't really be accurate detecting functions/classes etc. that
 // are conditionally defined.
 public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst) { return AstVisitAction.SkipChildren; }
Ejemplo n.º 15
0
 /// <summary/>
 public virtual object VisitIfStatement(IfStatementAst ifStmtAst) { return null; }
Ejemplo n.º 16
0
 /// <summary/>
 public virtual object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return _decorated.VisitIfStatement(ifStmtAst);
 }
Ejemplo n.º 17
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ast)
 {
     return this.Check(ast);
 }
Ejemplo n.º 18
0
 public object VisitIfStatement(IfStatementAst ifStmtAst) { return AutomationNull.Value; }
Ejemplo n.º 19
0
 public virtual AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return AstVisitAction.Continue;
 }
Ejemplo n.º 20
0
 public object VisitIfStatement(IfStatementAst ifStmtAst) { throw PSTraceSource.NewArgumentException("ast"); }
Ejemplo n.º 21
0
 /// <summary/>
 public virtual object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(null);
 }
Ejemplo n.º 22
0
        public object VisitIfStatement(IfStatementAst ifStmtAst)
        {
            int clauseCount = ifStmtAst.Clauses.Count;

            var exprs = new Tuple<BlockExpression, Expression>[clauseCount];
            for (int i = 0; i < clauseCount; ++i)
            {
                IfClause ifClause = ifStmtAst.Clauses[i];
                var cond = Expression.Block(
                    UpdatePosition(ifClause.Item1),
                    CaptureStatementResults(ifClause.Item1, CaptureAstContext.Condition).Convert(typeof(bool)));
                var body = Compile(ifClause.Item2);
                exprs[i] = Tuple.Create(cond, body);
            }

            Expression elseExpr = null;
            if (ifStmtAst.ElseClause != null)
            {
                elseExpr = Compile(ifStmtAst.ElseClause);
            }

            Expression result = null;
            for (int i = clauseCount - 1; i >= 0; --i)
            {
                var cond = exprs[i].Item1;
                var body = exprs[i].Item2;
                if (elseExpr != null)
                {
                    result = elseExpr = Expression.IfThenElse(cond, body, elseExpr);
                }
                else
                {
                    result = elseExpr = Expression.IfThen(cond, body);
                }
            }

            return result;
        }
Ejemplo n.º 23
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return false;
 }
Ejemplo n.º 24
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return AstVisitAction.Continue;
 }
Ejemplo n.º 25
0
 /// <summary/>
 public virtual AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(AstVisitAction.Continue);
 }
Ejemplo n.º 26
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     Block next = new Block();
     int count = ifStmtAst.Clauses.Count;
     for (int i = 0; i < count; i++)
     {
         Tuple<PipelineBaseAst, StatementBlockAst> tuple = ifStmtAst.Clauses[i];
         bool flag = (i == (count - 1)) && (ifStmtAst.ElseClause == null);
         Block block2 = new Block();
         Block block3 = flag ? next : new Block();
         tuple.Item1.Accept(this);
         this._currentBlock.FlowsTo(block2);
         this._currentBlock.FlowsTo(block3);
         this._currentBlock = block2;
         tuple.Item2.Accept(this);
         this._currentBlock.FlowsTo(next);
         this._currentBlock = block3;
     }
     if (ifStmtAst.ElseClause != null)
     {
         ifStmtAst.ElseClause.Accept(this);
         this._currentBlock.FlowsTo(next);
     }
     this._currentBlock = next;
     return null;
 }
Ejemplo n.º 27
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(AutomationNull.Value);
 }
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     throw new NotImplementedException();
 }