Beispiel #1
0
        private static IEnumerable <ExpressionAst> GetAssignmentTargets(ExpressionAst expressionAst)
        {
            ParenExpressionAst iteratorVariable0 = expressionAst as ParenExpressionAst;

            if (iteratorVariable0 != null)
            {
                foreach (ExpressionAst iteratorVariable1 in GetAssignmentTargets(iteratorVariable0.Pipeline.GetPureExpression()))
                {
                    yield return(iteratorVariable1);
                }
            }
            else
            {
                ArrayLiteralAst iteratorVariable2 = expressionAst as ArrayLiteralAst;
                if (iteratorVariable2 != null)
                {
                    foreach (ExpressionAst iteratorVariable3 in iteratorVariable2.Elements.SelectMany <ExpressionAst, ExpressionAst>(new Func <ExpressionAst, IEnumerable <ExpressionAst> >(VariableAnalysis.GetAssignmentTargets)))
                    {
                        yield return(iteratorVariable3);
                    }
                }
                else
                {
                    yield return(expressionAst);
                }
            }
        }
Beispiel #2
0
        private void CheckLHSAssign(ExpressionAst lhs, BitArray assignedBitArray)
        {
            ConvertExpressionAst ast = lhs as ConvertExpressionAst;
            Type convertType         = null;

            if (ast != null)
            {
                lhs         = ast.Child;
                convertType = ast.StaticType;
            }
            VariableExpressionAst item         = lhs as VariableExpressionAst;
            VariablePath          variablePath = item.VariablePath;

            if (variablePath.IsAnyLocal())
            {
                string unaliasedVariableName = GetUnaliasedVariableName(variablePath);
                if ((convertType == null) && (unaliasedVariableName.Equals("foreach", StringComparison.OrdinalIgnoreCase) || unaliasedVariableName.Equals("switch", StringComparison.OrdinalIgnoreCase)))
                {
                    convertType = typeof(object);
                }
                VariableAnalysisDetails details = this.CheckLHSAssignVar(unaliasedVariableName, assignedBitArray, convertType);
                details.AssociatedAsts.Add(item);
                item.TupleIndex = details.LocalTupleIndex;
                item.Automatic  = details.Automatic;
            }
            else
            {
                item.TupleIndex = -2;
            }
        }
 private static bool IsNullDivisor(ExpressionAst operand)
 {
     VariableExpressionAst ast = operand as VariableExpressionAst;
     if (ast != null)
     {
         BinaryExpressionAst parent = operand.Parent as BinaryExpressionAst;
         if ((parent == null) || (parent.Right != operand))
         {
             return false;
         }
         switch (parent.Operator)
         {
             case TokenKind.Divide:
             case TokenKind.Rem:
             case TokenKind.DivideEquals:
             case TokenKind.RemainderEquals:
             {
                 string unqualifiedPath = ast.VariablePath.UnqualifiedPath;
                 if (!unqualifiedPath.Equals("false", StringComparison.OrdinalIgnoreCase))
                 {
                     return unqualifiedPath.Equals("null", StringComparison.OrdinalIgnoreCase);
                 }
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #4
0
        private ExpressionAst CheckUsingExpression(ExpressionAst exprAst)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            if (exprAst is VariableExpressionAst)
            {
                return(null);
            }
            MemberExpressionAst ast = exprAst as MemberExpressionAst;

            if (((ast != null) && !(ast is InvokeMemberExpressionAst)) && (ast.Member is StringConstantExpressionAst))
            {
                return(this.CheckUsingExpression(ast.Expression));
            }
            IndexExpressionAst ast2 = exprAst as IndexExpressionAst;

            if (ast2 == null)
            {
                return(exprAst);
            }
            if (!this.IsValidAttributeArgument(ast2.Index))
            {
                return(ast2.Index);
            }
            return(this.CheckUsingExpression(ast2.Target));
        }
Beispiel #5
0
 public MemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst member, bool @static)
     : base(extent)
 {
     this.Expression = expression;
     this.Member     = member;
     this.Static     = @static;
 }
Beispiel #6
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)));
        }
