コード例 #1
0
ファイル: JavaMethod.cs プロジェクト: spaceflint7/bluebonnet
 public JavaMethod(JavaClass jclass, JavaMethodRef methodRef)
 {
     Name       = methodRef.Name;
     ReturnType = methodRef.ReturnType;
     Parameters = new List <JavaFieldRef>(methodRef.Parameters);
     Class      = jclass;
 }
コード例 #2
0
ファイル: JavaWriter.cs プロジェクト: spaceflint7/bluebonnet
        public ushort ConstInterfaceMethod(JavaType vClass, JavaMethodRef vMethod)
        {
            ushort classIndex       = ConstClass(vClass);
            ushort nameAndTypeIndex = ConstNameAndType(vMethod.Name, vMethod.ToDescriptor());

            return((ushort)constants.Put(
                       new JavaConstant.InterfaceMethodRef(classIndex, nameAndTypeIndex), Where));
        }
コード例 #3
0
        public JavaMethod(JavaReader rdr, bool withCode = true)
        {
            Class = rdr.Class;

            Flags = (JavaAccessFlags)rdr.Read16();

            Name = rdr.ConstUtf8(rdr.Read16());

            rdr.Where.Push($"method '{Name}'");

            var tmpMethod = new JavaMethodRef(rdr.ConstUtf8(rdr.Read16()), rdr.Where);

            ReturnType = tmpMethod.ReturnType;
            Parameters = tmpMethod.Parameters;

            var attributes = new JavaAttributeSet(rdr, withCode);

            Exceptions = attributes.GetAttr <JavaAttribute.Exceptions>()?.classes;

            var codeAttr = attributes.GetAttr <JavaAttribute.Code>();

            if (withCode && codeAttr != null)
            {
                #if !DEBUG
                try
                {
                #endif
                Code = new JavaCode(rdr, this, codeAttr);
                #if !DEBUG
            }
            catch (IndexOutOfRangeException)
            {
                throw rdr.Where.Exception("unexpected end of code");
            }
                #endif
            }

            InitParameterNames(attributes, codeAttr);

            rdr.Where.Pop();
        }
コード例 #4
0
ファイル: JavaDynamic.cs プロジェクト: spaceflint7/bluebonnet
        //
        // create a CallSite that returns an object that implements the
        // functional interface 'declType', containing a single method with the
        // signature 'declMethod'.  this interface method is a proxy that calls
        // the method 'implMethod' from class 'implClass'.
        //
        // 'captureParameters' may optionally specify any number of parameters,
        // which would be on the stack when 'invokedynamic' is executed.  these
        // parameters are captured by the callsite, and injected as the first
        // several parameters of 'implMethod' when the proxy is called.  the
        // parameter list for 'implMethod' should not include these parameters;
        // they are inserted by this method.
        //
        // callKind should be InvokeStatic, InvokeVirtual, or InvokeInterface,
        // and specifies the type of 'implMethod'.  if not InvokeStatic, it is
        // as if the first parameter in 'captureParameters' is 'declType'.
        //

        public JavaCallSite(JavaType declType, JavaMethodRef declMethod,
                            JavaType implClass, JavaMethodRef implMethod,
                            List <JavaFieldRef> captureParameters,
                            JavaMethodHandle.HandleKind callKind)
        {
            BootstrapMethod      = GetLambdaMetafactory();
            BootstrapMethodIndex = 0xFFFF;

            var invokedMethod = new JavaMethodRef();

            invokedMethod.Name       = declMethod.Name;
            invokedMethod.ReturnType = declType;
            invokedMethod.Parameters = new List <JavaFieldRef>();
            if (callKind != JavaMethodHandle.HandleKind.InvokeStatic)
            {
                invokedMethod.Parameters.Add(new JavaFieldRef("", implClass));
            }
            InvokedMethod = invokedMethod;

            var methodHandle = new JavaMethodHandle();

            methodHandle.Class             = implClass;
            methodHandle.Method            = implMethod;
            methodHandle.Kind              = callKind;
            methodHandle.IsInterfaceMethod =
                (callKind == JavaMethodHandle.HandleKind.InvokeInterface);

            JavaMethodType castMethod = new JavaMethodType(declMethod.ReturnType, null);

            castMethod.Parameters = new List <JavaFieldRef>();
            for (int i = 0; i < implMethod.Parameters.Count; i++)
            {
                JavaType castParameterType = declMethod.Parameters[i].Type;
                if (castParameterType.Equals(JavaType.ObjectType))
                {
                    var implParameterType = implMethod.Parameters[i].Type;
                    castParameterType = implParameterType.Wrapper ?? implParameterType;
                }
                castMethod.Parameters.Add(new JavaFieldRef("", castParameterType));
            }

            BootstrapArgs = new object[3];
            // arg#0 (aka 'samMethodType') specifies the signature, minus the name,
            // of the method in the functional interface.  note that the name was
            // already inserted into 'InvokedMethod', above
            BootstrapArgs[0] =
                new JavaMethodType(declMethod.ReturnType, declMethod.Parameters);
            // arg#1 (aka 'implMethod') specifies the name and signature of the
            // method that provides the actual implementation for the interface
            BootstrapArgs[1] = methodHandle;
            // arg#2 (aka 'instantiatedMethodType') specifies optional conversions
            // on the parameters passed to the 'invokeinterface' instructions.
            // in particular, boxing of primitives to standard wrapper types, or
            // casting generic java.lang.Object to a more restricted type.
            BootstrapArgs[2] =
                new JavaMethodType(castMethod.ReturnType, castMethod.Parameters);

            if (captureParameters != null)
            {
                invokedMethod.Parameters.AddRange(captureParameters);
                var newParameters = new List <JavaFieldRef>(captureParameters);
                newParameters.AddRange(implMethod.Parameters);
                methodHandle.Method = new JavaMethodRef(
                    implMethod.Name, implMethod.ReturnType, newParameters);
            }
        }
コード例 #5
0
ファイル: JavaDynamic.cs プロジェクト: spaceflint7/bluebonnet
 public JavaCallSite(ushort index, JavaMethodRef method)
 {
     InvokedMethod        = method;
     BootstrapMethodIndex = index;
 }