コード例 #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);
        }
コード例 #2
0
ファイル: SourceMapper.cs プロジェクト: gpduck/ScriptMap
    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));
    }
コード例 #3
0
        /// <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;
        }
コード例 #4
0
ファイル: AstVisitor.cs プロジェクト: 40a/PowerShell
 public override AstVisitAction VisitIfStatement(IfStatementAst ast) { return CheckParent(ast); }
コード例 #5
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(false);
 }
コード例 #6
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
コード例 #7
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ast)
 {
     return(Check(ast));
 }
コード例 #8
0
ファイル: ExecutionVisitor.cs プロジェクト: JayBazuzi/Pash
        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;
        }
コード例 #9
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(AstVisitAction.Continue);
 }
コード例 #10
0
 public object VisitIfStatement(IfStatementAst ifStmtAst) { throw new UnexpectedElementException(); }
コード例 #11
0
ファイル: SemanticChecks.cs プロジェクト: dfinke/powershell
        public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
        {
            // If statements are accepted if their conditions and bodies are accepted.

            return AstVisitAction.Continue;
        }
コード例 #12
0
 /// <summary/>
 public virtual AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst) => DefaultVisit(ifStmtAst);
コード例 #13
0
ファイル: Compiler.cs プロジェクト: nickchal/pash
 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;
 }
コード例 #14
0
ファイル: ScriptAnalysis.cs プロジェクト: 40a/PowerShell
 // 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; }
コード例 #15
0
ファイル: AstVisitor.cs プロジェクト: 40a/PowerShell
 /// <summary/>
 public virtual object VisitIfStatement(IfStatementAst ifStmtAst) { return null; }
コード例 #16
0
 /// <summary/>
 public virtual object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return _decorated.VisitIfStatement(ifStmtAst);
 }
コード例 #17
0
ファイル: AstSearcher.cs プロジェクト: nickchal/pash
 public override AstVisitAction VisitIfStatement(IfStatementAst ast)
 {
     return this.Check(ast);
 }
コード例 #18
0
ファイル: ConstantValues.cs プロジェクト: 40a/PowerShell
 public object VisitIfStatement(IfStatementAst ifStmtAst) { return AutomationNull.Value; }
コード例 #19
0
ファイル: AstVisitor.cs プロジェクト: JamesTryand/Pash2
 public virtual AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return AstVisitAction.Continue;
 }
コード例 #20
0
ファイル: SafeValues.cs プロジェクト: 40a/PowerShell
 public object VisitIfStatement(IfStatementAst ifStmtAst) { throw PSTraceSource.NewArgumentException("ast"); }
コード例 #21
0
 /// <summary/>
 public virtual object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(null);
 }
コード例 #22
0
ファイル: Compiler.cs プロジェクト: 40a/PowerShell
        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;
        }
コード例 #23
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return false;
 }
コード例 #24
0
 public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return AstVisitAction.Continue;
 }
コード例 #25
0
 /// <summary/>
 public virtual AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(AstVisitAction.Continue);
 }
コード例 #26
0
ファイル: VariableAnalysis.cs プロジェクト: nickchal/pash
 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;
 }
コード例 #27
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     return(AutomationNull.Value);
 }
コード例 #28
0
 public object VisitIfStatement(IfStatementAst ifStmtAst)
 {
     throw new NotImplementedException();
 }