Beispiel #7
0
        private static bool IsNullDivisor(ExpressionAst operand)
        {
            var varExpr = operand as VariableExpressionAst;

            if (varExpr == null)
            {
                return(false);
            }

            var parent = operand.Parent as BinaryExpressionAst;

            if (parent == null || parent.Right != operand)
            {
                return(false);
            }

            switch (parent.Operator)
            {
            case TokenKind.Divide:
            case TokenKind.DivideEquals:
            case TokenKind.Rem:
            case TokenKind.RemainderEquals:
                string name = varExpr.VariablePath.UnqualifiedPath;
                return(name.Equals(SpecialVariables.False, StringComparison.OrdinalIgnoreCase) ||
                       name.Equals(SpecialVariables.Null, StringComparison.OrdinalIgnoreCase));
            }

            return(false);
        }
        public AssignmentStatementAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, StatementAst right, IScriptExtent errorPosition) : base(extent)
        {
            if (((left == null) || (right == null)) || (errorPosition == null))
            {
                throw PSTraceSource.NewArgumentNullException((left == null) ? "left" : ((right == null) ? "right" : "errorPosition"));
            }
            if ((@operator.GetTraits() & TokenFlags.AssignmentOperator) == TokenFlags.None)
            {
                throw PSTraceSource.NewArgumentException("operator");
            }
            PipelineAst ast = right as PipelineAst;

            if ((ast != null) && (ast.PipelineElements.Count == 1))
            {
                CommandExpressionAst ast2 = ast.PipelineElements[0] as CommandExpressionAst;
                if (ast2 != null)
                {
                    right = ast2;
                    right.ClearParent();
                }
            }
            this.Operator = @operator;
            this.Left     = left;
            base.SetParent(left);
            this.Right = right;
            base.SetParent(right);
            this.ErrorPosition = errorPosition;
        }
 public CommandParameterAst(IScriptExtent extent, string parameterName, ExpressionAst argument, IScriptExtent errorPosition)
     : base(extent)
 {
     this.ParameterName = parameterName;
     this.Argument = argument;
     this.ErrorPosition = errorPosition;
 }
Beispiel #10
0
        private static bool IsNullDivisor(ExpressionAst operand)
        {
            VariableExpressionAst ast = operand as VariableExpressionAst;

            if (ast != null)
            {
                BinaryExpressionAst parent = operand.Parent as BinaryExpressionAst;
                if ((parent == null) || (parent.Right != operand))
                {
                    return(false);
                }
                switch (parent.Operator)
                {
                case TokenKind.Divide:
                case TokenKind.Rem:
                case TokenKind.DivideEquals:
                case TokenKind.RemainderEquals:
                {
                    string unqualifiedPath = ast.VariablePath.UnqualifiedPath;
                    if (!unqualifiedPath.Equals("false", StringComparison.OrdinalIgnoreCase))
                    {
                        return(unqualifiedPath.Equals("null", StringComparison.OrdinalIgnoreCase));
                    }
                    return(true);
                }
                }
            }
            return(false);
        }
        public ExpandableStringExpressionAst(IScriptExtent extent, string value, System.Management.Automation.Language.StringConstantType type) : base(extent)
        {
            if (value == null)
            {
                throw PSTraceSource.NewArgumentNullException("value");
            }
            if (((type != System.Management.Automation.Language.StringConstantType.DoubleQuoted) && (type != System.Management.Automation.Language.StringConstantType.DoubleQuotedHereString)) && (type != System.Management.Automation.Language.StringConstantType.BareWord))
            {
                throw PSTraceSource.NewArgumentException("type");
            }
            ExpressionAst ast = Parser.ScanString(value);
            ExpandableStringExpressionAst ast2 = ast as ExpandableStringExpressionAst;

            if (ast2 != null)
            {
                this.FormatExpression  = ast2.FormatExpression;
                this.NestedExpressions = ast2.NestedExpressions;
            }
            else
            {
                this.FormatExpression  = "{0}";
                this.NestedExpressions = new ReadOnlyCollection <ExpressionAst>(new ExpressionAst[] { ast });
            }
            this.Value = value;
            this.StringConstantType = type;
        }
 public NamedAttributeArgumentAst(IScriptExtent extent, string argumentName, ExpressionAst argument, bool expressionOmitted)
     : base(extent)
 {
     this.Argument = argument;
     this.ArgumentName = argumentName;
     this.ExpressionOmitted = expressionOmitted;
 }
