private void CheckArrayLiteralAssignment(ArrayLiteralAst ast, Action<Ast> reportError) { RuntimeHelpers.EnsureSufficientExecutionStack(); foreach (ExpressionAst ast2 in ast.Elements) { this.CheckAssignmentTarget(ast2, true, reportError); } }
public System.Object VisitArrayLiteral(System.Management.Automation.Language.ArrayLiteralAst arrayLiteralAst) { IScriptExtent mappedExtent = MapExtent(arrayLiteralAst.Extent); List <ExpressionAst> mappedExpressions = new List <ExpressionAst>(); foreach (ExpressionAst expression in arrayLiteralAst.Elements) { mappedExpressions.Add(_VisitExpression(expression)); } return(new ArrayLiteralAst(mappedExtent, mappedExpressions)); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { // An array literal is a constant when we're generating metadata, but when // we're generating code, we need to create new arrays or we'd have an aliasing problem. return((CheckingAttributeArgument || CheckingRequiresArgument) && arrayLiteralAst.Elements.All(e => (bool)e.Accept(this))); }
/// <summary/> public virtual object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return _decorated.VisitArrayLiteral(arrayLiteralAst); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { foreach (ExpressionAst ast in arrayLiteralAst.Elements) { ast.Accept(this); } return null; }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return AstVisitAction.Continue; }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return Expression.NewArrayInit(typeof(object), arrayLiteralAst.Elements.Select(elem => Compile(elem).Cast(typeof(object)))); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return (from e in arrayLiteralAst.Elements select e.Accept(this)).ToArray<object>(); }
public virtual AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return AstVisitAction.Continue; }
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 VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return((!this.CheckingAttributeArgument && !this.CheckingRequiresArgument) ? ((object)0) : ((object)!(from e in arrayLiteralAst.Elements where !((bool)e.Accept(this)) select e).Any <ExpressionAst>())); }
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; }
/// <summary/> public virtual object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return null; }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst ast) { return CheckParent(ast); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return((from e in arrayLiteralAst.Elements select e.Accept(this)).ToArray <object>()); }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { _pipelineCommandRuntime.WriteObject(arrayLiteralAst.Elements.Select(EvaluateAst).ToArray(), true); return AstVisitAction.SkipChildren; }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return Expression.NewArrayInit(typeof(object), (IEnumerable<Expression>) (from elem in arrayLiteralAst.Elements select this.Compile(elem).Cast(typeof(object)))); }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst ast) { return(Check(ast)); }
/// <summary/> public virtual AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) => DefaultVisit(arrayLiteralAst);
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { // An array literal is safe ArrayList arrayElements = new ArrayList(); foreach (var element in arrayLiteralAst.Elements) { arrayElements.Add(element.Accept(this)); } return arrayElements.ToArray(); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { bool isSafe = arrayLiteralAst.Elements.All(e => (bool)e.Accept(this)); // An array literal is safe return isSafe; }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { foreach (var element in arrayLiteralAst.Elements) { element.Accept(this); } return null; }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { // Allowed if elements are allowed. return AstVisitAction.Continue; }
private void CreateBindingResultForSuccessfulBind(CommandAst commandAst, PseudoBindingInfo bindingInfo) { _bindingInfo = bindingInfo; // Check if there is exactly one parameter set valid. In that case, // ValidParameterSetFlags is exactly a power of two. Otherwise, // add to the binding exceptions. bool parameterSetSpecified = bindingInfo.ValidParameterSetsFlags != UInt32.MaxValue; bool remainingParameterSetIncludesDefault = (bindingInfo.DefaultParameterSetFlag != 0) && ((bindingInfo.ValidParameterSetsFlags & bindingInfo.DefaultParameterSetFlag) == bindingInfo.DefaultParameterSetFlag); // (x & (x -1 ) == 0) is a bit hack to determine if something is // exactly a power of two. bool onlyOneRemainingParameterSet = (bindingInfo.ValidParameterSetsFlags != 0) && (bindingInfo.ValidParameterSetsFlags & (bindingInfo.ValidParameterSetsFlags - 1)) == 0; if (parameterSetSpecified && (!remainingParameterSetIncludesDefault) && (!onlyOneRemainingParameterSet)) { ParameterBindingException bindingException = new ParameterBindingException( ErrorCategory.InvalidArgument, null, null, null, null, null, ParameterBinderStrings.AmbiguousParameterSet, "AmbiguousParameterSet"); BindingExceptions.Add(commandAst.CommandElements[0].Extent.Text, new StaticBindingError(commandAst.CommandElements[0], bindingException)); } // Add error for duplicate parameters if (bindingInfo.DuplicateParameters != null) { foreach (AstParameterArgumentPair duplicateParameter in bindingInfo.DuplicateParameters) { AddDuplicateParameterBindingException(duplicateParameter.Parameter); } } // Add error for parameters not found if (bindingInfo.ParametersNotFound != null) { foreach (CommandParameterAst parameterNotFound in bindingInfo.ParametersNotFound) { ParameterBindingException bindingException = new ParameterBindingException( ErrorCategory.InvalidArgument, null, parameterNotFound.ErrorPosition, parameterNotFound.ParameterName, null, null, ParameterBinderStrings.NamedParameterNotFound, "NamedParameterNotFound"); BindingExceptions.Add(parameterNotFound.ParameterName, new StaticBindingError(parameterNotFound, bindingException)); } } // Add error for ambiguous parameters if (bindingInfo.AmbiguousParameters != null) { foreach (CommandParameterAst ambiguousParameter in bindingInfo.AmbiguousParameters) { ParameterBindingException bindingException = bindingInfo.BindingExceptions[ambiguousParameter]; BindingExceptions.Add(ambiguousParameter.ParameterName, new StaticBindingError(ambiguousParameter, bindingException)); } } // Add error for unbound positional parameters if (bindingInfo.UnboundArguments != null) { foreach (AstParameterArgumentPair unboundArgument in bindingInfo.UnboundArguments) { AstPair argument = unboundArgument as AstPair; ParameterBindingException bindingException = new ParameterBindingException( ErrorCategory.InvalidArgument, null, argument.Argument.Extent, argument.Argument.Extent.Text, null, null, ParameterBinderStrings.PositionalParameterNotFound, "PositionalParameterNotFound"); BindingExceptions.Add(argument.Argument.Extent.Text, new StaticBindingError(argument.Argument, bindingException)); } } // Process the bound parameters if (bindingInfo.BoundParameters != null) { foreach (KeyValuePair<string, MergedCompiledCommandParameter> item in bindingInfo.BoundParameters) { CompiledCommandParameter parameter = item.Value.Parameter; CommandElementAst value = null; Object constantValue = null; // This is a single argument AstPair argumentAstPair = bindingInfo.BoundArguments[item.Key] as AstPair; if (argumentAstPair != null) { value = argumentAstPair.Argument; } // This is a parameter that took an argument, as well as ValueFromRemainingArguments. // Merge the arguments into a single fake argument. AstArrayPair argumentAstArrayPair = bindingInfo.BoundArguments[item.Key] as AstArrayPair; if (argumentAstArrayPair != null) { List<ExpressionAst> arguments = new List<ExpressionAst>(); foreach (ExpressionAst expression in argumentAstArrayPair.Argument) { ArrayLiteralAst expressionArray = expression as ArrayLiteralAst; if (expressionArray != null) { foreach (ExpressionAst newExpression in expressionArray.Elements) { arguments.Add((ExpressionAst)newExpression.Copy()); } } else { arguments.Add((ExpressionAst)expression.Copy()); } } // Define the virtual extent and virtual ArrayLiteral. IScriptExtent fakeExtent = arguments[0].Extent; ArrayLiteralAst fakeArguments = new ArrayLiteralAst(fakeExtent, arguments); value = fakeArguments; } // Special handling of switch parameters if (parameter.Type == typeof(SwitchParameter)) { if ((value != null) && (String.Equals("$false", value.Extent.Text, StringComparison.OrdinalIgnoreCase))) { continue; } constantValue = true; } // We got a parameter and a value if ((value != null) || (constantValue != null)) { BoundParameters.Add(item.Key, new ParameterBindingResult(parameter, value, constantValue)); } else { bool takesValueFromPipeline = false; foreach (ParameterSetSpecificMetadata parameterSet in parameter.GetMatchingParameterSetData(bindingInfo.ValidParameterSetsFlags)) { if (parameterSet.ValueFromPipeline) { takesValueFromPipeline = true; break; } } if (!takesValueFromPipeline) { // We have a parameter with no value that isn't a switch parameter, or input parameter ParameterBindingException bindingException = new ParameterBindingException( ErrorCategory.InvalidArgument, null, commandAst.CommandElements[0].Extent, parameter.Name, parameter.Type, null, ParameterBinderStrings.MissingArgument, "MissingArgument"); BindingExceptions.Add(commandAst.CommandElements[0].Extent.Text, new StaticBindingError(commandAst.CommandElements[0], bindingException)); } } } } }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return arrayLiteralAst.Elements.Select(e => e.Visit(this)).ToArray(); }
/// <summary> /// Visit array literal /// </summary> /// <param name="arrayLiteralAst"></param> /// <returns></returns> public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { if (arrayLiteralAst == null) return null; foreach (var element in arrayLiteralAst.Elements) { element.Visit(this.Decorator); } return null; }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return(AstVisitAction.Continue); }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { var arrayList = new List<object>(); foreach (var el in arrayLiteralAst.Elements) { arrayList.Add(EvaluateAst(el)); } _pipelineCommandRuntime.WriteObject(arrayList.ToArray(), false); return AstVisitAction.SkipChildren; }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst ast) { return this.Check(ast); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { CheckIsConstant(arrayLiteralAst, "Caller to verify ast is constant"); return(arrayLiteralAst.Elements.Select(e => e.Accept(this)).ToArray()); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return arrayLiteralAst.Elements.All<ExpressionAst>(e => ((bool) e.Accept(this))); }
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { throw new NotImplementedException(); //VisitArrayLiteral(arrayLiteralAst); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { // An array literal is a constant when we're generating metadata, but when // we're generating code, we need to create new arrays or we'd have an aliasing problem. return (CheckingAttributeArgument || CheckingRequiresArgument) && arrayLiteralAst.Elements.All(e => (bool)e.Accept(this)); }
public virtual AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return(AstVisitAction.Continue); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { CheckIsConstant(arrayLiteralAst, "Caller to verify ast is constant"); return arrayLiteralAst.Elements.Select(e => e.Accept(this)).ToArray(); }
/// <summary/> public virtual object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return(null); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { bool isSafe = arrayLiteralAst.Elements.All(e => (bool)e.Accept(this)); // An array literal is safe return isSafe; }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { return ((!this.CheckingAttributeArgument && !this.CheckingRequiresArgument) ? ((object) 0) : ((object) !(from e in arrayLiteralAst.Elements where !((bool) e.Accept(this)) select e).Any<ExpressionAst>())); }
public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) { var items = arrayLiteralAst.Elements.Select(Visit).OfType<CodeExpression>().ToArray(); return new CodeArrayCreateExpression("System.Object", items); }