internal static Dictionary <string, VariableAnalysisDetails> Visit(TrapStatementAst trap)
        {
            FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(true, false);

            trap.Body.InternalVisit(visitor);
            return(visitor._variables);
        }
        internal static Dictionary <string, VariableAnalysisDetails> Visit(ExpressionAst exprAst)
        {
            FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(true, false);

            exprAst.InternalVisit(visitor);
            return(visitor._variables);
        }
示例#3
0
 // Used to analyze an expression that is invoked separately, i.e. a default argument.
 internal static Dictionary<string, VariableAnalysisDetails> Visit(ExpressionAst exprAst)
 {
     // We disable optimizations for default expressions because it simplifies what we need to do when
     // invoking the default expression, 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);
     exprAst.InternalVisit(visitor);
     return visitor._variables;
 }
示例#4
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;
 }
示例#5
0
 private Tuple <Type, Dictionary <string, int> > AnalyzeImpl(ExpressionAst exprAst)
 {
     this._variables            = FindAllVariablesVisitor.Visit(exprAst);
     this._disableOptimizations = true;
     this.Init();
     this._localsAllocated = SpecialVariables.AutomaticVariables.Length;
     this._currentBlock    = this._entryBlock;
     exprAst.Accept(this);
     this._currentBlock.FlowsTo(this._exitBlock);
     return(this.FinishAnalysis(false));
 }
示例#6
0
 internal static Dictionary<string, VariableAnalysisDetails> Visit(IParameterMetadataProvider ast, bool disableOptimizations, bool scriptCmdlet, out int localsAllocated, out bool forceNoOptimizing)
 {
     FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(disableOptimizations, scriptCmdlet);
     ast.Body.InternalVisit(visitor);
     forceNoOptimizing = visitor._disableOptimizations;
     if (ast.Parameters != null)
     {
         visitor.VisitParameters(ast.Parameters);
     }
     localsAllocated = (from details in visitor._variables
         where details.Value.LocalTupleIndex != -1
         select details).Count<KeyValuePair<string, VariableAnalysisDetails>>();
     return visitor._variables;
 }
        internal static Dictionary <string, VariableAnalysisDetails> Visit(IParameterMetadataProvider ast, bool disableOptimizations, bool scriptCmdlet, out int localsAllocated, out bool forceNoOptimizing)
        {
            FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(disableOptimizations, scriptCmdlet);

            ast.Body.InternalVisit(visitor);
            forceNoOptimizing = visitor._disableOptimizations;
            if (ast.Parameters != null)
            {
                visitor.VisitParameters(ast.Parameters);
            }
            localsAllocated = (from details in visitor._variables
                               where details.Value.LocalTupleIndex != -1
                               select details).Count <KeyValuePair <string, VariableAnalysisDetails> >();
            return(visitor._variables);
        }
示例#8
0
 private Tuple <Type, Dictionary <string, int> > AnalyzeImpl(IParameterMetadataProvider ast, bool disableOptimizations, bool scriptCmdlet)
 {
     this._variables = FindAllVariablesVisitor.Visit(ast, disableOptimizations, scriptCmdlet, out this._localsAllocated, out this._disableOptimizations);
     this.Init();
     if (ast.Parameters != null)
     {
         foreach (ParameterAst ast2 in ast.Parameters)
         {
             VariablePath variablePath = ast2.Name.VariablePath;
             if (variablePath.IsAnyLocal())
             {
                 bool flag = false;
                 int  num  = -1;
                 Type c    = null;
                 foreach (AttributeBaseAst ast3 in ast2.Attributes)
                 {
                     if (ast3 is TypeConstraintAst)
                     {
                         num++;
                         if (c == null)
                         {
                             c = ast3.TypeName.GetReflectionType();
                         }
                     }
                     else
                     {
                         Type reflectionAttributeType = ast3.TypeName.GetReflectionAttributeType();
                         if (typeof(ValidateArgumentsAttribute).IsAssignableFrom(reflectionAttributeType) || typeof(ArgumentTransformationAttribute).IsAssignableFrom(reflectionAttributeType))
                         {
                             flag = true;
                         }
                     }
                 }
                 string unaliasedVariableName    = GetUnaliasedVariableName(variablePath);
                 VariableAnalysisDetails details = this._variables[unaliasedVariableName];
                 c = c ?? (details.Type ?? typeof(object));
                 if (((flag || (num > 0)) || (typeof(PSReference).IsAssignableFrom(c) || MustBeBoxed(c))) && (!details.Automatic && !details.PreferenceVariable))
                 {
                     details.LocalTupleIndex = -2;
                 }
                 this._entryBlock.AddAst(new AssignmentTarget(unaliasedVariableName, c));
             }
         }
     }
     ast.Body.Accept(this);
     return(this.FinishAnalysis(scriptCmdlet));
 }
示例#9
0
        internal static Dictionary<string, VariableAnalysisDetails> Visit(IParameterMetadataProvider ast,
                                                                          bool disableOptimizations,
                                                                          bool scriptCmdlet,
                                                                          out int localsAllocated,
                                                                          out bool forceNoOptimizing)
        {
            var visitor = new FindAllVariablesVisitor(disableOptimizations, scriptCmdlet);

            // Visit the body before the parameters so we don't allocate any tuple slots for parameters
            // if we won't be optimizing because of a call to new-variable/remove-variable, etc.

            ast.Body.InternalVisit(visitor);
            forceNoOptimizing = visitor._disableOptimizations;

            if (ast.Parameters != null)
            {
                visitor.VisitParameters(ast.Parameters);
            }
            localsAllocated = visitor._variables.Where(details => details.Value.LocalTupleIndex != VariableAnalysis.Unanalyzed).Count();
            return visitor._variables;
        }
示例#10
0
 internal static Dictionary<string, VariableAnalysisDetails> Visit(TrapStatementAst trap)
 {
     FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(true, false);
     trap.Body.InternalVisit(visitor);
     return visitor._variables;
 }
示例#11
0
 internal static Dictionary<string, VariableAnalysisDetails> Visit(ExpressionAst exprAst)
 {
     FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(true, false);
     exprAst.InternalVisit(visitor);
     return visitor._variables;
 }