Beispiel #13
0
 public MemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst member, bool @static)
     : base(extent)
 {
     this.Expression = expression;
     this.Member = member;
     this.Static = @static;
 }
Beispiel #14
0
 public ParameterAst(IScriptExtent extent, VariableExpressionAst name, IEnumerable<AttributeBaseAst> attributes, ExpressionAst defaultValue)
     : base(extent)
 {
     this.Name = name;
     this.Attributes = attributes.ToReadOnlyCollection();
     this.DefaultValue = defaultValue;
 }
 public NamedAttributeArgumentAst(IScriptExtent extent, string argumentName, ExpressionAst argument, bool expressionOmitted)
     : base(extent)
 {
     this.Argument          = argument;
     this.ArgumentName      = argumentName;
     this.ExpressionOmitted = expressionOmitted;
 }
        public Expression SetValue(Compiler compiler, Expression rhs)
        {
            ParameterExpression left = Expression.Variable(rhs.Type);
            int count = this.ArrayLiteral.Elements.Count;
            List <Expression> expressions = new List <Expression> {
                Expression.Assign(left, rhs)
            };

            for (int i = 0; i < count; i++)
            {
                Expression      expression2    = Expression.Call(left, CachedReflectionInfo.IList_get_Item, new Expression[] { ExpressionCache.Constant(i) });
                ExpressionAst   ast            = this.ArrayLiteral.Elements[i];
                ArrayLiteralAst pureExpression = ast as ArrayLiteralAst;
                if (ast is ParenExpressionAst)
                {
                    pureExpression = ((ParenExpressionAst)ast).Pipeline.GetPureExpression() as ArrayLiteralAst;
                }
                if (pureExpression != null)
                {
                    expression2 = Expression.Dynamic(PSArrayAssignmentRHSBinder.Get(pureExpression.Elements.Count), typeof(IList), expression2);
                }
                expressions.Add(compiler.ReduceAssignment((ISupportsAssignment)ast, TokenKind.Equals, expression2));
            }
            expressions.Add(left);
            return(Expression.Block(new ParameterExpression[] { left }, expressions));
        }
        internal static Dictionary <string, VariableAnalysisDetails> Visit(ExpressionAst exprAst)
        {
            FindAllVariablesVisitor visitor = new FindAllVariablesVisitor(true, false);

            exprAst.InternalVisit(visitor);
            return(visitor._variables);
        }
        private string ReplaceExpandableValue(string expStr, ExpressionAst ast, string value)
        {
            var relStart = ast.Extent.StartOffset - Extent.StartOffset - 1;
            var relEnd   = ast.Extent.EndOffset - Extent.StartOffset - 1;

            return(expStr.Substring(0, relStart) + value + expStr.Substring(relEnd));
        }
Beispiel #19
0
 public CommandParameterAst(IScriptExtent extent, string parameterName, ExpressionAst argument, IScriptExtent errorPosition)
     : base(extent)
 {
     this.ParameterName = parameterName;
     this.Argument      = argument;
     this.ErrorPosition = errorPosition;
 }
Beispiel #20
0
 private static VariableExpressionAst ExtractUsingVariableImpl(ExpressionAst expression)
 {
     VariableExpressionAst subExpression;
     UsingExpressionAst ast = expression as UsingExpressionAst;
     if (ast != null)
     {
         subExpression = ast.SubExpression as VariableExpressionAst;
         if (subExpression != null)
         {
             return subExpression;
         }
         return ExtractUsingVariableImpl(ast.SubExpression);
     }
     IndexExpressionAst ast3 = expression as IndexExpressionAst;
     if (ast3 != null)
     {
         subExpression = ast3.Target as VariableExpressionAst;
         if (subExpression != null)
         {
             return subExpression;
         }
         return ExtractUsingVariableImpl(ast3.Target);
     }
     MemberExpressionAst ast4 = expression as MemberExpressionAst;
     if (ast4 == null)
     {
         return null;
     }
     subExpression = ast4.Expression as VariableExpressionAst;
     if (subExpression != null)
     {
         return subExpression;
     }
     return ExtractUsingVariableImpl(ast4.Expression);
 }
