Example #1
0
        private bool AstAssignsToSameVariable(Ast ast)
        {
            ParameterAst ast2 = ast as ParameterAst;

            if (ast2 != null)
            {
                return(this.VariablePath.IsUnscopedVariable && ast2.Name.VariablePath.UnqualifiedPath.Equals(this.VariablePath.UnqualifiedPath, StringComparison.OrdinalIgnoreCase));
            }
            ForEachStatementAst ast3 = ast as ForEachStatementAst;

            if (ast3 != null)
            {
                return(this.VariablePath.IsUnscopedVariable && ast3.Variable.VariablePath.UnqualifiedPath.Equals(this.VariablePath.UnqualifiedPath, StringComparison.OrdinalIgnoreCase));
            }
            AssignmentStatementAst ast4 = (AssignmentStatementAst)ast;
            ExpressionAst          left = ast4.Left;
            ConvertExpressionAst   ast6 = left as ConvertExpressionAst;

            if (ast6 != null)
            {
                left = ast6.Child;
            }
            VariableExpressionAst ast7 = left as VariableExpressionAst;

            if (ast7 == null)
            {
                return(false);
            }
            System.Management.Automation.VariablePath variablePath = ast7.VariablePath;
            return(variablePath.UserPath.Equals(this.VariablePath.UserPath, StringComparison.OrdinalIgnoreCase) || (this.VariablePath.IsScript && this.VariablePath.UnqualifiedPath.Equals(variablePath.UnqualifiedPath, StringComparison.OrdinalIgnoreCase)));
        }
 public override AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     if (parameterAst.Name.VariablePath.IsAnyLocal())
     {
         this._validVariables.Add(parameterAst.Name.VariablePath.UnqualifiedPath);
     }
     return AstVisitAction.Continue;
 }
Example #3
0
 public override AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     foreach (AttributeBaseAst ast in parameterAst.Attributes)
     {
         if ((ast is TypeConstraintAst) && ast.TypeName.FullName.Equals("ordered", StringComparison.OrdinalIgnoreCase))
         {
             this._parser.ReportError(ast.Extent, ParserStrings.OrderedAttributeOnlyOnHashLiteralNode, new object[] { ast.TypeName.FullName });
         }
     }
     return(AstVisitAction.Continue);
 }
Example #4
0
    public System.Object VisitParameter(System.Management.Automation.Language.ParameterAst parameterAst)
    {
        IScriptExtent mappedExtent = MapExtent(parameterAst.Extent);

        VariableExpressionAst         mappedName       = (VariableExpressionAst)VisitVariableExpression(parameterAst.Name);
        LinkedList <AttributeBaseAst> mappedAttributes = new LinkedList <AttributeBaseAst>();

        foreach (AttributeBaseAst ab in parameterAst.Attributes)
        {
            mappedAttributes.AddLast(_VisitAttributeBase(ab));
        }
        ExpressionAst mappedDefaultValue = parameterAst.DefaultValue != null?_VisitExpression(parameterAst.DefaultValue) : null;

        return(new ParameterAst(mappedExtent, mappedName, mappedAttributes, mappedDefaultValue));
    }
Example #5
0
 public virtual AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     return AstVisitAction.Continue;
 }
Example #6
0
 private void BindVariable(ParameterAst scriptParameter, CommandParameter argument)
 {
     var value = GetParameterValue(scriptParameter, argument);
     _executionContext.SetVariable(scriptParameter.Name.VariablePath.UserPath, value);
 }
 /// <summary/>
 public virtual object VisitParameter(ParameterAst parameterAst)
 {
     return _decorated.VisitParameter(parameterAst);
 }
Example #8
0
 private object GetParameterValue(ParameterAst scriptParameter, CommandParameter parameter)
 {
     if (parameter != null)
     {
         return parameter.Value;
     }
     return GetDefaultParameterValue(scriptParameter);
 }
Example #9
0
 public override AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     foreach (AttributeBaseAst ast in parameterAst.Attributes)
     {
         if ((ast is TypeConstraintAst) && ast.TypeName.FullName.Equals("ordered", StringComparison.OrdinalIgnoreCase))
         {
             this._parser.ReportError(ast.Extent, ParserStrings.OrderedAttributeOnlyOnHashLiteralNode, new object[] { ast.TypeName.FullName });
         }
     }
     return AstVisitAction.Continue;
 }
