public override SyntaxList <StatementSyntax> VisitForEachBlock(VBSyntax.ForEachBlockSyntax node) { var stmt = node.ForEachStatement; TypeSyntax type = null; SyntaxToken id; if (stmt.ControlVariable is VBSyntax.VariableDeclaratorSyntax) { var v = (VBSyntax.VariableDeclaratorSyntax)stmt.ControlVariable; var declaration = VisualBasicConverter.SplitVariableDeclarations(v, _nodesVisitor, _semanticModel).Values.Single(); type = declaration.Type; id = declaration.Variables[0].Identifier; } else { var v = (IdentifierNameSyntax)stmt.ControlVariable.Accept(_nodesVisitor); id = v.Identifier; type = SyntaxFactory.ParseTypeName("var"); } var block = SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))); return(SingleStatement(SyntaxFactory.ForEachStatement( type, id, (ExpressionSyntax)stmt.Expression.Accept(_nodesVisitor), block.UnpackNonNestedBlock() ))); }
public async Task <Document> SingleFirstPass(Document document) { var converted = await VisualBasicConverter.ConvertCompilationTree(document, _csharpViewOfVbSymbols, _csharpReferenceProject); var convertedDocument = _convertedCsProject.AddDocument(document.FilePath, converted); _convertedCsProject = convertedDocument.Project; return(convertedDocument); }
public SyntaxTree SingleFirstPass(Compilation sourceCompilation, SyntaxTree tree) { _sourceCompilation = sourceCompilation; var converted = VisualBasicConverter.ConvertCompilationTree((VisualBasicCompilation)sourceCompilation, (VisualBasicSyntaxTree)tree); var convertedTree = SyntaxFactory.SyntaxTree(converted); _firstPassResults.Add(convertedTree); return(convertedTree); }
public override SyntaxList <StatementSyntax> VisitLocalDeclarationStatement(VBSyntax.LocalDeclarationStatementSyntax node) { var modifiers = VisualBasicConverter.ConvertModifiers(node.Modifiers, TokenContext.Local); var declarations = new List <LocalDeclarationStatementSyntax>(); foreach (var declarator in node.Declarators) { foreach (var decl in VisualBasicConverter.SplitVariableDeclarations(declarator, _nodesVisitor, _semanticModel)) { declarations.Add(SyntaxFactory.LocalDeclarationStatement(modifiers, decl.Value)); } } return(SyntaxFactory.List <StatementSyntax>(declarations)); }
public override SyntaxList <StatementSyntax> VisitUsingBlock(VBSyntax.UsingBlockSyntax node) { var statementSyntax = SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))); if (node.UsingStatement.Expression == null) { StatementSyntax stmt = statementSyntax; foreach (var v in node.UsingStatement.Variables.Reverse()) { foreach (var declaration in VisualBasicConverter.SplitVariableDeclarations(v, _nodesVisitor, _semanticModel).Values.Reverse()) { stmt = SyntaxFactory.UsingStatement(declaration, null, stmt); } } return(SingleStatement(stmt)); } var expr = (ExpressionSyntax)node.UsingStatement.Expression.Accept(_nodesVisitor); var unpackPossiblyNestedBlock = statementSyntax.UnpackPossiblyNestedBlock(); // Allow reduced indentation for multiple usings in a row return(SingleStatement(SyntaxFactory.UsingStatement(null, expr, unpackPossiblyNestedBlock))); }
public override SyntaxList <StatementSyntax> VisitForBlock(VBSyntax.ForBlockSyntax node) { var stmt = node.ForStatement; ExpressionSyntax startValue = (ExpressionSyntax)stmt.FromValue.Accept(_nodesVisitor); VariableDeclarationSyntax declaration = null; ExpressionSyntax id; if (stmt.ControlVariable is VBSyntax.VariableDeclaratorSyntax) { var v = (VBSyntax.VariableDeclaratorSyntax)stmt.ControlVariable; declaration = VisualBasicConverter.SplitVariableDeclarations(v, _nodesVisitor, _semanticModel).Values.Single(); declaration = declaration.WithVariables(SyntaxFactory.SingletonSeparatedList(declaration.Variables[0].WithInitializer(SyntaxFactory.EqualsValueClause(startValue)))); id = SyntaxFactory.IdentifierName(declaration.Variables[0].Identifier); } else { id = (ExpressionSyntax)stmt.ControlVariable.Accept(_nodesVisitor); var symbol = _semanticModel.GetSymbolInfo(stmt.ControlVariable).Symbol; if (!_semanticModel.LookupSymbols(node.FullSpan.Start, name: symbol.Name).Any()) { var variableDeclaratorSyntax = SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(symbol.Name), null, SyntaxFactory.EqualsValueClause(startValue)); declaration = SyntaxFactory.VariableDeclaration( SyntaxFactory.IdentifierName("var"), SyntaxFactory.SingletonSeparatedList(variableDeclaratorSyntax)); } else { startValue = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, id, startValue); } } var step = (ExpressionSyntax)stmt.StepClause?.StepValue.Accept(_nodesVisitor); PrefixUnaryExpressionSyntax value = step.SkipParens() as PrefixUnaryExpressionSyntax; ExpressionSyntax condition; if (value == null) { condition = SyntaxFactory.BinaryExpression(SyntaxKind.LessThanOrEqualExpression, id, (ExpressionSyntax)stmt.ToValue.Accept(_nodesVisitor)); } else { condition = SyntaxFactory.BinaryExpression(SyntaxKind.GreaterThanOrEqualExpression, id, (ExpressionSyntax)stmt.ToValue.Accept(_nodesVisitor)); } if (step == null) { step = SyntaxFactory.PostfixUnaryExpression(SyntaxKind.PostIncrementExpression, id); } else { step = SyntaxFactory.AssignmentExpression(SyntaxKind.AddAssignmentExpression, id, step); } var block = SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))); return(SingleStatement(SyntaxFactory.ForStatement( declaration, declaration != null ? SyntaxFactory.SeparatedList <ExpressionSyntax>() : SyntaxFactory.SingletonSeparatedList(startValue), condition, SyntaxFactory.SingletonSeparatedList(step), block.UnpackNonNestedBlock()))); }
public async Task <SyntaxNode> SingleFirstPass(Document document) { return(await VisualBasicConverter.ConvertCompilationTree(document, _csharpViewOfVbSymbols, _csharpReferenceProject)); }
public async Task <SyntaxNode> SingleFirstPassAsync(Document document) { return(await VisualBasicConverter.ConvertCompilationTreeAsync(document, _csharpViewOfVbSymbols, _csharpReferenceProject, OptionalOperations, _typeToInheritors, _cancellationToken)); }