Beispiel #21
0
 internal static bool TrySafeEval(ExpressionAst ast, ExecutionContext executionContext, out object value)
 {
     bool flag;
     if (!((bool) ast.Accept(new SafeExprEvaluator())))
     {
         value = null;
         return false;
     }
     PSLanguageMode? nullable = null;
     try
     {
         if (ExecutionContext.HasEverUsedConstrainedLanguage)
         {
             nullable = new PSLanguageMode?(executionContext.LanguageMode);
             executionContext.LanguageMode = PSLanguageMode.ConstrainedLanguage;
         }
         value = Compiler.GetExpressionValue(ast, executionContext, (IList)null);
         flag = true;
     }
     catch
     {
         value = null;
         flag = false;
     }
     finally
     {
         if (nullable.HasValue)
         {
             executionContext.LanguageMode = nullable.Value;
         }
     }
     return flag;
 }
Beispiel #22
0
 public AssignmentStatementAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, StatementAst right, IScriptExtent errorPosition) : base(extent)
 {
     if (((left == null) || (right == null)) || (errorPosition == null))
     {
         throw PSTraceSource.NewArgumentNullException((left == null) ? "left" : ((right == null) ? "right" : "errorPosition"));
     }
     if ((@operator.GetTraits() & TokenFlags.AssignmentOperator) == TokenFlags.None)
     {
         throw PSTraceSource.NewArgumentException("operator");
     }
     PipelineAst ast = right as PipelineAst;
     if ((ast != null) && (ast.PipelineElements.Count == 1))
     {
         CommandExpressionAst ast2 = ast.PipelineElements[0] as CommandExpressionAst;
         if (ast2 != null)
         {
             right = ast2;
             right.ClearParent();
         }
     }
     this.Operator = @operator;
     this.Left = left;
     base.SetParent(left);
     this.Right = right;
     base.SetParent(right);
     this.ErrorPosition = errorPosition;
 }
 public InvokeMemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst method, IEnumerable<ExpressionAst> arguments, bool @static) : base(extent, expression, method, @static)
 {
     if ((arguments != null) && arguments.Any<ExpressionAst>())
     {
         this.Arguments = new ReadOnlyCollection<ExpressionAst>(arguments.ToArray<ExpressionAst>());
         base.SetParents((IEnumerable<Ast>) this.Arguments);
     }
 }
 public InvokeMemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst method, IEnumerable <ExpressionAst> arguments, bool @static) : base(extent, expression, method, @static)
 {
     if ((arguments != null) && arguments.Any <ExpressionAst>())
     {
         this.Arguments = new ReadOnlyCollection <ExpressionAst>(arguments.ToArray <ExpressionAst>());
         base.SetParents((IEnumerable <Ast>) this.Arguments);
     }
 }
 public AssignmentStatementAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, StatementAst right, IScriptExtent errorPosition)
     : base(extent)
 {
     this.Left = left;
     this.Operator = @operator;
     this.Right = right;
     this.ErrorPosition = errorPosition;
 }
Beispiel #26
0
 public AssignmentStatementAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, StatementAst right, IScriptExtent errorPosition)
     : base(extent)
 {
     this.Left          = left;
     this.Operator      = @operator;
     this.Right         = right;
     this.ErrorPosition = errorPosition;
 }
Beispiel #27
0
 public BinaryExpressionAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, ExpressionAst right, IScriptExtent errorPosition)
     : base(extent)
 {
     this.Left          = left;
     this.Operator      = @operator;
     this.Right         = @right;
     this.ErrorPosition = errorPosition;
 }
Beispiel #28
0
 public BreakStatementAst(IScriptExtent extent, ExpressionAst label) : base(extent)
 {
     if (label != null)
     {
         this.Label = label;
         base.SetParent(label);
     }
 }
 public BinaryExpressionAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, ExpressionAst right, IScriptExtent errorPosition)
     : base(extent)
 {
     this.Left = left;
     this.Operator = @operator;
     this.Right = @right;
     this.ErrorPosition = errorPosition;
 }
