Beispiel #1
0
    public System.Object VisitAttributedExpression(System.Management.Automation.Language.AttributedExpressionAst attributedExpressionAst)
    {
        IScriptExtent mappedExtent = MapExtent(attributedExpressionAst.Extent);

        AttributeBaseAst mappedAttribute = _VisitAttributeBase(attributedExpressionAst.Attribute);
        ExpressionAst    mappedChild     = _VisitExpression(attributedExpressionAst.Child);

        return(new AttributedExpressionAst(mappedExtent, mappedAttribute, mappedChild));
    }
Beispiel #2
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 #3
0
        private List <AttributeBaseAst> GetAttributes()
        {
            List <AttributeBaseAst> list = new List <AttributeBaseAst>();

            for (AttributedExpressionAst ast = this; ast != null; ast = ast.Child as AttributedExpressionAst)
            {
                list.Add(ast.Attribute);
            }
            list.Reverse();
            return(list);
        }
Beispiel #4
0
        public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
        {
            AttributeBaseAst attribute = attributedExpressionAst.Attribute;

            while (attributedExpressionAst != null)
            {
                if (attributedExpressionAst.Child is VariableExpressionAst)
                {
                    return(AstVisitAction.Continue);
                }
                attributedExpressionAst = attributedExpressionAst.Child as AttributedExpressionAst;
            }
            this._parser.ReportError(attribute.Extent, ParserStrings.UnexpectedAttribute, new object[] { attribute.TypeName.FullName });
            return(AstVisitAction.Continue);
        }
 /// <summary/>
 public virtual object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return _decorated.VisitAttributedExpression(attributedExpressionAst);
 }
