Enable eval statements
[mono.git] / mcs / mcs / lambda.cs
index 363b4bc8cac3a83826ed7d0826b3aecf17c59641..0de7fe4bc9a0a0e57735c40e5a443f3b737cd384 100644 (file)
@@ -9,10 +9,11 @@
 // Copyright 2007-2008 Novell, Inc
 //
 
-using System;
-using System.Collections;
-using System.Reflection;
+#if STATIC
+using IKVM.Reflection.Emit;
+#else
 using System.Reflection.Emit;
+#endif
 
 namespace Mono.CSharp {
        public class LambdaExpression : AnonymousMethodExpression
@@ -27,12 +28,12 @@ namespace Mono.CSharp {
                {
                }
 
-               protected override Expression CreateExpressionTree (ResolveContext ec, Type delegate_type)
+               protected override Expression CreateExpressionTree (ResolveContext ec, TypeSpec delegate_type)
                {
                        if (ec.IsInProbingMode)
                                return this;
 
-                       BlockContext bc = new BlockContext (ec.MemberContext, ec.CurrentBlock.Explicit, TypeManager.void_type) {
+                       BlockContext bc = new BlockContext (ec.MemberContext, ec.ConstructorBlock, TypeManager.void_type) {
                                CurrentAnonymousMethod = ec.CurrentAnonymousMethod
                        };
 
@@ -55,12 +56,12 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override ParametersCompiled ResolveParameters (ResolveContext ec, TypeInferenceContext tic, Type delegateType)
+               protected override ParametersCompiled ResolveParameters (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegateType)
                {
-                       if (!TypeManager.IsDelegateType (delegateType))
+                       if (!delegateType.IsDelegate)
                                return null;
 
-                       AParametersCollection d_params = TypeManager.GetDelegateParameters (ec, delegateType);
+                       AParametersCollection d_params = Delegate.GetParameters (delegateType);
 
                        if (HasExplicitParameters) {
                                if (!VerifyExplicitParameters (ec, delegateType, d_params))
@@ -76,19 +77,14 @@ namespace Mono.CSharp {
                        if (!VerifyParameterCompatibility (ec, delegateType, d_params, ec.IsInProbingMode))
                                return null;
 
-                       Type [] ptypes = new Type [Parameters.Count];
+                       TypeSpec [] ptypes = new TypeSpec [Parameters.Count];
                        for (int i = 0; i < d_params.Count; i++) {
                                // D has no ref or out parameters
                                if ((d_params.FixedParameters [i].ModFlags & Parameter.Modifier.ISBYREF) != 0)
                                        return null;
 
-                               Type d_param = d_params.Types [i];
+                               TypeSpec d_param = d_params.Types [i];
 
-#if MS_COMPATIBLE
-                               // Blablabla, because reflection does not work with dynamic types
-                               if (d_param.IsGenericParameter)
-                                       d_param = delegateType.GetGenericArguments () [d_param.GenericParameterPosition];
-#endif
                                //
                                // When type inference context exists try to apply inferred type arguments
                                //
@@ -97,31 +93,30 @@ namespace Mono.CSharp {
                                }
 
                                ptypes [i] = d_param;
-                               ((ImplicitLambdaParameter) Parameters.FixedParameters [i]).Type = d_param;
+                               ImplicitLambdaParameter ilp = (ImplicitLambdaParameter) Parameters.FixedParameters [i];
+                               ilp.SetParameterType (d_param);
+                               ilp.Resolve (null, i);
                        }
 
                        Parameters.Types = ptypes;
                        return Parameters;
                }
 
-               protected override Expression DoResolve (ResolveContext ec)
+               protected override AnonymousMethodBody CompatibleMethodFactory (TypeSpec returnType, TypeSpec delegateType, ParametersCompiled p, ParametersBlock b)
+               {
+                       return new LambdaMethod (p, b, returnType, delegateType, loc);
+               }
+
+               protected override bool DoResolveParameters (ResolveContext rc)
                {
                        //
                        // Only explicit parameters can be resolved at this point
                        //
                        if (HasExplicitParameters) {
-                               if (!Parameters.Resolve (ec))
-                                       return null;
+                               return Parameters.Resolve (rc);
                        }
 
-                       eclass = ExprClass.Value;
-                       type = InternalType.AnonymousMethod;
-                       return this;
-               }
-
-               protected override AnonymousMethodBody CompatibleMethodFactory (Type returnType, Type delegateType, ParametersCompiled p, ToplevelBlock b)
-               {
-                       return new LambdaMethod (p, b, returnType, delegateType, loc);
+                       return true;
                }
 
                public override string GetSignatureForError ()
@@ -130,19 +125,16 @@ namespace Mono.CSharp {
                }
        }
 
-       public class LambdaMethod : AnonymousMethodBody
+       class LambdaMethod : AnonymousMethodBody
        {
                public LambdaMethod (ParametersCompiled parameters,
-                                       ToplevelBlock block, Type return_type, Type delegate_type,
+                                       ParametersBlock block, TypeSpec return_type, TypeSpec delegate_type,
                                        Location loc)
                        : base (parameters, block, return_type, delegate_type, loc)
                {
                }
 
-               protected override void CloneTo (CloneContext clonectx, Expression target)
-               {
-                       // TODO: nothing ??
-               }
+               #region Properties
 
                public override string ContainerType {
                        get {
@@ -150,6 +142,13 @@ namespace Mono.CSharp {
                        }
                }
 
+               #endregion
+
+               protected override void CloneTo (CloneContext clonectx, Expression target)
+               {
+                       // TODO: nothing ??
+               }
+
                public override Expression CreateExpressionTree (ResolveContext ec)
                {
                        BlockContext bc = new BlockContext (ec.MemberContext, Block, ReturnType);
@@ -190,7 +189,7 @@ namespace Mono.CSharp {
                {
                        if (statement != null) {
                                statement.EmitStatement (ec);
-                               ec.ig.Emit (OpCodes.Ret);
+                               ec.Emit (OpCodes.Ret);
                                return;
                        }