Example #1
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock) : base(extent)
 {
     if (paramBlock != null)
     {
         this.ParamBlock = paramBlock;
         base.SetParent(paramBlock);
     }
     if (beginBlock != null)
     {
         this.BeginBlock = beginBlock;
         base.SetParent(beginBlock);
     }
     if (processBlock != null)
     {
         this.ProcessBlock = processBlock;
         base.SetParent(processBlock);
     }
     if (endBlock != null)
     {
         this.EndBlock = endBlock;
         base.SetParent(endBlock);
     }
     if (dynamicParamBlock != null)
     {
         this.DynamicParamBlock = dynamicParamBlock;
         base.SetParent(dynamicParamBlock);
     }
 }
Example #2
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock) : base(extent)
 {
     if (paramBlock != null)
     {
         this.ParamBlock = paramBlock;
         base.SetParent(paramBlock);
     }
     if (beginBlock != null)
     {
         this.BeginBlock = beginBlock;
         base.SetParent(beginBlock);
     }
     if (processBlock != null)
     {
         this.ProcessBlock = processBlock;
         base.SetParent(processBlock);
     }
     if (endBlock != null)
     {
         this.EndBlock = endBlock;
         base.SetParent(endBlock);
     }
     if (dynamicParamBlock != null)
     {
         this.DynamicParamBlock = dynamicParamBlock;
         base.SetParent(dynamicParamBlock);
     }
 }
Example #3
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock)
     : base(extent)
 {
     this.BeginBlock = beginBlock;
     this.DynamicParamBlock = dynamicParamBlock;
     this.EndBlock = endBlock;
     this.ParamBlock = paramBlock;
     this.ProcessBlock = processBlock;
 }
Example #4
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock)
     : base(extent)
 {
     this.BeginBlock        = beginBlock;
     this.DynamicParamBlock = dynamicParamBlock;
     this.EndBlock          = endBlock;
     this.ParamBlock        = paramBlock;
     this.ProcessBlock      = processBlock;
 }
Example #5
0
    public System.Object VisitNamedBlock(System.Management.Automation.Language.NamedBlockAst namedBlockAst)
    {
        IScriptExtent mappedExtent = MapExtent(namedBlockAst.Extent);

        LinkedList <StatementAst> mappedStatements = new LinkedList <StatementAst>();

        foreach (StatementAst s in namedBlockAst.Statements)
        {
            mappedStatements.AddLast(_VisitStatement(s));
        }
        LinkedList <TrapStatementAst> mappedTraps = new LinkedList <TrapStatementAst>();

        if (namedBlockAst.Traps != null)
        {
            foreach (TrapStatementAst ts in namedBlockAst.Traps)
            {
                mappedTraps.AddLast((TrapStatementAst)VisitTrap(ts));
            }
        }
        // this doesn't really map the statement block
        StatementBlockAst mappedStatementBlock = new StatementBlockAst(mappedExtent, mappedStatements, mappedTraps);

        return(new NamedBlockAst(mappedExtent, namedBlockAst.BlockKind, mappedStatementBlock, namedBlockAst.Unnamed));
    }
Example #6
0
 /// <summary/>
 public virtual AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(AstVisitAction.Continue);
 }
Example #7
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(false);
 }
Example #8
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst ast)
 {
     return(Check(ast));
 }
Example #9
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return false;
 }
Example #10
0
 /// <summary/>
 public virtual AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst) => DefaultVisit(namedBlockAst);
Example #11
0
 public virtual AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return AstVisitAction.Continue;
 }
Example #12
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst ast)
 {
     return this.Check(ast);
 }
 /// <summary/>
 public virtual object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return _decorated.VisitNamedBlock(namedBlockAst);
 }
 public object VisitNamedBlock(NamedBlockAst namedBlockAst) { throw new UnexpectedElementException(); }
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(AstVisitAction.Continue);
 }
