Exemplo n.º 1
0
        private DirectiveTriviaSyntax ParseElifDirective(SyntaxToken hash, SyntaxToken keyword, bool isActive, bool endIsActive)
        {
            var expr = this.ParseExpression();
            var eod  = this.ParseEndOfDirective(ignoreErrors: false);

            if (_context.HasPreviousIfOrElif())
            {
                var isTrue      = this.EvaluateBool(expr);
                var branchTaken = endIsActive && isTrue && !_context.PreviousBranchTaken();
                return(SyntaxFactory.ElifDirectiveTrivia(hash, keyword, expr, eod, endIsActive, branchTaken, isTrue));
            }
            else
            {
                eod = eod.TokenWithLeadingTrivia(SyntaxList.Concat(SyntaxFactory.DisabledText(expr.ToFullString()), eod.GetLeadingTrivia()));
                if (_context.HasUnfinishedRegion())
                {
                    return(this.AddError(SyntaxFactory.BadDirectiveTrivia(hash, keyword, eod, isActive), ErrorCode.ERR_EndRegionDirectiveExpected));
                }
                else if (_context.HasUnfinishedIf())
                {
                    return(this.AddError(SyntaxFactory.BadDirectiveTrivia(hash, keyword, eod, isActive), ErrorCode.ERR_EndifDirectiveExpected));
                }
                else
                {
                    return(this.AddError(SyntaxFactory.BadDirectiveTrivia(hash, keyword, eod, isActive), ErrorCode.ERR_UnexpectedDirective));
                }
            }
        }
            private SyntaxList <VB.Syntax.StatementSyntax> VisitComplexForStatement(CS.Syntax.ForStatementSyntax node)
            {
                // VB doesn't have a for loop.  So convert:
                //   for (declarations; condition; incrementors) body into:
                //
                // declarations
                // while (condition) {
                //   body;
                //   incrementors;
                // }

                VB.Syntax.WhileStatementSyntax begin;
                if (node.Condition == null)
                {
                    begin = VB.SyntaxFactory.WhileStatement(
                        condition: VB.SyntaxFactory.TrueLiteralExpression(VB.SyntaxFactory.Token(VB.SyntaxKind.TrueKeyword)));
                }
                else
                {
                    begin = VB.SyntaxFactory.WhileStatement(
                        condition: nodeVisitor.VisitExpression(node.Condition));
                }

                SyntaxList <VB.Syntax.StatementSyntax> initialBlock = Visit(node.Statement);

                List <VB.Syntax.StatementSyntax> whileStatements = initialBlock.Concat(
                    node.Incrementors.Select(nodeVisitor.VisitStatement)).ToList();
                SyntaxList <VB.Syntax.StatementSyntax> whileBody = List <VB.Syntax.StatementSyntax>(whileStatements);

                VB.Syntax.WhileBlockSyntax whileBlock = VB.SyntaxFactory.WhileBlock(
                    begin,
                    whileBody);

                List <VB.Syntax.StatementSyntax> statements = new List <VB.Syntax.StatementSyntax>();

                if (node.Declaration != null)
                {
                    statements.Add(nodeVisitor.Visit <VB.Syntax.StatementSyntax>(node.Declaration));
                }

                statements.Add(whileBlock);

                return(List <VB.Syntax.StatementSyntax>(statements));
            }
Exemplo n.º 3
0
        public static SyntaxToken AddNodesAsTrailingTrivia(this SyntaxToken token, params SyntaxNode[] nodes)
        {
            var trivia = nodes.ConvertToTriviaList();

            return(token.WithTrailingTrivia(SyntaxList.Concat(token.GetTrailingTrivia(), trivia)));
        }