Beispiel #6
0
        private ExpressionAst UnaryExpressionRule()
        {
            //G  unary-expression:
            //G      primary-expression
            //G      expression-with-unary-operator
            //G
            //G  expression-with-unary-operator:
            //G      ','   new-lines:opt   unary-expression
            //G      '-not'   new-lines:opt   unary-expression
            //G      '!'   new-lines:opt   unary-expression
            //G      '-bnot'   new-lines:opt   unary-expression
            //G      '+'   new-lines:opt   unary-expression
            //G      dash   new-lines:opt   unary-expression
            //G      pre-increment-expression
            //G      pre-decrement-expression
            //G      cast-expression
            //G      '-split'   new-lines:opt   unary-expression
            //G      '-join'   new-lines:opt   unary-expression
            //G
            //G  pre-increment-expression:
            //G      '++'   new-lines:opt   unary-expression
            //G
            //G  pre-decrement-expression:
            //G      dashdash   new-lines:opt   unary-expression
            //G
            //G  cast-expression:
            //G      type-literal   unary-expression
            RuntimeHelpers.EnsureSufficientExecutionStack();
            ExpressionAst expr = null;
            Token token;
            bool oldAllowSignedNumbers = _tokenizer.AllowSignedNumbers;
            try
            {
                _tokenizer.AllowSignedNumbers = true;
                if (_ungotToken != null && _ungotToken.Kind == TokenKind.Minus)
                {
                    Resync(_ungotToken);
                }

                token = PeekToken();
            }
            finally
            {
                _tokenizer.AllowSignedNumbers = oldAllowSignedNumbers;
            }

            ExpressionAst child;
            if (token.Kind.HasTrait(TokenFlags.UnaryOperator))
            {
                if (_disableCommaOperator && token.Kind == TokenKind.Comma)
                {
                    return null;
                }

                SkipToken();
                SkipNewlines();
                child = UnaryExpressionRule();
                if (child != null)
                {
                    if (token.Kind == TokenKind.Comma)
                    {
                        expr = new ArrayLiteralAst(ExtentOf(token, child), new ExpressionAst[] { child });
                    }
                    else
                    {
                        expr = new UnaryExpressionAst(ExtentOf(token, child), token.Kind, child);
                    }
                }
                else
                {
                    // ErrorRecovery: don't bother constructing a unary expression, but we know we must have
                    // some sort of expression, so return an error expression.

                    // Use token.Text, not token.Kind.Text() b/c the kind might not match the actual operator used
                    // when a case insensitive operator is used.
                    ReportIncompleteInput(After(token), () => ParserStrings.MissingExpressionAfterOperator, token.Text);
                    return new ErrorExpressionAst(token.Extent);
                }
            }
            else if (token.Kind == TokenKind.LBracket)
            {
                // Possibly a type literal or attribute.
                var attributes = AttributeListRule(true);
                if (attributes == null)
                {
                    return null;
                }

                AttributeBaseAst lastAttribute = attributes.Last();
                if (lastAttribute is AttributeAst)
                {
                    SkipNewlines();
                    child = UnaryExpressionRule();
                    if (child == null)
                    {
                        // ErrorRecovery: We have a list of attributes, and we know it's not before a param statement,
                        // so we know we must have some sort of expression.  Return an error expression then.

                        ReportIncompleteInput(lastAttribute.Extent,
                            () => ParserStrings.UnexpectedAttribute, lastAttribute.TypeName.FullName);
                        return new ErrorExpressionAst(ExtentOf(token, lastAttribute));
                    }
                    expr = new AttributedExpressionAst(ExtentOf(lastAttribute, child), lastAttribute, child);
                }
                else
                {
                    Diagnostics.Assert(_ungotToken == null || ErrorList.Count > 0,
                                        "Unexpected lookahead from AttributeListRule.");
                    // If we've looked ahead, don't go looking for a member access token, we've already issued an error,
                    // just assume we're not trying to access a member.
                    var memberAccessToken = _ungotToken != null ? null : NextMemberAccessToken(false);
                    if (memberAccessToken != null)
                    {
                        expr = CheckPostPrimaryExpressionOperators(memberAccessToken,
                                                                   new TypeExpressionAst(lastAttribute.Extent,
                                                                                         lastAttribute.TypeName));
                    }
                    else
                    {
                        token = PeekToken();
                        if (token.Kind != TokenKind.NewLine && token.Kind != TokenKind.Comma)
                        {
                            child = UnaryExpressionRule();
                            if (child != null)
                            {
                                expr = new ConvertExpressionAst(ExtentOf(lastAttribute, child),
                                                                (TypeConstraintAst)lastAttribute, child);
                            }
                        }
                    }

                    if (expr == null)
                    {
                        expr = new TypeExpressionAst(lastAttribute.Extent, lastAttribute.TypeName);
                    }
                }

                for (int i = attributes.Count - 2; i >= 0; --i)
                {
                    var typeConstraint = attributes[i] as TypeConstraintAst;

                    expr = typeConstraint != null
                                ? new ConvertExpressionAst(ExtentOf(typeConstraint, expr), typeConstraint, expr)
                                : new AttributedExpressionAst(ExtentOf(attributes[i], expr), attributes[i], expr);
                }
            }
            else
            {
                expr = PrimaryExpressionRule(withMemberAccess: true);
            }

            if (expr != null)
            {
                token = PeekToken();
                TokenKind operation = (token.Kind == TokenKind.PlusPlus)
                                            ? TokenKind.PostfixPlusPlus
                                            : (token.Kind == TokenKind.MinusMinus)
                                                ? TokenKind.PostfixMinusMinus
                                                : TokenKind.Unknown;
                if (operation != TokenKind.Unknown)
                {
                    SkipToken();
                    expr = new UnaryExpressionAst(ExtentOf(expr, token), operation, expr);
                }
            }

            return expr;
        }
Beispiel #7
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return(false);
 }
Beispiel #8
0
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst ast) { return CheckParent(ast); }
Beispiel #9
0
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst ast)
 {
     return(Check(ast));
 }
Beispiel #10
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Beispiel #11
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     attributedExpressionAst.Child.Accept(this);
     return(null);
 }
