Example #1
0
        private async Task <T> ConvertHandled <T>(SyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CS.CSharpSyntaxNode
        {
            try {
                var converted = (T)await _wrappedVisitor.Visit(vbNode);

                return(sourceTriviaMap == SourceTriviaMapKind.None || _syntaxTree != vbNode.SyntaxTree
                    ? converted.WithoutSourceMapping()
                    : sourceTriviaMap == SourceTriviaMapKind.SubNodesOnly
                        ? converted
                        : WithSourceMapping(vbNode, converted));
            } catch (Exception e) {
                var dummyStatement = (T)(object)CS.SyntaxFactory.EmptyStatement();
                return(dummyStatement.WithCsTrailingErrorComment((VBasic.VisualBasicSyntaxNode)vbNode, e));
            }
        }
Example #2
0
    private async Task <SyntaxList <StatementSyntax> > AddLocalVariablesAsync(VBasic.VisualBasicSyntaxNode node, VBasic.SyntaxKind exitableType = default, bool isBreakableInCs = false)
    {
        _additionalLocals.PushScope(exitableType, isBreakableInCs);
        try {
            var convertedStatements = await _wrappedVisitor.Visit(node);

            var withLocals = await _additionalLocals.CreateLocalsAsync(node, convertedStatements, _generatedNames, _semanticModel);

            var allStatements = _additionalLocals.CreateStatements(node, withLocals, _generatedNames, _semanticModel);

            if (isBreakableInCs && exitableType == VBasic.SyntaxKind.TryKeyword)
            {
                var doOnce = SyntaxFactory.DoStatement(SyntaxFactory.Block(allStatements), CommonConversions.Literal(false));
                allStatements = SyntaxFactory.SingletonList <StatementSyntax>(doOnce);
            }
            return(allStatements);
        } finally {
            _additionalLocals.PopScope();
        }
    }
        private async Task <T> ConvertHandledAsync <T>(SyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CS.CSharpSyntaxNode
        {
            try {
                var converted = (T)await _wrappedVisitor.Visit(vbNode);

                return(sourceTriviaMap == SourceTriviaMapKind.None || _syntaxTree != vbNode.SyntaxTree
                    ? converted.WithoutSourceMapping()
                    : sourceTriviaMap == SourceTriviaMapKind.SubNodesOnly
                        ? converted
                        : WithSourceMapping(vbNode, converted));
            } catch (Exception e) when(typeof(T).IsAssignableFrom(typeof(CSSyntax.EmptyStatementSyntax)))
            {
                var dummyStatement = (T)(object)CS.SyntaxFactory.EmptyStatement();

                return(dummyStatement.WithCsTrailingErrorComment((VBasic.VisualBasicSyntaxNode)vbNode, e));
            } catch (Exception e) when(!(e is ExceptionWithNodeInformation))
            {
                throw e.WithNodeInformation(vbNode);
            }
        }
Example #4
0
    private async Task <T> ConvertHandledAsync <T>(VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CSharpSyntaxNode
    {
        try {
            var converted = (T)await _wrappedVisitor.Visit(vbNode);

            return(sourceTriviaMap == SourceTriviaMapKind.None || _syntaxTree != vbNode.SyntaxTree
                ? converted.WithoutSourceMapping()
                : sourceTriviaMap == SourceTriviaMapKind.SubNodesOnly
                    ? converted
                    : WithSourceMapping(vbNode, converted));
        } catch (Exception e) when(_dummyLiteral is T dummy)
        {
            return(dummy.WithCsTrailingErrorComment(vbNode, e));
        } catch (Exception e) when(_dummyStatement is T dummy)
        {
            return(dummy.WithCsTrailingErrorComment(vbNode, e));
        } catch (Exception e) when(_dummyCompilationUnit is T dummy)
        {
            return(dummy.WithCsTrailingErrorComment(vbNode, e));
        } catch (Exception e) when(!(e is ExceptionWithNodeInformation))
        {
            throw e.WithNodeInformation(vbNode);
        }
    }