public override IAssignableExpression VisitAnonymousMethodExpression(IAnonymousMethodExpression expr, IList <IStatement> body) { var lambdaName = expr.GetName(); var lambdaBody = new KaVEList <IStatement>(); var bodyVisitor = new BodyVisitor(_nameGen, _marker); expr.Body.Accept(bodyVisitor, lambdaBody); return(new LambdaExpression { Name = lambdaName, Body = lambdaBody }); }
private void AddAccessorDecl(IAccessorOwnerDeclaration decl, KaVE.Commons.Model.SSTs.Declarations.IPropertyDeclaration propDecl) { foreach (var accessor in decl.AccessorDeclarations) { var bodyVisitor = new BodyVisitor(new UniqueVariableNameGenerator(), _marker); var body = Lists.NewList <IKaVEStatement>(); if (accessor.Kind == AccessorKind.GETTER) { body = propDecl.Get; } if (accessor.Kind == AccessorKind.SETTER) { body = propDecl.Set; } accessor.Accept(bodyVisitor, 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); }); } } }