Example #10
0
 public object VisitParameter(ParameterAst parameterAst)
 {
     return null;
 }
        // We assume they have the same name
        private bool CompareParamAsts(ParameterAst paramAst1, ParameterAst paramAst2)
        {
            if (paramAst1.StaticType != paramAst2.StaticType)
            {
                return false;
            }

            if ((paramAst1.Attributes == null && paramAst2.Attributes != null)
                || (paramAst1.Attributes != null && paramAst2.Attributes == null))
            {
                return false;
            }

            if (paramAst1.Attributes != null && paramAst2.Attributes != null)
            {
                if (paramAst1.Attributes.Count() != paramAst2.Attributes.Count())
                {
                    return false;
                }

                HashSet<string> attributes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                foreach (var attribute in paramAst1.Attributes)
                {
                    attributes.Add(attribute.TypeName.FullName);
                }

                foreach (var attribute in paramAst2.Attributes)
                {
                    if (!attributes.Contains(attribute.TypeName.FullName))
                    {
                        return false;
                    }
                }

            }

            return true;
        }
Example #12
0
 public object VisitParameter(ParameterAst parameterAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Example #13
0
 private static RuntimeDefinedParameter GetRuntimeDefinedParameter(ParameterAst parameterAst, ref bool customParameterSet, ref bool usesCmdletBinding)
 {
     object obj3;
     List<Attribute> list = new List<Attribute>();
     bool flag = false;
     foreach (AttributeBaseAst ast in parameterAst.Attributes)
     {
         Attribute item = ast.GetAttribute();
         list.Add(item);
         ParameterAttribute attribute2 = item as ParameterAttribute;
         if (attribute2 != null)
         {
             flag = true;
             usesCmdletBinding = true;
             if ((attribute2.Position != -2147483648) || !attribute2.ParameterSetName.Equals("__AllParameterSets", StringComparison.OrdinalIgnoreCase))
             {
                 customParameterSet = true;
             }
         }
     }
     list.Reverse();
     if (!flag)
     {
         list.Insert(0, new ParameterAttribute());
     }
     RuntimeDefinedParameter parameter = new RuntimeDefinedParameter(parameterAst.Name.VariablePath.UserPath, parameterAst.StaticType, new Collection<Attribute>(list.ToArray()));
     if (parameterAst.DefaultValue != null)
     {
         object obj2;
         if (IsConstantValueVisitor.IsConstant(parameterAst.DefaultValue, out obj2, false, false))
         {
             parameter.Value = obj2;
             return parameter;
         }
         DefaultValueExpressionWrapper wrapper = new DefaultValueExpressionWrapper {
             Expression = parameterAst.DefaultValue
         };
         parameter.Value = wrapper;
         return parameter;
     }
     if (TryGetDefaultParameterValue(parameterAst.StaticType, out obj3) && (obj3 != null))
     {
         parameter.Value = obj3;
     }
     return parameter;
 }
Example #14
0
 private ParameterAst ParameterRule()
 {
     ParameterAst parameterAst;
     IScriptExtent extent;
     IScriptExtent scriptExtent;
     ExpressionAst expressionAst = null;
     bool flag = this._disableCommaOperator;
     TokenizerMode mode = this._tokenizer.Mode;
     try
     {
         this._disableCommaOperator = true;
         this.SetTokenizerMode(TokenizerMode.Expression);
         this.SkipNewlines();
         List<AttributeBaseAst> attributeBaseAsts = this.AttributeListRule(false);
         this.SkipNewlines();
         Token token = this.NextToken();
         if (token.Kind == TokenKind.Variable || token.Kind == TokenKind.SplattedVariable)
         {
             VariableToken variableToken = (VariableToken)token;
             this.SkipNewlines();
             Token token1 = this.PeekToken();
             if (token1.Kind == TokenKind.Equals)
             {
                 this.SkipToken();
                 this.SkipNewlines();
                 expressionAst = this.ExpressionRule();
                 if (expressionAst == null)
                 {
                     object[] objArray = new object[1];
                     objArray[0] = token1.Kind.Text();
                     this.ReportIncompleteInput(Parser.After(token1), ParserStrings.MissingExpressionAfterToken, objArray);
                 }
             }
             if (attributeBaseAsts == null)
             {
                 extent = variableToken.Extent;
             }
             else
             {
                 extent = attributeBaseAsts[0].Extent;
             }
             IScriptExtent scriptExtent1 = extent;
             if (expressionAst == null)
             {
                 scriptExtent = variableToken.Extent;
             }
             else
             {
                 scriptExtent = expressionAst.Extent;
             }
             IScriptExtent scriptExtent2 = scriptExtent;
             return new ParameterAst(Parser.ExtentOf(scriptExtent1, scriptExtent2), new VariableExpressionAst(variableToken), attributeBaseAsts, expressionAst);
         }
         else
         {
             this.UngetToken(token);
             if (attributeBaseAsts == null)
             {
                 parameterAst = null;
             }
             else
             {
                 this.ReportIncompleteInput(Parser.After(attributeBaseAsts.Last<AttributeBaseAst>()), ParserStrings.InvalidFunctionParameter, new object[0]);
                 TokenKind[] tokenKindArray = new TokenKind[1];
                 tokenKindArray[0] = TokenKind.RParen;
                 this.SyncOnError(tokenKindArray);
                 IScriptExtent scriptExtent3 = Parser.ExtentOf(attributeBaseAsts[0].Extent, attributeBaseAsts[attributeBaseAsts.Count - 1].Extent);
                 parameterAst = new ParameterAst(scriptExtent3, new VariableExpressionAst(scriptExtent3, "__error__", false), attributeBaseAsts, null);
             }
         }
     }
     finally
     {
         this._disableCommaOperator = flag;
         this.SetTokenizerMode(mode);
     }
     return parameterAst;
 }
 private TypeConstraintAst GetTypeAttributeAst(ParameterAst paramAst)
 {
     if (paramAst.Attributes != null)
     {
         foreach(var attr in paramAst.Attributes)
         {
             if (attr.GetType() == typeof(TypeConstraintAst))
             {
                 return attr as TypeConstraintAst;
             }
         }
     }
     return null;
 }
 private List<CorrectionExtent> GetCorrectionExtent(ParameterAst paramAst)
 {
     //Find the parameter type extent and replace that with secure string
     IScriptExtent extent;
     var typeAttributeAst = GetTypeAttributeAst(paramAst);
     var corrections = new List<CorrectionExtent>();
     string correctionText;
     if (typeAttributeAst == null)
     {
         // cannot find any type attribute
         extent = paramAst.Name.Extent;
         correctionText = string.Format("[SecureString] {0}", paramAst.Name.Extent.Text);
     }
     else
     {
         // replace only the existing type with [SecureString]
         extent = typeAttributeAst.Extent;
         correctionText = typeAttributeAst.TypeName.IsArray ? "[SecureString[]]" : "[SecureString]";
     }
     string description = string.Format(
         CultureInfo.CurrentCulture,
         Strings.AvoidUsingPlainTextForPasswordCorrectionDescription,
         paramAst.Name.Extent.Text);
     corrections.Add(new CorrectionExtent(
         extent.StartLineNumber,
         extent.EndLineNumber,
         extent.StartColumnNumber,
         extent.EndColumnNumber,
         correctionText.ToString(),
         paramAst.Extent.File,
         description));
     return corrections;
 }
Example #17
0
        internal override IEnumerable <PSTypeName> GetInferredType(CompletionContext context)
        {
            if (this.VariablePath.IsVariable)
            {
                Ast parent = this.Parent;
                if (this.VariablePath.IsUnqualified && (this.VariablePath.UserPath.Equals("_", StringComparison.Ordinal) || this.VariablePath.UserPath.Equals("PSItem", StringComparison.OrdinalIgnoreCase)))
                {
                    while (parent != null)
                    {
                        if (parent is ScriptBlockExpressionAst)
                        {
                            break;
                        }
                        parent = parent.Parent;
                    }
                    if (parent != null)
                    {
                        if ((parent.Parent is CommandExpressionAst) && (parent.Parent.Parent is PipelineAst))
                        {
                            if (parent.Parent.Parent.Parent is HashtableAst)
                            {
                                parent = parent.Parent.Parent.Parent;
                            }
                            else if ((parent.Parent.Parent.Parent is ArrayLiteralAst) && (parent.Parent.Parent.Parent.Parent is HashtableAst))
                            {
                                parent = parent.Parent.Parent.Parent.Parent;
                            }
                        }
                        if (parent.Parent is CommandParameterAst)
                        {
                            parent = parent.Parent;
                        }
                        CommandAst iteratorVariable1 = parent.Parent as CommandAst;
                        if (iteratorVariable1 != null)
                        {
                            PipelineAst iteratorVariable2 = (PipelineAst)iteratorVariable1.Parent;
                            int         iteratorVariable3 = iteratorVariable2.PipelineElements.IndexOf(iteratorVariable1) - 1;
                            if (iteratorVariable3 >= 0)
                            {
                                foreach (PSTypeName iteratorVariable4 in iteratorVariable2.PipelineElements[0].GetInferredType(context))
                                {
                                    if (iteratorVariable4.Type != null)
                                    {
                                        if (iteratorVariable4.Type.IsArray)
                                        {
                                            yield return(new PSTypeName(iteratorVariable4.Type.GetElementType()));

                                            continue;
                                        }
                                        if (typeof(IEnumerable).IsAssignableFrom(iteratorVariable4.Type))
                                        {
                                            IEnumerable <Type> iteratorVariable5 = from t in iteratorVariable4.Type.GetInterfaces()
                                                                                   where t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(IEnumerable <>))
                                                                                   select t;
                                            foreach (Type iteratorVariable6 in iteratorVariable5)
                                            {
                                                yield return(new PSTypeName(iteratorVariable6.GetGenericArguments()[0]));
                                            }
                                            continue;
                                        }
                                    }
                                    yield return(iteratorVariable4);
                                }
                            }
                            goto Label_0833;
                        }
                    }
                }
                if (this.VariablePath.IsUnqualified)
                {
                    for (int i = 0; i < SpecialVariables.AutomaticVariables.Length; i++)
                    {
                        if (this.VariablePath.UserPath.Equals(SpecialVariables.AutomaticVariables[i], StringComparison.OrdinalIgnoreCase))
                        {
                            Type type = SpecialVariables.AutomaticVariableTypes[i];
                            if (!type.Equals(typeof(object)))
                            {
                                yield return(new PSTypeName(type));

                                break;
                            }
                            break;
                        }
                    }
                }
                while (parent.Parent != null)
                {
                    parent = parent.Parent;
                }
                if (parent.Parent is FunctionDefinitionAst)
                {
                    parent = parent.Parent;
                }
                IEnumerable <Ast> source             = AstSearcher.FindAll(parent, ast => (((ast is ParameterAst) || (ast is AssignmentStatementAst)) || (ast is ForEachStatementAst)) && this.AstAssignsToSameVariable(ast), true);
                ParameterAst      iteratorVariable10 = source.OfType <ParameterAst>().FirstOrDefault <ParameterAst>();
                if (iteratorVariable10 != null)
                {
                    PSTypeName[] iteratorVariable11 = iteratorVariable10.GetInferredType(context).ToArray <PSTypeName>();
                    if (iteratorVariable11.Length > 0)
                    {
                        foreach (PSTypeName iteratorVariable12 in iteratorVariable11)
                        {
                            yield return(iteratorVariable12);
                        }
                        goto Label_0833;
                    }
                }
                AssignmentStatementAst[] iteratorVariable13 = source.OfType <AssignmentStatementAst>().ToArray <AssignmentStatementAst>();
                foreach (AssignmentStatementAst iteratorVariable14 in iteratorVariable13)
                {
                    ConvertExpressionAst left = iteratorVariable14.Left as ConvertExpressionAst;
                    if ((left != null) && (left.StaticType != null))
                    {
                        yield return(new PSTypeName(left.StaticType));

                        goto Label_0833;
                    }
                }
                ForEachStatementAst iteratorVariable16 = source.OfType <ForEachStatementAst>().FirstOrDefault <ForEachStatementAst>();
                if (iteratorVariable16 != null)
                {
                    foreach (PSTypeName iteratorVariable17 in iteratorVariable16.Condition.GetInferredType(context))
                    {
                        yield return(iteratorVariable17);
                    }
                }
                else
                {
                    int startOffset        = this.Extent.StartOffset;
                    int iteratorVariable19 = 0x7fffffff;
                    AssignmentStatementAst iteratorVariable20 = null;
                    foreach (AssignmentStatementAst ast in iteratorVariable13)
                    {
                        int endOffset = ast.Extent.EndOffset;
                        if ((endOffset < startOffset) && ((startOffset - endOffset) < iteratorVariable19))
                        {
                            iteratorVariable19 = startOffset - endOffset;
                            iteratorVariable20 = ast;
                        }
                    }
                    if (iteratorVariable20 != null)
                    {
                        foreach (PSTypeName iteratorVariable21 in iteratorVariable20.Right.GetInferredType(context))
                        {
                            yield return(iteratorVariable21);
                        }
                    }
                }
            }
Label_0833:
            yield break;
        }
