private static bool TryGetNodeForeSingleLineLambdaExpression(SyntaxKind kind, StatementSyntax statement, out VisualBasicSyntaxNode singleNode)
        {
            switch (kind)
            {
            case SyntaxKind.SingleLineSubLambdaExpression when statement.DescendantNodesAndSelf().OfType <StatementSyntax>().Count() == 1:
                singleNode = statement;

                return(true);

            case SyntaxKind.SingleLineFunctionLambdaExpression when UnpackExpressionFromStatement(statement, out var expression):
                singleNode = expression;

                return(true);

            default:
                singleNode = null;
                return(false);
            }
        }
예제 #2
0
        private static bool TryGetNodeForeSingleLineLambdaExpression(SyntaxKind kind,
                                                                     SyntaxList <StatementSyntax> statements, out VisualBasicSyntaxNode singleNode)
        {
            switch (kind)
            {
            case SyntaxKind.SingleLineSubLambdaExpression:
                singleNode = statements[0];
                return(true);

            case SyntaxKind.SingleLineFunctionLambdaExpression when UnpackExpressionFromStatement(statements[0], out var expression):
                singleNode = expression;

                return(true);

            default:
                singleNode = null;
                return(false);
            }
        }
 public static bool IsKind(this SyntaxToken token, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind1, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind2, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind3)
 {
     return(VisualBasicExtensions.Kind(token) == kind1 ||
            VisualBasicExtensions.Kind(token) == kind2 ||
            VisualBasicExtensions.Kind(token) == kind3);
 }
 public static bool HasMatchingText(this SyntaxToken token, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind)
 {
     return(token.ToString() == VBasic.SyntaxFacts.GetText(kind));
 }
 public static bool IsKindOrHasMatchingText(this SyntaxToken token, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind)
 {
     return(VisualBasicExtensions.Kind(token) == kind || token.HasMatchingText(kind));
 }
예제 #6
0
        private static LambdaHeaderSyntax CreateFunctionHeader(SyntaxTokenList modifiers, ParameterListSyntax parameterList,
                                                               out EndBlockStatementSyntax endBlock, out SyntaxKind multiLineExpressionKind)
        {
            LambdaHeaderSyntax header;

            header = SyntaxFactory.FunctionLambdaHeader(SyntaxFactory.List <AttributeListSyntax>(),
                                                        ConvertModifiers(modifiers, SyntaxKindExtensions.TokenContext.Local), parameterList, null);
            endBlock = SyntaxFactory.EndBlockStatement(SyntaxKind.EndFunctionStatement,
                                                       SyntaxFactory.Token(SyntaxKind.FunctionKeyword));
            multiLineExpressionKind = SyntaxKind.MultiLineFunctionLambdaExpression;
            return(header);
        }
예제 #7
0
 public KeywordPair(CS.SyntaxKind cs, VB.SyntaxKind vb, System.AttributeTargets target = AttributeTargets.All)
 {
     CS = cs;
     VB = vb;
     Targets = target;
 }
