ソースを参照

Fix expansion method signature and call

Signature: Include the type in the signature if it is an expansion method
Call: Call invokeStatic if its an expansion method
kindlich 5年前
コミット
d2fdb13730
この署名に対応する既知のキーがデータベースに存在しません

+ 3
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java ファイルの表示

@@ -4220,9 +4220,11 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
4220 4220
 			getJavaWriter().invokeStatic(methodInfo);
4221 4221
 		} else if (methodInfo.kind == JavaMethod.Kind.INTERFACE) {
4222 4222
 			getJavaWriter().invokeInterface(methodInfo);
4223
+		} else if (methodInfo.kind == JavaMethod.Kind.EXPANSION) {
4224
+			getJavaWriter().invokeStatic(methodInfo);
4223 4225
 		} else if (methodInfo.kind == JavaMethod.Kind.COMPILED) {
4224 4226
 			Objects.requireNonNull(methodInfo.translation).translate(expression, this);
4225
-		} else if (methodInfo.cls.kind == JavaClass.Kind.INTERFACE) {
4227
+		} else if (methodInfo.cls != null && methodInfo.cls.kind == JavaClass.Kind.INTERFACE) {
4226 4228
 			getJavaWriter().invokeInterface(methodInfo);
4227 4229
 		} else {
4228 4230
 			getJavaWriter().invokeVirtual(methodInfo);

+ 19
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java ファイルの表示

@@ -221,7 +221,11 @@ public abstract class JavaContext {
221 221
 	}
222 222
 	
223 223
 	public String getMethodDescriptor(FunctionHeader header) {
224
-		return getMethodDescriptor(header, false);
224
+		return getMethodDescriptor(header, false, "");
225
+	}
226
+
227
+	public String getMethodDescriptorExpansion(FunctionHeader header, StoredType expandedType) {
228
+		return getMethodDescriptor(header, false, getDescriptor(expandedType));
225 229
 	}
226 230
 	
227 231
     public String getMethodSignature(FunctionHeader header) {
@@ -229,7 +233,7 @@ public abstract class JavaContext {
229 233
     }
230 234
 	
231 235
 	public String getEnumConstructorDescriptor(FunctionHeader header) {
232
-		return getMethodDescriptor(header, true);
236
+		return getMethodDescriptor(header, true, "");
233 237
 	}
234 238
 	
235 239
 	public JavaSynthesizedFunctionInstance getFunction(FunctionTypeID type) {
@@ -339,14 +343,25 @@ public abstract class JavaContext {
339 343
 			return new JavaSynthesizedClass(range.cls, new TypeID[] { type.baseType.type });
340 344
 		}
341 345
 	}
342
-	
343
-	private String getMethodDescriptor(FunctionHeader header, boolean isEnumConstructor) {
346
+
347
+	/**
348
+	 * @param header Function Header
349
+	 * @param isEnumConstructor If this is an enum constructor, add String, int as parameters
350
+	 * @param expandedType If this is for an expanded type, add the type at the beginning.
351
+	 *                        Can be null or an empty string if this is not an expansion method header
352
+	 * @return Method descriptor {@code (<LClass;*No.TypeParameters><LString;I if enum><expandedType><headerTypes>)<retType> }
353
+	 */
354
+	private String getMethodDescriptor(FunctionHeader header, boolean isEnumConstructor, String expandedType) {
344 355
         StringBuilder descBuilder = new StringBuilder("(");
345 356
 		for (int i = 0; i < header.getNumberOfTypeParameters(); i++)
346 357
 			descBuilder.append("Ljava/lang/Class;");
347 358
 		
348 359
         if (isEnumConstructor)
349 360
             descBuilder.append("Ljava/lang/String;I");
361
+
362
+        //TODO: Put this earlier? We'd need to agree on one...
363
+        if(expandedType != null)
364
+        	descBuilder.append(expandedType);
350 365
 		
351 366
         for (FunctionParameter parameter : header.parameters) {
352 367
 			descBuilder.append(getDescriptor(parameter.type));

+ 13
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java ファイルの表示

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.javashared.prepare;
7 7
 
8
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
8 9
 import org.openzen.zenscript.javashared.JavaNativeClass;
9 10
 import org.openzen.zencode.shared.StringExpansion;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
@@ -166,16 +167,24 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
166 167
 		JavaMethod method = null;
167 168
 		if (nativeTag != null && nativeClass != null)
168 169
 			method = nativeClass.getMethod(nativeTag.value);
169
-		if (method == null)
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);
175
+			} else {
176
+				descriptor = context.getMethodDescriptor(header);
177
+			}
170 178
 			method = new JavaMethod(
171 179
 					cls,
172
-					getKind(member),
180
+					kind,
173 181
 					name,
174 182
 					true,
175
-					context.getMethodDescriptor(header),
183
+					descriptor,
176 184
 					JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
177 185
 					header.getReturnType().type instanceof GenericTypeID,
178
-					header.useTypeParameters()); 
186
+					header.useTypeParameters());
187
+		}
179 188
 		
180 189
 		if (method.compile) {
181 190
 			if (DEBUG_EMPTY && cls.empty)

読み込み中…
キャンセル
保存