Example #18
0
 public override AstVisitAction VisitParameter(ParameterAst ast)
 {
     return(Check(ast));
 }
Example #19
0
 /// <summary/>
 public virtual AstVisitAction VisitParameter(ParameterAst parameterAst) => DefaultVisit(parameterAst);
Example #20
0
 public object VisitParameter(ParameterAst parameterAst)
 {
     return(false);
 }
Example #21
0
        public override AstVisitAction VisitParameter(ParameterAst parameterAst)
        {
            Diagnostics.Assert(FoundError, "VisitParamBlock or VisitFunctionDeclaration should have already reported an error");

            return AstVisitAction.Continue;
        }
 /// <summary>
 /// Returns script extent of username and password parameters
 /// </summary>
 /// <param name="usernameAst"></param>
 /// <param name="passwordAst"></param>
 /// <returns>IScriptExtent</returns>
 private IScriptExtent GetExtent(ParameterAst usernameAst, ParameterAst passwordAst, Ast scriptAst)
 {
     var usrExt = usernameAst.Extent;
     var pwdExt = passwordAst.Extent;
     IScriptExtent startExt, endExt;
     var usrBeforePwd
         = (usrExt.StartLineNumber == pwdExt.StartLineNumber
             && usrExt.StartColumnNumber < pwdExt.StartColumnNumber)
             || usrExt.StartLineNumber < pwdExt.StartLineNumber;
     if (usrBeforePwd)
     {
         startExt = usrExt;
         endExt = pwdExt;
     }
     else
     {
         startExt = pwdExt;
         endExt = usrExt;
     }
     var startPos = new ScriptPosition(
         startExt.File,
         startExt.StartLineNumber,
         startExt.StartColumnNumber,
         startExt.StartScriptPosition.Line);
     var endPos = new ScriptPosition(
         endExt.File,
         endExt.EndLineNumber,
         endExt.EndColumnNumber,
         endExt.EndScriptPosition.Line);
     return new ScriptExtent(startPos, endPos);
 }