Beispiel #30
0
 public ContinueStatementAst(IScriptExtent extent, ExpressionAst label) : base(extent)
 {
     if (label != null)
     {
         this.Label = label;
         base.SetParent(label);
     }
 }
Beispiel #31
0
 internal CommandParameterAst(IScriptExtent extent, string parameterName, ExpressionAst argument,
                              IScriptExtent errorPosition, bool requiresValue)
     : base(extent)
 {
     this.ParameterName = parameterName;
     this.Argument      = argument;
     this.ErrorPosition = errorPosition;
     RequiresArgument   = requiresValue;
 }
Beispiel #32
0
 public CommandExpressionAst(IScriptExtent extent, ExpressionAst expression, IEnumerable<RedirectionAst> redirections) : base(extent, redirections)
 {
     if (expression == null)
     {
         throw PSTraceSource.NewArgumentNullException("expression");
     }
     this.Expression = expression;
     base.SetParent(expression);
 }
Beispiel #33
0
 internal CommandParameterAst(IScriptExtent extent, string parameterName, ExpressionAst argument,
                              IScriptExtent errorPosition, bool requiresValue)
     : base(extent)
 {
     this.ParameterName = parameterName;
     this.Argument = argument;
     this.ErrorPosition = errorPosition;
     RequiresArgument = requiresValue;
 }
Beispiel #34
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;
 }
Beispiel #35
0
 public CommandExpressionAst(IScriptExtent extent, ExpressionAst expression, IEnumerable <RedirectionAst> redirections) : base(extent, redirections)
 {
     if (expression == null)
     {
         throw PSTraceSource.NewArgumentNullException("expression");
     }
     this.Expression = expression;
     base.SetParent(expression);
 }
Beispiel #36
0
        private ISupportsAssignment GetActualAssignableAst()
        {
            ExpressionAst child = this;

            for (AttributedExpressionAst ast2 = child as AttributedExpressionAst; ast2 != null; ast2 = child as AttributedExpressionAst)
            {
                child = ast2.Child;
            }
            return((ISupportsAssignment)child);
        }
Beispiel #37
0
 public FileRedirectionAst(IScriptExtent extent, RedirectionStream stream, ExpressionAst file, bool append) : base(extent, stream)
 {
     if (file == null)
     {
         throw PSTraceSource.NewArgumentNullException("file");
     }
     this.Location = file;
     base.SetParent(file);
     this.Append = append;
 }
 public UsingExpressionAst(IScriptExtent extent, ExpressionAst expressionAst) : base(extent)
 {
     if (expressionAst == null)
     {
         throw PSTraceSource.NewArgumentNullException("expressionAst");
     }
     this.SubExpression = expressionAst;
     base.SetParent(this.SubExpression);
     this.RuntimeUsingIndex = -1;
 }
Beispiel #39
0
 public FileRedirectionAst(IScriptExtent extent, RedirectionStream stream, ExpressionAst file, bool append) : base(extent, stream)
 {
     if (file == null)
     {
         throw PSTraceSource.NewArgumentNullException("file");
     }
     this.Location = file;
     base.SetParent(file);
     this.Append = append;
 }
Beispiel #40
0
 public UsingExpressionAst(IScriptExtent extent, ExpressionAst expressionAst) : base(extent)
 {
     if (expressionAst == null)
     {
         throw PSTraceSource.NewArgumentNullException("expressionAst");
     }
     this.SubExpression = expressionAst;
     base.SetParent(this.SubExpression);
     this.RuntimeUsingIndex = -1;
 }
Beispiel #41
0
 public IndexExpressionAst(IScriptExtent extent, ExpressionAst target, ExpressionAst index) : base(extent)
 {
     if ((target == null) || (index == null))
     {
         throw PSTraceSource.NewArgumentNullException((target == null) ? "target" : "index");
     }
     this.Target = target;
     base.SetParent(target);
     this.Index = index;
     base.SetParent(index);
 }
 public IndexExpressionAst(IScriptExtent extent, ExpressionAst target, ExpressionAst index) : base(extent)
 {
     if ((target == null) || (index == null))
     {
         throw PSTraceSource.NewArgumentNullException((target == null) ? "target" : "index");
     }
     this.Target = target;
     base.SetParent(target);
     this.Index = index;
     base.SetParent(index);
 }
 public AttributedExpressionAst(IScriptExtent extent, AttributeBaseAst attribute, ExpressionAst child) : base(extent)
 {
     if ((attribute == null) || (child == null))
     {
         throw PSTraceSource.NewArgumentNullException((attribute == null) ? "attribute" : "child");
     }
     this.Attribute = attribute;
     base.SetParent(attribute);
     this.Child = child;
     base.SetParent(child);
 }
