-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathNewExposer.java
More file actions
59 lines (49 loc) · 1.88 KB
/
NewExposer.java
File metadata and controls
59 lines (49 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.python.expose.generate;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.python.core.PyNewWrapper;
public class NewExposer extends Exposer {
private Type onType;
private String name;
public NewExposer(Type onType, int access, String methodName, String desc, String[] exceptions) {
super(PyNewWrapper.class, onType.getClassName() + "$exposed___new__");
this.onType = onType;
this.name = methodName;
if ((access & Opcodes.ACC_STATIC) == 0) {
throwInvalid("Full methods for @ExposedNew must be static");
}
if (!Type.getReturnType(desc).equals(PYOBJ)) {
throwInvalid("@ExposedNew methods must return PyObject");
}
if (exceptions != null && exceptions.length > 0) {
throwInvalid("@ExposedNew methods may not throw checked exceptions");
}
}
private void throwInvalid(String msg) {
throw new InvalidExposingException(msg + "[method=" + onType.getClassName() + "." + name
+ "]");
}
@Override
protected void generate() {
generateConstructor();
generateNewImpl();
}
private void generateConstructor() {
startConstructor();
mv.visitVarInsn(ALOAD, 0);
superConstructor();
endConstructor();
}
private void generateNewImpl() {
startMethod("new_impl", PYOBJ, BOOLEAN, PYTYPE, APYOBJ, ASTRING);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ILOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ALOAD, 4);
mv.visitMethodInsn(INVOKESTATIC, onType.getInternalName(), name, NEW_DESCRIPTOR, false);
endMethod(ARETURN);
}
public static final String NEW_DESCRIPTOR = Type.getMethodDescriptor(PYOBJ,
new Type[] {PYNEWWRAPPER, BOOLEAN, PYTYPE, APYOBJ, ASTRING});
}