Exemplo n.º 1
0
        public Statement GetStatement()
        {
            var whenNotNull = statementInterpreterHandler.GetStatement(conditionalAccessExpressionSyntax.WhenNotNull);

            var condition = new BinaryStatement
            {
                Left    = statementInterpreterHandler.GetStatement(conditionalAccessExpressionSyntax.Expression),
                Right   = new ConstantStatement(null),
                Operand = BinaryOperand.NotEqual
            };

            //IsAssignment
            var parent = GetParent(conditionalAccessExpressionSyntax);

            if (parent is ArgumentSyntax ||
                parent is EqualsValueClauseSyntax)
            {
                return(new ConditionalStatement
                {
                    Condition = condition,
                    IfTrue = whenNotNull,
                    IfFalse = new ConstantStatement(null)
                });
            }

            return(new IfStatement
            {
                Condition = condition,
                IfTrue = whenNotNull
            });
        }
Exemplo n.º 2
0
        public Statement GetStatement()
        {
            var typeInfo = semanticModel.GetTypeInfo(objectCreationExpressionSyntax);

            var objectCreationStatement = new ObjectCreationStatement
            {
                Type = typeInfo.GetClassType()
            };

            if (objectCreationExpressionSyntax.Initializer != null)
            {
                objectCreationStatement.Initializer = new List <Statement>();

                foreach (var expression in objectCreationExpressionSyntax.Initializer.Expressions)
                {
                    var statement = statementInterpreterHandler.GetStatement(expression)
                    ;
                    objectCreationStatement.Initializer.Add(statement);
                }
            }

            if (objectCreationExpressionSyntax.ArgumentList?.Arguments != null)
            {
                var arguments = new List <Statement>();

                foreach (var argumentSyntax in objectCreationExpressionSyntax.ArgumentList.Arguments)
                {
                    arguments.Add(statementInterpreterHandler.GetStatement(argumentSyntax));
                }

                objectCreationStatement.ArgumentList = arguments;
            }

            return(objectCreationStatement);
        }
        public Statement GetStatement()
        {
            var block        = new Block();
            var initializers = new List <Statement>();

            if (forStatementSyntax.Declaration != null)
            {
                var declaration = statementInterpreterHandler.GetStatement(forStatementSyntax.Declaration) as MultiStatement;
                foreach (var declarationStatement in declaration.Statements)
                {
                    if (declarationStatement is LocalVariableDeclaration)
                    {
                        block.Statements.Add(declarationStatement);
                    }
                    else
                    {
                        initializers.Add(declarationStatement);
                    }
                }
            }
            initializers.AddRange(forStatementSyntax.Initializers.Select(x => statementInterpreterHandler.GetStatement(x)).ToList());
            var condition    = forStatementSyntax.Condition == null ? null : statementInterpreterHandler.GetStatement(forStatementSyntax.Condition);
            var iterators    = forStatementSyntax.Incrementors.Select(x => statementInterpreterHandler.GetStatement(x)).ToList();
            var statement    = statementInterpreterHandler.GetStatement(forStatementSyntax.Statement);
            var forStatement = new ForStatement
            {
                Initializers = initializers,
                Condition    = condition,
                Iterators    = iterators,
                Statement    = statement
            };

            block.Statements.Add(forStatement);
            return(block);
        }
Exemplo n.º 4
0
        public Statement GetStatement()
        {
            if (binaryExpressionSyntax.Kind() == SyntaxKind.IsExpression)
            {
                var statement  = statementInterpreterHandler.GetStatement(binaryExpressionSyntax.Left);
                var typeSymbol = (INamedTypeSymbol)semanticModel.GetSymbolInfo(binaryExpressionSyntax.Right).Symbol;
                return(new IsTypeStatement
                {
                    Statement = statement,
                    Type = typeSymbol.GetClassType()
                });
            }
            else if (binaryExpressionSyntax.Kind() == SyntaxKind.AsExpression)
            {
                var statement  = statementInterpreterHandler.GetStatement(binaryExpressionSyntax.Left);
                var typeSymbol = (INamedTypeSymbol)semanticModel.GetSymbolInfo(binaryExpressionSyntax.Right).Symbol;
                return(new AsStatement
                {
                    Statement = statement,
                    Type = typeSymbol.GetClassType()
                });
            }

            var binaryStatement = new BinaryStatement();

            binaryStatement.Left  = statementInterpreterHandler.GetStatement(binaryExpressionSyntax.Left);
            binaryStatement.Right = statementInterpreterHandler.GetStatement(binaryExpressionSyntax.Right);

            binaryStatement.Operand = GetOperand(binaryExpressionSyntax.Kind());
            return(binaryStatement);
        }
 public Statement GetStatement()
 {
     return(new ConditionalStatement
     {
         Condition = statementInterpreterHandler.GetStatement(conditionalExpressionSyntax.Condition),
         IfTrue = statementInterpreterHandler.GetStatement(conditionalExpressionSyntax.WhenTrue),
         IfFalse = statementInterpreterHandler.GetStatement(conditionalExpressionSyntax.WhenFalse),
     });
 }
 public Statement GetStatement()
 {
     return(new IfStatement
     {
         Condition = statementInterpreterHandler.GetStatement(ifStatementSyntax.Condition),
         IfTrue = statementInterpreterHandler.GetStatement(ifStatementSyntax.Statement),
         IfFalse = ifStatementSyntax.Else != null?statementInterpreterHandler.GetStatement(ifStatementSyntax.Else) : null,
     });
 }