Example #23
0
        public override AstVisitAction VisitParameter(ParameterAst parameterAst)
        {
            bool isClassMethod = parameterAst.Parent.Parent is FunctionMemberAst;
            bool isParamTypeDefined = false;
            foreach (AttributeBaseAst attribute in parameterAst.Attributes)
            {
                if (attribute is TypeConstraintAst)
                {
                    if (attribute.TypeName.FullName.Equals(LanguagePrimitives.OrderedAttribute, StringComparison.OrdinalIgnoreCase))
                    {
                        _parser.ReportError(attribute.Extent, () => ParserStrings.OrderedAttributeOnlyOnHashLiteralNode, attribute.TypeName.FullName);
                    }
                    else
                    {
                        if (isClassMethod)
                        {
                            // attribute represent parameter type.
                            if (isParamTypeDefined)
                            {
                                _parser.ReportError(attribute.Extent, () => ParserStrings.MultipleTypeConstraintsOnMethodParam);
                            }
                            isParamTypeDefined = true;
                        }
                    }
                }
            }

            return AstVisitAction.Continue;
        }
 /// <summary>
 /// Visit parameter
 /// </summary>
 /// <param name="parameterAst"></param>
 /// <returns></returns>
 public object VisitParameter(ParameterAst parameterAst)
 {
     // Nothing to do now, we've already allocated parameters in the first pass looking for all variable names.
     System.Diagnostics.Debug.Assert(false, "Code is unreachable");
     return null;
 }
