예제 #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);
     }
 }
예제 #2
0
 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());
 }
예제 #3
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);
     }
 }
예제 #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;
 }
예제 #5
0
 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());
     }
 }
예제 #6
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;
 }
예제 #7
0
        bool IParameterMetadataProvider.UsesCmdletBinding()
        {
            bool flag = false;

            if (this.Parameters != null)
            {
                return(ParamBlockAst.UsesCmdletBinding(this.Parameters));
            }
            if (this.Body.ParamBlock != null)
            {
                flag = ((IParameterMetadataProvider)this.Body).UsesCmdletBinding();
            }
            return(flag);
        }
예제 #8
0
        bool IParameterMetadataProvider.UsesCmdletBinding()
        {
            bool flag = false;

            if (this.ParamBlock != null)
            {
                flag = (from attribute in this.ParamBlock.Attributes
                        where typeof(CmdletBindingAttribute).Equals(attribute.TypeName.GetReflectionAttributeType())
                        select attribute).Any <AttributeAst>();
                if (!flag)
                {
                    flag = ParamBlockAst.UsesCmdletBinding(this.ParamBlock.Parameters);
                }
            }
            return(flag);
        }
예제 #9
0
    public System.Object VisitParamBlock(System.Management.Automation.Language.ParamBlockAst paramBlockAst)
    {
        IScriptExtent mappedExtent = MapExtent(paramBlockAst.Extent);

        LinkedList <AttributeAst> mappedAttributes = new LinkedList <AttributeAst>();

        foreach (AttributeAst a in paramBlockAst.Attributes)
        {
            mappedAttributes.AddLast((AttributeAst)VisitAttribute(a));
        }
        LinkedList <ParameterAst> mappedParameters = new LinkedList <ParameterAst>();

        foreach (ParameterAst p in paramBlockAst.Parameters)
        {
            mappedParameters.AddLast((ParameterAst)VisitParameter(p));
        }

        return(new ParamBlockAst(mappedExtent, mappedAttributes, mappedParameters));
    }
예제 #10
0
 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);
     }
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
예제 #13
0
        public override AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
        {
            CheckForDuplicateParameters(paramBlockAst.Parameters);

            return AstVisitAction.Continue;
        }
예제 #14
0
 public virtual AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst) => DefaultVisit(paramBlockAst);
 /// <summary>
 /// Visit param block
 /// </summary>
 /// <param name="paramBlockAst"></param>
 /// <returns></returns>
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return null;
 }
 /// <summary/>
 public virtual object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return _decorated.VisitParamBlock(paramBlockAst);
 }
예제 #17
0
        internal string ToStringForSerialization(Tuple <List <VariableExpressionAst>, string> usingVariablesTuple, int initialStartOffset, int initialEndOffset)
        {
            List <VariableExpressionAst> collection = usingVariablesTuple.Item1;
            string     str   = usingVariablesTuple.Item2;
            List <Ast> list2 = new List <Ast>(collection);

            if (this.ParamBlock != null)
            {
                list2.Add(this.ParamBlock);
            }
            int           startOffset = base.Extent.StartOffset;
            int           startIndex  = initialStartOffset - startOffset;
            int           num3        = initialEndOffset - startOffset;
            string        str2        = this.ToString();
            StringBuilder builder     = new StringBuilder();

            foreach (Ast ast in from ast in list2
                     orderby ast.Extent.StartOffset
                     select ast)
            {
                int num4 = ast.Extent.StartOffset - startOffset;
                int num5 = ast.Extent.EndOffset - startOffset;
                if (num4 >= startIndex)
                {
                    if (num4 >= num3)
                    {
                        break;
                    }
                    VariableExpressionAst ast2 = ast as VariableExpressionAst;
                    if (ast2 != null)
                    {
                        string userPath = ast2.VariablePath.UserPath;
                        string str4     = ast2.Splatted ? "@" : "$";
                        string str5     = str4 + "__using_" + userPath;
                        builder.Append(str2.Substring(startIndex, num4 - startIndex));
                        builder.Append(str5);
                        startIndex = num5;
                    }
                    else
                    {
                        int           num6;
                        ParamBlockAst ast3 = ast as ParamBlockAst;
                        if (ast3.Parameters.Count == 0)
                        {
                            num6 = num5 - 1;
                        }
                        else
                        {
                            ParameterAst ast4 = ast3.Parameters[0];
                            num6 = (ast4.Attributes.Count == 0) ? (ast4.Name.Extent.StartOffset - startOffset) : (ast4.Attributes[0].Extent.StartOffset - startOffset);
                            str  = str + ",\n";
                        }
                        builder.Append(str2.Substring(startIndex, num6 - startIndex));
                        builder.Append(str);
                        startIndex = num6;
                    }
                }
            }
            builder.Append(str2.Substring(startIndex, num3 - startIndex));
            string str6 = builder.ToString();

            if (((base.Parent is ScriptBlockExpressionAst) && (initialStartOffset == base.Extent.StartOffset)) && (initialEndOffset == base.Extent.EndOffset))
            {
                str6 = str6.Substring(1, str6.Length - 2);
            }
            return(str6);
        }
예제 #18
0
 public override AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     this.ReportError(paramBlockAst, () => ParserStrings.ParameterDeclarationNotSupportedInDataSection, new object[0]);
     return AstVisitAction.Continue;
 }
