public override Expression CoerceAnonymousNestedFunction(AnonymousNestedFunction func, TypeNode targetType, bool explicitCoercion, TypeViewer typeViewer) { if (func is AnonymousNestedDelegate && !(targetType is DelegateNode)) { this.HandleError(func, Error.AnonMethToNonDel, this.GetTypeName(targetType)); return null; } return base.CoerceAnonymousNestedFunction(func, targetType, explicitCoercion, typeViewer); }
public virtual Expression VisitAnonymousNestedFunction(AnonymousNestedFunction func) { if (func == null) return null; func.Parameters = this.VisitParameterList(func.Parameters); func.Body = this.VisitBlock(func.Body); return func; }
public override Expression VisitAnonymousNestedFunction(AnonymousNestedFunction func) { if (func == null) return null; AnonymousNestedFunction dup = (AnonymousNestedFunction)func.Clone(); if (func.Method != null) { dup.Method = this.VisitMethod(func.Method); //^ assume dup.Method != null; dup.Parameters = dup.Method.Parameters; dup.Body = dup.Method.Body; return dup; } return base.VisitAnonymousNestedFunction(dup); }
private Expression ParseLambdaExpression(SourceContext sctx, ParameterList pars, TokenSet followers) { Debug.Assert(this.currentToken == Token.Lambda); int lambdaPos = this.scanner.endPos; Block body; this.GetNextToken(); if (this.currentToken == Token.LeftBrace) body = this.ParseBlock(followers); else{ Expression expr = this.ParseExpression(followers); if (expr == null) return null; body = new Block(new StatementList(new Return(expr, expr.SourceContext)), expr.SourceContext); } AnonymousNestedFunction func = new AnonymousNestedFunction(pars, body); func.SourceContext = sctx; func.SourceContext.EndPos = lambdaPos; return func; }
//TODO: get rid of stateAfterBrace private Expression ParseBlockExpression(ScannerState stateAfterBrace, object sctx, TokenSet followers){ bool savedSawReturnOrYield = this.sawReturnOrYield; this.sawReturnOrYield = false; Block block = new Block(); block.Checked = this.insideCheckedBlock; block.IsUnsafe = this.inUnsafeCode; block.SuppressCheck = this.insideUncheckedBlock; SourceContext ctx = (SourceContext)sctx; ctx.EndPos = this.scanner.CurrentSourceContext.EndPos; Debug.Assert(this.currentToken == Token.LeftBrace); // this.GetNextToken(); block.SourceContext = ctx; block.Statements = new StatementList(new ExpressionStatement(ParseComprehension(followers))); // block.Statements = this.ParseStatementsWithOptionalExpression(followers|Token.RightBrace); if (this.arrayInitializerOpeningContext != null && block.Statements == null && this.currentToken == Token.RightBrace){ this.GetNextToken(); this.sawReturnOrYield = savedSawReturnOrYield; return null; } block.SourceContext.EndPos = this.scanner.CurrentSourceContext.EndPos; this.scanner.state = stateAfterBrace; // this.ParseBracket(ctx, Token.RightBrace, followers, Error.ExpectedRightBrace); Expression result = null; if (sawReturnOrYield) result = new AnonymousNestedFunction(new ParameterList(0), block); else result = new BlockExpression(block); result.SourceContext = ctx; this.sawReturnOrYield = savedSawReturnOrYield; return result; }
public EventingVisitor(Action<AnonymousNestedFunction> visitAnonymousNestedFunction) { VisitedAnonymousNestedFunction += visitAnonymousNestedFunction; } public event Action<AnonymousNestedFunction> VisitedAnonymousNestedFunction; public override Expression VisitAnonymousNestedFunction(AnonymousNestedFunction func) { if (VisitedAnonymousNestedFunction != null) VisitedAnonymousNestedFunction(func); return base.VisitAnonymousNestedFunction(func); }