X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Flambda.cs;h=42a096dab1289e619b4676f6619331d48366684e;hb=cc39d7ebf1bfa8fafd6adc3a9fda354672579d1c;hp=244b8d942e22b6cecad6dc952cb7b77f03c6bb07;hpb=8aeff11832e6f3448859419f82b73dfa60bc3355;p=mono.git diff --git a/mcs/mcs/lambda.cs b/mcs/mcs/lambda.cs index 244b8d942e2..42a096dab12 100644 --- a/mcs/mcs/lambda.cs +++ b/mcs/mcs/lambda.cs @@ -10,7 +10,6 @@ // using System; -using System.Collections; using System.Reflection; using System.Reflection.Emit; @@ -27,12 +26,16 @@ namespace Mono.CSharp { { } - protected override Expression CreateExpressionTree (EmitContext ec, Type delegate_type) + protected override Expression CreateExpressionTree (ResolveContext ec, TypeSpec delegate_type) { if (ec.IsInProbingMode) return this; - - Expression args = Parameters.CreateExpressionTree (ec, loc); + + BlockContext bc = new BlockContext (ec.MemberContext, ec.ConstructorBlock, TypeManager.void_type) { + CurrentAnonymousMethod = ec.CurrentAnonymousMethod + }; + + Expression args = Parameters.CreateExpressionTree (bc, loc); Expression expr = Block.CreateExpressionTree (ec); if (expr == null) return null; @@ -40,7 +43,7 @@ namespace Mono.CSharp { Arguments arguments = new Arguments (2); arguments.Add (new Argument (expr)); arguments.Add (new Argument (args)); - return CreateExpressionFactoryCall ("Lambda", + return CreateExpressionFactoryCall (ec, "Lambda", new TypeArguments (new TypeExpression (delegate_type, loc)), arguments); } @@ -51,15 +54,15 @@ namespace Mono.CSharp { } } - protected override ParametersCompiled ResolveParameters (EmitContext 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 (delegateType); + AParametersCollection d_params = Delegate.GetParameters (ec.Compiler, delegateType); if (HasExplicitParameters) { - if (!VerifyExplicitParameters (delegateType, d_params, ec.IsInProbingMode)) + if (!VerifyExplicitParameters (ec, delegateType, d_params)) return null; return Parameters; @@ -69,22 +72,17 @@ namespace Mono.CSharp { // If L has an implicitly typed parameter list we make implicit parameters explicit // Set each parameter of L is given the type of the corresponding parameter in D // - if (!VerifyParameterCompatibility (delegateType, d_params, ec.IsInProbingMode)) + 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 // @@ -93,31 +91,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; } - public override Expression DoResolve (EmitContext 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 () @@ -126,19 +123,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 { @@ -146,9 +140,17 @@ namespace Mono.CSharp { } } - public override Expression CreateExpressionTree (EmitContext ec) + #endregion + + protected override void CloneTo (CloneContext clonectx, Expression target) + { + // TODO: nothing ?? + } + + public override Expression CreateExpressionTree (ResolveContext ec) { - Expression args = parameters.CreateExpressionTree (ec, loc); + BlockContext bc = new BlockContext (ec.MemberContext, Block, ReturnType); + Expression args = parameters.CreateExpressionTree (bc, loc); Expression expr = Block.CreateExpressionTree (ec); if (expr == null) return null; @@ -156,7 +158,7 @@ namespace Mono.CSharp { Arguments arguments = new Arguments (2); arguments.Add (new Argument (expr)); arguments.Add (new Argument (args)); - return CreateExpressionFactoryCall ("Lambda", + return CreateExpressionFactoryCall (ec, "Lambda", new TypeArguments (new TypeExpression (type, loc)), arguments); } @@ -176,7 +178,7 @@ namespace Mono.CSharp { { } - public override Expression CreateExpressionTree (EmitContext ec) + public override Expression CreateExpressionTree (ResolveContext ec) { return Expr.CreateExpressionTree (ec); } @@ -185,14 +187,14 @@ namespace Mono.CSharp { { if (statement != null) { statement.EmitStatement (ec); - ec.ig.Emit (OpCodes.Ret); + ec.Emit (OpCodes.Ret); return; } base.Emit (ec); } - protected override bool DoResolve (EmitContext ec) + protected override bool DoResolve (BlockContext ec) { // // When delegate returns void, only expression statements can be used @@ -204,7 +206,7 @@ namespace Mono.CSharp { statement = Expr as ExpressionStatement; if (statement == null) - Expr.Error_InvalidExpressionStatement (); + Expr.Error_InvalidExpressionStatement (ec); return true; }