Explorar el Código

Merge remote-tracking branch 'remotes/kindlich/development' into development

Stan Hebben hace 6 años
padre
commit
5a853b46ae

+ 1
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Ver fichero

@@ -1660,6 +1660,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1660 1660
 		
1661 1661
 		final String descriptor = context.getMethodDescriptor(expression.header);
1662 1662
         final String signature = context.getMethodSignature(expression.header);
1663
+		final String signature2 = context.getMethodDescriptor(expression.header);
1663 1664
 		final String name = context.getLambdaCounter();
1664 1665
 
1665 1666
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", descriptor);

+ 18
- 7
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Ver fichero

@@ -1,6 +1,7 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler.definitions;
2 2
 
3
-import org.openzen.zenscript.javashared.JavaTypeGenericVisitor;
3
+import org.openzen.zenscript.codemodel.member.MethodMember;
4
+import org.openzen.zenscript.javashared.*;
4 5
 import org.objectweb.asm.ClassWriter;
5 6
 import org.objectweb.asm.Opcodes;
6 7
 import org.openzen.zenscript.codemodel.definition.*;
@@ -10,7 +11,6 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
10 11
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
11 12
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
12 13
 import org.openzen.zenscript.javabytecode.compiler.*;
13
-import org.openzen.zenscript.javashared.JavaClass;
14 14
 
15 15
 import java.io.FileOutputStream;
16 16
 import java.io.IOException;
@@ -18,9 +18,6 @@ import java.util.ArrayList;
18 18
 import java.util.List;
19 19
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
20 20
 import org.openzen.zenscript.codemodel.type.StoredType;
21
-import org.openzen.zenscript.javashared.JavaMethod;
22
-import org.openzen.zenscript.javashared.JavaModifiers;
23
-import org.openzen.zenscript.javashared.JavaVariantOption;
24 21
 
25 22
 
26 23
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
@@ -56,7 +53,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
56 53
 		}
57 54
         String signature = null;
58 55
 
59
-        writer.visit(Opcodes.V1_8, definition.modifiers, toClass.internalName, signature, superTypeInternalName, interfaces.toArray(new String[interfaces.size()]));
56
+        writer.visit(Opcodes.V1_8, definition.modifiers, toClass.internalName, signature, superTypeInternalName, interfaces.toArray(new String[0]));
60 57
 		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(context, writer, toClass, definition);
61 58
         for (IDefinitionMember member : definition.members) {
62 59
             member.accept(memberVisitor);
@@ -160,7 +157,21 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
160 157
 
161 158
 	@Override
162 159
 	public byte[] visitExpansion(ExpansionDefinition definition) {
163
-		return null;
160
+
161
+		JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
162
+		final JavaClass expansionClassInfo = context.getJavaModule(definition.module).getExpansionClassInfo(definition);
163
+		final String internalName = expansionClassInfo.internalName;
164
+
165
+		writer.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC |Opcodes.ACC_STATIC, internalName, null, "java/lang/Object", null);
166
+		JavaExpansionMemberVisitor memberVisitor = new JavaExpansionMemberVisitor(context, writer, expansionClassInfo, definition);
167
+
168
+		for (IDefinitionMember member : definition.members) {
169
+			member.accept(memberVisitor);
170
+		}
171
+		memberVisitor.end();
172
+		writer.visitEnd();
173
+
174
+		return writer.toByteArray();
164 175
 	}
165 176
 
166 177
 	@Override

+ 119
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaExpansionMemberVisitor.java Ver fichero

@@ -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
+}

Loading…
Cancelar
Guardar