Exemplo n.º 7
0
        public Statement GetStatement()
        {
            var method = statementInterpreterHandler.GetStatement(ies.Expression);

            if (method is NameOfStatement)
            {
                //nameof()
                var arguments1 = ies.ArgumentList.Arguments.Select(x => statementInterpreterHandler.GetStatement(x));
                return(new ConstantStatement(arguments1.Cast <IdentifierStatement>().First().Name));
            }

            var invocationStatement = new InvocationStatement();

            var methodSymbolInfo = semanticModel.GetSymbolInfo(ies.Expression);

            var arguments = new List <Statement>();

            if (methodSymbolInfo.Symbol is IMethodSymbol methodSymbol)
            {
                for (int i = 0; i < methodSymbol.Parameters.Length; i++)
                {
                    var parameter = methodSymbol.Parameters[i];
                    if (!parameter.IsOptional)
                    {
                        arguments.Add(statementInterpreterHandler.GetStatement(ies.ArgumentList.Arguments[i]));
                    }
                    else
                    {
                        var argumentSyntax = ies.ArgumentList.Arguments.FirstOrDefault(x => x.NameColon != null && x.NameColon.Name.Identifier.ValueText == parameter.Name);
                        if (argumentSyntax == null)
                        {
                            if (ies.ArgumentList.Arguments.Count <= i)
                            {
                                //use default value
                                arguments.Add(new ConstantStatement(parameter.ExplicitDefaultValue));
                            }
                            else
                            {
                                arguments.Add(statementInterpreterHandler.GetStatement(ies.ArgumentList.Arguments[i]));
                            }
                        }
                        else
                        {
                            arguments.Add(statementInterpreterHandler.GetStatement(argumentSyntax));
                        }
                    }
                }
                invocationStatement.ParametersSignature = methodSymbol.Parameters.Select(x => x.Type.GetClassType()).ToArray();
            }

            invocationStatement.Method = method as MethodMemberStatement;
            invocationStatement.Arguments.AddRange(arguments);

            return(invocationStatement);
        }
        public Statement GetStatement()
        {
            var condition = statementInterpreterHandler.GetStatement(whileStatementSyntax.Condition);
            var statement = statementInterpreterHandler.GetStatement(whileStatementSyntax.Statement);

            return(new WhileStatement
            {
                Conditional = condition,
                Statement = statement
            });
        }
