コード例 #1
0
        private static DirectMethodHandle MakeAllocator(MemberName ctor)
        {
            assert(ctor.Constructor && ctor.Name.Equals("<init>"));
            Class instanceClass = ctor.DeclaringClass;

            ctor = ctor.AsConstructor();
            assert(ctor.Constructor && ctor.ReferenceKind == REF_newInvokeSpecial) : ctor;
            MethodType mtype = ctor.MethodType.ChangeReturnType(instanceClass);
            LambdaForm lform = PreparedLambdaForm(ctor);
            MemberName init  = ctor.AsSpecial();

            assert(init.MethodType.ReturnType() == typeof(void));
            return(new Constructor(mtype, lform, ctor, init, instanceClass));
        }
コード例 #2
0
        // Factory methods:
        internal static DirectMethodHandle Make(sbyte refKind, Class receiver, MemberName member)
        {
            MethodType mtype = member.MethodOrFieldType;

            if (!member.Static)
            {
                if (!receiver.IsSubclassOf(member.DeclaringClass) || member.Constructor)
                {
                    throw new InternalError(member.ToString());
                }
                mtype = mtype.InsertParameterTypes(0, receiver);
            }
            if (!member.Field)
            {
                if (refKind == REF_invokeSpecial)
                {
                    member = member.AsSpecial();
                    LambdaForm lform = PreparedLambdaForm(member);
                    return(new Special(mtype, lform, member));
                }
                else
                {
                    LambdaForm lform = PreparedLambdaForm(member);
                    return(new DirectMethodHandle(mtype, lform, member));
                }
            }
            else
            {
                LambdaForm lform = PreparedFieldLambdaForm(member);
                if (member.Static)
                {
                    long   offset = MethodHandleNatives.staticFieldOffset(member);
                    Object @base  = MethodHandleNatives.staticFieldBase(member);
                    return(new StaticAccessor(mtype, lform, member, @base, offset));
                }
                else
                {
                    long offset = MethodHandleNatives.objectFieldOffset(member);
                    assert(offset == (int)offset);
                    return(new Accessor(mtype, lform, member, (int)offset));
                }
            }
        }