///////////////////////////////////////////////////////////////////////////////// // Expression types. private ExprBinOp VisitBoundLambda(ExprBoundLambda anonmeth) { Debug.Assert(anonmeth != null); MethodSymbol lambdaMethod = GetPreDefMethod(PREDEFMETH.PM_EXPRESSION_LAMBDA); AggregateType delegateType = anonmeth.DelegateType; TypeArray lambdaTypeParams = GetSymbolLoader().getBSymmgr().AllocParams(1, new CType[] { delegateType }); AggregateType expressionType = GetSymbolLoader().GetPredefindType(PredefinedType.PT_EXPRESSION); MethWithInst mwi = new MethWithInst(lambdaMethod, expressionType, lambdaTypeParams); Expr createParameters = CreateWraps(anonmeth); Debug.Assert(createParameters != null); Debug.Assert(anonmeth.Expression != null); Expr body = Visit(anonmeth.Expression); Debug.Assert(anonmeth.ArgumentScope.nextChild == null); Expr parameters = GenerateParamsArray(null, PredefinedType.PT_PARAMETEREXPRESSION); Expr args = GetExprFactory().CreateList(body, parameters); CType typeRet = GetSymbolLoader().GetTypeManager().SubstType(mwi.Meth().RetType, mwi.GetType(), mwi.TypeArgs); ExprMemberGroup pMemGroup = GetExprFactory().CreateMemGroup(null, mwi); ExprCall call = GetExprFactory().CreateCall(0, typeRet, args, pMemGroup, mwi); call.PredefinedMethod = PREDEFMETH.PM_EXPRESSION_LAMBDA; return(GetExprFactory().CreateSequence(createParameters, call)); }
private Expr CreateWraps(ExprBoundLambda anonmeth) { Expr sequence = null; for (Symbol sym = anonmeth.ArgumentScope.firstChild; sym != null; sym = sym.nextChild) { if (!(sym is LocalVariableSymbol local)) { continue; } Debug.Assert(anonmeth.Expression != null); Expr create = GenerateParameter(local.name.Text, local.GetType()); local.wrap = GetExprFactory().CreateWrap(create); Expr save = GetExprFactory().CreateSave(local.wrap); if (sequence == null) { sequence = save; } else { sequence = GetExprFactory().CreateSequence(sequence, save); } } return(sequence); }
public ExprBoundLambda CreateAnonymousMethod(AggregateType delegateType) { Debug.Assert(delegateType == null || delegateType.isDelegateType()); ExprBoundLambda rval = new ExprBoundLambda(delegateType); return(rval); }
public ExprBoundLambda CreateAnonymousMethod(AggregateType delegateType) { Debug.Assert(delegateType == null || delegateType.isDelegateType()); ExprBoundLambda rval = new ExprBoundLambda(); rval.Kind = ExpressionKind.EK_BOUNDLAMBDA; rval.Type = delegateType; rval.Flags = 0; Debug.Assert(rval != null); return(rval); }
public static ExprBinOp Rewrite(ExprBoundLambda expr, ExprFactory expressionFactory, SymbolLoader symbolLoader) => new ExpressionTreeRewriter(expressionFactory, symbolLoader).VisitBoundLambda(expr);
protected virtual Expr VisitBOUNDLAMBDA(ExprBoundLambda pExpr) { return(VisitEXPR(pExpr)); }
public static ExprBinOp Rewrite(ExprBoundLambda expr) => new ExpressionTreeRewriter().VisitBoundLambda(expr);