Example #16
0
        private ScriptBlockAst NamedBlockListRule(Token lCurly, List<UsingStatementAst> usingStatements, ParamBlockAst paramBlockAst)
        {
            //G  named-block-list:
            //G      named-block
            //G      named-block-list   named-block
            //G  named-block:
            //G      statement-terminators:opt   block-name   statement-block
            //G  block-name:  one of
            //G      'dynamicparam'   'begin'   'process'    'end'

            NamedBlockAst dynamicParamBlock = null;
            NamedBlockAst beginBlock = null;
            NamedBlockAst processBlock = null;
            NamedBlockAst endBlock = null;
            IScriptExtent startExtent = lCurly != null
                                            ? lCurly.Extent
                                            : (paramBlockAst != null) ? paramBlockAst.Extent : null;
            IScriptExtent endExtent = null;
            IScriptExtent extent;

            while (true)
            {
                Token blockNameToken = NextToken();
                switch (blockNameToken.Kind)
                {
                    default:
                        UngetToken(blockNameToken);
                        goto finished_named_block_list;

                    case TokenKind.Dynamicparam:
                    case TokenKind.Begin:
                    case TokenKind.Process:
                    case TokenKind.End:
                        break;
                }

                if (startExtent == null)
                {
                    startExtent = blockNameToken.Extent;
                }
                endExtent = blockNameToken.Extent;

                StatementBlockAst statementBlock = StatementBlockRule();

                if (statementBlock == null)
                {
                    // ErrorRecovery: Eat the block name and keep going, there might be a valid block next.

                    ReportIncompleteInput(After(blockNameToken.Extent),
                        () => ParserStrings.MissingNamedStatementBlock, blockNameToken.Kind.Text());
                    statementBlock = new StatementBlockAst(blockNameToken.Extent, Utils.EmptyArray<StatementAst>(), null);
                }
                else
                {
                    endExtent = statementBlock.Extent;
                }

                extent = ExtentOf(blockNameToken, endExtent);
                if (blockNameToken.Kind == TokenKind.Begin && beginBlock == null)
                {
                    beginBlock = new NamedBlockAst(extent, TokenKind.Begin, statementBlock, false);
                }
                else if (blockNameToken.Kind == TokenKind.Process && processBlock == null)
                {
                    processBlock = new NamedBlockAst(extent, TokenKind.Process, statementBlock, false);
                }
                else if (blockNameToken.Kind == TokenKind.End && endBlock == null)
                {
                    endBlock = new NamedBlockAst(extent, TokenKind.End, statementBlock, false);
                }
                else if (blockNameToken.Kind == TokenKind.Dynamicparam && dynamicParamBlock == null)
                {
                    dynamicParamBlock = new NamedBlockAst(extent, TokenKind.Dynamicparam, statementBlock, false);
                }
                else
                {
                    // ErrorRecovery: this is a semantic error, we can keep parsing w/o trouble.

                    ReportError(extent,
                        () => ParserStrings.DuplicateScriptCommandClause, blockNameToken.Kind.Text());
                }

                SkipNewlinesAndSemicolons();
            }
        finished_named_block_list:

            IScriptExtent scriptBlockExtent;
            extent = ExtentOf(startExtent, endExtent);
            CompleteScriptBlockBody(lCurly, ref extent, out scriptBlockExtent);

            return new ScriptBlockAst(scriptBlockExtent, usingStatements, paramBlockAst, beginBlock, processBlock, endBlock,
                dynamicParamBlock);
        }
Example #17
0
        public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
        {
            Diagnostics.Assert(_allowEnvironmentVariables || FoundError, "VisitScriptBlock should have already reported an error");

            return AstVisitAction.Continue;
        }
Example #18
0
        public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinitionAst configurationDefinitionAst)
        {
            //
            // Check if the ScriptBlockAst contains NamedBlockAst other than the End block
            //
            ScriptBlockAst configBody = configurationDefinitionAst.Body.ScriptBlock;
            if (configBody.BeginBlock != null || configBody.ProcessBlock != null || configBody.DynamicParamBlock != null)
            {
                var unsupportedNamedBlocks = new NamedBlockAst[] { configBody.BeginBlock, configBody.ProcessBlock, configBody.DynamicParamBlock };
                foreach (NamedBlockAst namedBlock in unsupportedNamedBlocks)
                {
                    if (namedBlock != null)
                    {
                        _parser.ReportError(namedBlock.OpenCurlyExtent, () => ParserStrings.UnsupportedNamedBlockInConfiguration);
                    }
                }

                // ToRemove: No need to continue the parsing if there is no EndBlock, check if (configBody.EndBlock == null)
            }

            return AstVisitAction.Continue;
        }
Example #19
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst ast) { return CheckParent(ast); }
Example #20
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     if (namedBlockAst.Traps.Any())
     {
         return VisitNamedBlockWithTraps(namedBlockAst);
     }
     foreach (var stmt in namedBlockAst.Statements)
     {
         VisitStatement(stmt);
     }
     return AstVisitAction.SkipChildren;
 }
 /// <summary>
 /// Visit named block
 /// </summary>
 /// <param name="namedBlockAst"></param>
 /// <returns></returns>
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     if (namedBlockAst == null) return null;
     // Don't visit traps - they get their own scope
     return VisitStatementBlock(namedBlockAst.Statements);
 }
