|
@@ -15,6 +15,7 @@ import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
|
15
|
15
|
import org.openzen.zenscript.javashared.JavaCompiledModule;
|
16
|
16
|
import org.openzen.zenscript.javashared.JavaField;
|
17
|
17
|
import org.openzen.zenscript.javashared.JavaMethod;
|
|
18
|
+import org.openzen.zenscript.javashared.JavaParameterInfo;
|
18
|
19
|
|
19
|
20
|
import java.util.ArrayList;
|
20
|
21
|
import java.util.stream.Collectors;
|
|
@@ -175,32 +176,36 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
|
175
|
176
|
|
176
|
177
|
final ArrayList<TypeParameter> typeParameters = new ArrayList<>();
|
177
|
178
|
expandedClass.type.extractTypeParameters(typeParameters);
|
|
179
|
+ {
|
178
|
180
|
|
179
|
|
- final String descMiddle, signatureMiddle, signatureStart;
|
180
|
|
- if(typeParameters.isEmpty()) {
|
181
|
|
- descMiddle = signatureMiddle = signatureStart = "";
|
182
|
|
- } else {
|
183
|
|
- final StringBuilder descMiddleBuilder = new StringBuilder();
|
184
|
|
- final StringBuilder signatureMiddleBuilder = new StringBuilder();
|
185
|
|
- final StringBuilder signatureStartBuilder = new StringBuilder("<");
|
|
181
|
+ final String descMiddle, signatureMiddle, signatureStart;
|
|
182
|
+ if (typeParameters.isEmpty()) {
|
|
183
|
+ descMiddle = signatureMiddle = signatureStart = "";
|
|
184
|
+ } else {
|
|
185
|
+ final StringBuilder descMiddleBuilder = new StringBuilder();
|
|
186
|
+ final StringBuilder signatureMiddleBuilder = new StringBuilder();
|
|
187
|
+ final StringBuilder signatureStartBuilder = new StringBuilder("<");
|
|
188
|
+
|
|
189
|
+ for (TypeParameter typeParameter : typeParameters) {
|
|
190
|
+ descMiddleBuilder.append("Ljava/lang/Class;");
|
|
191
|
+ signatureMiddleBuilder.append("Ljava/lang/Class<T").append(typeParameter.name).append(";>;");
|
|
192
|
+ signatureStartBuilder.append(typeParameter.name).append(":Ljava/lang/Object;");
|
|
193
|
+ }
|
186
|
194
|
|
187
|
|
- for (TypeParameter typeParameter : typeParameters) {
|
188
|
|
- descMiddleBuilder.append("Ljava/lang/Class;");
|
189
|
|
- signatureMiddleBuilder.append("Ljava/lang/Class<T").append(typeParameter.name).append(";>;");
|
190
|
|
- signatureStartBuilder.append(typeParameter.name).append(":Ljava/lang/Object;");
|
|
195
|
+ descMiddle = descMiddleBuilder.toString();
|
|
196
|
+ signatureMiddle = signatureMiddleBuilder.toString();
|
|
197
|
+ signatureStart = signatureStartBuilder.append(">").toString();
|
191
|
198
|
}
|
192
|
199
|
|
193
|
|
- descMiddle = descMiddleBuilder.toString();
|
194
|
|
- signatureMiddle = signatureMiddleBuilder.toString();
|
195
|
|
- signatureStart = signatureStartBuilder.append(">").toString();
|
196
|
|
- }
|
197
|
200
|
|
198
|
|
- if (isStatic) {
|
199
|
|
- descriptor = "(" + descMiddle + ")" + context.getDescriptor(returnType);
|
200
|
|
- signature = signatureStart + "(" + signatureMiddle + ")" + context.getSignature(returnType);
|
201
|
|
- } else {
|
202
|
|
- descriptor = "(" + context.getDescriptor(expandedClass) + descMiddle + ")" + context.getDescriptor(returnType);
|
203
|
|
- signature = signatureStart + "(" + context.getSignature(expandedClass) + signatureMiddle + ")" + context.getSignature(returnType);
|
|
201
|
+ if (isStatic) {
|
|
202
|
+ descriptor = "(" + descMiddle + ")" + context.getDescriptor(returnType);
|
|
203
|
+ signature = signatureStart + "(" + signatureMiddle + ")" + context.getSignature(returnType);
|
|
204
|
+ } else {
|
|
205
|
+ descriptor = "(" + context.getDescriptor(expandedClass) + descMiddle + ")" + context.getDescriptor(returnType);
|
|
206
|
+ signature = signatureStart + "(" + context.getSignature(expandedClass) + signatureMiddle + ")" + context
|
|
207
|
+ .getSignature(returnType);
|
|
208
|
+ }
|
204
|
209
|
}
|
205
|
210
|
|
206
|
211
|
final Label methodStart = new Label();
|
|
@@ -236,16 +241,101 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
|
236
|
241
|
|
237
|
242
|
@Override
|
238
|
243
|
public Void visitSetter(SetterMember member) {
|
|
244
|
+ final boolean isStatic = member.isStatic();
|
|
245
|
+ final StoredType setterType = member.parameter.type;
|
|
246
|
+
|
|
247
|
+ final ArrayList<TypeParameter> typeParameters = new ArrayList<>();
|
|
248
|
+ expandedClass.type.extractTypeParameters(typeParameters);
|
|
249
|
+ CompilerUtils.tagMethodParameters(context, javaModule, member.getHeader(), isStatic, typeParameters);
|
|
250
|
+ setterType.type.extractTypeParameters(typeParameters);
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+ final String signature = context.getMethodSignatureExpansion(member.getHeader(), expandedClass);
|
|
254
|
+ final String description = context.getMethodDescriptorExpansion(member.getHeader(), expandedClass);
|
|
255
|
+
|
|
256
|
+ final Label methodStart = new Label();
|
|
257
|
+ final Label methodEnd = new Label();
|
|
258
|
+
|
|
259
|
+ final JavaMethod javaMethod = context.getJavaMethod(member);
|
|
260
|
+ final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, true, signature, description, new String[0]);
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+ methodWriter.label(methodStart);
|
|
264
|
+ if (!isStatic) {
|
|
265
|
+ methodWriter.nameVariable(0, "expandedObj", methodStart, methodEnd, context.getType(this.expandedClass));
|
|
266
|
+ methodWriter.nameParameter(0, "expandedObj");
|
|
267
|
+ }
|
|
268
|
+
|
|
269
|
+ int i = isStatic ? 0 : 1;
|
|
270
|
+ for (TypeParameter typeParameter : typeParameters) {
|
|
271
|
+ final String name = "typeOf" + typeParameter.name;
|
|
272
|
+ methodWriter.nameVariable(i, name, methodStart, methodEnd, Type.getType(Class.class));
|
|
273
|
+ methodWriter.nameParameter(0, name);
|
|
274
|
+ i++;
|
|
275
|
+ }
|
|
276
|
+
|
|
277
|
+ //in script you use $ but the parameter is named "value", which to choose?
|
|
278
|
+ //final String name = member.parameter.name;
|
|
279
|
+ final String name = "$";
|
|
280
|
+ methodWriter.nameVariable(i, name, methodStart, methodEnd, context.getType(setterType));
|
|
281
|
+ methodWriter.nameParameter(0, name);
|
|
282
|
+
|
|
283
|
+ javaModule.setParameterInfo(member.parameter, new JavaParameterInfo(i, context.getDescriptor(setterType)));
|
|
284
|
+
|
|
285
|
+ final JavaStatementVisitor javaStatementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
|
|
286
|
+ javaStatementVisitor.start();
|
|
287
|
+ member.body.accept(javaStatementVisitor);
|
|
288
|
+ javaStatementVisitor.end();
|
|
289
|
+ methodWriter.label(methodEnd);
|
|
290
|
+
|
239
|
291
|
return null;
|
240
|
292
|
}
|
241
|
293
|
|
242
|
294
|
@Override
|
243
|
295
|
public Void visitOperator(OperatorMember member) {
|
244
|
|
- return null;
|
|
296
|
+ final JavaMethod javaMethod = context.getJavaMethod(member);
|
|
297
|
+ final MethodMember methodMember = new MethodMember(member.position, member.definition, member.getEffectiveModifiers(), javaMethod.name, member.header, member.builtin);
|
|
298
|
+ methodMember.body = member.body;
|
|
299
|
+ methodMember.annotations = member.annotations;
|
|
300
|
+ javaModule.setMethodInfo(methodMember, javaMethod);
|
|
301
|
+
|
|
302
|
+ return methodMember.accept(this);
|
245
|
303
|
}
|
246
|
304
|
|
247
|
305
|
@Override
|
248
|
306
|
public Void visitCaster(CasterMember member) {
|
|
307
|
+
|
|
308
|
+ final ArrayList<TypeParameter> typeParameters = new ArrayList<>();
|
|
309
|
+ expandedClass.type.extractTypeParameters(typeParameters);
|
|
310
|
+
|
|
311
|
+ CompilerUtils.tagMethodParameters(context, javaModule, member.getHeader(), false, typeParameters);
|
|
312
|
+ member.toType.type.extractTypeParameters(typeParameters);
|
|
313
|
+
|
|
314
|
+ final String methodSignature = context.getMethodSignatureExpansion(member.getHeader(), expandedClass);
|
|
315
|
+ final String methodDescriptor = context.getMethodDescriptorExpansion(member.getHeader(), expandedClass);
|
|
316
|
+
|
|
317
|
+ final Label methodStart = new Label();
|
|
318
|
+ final Label methodEnd = new Label();
|
|
319
|
+
|
|
320
|
+ final JavaMethod javaMethod = context.getJavaMethod(member);
|
|
321
|
+ final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, true, methodSignature, methodDescriptor, new String[0]);
|
|
322
|
+
|
|
323
|
+ methodWriter.label(methodStart);
|
|
324
|
+ methodWriter.nameVariable(0, "expandedObj", methodStart, methodEnd, context.getType(this.expandedClass));
|
|
325
|
+ methodWriter.nameParameter(0, "expandedObj");
|
|
326
|
+
|
|
327
|
+ int i = 1;
|
|
328
|
+ for (TypeParameter typeParameter : typeParameters) {
|
|
329
|
+ final String name = "typeOf" + typeParameter.name;
|
|
330
|
+ methodWriter.nameVariable(i, name, methodStart, methodEnd, Type.getType(Class.class));
|
|
331
|
+ methodWriter.nameParameter(0, name);
|
|
332
|
+ }
|
|
333
|
+
|
|
334
|
+ final JavaStatementVisitor javaStatementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
|
|
335
|
+ javaStatementVisitor.start();
|
|
336
|
+ member.body.accept(javaStatementVisitor);
|
|
337
|
+ javaStatementVisitor.end();
|
|
338
|
+ methodWriter.label(methodEnd);
|
249
|
339
|
return null;
|
250
|
340
|
}
|
251
|
341
|
|
|
@@ -256,7 +346,14 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
|
256
|
346
|
|
257
|
347
|
@Override
|
258
|
348
|
public Void visitCaller(CallerMember member) {
|
259
|
|
- return null;
|
|
349
|
+ //It's gonna be a method anyways, so why not reuse the code ^^
|
|
350
|
+ final JavaMethod javaMethod = context.getJavaMethod(member);
|
|
351
|
+ final MethodMember call = new MethodMember(member.position, member.definition, member.getEffectiveModifiers(), javaMethod.name, member.header, member.builtin);
|
|
352
|
+ call.body = member.body;
|
|
353
|
+ call.annotations = member.annotations;
|
|
354
|
+
|
|
355
|
+ javaModule.setMethodInfo(call, javaMethod);
|
|
356
|
+ return call.accept(this);
|
260
|
357
|
}
|
261
|
358
|
|
262
|
359
|
@Override
|