Beispiel #12
0
 private ExpressionAst UnaryExpressionRule()
 {
     Token token;
     ExpressionAst expressionAst;
     TokenKind tokenKind;
     Token token1;
     ExpressionAst convertExpressionAst;
     RuntimeHelpers.EnsureSufficientExecutionStack();
     ExpressionAst typeExpressionAst = null;
     bool allowSignedNumbers = this._tokenizer.AllowSignedNumbers;
     try
     {
         this._tokenizer.AllowSignedNumbers = true;
         if (this._ungotToken != null && this._ungotToken.Kind == TokenKind.Minus)
         {
             this.Resync(this._ungotToken);
         }
         token = this.PeekToken();
     }
     finally
     {
         this._tokenizer.AllowSignedNumbers = allowSignedNumbers;
     }
     if (!token.Kind.HasTrait(TokenFlags.UnaryOperator))
     {
         if (token.Kind != TokenKind.LBracket)
         {
             typeExpressionAst = this.PrimaryExpressionRule(true);
         }
         else
         {
             List<AttributeBaseAst> attributeBaseAsts = this.AttributeListRule(true);
             if (attributeBaseAsts != null)
             {
                 AttributeBaseAst attributeBaseAst = attributeBaseAsts.Last<AttributeBaseAst>();
                 if (attributeBaseAst as AttributeAst == null)
                 {
                     if (this._ungotToken != null)
                     {
                         token1 = null;
                     }
                     else
                     {
                         token1 = this.NextMemberAccessToken(false);
                     }
                     Token token2 = token1;
                     if (token2 == null)
                     {
                         token = this.PeekToken();
                         if (token.Kind != TokenKind.NewLine && token.Kind != TokenKind.Comma)
                         {
                             expressionAst = this.UnaryExpressionRule();
                             if (expressionAst != null)
                             {
                                 typeExpressionAst = new ConvertExpressionAst(Parser.ExtentOf(attributeBaseAst, expressionAst), (TypeConstraintAst)attributeBaseAst, expressionAst);
                             }
                         }
                     }
                     else
                     {
                         typeExpressionAst = this.CheckPostPrimaryExpressionOperators(token2, new TypeExpressionAst(attributeBaseAst.Extent, attributeBaseAst.TypeName));
                     }
                     if (typeExpressionAst == null)
                     {
                         typeExpressionAst = new TypeExpressionAst(attributeBaseAst.Extent, attributeBaseAst.TypeName);
                     }
                 }
                 else
                 {
                     this.SkipNewlines();
                     expressionAst = this.UnaryExpressionRule();
                     if (expressionAst != null)
                     {
                         typeExpressionAst = new AttributedExpressionAst(Parser.ExtentOf(attributeBaseAst, expressionAst), attributeBaseAst, expressionAst);
                     }
                     else
                     {
                         object[] fullName = new object[1];
                         fullName[0] = attributeBaseAst.TypeName.FullName;
                         this.ReportIncompleteInput(attributeBaseAst.Extent, ParserStrings.UnexpectedAttribute, fullName);
                         return new ErrorExpressionAst(Parser.ExtentOf(token, attributeBaseAst), null);
                     }
                 }
                 for (int i = attributeBaseAsts.Count - 2; i >= 0; i--)
                 {
                     TypeConstraintAst item = attributeBaseAsts[i] as TypeConstraintAst;
                     if (item != null)
                     {
                         convertExpressionAst = new ConvertExpressionAst(Parser.ExtentOf(item, typeExpressionAst), item, typeExpressionAst);
                     }
                     else
                     {
                         convertExpressionAst = new AttributedExpressionAst(Parser.ExtentOf(attributeBaseAsts[i], typeExpressionAst), attributeBaseAsts[i], typeExpressionAst);
                     }
                     typeExpressionAst = convertExpressionAst;
                 }
             }
             else
             {
                 return null;
             }
         }
     }
     else
     {
         if (!this._disableCommaOperator || token.Kind != TokenKind.Comma)
         {
             this.SkipToken();
             this.SkipNewlines();
             expressionAst = this.UnaryExpressionRule();
             if (expressionAst == null)
             {
                 object[] text = new object[1];
                 text[0] = token.Text;
                 this.ReportIncompleteInput(Parser.After(token), ParserStrings.MissingExpressionAfterOperator, text);
                 return new ErrorExpressionAst(token.Extent, null);
             }
             else
             {
                 if (token.Kind != TokenKind.Comma)
                 {
                     typeExpressionAst = new UnaryExpressionAst(Parser.ExtentOf(token, expressionAst), token.Kind, expressionAst);
                 }
                 else
                 {
                     ExpressionAst[] expressionAstArray = new ExpressionAst[1];
                     expressionAstArray[0] = expressionAst;
                     typeExpressionAst = new ArrayLiteralAst(Parser.ExtentOf(token, expressionAst), expressionAstArray);
                 }
             }
         }
         else
         {
             return null;
         }
     }
     if (typeExpressionAst != null)
     {
         token = this.PeekToken();
         if (token.Kind == TokenKind.PlusPlus)
         {
             tokenKind = TokenKind.PostfixPlusPlus;
         }
         else
         {
             if (token.Kind == TokenKind.MinusMinus)
             {
                 tokenKind = TokenKind.PostfixMinusMinus;
             }
             else
             {
                 tokenKind = TokenKind.Unknown;
             }
         }
         TokenKind tokenKind1 = tokenKind;
         if (tokenKind1 != TokenKind.Unknown)
         {
             this.SkipToken();
             typeExpressionAst = new UnaryExpressionAst(Parser.ExtentOf(typeExpressionAst, token), tokenKind1, typeExpressionAst);
         }
     }
     return typeExpressionAst;
 }
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst) { throw new UnexpectedElementException(); }
Beispiel #14
0
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     throw new NotImplementedException(); //VisitAttributedExpression(attributedExpressionAst);
 }