Exemplo n.º 9
0
        public Statement GetStatement()
        {
            var switchStatement = new SwitchStatement();

            switchStatement.SwitchValue = statementInterpreterHandler.GetStatement(switchStatementSyntax.Expression);

            var switchCases = new List <SwitchCase>();

            foreach (var section in switchStatementSyntax.Sections)
            {
                var block = new Block();

                foreach (var statementSyntax in section.Statements)
                {
                    if (statementSyntax is BreakStatementSyntax)
                    {
                        continue;
                    }

                    var statement = statementInterpreterHandler.GetStatement(statementSyntax);
                    if (statement is MultiStatement multiStatement)
                    {
                        block.Statements.AddRange(multiStatement.Statements);
                    }
                    else
                    {
                        block.Statements.Add(statement);
                    }
                }

                if (section.Labels.Count == 1 && section.Labels.Single() is DefaultSwitchLabelSyntax defaultSwitch)
                {
                    switchStatement.Default = block;
                }
                else
                {
                    var switchCase = new SwitchCase();

                    switchCase.Tests = section.Labels.Cast <CaseSwitchLabelSyntax>()
                                       .Select(x => statementInterpreterHandler.GetStatement(x.Value)).ToArray();

                    switchCase.Body = block;

                    switchCases.Add(switchCase);
                }
            }

            switchStatement.Cases = switchCases.ToArray();

            return(switchStatement);
        }
        public Statement GetStatement()
        {
            var assignmentStatement = new BinaryStatement();

            assignmentStatement.Left = statementInterpreterHandler.GetStatement(assignmentExpressionSyntax.Left)
            ;

            assignmentStatement.Right = statementInterpreterHandler
                                        .GetStatement(assignmentExpressionSyntax.Right);

            assignmentStatement.Operand = GetOperand(assignmentExpressionSyntax.Kind());

            return(assignmentStatement);
        }
        public Statement GetStatement()
        {
            var tryStatement = new TryStatement();

            tryStatement.TryBlock = statementInterpreterHandler.GetStatement(tryStatementSyntax.Block);

            tryStatement.Catches.AddRange(tryStatementSyntax.Catches.Select(x =>
                                                                            statementInterpreterHandler.GetStatement(x)).Cast <CatchStatement>());

            tryStatement.Finally = tryStatementSyntax.Finally == null ?
                                   null : statementInterpreterHandler.GetStatement(tryStatementSyntax.Finally);

            return(tryStatement);
        }
Exemplo n.º 12
0
        public Statement GetStatement()
        {
            var statement = statementInterpreterHandler.GetStatement(patternExpressionSyntax.Expression);

            if (patternExpressionSyntax.Pattern is ConstantPatternSyntax constantPatternSyntax)
            {
                return(new ObjectEqualStatement
                {
                    Left = statement,
                    Right = statementInterpreterHandler.GetStatement(constantPatternSyntax.Expression)
                });
            }

            return(null);
        }
Exemplo n.º 13
0
        public Statement GetStatement()
        {
            var retVal           = new List <Statement>();
            var variableTypeInfo = semanticModel.GetTypeInfo(variableDeclarationSyntax.Type);
            var type             = variableTypeInfo.GetClassType();

            foreach (var variable in variableDeclarationSyntax.Variables)
            {
                if (variable.IsMissing)
                {
                    continue;
                }
                var localdeclaration = new LocalVariableDeclaration();

                localdeclaration.Name = variable.Identifier.ValueText;
                localdeclaration.Type = type;

                scopedLocalVariableDeclarations.Add(localdeclaration);
                retVal.Add(localdeclaration);

                //assignment
                if (variable.Initializer != null)
                {
                    var statement = statementInterpreterHandler.GetStatement(variable.Initializer);

                    retVal.Add(statement);
                }
            }

            return(new MultiStatement
            {
                Statements = retVal
            });
        }
        public Statement GetStatement()
        {
            var conditionalAccess = GetConditionalAccessExpressionSyntax(memberBindingExpression);
            var parent            = statementInterpreterHandler.GetStatement(conditionalAccess.Expression);

            return(statementInterpreterHandler.GetStatementInterpreter(memberBindingExpression.Name, parent));
        }
Exemplo n.º 15
0
        public Statement GetStatement()
        {
            var statement = new UnaryStatement
            {
                Operand = statementInterpreterHandler.GetStatement(prefixUnaryExpressionSyntax.Operand)
            };

            switch (prefixUnaryExpressionSyntax.Kind())
            {
            case Microsoft.CodeAnalysis.CSharp.SyntaxKind.PreDecrementExpression:
                statement.Operator = UnaryOperand.PreDecrementAssign;
                break;

            case Microsoft.CodeAnalysis.CSharp.SyntaxKind.PreIncrementExpression:
                statement.Operator = UnaryOperand.PreIncrementAssign;
                break;

            case Microsoft.CodeAnalysis.CSharp.SyntaxKind.LogicalNotExpression:
                statement.Operator = UnaryOperand.Not;
                break;

            case Microsoft.CodeAnalysis.CSharp.SyntaxKind.BitwiseNotExpression:
                statement.Operator = UnaryOperand.OnesComplement;
                break;

            default:
                throw new NotSupportedException(prefixUnaryExpressionSyntax.Kind() + " is not supported unary operation");
            }
            return(statement);
        }
