public override bool Resolve(BlockContext ec) { TypeExpression storey_type_expr = new TypeExpression(host.Definition, loc); List <Expression> init = null; if (host.hoisted_this != null) { init = new List <Expression> (host.hoisted_params == null ? 1 : host.HoistedParameters.Count + 1); HoistedThis ht = host.hoisted_this; FieldExpr from = new FieldExpr(ht.Field, loc); from.InstanceExpression = new CompilerGeneratedThis(ec.CurrentType, loc); init.Add(new ElementInitializer(ht.Field.Name, from, loc)); } if (host.hoisted_params != null) { if (init == null) { init = new List <Expression> (host.HoistedParameters.Count); } for (int i = 0; i < host.hoisted_params.Count; ++i) { HoistedParameter hp = (HoistedParameter)host.hoisted_params [i]; HoistedParameter hp_cp = (HoistedParameter)host.hoisted_params_copy [i]; FieldExpr from = new FieldExpr(hp_cp.Field, loc); from.InstanceExpression = new CompilerGeneratedThis(ec.CurrentType, loc); init.Add(new ElementInitializer(hp.Field.Name, from, loc)); } } if (init != null) { new_storey = new NewInitialize(storey_type_expr, null, new CollectionOrObjectInitializers(init, loc), loc); } else { new_storey = new New(storey_type_expr, null, loc); } new_storey = new_storey.Resolve(ec); if (new_storey != null) { new_storey = Convert.ImplicitConversionRequired(ec, new_storey, host_method.MemberType, loc); } ec.CurrentBranching.CurrentUsageVector.Goto(); return(true); }
public override bool Resolve(BlockContext ec) { TypeExpression storey_type_expr = new TypeExpression(host.Definition, loc); List <Expression> init = null; if (host.hoisted_this != null) { init = new List <Expression> (host.hoisted_params == null ? 1 : host.HoistedParameters.Count + 1); HoistedThis ht = host.hoisted_this; FieldExpr from = new FieldExpr(ht.Field, loc); from.InstanceExpression = CompilerGeneratedThis.Instance; init.Add(new ElementInitializer(ht.Field.Name, from, loc)); } if (host.hoisted_params != null) { if (init == null) { init = new List <Expression> (host.HoistedParameters.Count); } for (int i = 0; i < host.hoisted_params.Count; ++i) { HoistedParameter hp = (HoistedParameter)host.hoisted_params [i]; HoistedParameter hp_cp = (HoistedParameter)host.hoisted_params_copy [i]; FieldExpr from = new FieldExpr(hp_cp.Field, loc); from.InstanceExpression = CompilerGeneratedThis.Instance; init.Add(new ElementInitializer(hp.Field.Name, from, loc)); } } if (init != null) { new_storey = new NewInitialize(storey_type_expr, null, new CollectionOrObjectInitializers(init, loc), loc); } else { new_storey = new New(storey_type_expr, null, loc); } new_storey = new_storey.Resolve(ec); if (new_storey != null) { new_storey = Convert.ImplicitConversionRequired(ec, new_storey, host_method.MemberType, loc); } var t = ec.Module.PredefinedTypes.Interlocked.Resolve(loc); if (t != null) { var p = new ParametersImported( new[] { new ParameterData(null, Parameter.Modifier.REF), new ParameterData(null, Parameter.Modifier.NONE), new ParameterData(null, Parameter.Modifier.NONE) }, new[] { TypeManager.int32_type, TypeManager.int32_type, TypeManager.int32_type }, false); var f = new MemberFilter("CompareExchange", 0, MemberKind.Method, p, TypeManager.int32_type); TypeManager.int_interlocked_compare_exchange = TypeManager.GetPredefinedMethod(t, f, loc); } ec.CurrentBranching.CurrentUsageVector.Goto(); return(true); }
protected override bool DoDefineMembers() { current_field = AddCompilerGeneratedField("$current", iterator_type_expr); disposing_field = AddCompilerGeneratedField("$disposing", new TypeExpression(Compiler.BuiltinTypes.Bool, Location)); if (Iterator.IsEnumerable && hoisted_params != null) { // // Iterators are independent, each GetEnumerator call has to // create same enumerator therefore we have to keep original values // around for re-initialization // hoisted_params_copy = new List <HoistedParameter> (hoisted_params.Count); foreach (HoistedParameter hp in hoisted_params) { // // Don't create field copy for unmodified captured parameters // HoistedParameter hp_copy; if (hp.IsAssigned) { hp_copy = new HoistedParameter(hp, "<$>" + hp.Field.Name); } else { hp_copy = null; } hoisted_params_copy.Add(hp_copy); } } if (generic_enumerator_type != null) { Define_Current(true); } Define_Current(false); new DisposeMethod(this); Define_Reset(); if (Iterator.IsEnumerable) { FullNamedExpression explicit_iface = new TypeExpression(Compiler.BuiltinTypes.IEnumerable, Location); var name = new MemberName("GetEnumerator", null, explicit_iface, Location.Null); if (generic_enumerator_type != null) { explicit_iface = new TypeExpression(generic_enumerable_type, Location); var gname = new MemberName("GetEnumerator", null, explicit_iface, Location.Null); Method gget_enumerator = GetEnumeratorMethod.Create(this, new TypeExpression(generic_enumerator_type, Location), gname); // // Just call generic GetEnumerator implementation // var stmt = new Return(new Invocation(new DynamicMethodGroupExpr(gget_enumerator, Location), null), Location); Method get_enumerator = GetEnumeratorMethod.Create(this, new TypeExpression(Compiler.BuiltinTypes.IEnumerator, Location), name, stmt); Members.Add(get_enumerator); Members.Add(gget_enumerator); } else { Members.Add(GetEnumeratorMethod.Create(this, new TypeExpression(Compiler.BuiltinTypes.IEnumerator, Location), name)); } } return(base.DoDefineMembers()); }
public override bool Resolve(EmitContext ec) { TypeExpression storey_type_expr = new TypeExpression(host.TypeBuilder, loc); ArrayList init = null; if (host.hoisted_this != null) { init = new ArrayList(host.hoisted_params == null ? 1 : host.HoistedParameters.Count + 1); HoistedThis ht = host.hoisted_this; FieldExpr from = new FieldExpr(ht.Field.FieldBuilder, loc); from.InstanceExpression = CompilerGeneratedThis.Instance; init.Add(new ElementInitializer(ht.Field.Name, from, loc)); } if (host.hoisted_params != null) { if (init == null) { init = new ArrayList(host.HoistedParameters.Count); } for (int i = 0; i < host.hoisted_params.Count; ++i) { HoistedParameter hp = (HoistedParameter)host.hoisted_params [i]; HoistedParameter hp_cp = (HoistedParameter)host.hoisted_params_copy [i]; FieldExpr from = new FieldExpr(hp_cp.Field.FieldBuilder, loc); from.InstanceExpression = CompilerGeneratedThis.Instance; init.Add(new ElementInitializer(hp.Field.Name, from, loc)); } } if (init != null) { new_storey = new NewInitialize(storey_type_expr, new ArrayList(0), new CollectionOrObjectInitializers(init, loc), loc); } else { new_storey = new New(storey_type_expr, new ArrayList(0), loc); } new_storey = new_storey.Resolve(ec); if (new_storey != null) { new_storey = Convert.ImplicitConversionRequired(ec, new_storey, host_method.MemberType, loc); } if (TypeManager.int_interlocked_compare_exchange == null) { Type t = TypeManager.CoreLookupType("System.Threading", "Interlocked", Kind.Class, true); if (t != null) { TypeManager.int_interlocked_compare_exchange = TypeManager.GetPredefinedMethod( t, "CompareExchange", loc, TypeManager.int32_type, TypeManager.int32_type, TypeManager.int32_type); } } ec.CurrentBranching.CurrentUsageVector.Goto(); return(true); }