Example #25
0
        internal string ToStringForSerialization(Tuple <List <VariableExpressionAst>, string> usingVariablesTuple, int initialStartOffset, int initialEndOffset)
        {
            List <VariableExpressionAst> collection = usingVariablesTuple.Item1;
            string     str   = usingVariablesTuple.Item2;
            List <Ast> list2 = new List <Ast>(collection);

            if (this.ParamBlock != null)
            {
                list2.Add(this.ParamBlock);
            }
            int           startOffset = base.Extent.StartOffset;
            int           startIndex  = initialStartOffset - startOffset;
            int           num3        = initialEndOffset - startOffset;
            string        str2        = this.ToString();
            StringBuilder builder     = new StringBuilder();

            foreach (Ast ast in from ast in list2
                     orderby ast.Extent.StartOffset
                     select ast)
            {
                int num4 = ast.Extent.StartOffset - startOffset;
                int num5 = ast.Extent.EndOffset - startOffset;
                if (num4 >= startIndex)
                {
                    if (num4 >= num3)
                    {
                        break;
                    }
                    VariableExpressionAst ast2 = ast as VariableExpressionAst;
                    if (ast2 != null)
                    {
                        string userPath = ast2.VariablePath.UserPath;
                        string str4     = ast2.Splatted ? "@" : "$";
                        string str5     = str4 + "__using_" + userPath;
                        builder.Append(str2.Substring(startIndex, num4 - startIndex));
                        builder.Append(str5);
                        startIndex = num5;
                    }
                    else
                    {
                        int           num6;
                        ParamBlockAst ast3 = ast as ParamBlockAst;
                        if (ast3.Parameters.Count == 0)
                        {
                            num6 = num5 - 1;
                        }
                        else
                        {
                            ParameterAst ast4 = ast3.Parameters[0];
                            num6 = (ast4.Attributes.Count == 0) ? (ast4.Name.Extent.StartOffset - startOffset) : (ast4.Attributes[0].Extent.StartOffset - startOffset);
                            str  = str + ",\n";
                        }
                        builder.Append(str2.Substring(startIndex, num6 - startIndex));
                        builder.Append(str);
                        startIndex = num6;
                    }
                }
            }
            builder.Append(str2.Substring(startIndex, num3 - startIndex));
            string str6 = builder.ToString();

            if (((base.Parent is ScriptBlockExpressionAst) && (initialStartOffset == base.Extent.StartOffset)) && (initialEndOffset == base.Extent.EndOffset))
            {
                str6 = str6.Substring(1, str6.Length - 2);
            }
            return(str6);
        }
        private bool WrongCredentialUsage(ParameterAst parameter)
        {
            if (parameter.Name.VariablePath.UserPath.Equals("Credential", StringComparison.OrdinalIgnoreCase))
            {
                var psCredentialType = parameter.Attributes.FirstOrDefault(paramAttribute => (paramAttribute.TypeName.IsArray && (paramAttribute.TypeName as ArrayTypeName).ElementType.GetReflectionType() == typeof(PSCredential))
                    || paramAttribute.TypeName.GetReflectionType() == typeof(PSCredential));

                var credentialAttribute = parameter.Attributes.FirstOrDefault(paramAttribute => paramAttribute.TypeName.GetReflectionType() == typeof(CredentialAttribute));

                // check that both exists and pscredentialtype comes before credential attribute
                if (psCredentialType != null && credentialAttribute != null && psCredentialType.Extent.EndOffset < credentialAttribute.Extent.StartOffset)
                {
                    return false;
                }

                return true;
            }

            return false;
        }
