MergeGenerated() public static method

public static MergeGenerated ( CompilerContext ctx, ParametersCompiled userParams, bool checkConflicts, Parameter compilerParams, System.TypeSpec compilerTypes ) : ParametersCompiled
ctx CompilerContext
userParams ParametersCompiled
checkConflicts bool
compilerParams Parameter
compilerTypes System.TypeSpec
return ParametersCompiled
Esempio n. 1
0
        void DefineAsyncMethods(TypeExpression returnType)
        {
            var iasync_result  = Module.PredefinedTypes.IAsyncResult;
            var async_callback = Module.PredefinedTypes.AsyncCallback;

            //
            // It's ok when async types don't exist, the delegate will have Invoke method only
            //
            if (!iasync_result.Define() || !async_callback.Define())
            {
                return;
            }

            //
            // BeginInvoke
            //
            ParametersCompiled async_parameters;

            if (Parameters.Count == 0)
            {
                async_parameters = ParametersCompiled.EmptyReadOnlyParameters;
            }
            else
            {
                var compiled = new Parameter[Parameters.Count];
                for (int i = 0; i < compiled.Length; ++i)
                {
                    var p = parameters[i];
                    compiled[i] = new Parameter(new TypeExpression(parameters.Types[i], Location),
                                                p.Name,
                                                p.ModFlags & Parameter.Modifier.RefOutMask,
                                                p.OptAttributes == null ? null : p.OptAttributes.Clone(), Location);
                }

                async_parameters = new ParametersCompiled(compiled);
            }

            async_parameters = ParametersCompiled.MergeGenerated(Compiler, async_parameters, false,
                                                                 new Parameter[] {
                new Parameter(new TypeExpression(async_callback.TypeSpec, Location), "callback", Parameter.Modifier.NONE, null, Location),
                new Parameter(new TypeExpression(Compiler.BuiltinTypes.Object, Location), "object", Parameter.Modifier.NONE, null, Location)
            },
                                                                 new [] {
                async_callback.TypeSpec,
                Compiler.BuiltinTypes.Object
            }
                                                                 );

            BeginInvokeBuilder = new Method(this,
                                            new TypeExpression(iasync_result.TypeSpec, Location), MethodModifiers,
                                            new MemberName("BeginInvoke"), async_parameters, null);
            BeginInvokeBuilder.Define();

            //
            // EndInvoke is a bit more interesting, all the parameters labeled as
            // out or ref have to be duplicated here.
            //

            //
            // Define parameters, and count out/ref parameters
            //
            ParametersCompiled end_parameters;
            int out_params = 0;

            foreach (Parameter p in Parameters.FixedParameters)
            {
                if ((p.ModFlags & Parameter.Modifier.RefOutMask) != 0)
                {
                    ++out_params;
                }
            }

            if (out_params > 0)
            {
                Parameter[] end_params = new Parameter[out_params];

                int param = 0;
                for (int i = 0; i < Parameters.FixedParameters.Length; ++i)
                {
                    Parameter p = parameters [i];
                    if ((p.ModFlags & Parameter.Modifier.RefOutMask) == 0)
                    {
                        continue;
                    }

                    end_params [param++] = new Parameter(new TypeExpression(p.Type, Location),
                                                         p.Name,
                                                         p.ModFlags & Parameter.Modifier.RefOutMask,
                                                         p.OptAttributes == null ? null : p.OptAttributes.Clone(), Location);
                }

                end_parameters = new ParametersCompiled(end_params);
            }
            else
            {
                end_parameters = ParametersCompiled.EmptyReadOnlyParameters;
            }

            end_parameters = ParametersCompiled.MergeGenerated(Compiler, end_parameters, false,
                                                               new Parameter(
                                                                   new TypeExpression(iasync_result.TypeSpec, Location),
                                                                   "result", Parameter.Modifier.NONE, null, Location),
                                                               iasync_result.TypeSpec);

            //
            // Create method, define parameters, register parameters with type system
            //
            EndInvokeBuilder = new Method(this, returnType, MethodModifiers, new MemberName("EndInvoke"), end_parameters, null);
            EndInvokeBuilder.Define();
        }
Esempio n. 2
0
        void DefineAsyncMethods(CallingConventions cc)
        {
            //
            // BeginInvoke
            //
            ParametersCompiled async_parameters = ParametersCompiled.MergeGenerated(Parameters, false,
                                                                                    new Parameter [] {
                new Parameter(null, "callback", Parameter.Modifier.NONE, null, Location),
                new Parameter(null, "object", Parameter.Modifier.NONE, null, Location)
            },
                                                                                    new Type [] {
                TypeManager.asynccallback_type,
                TypeManager.object_type
            }
                                                                                    );

            BeginInvokeBuilder = TypeBuilder.DefineMethod("BeginInvoke",
                                                          mattr, cc, TypeManager.iasyncresult_type, async_parameters.GetEmitTypes());

            BeginInvokeBuilder.SetImplementationFlags(MethodImplAttributes.Runtime);
            TypeManager.RegisterMethod(BeginInvokeBuilder, async_parameters);
            member_cache.AddMember(BeginInvokeBuilder, this);

            //
            // EndInvoke is a bit more interesting, all the parameters labeled as
            // out or ref have to be duplicated here.
            //

            //
            // Define parameters, and count out/ref parameters
            //
            ParametersCompiled end_parameters;
            int out_params = 0;

            foreach (Parameter p in Parameters.FixedParameters)
            {
                if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
                {
                    ++out_params;
                }
            }

            if (out_params > 0)
            {
                Type []     end_param_types = new Type [out_params];
                Parameter[] end_params      = new Parameter [out_params];

                int param = 0;
                for (int i = 0; i < Parameters.FixedParameters.Length; ++i)
                {
                    Parameter p = Parameters [i];
                    if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
                    {
                        continue;
                    }

                    end_param_types [param] = Parameters.Types [i];
                    end_params [param]      = p;
                    ++param;
                }
                end_parameters = ParametersCompiled.CreateFullyResolved(end_params, end_param_types);
            }
            else
            {
                end_parameters = ParametersCompiled.EmptyReadOnlyParameters;
            }

            end_parameters = ParametersCompiled.MergeGenerated(end_parameters, false,
                                                               new Parameter(null, "result", Parameter.Modifier.NONE, null, Location), TypeManager.iasyncresult_type);

            //
            // Create method, define parameters, register parameters with type system
            //
            EndInvokeBuilder = TypeBuilder.DefineMethod("EndInvoke", mattr, cc, ret_type, end_parameters.GetEmitTypes());
            EndInvokeBuilder.SetImplementationFlags(MethodImplAttributes.Runtime);

            end_parameters.ApplyAttributes(EndInvokeBuilder);
            TypeManager.RegisterMethod(EndInvokeBuilder, end_parameters);
            member_cache.AddMember(EndInvokeBuilder, this);
        }