GetPredefinedMethod() public static method

public static GetPredefinedMethod ( System.TypeSpec t, MemberFilter filter, Mono.CSharp.Location loc ) : MethodSpec
t System.TypeSpec
filter MemberFilter
loc Mono.CSharp.Location
return MethodSpec
Esempio n. 1
0
                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);
                }
Esempio n. 2
0
                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);
                }