Example #27
0
 private object GetParameterValue(ParameterAst scriptParameter, CommandParameter parameter)
 {
     if (parameter != null)
     {
         return parameter.Value;
     }
     return _scopedExecutionVisitor.EvaluateAst(scriptParameter.DefaultValue);;
 }
Example #28
0
 private object GetDefaultParameterValue(ParameterAst scriptParameter)
 {
     var constantExpression = scriptParameter.DefaultValue as ConstantExpressionAst;
     if (constantExpression != null)
     {
         return constantExpression.Value;
     }
     return null;
 }
 public object VisitParameter(ParameterAst parameterAst) { throw new UnexpectedElementException(); }
Example #30
0
 private object GetParameterValue(ParameterAst scriptParameter, CommandParameter argument)
 {
     if (argument != null)
     {
         return argument.Value;
     }
     if (scriptParameter.DefaultValue == null)
     {
         return null;
     }
     return _executionVisitor.EvaluateAst(scriptParameter.DefaultValue);
 }
 public override AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     return(AstVisitAction.Continue);
 }
Example #32
0
 public override AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     throw new NotImplementedException(); //VisitParameter(parameterAst);
 }
Example #33
0
 public override AstVisitAction VisitParameter(ParameterAst ast)
 {
     return this.Check(ast);
 }
