Пример #1
0
        public static SeparatedSyntaxList <TNode> SeparatedList <TNode>(params CSharpSyntaxNode[] nodes) where TNode : CSharpSyntaxNode
        {
            if (nodes != null)
            {
                return(new SeparatedSyntaxList <TNode>(SyntaxList.List(nodes)));
            }

            return(default(SeparatedSyntaxList <TNode>));
        }
Пример #2
0
 public static SeparatedSyntaxList <TNode> SeparatedList <TNode>(
     TNode node1,
     SyntaxToken token,
     TNode node2
     ) where TNode : CSharpSyntaxNode
 {
     return(new SeparatedSyntaxList <TNode>(
                new SyntaxList <CSharpSyntaxNode>(SyntaxList.List(node1, token, node2))
                ));
 }
        // If "isMethodBody" is true, then this is the immediate body of a method/accessor.
        // In this case, we create a many-child list if the body is not a small single statement.
        // This then allows a "with many weak children" red node when the red node is created.
        // If "isAccessorBody" is true, then we produce a special diagnostic if the open brace is
        // missing.  Also, "isMethodBody" must be true.
        private BlockSyntax ParseBlock(bool isMethodBody = false)
        {
            // Check again for incremental re-use, since ParseBlock is called from a bunch of places
            // other than ParseStatement()
            if (this.IsIncrementalAndFactoryContextMatches && this.CurrentNodeKind == SyntaxKind.Block)
            {
                return((BlockSyntax)this.EatNode());
            }

            // There's a special error code for a missing token after an accessor keyword
            var openBrace = this.EatToken(SyntaxKind.OpenBraceToken);

            var statements = this._pool.Allocate <StatementSyntax>();

            try
            {
                CSharpSyntaxNode tmp = openBrace;
                this.ParseStatements(ref tmp, statements, stopOnSwitchSections: false);
                openBrace = (SyntaxToken)tmp;
                var closeBrace = this.EatToken(SyntaxKind.CloseBraceToken);

                SyntaxList <StatementSyntax> statementList;
                if (isMethodBody && IsLargeEnoughNonEmptyStatementList(statements))
                {
                    // Force creation a many-children list, even if only 1, 2, or 3 elements in the statement list.
                    statementList = new SyntaxList <StatementSyntax>(SyntaxList.List(((SyntaxListBuilder)statements).ToArray()));
                }
                else
                {
                    statementList = statements;
                }

                return(_syntaxFactory.Block(openBrace, statementList, closeBrace));
            }
            finally
            {
                this._pool.Free(statements);
            }
        }
Пример #4
0
        internal CSharpSyntaxNode ToListNode()
        {
            switch (this.Count)
            {
            case 0:
                return(null);

            case 1:
                return(_nodes[0]);

            case 2:
                return(SyntaxList.List(_nodes[0], _nodes[1]));

            case 3:
                return(SyntaxList.List(_nodes[0], _nodes[1], _nodes[2]));

            default:
                var tmp = new ArrayElement <CSharpSyntaxNode> [this.Count];
                Array.Copy(_nodes, tmp, this.Count);
                return(SyntaxList.List(tmp));
            }
        }
Пример #5
0
 internal static CSharpSyntaxNode ListNode(params ArrayElement <CSharpSyntaxNode>[] nodes)
 {
     return(SyntaxList.List(nodes));
 }
Пример #6
0
 internal static CSharpSyntaxNode ListNode(CSharpSyntaxNode node0, CSharpSyntaxNode node1, CSharpSyntaxNode node2)
 {
     return(SyntaxList.List(node0, node1, node2));
 }
Пример #7
0
 public static SyntaxList <TNode> List <TNode>(TNode node0, TNode node1, TNode node2) where TNode : CSharpSyntaxNode
 {
     return(new SyntaxList <TNode>(SyntaxList.List(node0, node1, node2)));
 }
Пример #8
0
        private ParameterSyntax ParseParameter(
            SyntaxListBuilder <AnnotationSyntax> attributes,
            SyntaxListBuilder modifiers,
            bool allowThisKeyword,
            bool allowDefaults,
            bool allowAttributes,
            bool allowFieldModifiers)
        {
            if (this.IsIncrementalAndFactoryContextMatches && CanReuseParameter(this.CurrentNode as CSharp.Syntax.ParameterSyntax, attributes, modifiers))
            {
                return((ParameterSyntax)this.EatNode());
            }

            this.ParseAnnotationDeclarations(attributes, allowAttributes);
            this.ParseParameterModifiers(modifiers, allowThisKeyword, allowFieldModifiers);



            TypeSyntax type = null;

            type = this.ParseType(true);


            var hasArgList = this.CurrentToken.Kind == SyntaxKind.DotDotDotToken;

            SyntaxToken dotdotdotTk = default(SyntaxToken);

            if (hasArgList)
            {
                dotdotdotTk = this.EatToken(SyntaxKind.DotDotDotToken);
            }


            SyntaxToken name = null;
            //if (!hasArgList)
            {
                name = this.ParseIdentifierToken();

                // When the user type "int foo[]", give them a useful error
                if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind == SyntaxKind.CloseBracketToken)
                {
                    var open  = this.EatToken();
                    var close = this.EatToken();
                    open = this.AddError(open, ErrorCode.ERR_BadArraySyntax);
                    name = AddTrailingSkippedSyntax(name, SyntaxList.List(open, close));
                }
            }
            //else if (this.IsPossibleName())
            //{
            //	// Current token is an identifier token, we expected a CloseParenToken.
            //	// Get the expected token error for the missing token with correct diagnostic
            //	// span and then parse the identifier token.

            //	SyntaxDiagnosticInfo diag = this.GetExpectedTokenError(SyntaxKind.CloseParenToken, SyntaxKind.IdentifierToken);
            //	name = this.ParseIdentifierToken();
            //	name = WithAdditionalDiagnostics(name, diag);
            //}
            //else
            //{
            //	// name is not optional on ParameterSyntax
            //	name = this.EatToken(SyntaxKind.ArgListKeyword);
            //}

            EqualsValueClauseSyntax def = null;

            if (this.CurrentToken.Kind == SyntaxKind.EqualsToken)
            {
                var equals = this.EatToken(SyntaxKind.EqualsToken);
                var expr   = this.ParseExpression();
                def = _syntaxFactory.EqualsValueClause(equals, expr);

                if (!allowDefaults)
                {
                    def = this.AddError(def, equals, ErrorCode.ERR_DefaultValueNotAllowed);
                }
                else
                {
                    def = CheckFeatureAvailability(def, MessageID.IDS_FeatureOptionalParameter);
                }
            }

            return(_syntaxFactory.Parameter(attributes, modifiers.ToTokenList(), type, dotdotdotTk, name, def));
        }
Пример #9
0
 internal static GreenNode ListNode(params ArrayElement <GreenNode>[] nodes)
 {
     return(SyntaxList.List(nodes));
 }
Пример #10
0
 internal static GreenNode ListNode(CSharpSyntaxNode node0, CSharpSyntaxNode node1)
 {
     return(SyntaxList.List(node0, node1));
 }