Exemplo n.º 16
0
 public Statement GetStatement()
 {
     return(new ThrowStatement
     {
         Statement = statementInterpreterHandler.GetStatement(throwStatementSyntax.Expression)
     });
 }
        public Statement GetStatement()
        {
            var awaitStatement = new AwaitStatement();

            awaitStatement.Statement = statementInterpreterHandler.GetStatement(awaitExpressionSyntax.Expression);
            return(awaitStatement);
        }
Exemplo n.º 18
0
        public Statement GetStatement()
        {
            var lamdaStatement = new LamdaStatement();

            var parameters = anonymousMethodExpressionSyntax.ParameterList?.Parameters
                             .Select(x => statementInterpreterHandler.GetStatement(x));

            lamdaStatement.Parameters = parameters?.Cast <Parameter>()?.ToArray() ?? new Parameter[0];

            lamdaStatement.Body = statementInterpreterHandler.GetStatement(anonymousMethodExpressionSyntax.Body);

            var typeInfo = semanticModel.GetTypeInfo(anonymousMethodExpressionSyntax);

            lamdaStatement.Type = typeInfo.ConvertedType.GetClassType();

            return(lamdaStatement);
        }
Exemplo n.º 19
0
        public Statement GetStatement()
        {
            var parent = statementInterpreterHandler.GetStatement(memberAccessExpressionSyntax.Expression)
            ;

            return(statementInterpreterHandler.GetStatementInterpreter(memberAccessExpressionSyntax.Name, parent)
                   );
        }
Exemplo n.º 20
0
        public Statement GetStatement()
        {
            var lamdaStatement = new LamdaStatement();

            var parameters = parenthesizedLambdaExpressionSyntax.ParameterList.Parameters
                             .Select(x => statementInterpreterHandler.GetStatement(x));

            lamdaStatement.Parameters = parameters.Cast <Parameter>().ToArray();

            lamdaStatement.Body = statementInterpreterHandler.GetStatement(parenthesizedLambdaExpressionSyntax.Body);

            var typeInfo = semanticModel.GetTypeInfo(parenthesizedLambdaExpressionSyntax);

            lamdaStatement.Type = typeInfo.ConvertedType.GetClassType();

            lamdaStatement.IsAsync = parenthesizedLambdaExpressionSyntax.AsyncKeyword.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.AsyncKeyword);

            return(lamdaStatement);
        }
Exemplo n.º 21
0
        public Statement GetStatement()
        {
            var statement = new CastStatement
            {
                Statement = statementInterpreterHandler.GetStatement(castExpressionSyntax.Expression)
            };

            statement.Type = castExpressionSyntax.Type.GetClassType(semanticModel);

            return(statement);
        }
        public Statement GetStatement()
        {
            var statement = new ElementAccessStatement();

            statement.Type  = GetClassType();
            statement.Array = statementInterpreterHandler.GetStatement(elementAccessExpressionSyntax.Expression);

            statement.Indexes = elementAccessExpressionSyntax.ArgumentList.Arguments.Select(x => statementInterpreterHandler.GetStatement(x)).ToList();

            return(statement);
        }
        public Statement GetStatement()
        {
            if (arrayCreationExpressionSyntax.Initializer == null)
            {
                var statement = new ArrayCreationStatement();
                statement.Type   = arrayCreationExpressionSyntax.Type.ElementType.GetClassType(semanticModel);
                statement.Bounds = new System.Collections.Generic.List <Statement>();
                foreach (var rank in arrayCreationExpressionSyntax.Type.RankSpecifiers)
                {
                    foreach (var size in rank.Sizes)
                    {
                        statement.Bounds.Add(statementInterpreterHandler.GetStatement(size));
                    }
                }

                return(statement);
            }

            return(statementInterpreterHandler.GetStatement(arrayCreationExpressionSyntax.Initializer)
                   );
        }
        public Statement GetStatement()
        {
            var parameterType = semanticModel.GetTypeInfo(forEachStatementSyntax.Type).GetClassType();

            var parameter = new LocalVariableDeclaration
            {
                Type = parameterType,
                Name = forEachStatementSyntax.Identifier.ValueText
            };

            var collection = statementInterpreterHandler.GetStatement(forEachStatementSyntax.Expression);

            var body = statementInterpreterHandler.GetStatement(forEachStatementSyntax.Statement);

            return(new ForEachStatement
            {
                Variable = parameter,
                Collection = collection,
                Body = body
            });
        }
