public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, StatementBlockAst statements, bool isFilter) : base(extent) { this.ParamBlock = paramBlock; this.EndBlock = new NamedBlockAst(extent, TokenKind.End, statements, true); if (isFilter) throw new NotImplementedException(this.ToString()); }
public TryStatementAst(IScriptExtent extent, StatementBlockAst body, IEnumerable <CatchClauseAst> catchClauses, StatementBlockAst @finally) : base(extent) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if (((catchClauses == null) || !catchClauses.Any <CatchClauseAst>()) && (@finally == null)) { throw PSTraceSource.NewArgumentException("catchClauses"); } this.Body = body; base.SetParent(body); if ((catchClauses != null) && catchClauses.Any <CatchClauseAst>()) { this.CatchClauses = new ReadOnlyCollection <CatchClauseAst>(catchClauses.ToArray <CatchClauseAst>()); base.SetParents((IEnumerable <Ast>) this.CatchClauses); } else { this.CatchClauses = EmptyCatchClauses; } if (@finally != null) { this.Finally = @finally; base.SetParent(@finally); } }
public TryStatementAst(IScriptExtent extent, StatementBlockAst body, IEnumerable <CatchClauseAst> catchClauses, StatementBlockAst @finally) : base(extent) { this.Body = body; this.CatchClauses = catchClauses.ToReadOnlyCollection(); this.Finally = @finally; }
public DoUntilStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition, body) { if (condition == null) { throw PSTraceSource.NewArgumentNullException("condition"); } }
public TryStatementAst(IScriptExtent extent, StatementBlockAst body, IEnumerable<CatchClauseAst> catchClauses, StatementBlockAst @finally) : base(extent) { this.Body = body; this.CatchClauses = catchClauses.ToReadOnlyCollection(); this.Finally = @finally; }
private void CheckForFlowOutOfFinally(Ast ast, string label) { for (Ast ast2 = ast.Parent; ast2 != null; ast2 = ast2.Parent) { if ((ast2 is ScriptBlockAst) || (ast2 is TrapStatementAst)) { break; } if (ast2 is NamedBlockAst) { return; } if (((label != null) && (ast2 is LoopStatementAst)) && LoopFlowException.MatchLoopLabel(label, ((LoopStatementAst)ast2).Label ?? "")) { return; } StatementBlockAst ast3 = ast2 as StatementBlockAst; if (ast3 != null) { TryStatementAst parent = ast3.Parent as TryStatementAst; if ((parent != null) && (parent.Finally == ast3)) { this._parser.ReportError(ast.Extent, ParserStrings.ControlLeavingFinally, new object[0]); return; } } } }
public TryStatementAst(IScriptExtent extent, StatementBlockAst body, IEnumerable<CatchClauseAst> catchClauses, StatementBlockAst @finally) : base(extent) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if (((catchClauses == null) || !catchClauses.Any<CatchClauseAst>()) && (@finally == null)) { throw PSTraceSource.NewArgumentException("catchClauses"); } this.Body = body; base.SetParent(body); if ((catchClauses != null) && catchClauses.Any<CatchClauseAst>()) { this.CatchClauses = new ReadOnlyCollection<CatchClauseAst>(catchClauses.ToArray<CatchClauseAst>()); base.SetParents((IEnumerable<Ast>) this.CatchClauses); } else { this.CatchClauses = EmptyCatchClauses; } if (@finally != null) { this.Finally = @finally; base.SetParent(@finally); } }
public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable<Tuple<ExpressionAst, StatementBlockAst>> clauses, StatementBlockAst @default) : base(extent, label, condition) { this.Flags = flags; this.Clauses = clauses.ToReadOnlyCollection(); this.Default = @default; }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { ArrayList statementList = new ArrayList(); foreach (var statement in statementBlockAst.Statements) { if (statement != null) { var obj = statement.Accept(this); var enumerator = LanguagePrimitives.GetEnumerator(obj); if (enumerator != null) { while (enumerator.MoveNext()) { statementList.Add(enumerator.Current); } } else { statementList.Add(obj); } } else { throw PSTraceSource.NewArgumentException("ast"); } } return(statementList.ToArray()); }
public DataStatementAst(IScriptExtent extent, string variableName, IEnumerable<ExpressionAst> commandsAllowed, StatementBlockAst body) : base(extent) { this._tupleIndex = -1; if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if (string.IsNullOrWhiteSpace(variableName)) { variableName = null; } this.Variable = variableName; if ((commandsAllowed != null) && commandsAllowed.Any<ExpressionAst>()) { this.CommandsAllowed = new ReadOnlyCollection<ExpressionAst>(commandsAllowed.ToArray<ExpressionAst>()); base.SetParents((IEnumerable<Ast>) this.CommandsAllowed); this.HasNonConstantAllowedCommand = (from ast in this.CommandsAllowed where !(ast is StringConstantExpressionAst) select ast).Any<ExpressionAst>(); } else { this.CommandsAllowed = new ReadOnlyCollection<ExpressionAst>(EmptyCommandsAllowed); } this.Body = body; base.SetParent(body); }
public DataStatementAst(IScriptExtent extent, string variableName, IEnumerable<ExpressionAst> commandsAllowed, StatementBlockAst body) : base(extent) { this.Variable = variableName; this.CommandsAllowed = commandsAllowed.ToReadOnlyCollection(); this.Body = body; }
public ArrayExpressionAst(IScriptExtent extent, StatementBlockAst statementBlock) : base(extent) { if (statementBlock == null) { throw PSTraceSource.NewArgumentNullException("statementBlock"); } this.SubExpression = statementBlock; base.SetParent(statementBlock); }
protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } this.Body = body; base.SetParent(body); }
public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, StatementBlockAst statements, bool isFilter) : base(extent) { this.EndBlock = new NamedBlockAst(extent, TokenKind.End, statements, true); if (isFilter) { throw new NotImplementedException(this.ToString()); } }
public SubExpressionAst(IScriptExtent extent, StatementBlockAst statementBlock) : base(extent) { if (statementBlock == null) { throw PSTraceSource.NewArgumentNullException("statementBlock"); } this.SubExpression = statementBlock; base.SetParent(statementBlock); }
public ForEachStatementAst(IScriptExtent extent, string label, ForEachFlags flags, VariableExpressionAst variable, PipelineBaseAst expression, StatementBlockAst body) : base(extent, label, expression, body) { if ((expression == null) || (variable == null)) { throw PSTraceSource.NewArgumentNullException((expression == null) ? "expression" : "variablePath"); } this.Flags = flags; this.Variable = variable; base.SetParent(variable); }
public ForStatementAst(IScriptExtent extent, string label, PipelineBaseAst initializer, PipelineBaseAst condition, PipelineBaseAst iterator, StatementBlockAst body) : base(extent, label, condition, body) { if (initializer != null) { this.Initializer = initializer; base.SetParent(initializer); } if (iterator != null) { this.Iterator = iterator; base.SetParent(iterator); } }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { if (statementBlockAst.Traps != null) { return(false); } if (statementBlockAst.Statements.Count > 1) { return(false); } StatementAst ast = statementBlockAst.Statements.FirstOrDefault <StatementAst>(); return((ast == null) ? ((object)false) : ((object)((bool)ast.Accept(this)))); }
public IfStatementAst(IScriptExtent extent, IEnumerable<Tuple<PipelineBaseAst, StatementBlockAst>> clauses, StatementBlockAst elseClause) : base(extent) { if ((clauses == null) || !clauses.Any<Tuple<PipelineBaseAst, StatementBlockAst>>()) { throw PSTraceSource.NewArgumentException("clauses"); } this.Clauses = new ReadOnlyCollection<Tuple<PipelineBaseAst, StatementBlockAst>>(clauses.ToArray<Tuple<PipelineBaseAst, StatementBlockAst>>()); base.SetParents<PipelineBaseAst, StatementBlockAst>(this.Clauses); if (elseClause != null) { this.ElseClause = elseClause; base.SetParent(elseClause); } }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { if (statementBlockAst.Traps != null) { return(false); } if (statementBlockAst.Statements.Count > 1) { return(false); } var pipeline = statementBlockAst.Statements.FirstOrDefault(); return(pipeline != null && (bool)pipeline.Accept(this)); }
public TrapStatementAst(IScriptExtent extent, TypeConstraintAst trapType, StatementBlockAst body) : base(extent) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if (trapType != null) { this.TrapType = trapType; base.SetParent(trapType); } this.Body = body; base.SetParent(body); }
public NamedBlockAst(IScriptExtent extent, TokenKind blockName, StatementBlockAst statementBlock, bool unnamed) : base(extent) { this.BlockKind = blockName; if (statementBlock == null) { this.Statements = new ReadOnlyCollection<StatementAst>(new StatementAst[] { }); } else { this.Statements = statementBlock.Statements; } this.Unnamed = unnamed; }
public BlockStatementAst(IScriptExtent extent, Token kind, StatementBlockAst body) : base(extent) { if ((kind == null) || (body == null)) { throw PSTraceSource.NewArgumentNullException((kind == null) ? "kind" : "body"); } if ((kind.Kind != TokenKind.Sequence) && (kind.Kind != TokenKind.Parallel)) { throw PSTraceSource.NewArgumentException("kind"); } this.Kind = kind; this.Body = body; base.SetParent(body); }
public NamedBlockAst(IScriptExtent extent, TokenKind blockName, StatementBlockAst statementBlock, bool unnamed) : base(extent) { this.BlockKind = blockName; if (statementBlock == null) { this.Statements = new ReadOnlyCollection <StatementAst>(new StatementAst[] { }); } else { this.Statements = statementBlock.Statements; } this.Unnamed = unnamed; }
internal override AstVisitAction InternalVisit(AstVisitor visitor) { AstVisitAction action = visitor.VisitNamedBlock(this); switch (action) { case AstVisitAction.SkipChildren: return(AstVisitAction.Continue); case AstVisitAction.Continue: action = StatementBlockAst.InternalVisit(visitor, this.Traps, this.Statements, action); break; } return(action); }
public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable<Tuple<ExpressionAst, StatementBlockAst>> clauses, StatementBlockAst @default) : base(extent, label, condition) { if (((clauses == null) || !clauses.Any<Tuple<ExpressionAst, StatementBlockAst>>()) && (@default == null)) { throw PSTraceSource.NewArgumentException("clauses"); } this.Flags = flags; this.Clauses = new ReadOnlyCollection<Tuple<ExpressionAst, StatementBlockAst>>(((clauses != null) && clauses.Any<Tuple<ExpressionAst, StatementBlockAst>>()) ? ((IList<Tuple<ExpressionAst, StatementBlockAst>>) clauses.ToArray<Tuple<ExpressionAst, StatementBlockAst>>()) : ((IList<Tuple<ExpressionAst, StatementBlockAst>>) EmptyClauseArray)); base.SetParents<ExpressionAst, StatementBlockAst>(this.Clauses); if (@default != null) { this.Default = @default; base.SetParent(@default); } }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { if (statementBlockAst != null) { var statements = statementBlockAst.Statements; if (statements != null) { var firstStatement = statements.FirstOrDefault(); if (firstStatement != null) { return firstStatement.Visit(this); } } } return null; }
public CatchClauseAst(IScriptExtent extent, IEnumerable<TypeConstraintAst> catchTypes, StatementBlockAst body) : base(extent) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if ((catchTypes != null) && catchTypes.Any<TypeConstraintAst>()) { this.CatchTypes = new ReadOnlyCollection<TypeConstraintAst>(catchTypes.ToArray<TypeConstraintAst>()); base.SetParents((IEnumerable<Ast>) this.CatchTypes); } else { this.CatchTypes = EmptyCatchTypes; } this.Body = body; base.SetParent(body); }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { bool isSafe = true; foreach (var statement in statementBlockAst.Statements) { _visitCount++; if (statement == null) { isSafe = false; break; } if (!(bool)statement.Accept(this)) { isSafe = false; break; } } return isSafe; }
public NamedBlockAst(IScriptExtent extent, TokenKind blockName, StatementBlockAst statementBlock, bool unnamed) : base(extent) { if (!blockName.HasTrait(TokenFlags.ScriptBlockBlockName) || (unnamed && ((blockName == TokenKind.Begin) || (blockName == TokenKind.Dynamicparam)))) { throw PSTraceSource.NewArgumentException("blockName"); } if (statementBlock == null) { throw PSTraceSource.NewArgumentNullException("statementBlock"); } this.Unnamed = unnamed; this.BlockKind = blockName; ReadOnlyCollection <StatementAst> statements = statementBlock.Statements; this.Statements = statements; foreach (StatementAst ast in statements) { ast.ClearParent(); } base.SetParents((IEnumerable <Ast>)statements); ReadOnlyCollection <TrapStatementAst> traps = statementBlock.Traps; if ((traps != null) && traps.Any <TrapStatementAst>()) { this.Traps = traps; foreach (TrapStatementAst ast2 in traps) { ast2.ClearParent(); } base.SetParents((IEnumerable <Ast>)traps); } if (!unnamed) { InternalScriptExtent extent2 = statementBlock.Extent as InternalScriptExtent; if (extent2 != null) { this.OpenCurlyExtent = new InternalScriptExtent(extent2.PositionHelper, extent2.StartOffset, extent2.StartOffset + 1); this.CloseCurlyExtent = new InternalScriptExtent(extent2.PositionHelper, extent2.EndOffset - 1, extent2.EndOffset); } } }
public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, StatementBlockAst statements, bool isFilter) : base(extent) { if (statements == null) { throw PSTraceSource.NewArgumentNullException("statements"); } if (paramBlock != null) { this.ParamBlock = paramBlock; base.SetParent(paramBlock); } if (isFilter) { this.ProcessBlock = new NamedBlockAst(statements.Extent, TokenKind.Process, statements, true); base.SetParent(this.ProcessBlock); } else { this.EndBlock = new NamedBlockAst(statements.Extent, TokenKind.End, statements, true); base.SetParent(this.EndBlock); } }
public System.Object VisitStatementBlock(System.Management.Automation.Language.StatementBlockAst statementBlockAst) { IScriptExtent mappedExtent = MapExtent(statementBlockAst.Extent); LinkedList <StatementAst> mappedStatements = new LinkedList <StatementAst>(); foreach (StatementAst s in statementBlockAst.Statements) { mappedStatements.AddLast(_VisitStatement(s)); } LinkedList <TrapStatementAst> mappedTraps = new LinkedList <TrapStatementAst>(); if (statementBlockAst.Traps != null) { foreach (TrapStatementAst ts in statementBlockAst.Traps) { mappedTraps.AddLast((TrapStatementAst)VisitTrap(ts)); } } return(new StatementBlockAst(mappedExtent, mappedStatements, mappedTraps)); }
public NamedBlockAst(IScriptExtent extent, TokenKind blockName, StatementBlockAst statementBlock, bool unnamed) : base(extent) { if (!blockName.HasTrait(TokenFlags.ScriptBlockBlockName) || (unnamed && ((blockName == TokenKind.Begin) || (blockName == TokenKind.Dynamicparam)))) { throw PSTraceSource.NewArgumentException("blockName"); } if (statementBlock == null) { throw PSTraceSource.NewArgumentNullException("statementBlock"); } this.Unnamed = unnamed; this.BlockKind = blockName; ReadOnlyCollection<StatementAst> statements = statementBlock.Statements; this.Statements = statements; foreach (StatementAst ast in statements) { ast.ClearParent(); } base.SetParents((IEnumerable<Ast>) statements); ReadOnlyCollection<TrapStatementAst> traps = statementBlock.Traps; if ((traps != null) && traps.Any<TrapStatementAst>()) { this.Traps = traps; foreach (TrapStatementAst ast2 in traps) { ast2.ClearParent(); } base.SetParents((IEnumerable<Ast>) traps); } if (!unnamed) { InternalScriptExtent extent2 = statementBlock.Extent as InternalScriptExtent; if (extent2 != null) { this.OpenCurlyExtent = new InternalScriptExtent(extent2.PositionHelper, extent2.StartOffset, extent2.StartOffset + 1); this.CloseCurlyExtent = new InternalScriptExtent(extent2.PositionHelper, extent2.EndOffset - 1, extent2.EndOffset); } } }
public virtual AstVisitAction VisitStatementBlock(StatementBlockAst statementBlockAst) { return AstVisitAction.Continue; }
public ForEachStatementAst(IScriptExtent extent, string label, ForEachFlags flags, VariableExpressionAst variable, PipelineBaseAst expression, StatementBlockAst body) : base(extent, label, expression, body) { this.Flags = flags; this.Variable = variable; }
public ForStatementAst(IScriptExtent extent, string label, PipelineBaseAst initializer, PipelineBaseAst condition, PipelineBaseAst iterator, StatementBlockAst body) : base(extent, label, condition, body) { this.Initializer = initializer; this.Iterator = iterator; }
/// <summary/> public virtual object VisitStatementBlock(StatementBlockAst statementBlockAst) { return _decorated.VisitStatementBlock(statementBlockAst); }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { if (statementBlockAst.Traps != null) { return false; } if (statementBlockAst.Statements.Count > 1) { return false; } StatementAst ast = statementBlockAst.Statements.FirstOrDefault<StatementAst>(); return ((ast == null) ? ((object) false) : ((object) ((bool) ast.Accept(this)))); }
/// <summary/> public virtual object VisitStatementBlock(StatementBlockAst statementBlockAst) { return(null); }
public WhileStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition, body) { }
public override AstVisitAction VisitStatementBlock(StatementBlockAst statementBlockAst) { return base.VisitStatementBlock(statementBlockAst); }
protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition) { this.Body = body; }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { return(this.VisitStatementBlock(statementBlockAst.Statements)); }
private AstVisitAction VisitSimpleLoopStatement(StatementBlockAst body, PipelineBaseAst condition, bool preExecuteBody, bool invertCond) { // TODO: pass loop label // preExecuteBody is for do while/until loops if (preExecuteBody && !EvaluateLoopBodyAst(body, null)) { return AstVisitAction.SkipChildren; } // the condition is XORed with invertCond and menas: (true && !invertCond) || (false && invertCond) while (LanguagePrimitives.ConvertTo<bool>(EvaluateAst(condition)) ^ invertCond) { if (!EvaluateLoopBodyAst(body, null)) { break; } } return AstVisitAction.SkipChildren; }
public override AstVisitAction VisitStatementBlock(StatementBlockAst ast) { return(Check(ast)); }
/// <summary/> public virtual AstVisitAction VisitStatementBlock(StatementBlockAst statementBlockAst) { return(AstVisitAction.Continue); }
public DoUntilStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition, body) { }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { CheckIsConstant(statementBlockAst, "Caller to verify ast is constant"); return(statementBlockAst.Statements[0].Accept(this)); }
public WhileStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition, body) { if (condition == null) { throw PSTraceSource.NewArgumentNullException("condition"); } }
public object VisitStatementBlock(StatementBlockAst statementBlockAst) { return(statementBlockAst.Statements.First <StatementAst>().Accept(this)); }
public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable <Tuple <ExpressionAst, StatementBlockAst> > clauses, StatementBlockAst @default) : base(extent, label, condition) { this.Flags = flags; this.Clauses = clauses.ToReadOnlyCollection(); this.Default = @default; }
public CatchClauseAst(IScriptExtent extent, IEnumerable <TypeConstraintAst> catchTypes, StatementBlockAst body) : base(extent) { if (body == null) { throw PSTraceSource.NewArgumentNullException("body"); } if ((catchTypes != null) && catchTypes.Any <TypeConstraintAst>()) { this.CatchTypes = new ReadOnlyCollection <TypeConstraintAst>(catchTypes.ToArray <TypeConstraintAst>()); base.SetParents((IEnumerable <Ast>) this.CatchTypes); } else { this.CatchTypes = EmptyCatchTypes; } this.Body = body; base.SetParent(body); }
public IfStatementAst(IScriptExtent extent, IEnumerable<Tuple<PipelineBaseAst, StatementBlockAst>> clauses, StatementBlockAst elseClause) : base(extent) { this.Clauses = clauses.ToReadOnlyCollection(); this.ElseClause = elseClause; }
ArrayExpressionAst BuildArrayExpressionAst(ParseTreeNode parseTreeNode) { VerifyTerm(parseTreeNode, this._grammar.array_expression); StatementBlockAst statements; // check if we have statements or it's empty if (parseTreeNode.ChildNodes[1].Term == _grammar.statement_list) { statements = BuildStatementListAst(parseTreeNode.ChildNodes[1]); } else { // otherwise make such an Ast without statements statements = new StatementBlockAst(new ScriptExtent(parseTreeNode.ChildNodes[1]), new StatementAst[] { }, new TrapStatementAst[] { }); } return new ArrayExpressionAst( new ScriptExtent(parseTreeNode), statements ); }
public ArrayExpressionAst(IScriptExtent extent, StatementBlockAst statementBlock) : base(extent) { this.SubExpression = statementBlock; }