Example #1
0
 private ScriptBlock(IParameterMetadataProvider ast, bool isFilter, CompiledScriptBlockData _scriptBlockData)
 {
     this.languageMode = null;
     this._ast = ast;
     this._scriptBlockData = _scriptBlockData;
     this._isFilter = isFilter;
     this.SetLanguageModeFromContext();
 }
Example #2
0
        private ScriptBlock(CompiledScriptBlockData scriptBlockData)
        {
            _scriptBlockData = scriptBlockData;

            // LanguageMode is a nullable PSLanguageMode enumeration because script blocks
            // need to inherit the language mode from the context in which they are executing.
            // We can't assume FullLanguage by default when there is no context, as there are
            // script blocks (such as the script blocks used in Workflow activities) that are
            // created by the host without a "current language mode" to inherit. They ultimately
            // get their language mode set when they are finally invoked in a constrained
            // language runspace.
            // Script blocks that should always be run under FullLanguage mode (i.e.: set in
            // InitialSessionState, etc.) should explicitly set the LanguageMode to FullLanguage
            // when they are created.
            ExecutionContext context = LocalPipeline.GetExecutionContextFromTLS();
            if (context != null)
            {
                this.LanguageMode = context.LanguageMode;
            }
        }
Example #3
0
 internal void Compile(CompiledScriptBlockData scriptBlock, bool optimize)
 {
     IParameterMetadataProvider ast = scriptBlock.Ast;
     this.Optimize = optimize;
     this._compilingScriptCmdlet = scriptBlock.UsesCmdletBinding;
     string file = ((Ast) ast).Extent.File;
     if (file != null)
     {
         this._debugSymbolDocument = Expression.SymbolDocument(file);
     }
     Tuple<Type, Dictionary<string, int>> tuple = VariableAnalysis.Analyze(ast, !optimize, this._compilingScriptCmdlet);
     this.LocalVariablesTupleType = tuple.Item1;
     Dictionary<string, int> dictionary = tuple.Item2;
     if (!dictionary.TryGetValue("switch", out this._switchTupleIndex))
     {
         this._switchTupleIndex = -2;
     }
     if (!dictionary.TryGetValue("foreach", out this._foreachTupleIndex))
     {
         this._foreachTupleIndex = -2;
     }
     this.LocalVariablesParameter = Expression.Variable(this.LocalVariablesTupleType, "locals");
     ast.Body.Accept(this);
     if (!this._sequencePoints.Any<IScriptExtent>())
     {
         this._sequencePoints.Add(((Ast) ast).Extent);
     }
     if (optimize)
     {
         scriptBlock.DynamicParamBlockTree = this._dynamicParamBlockLambda;
         scriptBlock.BeginBlockTree = this._beginBlockLambda;
         scriptBlock.ProcessBlockTree = this._processBlockLambda;
         scriptBlock.EndBlockTree = this._endBlockLambda;
         scriptBlock.LocalsMutableTupleType = this.LocalVariablesTupleType;
         scriptBlock.NameToIndexMap = dictionary;
     }
     else
     {
         scriptBlock.UnoptimizedDynamicParamBlockTree = this._dynamicParamBlockLambda;
         scriptBlock.UnoptimizedBeginBlockTree = this._beginBlockLambda;
         scriptBlock.UnoptimizedProcessBlockTree = this._processBlockLambda;
         scriptBlock.UnoptimizedEndBlockTree = this._endBlockLambda;
         scriptBlock.UnoptimizedLocalsMutableTupleType = this.LocalVariablesTupleType;
     }
     scriptBlock.CompileInterpretDecision = (this._stmtCount > 300) ? CompileInterpretChoice.NeverCompile : CompileInterpretChoice.CompileOnDemand;
     if (scriptBlock.SequencePoints == null)
     {
         scriptBlock.SequencePoints = this._sequencePoints.ToArray();
     }
 }