예제 #1
0
        public override void VisitMethodDeclaration(IMethodDeclaration decl, SST context)
        {
            _cancellationToken.ThrowIfCancellationRequested();

            if (decl.DeclaredElement != null)
            {
                var methodName = decl.DeclaredElement.GetName <IMethodName>();

                var sstDecl = new MethodDeclaration
                {
                    Name         = methodName,
                    IsEntryPoint = _entryPoints.Contains(methodName)
                };
                context.Methods.Add(sstDecl);

                if (decl == _marker.AffectedNode)
                {
                    sstDecl.Body.Add(new ExpressionStatement {
                        Expression = new CompletionExpression()
                    });
                }

                if (!decl.IsAbstract)
                {
                    var bodyVisitor = new BodyVisitor(new UniqueVariableNameGenerator(), _marker);

                    Execute.AndSupressExceptions(
                        delegate { decl.Accept(bodyVisitor, sstDecl.Body); });
                }
            }
        }
예제 #2
0
        public IAssignableExpression ToAssignableExpr(ICSharpExpression csExpr, IList <IStatement> body)
        {
            IAssignableExpression result = new UnknownExpression();

            Execute.AndSupressExceptions(
                () =>
            {
                result = csExpr == null
                        ? new UnknownExpression()
                        : csExpr.Accept(this, body) ?? new UnknownExpression();
            });
            return(result);
        }
예제 #3
0
        public IAssignableExpression ToAssignableExpr(IVariableInitializer csExpr, IList <IStatement> body)
        {
            IAssignableExpression result = new UnknownExpression();

            Execute.AndSupressExceptions(
                () =>
            {
                var exprInit = csExpr as IExpressionInitializer;
                if (exprInit != null && exprInit.Value != null)
                {
                    result = exprInit.Value.Accept(this, body) ?? new UnknownExpression();
                }
            });
            return(result);
        }
예제 #4
0
        public ISimpleExpression ToSimpleExpression(ICSharpExpression csExpr, IList <IStatement> body)
        {
            if (csExpr == null)
            {
                return(new UnknownExpression());
            }

            IAssignableExpression expr = new UnknownExpression();

            Execute.AndSupressExceptions(
                () => { expr = csExpr.Accept(this, body) ?? new UnknownExpression(); });

            var simpleExpression = expr as ISimpleExpression;

            if (simpleExpression != null)
            {
                return(simpleExpression);
            }

            var newRef = new VariableReference {
                Identifier = _nameGen.GetNextVariableName()
            };
            var exprIType = csExpr.GetExpressionType().ToIType();
            // TODO write test for this null check
            var exprType = exprIType == null ? Names.UnknownType : exprIType.GetName();

            body.Add(
                new VariableDeclaration
            {
                Reference = newRef,
                Type      = exprType
            });
            body.Add(
                new Assignment
            {
                Reference  = newRef,
                Expression = expr
            });
            return(new ReferenceExpression {
                Reference = newRef
            });
        }
예제 #5
0
        public override void VisitBlock(IBlock block, IList <IStatement> body)
        {
            // TODO NameUpdate: changed another helper to overriding this method, check if Null check is really necessary now
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (block == null)
            {
                return;
            }
            // TODO NameUpdate: untested addition
            AddIf(block, CompletionCase.EmptyCompletionBefore, body);
            // TODO NameUpdate: untested addition
            AddIf(block, CompletionCase.InBody, body);

            foreach (var stmt in block.Statements)
            {
                Execute.AndSupressExceptions(
                    delegate { stmt.Accept(this, body); });
            }
            // TODO NameUpdate: untested addition
            AddIf(block, CompletionCase.EmptyCompletionAfter, body);
        }
예제 #6
0
        public override void VisitConstructorDeclaration(IConstructorDeclaration decl, SST context)
        {
            _cancellationToken.ThrowIfCancellationRequested();

            var nameGen   = new UniqueVariableNameGenerator();
            var exprVisit = new ExpressionVisitor(nameGen, _marker);

            if (decl.DeclaredElement != null)
            {
                var methodName = decl.DeclaredElement.GetName <IMethodName>();

                var sstDecl = new MethodDeclaration
                {
                    Name         = methodName,
                    IsEntryPoint = _entryPoints.Contains(methodName)
                };
                context.Methods.Add(sstDecl);

                if (decl == _marker.AffectedNode)
                {
                    sstDecl.Body.Add(new ExpressionStatement {
                        Expression = new CompletionExpression()
                    });
                }

                if (decl.Initializer != null)
                {
                    var name = Names.UnknownMethod;

                    var substitution = decl.DeclaredElement.IdSubstitution;
                    var resolvedRef  = decl.Initializer.Reference.Resolve();
                    if (resolvedRef.DeclaredElement != null)
                    {
                        name = resolvedRef.DeclaredElement.GetName <IMethodName>(substitution);
                    }

                    var args = Lists.NewList <ISimpleExpression>();
                    foreach (var p in decl.Initializer.Arguments)
                    {
                        var expr = exprVisit.ToSimpleExpression(p.Value, sstDecl.Body);
                        args.Add(expr);
                    }

                    var varId = new VariableReference().Identifier; // default value
                    if (decl.Initializer.Instance != null)
                    {
                        var tokenType = decl.Initializer.Instance.GetTokenType();
                        var isThis    = CSharpTokenType.THIS_KEYWORD == tokenType;
                        var isBase    = CSharpTokenType.BASE_KEYWORD == tokenType;

                        varId = isThis ? "this" : isBase ? "base" : varId;
                    }

                    sstDecl.Body.Add(
                        new ExpressionStatement
                    {
                        Expression = new InvocationExpression
                        {
                            Reference = new VariableReference {
                                Identifier = varId
                            },
                            MethodName = name,
                            Parameters = args
                        }
                    });
                }

                if (!decl.IsAbstract)
                {
                    var bodyVisitor = new BodyVisitor(nameGen, _marker);

                    Execute.AndSupressExceptions(
                        delegate { decl.Accept(bodyVisitor, sstDecl.Body); });
                }
            }
        }
예제 #7
0
 public void ShouldNotSuppressOtherExceptions()
 {
     Execute.AndSupressExceptions(() => { throw new IOException(); });
 }
예제 #8
0
 public void ShouldSuppressException(Exception e)
 {
     Execute.AndSupressExceptions(() => { throw e; });
 }