Browse Source

- Starting work on improving type parameter usage in generic methods

Stan Hebben 6 years ago
parent
commit
b0895350cb
27 changed files with 258 additions and 35 deletions
  1. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java
  3. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java
  4. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeVisitorWithContext.java
  5. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  6. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java
  7. 17
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  8. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaBoxingTypeVisitor.java
  9. 8
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  10. 136
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeExpressionVisitor.java
  11. 4
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  12. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  13. 9
    14
      JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java
  14. 1
    1
      JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java
  15. 14
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java
  16. 7
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaMethod.java
  17. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java
  18. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeGenericVisitor.java
  19. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInfo.java
  20. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java
  21. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeNameVisitor.java
  22. 25
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeParameterInfo.java
  23. 5
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  24. 9
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java
  25. 1
    1
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/TypeSerializer.java
  26. 1
    1
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java
  27. 1
    1
      common.gradle

+ 8
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java View File

@@ -113,6 +113,14 @@ public class FunctionHeader {
113 113
 		hasUnknowns = hasUnknowns(parameters, returnType);
114 114
 	}
115 115
 	
116
+	public boolean[] useTypeParameters() {
117
+		boolean[] useTypeParameters = new boolean[typeParameters.length];
118
+		for (int i = 0; i < useTypeParameters.length; i++)
119
+			useTypeParameters[i] = true;
120
+		
121
+		return useTypeParameters;
122
+	}
123
+	
116 124
 	public StoredType getReturnType() {
117 125
 		return returnType;
118 126
 	}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java View File

@@ -45,7 +45,7 @@ public class OptionalTypeID implements TypeID {
45 45
 	
46 46
 	@Override
47 47
 	public <C, R, E extends Exception> R accept(C context, TypeVisitorWithContext<C, R, E> visitor) throws E {
48
-		return visitor.visitModified(context, this);
48
+		return visitor.visitOptional(context, this);
49 49
 	}
50 50
 
51 51
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java View File

@@ -148,7 +148,7 @@ public class TypeMatcher implements TypeVisitorWithContext<TypeMatcher.Matching,
148 148
 	}
149 149
 
150 150
 	@Override
