|
@@ -0,0 +1,119 @@
|
|
1
|
+package org.openzen.zenscript.javabytecode.compiler.definitions;
|
|
2
|
+
|
|
3
|
+import org.objectweb.asm.ClassWriter;
|
|
4
|
+import org.objectweb.asm.Label;
|
|
5
|
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
|
|
6
|
+import org.openzen.zenscript.codemodel.member.*;
|
|
7
|
+import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
|
|
8
|
+import org.openzen.zenscript.javabytecode.compiler.CompilerUtils;
|
|
9
|
+import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
|
|
10
|
+import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
|
|
11
|
+import org.openzen.zenscript.javashared.JavaClass;
|
|
12
|
+import org.openzen.zenscript.javashared.JavaCompiledModule;
|
|
13
|
+import org.openzen.zenscript.javashared.JavaField;
|
|
14
|
+import org.openzen.zenscript.javashared.JavaMethod;
|
|
15
|
+
|
|
16
|
+public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
|
|
17
|
+
|
|
18
|
+ private final ClassWriter writer;
|
|
19
|
+ private final JavaBytecodeContext context;
|
|
20
|
+ private final JavaClass toClass;
|
|
21
|
+ private final HighLevelDefinition definition;
|
|
22
|
+ private final JavaCompiledModule javaModule;
|
|
23
|
+
|
|
24
|
+ public JavaExpansionMemberVisitor(JavaBytecodeContext context, ClassWriter writer, JavaClass toClass, HighLevelDefinition definition) {
|
|
25
|
+ this.writer = writer;
|
|
26
|
+ this.toClass = toClass;
|
|
27
|
+ this.definition = definition;
|
|
28
|
+ this.context = context;
|
|
29
|
+ javaModule = context.getJavaModule(definition.module);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ public void end() {
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ @Override
|
|
36
|
+ public Void visitConst(ConstMember member) {
|
|
37
|
+ JavaField field = context.getJavaField(member);
|
|
38
|
+ writer.visitField(CompilerUtils.calcAccess(member.getEffectiveModifiers()), field.name, field.descriptor, field.signature, null).visitEnd();
|
|
39
|
+ return null;
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ @Override
|
|
43
|
+ public Void visitField(FieldMember member) {
|
|
44
|
+ throw new IllegalStateException("Cannot add fields via expansions");
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ @Override
|
|
48
|
+ public Void visitConstructor(ConstructorMember member) {
|
|
49
|
+ throw new IllegalStateException("Cannot add constructors via expansions");
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ @Override
|
|
53
|
+ public Void visitDestructor(DestructorMember member) {
|
|
54
|
+ throw new IllegalStateException("Cannot add constructors via expansions");
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ @Override
|
|
58
|
+ public Void visitMethod(MethodMember member) {
|
|
59
|
+ final boolean isStatic = member.isStatic();
|
|
60
|
+ final JavaMethod method = context.getJavaMethod(member);
|
|
61
|
+ if(!method.compile)
|
|
62
|
+ return null;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+ CompilerUtils.tagMethodParameters(context, javaModule, member.header, member.isStatic());
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+ final Label methodStart = new Label();
|
|
69
|
+ final Label methodEnd = new Label();
|
|
70
|
+ final JavaWriter methodWriter = new JavaWriter(writer, method, definition, context.getMethodSignature(member.header), null);
|
|
71
|
+
|
|
72
|
+ return null;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Override
|
|
76
|
+ public Void visitGetter(GetterMember member) {
|
|
77
|
+ throw new IllegalStateException("Cannot add getters via expansions");
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Override
|
|
81
|
+ public Void visitSetter(SetterMember member) {
|
|
82
|
+ throw new IllegalStateException("Cannot add setters via expansions");
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Override
|
|
86
|
+ public Void visitOperator(OperatorMember member) {
|
|
87
|
+ return null;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ @Override
|
|
91
|
+ public Void visitCaster(CasterMember member) {
|
|
92
|
+ return null;
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ @Override
|
|
96
|
+ public Void visitCustomIterator(IteratorMember member) {
|
|
97
|
+ return null;
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ @Override
|
|
101
|
+ public Void visitCaller(CallerMember member) {
|
|
102
|
+ return null;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ @Override
|
|
106
|
+ public Void visitImplementation(ImplementationMember member) {
|
|
107
|
+ return null;
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Override
|
|
111
|
+ public Void visitInnerDefinition(InnerDefinitionMember member) {
|
|
112
|
+ return null;
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ @Override
|
|
116
|
+ public Void visitStaticInitializer(StaticInitializerMember member) {
|
|
117
|
+ throw new IllegalStateException("Cannot add Static initializers via expansions");
|
|
118
|
+ }
|
|
119
|
+}
|