Example #1
0
    public System.Object VisitTrap(System.Management.Automation.Language.TrapStatementAst trapStatementAst)
    {
        IScriptExtent mappedExtent = MapExtent(trapStatementAst.Extent);

        TypeConstraintAst mappedTrapType = (TypeConstraintAst)VisitTypeConstraint(trapStatementAst.TrapType);
        StatementBlockAst mappedBody     = (StatementBlockAst)VisitStatementBlock(trapStatementAst.Body);

        return(new TrapStatementAst(mappedExtent, mappedTrapType, mappedBody));
    }
Example #2
0
 internal static Dictionary<string, VariableAnalysisDetails> Visit(TrapStatementAst trap)
 {
     // We disable optimizations for trap because it simplifies what we need to do when invoking
     // the trap, and it's assumed that the code inside a trap rarely, if ever, actually creates
     // any local variables.
     var visitor = new FindAllVariablesVisitor(disableOptimizations: true, scriptCmdlet: false);
     trap.Body.InternalVisit(visitor);
     return visitor._variables;
 }
 /// <summary/>
 public virtual object VisitTrap(TrapStatementAst trapStatementAst)
 {
     return _decorated.VisitTrap(trapStatementAst);
 }
        /// <summary>
        /// Visit trap
        /// </summary>
        /// <param name="trapStatementAst"></param>
        /// <returns></returns>
        public object VisitTrap(TrapStatementAst trapStatementAst)
        {
            if (trapStatementAst == null) return null;

            trapStatementAst.Body.Visit(this.Decorator);
            return null;
        }
Example #5
0
 internal static Tuple<Type, Dictionary<string, int>> AnalyzeTrap(TrapStatementAst trap)
 {
     return new VariableAnalysis().AnalyzeImpl(trap);
 }
 public override AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     this.ReportError(trapStatementAst, () => ParserStrings.TrapStatementNotSupportedInDataSection, new object[0]);
     return AstVisitAction.Continue;
 }
Example #7
0
        private Tuple<Type, Dictionary<string, int>> AnalyzeImpl(TrapStatementAst trap)
        {
            _variables = FindAllVariablesVisitor.Visit(trap);

            // We disable optimizations for trap because it simplifies what we need to do when invoking
            // the trap, and it's assumed that the code inside a trap rarely, if ever, actually creates
            // any local variables.
            _disableOptimizations = true;
            Init();

            _localsAllocated = SpecialVariables.AutomaticVariables.Length;
            _currentBlock = _entryBlock;
            trap.Body.Accept(this);
            _currentBlock.FlowsTo(_exitBlock);

            return FinishAnalysis();
        }
Example #8
0
 public override AstVisitAction VisitTrap(TrapStatementAst ast) { return CheckParent(ast); }
Example #9
0
 /// <summary/>
 public virtual AstVisitAction VisitTrap(TrapStatementAst trapStatementAst) => DefaultVisit(trapStatementAst);
Example #10
0
 public override AstVisitAction VisitTrap(TrapStatementAst ast)
 {
     return(CheckScriptBlock(ast));
 }
Example #11
0
 public override AstVisitAction VisitTrap(TrapStatementAst ast)
 {
     return(CheckParent(ast));
 }
Example #12
0
 /// <summary/>
 public virtual object VisitTrap(TrapStatementAst trapStatementAst)
 {
     return(null);
 }
Example #13
0
 private Tuple<Action<FunctionContext>, Type> CompileTrap(TrapStatementAst trap)
 {
     Compiler compiler = new Compiler(this._sequencePoints) {
         _compilingTrap = true
     };
     string funcName = this._currentFunctionName + "<trap>";
     if (trap.TrapType != null)
     {
         funcName = funcName + "<" + trap.TrapType.TypeName.Name + ">";
     }
     Tuple<Type, Dictionary<string, int>> tuple = VariableAnalysis.AnalyzeTrap(trap);
     compiler.LocalVariablesTupleType = tuple.Item1;
     compiler.LocalVariablesParameter = Expression.Variable(compiler.LocalVariablesTupleType, "locals");
     Expression<Action<FunctionContext>> expression = compiler.CompileSingleLambda(trap.Body.Statements, trap.Body.Traps, funcName, null, null);
     return Tuple.Create<Action<FunctionContext>, Type>(expression.Compile(), compiler.LocalVariablesTupleType);
 }
Example #14
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     return null;
 }
Example #15
0
 internal static Dictionary<string, VariableAnalysisDetails> Visit(TrapStatementAst trap)
 {
     FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(true, false);
     trap.Body.InternalVisit(visitor);
     return visitor._variables;
 }
