Browse Source

More work on generics

This time for nonexpansions.
The method signatures should be calculated correctly now, though they are still only filled with nulls
kindlich 4 years ago
parent
commit
c984531cc3
No known key found for this signature in database

+ 34
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java View File

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.member.IDefinitionMember;
12 12
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13 13
 import org.openzen.zenscript.codemodel.type.StoredType;
14 14
 import org.openzen.zenscript.codemodel.type.TypeID;
15
+import org.openzen.zenscript.javashared.JavaField;
15 16
 import org.openzen.zenscript.javashared.JavaParameterInfo;
16 17
 
17 18
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
@@ -72,6 +73,38 @@ public class CompilerUtils {
72 73
     }
73 74
 
74 75
     public static void tagConstructorParameters(JavaBytecodeContext context, JavaCompiledModule module, HighLevelDefinition definition, FunctionHeader header, boolean isEnum) {
76
+		int index = 1;
77
+		for (TypeParameter typeParameter : definition.typeParameters) {
78
+			final JavaField field = new JavaField(context.getJavaClass(definition),
79
+					"typeOf" + typeParameter.name,
80
+					"Ljava/lang/Class;",
81
+					//"Ljava/lang/Class;"
82
+					"Ljava/lang/Class<T" + typeParameter.name + ";>;"
83
+			);
84
+			final JavaTypeParameterInfo info = new JavaTypeParameterInfo(index, field);
85
+			module.setTypeParameterInfo(typeParameter, info);
86
+			index++;
87
+		}
88
+
89
+		for (int i = 0; i < header.typeParameters.length; i++) {
90
+			TypeParameter typeParameter = header.typeParameters[i];
91
+			final JavaField field = new JavaField(context.getJavaClass(definition),
92
+					"typeOf" + typeParameter.name,
93
+					"Ljava/lang/Class;",
94
+					//"Ljava/lang/Class;"
95
+					"Ljava/lang/Class<T" + typeParameter.name + ";>;"
96
+					);
97
+			final JavaTypeParameterInfo info = new JavaTypeParameterInfo(index, field);
98
+			module.setTypeParameterInfo(typeParameter, info);
99
+			index++;
100
+		}
101
+		for (int i = 0; i < header.parameters.length; i++) {
102
+			FunctionParameter parameter = header.parameters[i];
103
+			String parameterType = context.getDescriptor(parameter.type);
104
+			module.setParameterInfo(parameter, new JavaParameterInfo(index, parameterType));
105
+			index++;
106
+		}
107
+		/*
75 108
 		int index = header.getNumberOfTypeParameters();
76 109
 		for (int i = 0; i < definition.typeParameters.length; i++) {
77 110
 			JavaTypeParameterInfo info = module.getTypeParameterInfo(definition.typeParameters[i]);
@@ -87,6 +120,7 @@ public class CompilerUtils {
87 120
             String parameterType = context.getDescriptor(parameter.type);
88 121
 			module.setParameterInfo(parameter, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
89 122
         }
123
+		 */
90 124
     }
91 125
 