예제 #19
0
파일: Parser.cs 프로젝트: nickchal/pash
 private ScriptBlockAst ScriptBlockBodyRule(Token lCurly, ParamBlockAst paramBlockAst, bool isFilter)
 {
     IScriptExtent scriptExtent = null;
     IScriptExtent extent;
     Token token = this.PeekToken();
     if ((token.TokenFlags & TokenFlags.ScriptBlockBlockName) != TokenFlags.ScriptBlockBlockName)
     {
         List<TrapStatementAst> trapStatementAsts = new List<TrapStatementAst>();
         List<StatementAst> statementAsts = new List<StatementAst>();
         if (paramBlockAst != null)
         {
             extent = paramBlockAst.Extent;
         }
         else
         {
             extent = null;
         }
         IScriptExtent scriptExtent1 = extent;
         do
         {
             IScriptExtent scriptExtent2 = this.StatementListRule(statementAsts, trapStatementAsts);
             if (scriptExtent1 != null)
             {
                 if (scriptExtent2 == null)
                 {
                     continue;
                 }
                 scriptExtent1 = Parser.ExtentOf(scriptExtent1, scriptExtent2);
             }
             else
             {
                 scriptExtent1 = scriptExtent2;
             }
         }
         while (!this.CompleteScriptBlockBody(lCurly, ref scriptExtent1, out scriptExtent));
         IScriptExtent scriptExtent3 = scriptExtent;
         ParamBlockAst paramBlockAst1 = paramBlockAst;
         IScriptExtent scriptExtent4 = scriptExtent1;
         IScriptExtent emptyExtent = scriptExtent4;
         if (scriptExtent4 == null)
         {
             emptyExtent = PositionUtilities.EmptyExtent;
         }
         return new ScriptBlockAst(scriptExtent3, paramBlockAst1, new StatementBlockAst(emptyExtent, statementAsts, trapStatementAsts), isFilter);
     }
     else
     {
         return this.NamedBlockListRule(lCurly, paramBlockAst);
     }
 }
예제 #20
0
 public override AstVisitAction VisitParamBlock(ParamBlockAst ast) { return CheckParent(ast); }
예제 #21
0
 public override AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     this.CheckForDuplicateParameters(paramBlockAst.Parameters);
     return(AstVisitAction.Continue);
 }
예제 #22
0
 /// <summary/>
 public virtual object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return(null);
 }
예제 #23
0
 public override AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     throw new NotImplementedException(); //VisitParamBlock(paramBlockAst);
 }
예제 #24
0
 public override AstVisitAction VisitParamBlock(ParamBlockAst ast)
 {
     return this.Check(ast);
 }
 public override AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     this.ReportError(paramBlockAst, () => ParserStrings.ParameterDeclarationNotSupportedInDataSection, new object[0]);
     return(AstVisitAction.Continue);
 }
 public object VisitParamBlock(ParamBlockAst paramBlockAst) { throw new UnexpectedElementException(); }
예제 #27
0
파일: Parser.cs 프로젝트: dfinke/powershell
        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);
        }
예제 #28
0
 public virtual AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return AstVisitAction.Continue;
 }
예제 #29
0
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return(AutomationNull.Value);
 }
예제 #30
0
 public override AstVisitAction VisitParamBlock(ParamBlockAst ast)
 {
     return(Check(ast));
 }
예제 #31
0
파일: Parser.cs 프로젝트: dfinke/powershell
        private ScriptBlockAst ScriptBlockBodyRule(Token lCurly, List<UsingStatementAst> usingStatements, ParamBlockAst paramBlockAst, bool isFilter, StatementAst predefinedStatementAst)
        {
            //G  script-block-body:
            //G      named-block-list
            //G      statement-list

            Token token = PeekToken();

            if ((token.TokenFlags & TokenFlags.ScriptBlockBlockName) == TokenFlags.ScriptBlockBlockName)
            {
                return NamedBlockListRule(lCurly, usingStatements, paramBlockAst);
            }

            List<TrapStatementAst> traps = new List<TrapStatementAst>();
            List<StatementAst> statements = new List<StatementAst>();
            if (predefinedStatementAst != null)
            {
                statements.Add(predefinedStatementAst);
            }
            IScriptExtent statementListExtent = paramBlockAst != null ? paramBlockAst.Extent : null;
            IScriptExtent scriptBlockExtent;

            while (true)
            {
                IScriptExtent extent = StatementListRule(statements, traps);
                if (statementListExtent == null)
                {
                    statementListExtent = extent;
                }
                else if (extent != null)
                {
                    statementListExtent = ExtentOf(statementListExtent, extent);
                }

                if (CompleteScriptBlockBody(lCurly, ref statementListExtent, out scriptBlockExtent))
                {
                    break;
                }
            }

            return new ScriptBlockAst(scriptBlockExtent, usingStatements, paramBlockAst,
                new StatementBlockAst(statementListExtent ?? PositionUtilities.EmptyExtent, statements, traps), isFilter);
        }
예제 #32
0
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return false;
 }
예제 #33
0
파일: Parser.cs 프로젝트: nickchal/pash
 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);
 }
예제 #34
0
 public virtual AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return(AstVisitAction.Continue);
 }
예제 #35
0
 public object VisitParamBlock(ParamBlockAst paramBlockAst) { return AutomationNull.Value; }
예제 #36
0
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     return(false);
 }
예제 #37
0
 public object VisitParamBlock(ParamBlockAst paramBlockAst) { throw PSTraceSource.NewArgumentException("ast"); }
예제 #38
0
파일: Compiler.cs 프로젝트: 40a/PowerShell
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     Diagnostics.Assert(false, "Nothing to generate for a parameter block");
     return null;
 }
 public object VisitParamBlock(ParamBlockAst paramBlockAst)
 {
     throw new NotImplementedException();
 }