Beispiel #15
0
        public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
        {
            // Attributes are not allowed, they may code in attribute constructors.
            ReportError(attributedExpressionAst, () => ParserStrings.AttributeNotSupportedInDataSection);

            return AstVisitAction.Continue;
        }
Beispiel #16
0
        public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
        {
            // The attribute (and not the entire expression) is used for the error extent.
            var errorAst = attributedExpressionAst.Attribute;
            while (attributedExpressionAst != null)
            {
                if (attributedExpressionAst.Child is VariableExpressionAst)
                {
                    return AstVisitAction.Continue;
                }

                attributedExpressionAst = attributedExpressionAst.Child as AttributedExpressionAst;
            }

            _parser.ReportError(errorAst.Extent, () => ParserStrings.UnexpectedAttribute, errorAst.TypeName.FullName);

            return AstVisitAction.Continue;
        }
Beispiel #17
0
 /// <summary/>
 public virtual AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst) => DefaultVisit(attributedExpressionAst);
Beispiel #18
0
 /// <summary/>
 public virtual object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst) { return null; }
Beispiel #19
0
        public override AstVisitAction VisitConvertExpression(ConvertExpressionAst convertExpressionAst)
        {
            Func <Ast, bool> predicate = null;

            if (convertExpressionAst.Type.TypeName.FullName.Equals("ordered", StringComparison.OrdinalIgnoreCase) && !(convertExpressionAst.Child is HashtableAst))
            {
                this._parser.ReportError(convertExpressionAst.Extent, ParserStrings.OrderedAttributeOnlyOnHashLiteralNode, new object[] { convertExpressionAst.Type.TypeName.FullName });
            }
            if (typeof(PSReference).Equals(convertExpressionAst.Type.TypeName.GetReflectionType()))
            {
                ExpressionAst child = convertExpressionAst.Child;
                bool          flag  = false;
                while (true)
                {
                    AttributedExpressionAst ast2 = child as AttributedExpressionAst;
                    if (ast2 == null)
                    {
                        break;
                    }
                    ConvertExpressionAst ast3 = ast2 as ConvertExpressionAst;
                    if ((ast3 != null) && typeof(PSReference).Equals(ast3.Type.TypeName.GetReflectionType()))
                    {
                        flag = true;
                        this._parser.ReportError(ast3.Type.Extent, ParserStrings.ReferenceNeedsToBeByItselfInTypeSequence, new object[0]);
                    }
                    child = ast2.Child;
                }
                for (AttributedExpressionAst ast4 = convertExpressionAst.Parent as AttributedExpressionAst; ast4 != null; ast4 = ast4.Child as AttributedExpressionAst)
                {
                    ConvertExpressionAst ast5 = ast4 as ConvertExpressionAst;
                    if ((ast5 != null) && !flag)
                    {
                        if (typeof(PSReference).Equals(ast5.Type.TypeName.GetReflectionType()))
                        {
                            break;
                        }
                        Ast  parent = ast4.Parent;
                        bool flag2  = false;
                        while (parent != null)
                        {
                            if (parent is AssignmentStatementAst)
                            {
                                if (predicate == null)
                                {
                                    predicate = ast1 => ast1 == convertExpressionAst;
                                }
                                flag2 = ((AssignmentStatementAst)parent).Left.Find(predicate, true) != null;
                                break;
                            }
                            if (parent is CommandExpressionAst)
                            {
                                break;
                            }
                            parent = parent.Parent;
                        }
                        if (!flag2)
                        {
                            this._parser.ReportError(convertExpressionAst.Type.Extent, ParserStrings.ReferenceNeedsToBeLastTypeInTypeConversion, new object[0]);
                        }
                    }
                }
            }
            return(AstVisitAction.Continue);
        }
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     this.ReportError(attributedExpressionAst, () => ParserStrings.AttributeNotSupportedInDataSection, new object[0]);
     return(AstVisitAction.Continue);
 }