Exemplo n.º 25
0
        private Statement GetStatement(InterpolatedStringContentSyntax interpolatedStringContentSyntax)
        {
            if (interpolatedStringContentSyntax is InterpolationSyntax interpolationSyntax)
            {
                return(statementInterpreterHandler.GetStatement(interpolationSyntax.Expression));
            }
            else
            {
                var stringTextSyntax = (InterpolatedStringTextSyntax)interpolatedStringContentSyntax;

                return(new ConstantStatement(stringTextSyntax.TextToken.Text));
            }
        }
Exemplo n.º 26
0
        public Statement GetStatement()
        {
            var catchStatement = new CatchStatement();

            catchStatement.Block  = statementInterpreterHandler.GetStatement(catchClauseSyntax.Block);
            catchStatement.Filter = catchClauseSyntax.Filter == null ?
                                    null : statementInterpreterHandler.GetStatement(catchClauseSyntax.Filter.FilterExpression);

            if (catchClauseSyntax.Declaration != null)
            {
                catchStatement.Type = semanticModel.GetTypeInfo(catchClauseSyntax.Declaration.Type).GetClassType();

                if (!catchClauseSyntax.Declaration.Identifier.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.None))
                {
                    catchStatement.Variable = new LocalVariableDeclaration
                    {
                        Type = catchStatement.Type,
                        Name = catchClauseSyntax.Declaration.Identifier.ValueText
                    };
                }
            }
            return(catchStatement);
        }
        public Statement GetStatement()
        {
            Statement variable = null;
            Statement resource = null;

            if (usingStatementSyntax.Declaration != null)
            {
                var declaration = statementInterpreterHandler.GetStatement(usingStatementSyntax.Declaration) as MultiStatement;
                variable = declaration.Statements.FirstOrDefault(x => x is LocalVariableDeclaration);
                resource = (declaration.Statements.FirstOrDefault(x => x is BinaryStatement) as BinaryStatement).Right;
            }
            else
            {
                resource = statementInterpreterHandler.GetStatement(usingStatementSyntax.Expression);
            }
            var body = statementInterpreterHandler.GetStatement(usingStatementSyntax.Statement);

            return(new UsingStatement
            {
                Resource = resource,
                Body = body,
                Variable = variable
            });
        }
Exemplo n.º 28
0
        public Statement GetStatement()
        {
            var conditionalAccess = GetConditionalAccessExpressionSyntax(elementBindingExpression);

            elementAccessExpression = conditionalAccess.Expression;

            var statement = new ElementAccessStatement();

            statement.Type  = GetClassType();
            statement.Array = statementInterpreterHandler.GetStatement(elementAccessExpression);

            statement.Indexes = elementBindingExpression.ArgumentList.Arguments.Select(x => statementInterpreterHandler.GetStatement(x)).ToList();

            return(statement);
        }
Exemplo n.º 29
0
        public Statement GetStatement()
        {
            var kind = initializerExpressionSyntax.Kind();

            if (kind == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ArrayInitializerExpression)
            {
                var statement = new ArrayCreationStatement();
                statement.Type = GetTypeSyntax(initializerExpressionSyntax);

                statement.Bounds = new List <Statement>();
                statement.Bounds.Add(new ConstantStatement(initializerExpressionSyntax.Expressions.Count));
                statement.Initializers = new List <Statement>();
                bool getInnerArrayLength = false;
                foreach (var expression in initializerExpressionSyntax.Expressions)
                {
                    var innerStatement = statementInterpreterHandler.GetStatement(expression);

                    if (innerStatement is ArrayCreationStatement arrayCreationStatement)
                    {
                        if (!getInnerArrayLength)
                        {
                            statement.Bounds.AddRange(
                                arrayCreationStatement.Bounds.Select(x => x));
                            getInnerArrayLength = true;
                        }
                        statement.Initializers.AddRange(
                            arrayCreationStatement.Initializers.Select(x => x));
                    }
                    else
                    {
                        statement.Initializers.Add(innerStatement);
                    }
                }
                return(statement);
            }
            else
            {
                var statement = new InitializerStatement();
                statement.Statements = initializerExpressionSyntax.Expressions.Select(x =>
                                                                                      statementInterpreterHandler.GetStatement(x)).ToList();

                return(statement);
            }
        }
Exemplo n.º 30
0
        public Statement GetStatement()
        {
            var block = new Block();

            foreach (var statementSyntax in blockSyntax.Statements)
            {
                var statement = statementInterpreterHandler.GetStatement(statementSyntax);
                if (statement is MultiStatement multiStatement)
                {
                    block.Statements.AddRange(multiStatement.Statements);
                }
                else
                {
                    block.Statements.Add(statement);
                }
            }

            return(block);
        }