Beispiel #44
0
        public override AstVisitAction VisitUsingExpression(UsingExpressionAst usingExpressionAst)
        {
            ExpressionAst subExpression = usingExpressionAst.SubExpression;
            ExpressionAst ast2          = this.CheckUsingExpression(subExpression);

            if (ast2 != null)
            {
                this._parser.ReportError(ast2.Extent, ParserStrings.InvalidUsingExpression, new object[0]);
            }
            return(AstVisitAction.Continue);
        }
Beispiel #45
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));
 }
Beispiel #46
0
 public MemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst member, bool @static) : base(extent)
 {
     if ((expression == null) || (member == null))
     {
         throw PSTraceSource.NewArgumentNullException((expression == null) ? "expression" : "member");
     }
     this.Expression = expression;
     base.SetParent(expression);
     this.Member = member;
     base.SetParent(member);
     this.Static = @static;
 }
Beispiel #47
0
 public MemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst member, bool @static) : base(extent)
 {
     if ((expression == null) || (member == null))
     {
         throw PSTraceSource.NewArgumentNullException((expression == null) ? "expression" : "member");
     }
     this.Expression = expression;
     base.SetParent(expression);
     this.Member = member;
     base.SetParent(member);
     this.Static = @static;
 }
Beispiel #48
0
 public UnaryExpressionAst(IScriptExtent extent, System.Management.Automation.Language.TokenKind tokenKind, ExpressionAst child) : base(extent)
 {
     if ((tokenKind.GetTraits() & TokenFlags.UnaryOperator) == TokenFlags.None)
     {
         throw PSTraceSource.NewArgumentException("tokenKind");
     }
     if (child == null)
     {
         throw PSTraceSource.NewArgumentNullException("child");
     }
     this.TokenKind = tokenKind;
     this.Child = child;
     base.SetParent(child);
 }
Beispiel #49
0
 public CommandParameterAst(IScriptExtent extent, string parameterName, ExpressionAst argument, IScriptExtent errorPosition) : base(extent)
 {
     if ((errorPosition == null) || string.IsNullOrEmpty(parameterName))
     {
         throw PSTraceSource.NewArgumentNullException((errorPosition == null) ? "errorPosition" : "parameterName");
     }
     this.ParameterName = parameterName;
     if (argument != null)
     {
         this.Argument = argument;
         base.SetParent(argument);
     }
     this.ErrorPosition = errorPosition;
 }
Beispiel #50
0
        private static string GetLabel(ExpressionAst expr)
        {
            if (expr == null)
            {
                return("");
            }
            StringConstantExpressionAst ast = expr as StringConstantExpressionAst;

            if (ast == null)
            {
                return(null);
            }
            return(ast.Value);
        }
 public CommandParameterAst(IScriptExtent extent, string parameterName, ExpressionAst argument, IScriptExtent errorPosition) : base(extent)
 {
     if ((errorPosition == null) || string.IsNullOrEmpty(parameterName))
     {
         throw PSTraceSource.NewArgumentNullException((errorPosition == null) ? "errorPosition" : "parameterName");
     }
     this.ParameterName = parameterName;
     if (argument != null)
     {
         this.Argument = argument;
         base.SetParent(argument);
     }
     this.ErrorPosition = errorPosition;
 }
 public NamedAttributeArgumentAst(IScriptExtent extent, string argumentName, ExpressionAst argument, bool expressionOmitted) : base(extent)
 {
     if (string.IsNullOrEmpty(argumentName))
     {
         throw PSTraceSource.NewArgumentNullException("argumentName");
     }
     if (argument == null)
     {
         throw PSTraceSource.NewArgumentNullException("argument");
     }
     this.Argument = argument;
     base.SetParent(argument);
     this.ArgumentName      = argumentName;
     this.ExpressionOmitted = expressionOmitted;
 }
 public NamedAttributeArgumentAst(IScriptExtent extent, string argumentName, ExpressionAst argument, bool expressionOmitted) : base(extent)
 {
     if (string.IsNullOrEmpty(argumentName))
     {
         throw PSTraceSource.NewArgumentNullException("argumentName");
     }
     if (argument == null)
     {
         throw PSTraceSource.NewArgumentNullException("argument");
     }
     this.Argument = argument;
     base.SetParent(argument);
     this.ArgumentName = argumentName;
     this.ExpressionOmitted = expressionOmitted;
 }