예제 #8
0
        static SyntaxKind ConvertToken(VBasic.SyntaxKind t, TokenContext context = TokenContext.Global)
        {
            switch (t)
            {
            case VBasic.SyntaxKind.None:
                return(SyntaxKind.None);

            // built-in types
            case VBasic.SyntaxKind.BooleanKeyword:
                return(SyntaxKind.BoolKeyword);

            case VBasic.SyntaxKind.ByteKeyword:
                return(SyntaxKind.ByteKeyword);

            case VBasic.SyntaxKind.SByteKeyword:
                return(SyntaxKind.SByteKeyword);

            case VBasic.SyntaxKind.ShortKeyword:
                return(SyntaxKind.ShortKeyword);

            case VBasic.SyntaxKind.UShortKeyword:
                return(SyntaxKind.UShortKeyword);

            case VBasic.SyntaxKind.IntegerKeyword:
                return(SyntaxKind.IntKeyword);

            case VBasic.SyntaxKind.UIntegerKeyword:
                return(SyntaxKind.UIntKeyword);

            case VBasic.SyntaxKind.LongKeyword:
                return(SyntaxKind.LongKeyword);

            case VBasic.SyntaxKind.ULongKeyword:
                return(SyntaxKind.ULongKeyword);

            case VBasic.SyntaxKind.DoubleKeyword:
                return(SyntaxKind.DoubleKeyword);

            case VBasic.SyntaxKind.SingleKeyword:
                return(SyntaxKind.FloatKeyword);

            case VBasic.SyntaxKind.DecimalKeyword:
                return(SyntaxKind.DecimalKeyword);

            case VBasic.SyntaxKind.StringKeyword:
                return(SyntaxKind.StringKeyword);

            case VBasic.SyntaxKind.CharKeyword:
                return(SyntaxKind.CharKeyword);

            case VBasic.SyntaxKind.ObjectKeyword:
                return(SyntaxKind.ObjectKeyword);

            // literals
            case VBasic.SyntaxKind.NothingKeyword:
                return(SyntaxKind.NullKeyword);

            case VBasic.SyntaxKind.TrueKeyword:
                return(SyntaxKind.TrueKeyword);

            case VBasic.SyntaxKind.FalseKeyword:
                return(SyntaxKind.FalseKeyword);

            case VBasic.SyntaxKind.MeKeyword:
                return(SyntaxKind.ThisKeyword);

            case VBasic.SyntaxKind.MyBaseKeyword:
                return(SyntaxKind.BaseKeyword);

            // modifiers
            case VBasic.SyntaxKind.PublicKeyword:
                return(SyntaxKind.PublicKeyword);

            case VBasic.SyntaxKind.FriendKeyword:
                return(SyntaxKind.InternalKeyword);

            case VBasic.SyntaxKind.ProtectedKeyword:
                return(SyntaxKind.ProtectedKeyword);

            case VBasic.SyntaxKind.PrivateKeyword:
                return(SyntaxKind.PrivateKeyword);

            case VBasic.SyntaxKind.ByRefKeyword:
                return(SyntaxKind.RefKeyword);

            case VBasic.SyntaxKind.ParamArrayKeyword:
                return(SyntaxKind.ParamsKeyword);

            case VBasic.SyntaxKind.ReadOnlyKeyword:
                return(SyntaxKind.ReadOnlyKeyword);

            case VBasic.SyntaxKind.OverridesKeyword:
                return(SyntaxKind.OverrideKeyword);

            case VBasic.SyntaxKind.SharedKeyword:
                return(SyntaxKind.StaticKeyword);

            case VBasic.SyntaxKind.ConstKeyword:
                return(SyntaxKind.ConstKeyword);

            case VBasic.SyntaxKind.PartialKeyword:
                return(SyntaxKind.PartialKeyword);

            // unary operators
            case VBasic.SyntaxKind.UnaryMinusExpression:
                return(SyntaxKind.UnaryMinusExpression);

            case VBasic.SyntaxKind.UnaryPlusExpression:
                return(SyntaxKind.UnaryPlusExpression);

            case VBasic.SyntaxKind.NotExpression:
                return(SyntaxKind.LogicalNotExpression);

            // binary operators
            case VBasic.SyntaxKind.ConcatenateExpression:
            case VBasic.SyntaxKind.AddExpression:
                return(SyntaxKind.AddExpression);

            case VBasic.SyntaxKind.SubtractExpression:
                return(SyntaxKind.SubtractExpression);

            case VBasic.SyntaxKind.MultiplyExpression:
                return(SyntaxKind.MultiplyExpression);

            case VBasic.SyntaxKind.DivideExpression:
                return(SyntaxKind.DivideExpression);

            case VBasic.SyntaxKind.AndAlsoExpression:
                return(SyntaxKind.LogicalAndExpression);

            case VBasic.SyntaxKind.OrElseExpression:
                return(SyntaxKind.LogicalOrExpression);

            case VBasic.SyntaxKind.OrExpression:
                return(SyntaxKind.BitwiseOrExpression);

            case VBasic.SyntaxKind.AndExpression:
                return(SyntaxKind.BitwiseAndExpression);

            case VBasic.SyntaxKind.ExclusiveOrExpression:
                return(SyntaxKind.ExclusiveOrExpression);

            case VBasic.SyntaxKind.EqualsExpression:
                return(SyntaxKind.EqualsExpression);

            case VBasic.SyntaxKind.NotEqualsExpression:
                return(SyntaxKind.NotEqualsExpression);

            case VBasic.SyntaxKind.GreaterThanExpression:
                return(SyntaxKind.GreaterThanExpression);

            case VBasic.SyntaxKind.GreaterThanOrEqualExpression:
                return(SyntaxKind.GreaterThanOrEqualExpression);

            case VBasic.SyntaxKind.LessThanExpression:
                return(SyntaxKind.LessThanExpression);

            case VBasic.SyntaxKind.LessThanOrEqualExpression:
                return(SyntaxKind.LessThanOrEqualExpression);

            // assignment
            case VBasic.SyntaxKind.SimpleAssignmentStatement:
                return(SyntaxKind.SimpleAssignmentExpression);

            case VBasic.SyntaxKind.AddAssignmentStatement:
                return(SyntaxKind.AddAssignmentExpression);

            case VBasic.SyntaxKind.SubtractAssignmentStatement:
                return(SyntaxKind.SubtractAssignmentExpression);

            case VBasic.SyntaxKind.MultiplyAssignmentStatement:
                return(SyntaxKind.MultiplyAssignmentExpression);

            case VBasic.SyntaxKind.DivideAssignmentStatement:
                return(SyntaxKind.DivideAssignmentExpression);

            // Casts
            case VBasic.SyntaxKind.CObjKeyword:
                return(SyntaxKind.ObjectKeyword);

            case VBasic.SyntaxKind.CBoolKeyword:
                return(SyntaxKind.BoolKeyword);

            case VBasic.SyntaxKind.CCharKeyword:
                return(SyntaxKind.CharKeyword);

            case VBasic.SyntaxKind.CSByteKeyword:
                return(SyntaxKind.SByteKeyword);

            case VBasic.SyntaxKind.CByteKeyword:
                return(SyntaxKind.ByteKeyword);

            case VBasic.SyntaxKind.CShortKeyword:
                return(SyntaxKind.ShortKeyword);

            case VBasic.SyntaxKind.CUShortKeyword:
                return(SyntaxKind.UShortKeyword);

            case VBasic.SyntaxKind.CIntKeyword:
                return(SyntaxKind.IntKeyword);

            case VBasic.SyntaxKind.CUIntKeyword:
                return(SyntaxKind.UIntKeyword);

            case VBasic.SyntaxKind.CLngKeyword:
                return(SyntaxKind.LongKeyword);

            case VBasic.SyntaxKind.CULngKeyword:
                return(SyntaxKind.ULongKeyword);

            case VBasic.SyntaxKind.CDecKeyword:
                return(SyntaxKind.DecimalKeyword);

            case VBasic.SyntaxKind.CSngKeyword:
                return(SyntaxKind.FloatKeyword);

            case VBasic.SyntaxKind.CDblKeyword:
                return(SyntaxKind.DoubleKeyword);

            case VBasic.SyntaxKind.CStrKeyword:
                return(SyntaxKind.StringKeyword);

            //
            case VBasic.SyntaxKind.AssemblyKeyword:
                return(SyntaxKind.AssemblyKeyword);
            }
            throw new NotSupportedException(t + " not supported!");
        }
 public static bool HasModifier(this VBSyntax.MethodBaseSyntax d, VBasic.SyntaxKind modifierKind)
 {
     return(d.Modifiers.Any(m => SyntaxTokenExtensions.IsKind(m, modifierKind)));
 }
예제 #10
0
 public static bool IsParentKind(this SyntaxNode node, VBasic.SyntaxKind kind)
 {
     return(node?.Parent.IsKind(kind) == true);
 }
예제 #11
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();
            }
        }
예제 #12
0
        public static bool MatchesKind(this SyntaxTrivia trivia, VBasic.SyntaxKind kind1, VBasic.SyntaxKind kind2)
        {
            var triviaKind = VBasic.VisualBasicExtensions.Kind(trivia);

            return(triviaKind == kind1 || triviaKind == kind2);
        }
예제 #13
0
 public static bool MatchesKind(this SyntaxTrivia trivia, VBasic.SyntaxKind kind)
 {
     return(VBasic.VisualBasicExtensions.Kind(trivia) == kind);
 }
예제 #14
0
 public record ScopeState(List <IHoistedNode> HoistedNodes, VBasic.SyntaxKind ExitableKind, bool IsBreakableInCs = false)
 {
예제 #15
0
 public BreakPair(CS.SyntaxKind cs, VB.SyntaxKind vb, VB.SyntaxKind exitTargetKeyword, System.AttributeTargets target = AttributeTargets.All)
     : base(cs, vb, target)
 {
     this.ExitTargetKeyword = exitTargetKeyword;
 }