public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { if (dataStatementAst.Variable != null) { this.NoteVariable(dataStatementAst.Variable, -1, null, false, false); } return(AstVisitAction.Continue); }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { IEnumerable <string> allowedCommands = dataStatementAst.HasNonConstantAllowedCommand ? null : GetConstantDataStatementAllowedCommands(dataStatementAst); RestrictedLanguageChecker visitor = new RestrictedLanguageChecker(this._parser, allowedCommands, null, false); dataStatementAst.Body.InternalVisit(visitor); return(AstVisitAction.Continue); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { dataStatementAst.Body.Accept(this); if (dataStatementAst.Variable != null) { this._currentBlock.AddAst(dataStatementAst); } return(null); }
private static IEnumerable <string> GetConstantDataStatementAllowedCommands(DataStatementAst dataStatementAst) { yield return("ConvertFrom-StringData"); foreach (ExpressionAst iteratorVariable0 in dataStatementAst.CommandsAllowed) { yield return(((StringConstantExpressionAst)iteratorVariable0).Value); } }
internal static void CheckDataStatementAstAtRuntime(DataStatementAst dataStatementAst, string[] allowedCommands) { Parser parser = new Parser(); RestrictedLanguageChecker visitor = new RestrictedLanguageChecker(parser, allowedCommands, null, false); dataStatementAst.Body.InternalVisit(visitor); if (parser.ErrorList.Any<ParseError>()) { throw new ParseException(parser.ErrorList.ToArray()); } }
internal static void CheckDataStatementAstAtRuntime(DataStatementAst dataStatementAst, string[] allowedCommands) { Parser parser = new Parser(); RestrictedLanguageChecker visitor = new RestrictedLanguageChecker(parser, allowedCommands, null, false); dataStatementAst.Body.InternalVisit(visitor); if (parser.ErrorList.Any <ParseError>()) { throw new ParseException(parser.ErrorList.ToArray()); } }
private void AnalyzeBlock(BitArray assignedBitArray, Block block) { foreach (Ast ast in block._asts) { VariableExpressionAst ast2 = ast as VariableExpressionAst; if (ast2 != null) { VariablePath variablePath = ast2.VariablePath; if (variablePath.IsAnyLocal()) { string unaliasedVariableName = GetUnaliasedVariableName(variablePath); VariableAnalysisDetails details = this._variables[unaliasedVariableName]; if (details.Automatic) { ast2.TupleIndex = details.LocalTupleIndex; ast2.Automatic = true; } else { ast2.TupleIndex = (assignedBitArray[details.BitIndex] && !details.PreferenceVariable) ? details.LocalTupleIndex : -2; } } } else { AssignmentTarget target = ast as AssignmentTarget; if (target != null) { if (target._targetAst != null) { this.CheckLHSAssign(target._targetAst, assignedBitArray); } else { this.CheckLHSAssignVar(target._variableName, assignedBitArray, target._type); } } else { DataStatementAst item = ast as DataStatementAst; if (item != null) { VariableAnalysisDetails details2 = this.CheckLHSAssignVar(item.Variable, assignedBitArray, typeof(object)); item.TupleIndex = details2.LocalTupleIndex; details2.AssociatedAsts.Add(item); } } } } }
public System.Object VisitDataStatement(System.Management.Automation.Language.DataStatementAst dataStatementAst) { IScriptExtent mappedExtent = MapExtent(dataStatementAst.Extent); LinkedList <ExpressionAst> mappedCommandsAllowed = new LinkedList <ExpressionAst>(); foreach (ExpressionAst e in dataStatementAst.CommandsAllowed) { mappedCommandsAllowed.AddLast(_VisitExpression(e)); } StatementBlockAst mappedBody = (StatementBlockAst)VisitStatementBlock(dataStatementAst.Body); return(new DataStatementAst(mappedExtent, dataStatementAst.Variable, mappedCommandsAllowed, mappedBody)); }
private static void FixTupleIndex(Ast ast, int newIndex) { VariableExpressionAst ast2 = ast as VariableExpressionAst; if (ast2 != null) { if (ast2.TupleIndex != -2) { ast2.TupleIndex = newIndex; } } else { DataStatementAst ast3 = ast as DataStatementAst; if ((ast3 != null) && (ast3.TupleIndex != -2)) { ast3.TupleIndex = newIndex; } } }
public object VisitDataStatement(DataStatementAst dataStatementAst) { return(false); }
/// <summary/> public virtual AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) => DefaultVisit(dataStatementAst);
/// <summary/> public virtual object VisitDataStatement(DataStatementAst dataStatementAst) { return null; }
public virtual AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { return AstVisitAction.Continue; }
/// <summary> /// Visit data statement /// </summary> /// <param name="dataStatementAst"></param> /// <returns></returns> public object VisitDataStatement(DataStatementAst dataStatementAst) { if (dataStatementAst == null) return null; dataStatementAst.Body.Visit(this.Decorator); if (dataStatementAst.Variable != null) { _currentBlock.AddAst(new AssignmentTarget(dataStatementAst.Variable, null)); } return null; }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { this.ReportError(dataStatementAst, () => ParserStrings.DataSectionStatementNotSupportedInDataSection, new object[0]); return(AstVisitAction.Continue); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { throw new UnexpectedElementException(); }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { IEnumerable<string> allowedCommands = dataStatementAst.HasNonConstantAllowedCommand ? null : GetConstantDataStatementAllowedCommands(dataStatementAst); RestrictedLanguageChecker checker = new RestrictedLanguageChecker(_parser, allowedCommands, null, false); dataStatementAst.Body.InternalVisit(checker); return AstVisitAction.Continue; }
private static IEnumerable<string> GetConstantDataStatementAllowedCommands(DataStatementAst dataStatementAst) { yield return "ConvertFrom-StringData"; foreach (var allowed in dataStatementAst.CommandsAllowed) { yield return ((StringConstantExpressionAst)allowed).Value; } }
internal static void CheckDataStatementLanguageModeAtRuntime(DataStatementAst dataStatementAst, ExecutionContext executionContext) { // If we get here, we have already determined the data statement invokes commands, so // we only need to check the language mode. if (executionContext.LanguageMode == PSLanguageMode.ConstrainedLanguage) { var parser = new Parser(); parser.ReportError(dataStatementAst.CommandsAllowed[0].Extent, () => ParserStrings.DataSectionAllowedCommandDisallowed); throw new ParseException(parser.ErrorList.ToArray()); } }
public override AstVisitAction VisitDataStatement(DataStatementAst ast) { return CheckParent(ast); }
/// <summary> /// Visit datastatement /// </summary> /// <param name="dataStatementAst"></param> /// <returns></returns> public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { if (dataStatementAst != null && dataStatementAst.Variable != null) { NoteVariable(dataStatementAst.Variable, null); } return AstVisitAction.Continue; }
public override AstVisitAction VisitDataStatement(DataStatementAst ast) { return this.Check(ast); }
/// <summary/> public virtual object VisitDataStatement(DataStatementAst dataStatementAst) { return _decorated.VisitDataStatement(dataStatementAst); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { return AutomationNull.Value; }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { throw new NotImplementedException(); //VisitDataStatement(dataStatementAst); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { throw PSTraceSource.NewArgumentException("ast"); }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { if (dataStatementAst.Variable != null) { this.NoteVariable(dataStatementAst.Variable, -1, null, false, false); } return AstVisitAction.Continue; }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { return AstVisitAction.SkipChildren; }
public override AstVisitAction VisitDataStatement(DataStatementAst ast) { return(Check(ast)); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { throw PSTraceSource.NewArgumentException("ast"); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { // We'll generate the following: // // try // { // oldLanguageMode = context.LanguageMode; // CheckLanguageMode (if necessary, only if SupportedCommands specified) // CheckAllowedCommands (if necessary, it may have been done at parse time if possible) // context.LanguageMode = PSLanguageMode.RestrictedLanguage; // either: // dataStatementAst.Variable = execute body // or if the variable name was not specified: // execute body, writing results to the current output pipe // } // finally // { // context.LanguageMode = oldLanguageMode; // } var oldLanguageMode = NewTemp(typeof(PSLanguageMode), "oldLanguageMode"); var languageModePropertyExpr = Expression.Property(_executionContextParameter, CachedReflectionInfo.ExecutionContext_LanguageMode); var exprs = new List<Expression> { // Save old language mode before doing anything else so if there is an exception, we don't // "restore" the language mode to an uninitialized value (which happens to be "full" mode. Expression.Assign(oldLanguageMode, languageModePropertyExpr), UpdatePosition(dataStatementAst), // Auto-import utility module if needed, so that ConvertFrom-StringData isn't set to RestrictedLanguage // by the data section. Expression.Call(CachedReflectionInfo.RestrictedLanguageChecker_EnsureUtilityModuleLoaded, _executionContextParameter) }; if (dataStatementAst.CommandsAllowed.Count > 0) { // If CommandsAllowed was specified, we need to check the language mode - the data section runs // in restricted language mode and we don't want to allow disallowed commands to run if we were in // constrained language mode. exprs.Add( Expression.Call( CachedReflectionInfo.RestrictedLanguageChecker_CheckDataStatementLanguageModeAtRuntime, Expression.Constant(dataStatementAst), _executionContextParameter)); } if (dataStatementAst.HasNonConstantAllowedCommand) { // We couldn't check the commands allowed at parse time, so we must do so at runtime exprs.Add( Expression.Call(CachedReflectionInfo.RestrictedLanguageChecker_CheckDataStatementAstAtRuntime, Expression.Constant(dataStatementAst), Expression.NewArrayInit(typeof(string), dataStatementAst.CommandsAllowed.Select( elem => Compile(elem).Convert(typeof(string)))))); } exprs.Add(Expression.Assign(languageModePropertyExpr, Expression.Constant(PSLanguageMode.RestrictedLanguage))); // If we'll be assigning directly, we need to capture the value, otherwise just write to the current output pipe. // We should not preserve the partial output if exception is thrown when evaluating the body expr. var dataExpr = dataStatementAst.Variable != null ? CaptureAstResults(dataStatementAst.Body, CaptureAstContext.AssignmentWithoutResultPreservation).Cast(typeof(object)) : Compile(dataStatementAst.Body); exprs.Add(dataExpr); var block = Expression.Block( new[] { oldLanguageMode }, Expression.TryFinally( Expression.Block(exprs), Expression.Assign(languageModePropertyExpr, oldLanguageMode))); if (dataStatementAst.Variable != null) { return dataStatementAst.TupleIndex < 0 ? CallSetVariable(Expression.Constant(new VariablePath("local:" + dataStatementAst.Variable)), block) : Expression.Assign(GetLocal(dataStatementAst.TupleIndex), block); } return block; }
public object VisitDataStatement(DataStatementAst dataStatementAst) { Func<ExpressionAst, Expression> selector = null; List<Expression> expressions = new List<Expression> { this.UpdatePosition(dataStatementAst) }; if (dataStatementAst.HasNonConstantAllowedCommand) { if (selector == null) { selector = elem => this.Compile(elem).Convert(typeof(string)); } expressions.Add(Expression.Call(CachedReflectionInfo.RestrictedLanguageChecker_CheckDataStatementAstAtRuntime, Expression.Constant(dataStatementAst), Expression.NewArrayInit(typeof(string), dataStatementAst.CommandsAllowed.Select<ExpressionAst, Expression>(selector)))); } ParameterExpression left = this.NewTemp(typeof(PSLanguageMode), "oldLanguageMode"); MemberExpression right = Expression.Property(_executionContextParameter, CachedReflectionInfo.ExecutionContext_LanguageMode); expressions.Add(Expression.Assign(left, right)); expressions.Add(Expression.Assign(right, Expression.Constant(PSLanguageMode.RestrictedLanguage))); Expression item = (dataStatementAst.Variable != null) ? this.CaptureAstResults(dataStatementAst.Body, CaptureAstContext.Assignment, null).Cast(typeof(object)) : this.Compile(dataStatementAst.Body); expressions.Add(item); BlockExpression expression4 = Expression.Block(new ParameterExpression[] { left }, new Expression[] { Expression.TryFinally(Expression.Block(expressions), Expression.Assign(right, left)) }); if (dataStatementAst.Variable == null) { return expression4; } if (dataStatementAst.TupleIndex >= 0) { return Expression.Assign(this.GetLocal(dataStatementAst.TupleIndex), expression4); } return CallSetVariable(Expression.Constant(new VariablePath("local:" + dataStatementAst.Variable)), expression4, null); }
/// <summary/> public virtual object VisitDataStatement(DataStatementAst dataStatementAst) { return(null); }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { if (dataStatementAst.Variable != null) { NoteVariable(dataStatementAst.Variable, VariableAnalysis.Unanalyzed, null); } return AstVisitAction.Continue; }
public object VisitDataStatement(DataStatementAst dataStatementAst) { return false; }
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { this.ReportError(dataStatementAst, () => ParserStrings.DataSectionStatementNotSupportedInDataSection, new object[0]); return AstVisitAction.Continue; }
/// <summary/> public virtual AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) { return(AstVisitAction.Continue); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { dataStatementAst.Body.Accept(this); if (dataStatementAst.Variable != null) { this._currentBlock.AddAst(dataStatementAst); } return null; }
public object VisitDataStatement(DataStatementAst dataStatementAst) { return(AutomationNull.Value); }
public object VisitDataStatement(DataStatementAst dataStatementAst) { throw new NotImplementedException(); }