151
-	public Boolean visitModified(Matching context, OptionalTypeID type) {
151
+	public Boolean visitOptional(Matching context, OptionalTypeID type) {
152 152
 		if (context.type.type instanceof OptionalTypeID) {
153 153
 			OptionalTypeID modified = (OptionalTypeID) context.type.type;
154 154
 			return match(context, modified.baseType.stored(), type.baseType.stored());

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeVisitorWithContext.java View File

@@ -30,7 +30,7 @@ public interface TypeVisitorWithContext<C, R, E extends Exception> {
30 30
 	
31 31
 	R visitRange(C context, RangeTypeID range) throws E;
32 32
 	
33
-	R visitModified(C context, OptionalTypeID type) throws E;
33
+	R visitOptional(C context, OptionalTypeID type) throws E;
34 34
 	
35 35
 	default R visitInvalid(C context, InvalidTypeID type) throws E {
36 36
 		throw new RuntimeException("Invalid type: " + type.message);

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java View File

@@ -576,7 +576,7 @@ public class TypeMemberBuilder implements TypeVisitorWithContext<Void, Void, Run
576 576
 	}
577 577
 
578 578
 	@Override
579
-	public Void visitModified(Void context, OptionalTypeID modified) {
579
+	public Void visitOptional(Void context, OptionalTypeID modified) {
580 580
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "modified", Modifiers.PUBLIC, null);
581 581
 		modified.baseType.accept(context, this);
582 582
 		

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java View File

@@ -28,7 +28,7 @@ import org.openzen.zenscript.javashared.JavaTypeUtils;
28 28
  * @author Hoofdgebruiker
29 29
  */
30 30
 public class JavaBytecodeContext extends JavaContext {
31
-	private final JavaBytecodeModule target;
31
+	public final JavaBytecodeModule target;
32 32
 	private final TypeGenerator typeGenerator;
33 33
 	private final JavaTypeInternalNameVisitor internalNameVisitor;
34 34
 	private final JavaTypeDescriptorVisitor descriptorVisitor;

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

@@ -6,6 +6,7 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
6 6
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
7 7
 import org.openzen.zenscript.codemodel.Modifiers;
8 8
 import org.openzen.zenscript.codemodel.expression.switchvalue.*;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
9 10
 import org.openzen.zenscript.codemodel.member.FieldMember;
10 11
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11 12
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -15,6 +16,7 @@ import org.openzen.zenscript.javashared.JavaParameterInfo;
15 16
 
16 17
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
17 18
 import org.openzen.zenscript.javashared.JavaCompiledModule;
19
+import org.openzen.zenscript.javashared.JavaTypeParameterInfo;
18 20
 
19 21
 public class CompilerUtils {
20 22
 
@@ -48,7 +50,10 @@ public class CompilerUtils {
48 50
 
49 51
     public static void tagMethodParameters(JavaBytecodeContext context, JavaCompiledModule module, FunctionHeader header, boolean isStatic) {
50 52
 		int index = header.getNumberOfTypeParameters();
51
-		
53
+		for (int i = 0; i < header.typeParameters.length; i++) {
54
+			TypeParameter parameter = header.typeParameters[i];
55
+			module.setTypeParameterInfo(parameter, new JavaTypeParameterInfo(index++));
56
+		}
52 57
         for (int i = 0; i < header.parameters.length; i++) {
53 58
             FunctionParameter parameter = header.parameters[i];
54 59
             String parameterType = context.getDescriptor(parameter.type);
@@ -57,7 +62,17 @@ public class CompilerUtils {
57 62
         }
58 63
     }
59 64
 
60
-    public static void tagConstructorParameters(JavaBytecodeContext context, JavaCompiledModule module, FunctionHeader header, boolean isEnum) {
65
+    public static void tagConstructorParameters(JavaBytecodeContext context, JavaCompiledModule module, HighLevelDefinition definition, FunctionHeader header, boolean isEnum) {
66
+		int index = header.getNumberOfTypeParameters();
67
+		for (int i = 0; i < definition.typeParameters.length; i++) {
68
+			JavaTypeParameterInfo info = module.getTypeParameterInfo(definition.typeParameters[i]);
69
+			if (info.field != null)
70
+				index++;
71
+		}
72
+		for (int i = 0; i < header.typeParameters.length; i++) {
73
+			TypeParameter parameter = header.typeParameters[i];
74
+			module.setTypeParameterInfo(parameter, new JavaTypeParameterInfo(index++));
75
+		}
61 76
         for (int i = 0; i < header.parameters.length; i++) {
62 77
             FunctionParameter parameter = header.parameters[i];
63 78
             String parameterType = context.getDescriptor(parameter.type);

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

@@ -122,7 +122,7 @@ public class JavaBoxingTypeVisitor implements TypeVisitorWithContext<StoredType,
122 122
 	}
123 123
 
124 124
 	@Override
125
-	public Void visitModified(StoredType context, OptionalTypeID type) {
125
+	public Void visitOptional(StoredType context, OptionalTypeID type) {
126 126
 		//NO-OP
127 127
 		return null;
128 128
 	}

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

@@ -376,6 +376,14 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
376 376
 		BuiltinID builtin = expression.member.getBuiltin();
377 377
 		if (builtin == null) {
378 378
 			expression.target.accept(this);
379
+			
380
+			JavaMethod methodInfo = context.getJavaMethod(expression.member);
381
+			for (int i = 0; i < expression.arguments.typeArguments.length; i++) {
382
+				if (methodInfo.typeParameterArguments[i]) {
383
+					StoredType arguments = expression.arguments.typeArguments[i];
384
+					
385
+				}
386
+			}
379 387
 			for (Expression argument : expression.arguments.arguments) {
380 388
 				argument.accept(this);
381 389
 			}

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

@@ -0,0 +1,136 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode.compiler;
7
+
8
+import java.util.Iterator;
9
+import java.util.Map;
10
+import org.openzen.zenscript.codemodel.type.ArrayTypeID;
11
+import org.openzen.zenscript.codemodel.type.AssocTypeID;
12
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
+import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
14
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
15
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
16
+import org.openzen.zenscript.codemodel.type.GenericTypeID;
17
+import org.openzen.zenscript.codemodel.type.IteratorTypeID;
18
+import org.openzen.zenscript.codemodel.type.OptionalTypeID;
19
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
20
+import org.openzen.zenscript.codemodel.type.StringTypeID;
21
+import org.openzen.zenscript.codemodel.type.TypeVisitorWithContext;
22
+import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
23
+import org.openzen.zenscript.javashared.JavaTypeParameterInfo;
24
+
25
+/**
26
+ *
27
+ * @author Stan Hebben
28
+ */
29
+public class JavaTypeExpressionVisitor implements TypeVisitorWithContext<JavaWriter, Void, RuntimeException> {
30
+	private final JavaBytecodeContext context;
31
+	
32
+	public JavaTypeExpressionVisitor(JavaBytecodeContext context) {
33
+		this.context = context;
34
+	}
35
+
36
+	@Override
37
+	public Void visitBasic(JavaWriter writer, BasicTypeID basic) {
38
+		switch (basic) {
39
+			case BOOL:
40
+				writer.constant(Boolean.class);
41
+				return null;
42
+			case SBYTE:
43
+				writer.constant(Byte.class);
44
+				return null;
45
+			case SHORT:
46
+				writer.constant(Short.class);
47
+				return null;
48
+			case BYTE:
49
+			case USHORT:
50
+			case INT:
51
+			case UINT:
52
+			case USIZE:
53
+				writer.constant(Integer.class);
54
+				return null;
55
+			case LONG:
56
+			case ULONG:
57
+				writer.constant(Long.class);
58
+				return null;
59
+			case FLOAT:
60
+				writer.constant(Float.class);
61
+				return null;
62
+			case DOUBLE:
63
+				writer.constant(Double.class);
64
+				return null;
65
+			case CHAR:
66
+				writer.constant(Character.class);
67
+				return null;
68
+			default:
69
+				throw new IllegalArgumentException();
70
+		}
71
+	}
72
+
73
+	@Override
74
+	public Void visitString(JavaWriter writer, StringTypeID string) {
75
+		writer.constant(String.class);
76
+		return null;
77
+	}
78
+
79
+	@Override
80
+	public Void visitArray(JavaWriter writer, ArrayTypeID array) {
81
+		throw new UnsupportedOperationException("Not yet implemented");
82
+	}
83
+
84
+	@Override
85
+	public Void visitAssoc(JavaWriter writer, AssocTypeID assoc) {
86
+		writer.constant(Map.class);
87
+		return null;
88
+	}
89
+
90
+	@Override
91
+	public Void visitGenericMap(JavaWriter writer, GenericMapTypeID map) {
92
+		writer.constant(Map.class);
93
+		return null;
94
+	}
95
+
96
+	@Override
97
+	public Void visitIterator(JavaWriter writer, IteratorTypeID iterator) {
98
+		writer.constant(Iterator.class);
99
+		return null;
100
+	}
101
+
102
+	@Override
103
+	public Void visitFunction(JavaWriter writer, FunctionTypeID function) {
104
+		writer.constantClass(context.getFunction(function).getCls());
105
+		return null;
106
+	}
107
+
108
+	@Override
109
+	public Void visitDefinition(JavaWriter writer, DefinitionTypeID definition) {
110
+		writer.constantClass(context.getJavaClass(definition.definition));
111
+		return null;
112
+	}
113
+
114
+	@Override
115
+	public Void visitGeneric(JavaWriter writer, GenericTypeID generic) {
116
+		JavaTypeParameterInfo info = context.target.getTypeParameterInfo(generic.parameter);
117
+		if (info.field != null) {
118
+			writer.loadObject(0); // this
119
+			writer.getField(info.field);
120
+		} else {
121
+			writer.loadObject(info.parameterIndex);
122
+		}
123
+		return null;
124
+	}
125
+
126
+	@Override
127
+	public Void visitRange(JavaWriter writer, RangeTypeID range) {
128
+		writer.constantClass(context.getRange(range).cls);
129
+		return null;
130
+	}
131
+
132
+	@Override
133
+	public Void visitOptional(JavaWriter writer, OptionalTypeID type) {
134
+		return type.baseType.accept(writer, this);
135
+	}
136
+}

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

@@ -187,6 +187,10 @@ public class JavaWriter {
187 187
 
188 188
         visitor.visitLdcInsn(value);
189 189
     }
190
+	
191
+	public void constantClass(JavaClass cls) {
192
+		visitor.visitLdcInsn(Type.getType(cls.internalName));
193
+	}
190 194
 
191 195
     public void pop() {
192 196
         if (debug)

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

@@ -64,7 +64,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
64 64
         final Label constructorEnd = new Label();
65 65
         final JavaWriter constructorWriter = new JavaWriter(member.position, writer, method, definition, context.getMethodSignature(member.header), null);
66 66
         constructorWriter.label(constructorStart);
67
-        CompilerUtils.tagConstructorParameters(context, javaModule, member.header, isEnum);
67
+        CompilerUtils.tagConstructorParameters(context, javaModule, member.definition, member.header, isEnum);
68 68
         for (FunctionParameter parameter : member.header.parameters) {
69 69
             constructorWriter.nameVariable(
70 70
                     javaModule.getParameterInfo(parameter).index,

+ 9
- 14
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

@@ -60,14 +60,13 @@ import stdlib.Strings;
60 60
 
61 61
 /**
62 62
  *
63
- * @author Hoofdgebruiker
63
+ * @author Stan Hebben
64 64
  */
65 65
 public class JavaNativeModule {
66 66
 	public final Module module;
67 67
 	private final ZSPackage pkg;
68 68
 	private final String basePackage;
69 69
 	private final GlobalTypeRegistry registry;
70
-	private final boolean allowNonAnnonated;
71 70
 	private final PackageDefinitions definitions = new PackageDefinitions();
72 71
 	private final JavaCompiledModule compiled;
73 72
 	
@@ -82,7 +81,6 @@ public class JavaNativeModule {
82 81
 			String name,
83 82
 			String basePackage,
84 83
 			GlobalTypeRegistry registry,
85
-			boolean allowNonAnnotated,
86 84
 			JavaNativeModule[] dependencies)
87 85
 	{
88 86
 		this.pkg = pkg;
@@ -94,7 +92,6 @@ public class JavaNativeModule {
94 92
 			definitionByClass.putAll(dependency.definitionByClass);
95 93
 		}
96 94
 		
97
-		this.allowNonAnnonated = allowNonAnnotated;
98 95
 		compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
99 96
 		
100 97
 		typeByClass.put(void.class, BasicTypeID.VOID);
@@ -148,7 +145,7 @@ public class JavaNativeModule {
148 145
 		if (definitionByClass.containsKey(cls))
149 146
 			return definitionByClass.get(cls);
150 147
 		
151
-		HighLevelDefinition result = addClass(cls, ZenCodeType.class.isAssignableFrom(cls));
148
+		HighLevelDefinition result = convertClass(cls);
152 149
 		definitionByClass.put(cls, result);
153 150
 		return result;
154 151
 	}
@@ -213,9 +210,7 @@ public class JavaNativeModule {
213 210
 		return classPkg;
214 211
 	}
215 212
 	
216
-	private <T> HighLevelDefinition addClass(Class<T> cls, boolean annotated) {
217
-		if (!annotated && !allowNonAnnonated)
218
-			throw new IllegalArgumentException("This class is not annotated as ZenCode class");
213
+	private <T> HighLevelDefinition convertClass(Class<T> cls) {
219 214
 		if ((cls.getModifiers() & Modifier.PUBLIC) == 0)
220 215
 			throw new IllegalArgumentException("Class must be public");
221 216
 		
@@ -260,7 +255,7 @@ public class JavaNativeModule {
260 255
 		StoredType thisType = new StoredType(registry.getForMyDefinition(definition), AutoStorageTag.INSTANCE);
261 256
 		for (Field field : cls.getDeclaredFields()) {
262 257
 			ZenCodeType.Field annotation = field.getAnnotation(ZenCodeType.Field.class);
263
-			if (annotated && annotation == null)
258
+			if (annotation == null)
264 259
 				continue;
265 260
 			if (!isPublic(field.getModifiers()))
266 261
 				continue;
@@ -278,7 +273,7 @@ public class JavaNativeModule {
278 273
 		boolean hasConstructor = false;
279 274
 		for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
280 275
 			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor)constructor.getAnnotation(ZenCodeType.Constructor.class);
281
-			if (constructorAnnotation != null || !annotated) {
276
+			if (constructorAnnotation != null) {
282 277
 				ConstructorMember member = asConstructor(definition, constructor);
283 278
 				definition.addMember(member);
284 279
 				compiled.setMethodInfo(member, getMethod(javaClass, constructor));
@@ -302,7 +297,7 @@ public class JavaNativeModule {
302 297
 			}
303 298
 			
304 299
 			ZenCodeType.Getter getter = method.getAnnotation(ZenCodeType.Getter.class);
305
-			if (getter != null || (!annotated && isGetterName(method.getName()) && method.getParameterCount() == 0)) {
300
+			if (getter != null) {
306 301
 				GetterMember member = asGetter(definition, method, getter);
307 302
 				definition.addMember(member);
308 303
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.getType()));
@@ -310,7 +305,7 @@ public class JavaNativeModule {
310 305
 			}
311 306
 			
312 307
 			ZenCodeType.Setter setter = method.getAnnotation(ZenCodeType.Setter.class);
313
-			if (setter != null || (!annotated && method.getName().startsWith("set") && method.getParameterCount() == 1)) {
308
+			if (setter != null) {
314 309
 				SetterMember member = asSetter(definition, method, setter);
315 310
 				definition.addMember(member);
316 311
 				compiled.setMethodInfo(member, getMethod(javaClass, method, BasicTypeID.VOID.stored));
@@ -333,11 +328,11 @@ public class JavaNativeModule {
333 328
 				continue;
334 329
 			}
335 330
 			
336
-			if (!annotated) {
331
+			/*if (!annotated) {
337 332
 				MethodMember member = asMethod(definition, method, null);
338 333
 				definition.addMember(member);
339 334
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
340
-			}
335
+			}*/
341 336
 		}
342 337
 		
343 338
 		return definition;

+ 1
- 1
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java View File

@@ -65,7 +65,7 @@ public class ScriptingEngine {
65 65
 	
66 66
 	public JavaNativeModule createNativeModule(String name, String basePackage, JavaNativeModule... dependencies) {
67 67
 		ZSPackage testPackage = new ZSPackage(space.rootPackage, name);
68
-		return new JavaNativeModule(testPackage, name, basePackage, registry, false, dependencies);
68
+		return new JavaNativeModule(testPackage, name, basePackage, registry, dependencies);
69 69
 	}
70 70
 	
71 71
 	public void registerNativeProvided(JavaNativeModule module) throws CompileException {

+ 14
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java View File

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.Modifiers;
13 13
 import org.openzen.zenscript.codemodel.Module;
14 14
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
15 15
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
16
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
16 17
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17 18
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
18 19
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
@@ -32,6 +33,7 @@ public class JavaCompiledModule {
32 33
 	private final Map<ImplementationMember, JavaImplementation> implementations = new HashMap<>();
33 34
 	private final Map<IDefinitionMember, JavaField> fields = new HashMap<>();
34 35
 	private final Map<IDefinitionMember, JavaMethod> methods = new HashMap<>();
36
+	private final Map<TypeParameter, JavaTypeParameterInfo> typeParameters = new HashMap<>();
35 37
 	private final Map<FunctionParameter, JavaParameterInfo> parameters = new HashMap<>();
36 38
 	private final Map<VariantDefinition.Option, JavaVariantOption> variantOptions = new HashMap<>();
37 39
 	
@@ -159,6 +161,18 @@ public class JavaCompiledModule {
159 161
 		return method;
160 162
 	}
161 163
 	
164
+	public void setTypeParameterInfo(TypeParameter parameter, JavaTypeParameterInfo info) {
165
+		typeParameters.put(parameter, info);
166
+	}
167
+	
168
+	public JavaTypeParameterInfo getTypeParameterInfo(TypeParameter parameter) {
169
+		JavaTypeParameterInfo info = typeParameters.get(parameter);
170
+		if (info == null)
171
+			throw new IllegalStateException("Missing parameter info for type parameter " + parameter);
172
+		
173
+		return info;
174
+	}
175
+	
162 176
 	public void setParameterInfo(FunctionParameter parameter, JavaParameterInfo info) {
163 177
 		parameters.put(parameter, info);
164 178
 	}

+ 7
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaMethod.java View File

@@ -51,8 +51,13 @@ public class JavaMethod {
51 51
 	public final String descriptor;
52 52
 	public final int modifiers;
53 53
 	public final boolean genericResult;
54
+	public final boolean[] typeParameterArguments;
54 55
 	
55 56
 	public JavaMethod(JavaClass cls, Kind kind, String name, boolean compile, String descriptor, int modifiers, boolean genericResult) {
57
+		this(cls, kind, name, compile, descriptor, modifiers, genericResult, new boolean[0]);
58
+	}
59
+	
60
+	public JavaMethod(JavaClass cls, Kind kind, String name, boolean compile, String descriptor, int modifiers, boolean genericResult, boolean[] typeParameterArguments) {
56 61
 		if (descriptor.contains("<")) // fix signature bug
57 62
 			throw new IllegalArgumentException("Invalid descriptor!");
58 63
 		
@@ -65,6 +70,7 @@ public class JavaMethod {
65 70
 		this.descriptor = descriptor;
66 71
 		this.modifiers = modifiers;
67 72
 		this.genericResult = genericResult;
73
+		this.typeParameterArguments = typeParameterArguments;
68 74
 	}
69 75
 	
70 76
 	public JavaMethod(JavaNativeTranslation<?> translation) {
@@ -76,6 +82,7 @@ public class JavaMethod {
76 82
 		this.descriptor = "";
77 83
 		this.modifiers = 0;
78 84
 		this.genericResult = false;
85
+		this.typeParameterArguments = new boolean[0];
79 86
 	}
80 87
 	
81 88
 	public String getMapping(JavaClass definition) {

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

@@ -145,7 +145,7 @@ public class JavaSyntheticTypeSignatureConverter implements TypeVisitorWithConte
145 145
 	}
146 146
 
147 147
 	@Override
148
-	public String visitModified(StoredType context, OptionalTypeID type) {
148
+	public String visitOptional(StoredType context, OptionalTypeID type) {
149 149
 		StringBuilder result = new StringBuilder();
150 150
 		if (type.isOptional())
151 151
 			result.append("Optional");

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

@@ -142,7 +142,7 @@ public class JavaTypeGenericVisitor implements TypeVisitorWithContext<StoredType
142 142
 	}
143 143
 
144 144
 	@Override
145
-	public String visitModified(StoredType context, OptionalTypeID type) {
145
+	public String visitOptional(StoredType context, OptionalTypeID type) {
146 146
 		return type.baseType.accept(context, this);
147 147
 	}
148 148
 }

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

@@ -95,7 +95,7 @@ public class JavaTypeInfo {
95 95
 		}
96 96
 
97 97
 		@Override
98
-		public JavaTypeInfo visitModified(StoredType context, OptionalTypeID type) {
98
+		public JavaTypeInfo visitOptional(StoredType context, OptionalTypeID type) {
99 99
 			return type.baseType.accept(null, this);
100 100
 		}
101 101
 	}

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

@@ -108,7 +108,7 @@ public class JavaTypeInternalNameVisitor implements TypeVisitorWithContext<Store
108 108
     }
109 109
 
110 110
     @Override
111
-    public String visitModified(StoredType context, OptionalTypeID modified) {
111
+    public String visitOptional(StoredType context, OptionalTypeID modified) {
112 112
 		if (modified.isOptional())
113 113
 			return modified.withoutOptional().accept(context, forOptional);
114 114
 		

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

@@ -114,7 +114,7 @@ public class JavaTypeNameVisitor implements TypeVisitorWithContext<StoredType, S
114 114
 	}
115 115
 
116 116
 	@Override
117
-	public String visitModified(StoredType context, OptionalTypeID type) {
117
+	public String visitOptional(StoredType context, OptionalTypeID type) {
118 118
 		StringBuilder result = new StringBuilder();
119 119
 		if (type.isOptional())
120 120
 			result.append("Optional");

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

@@ -0,0 +1,25 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javashared;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class JavaTypeParameterInfo {
13
+	public final int parameterIndex;
14
+	public final JavaField field;
15
+	
16
+	public JavaTypeParameterInfo(int parameterIndex) {
17
+		this.parameterIndex = parameterIndex;
18
+		this.field = null;
19
+	}
20
+	
21
+	public JavaTypeParameterInfo(JavaField field) {
22
+		this.parameterIndex = -1;
23
+		this.field = field;
24
+	}
25
+}

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

@@ -300,6 +300,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
300 300
 			DefinitionMemberRef base = member.getOverrides();
301 301
 			
302 302
 			JavaMethod baseMethod = context.getJavaMethod(base.getTarget());
303
+			
303 304
 			method = new JavaMethod(
304 305
 					cls,
305 306
 					baseMethod.kind,
@@ -307,7 +308,8 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
307 308
 					true,
308 309
 					context.getMethodDescriptor(header),
309 310
 					JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
310
-					header.getReturnType().type instanceof GenericTypeID);
311
+					header.getReturnType().type instanceof GenericTypeID,
312
+					header.useTypeParameters());
311 313
 		} else if (method == null) {
312 314
 			method = new JavaMethod(
313 315
 					cls,
@@ -316,7 +318,8 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
316 318
 					true,
317 319
 					context.getMethodDescriptor(header),
318 320
 					JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
319
-					header.getReturnType().type instanceof GenericTypeID);
321
+					header.getReturnType().type instanceof GenericTypeID,
322
+					header.useTypeParameters());
320 323
 		}
321 324
 		
322 325
 		if (method.compile && member.getBuiltin() != BuiltinID.CLASS_DEFAULT_CONSTRUCTOR) {

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

@@ -167,7 +167,15 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
167 167
 		if (nativeTag != null && nativeClass != null)
168 168
 			method = nativeClass.getMethod(nativeTag.value);
169 169
 		if (method == null)
170
-			method = new JavaMethod(cls, getKind(member), name, true, context.getMethodDescriptor(header), JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()), header.getReturnType().type instanceof GenericTypeID); 
170
+			method = new JavaMethod(
171
+					cls,
172
+					getKind(member),
173
+					name,
174
+					true,
175
+					context.getMethodDescriptor(header),
176
+					JavaModifiers.getJavaModifiers(member.getEffectiveModifiers()),
177
+					header.getReturnType().type instanceof GenericTypeID,
178
+					header.useTypeParameters()); 
171 179
 		
172 180
 		if (method.compile) {
173 181
 			if (DEBUG_EMPTY && cls.empty)

+ 1
- 1
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/TypeSerializer.java View File

@@ -137,7 +137,7 @@ public class TypeSerializer implements TypeVisitorWithContext<TypeContext, Void,
137 137
 	}
138 138
 
139 139
 	@Override
140
-	public Void visitModified(TypeContext context, OptionalTypeID type) {
140
+	public Void visitOptional(TypeContext context, OptionalTypeID type) {
141 141
 		if (type.isOptional()) {
142 142
 			output.writeUInt(TypeEncoding.TYPE_OPTIONAL);
143 143
 			type.withoutOptional().accept(context, this);

+ 1
- 1
Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java View File

@@ -125,7 +125,7 @@ public class TypeValidator implements TypeVisitorWithContext<TypeContext, Void,
125 125
 	}
126 126
 
127 127
 	@Override
128
-	public Void visitModified(TypeContext context, OptionalTypeID type) {
128
+	public Void visitOptional(TypeContext context, OptionalTypeID type) {
129 129
 		// TODO: detect duplicate const
130 130
 		validate(context, type.baseType);
131 131
 		return null;

+ 1
- 1
common.gradle View File

@@ -6,7 +6,7 @@ apply plugin: 'java'
6 6
 apply plugin: 'maven'
7 7
 
8 8
 String mavenGroupId = 'org.openzen.zencode'
9
-String mavenVersion = '0.2.0'
9
+String mavenVersion = '0.3.0'
10 10
 
11 11
 sourceCompatibility = '1.8'
12 12
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

Loading…
Cancel
Save