Inheritance: System.Management.Automation.Language.AstVisitor
示例#1
0
 internal ScriptBlockParameterBinder(ReadOnlyCollection<ParameterAst> scriptParameters, ExecutionContext context,
                                     ExecutionVisitor executionVisitor)
 {
     _scriptParameters = scriptParameters;
     _executionContext = context;
     _executionVisitor = executionVisitor;
 }
        public Collection<PSObject> InvokeScript(string script, bool useNewScope, PipelineResultTypes writeToPipeline, IList input, params object[] args)
        {
            ScriptBlock scriptBlock = NewScriptBlock(script);
            var executionVisitor = new ExecutionVisitor(executionContext, commandRuntime);
            scriptBlock.Ast.Visit(executionVisitor);

            return new Collection<PSObject>();
        }
示例#3
0
 private void CreateOwnScope()
 {
     _originalContext = ExecutionContext;
     var executionSessionState = CommandInfo.Module != null ? CommandInfo.Module.SessionState
                                                            : ExecutionContext.SessionState;
     _scopedContext = ExecutionContext.Clone(executionSessionState, _scriptBlockInfo.ScopeUsage);
     _scopedExecutionVisitor = new ExecutionVisitor(_scopedContext, CommandRuntime, false);
 }
示例#4
0
        protected override void ProcessRecord()
        {
            this.ExecutionContext.SetVariable("_", this.InputObject);

            var executionVisitor = new ExecutionVisitor(
                this.ExecutionContext,
                (PipelineCommandRuntime)CommandRuntime
                );

            this.Process.Ast.Visit(executionVisitor);
        }
示例#5
0
        internal static SettableExpression Create(ExpressionAst valueExpression, ExecutionVisitor currentExecution)
        {
            if (valueExpression is VariableExpressionAst)
            {
                return(new SettableVariableExpression((VariableExpressionAst)valueExpression, currentExecution));
            }
            else if (valueExpression is MemberExpressionAst)
            {
                return(new SettableMemberExpression((MemberExpressionAst)valueExpression, currentExecution));
            }
            else if (valueExpression is IndexExpressionAst)
            {
                return(new SettableIndexExpression((IndexExpressionAst)valueExpression, currentExecution));
            }
            var msg = String.Format("The expression is not a modifiable value, but of type '{0}'. Please report this!",
                                    valueExpression.GetType().FullName);

            throw new InvalidOperationException(msg);
        }
示例#6
0
 public Collection<PSObject> InvokeScript(string script, bool useNewScope, PipelineResultTypes writeToPipeline, IList input, params object[] args)
 {
     var context = useNewScope ? executionContext.Clone(ScopeUsages.NewScriptScope)
                               : executionContext;
     //Let's see on the long run if there is an easier solution for this #ExecutionContextChange
     //we need to change the global execution context to change the scope we are currently operating in
     executionContext.CurrentRunspace.ExecutionContext = context;
     try
     {
         ScriptBlock scriptBlock = NewScriptBlock(script);
         var executionVisitor = new ExecutionVisitor(context, commandRuntime);
         // sburnicki - handle ExitException
         scriptBlock.Ast.Visit(executionVisitor);
     }
     finally //make sure we set back the old execution context, no matter what happened
     {
         executionContext.CurrentRunspace.ExecutionContext = executionContext;
     }
     return new Collection<PSObject>();
 }
示例#7
0
 internal static SettableExpression Create(ExpressionAst valueExpression, ExecutionVisitor currentExecution)
 {
     if (valueExpression is VariableExpressionAst)
     {
         return new SettableVariableExpression((VariableExpressionAst)valueExpression, currentExecution);
     }
     else if (valueExpression is InvokeMemberExpressionAst)
     {
         return new SettableInvokeMemberExpression((InvokeMemberExpressionAst)valueExpression, currentExecution);
     }
     else if (valueExpression is MemberExpressionAst)
     {
         return new SettableMemberExpression((MemberExpressionAst)valueExpression, currentExecution);
     }
     else if (valueExpression is IndexExpressionAst)
     {
         return new SettableIndexExpression((IndexExpressionAst)valueExpression, currentExecution);
     }
     var msg = String.Format("The expression is not a modifiable value, but of type '{0}'. Please report this!",
                             valueExpression.GetType().FullName);
     throw new InvalidOperationException(msg);
 }
示例#8
0
 internal SettableExpression(ExecutionVisitor currentExecution)
 {
     CurrentExecution = currentExecution;
 }
示例#9
0
 internal SettableVariableExpression(VariableExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base(currentExecution)
 {
     _expressionAst = expressionAst;
 }
示例#10
0
        private void FilterByScript()
        {
            ExecutionContext.SetVariable("_", InputObject);

            var executionVisitor = new ExecutionVisitor(ExecutionContext, (PipelineCommandRuntime)CommandRuntime);

            object result = executionVisitor.EvaluateAst(FilterScript.Ast, true);
            if (IsTrue(result))
            {
                WriteObject(InputObject);
            }
        }
示例#11
0
 public RedirectionVisitor(ExecutionVisitor visitor, IEnumerable <RedirectionAst> redirections)
 {
     _visitor      = visitor;
     _redirections = redirections.ToList();
 }
示例#12
0
 internal SettableIndexExpression(IndexExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base (currentExecution)
 {
     _expressionAst = expressionAst;
 }
示例#13
0
 public FileRedirectionVisitor(ExecutionVisitor visitor, PipelineCommandRuntime runtime)
 {
     _visitor = visitor;
     _runtime = runtime;
 }
示例#14
0
 internal SettableInvokeMemberExpression(InvokeMemberExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base(expressionAst, currentExecution)
 {
     _expressionAst = expressionAst;
 }
示例#15
0
 public RedirectionVisitor(ExecutionVisitor visitor, IEnumerable<RedirectionAst> redirections)
 {
     _visitor = visitor;
     _redirections = redirections.ToList();
 }
示例#16
0
 private void CreateOwnScope()
 {
     _originalContext = ExecutionContext;
     _scopedContext = ExecutionContext.Clone(_scriptBlockInfo.ScopeUsage);
     _scopedExecutionVisitor = new ExecutionVisitor(_scopedContext, CommandRuntime, false);
 }
示例#17
0
 internal SettableIndexExpression(IndexExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base(currentExecution)
 {
     _expressionAst = expressionAst;
 }
示例#18
0
 internal SettableVariableExpression(VariableExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base(currentExecution)
 {
     _expressionAst = expressionAst;
 }
示例#19
0
 internal SettableExpression(ExecutionVisitor currentExecution)
 {
     CurrentExecution = currentExecution;
 }
示例#20
0
 internal SettableMemberExpression(MemberExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base(currentExecution)
 {
     _expressionAst = expressionAst;
 }
示例#21
0
 public FileRedirectionVisitor(ExecutionVisitor visitor, PipelineCommandRuntime runtime)
 {
     _visitor = visitor;
     _runtime = runtime;
 }