Example #22
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return null;
 }
Example #23
0
        public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
        {
            if (namedBlockAst.Traps.Any())
            {
                return VisitNamedBlockWithTraps(namedBlockAst);
            }

            // just iterate over children
            return base.VisitNamedBlock(namedBlockAst);
        }
Example #24
0
 private Expression<Action<FunctionContext>> CompileNamedBlock(NamedBlockAst namedBlockAst, string funcName)
 {
     IScriptExtent entryExtent = null;
     IScriptExtent exitExtent = null;
     if (namedBlockAst.Unnamed)
     {
         ScriptBlockAst parent = (ScriptBlockAst) namedBlockAst.Parent;
         if ((parent.Parent != null) && (parent.Extent is InternalScriptExtent))
         {
             InternalScriptExtent extent = (InternalScriptExtent) parent.Extent;
             entryExtent = new InternalScriptExtent(extent.PositionHelper, extent.StartOffset, extent.StartOffset + 1);
             exitExtent = new InternalScriptExtent(extent.PositionHelper, extent.EndOffset - 1, extent.EndOffset);
         }
     }
     else
     {
         entryExtent = namedBlockAst.OpenCurlyExtent;
         exitExtent = namedBlockAst.CloseCurlyExtent;
     }
     return this.CompileSingleLambda(namedBlockAst.Statements, namedBlockAst.Traps, funcName, entryExtent, exitExtent);
 }
Example #25
0
        private AstVisitAction VisitNamedBlockWithTraps(NamedBlockAst namedBlockAst)
        {
            foreach (StatementAst statement in namedBlockAst.Statements)
            {
                try
                {
                    VisitStatement(statement);
                }
                catch (FlowControlException)
                {
                    // flow control as Exit, Return, Break, and Continue doesn't concern the user and is propagated
                    throw;
                }
                catch (Exception ex)
                {
                    TrapStatementAst trapStatementAst = FindMatchingTrapStatement(namedBlockAst.Traps, ex);
                    if (trapStatementAst == null)
                    {
                        throw;
                    }

                    SetUnderscoreVariable(ex);
                    AstVisitAction visitAction = VisitTrapBody(trapStatementAst);

                    if (visitAction != AstVisitAction.Continue)
                    {
                        return AstVisitAction.SkipChildren;
                    }
                }
            }

            return AstVisitAction.SkipChildren;
        }
Example #26
0
 private ScriptBlockAst NamedBlockListRule(Token lCurly, ParamBlockAst paramBlockAst)
 {
     IScriptExtent extent = null;
     IScriptExtent scriptExtent;
     Token token;
     IScriptExtent scriptExtent1 = null;
     IScriptExtent extent1;
     NamedBlockAst namedBlockAst = null;
     NamedBlockAst namedBlockAst1 = null;
     NamedBlockAst namedBlockAst2 = null;
     NamedBlockAst namedBlockAst3 = null;
     if (lCurly != null)
     {
         extent1 = lCurly.Extent;
     }
     else
     {
         if (paramBlockAst != null)
         {
             extent1 = paramBlockAst.Extent;
         }
         else
         {
             extent1 = null;
         }
     }
     IScriptExtent extent2 = extent1;
     while (true)
     {
         token = this.NextToken();
         TokenKind kind = token.Kind;
         if (kind > TokenKind.Dynamicparam)
         {
             if (kind != TokenKind.End && kind != TokenKind.Process)
             {
                 break;
             }
         }
         else
         {
             if (kind != TokenKind.Begin && kind != TokenKind.Dynamicparam)
             {
                 break;
             }
         }
         if (extent2 == null)
         {
             extent2 = token.Extent;
         }
         extent = token.Extent;
         StatementBlockAst statementBlockAst = this.StatementBlockRule();
         if (statementBlockAst != null)
         {
             extent = statementBlockAst.Extent;
         }
         else
         {
             object[] objArray = new object[1];
             objArray[0] = token.Kind.Text();
             this.ReportIncompleteInput(Parser.After(token.Extent), ParserStrings.MissingNamedStatementBlock, objArray);
             statementBlockAst = new StatementBlockAst(token.Extent, new StatementAst[0], null);
         }
         scriptExtent = Parser.ExtentOf(token, extent);
         if (token.Kind != TokenKind.Begin || namedBlockAst1 != null)
         {
             if (token.Kind != TokenKind.Process || namedBlockAst2 != null)
             {
                 if (token.Kind != TokenKind.End || namedBlockAst3 != null)
                 {
                     if (token.Kind != TokenKind.Dynamicparam || namedBlockAst != null)
                     {
                         object[] objArray1 = new object[1];
                         objArray1[0] = token.Kind.Text();
                         this.ReportError(scriptExtent, ParserStrings.DuplicateScriptCommandClause, objArray1);
                     }
                     else
                     {
                         namedBlockAst = new NamedBlockAst(scriptExtent, TokenKind.Dynamicparam, statementBlockAst, false);
                     }
                 }
                 else
                 {
                     namedBlockAst3 = new NamedBlockAst(scriptExtent, TokenKind.End, statementBlockAst, false);
                 }
             }
             else
             {
                 namedBlockAst2 = new NamedBlockAst(scriptExtent, TokenKind.Process, statementBlockAst, false);
             }
         }
         else
         {
             namedBlockAst1 = new NamedBlockAst(scriptExtent, TokenKind.Begin, statementBlockAst, false);
         }
         this.SkipNewlinesAndSemicolons();
     }
     this.UngetToken(token);
     scriptExtent = Parser.ExtentOf(extent2, extent);
     this.CompleteScriptBlockBody(lCurly, ref scriptExtent, out scriptExtent1);
     return new ScriptBlockAst(scriptExtent1, paramBlockAst, namedBlockAst1, namedBlockAst2, namedBlockAst3, namedBlockAst);
 }