Example #16
0
 public override AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     return AstVisitAction.SkipChildren;
 }
Example #17
0
 public virtual AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     return AstVisitAction.Continue;
 }
 public object VisitTrap(TrapStatementAst trapStatementAst) { throw new UnexpectedElementException(); }
Example #19
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     Diagnostics.Assert(false, "Traps are not visited directly.");
     return null;
 }
Example #20
0
 /// <summary/>
 public virtual AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     return(AstVisitAction.Continue);
 }
 public override AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     this.ReportError(trapStatementAst, () => ParserStrings.TrapStatementNotSupportedInDataSection, new object[0]);
     return(AstVisitAction.Continue);
 }
Example #22
0
 public override AstVisitAction VisitTrap(TrapStatementAst ast)
 {
     return this.CheckScriptBlock(ast);
 }
Example #23
0
 private Tuple<Type, Dictionary<string, int>> AnalyzeImpl(TrapStatementAst trap)
 {
     this._variables = FindAllVariablesVisitor.Visit(trap);
     this._disableOptimizations = true;
     this.Init();
     this._localsAllocated = SpecialVariables.AutomaticVariables.Length;
     this._currentBlock = this._entryBlock;
     trap.Body.Accept(this);
     this._currentBlock.FlowsTo(this._exitBlock);
     return this.FinishAnalysis(false);
 }
Example #24
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     return(AutomationNull.Value);
 }
Example #25
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     trapStatementAst.Body.Accept(this);
     return null;
 }
Example #26
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     return(false);
 }
 /// <summary>
 /// Visit Trap
 /// </summary>
 /// <param name="trapStatementAst"></param>
 /// <returns></returns>
 public override AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     // We don't want to discover any variables in traps - they get their own scope.
     return AstVisitAction.SkipChildren;
 }
Example #28
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Example #29
0
        private AstVisitAction VisitTrapBody(TrapStatementAst trapStatement)
        {
            foreach (StatementAst statement in trapStatement.Body.Statements)
            {
                try
                {
                    statement.Visit(this);
                }
                catch (ContinueException)
                {
                    return AstVisitAction.Continue;
                }
                catch (BreakException)
                {
                    WriteErrorRecord();
                    return AstVisitAction.SkipChildren;
                }
            }

            WriteErrorRecord();
            return AstVisitAction.Continue;
        }
Example #30
0
 public object VisitTrap(TrapStatementAst trapStatementAst) { return AutomationNull.Value; }
Example #31
0
        private AstVisitAction VisitTrapBody(TrapStatementAst trapStatement)
        {
            foreach (StatementAst statement in trapStatement.Body.Statements)
            {
                statement.Visit(this);

                if (statement is ContinueStatementAst)
                {
                    return AstVisitAction.Continue;
                }
                else if (statement is BreakStatementAst)
                {
                    WriteErrorRecord();
                    return AstVisitAction.SkipChildren;
                }
            }

            WriteErrorRecord();
            return AstVisitAction.Continue;
        }
Example #32
0
 public object VisitTrap(TrapStatementAst trapStatementAst) { throw PSTraceSource.NewArgumentException("ast"); }
Example #33
0
 public override AstVisitAction VisitTrap(TrapStatementAst trapStatementAst)
 {
     throw new NotImplementedException(); //VisitTrap(trapStatementAst);
 }
Example #34
0
        private Tuple<Action<FunctionContext>, Type> CompileTrap(TrapStatementAst trap)
        {
            var compiler = new Compiler(_sequencePoints) { _compilingTrap = true };
            string funcName = _currentFunctionName + "<trap>";
            if (trap.TrapType != null)
            {
                funcName += "<" + trap.TrapType.TypeName.Name + ">";
            }

            // We generate code as though we're dotting the trap, but in reality we don't dot it,
            // a new scope is always created.  The code gen for dotting means we can avoid passing
            // around the array of local variable names.  We assume traps don't need to perform well,
            // and that they rarely if ever actually create any local variables.  We still do the
            // variable analysis though because we must mark automatic variables like $_.
            var analysis = VariableAnalysis.AnalyzeTrap(trap);

            compiler.LocalVariablesTupleType = analysis.Item1;
            compiler.LocalVariablesParameter = Expression.Variable(compiler.LocalVariablesTupleType, "locals");

            var lambda = compiler.CompileSingleLambda(trap.Body.Statements, trap.Body.Traps, funcName, null, null, null);
            return Tuple.Create(lambda.Compile(), compiler.LocalVariablesTupleType);
        }
Example #35
0
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     return false;
 }
 public object VisitTrap(TrapStatementAst trapStatementAst)
 {
     throw new NotImplementedException();
 }