Example #34
0
 public object VisitParameter(ParameterAst parameterAst) { return AutomationNull.Value; }
Example #35
0
 public object VisitParameter(ParameterAst parameterAst) { throw PSTraceSource.NewArgumentException("ast"); }
Example #36
0
 /// <summary/>
 public virtual object VisitParameter(ParameterAst parameterAst)
 {
     return(null);
 }
Example #37
0
        private static RuntimeDefinedParameter GetRuntimeDefinedParameter(ParameterAst parameterAst, ref bool customParameterSet, ref bool usesCmdletBinding)
        {
            List<Attribute> attributes = new List<Attribute>();
            bool hasParameterAttribute = false;
            for (int index = 0; index < parameterAst.Attributes.Count; index++)
            {
                var attributeAst = parameterAst.Attributes[index];
                var attribute = attributeAst.GetAttribute();
                attributes.Add(attribute);

                var parameterAttribute = attribute as ParameterAttribute;
                if (parameterAttribute != null)
                {
                    hasParameterAttribute = true;
                    usesCmdletBinding = true;
                    if (parameterAttribute.Position != int.MinValue ||
                        !parameterAttribute.ParameterSetName.Equals(ParameterAttribute.AllParameterSets,
                                                                    StringComparison.OrdinalIgnoreCase))
                    {
                        customParameterSet = true;
                    }
                }
            }

            attributes.Reverse();
            if (!hasParameterAttribute)
            {
                attributes.Insert(0, new ParameterAttribute());
            }

            var result = new RuntimeDefinedParameter(parameterAst.Name.VariablePath.UserPath, parameterAst.StaticType,
                                                     new Collection<Attribute>(attributes.ToArray()));

            if (parameterAst.DefaultValue != null)
            {
                object constantValue;
                if (IsConstantValueVisitor.IsConstant(parameterAst.DefaultValue, out constantValue))
                {
                    result.Value = constantValue;
                }
                else
                {
                    // Expression isn't constant, create a wrapper that holds the ast, and if necessary,
                    // will cache a delegate to evaluate the default value.
                    result.Value = new DefaultValueExpressionWrapper { Expression = parameterAst.DefaultValue };
                }
            }
            else
            {
                object defaultValue;
                if (TryGetDefaultParameterValue(parameterAst.StaticType, out defaultValue) && defaultValue != null)
                {
                    // Skip setting the value when defaultValue is null because if we do call the setter,
                    // we'll try converting null to the parameter, which we might not want, e.g. if the parameter is [ref].
                    result.Value = defaultValue;
                }
            }
            return result;
        }
Example #38
0
 public object VisitParameter(ParameterAst parameterAst)
 {
     return false;
 }
Example #39
0
 public object VisitParameter(ParameterAst parameterAst)
 {
     Diagnostics.Assert(false, "Nothing to generate for a parameter");
     return null;
 }
Example #40
0
 /// <summary/>
 public virtual AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     return(AstVisitAction.Continue);
 }
 public override AstVisitAction VisitParameter(ParameterAst parameterAst)
 {
     return AstVisitAction.Continue;
 }
Example #42
0
 public object VisitParameter(ParameterAst parameterAst)
 {
     return(AutomationNull.Value);
 }
Example #43
0
 public override AstVisitAction VisitParameter(ParameterAst ast) { return CheckParent(ast); }