예제 #1
0
        /////////////////////////////////////////////////////////////////////////////////
        // 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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        public ExprBoundLambda CreateAnonymousMethod(AggregateType delegateType)
        {
            Debug.Assert(delegateType == null || delegateType.isDelegateType());
            ExprBoundLambda rval = new ExprBoundLambda(delegateType);

            return(rval);
        }
예제 #4
0
        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);
        }
예제 #5
0
 public static ExprBinOp Rewrite(ExprBoundLambda expr, ExprFactory expressionFactory, SymbolLoader symbolLoader) =>
 new ExpressionTreeRewriter(expressionFactory, symbolLoader).VisitBoundLambda(expr);
예제 #6
0
 protected virtual Expr VisitBOUNDLAMBDA(ExprBoundLambda pExpr)
 {
     return(VisitEXPR(pExpr));
 }
예제 #7
0
 public static ExprBinOp Rewrite(ExprBoundLambda expr) => new ExpressionTreeRewriter().VisitBoundLambda(expr);