Beispiel #54
0
 public BinaryExpressionAst(IScriptExtent extent, ExpressionAst left, TokenKind @operator, ExpressionAst right, IScriptExtent errorPosition) : base(extent)
 {
     if ((@operator.GetTraits() & TokenFlags.BinaryOperator) == TokenFlags.None)
     {
         throw PSTraceSource.NewArgumentException("operator");
     }
     if (((left == null) || (right == null)) || (errorPosition == null))
     {
         throw PSTraceSource.NewArgumentNullException((left == null) ? "left" : ((right == null) ? "right" : "errorPosition"));
     }
     this.Left = left;
     base.SetParent(left);
     this.Operator = @operator;
     this.Right = right;
     base.SetParent(right);
     this.ErrorPosition = errorPosition;
 }
Beispiel #55
0
 internal AstPair(CommandParameterAst parameterAst, ExpressionAst argumentAst)
 {
     if ((parameterAst != null) && (parameterAst.Argument != null))
     {
         throw PSTraceSource.NewArgumentException("parameterAst");
     }
     if ((parameterAst == null) && (argumentAst == null))
     {
         throw PSTraceSource.NewArgumentNullException("argumentAst");
     }
     base.Parameter = parameterAst;
     base.ParameterArgumentType = AstParameterArgumentType.AstPair;
     base.ParameterSpecified = parameterAst != null;
     base.ArgumentSpecified = argumentAst != null;
     base.ParameterName = (parameterAst != null) ? parameterAst.ParameterName : null;
     base.ParameterText = (parameterAst != null) ? parameterAst.ParameterName : null;
     base.ArgumentType = (argumentAst != null) ? argumentAst.StaticType : null;
     this._parameterContainsArgument = false;
     this._argument = argumentAst;
 }
Beispiel #56
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);
 }
Beispiel #57
0
 public ParameterAst(IScriptExtent extent, VariableExpressionAst name, IEnumerable<AttributeBaseAst> attributes, ExpressionAst defaultValue) : base(extent)
 {
     if (name == null)
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     if ((attributes != null) && attributes.Any<AttributeBaseAst>())
     {
         this.Attributes = new ReadOnlyCollection<AttributeBaseAst>(attributes.ToArray<AttributeBaseAst>());
         base.SetParents(attributes);
     }
     else
     {
         this.Attributes = EmptyAttributeList;
     }
     this.Name = name;
     base.SetParent(name);
     if (defaultValue != null)
     {
         this.DefaultValue = defaultValue;
         base.SetParent(defaultValue);
     }
 }
Beispiel #58
0
 private ObjectInfo GetObjectInfo(ExpressionAst expression)
 {
     return new ObjectInfo(EvaluateAst(expression));
 }
Beispiel #59
0
 private void VerifyExpressionIsIncrementableOrDecrementable(ExpressionAst exp, string op)
 {
     if (!SettableExpression.SupportedExpressions.Contains(exp.GetType()))
     {
         var msg = String.Format("The operator '{0}' can only be used for variables or properties", op);
         throw new ParseException(msg);
     }
 }
Beispiel #60
0
 public InvokeMemberExpressionAst(IScriptExtent extent, ExpressionAst expression, CommandElementAst method, IEnumerable<ExpressionAst> arguments, bool @static)
     : base(extent, expression, method, @static)
 {
     this.Arguments = arguments.ToReadOnlyCollection();
 }