public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { if (unaryExpressionAst.TokenKind.HasTrait(TokenFlags.DisallowedInRestrictedMode)) { this.ReportError(unaryExpressionAst, () => ParserStrings.OperatorNotSupportedInDataSection, new object[] { unaryExpressionAst.TokenKind.Text() }); } return(AstVisitAction.Continue); }
public System.Object VisitUnaryExpression(System.Management.Automation.Language.UnaryExpressionAst unaryExpressionAst) { IScriptExtent mappedExtent = MapExtent(unaryExpressionAst.Extent); ExpressionAst mappedChild = _VisitExpression(unaryExpressionAst.Child); return(new UnaryExpressionAst(mappedExtent, unaryExpressionAst.TokenKind, mappedChild)); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { if (t_context == null) { throw PSTraceSource.NewArgumentException(nameof(unaryExpressionAst)); } return(Compiler.GetExpressionValue(unaryExpressionAst, isTrustedInput: true, t_context, usingValues: null)); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { bool unaryExpressionIsSafe = unaryExpressionAst.TokenKind.HasTrait(TokenFlags.CanConstantFold) && !unaryExpressionAst.TokenKind.HasTrait(TokenFlags.DisallowedInRestrictedMode) && (bool)unaryExpressionAst.Child.Accept(this); if (unaryExpressionIsSafe) { _visitCount++; } return unaryExpressionIsSafe; }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { if (s_context != null) { return(Compiler.GetExpressionValue(unaryExpressionAst, true, s_context, null)); } else { throw PSTraceSource.NewArgumentException("ast"); } }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { Action <Ast> reportError = null; switch (unaryExpressionAst.TokenKind) { case TokenKind.MinusMinus: case TokenKind.PlusPlus: case TokenKind.PostfixPlusPlus: case TokenKind.PostfixMinusMinus: if (reportError == null) { reportError = delegate(Ast ast) { this._parser.ReportError(ast.Extent, ParserStrings.OperatorRequiresVariableOrProperty, new object[] { unaryExpressionAst.TokenKind.Text() }); }; } this.CheckAssignmentTarget(unaryExpressionAst.Child, false, reportError); break; } return(AstVisitAction.Continue); }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst ast) { return(Check(ast)); }
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; }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return(CompileAndInvoke(unaryExpressionAst)); }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { switch (unaryExpressionAst.TokenKind) { case TokenKind.PostfixPlusPlus: case TokenKind.PlusPlus: case TokenKind.MinusMinus: case TokenKind.PostfixMinusMinus: VisitIncrementDecrementExpression(unaryExpressionAst); break; case TokenKind.Not: var value = EvaluateAst(unaryExpressionAst.Child, _writeSideEffectsToPipeline); var boolValue = (bool) LanguagePrimitives.ConvertTo(value, typeof(bool)); _pipelineCommandRuntime.WriteObject(!boolValue); break; default: throw new NotImplementedException(unaryExpressionAst.ToString()); } return AstVisitAction.SkipChildren; }
/// <summary> /// Visit unary expression /// </summary> /// <param name="unaryExpressionAst"></param> /// <returns></returns> public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { if (unaryExpressionAst == null) return null; unaryExpressionAst.Child.Visit(this.Decorator); return null; }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return CompileAndInvoke(unaryExpressionAst); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { throw new UnexpectedElementException(); }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { switch (unaryExpressionAst.TokenKind) { case TokenKind.PlusPlus: case TokenKind.PostfixPlusPlus: case TokenKind.MinusMinus: case TokenKind.PostfixMinusMinus: CheckAssignmentTarget(unaryExpressionAst.Child, false, ast => _parser.ReportError(ast.Extent, () => ParserStrings.OperatorRequiresVariableOrProperty, unaryExpressionAst.TokenKind.Text())); break; } return AstVisitAction.Continue; }
/// <summary/> public virtual AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) => DefaultVisit(unaryExpressionAst);
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 override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { Action<Ast> reportError = null; switch (unaryExpressionAst.TokenKind) { case TokenKind.MinusMinus: case TokenKind.PlusPlus: case TokenKind.PostfixPlusPlus: case TokenKind.PostfixMinusMinus: if (reportError == null) { reportError = delegate (Ast ast) { this._parser.ReportError(ast.Extent, ParserStrings.OperatorRequiresVariableOrProperty, new object[] { unaryExpressionAst.TokenKind.Text() }); }; } this.CheckAssignmentTarget(unaryExpressionAst.Child, false, reportError); break; } return AstVisitAction.Continue; }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst ast) { return CheckParent(ast); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return(unaryExpressionAst.TokenKind.HasTrait(TokenFlags.CanConstantFold) && (bool)unaryExpressionAst.Child.Accept(this)); }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst ast) { return this.Check(ast); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { unaryExpressionAst.Child.Accept(this); return null; }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return (bool) unaryExpressionAst.Child.Accept(this); }
/// <summary/> public virtual object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return _decorated.VisitUnaryExpression(unaryExpressionAst); }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { var childVariableExpressionAst = unaryExpressionAst.Child as VariableExpressionAst; var childVariable = childVariableExpressionAst == null ? null : GetVariable(childVariableExpressionAst); var childVariableValue = childVariable == null ? null : childVariable.Value; switch (unaryExpressionAst.TokenKind) { case TokenKind.PostfixPlusPlus: if (childVariable == null) throw new NotImplementedException(unaryExpressionAst.ToString()); if (childVariableValue is PSObject) { if (this._writeSideEffectsToPipeline) this._pipelineCommandRuntime.WriteObject(childVariable.Value); childVariable.Value = PSObject.AsPSObject(((int)((PSObject)childVariableValue).BaseObject) + 1); } else throw new NotImplementedException(childVariableValue.ToString()); break; case TokenKind.PlusPlus: if (childVariable == null) throw new NotImplementedException(unaryExpressionAst.ToString()); if (childVariableValue is PSObject) { childVariable.Value = PSObject.AsPSObject(((int)((PSObject)childVariableValue).BaseObject) + 1); if (this._writeSideEffectsToPipeline) this._pipelineCommandRuntime.WriteObject(childVariable.Value); } else throw new NotImplementedException(childVariableValue.ToString()); break; default: throw new NotImplementedException(unaryExpressionAst.ToString()); } return AstVisitAction.SkipChildren; }
private void VisitIncrementDecrementExpression(UnaryExpressionAst unaryExpressionAst) { var token = unaryExpressionAst.TokenKind; // first validate the expression. Shouldn't fail, but let's be sure var validTokens = new [] { TokenKind.PostfixPlusPlus, TokenKind.PostfixMinusMinus, TokenKind.PlusPlus, TokenKind.MinusMinus}; if (!validTokens.Contains(token)) { throw new PSInvalidOperationException("The unary expression is not a decrement/increment expression. " + "Please report this issue."); } bool postfix = token == TokenKind.PostfixPlusPlus || token == TokenKind.PostfixMinusMinus; bool increment = token == TokenKind.PostfixPlusPlus || token == TokenKind.PlusPlus; // It's the duty of the AstBuilderto check wether the child expression is a settable expression SettableExpression affectedExpression = SettableExpression.Create(unaryExpressionAst.Child, this); object objValue = PSObject.Unwrap(affectedExpression.GetValue()); objValue = objValue ?? 0; // if the value is null, then we "convert" to integer 0, says the specification // check for non-numerics var valueType = objValue.GetType(); if (!valueType.IsNumeric()) { var msg = String.Format("The operator '{0}' can only be used for numbers. The operand is '{1}'", increment ? "++" : "--", valueType.FullName); throw new RuntimeException(msg, "OperatorRequiresNumber", ErrorCategory.InvalidOperation, objValue); } // if it's a postfix operation, then we need to write the numeric value to pipeline if (postfix && _writeSideEffectsToPipeline) { _pipelineCommandRuntime.WriteObject(objValue); } // now actually change the value, check for overflow dynamic dynValue = (dynamic)objValue; try { dynValue = checked(dynValue + (increment ? 1 : -1)); } catch (OverflowException) // cast to double on overflow { dynValue = LanguagePrimitives.ConvertTo<double>(objValue) + (increment ? 1 : -1); } // set the new value affectedExpression.SetValue((object)dynValue); // if it was a prefix, then we need to write the new value to pipeline if (!postfix && _writeSideEffectsToPipeline) { _pipelineCommandRuntime.WriteObject(dynValue); } }
public virtual AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return AstVisitAction.Continue; }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { throw new NotImplementedException(); //VisitUnaryExpression(unaryExpressionAst); }
/// <summary/> public virtual object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return null; }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return unaryExpressionAst.TokenKind.HasTrait(TokenFlags.CanConstantFold) && (bool)unaryExpressionAst.Child.Accept(this); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { CheckIsConstant(unaryExpressionAst, "Caller to verify ast is constant"); return CompileAndInvoke(unaryExpressionAst); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { unaryExpressionAst.Child.Accept(this); return(null); }
/// <summary/> public virtual object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return(null); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { if (s_context != null) { return Compiler.GetExpressionValue(unaryExpressionAst, true, s_context, null); } else { throw PSTraceSource.NewArgumentException("ast"); } }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return (!unaryExpressionAst.TokenKind.HasTrait(TokenFlags.CanConstantFold) ? ((object) false) : ((object) ((bool) unaryExpressionAst.Child.Accept(this)))); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { object constantValue; if (!CompilingConstantExpression && IsConstantValueVisitor.IsConstant(unaryExpressionAst, out constantValue)) { return Expression.Constant(constantValue); } ExpressionAst child = unaryExpressionAst.Child; switch (unaryExpressionAst.TokenKind) { case TokenKind.Exclaim: case TokenKind.Not: return DynamicExpression.Dynamic(PSUnaryOperationBinder.Get(ExpressionType.Not), typeof(object), CompileExpressionOperand(child)); case TokenKind.Minus: return DynamicExpression.Dynamic(PSBinaryOperationBinder.Get(ExpressionType.Subtract), typeof(object), ExpressionCache.Constant(0), CompileExpressionOperand(child)); case TokenKind.Plus: return DynamicExpression.Dynamic(PSBinaryOperationBinder.Get(ExpressionType.Add), typeof(object), ExpressionCache.Constant(0), CompileExpressionOperand(child)); case TokenKind.Bnot: return DynamicExpression.Dynamic(PSUnaryOperationBinder.Get(ExpressionType.OnesComplement), typeof(object), CompileExpressionOperand(child)); case TokenKind.PlusPlus: return CompileIncrementOrDecrement(child, 1, true); case TokenKind.MinusMinus: return CompileIncrementOrDecrement(child, -1, true); case TokenKind.PostfixPlusPlus: return CompileIncrementOrDecrement(child, 1, false); case TokenKind.PostfixMinusMinus: return CompileIncrementOrDecrement(child, -1, false); case TokenKind.Join: // TODO: replace this with faster code return Expression.Call(CachedReflectionInfo.ParserOps_UnaryJoinOperator, _executionContextParameter, Expression.Constant(unaryExpressionAst.Extent), (CompileExpressionOperand(child)).Cast(typeof(object))); case TokenKind.Isplit: case TokenKind.Csplit: // TODO: replace this with faster code return Expression.Call(CachedReflectionInfo.ParserOps_UnarySplitOperator, _executionContextParameter, Expression.Constant(unaryExpressionAst.Extent), (CompileExpressionOperand(child)).Cast(typeof(object))); } throw new InvalidOperationException("Unknown token in unary operator."); }
/// <summary/> public virtual AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { return(AstVisitAction.Continue); }
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { if (unaryExpressionAst.TokenKind.HasTrait(TokenFlags.DisallowedInRestrictedMode)) { this.ReportError(unaryExpressionAst, () => ParserStrings.OperatorNotSupportedInDataSection, new object[] { unaryExpressionAst.TokenKind.Text() }); } return AstVisitAction.Continue; }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { CheckIsConstant(unaryExpressionAst, "Caller to verify ast is constant"); return(CompileAndInvoke(unaryExpressionAst)); }
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) { throw new NotImplementedException(); }