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); }); } } }
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); }
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); }
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 }); }
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); }
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); }); } } }
public void ShouldNotSuppressOtherExceptions() { Execute.AndSupressExceptions(() => { throw new IOException(); }); }
public void ShouldSuppressException(Exception e) { Execute.AndSupressExceptions(() => { throw e; }); }