Beispiel #21
0
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     AttributeBaseAst attribute = attributedExpressionAst.Attribute;
     while (attributedExpressionAst != null)
     {
         if (attributedExpressionAst.Child is VariableExpressionAst)
         {
             return AstVisitAction.Continue;
         }
         attributedExpressionAst = attributedExpressionAst.Child as AttributedExpressionAst;
     }
     this._parser.ReportError(attribute.Extent, ParserStrings.UnexpectedAttribute, new object[] { attribute.TypeName.FullName });
     return AstVisitAction.Continue;
 }
Beispiel #22
0
 public virtual AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return AstVisitAction.Continue;
 }
Beispiel #23
0
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst ast)
 {
     return this.Check(ast);
 }
Beispiel #24
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst) { return AutomationNull.Value; }
Beispiel #25
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst) { throw PSTraceSource.NewArgumentException("ast"); }
Beispiel #26
0
 /// <summary/>
 public virtual object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return(null);
 }
 public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     this.ReportError(attributedExpressionAst, () => ParserStrings.AttributeNotSupportedInDataSection, new object[0]);
     return AstVisitAction.Continue;
 }
Beispiel #28
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return false;
 }
Beispiel #29
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     attributedExpressionAst.Child.Accept(this);
     return null;
 }
Beispiel #30
0
 /// <summary/>
 public virtual AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return(AstVisitAction.Continue);
 }
        /// <summary>
        /// Visit Attributed Expression
        /// </summary>
        /// <param name="attributedExpressionAst"></param>
        /// <returns></returns>
        public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
        {
            if (attributedExpressionAst == null) return null;

            attributedExpressionAst.Child.Visit(this.Decorator);
            return null;
        }
Beispiel #32
0
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     return(AutomationNull.Value);
 }
 public object VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst)
 {
     throw new NotImplementedException();
 }