示例#1
0
        private static void ProcessVariableDeclarationSyntax(VariableDeclarationSyntax variableDeclarationSyntax,
                                                             SimpleCompoundStatement wandaBlock)
        {
            foreach (var variableDeclaratorSyntax in variableDeclarationSyntax.Variables)
            {
                var variable = new Variable
                {
                    TypeRef = ResolveType(variableDeclarationSyntax.Type),
                    Name    = variableDeclaratorSyntax.Identifier.Text
                };
                wandaBlock.LocalVariables.Add(variable);
                var declaration = new SimpleDeclarationStatement
                {
                    Variable     = variable,
                    ParentBlock  = wandaBlock,
                    ParentMethod = wandaBlock.ParentMethod,
                };
                wandaBlock.Body.Add(declaration);
                if (variableDeclaratorSyntax.Initializer == null)
                {
                    continue;
                }

                var initializerValue = variableDeclaratorSyntax.Initializer.Value;

                var withWhat = ResolveValueToBlock(wandaBlock, initializerValue,
                                                   replaceCreatedDummyVariableWith: variable);

                if (withWhat == variable)
                {
                    continue;
                }

                if (withWhat == null)
                {
                    Log.Warning("Unable to parse assigned value expression {Expression} for {Variable}, using null", initializerValue, variable.Name);
                    withWhat = NullLiteral.Instance;
                }

                var assignment = new SimpleExpressionStatement
                {
                    Expression   = new SimpleAssignment(variable, withWhat),
                    ParentBlock  = wandaBlock,
                    ParentMethod = wandaBlock.ParentMethod,
                    // todo: location
                };

                if (withWhat is ILValue value)
                {
                    variable.TypeRef = value.TypeRef;
                }

                wandaBlock.Body.Add(assignment);
            }
        }
示例#2
0
        private static void ProcessWandaExpressionIntoWandaBlock(SimpleCompoundStatement wandaBlock,
                                                                 ExpressionBase wandaExpression)
        {
            var simpleExpressionStatement = new SimpleExpressionStatement
            {
                Expression   = wandaExpression,
                ParentBlock  = wandaBlock,
                ParentMethod = wandaBlock.ParentMethod
                               //Location = invocationExpressionSyntax.GetLocation()
            };

            wandaBlock.Body.Add(simpleExpressionStatement);
        }