121 * return buildPtr.invokeExact(p, offset, t);
122 * }
123 */
124 MethodVisitor mv = cw.visitMethod(ACC_PRIVATE, "makePtr", Type.getMethodDescriptor(Type.getType(Pointer.class), Type.LONG_TYPE, Type.getType(LayoutType.class)), null, null);
125 mv.visitCode();
126 mv.visitLdcInsn(cw.makeConstantPoolPatch(BUILD_PTR_MH));
127 mv.visitTypeInsn(CHECKCAST, Type.getInternalName(MethodHandle.class));
128 mv.visitVarInsn(ALOAD, 0);
129 mv.visitFieldInsn(GETFIELD, implClassName, POINTER_FIELD_NAME, Type.getDescriptor(Pointer.class));
130 mv.visitVarInsn(LLOAD, 1);
131 mv.visitVarInsn(ALOAD, 3);
132 mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(MethodHandle.class), "invokeExact", Type.getMethodDescriptor(Type.getType(Pointer.class), Type.getType(Pointer.class), Type.LONG_TYPE, Type.getType(LayoutType.class)), false);
133 mv.visitInsn(ARETURN);
134 mv.visitMaxs(0, 0);
135 mv.visitEnd();
136 }
137
138 @Override
139 protected void generateMethodImplementation(BinderClassWriter cw, Method method) {
140 if (method.isAnnotationPresent(Offset.class)) {
141 if (!method.isAnnotationPresent(C.class) || !method.isAnnotationPresent(NativeType.class)) {
142 throw new IllegalArgumentException("Unexpectedly found an @Offset annotated method without a @NativeType annotation");
143 }
144
145 long off = method.getAnnotation(Offset.class).offset();
146 if (off < 0 || off % 8 != 0) {
147 throw new Error("NYI: Sub-byte offsets (" + off + ") in struct type: " + interfaces[0].getCanonicalName());
148 }
149 off = off / 8;
150
151 generateFieldAccessors(cw, method, off);
152 } else if (method.getDeclaringClass() == Struct.class) {
153 // ignore - the corresponding methods are generated as part of setting up the record type
154 } else {
155 super.generateMethodImplementation(cw, method);
156 }
157 }
158
159 private void generateFieldAccessors(BinderClassWriter cw, Method method, long offset) {
160 Class<?> javaType = method.getReturnType();
161
|
121 * return buildPtr.invokeExact(p, offset, t);
122 * }
123 */
124 MethodVisitor mv = cw.visitMethod(ACC_PRIVATE, "makePtr", Type.getMethodDescriptor(Type.getType(Pointer.class), Type.LONG_TYPE, Type.getType(LayoutType.class)), null, null);
125 mv.visitCode();
126 mv.visitLdcInsn(cw.makeConstantPoolPatch(BUILD_PTR_MH));
127 mv.visitTypeInsn(CHECKCAST, Type.getInternalName(MethodHandle.class));
128 mv.visitVarInsn(ALOAD, 0);
129 mv.visitFieldInsn(GETFIELD, implClassName, POINTER_FIELD_NAME, Type.getDescriptor(Pointer.class));
130 mv.visitVarInsn(LLOAD, 1);
131 mv.visitVarInsn(ALOAD, 3);
132 mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(MethodHandle.class), "invokeExact", Type.getMethodDescriptor(Type.getType(Pointer.class), Type.getType(Pointer.class), Type.LONG_TYPE, Type.getType(LayoutType.class)), false);
133 mv.visitInsn(ARETURN);
134 mv.visitMaxs(0, 0);
135 mv.visitEnd();
136 }
137
138 @Override
139 protected void generateMethodImplementation(BinderClassWriter cw, Method method) {
140 if (method.isAnnotationPresent(Offset.class)) {
141 if (!method.isAnnotationPresent(NativeType.class)) {
142 throw new IllegalArgumentException("Unexpectedly found an @Offset annotated method without a @NativeType annotation");
143 }
144
145 long off = method.getAnnotation(Offset.class).offset();
146 if (off < 0 || off % 8 != 0) {
147 throw new Error("NYI: Sub-byte offsets (" + off + ") in struct type: " + interfaces[0].getCanonicalName());
148 }
149 off = off / 8;
150
151 generateFieldAccessors(cw, method, off);
152 } else if (method.getDeclaringClass() == Struct.class) {
153 // ignore - the corresponding methods are generated as part of setting up the record type
154 } else {
155 super.generateMethodImplementation(cw, method);
156 }
157 }
158
159 private void generateFieldAccessors(BinderClassWriter cw, Method method, long offset) {
160 Class<?> javaType = method.getReturnType();
161
|