Example #27
0
        private AstVisitAction VisitNamedBlockWithTraps(NamedBlockAst namedBlockAst)
        {
            foreach (StatementAst statement in namedBlockAst.Statements)
            {
                try
                {
                    statement.Visit(this);
                }
                catch (ReturnException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    TrapStatementAst trapStatementAst = FindMatchingTrapStatement(namedBlockAst.Traps, ex);
                    if (trapStatementAst == null)
                    {
                        throw;
                    }

                    SetUnderscoreVariable(ex);
                    AstVisitAction visitAction = VisitTrapBody(trapStatementAst);

                    if (visitAction != AstVisitAction.Continue)
                    {
                        return AstVisitAction.SkipChildren;
                    }
                }
            }

            return AstVisitAction.SkipChildren;
        }
Example #28
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst) { return AutomationNull.Value; }
Example #29
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     // just iterate over children
     return base.VisitNamedBlock(namedBlockAst);
 }
Example #30
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst) { throw PSTraceSource.NewArgumentException("ast"); }
Example #31
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(this.VisitStatementBlock(namedBlockAst.Statements));
 }
 /// <summary>
 /// Visit NamedBlockAst. Skip if name of the block
 /// is in namestobeskipped
 /// </summary>
 /// <param name="namedBlockAst"></param>
 /// <returns></returns>
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return VisitActionHelper(namedBlockAst);
 }
Example #33
0
 /// <summary/>
 public virtual object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(null);
 }
Example #34
0
        private Expression<Action<FunctionContext>> CompileNamedBlock(NamedBlockAst namedBlockAst, string funcName, ScriptBlockAst rootForDefiningTypes)
        {
            IScriptExtent entryExtent = null;
            IScriptExtent exitExtent = null;
            if (namedBlockAst.Unnamed)
            {
                // Get extent from the function or scriptblock expression parent, if any.
                var scriptBlock = (ScriptBlockAst)namedBlockAst.Parent;
                if (scriptBlock.Parent != null && scriptBlock.Extent is InternalScriptExtent)
                {
                    // We must have curlies at the start/end.
                    var scriptExtent = (InternalScriptExtent)scriptBlock.Extent;
                    entryExtent = new InternalScriptExtent(scriptExtent.PositionHelper, scriptExtent.StartOffset, scriptExtent.StartOffset + 1);
                    exitExtent = new InternalScriptExtent(scriptExtent.PositionHelper, scriptExtent.EndOffset - 1, scriptExtent.EndOffset);
                }
            }
            else
            {
                entryExtent = namedBlockAst.OpenCurlyExtent;
                exitExtent = namedBlockAst.CloseCurlyExtent;
            }

            return CompileSingleLambda(namedBlockAst.Statements, namedBlockAst.Traps, funcName, entryExtent, exitExtent, rootForDefiningTypes);
        }
Example #35
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Example #36
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     Diagnostics.Assert(false, "NamedBlockAst is handled specially, not via the visitor.");
     return null;
 }
Example #37
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(AutomationNull.Value);
 }
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return AstVisitAction.Continue;
 }
Example #39
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return this.VisitStatementBlock(namedBlockAst.Statements);
 }
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     throw new NotImplementedException();
 }