92 126
     public static void writeDefaultFieldInitializers(JavaBytecodeContext context, JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {

+ 31
- 9
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

@@ -6,6 +6,7 @@ import org.objectweb.asm.Opcodes;
6 6
 import org.objectweb.asm.Type;
7 7
 import org.openzen.zenscript.codemodel.CompareType;
8 8
 import org.openzen.zenscript.codemodel.FunctionParameter;
9
+import org.openzen.zenscript.codemodel.annotations.NativeTag;
9 10
 import org.openzen.zenscript.codemodel.expression.*;
10 11
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
11 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -385,12 +386,15 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
385 386
 
386 387
 			final List<TypeParameter> typeParameters;
387 388
 			{
388
-				final List<TypeParameter> parameters = new ArrayList<>(
389
-						Arrays.asList(expression.member.getTarget().definition.typeParameters)
390
-				);
389
+
390
+				final List<TypeParameter> parameters = new ArrayList<>();
391
+				if(expression.member.getTarget().definition.isExpansion()) {
392
+					parameters.addAll(Arrays.asList(expression.member.getTarget().definition.typeParameters));
393
+				}
391 394
 
392 395
 				//expression.member.getOwnerType().type.extractTypeParameters(parameters);
393
-				for (TypeParameter typeParameter : expression.instancedHeader.typeParameters) {
396
+				//expression.instancedHeader.typeParameters
397
+				for (TypeParameter typeParameter : expression.member.getTarget().getHeader().typeParameters) {
394 398
 					if(!parameters.contains(typeParameter)) {
395 399
 						parameters.add(typeParameter);
396 400
 					}
@@ -403,6 +407,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
403 407
 			if(methodInfo.compile) {
404 408
 				for (TypeParameter typeParameter : typeParameters) {
405 409
 					javaWriter.aConstNull(); // TODO: Replace with actual class
410
+					javaWriter.checkCast("java/lang/Class");
406 411
 				}
407 412
 			}
408 413
 
@@ -1313,9 +1318,11 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
1313 1318
 		//expression.member.type.type.extractTypeParameters(typeParameters);
1314 1319
 		expression.member.toType.type.extractTypeParameters(typeParameters);
1315 1320
 
1316
-		for (TypeParameter typeParameter : typeParameters) {
1317
-			javaWriter.aConstNull(); //Todo: Replace with actual Type
1318
-			javaWriter.checkCast("java/lang/Class");
1321
+		if (expression.member.member.definition.isExpansion()) {
1322
+			for (TypeParameter typeParameter : typeParameters) {
1323
+				javaWriter.aConstNull(); //Todo: Replace with actual Type
1324
+				javaWriter.checkCast("java/lang/Class");
1325
+			}
1319 1326
 		}
1320 1327
 
1321 1328
 		BuiltinID builtin = expression.member.member.builtin;
@@ -2160,6 +2167,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2160 2167
 	public Void visitGetField(GetFieldExpression expression) {
2161 2168
 		expression.target.accept(this);
2162 2169
 		getField(expression.field);
2170
+		javaWriter.checkCast(context.getType(expression.field.getType()));
2163 2171
 		return null;
2164 2172
 	}
2165 2173
 
@@ -2209,6 +2217,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2209 2217
 		if (builtin == null) {
2210 2218
 			if (context.hasJavaField(expression.getter)) {
2211 2219
 				javaWriter.getField(context.getJavaField(expression.getter));
2220
+				javaWriter.checkCast(context.getType(expression.getter.getType()));
2212 2221
 				return null;
2213 2222
 			}
2214 2223
 
@@ -2216,13 +2225,17 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2216 2225
 			final List<TypeParameter> typeParameters = new ArrayList<>();
2217 2226
 			expression.getter.member.getType().type.extractTypeParameters(typeParameters);
2218 2227
 
2219
-			for (TypeParameter typeParameter : typeParameters) {
2220
-				javaWriter.aConstNull(); //TODO: Replace with actual type
2228
+			if(expression.getter.member.definition.isExpansion()) {
2229
+				for (TypeParameter typeParameter : typeParameters) {
2230
+					javaWriter.aConstNull(); //TODO: Replace with actual type
2231
+					javaWriter.checkCast("java/lang/Class");
2232
+				}
2221 2233
 			}
2222 2234
 
2223 2235
 			if (!checkAndExecuteMethodInfo(expression.getter, expression.type, expression))
2224 2236
 				throw new IllegalStateException("Call target has no method info!");
2225 2237
 
2238
+			javaWriter.checkCast(context.getType(expression.getter.getType()));
2226 2239
 			return null;
2227 2240
 		}
2228 2241
 
@@ -2535,6 +2548,15 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2535 2548
 		javaWriter.newObject(method.cls);
2536 2549
 		javaWriter.dup();
2537 2550
 
2551
+
2552
+		if(!expression.constructor.getTarget().hasTag(NativeTag.class)) {
2553
+			for (StoredType typeArgument : expression.type.asDefinition().typeArguments) {
2554
+				javaWriter.aConstNull();
2555
+				javaWriter.checkCast("java/lang/Class");
2556
+			}
2557
+		}
2558
+
2559
+
2538 2560
 		for (Expression argument : expression.arguments.arguments) {
2539 2561
 			argument.accept(this);
2540 2562
 		}

+ 6
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaNonPushingExpressionVisitor.java View File

@@ -625,9 +625,12 @@ public class JavaNonPushingExpressionVisitor implements ExpressionVisitor<Void>
625 625
 	@Override
626 626
 	public Void visitSetter(SetterExpression expression) {
627 627
 		expression.target.accept(original);
628
-		for (TypeParameter typeParameter : expression.setter.member.definition.typeParameters) {
629
-			javaWriter.aConstNull(); //TODO replace with actual type
630
-			javaWriter.checkCast("java/lang/Class");
628
+
629
+		if (expression.setter.member.definition.isExpansion()) {
630
+			for (TypeParameter typeParameter : expression.setter.member.definition.typeParameters) {
631
+				javaWriter.aConstNull(); //TODO replace with actual type
632
+				javaWriter.checkCast("java/lang/Class");
633
+			}
631 634
 		}
632 635
 
633 636
 		expression.value.accept(original);

+ 1
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java View File

@@ -49,6 +49,7 @@ public class JavaWriter {
49 49
 			String[] exceptions,
50 50
 			String... annotations) {
51 51
 		this(position, visitor, nameVariables, method, forDefinition, false, signature, method.descriptor, exceptions, annotations);
52
+		this.position(position.fromLine);
52 53
 	}
53 54
 	
54 55
 	

+ 35
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java View File

@@ -64,9 +64,43 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
64 64
 			if (member instanceof ImplementationMember)
65 65
 				interfaces.add(context.getInternalName(((ImplementationMember) member).type));
66 66
 		}
67
-        String signature = null;
67
+        String signature;
68
+
69
+		{
70
+			final StringBuilder signatureBuilder = new StringBuilder();
71
+			if(definition.typeParameters.length != 0) {
72
+				signatureBuilder.append("<");
73
+				for (TypeParameter typeParameter : definition.typeParameters) {
74
+					signatureBuilder.append(typeParameter.name);
75
+					signatureBuilder.append(":");
76
+					signatureBuilder.append("Ljava/lang/Object;");
77
+				}
78
+				signatureBuilder.append(">");
79
+			}
80
+
81
+			signatureBuilder.append("L").append(superTypeInternalName).append(";");
82
+			for (IDefinitionMember member : definition.members) {
83
+				if(member instanceof ImplementationMember) {
84
+					signatureBuilder.append(context.getInternalName(((ImplementationMember) member).type));
85
+				}
86
+			}
87
+
88
+			signature = signatureBuilder.toString();
89
+		}
68 90
 
69 91
         writer.visit(Opcodes.V1_8, definition.modifiers, toClass.internalName, signature, superTypeInternalName, interfaces.toArray(new String[0]));
92
+		for (TypeParameter typeParameter : definition.typeParameters) {
93
+			//Add it to the class
94
+			writer.visitField(
95
+					Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL,
96
+					"typeOf" + typeParameter.name,
97
+					"Ljava/lang/Class;",
98
+					"Ljava/lang/Class<T" + typeParameter.name + ";>;",
99
+					//"Ljava/lang/Class;",
100
+					null
101
+			);
102
+		}
103
+
70 104
 		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(context, writer, toClass, definition);
71 105
         for (IDefinitionMember member : definition.members) {
72 106
             member.accept(memberVisitor);

+ 126
- 7
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java View File

@@ -7,19 +7,20 @@ import org.objectweb.asm.Type;
7 7
 import org.openzen.zenscript.codemodel.FunctionParameter;
8 8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9 9
 import org.openzen.zenscript.codemodel.Modifiers;
10
+import org.openzen.zenscript.codemodel.annotations.NativeTag;
10 11
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 14
 import org.openzen.zenscript.codemodel.member.*;
15
+import org.openzen.zenscript.codemodel.type.StoredType;
13 16
 import org.openzen.zenscript.javabytecode.compiler.*;
14 17
 
18
+import java.util.ArrayList;
19
+import java.util.Arrays;
15 20
 import java.util.Collections;
16 21
 import java.util.List;
17 22
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
18
-import org.openzen.zenscript.javashared.JavaClass;
19
-import org.openzen.zenscript.javashared.JavaCompiledModule;
20
-import org.openzen.zenscript.javashared.JavaField;
21
-import org.openzen.zenscript.javashared.JavaImplementation;
22
-import org.openzen.zenscript.javashared.JavaMethod;
23
+import org.openzen.zenscript.javashared.*;
23 24
 
24 25
 public class JavaMemberVisitor implements MemberVisitor<Void> {
25 26
     private final ClassWriter writer;
@@ -67,6 +68,22 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
67 68
         final JavaWriter constructorWriter = new JavaWriter(member.position, writer, method, definition, context.getMethodSignature(member.header), null);
68 69
         constructorWriter.label(constructorStart);
69 70
         CompilerUtils.tagConstructorParameters(context, javaModule, member.definition, member.header, isEnum);
71
+        if(isEnum) {
72
+			constructorWriter.nameParameter(0, "name");
73
+			constructorWriter.nameParameter(0, "index");
74
+		}
75
+
76
+		for (TypeParameter typeParameter : definition.typeParameters) {
77
+			constructorWriter.nameParameter(0, "typeof" + typeParameter.name);
78
+			constructorWriter.nameVariable(
79
+					javaModule.getTypeParameterInfo(typeParameter).parameterIndex,
80
+					"typeOf" + typeParameter.name,
81
+					constructorStart,
82
+					constructorEnd,
83
+					Type.getType(Class.class)
84
+			);
85
+		}
86
+
70 87
         for (FunctionParameter parameter : member.header.parameters) {
71 88
             constructorWriter.nameVariable(
72 89
                     javaModule.getParameterInfo(parameter).index,
@@ -95,6 +112,17 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
95 112
 			}
96 113
         }
97 114
 
115
+		for (TypeParameter typeParameter : definition.typeParameters) {
116
+			final JavaTypeParameterInfo typeParameterInfo = javaModule.getTypeParameterInfo(typeParameter);
117
+			final JavaField field = typeParameterInfo.field;
118
+
119
+			//Init from Constructor
120
+			final int parameterIndex = typeParameterInfo.parameterIndex;
121
+			constructorWriter.loadObject(0);
122
+			constructorWriter.loadObject(parameterIndex);
123
+			constructorWriter.putField(field);
124
+		}
125
+
98 126
 		if (member.body != null) {
99 127
 			member.body.accept(statementVisitor);
100 128
 		}
@@ -156,21 +184,105 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
156 184
 
157 185
 	@Override
158 186
 	public Void visitGetter(GetterMember member) {
187
+		if (member.hasTag(NativeTag.class)) {
188
+			return null;
189
+		}
190
+
191
+		final String descriptor = context.getMethodDescriptor(member.getHeader());
192
+		final String signature = context.getMethodSignature(member.getHeader(), true);
193
+
194
+		final Label methodStart = new Label();
195
+		final Label methodEnd = new Label();
196
+
197
+		final JavaMethod method = context.getJavaMethod(member);
198
+		final JavaWriter methodWriter = new JavaWriter(member.position, this.writer, true, method, definition, false, signature, descriptor, new String[0]);
199
+
200
+		methodWriter.label(methodStart);
201
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
202
+		statementVisitor.start();
203
+		member.body.accept(statementVisitor);
204
+		methodWriter.label(methodEnd);
205
+		statementVisitor.end();
206
+
159 207
 		return null;
160 208
 	}
161 209
 
162 210
 	@Override
163 211
 	public Void visitSetter(SetterMember member) {
212
+		final String signature = context.getMethodSignature(member.getHeader());
213
+		final String description = context.getMethodDescriptor(member.getHeader());
214
+
215
+		final Label methodStart = new Label();
216
+		final Label methodEnd = new Label();
217
+
218
+		final JavaMethod javaMethod = context.getJavaMethod(member);
219
+		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, false, signature, description, new String[0]);
220
+		methodWriter.label(methodStart);
221
+
222
+		//in script you use $ but the parameter is named "value", which to choose?
223
+		//final String name = member.parameter.name;
224
+		final String name = "$";
225
+		methodWriter.nameVariable(1, name, methodStart, methodEnd, context.getType(member.getType()));
226
+		methodWriter.nameParameter(0, name);
227
+
228
+		javaModule.setParameterInfo(member.parameter, new JavaParameterInfo(1, context.getDescriptor(member.getType())));
229
+
230
+		final JavaStatementVisitor javaStatementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
231
+		javaStatementVisitor.start();
232
+		member.body.accept(javaStatementVisitor);
233
+		javaStatementVisitor.end();
234
+		methodWriter.label(methodEnd);
235
+
164 236
 		return null;
165 237
 	}
166 238
 
167 239
 	@Override
168 240
 	public Void visitOperator(OperatorMember member) {
169
-		return null;
241
+
242
+		final JavaMethod javaMethod = context.getJavaMethod(member);
243
+		final MethodMember methodMember = new MethodMember(member.position, member.definition, member.getEffectiveModifiers(), javaMethod.name, member.header, member.builtin);
244
+		methodMember.body = member.body;
245
+		methodMember.annotations = member.annotations;
246
+		javaModule.setMethodInfo(methodMember, javaMethod);
247
+
248
+		return methodMember.accept(this);
170 249
 	}
171 250
 
172 251
 	@Override
173 252
 	public Void visitCaster(CasterMember member) {
253
+		final JavaMethod javaMethod = context.getJavaMethod(member);
254
+		if(javaMethod == null || !javaMethod.compile) {
255
+			return null;
256
+		}
257
+
258
+		final ArrayList<TypeParameter> typeParameters = new ArrayList<>(Arrays.asList(this.definition.typeParameters));
259
+
260
+		CompilerUtils.tagMethodParameters(context, javaModule, member.getHeader(), false, typeParameters);
261
+		member.toType.type.extractTypeParameters(typeParameters);
262
+
263
+		final String methodSignature = context.getMethodSignature(member.getHeader());
264
+		final String methodDescriptor = context.getMethodDescriptor(member.getHeader());
265
+
266
+		final Label methodStart = new Label();
267
+		final Label methodEnd = new Label();
268
+
269
+
270
+		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, false, methodSignature, methodDescriptor, new String[0]);
271
+
272
+		methodWriter.label(methodStart);
273
+
274
+		int i = 1;
275
+		for (TypeParameter typeParameter : typeParameters) {
276
+			final String name = "typeOf" + typeParameter.name;
277
+			methodWriter.nameVariable(i, name, methodStart, methodEnd, Type.getType(Class.class));
278
+			methodWriter.nameParameter(0, name);
279
+		}
280
+
281
+		final JavaStatementVisitor javaStatementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
282
+		javaStatementVisitor.start();
283
+		member.body.accept(javaStatementVisitor);
284
+		javaStatementVisitor.end();
285
+		methodWriter.label(methodEnd);
174 286
 		return null;
175 287
 	}
176 288
 
@@ -181,7 +293,14 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
181 293
 
182 294
 	@Override
183 295
 	public Void visitCaller(CallerMember member) {
184
-		return null;
296
+		//It's gonna be a method anyways, so why not reuse the code ^^
297
+		final JavaMethod javaMethod = context.getJavaMethod(member);
298
+		final MethodMember call = new MethodMember(member.position, member.definition, member.getEffectiveModifiers(), javaMethod.name, member.header, member.builtin);
299
+		call.body = member.body;
300
+		call.annotations = member.annotations;
301
+
302
+		javaModule.setMethodInfo(call, javaMethod);
303
+		return call.accept(this);
185 304
 	}
186 305
 
187 306
 	@Override

+ 11
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java View File

@@ -15,9 +15,11 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
15 15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
16 16
 import org.openzen.zenscript.codemodel.Modifiers;
17 17
 import org.openzen.zenscript.codemodel.Module;
18
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
18 19
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
19 20
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
20 21
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
22
+import org.openzen.zenscript.codemodel.member.DefinitionMember;
21 23
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
22 24
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
23 25
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
@@ -370,7 +372,7 @@ public abstract class JavaContext {
370 372
 	 *                        Can be null or an empty string if this is not an expansion method header
371 373
 	 * @return Method descriptor {@code (<LClass;*No.TypeParameters><LString;I if enum><expandedType><headerTypes>)<retType> }
372 374
 	 */
373
-	private String getMethodDescriptor(FunctionHeader header, boolean isEnumConstructor, String expandedType) {
375
+	public String getMethodDescriptor(FunctionHeader header, boolean isEnumConstructor, String expandedType) {
374 376
         StringBuilder descBuilder = new StringBuilder("(");
375 377
 		for (int i = 0; i < header.getNumberOfTypeParameters(); i++)
376 378
 			descBuilder.append("Ljava/lang/Class;");
@@ -389,4 +391,12 @@ public abstract class JavaContext {
389 391
         descBuilder.append(getDescriptor(header.getReturnType()));
390 392
         return descBuilder.toString();
391 393
     }
394
+
395
+	public String getMethodDescriptorConstructor(FunctionHeader header, DefinitionMember member) {
396
+		StringBuilder startBuilder = new StringBuilder();
397
+		for (TypeParameter typeParameter : member.definition.typeParameters) {
398
+			startBuilder.append("Ljava/lang/Class;");
399
+		}
400
+		return getMethodDescriptor(header, member.definition instanceof EnumDefinition, startBuilder.toString());
401
+	}
392 402
 }

+ 5
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeParameterInfo.java View File

@@ -22,4 +22,9 @@ public class JavaTypeParameterInfo {
22 22
 		this.parameterIndex = -1;
23 23
 		this.field = field;
24 24
 	}
25
+
26
+	public JavaTypeParameterInfo(int parameterIndex, JavaField field) {
27
+		this.parameterIndex = parameterIndex;
28
+		this.field = field;
29
+	}
25 30
 }

+ 22
- 9
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java View File

@@ -313,15 +313,28 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
313 313
 					header.getReturnType().type instanceof GenericTypeID,
314 314
 					header.useTypeParameters());
315 315
 		} else if (method == null) {
316
-			method = new JavaMethod(
317
-					cls,
318
-					getKind(member),
319
-					name,
320
-					true,
321
-					context.getMethodDescriptor(header),
322
-					modifiers | JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
323
-					header.getReturnType().type instanceof GenericTypeID,
324
-					header.useTypeParameters());
316
+			if(member instanceof ConstructorMember) {
317
+				method = new JavaMethod(
318
+						cls,
319
+						getKind(member),
320
+						name,
321
+						true,
322
+						context.getMethodDescriptorConstructor(header, member),
323
+						modifiers | JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
324
+						false,
325
+						header.useTypeParameters()
326
+				);
327
+			} else {
328
+				method = new JavaMethod(
329
+						cls,
330
+						getKind(member),
331
+						name,
332
+						true,
333
+						context.getMethodDescriptor(header),
334
+						modifiers | JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
335
+						header.getReturnType().type instanceof GenericTypeID,
336
+						header.useTypeParameters());
337
+			}
325 338
 		}
326 339
 		
327 340
 		if (method.compile && member.getBuiltin() != BuiltinID.CLASS_DEFAULT_CONSTRUCTOR) {

+ 28
- 14
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java View File

@@ -168,22 +168,36 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
168 168
 		if (nativeTag != null && nativeClass != null)
169 169
 			method = nativeClass.getMethod(nativeTag.value);
170 170
 		if (method == null) {
171
-			final JavaMethod.Kind kind = getKind(member);
172
-			final String descriptor;
173
-			if (kind == JavaMethod.Kind.EXPANSION && member.definition instanceof ExpansionDefinition) {
174
-				descriptor = context.getMethodDescriptorExpansion(header, ((ExpansionDefinition) member.definition).target);
171
+
172
+			if(member instanceof ConstructorMember) {
173
+				method = new JavaMethod(
174
+						cls,
175
+						getKind(member),
176
+						name,
177
+						true,
178
+						context.getMethodDescriptorConstructor(header, member),
179
+						JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
180
+						false,
181
+						header.useTypeParameters()
182
+				);
175 183
 			} else {
176
-				descriptor = context.getMethodDescriptor(header);
184
+				final JavaMethod.Kind kind = getKind(member);
185
+				final String descriptor;
186
+				if (kind == JavaMethod.Kind.EXPANSION && member.definition instanceof ExpansionDefinition) {
187
+					descriptor = context.getMethodDescriptorExpansion(header, ((ExpansionDefinition) member.definition).target);
188
+				} else {
189
+					descriptor = context.getMethodDescriptor(header);
190
+				}
191
+				method = new JavaMethod(
192
+						cls,
193
+						kind,
194
+						name,
195
+						true,
196
+						descriptor,
197
+						JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
198
+						header.getReturnType().type instanceof GenericTypeID,
199
+						header.useTypeParameters());
177 200
 			}
178
-			method = new JavaMethod(
179
-					cls,
180
-					kind,
181
-					name,
182
-					true,
183
-					descriptor,
184
-					JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
185
-					header.getReturnType().type instanceof GenericTypeID,
186
-					header.useTypeParameters());
187 201
 		}
188 202
 		
189 203
 		if (method.compile) {

Loading…
Cancel
Save