Ejemplo n.º 1
0
        bool ImportParameters(MethodReference fromMethod)
        {
            bool appendSuffix = false;

            int n = fromMethod.HasParameters ? fromMethod.Parameters.Count : 0;

            Parameters = new List <JavaFieldRef>(n);

            for (int i = 0; i < n; i++)
            {
                var fromParameterType = fromMethod.Parameters[i].ParameterType;
                var paramType         = CilType.From(fromParameterType);

                if (paramType.IsPointer)
                {
                    if (paramType.IsValueClass || (!paramType.IsReference))
                    {
                        paramType = CilType.MakeSpanOf(paramType);
                    }
                    else
                    {
                        throw CilMain.Where.Exception("invalid pointer type in parameter");
                    }
                }

                if (paramType.IsGenericParameter)
                {
                    appendSuffix = true;
                    var nm = "-generic-";
                    if (paramType.IsArray)
                    {
                        nm += "array-" + paramType.ArrayRank + "-";
                    }
                    if (paramType.IsByReference)
                    {
                        nm = "-ref" + nm.Replace("&", "");
                    }
                    nm       += "$" + ((GenericParameter)fromParameterType.GetElementType()).Position;
                    paramType = CilType.WrapMethodGenericParameter(paramType, nm);
                    Flags    |= GEN_ARGS;
                }

                if (paramType.IsByReference)
                {
                    if (paramType.IsValueClass)
                    {
                        paramType    = paramType.MakeByRef();
                        appendSuffix = true;
                    }
                    else
                    {
                        // byref of any reference type parameter becomes system.Reference,
                        // so add a unique method name suffix
                        var paramBoxedType = new BoxedType(paramType, false);
                        paramType     = paramBoxedType;
                        appendSuffix |= paramBoxedType.IsBoxedReference;
                    }
                }

                if (!appendSuffix)
                {
                    appendSuffix |= fromParameterType.IsGenericInstance;

                    if (!paramType.IsReference)
                    {
                        appendSuffix |= ShouldRenamePrimitive(paramType);
                    }
                }

                Parameters.Add(new JavaFieldRef("", paramType));
            }

            var returnType = CilType.From(fromMethod.ReturnType);

            if (returnType.IsGenericParameter)
            {
                returnType = CilType.WrapMethodGenericParameter(returnType);
            }
            else if (returnType.IsByReference)
            {
                returnType = new BoxedType(returnType, false);
            }
            ReturnType = returnType;

            appendSuffix |= fromMethod.ReturnType.IsGenericInstance;

            return(appendSuffix);