Przeglądaj źródła

- Fixed issues with closeables

- WIP on improving iterable implementations
- Added validation of implementation completeness
- Added definition normalization (now also adds destructors as necessary)
- Fix interfaces with base interfaces
Stan Hebben 6 lat temu
rodzic
commit
0d7459484b
37 zmienionych plików z 384 dodań i 50 usunięć
  1. 5
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  3. 9
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java
  4. 0
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java
  5. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java
  6. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  7. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  8. 9
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  9. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java
  10. 1
    9
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IPropertyMember.java
  11. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java
  12. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java
  13. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java
  14. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java
  15. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java
  16. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java
  17. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java
  18. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java
  19. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java
  20. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/DefinitionMemberRef.java
  21. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java
  22. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java
  23. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/PropertyRef.java
  24. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java
  25. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  26. 38
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  27. 19
    5
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  28. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java
  29. 9
    8
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  30. 4
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  31. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaNativeClass.java
  32. 46
    6
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java
  33. 64
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  34. 14
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java
  35. 6
    4
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java
  36. 2
    1
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  37. 41
    3
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java

+ 5
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Wyświetl plik

@@ -80,13 +80,13 @@ public class FunctionHeader {
80 80
 		hasUnknowns = hasUnknowns(parameters, returnType);
81 81
 	}
82 82
 	
83
-	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
83
+	public FunctionHeader(TypeParameter[] typeParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
84 84
 		if (returnType == null)
85 85
 			throw new NullPointerException();
86
-		if (genericParameters == null)
86
+		if (typeParameters == null)
87 87
 			throw new NullPointerException();
88 88
 		
89
-		this.typeParameters = genericParameters;
89
+		this.typeParameters = typeParameters;
90 90
 		this.returnType = returnType;
91 91
 		this.parameters = parameters;
92 92
 		this.thrownType = thrownType;
@@ -250,6 +250,8 @@ public class FunctionHeader {
250 250
 	}
251 251
 	
252 252
 	public boolean canOverride(TypeScope scope, FunctionHeader other) {
253
+		if (other == null)
254
+			throw new NullPointerException();
253 255
 		if (parameters.length != other.parameters.length)
254 256
 			return false;
255 257
 		if (returnType != BasicTypeID.UNDETERMINED && !scope.getTypeMembers(returnType).canCastImplicit(other.returnType))

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java Wyświetl plik

@@ -12,6 +12,7 @@ import org.openzen.zencode.shared.Taggable;
12 12
 import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation;
13 13
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
14 14
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
15
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
15 16
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
16 17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
17 18
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -141,8 +142,29 @@ public abstract class HighLevelDefinition extends Taggable {
141 142
 	}
142 143
 	
143 144
 	public void normalize(TypeScope scope) {
145
+		DestructorMember destructor = null;
146
+		List<FieldMember> fields = new ArrayList();
147
+		
144 148
 		for (IDefinitionMember member : members) {
145 149
 			member.normalize(scope);
150
+			
151
+			if (member instanceof DestructorMember)
152
+				destructor = (DestructorMember)member;
153
+			if (member instanceof FieldMember)
154
+				fields.add((FieldMember)member);
155
+		}
156
+		
157
+		if (isDestructible() && destructor == null && !(this instanceof ExpansionDefinition)) {
158
+			System.out.println("Added destructor to " + position);
159
+			destructor = new DestructorMember(position, this, Modifiers.PUBLIC);
160
+			members.add(destructor);
161
+		}
162
+		
163
+		for (FieldMember field : fields) {
164
+			if (field.autoGetter != null)
165
+				members.add(field.autoGetter);
166
+			if (field.autoSetter != null)
167
+				members.add(field.autoSetter);
146 168
 		}
147 169
 	}
148 170
 	

+ 9
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java Wyświetl plik

@@ -26,6 +26,15 @@ public class InterfaceDefinition extends HighLevelDefinition {
26 26
 		baseInterfaces.add(baseInterface);
27 27
 	}
28 28
 	
29
+	@Override
30
+	public boolean isDestructible() {
31
+		for (ITypeID baseInterface : baseInterfaces)
32
+			if (baseInterface.isDestructible())
33
+				return true;
34
+		
35
+		return super.isDestructible();
36
+	}
37
+	
29 38
 	@Override
30 39
 	public boolean isStatic() {
31 40
 		return true;

+ 0
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java Wyświetl plik

@@ -11,7 +11,6 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13 13
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
-import org.openzen.zenscript.codemodel.scope.TypeScope;
15 14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
17 16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java Wyświetl plik

@@ -63,4 +63,9 @@ public class ConstMember extends PropertyMember {
63 63
 		type = type.getNormalized();
64 64
 		value = value.normalize(scope);
65 65
 	}
66
+
67
+	@Override
68
+	public boolean isAbstract() {
69
+		return false;
70
+	}
66 71
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java Wyświetl plik

@@ -147,4 +147,9 @@ public class FieldMember extends PropertyMember {
147 147
 		if (initializer != null)
148 148
 			initializer = initializer.normalize(scope);
149 149
 	}
150
+
151
+	@Override
152
+	public boolean isAbstract() {
153
+		return false;
154
+	}
150 155
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java Wyświetl plik

@@ -60,4 +60,9 @@ public abstract class FunctionalMember extends DefinitionMember {
60 60
 		if (body != null)
61 61
 			body = body.normalize(scope, ConcatMap.empty(LoopStatement.class, LoopStatement.class));
62 62
 	}
63
+	
64
+	@Override
65
+	public boolean isAbstract() {
66
+		return body == null && builtin == null;
67
+	}
63 68
 }

+ 9
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java Wyświetl plik

@@ -10,6 +10,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
13
+import org.openzen.zenscript.codemodel.statement.Statement;
13 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14 15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -38,6 +39,14 @@ public class GetterMember extends FunctionalMember implements IPropertyMember {
38 39
 		this.type = type;
39 40
 	}
40 41
 	
42
+	@Override
43
+	public void setBody(Statement body) {
44
+		super.setBody(body);
45
+		
46
+		if (type == BasicTypeID.UNDETERMINED)
47
+			type = body.getReturnType();
48
+	}
49
+	
41 50
 	@Override
42 51
 	public ITypeID getType() {
43 52
 		return type;

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java Wyświetl plik

@@ -38,4 +38,6 @@ public interface IDefinitionMember {
38 38
 	DefinitionMemberRef getOverrides();
39 39
 
40 40
 	public void normalize(TypeScope scope);
41
+	
42
+	boolean isAbstract();
41 43
 }

+ 1
- 9
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IPropertyMember.java Wyświetl plik

@@ -5,8 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8
-import org.openzen.zencode.shared.CodePosition;
9
-import org.openzen.zenscript.codemodel.FunctionHeader;
10 8
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11 9
 import org.openzen.zenscript.codemodel.type.ITypeID;
12 10
 
@@ -14,15 +12,9 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
14 12
  *
15 13
  * @author Hoofdgebruiker
16 14
  */
17
-public interface IPropertyMember {
15
+public interface IPropertyMember extends IDefinitionMember {
18 16
 	ITypeID getType();
19 17
 	
20
-	CodePosition getPosition();
21
-	
22
-	String describe();
23
-
24
-	<T> T getTag(Class<T> type);
25
-	
26 18
 	boolean isStatic();
27 19
 	
28 20
 	boolean isFinal();

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java Wyświetl plik

@@ -70,4 +70,9 @@ public class ImplementationMember extends DefinitionMember {
70 70
 		for (IDefinitionMember member : members)
71 71
 			member.normalize(scope);
72 72
 	}
73
+
74
+	@Override
75
+	public boolean isAbstract() {
76
+		return false;
77
+	}
73 78
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java Wyświetl plik

@@ -63,4 +63,9 @@ public class InnerDefinitionMember extends DefinitionMember {
63 63
 	public void normalize(TypeScope scope) {
64 64
 		innerDefinition.normalize(scope);
65 65
 	}
66
+
67
+	@Override
68
+	public boolean isAbstract() {
69
+		return false;
70
+	}
66 71
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java Wyświetl plik

@@ -65,4 +65,9 @@ public class StaticInitializerMember extends Taggable implements IDefinitionMemb
65 65
 	public void normalize(TypeScope scope) {
66 66
 		body = body.normalize(scope, ConcatMap.empty(LoopStatement.class, LoopStatement.class));
67 67
 	}
68
+
69
+	@Override
70
+	public boolean isAbstract() {
71
+		return false;
72
+	}
68 73
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java Wyświetl plik

@@ -87,4 +87,9 @@ public class ArrayIteratorKeyValues extends Taggable implements IIteratorMember
87 87
 	public void normalize(TypeScope scope) {
88 88
 		
89 89
 	}
90
+
91
+	@Override
92
+	public boolean isAbstract() {
93
+		return false;
94
+	}
90 95
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java Wyświetl plik

@@ -82,4 +82,9 @@ public class ArrayIteratorValues extends Taggable implements IIteratorMember {
82 82
 	public void normalize(TypeScope scope) {
83 83
 		
84 84
 	}
85
+
86
+	@Override
87
+	public boolean isAbstract() {
88
+		return false;
89
+	}
85 90
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java Wyświetl plik

@@ -85,4 +85,9 @@ public class AssocIterator extends Taggable implements IIteratorMember {
85 85
 	public void normalize(TypeScope scope) {
86 86
 		
87 87
 	}
88
+
89
+	@Override
90
+	public boolean isAbstract() {
91
+		return false;
92
+	}
88 93
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java Wyświetl plik

@@ -93,4 +93,9 @@ public class RangeIterator extends Taggable implements IIteratorMember {
93 93
 	public void normalize(TypeScope scope) {
94 94
 		
95 95
 	}
96
+
97
+	@Override
98
+	public boolean isAbstract() {
99
+		return false;
100
+	}
96 101
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java Wyświetl plik

@@ -76,4 +76,9 @@ public class StringCharIterator extends Taggable implements IIteratorMember {
76 76
 	public void normalize(TypeScope scope) {
77 77
 		
78 78
 	}
79
+
80
+	@Override
81
+	public boolean isAbstract() {
82
+		return false;
83
+	}
79 84
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java Wyświetl plik

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12 12
 import org.openzen.zenscript.codemodel.expression.CastExpression;
13 13
 import org.openzen.zenscript.codemodel.expression.Expression;
14 14
 import org.openzen.zenscript.codemodel.member.CasterMember;
15
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 17
 
17 18
 /**
@@ -64,4 +65,9 @@ public class CasterMemberRef implements DefinitionMemberRef {
64 65
 	public MemberAnnotation[] getAnnotations() {
65 66
 		return member.annotations;
66 67
 	}
68
+
69
+	@Override
70
+	public IDefinitionMember getTarget() {
71
+		return member;
72
+	}
67 73
 }

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/DefinitionMemberRef.java Wyświetl plik

@@ -8,6 +8,7 @@ package org.openzen.zenscript.codemodel.member.ref;
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11 12
 
12 13
 /**
13 14
  *
@@ -25,4 +26,6 @@ public interface DefinitionMemberRef {
25 26
 	FunctionHeader getHeader();
26 27
 	
27 28
 	MemberAnnotation[] getAnnotations();
29
+	
30
+	IDefinitionMember getTarget();
28 31
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java Wyświetl plik

@@ -8,6 +8,7 @@ package org.openzen.zenscript.codemodel.member.ref;
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11 12
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
12 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13 14
 
@@ -53,4 +54,9 @@ public class ImplementationMemberRef implements DefinitionMemberRef {
53 54
 	public MemberAnnotation[] getAnnotations() {
54 55
 		return member.annotations;
55 56
 	}
57
+
58
+	@Override
59
+	public IDefinitionMember getTarget() {
60
+		return member;
61
+	}
56 62
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java Wyświetl plik

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11 11
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
12
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
12 13
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13 14
 import org.openzen.zenscript.codemodel.type.ITypeID;
14 15
 
@@ -62,4 +63,9 @@ public class IteratorMemberRef implements DefinitionMemberRef {
62 63
 			return null;
63 64
 		}
64 65
 	}
66
+
67
+	@Override
68
+	public IDefinitionMember getTarget() {
69
+		return target;
70
+	}
65 71
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/PropertyRef.java Wyświetl plik

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
12 13
 import org.openzen.zenscript.codemodel.member.IPropertyMember;
13 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -79,4 +80,9 @@ public abstract class PropertyRef implements DefinitionMemberRef {
79 80
 	public final MemberAnnotation[] getAnnotations() {
80 81
 		return member.getAnnotations();
81 82
 	}
83
+	
84
+	@Override
85
+	public final IDefinitionMember getTarget() {
86
+		return member;
87
+	}
82 88
 }

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java Wyświetl plik

@@ -48,18 +48,18 @@ public class ReturnStatement extends Statement {
48 48
 
49 49
 	@Override
50 50
 	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
51
-		Expression tValue = value.transform(transformer);
51
+		Expression tValue = value == null ? null : value.transform(transformer);
52 52
 		return tValue == value ? this : new ReturnStatement(position, tValue);
53 53
 	}
54 54
 
55 55
 	@Override
56 56
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
57
-		Expression tValue = value.transform(transformer);
57
+		Expression tValue = value == null ? null : value.transform(transformer);
58 58
 		return tValue == value ? this : new ReturnStatement(position, tValue);
59 59
 	}
60 60
 
61 61
 	@Override
62 62
 	public Statement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
63
-		return new ReturnStatement(position, value.normalize(scope));
63
+		return new ReturnStatement(position, value == null ? null : value.normalize(scope));
64 64
 	}
65 65
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java Wyświetl plik

@@ -264,7 +264,7 @@ public class DefinitionMemberGroup {
264 264
 				for (ITypeID resultHint : typeHints) {
265 265
 					Map<TypeParameter, ITypeID> mapping = new HashMap<>();
266 266
 					if (header.returnType.inferTypeParameters(scope.getMemberCache(), resultHint, mapping)) {
267
-						header = header.withGenericArguments(new GenericMapper(scope.getTypeRegistry(), mapping));
267
+						header = header.withGenericArguments(scope.getLocalTypeParameters().getInner(mapping));
268 268
 						break;
269 269
 					}
270 270
 				}

+ 38
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java Wyświetl plik

@@ -9,6 +9,7 @@ import java.util.ArrayList;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12
+import java.util.Set;
12 13
 import org.openzen.zencode.shared.CodePosition;
13 14
 import org.openzen.zencode.shared.CompileException;
14 15
 import org.openzen.zencode.shared.CompileExceptionCode;
@@ -23,6 +24,7 @@ import org.openzen.zenscript.codemodel.expression.NullExpression;
23 24
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
24 25
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
25 26
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
27
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
26 28
 import org.openzen.zenscript.codemodel.member.InnerDefinition;
27 29
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
28 30
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
@@ -142,6 +144,42 @@ public final class TypeMembers {
142 144
 		return null;
143 145
 	}
144 146
 	
147
+	public List<IDefinitionMember> getUnimplementedMembers(Set<IDefinitionMember> implemented) {
148
+		List<IDefinitionMember> result = new ArrayList<>();
149
+		for (TypeMember<CasterMemberRef> caster : casters) {
150
+			if (caster.member.member.isAbstract() && !implemented.contains(caster.member.member))
151
+				result.add(caster.member.member);
152
+		}
153
+		for (TypeMember<IteratorMemberRef> iterator : iterators) {
154
+			if (iterator.member.target.isAbstract() && !implemented.contains(iterator.member.target))
155
+				result.add(iterator.member.target);
156
+		}
157
+		for (Map.Entry<String, DefinitionMemberGroup> entry : members.entrySet()) {
158
+			DefinitionMemberGroup group = entry.getValue();
159
+			if (group.getGetter() != null && group.getGetter().member.isAbstract() && !implemented.contains(group.getGetter().member))
160
+				result.add(group.getGetter().member);
161
+			if (group.getSetter() != null && group.getSetter().member.isAbstract() && !implemented.contains(group.getSetter().member))
162
+				result.add(group.getSetter().member);
163
+			for (TypeMember<FunctionalMemberRef> member : group.getMethodMembers())
164
+				if (member.member.getTarget().isAbstract() && !implemented.contains(member.member.getTarget()))
165
+					result.add(member.member.getTarget());
166
+		}
167
+		for (Map.Entry<OperatorType, DefinitionMemberGroup> entry : operators.entrySet()) {
168
+			if (entry.getKey() == OperatorType.DESTRUCTOR)
169
+				continue; // destructor doesn't have to be implemented; the compiler can do so automatically
170
+			
171
+			DefinitionMemberGroup group = entry.getValue();
172
+			if (group.getGetter() != null && group.getGetter().member.isAbstract() && !implemented.contains(group.getGetter().member))
173
+				result.add(group.getGetter().member);
174
+			if (group.getSetter() != null && group.getSetter().member.isAbstract() && !implemented.contains(group.getSetter().member))
175
+				result.add(group.getSetter().member);
176
+			for (TypeMember<FunctionalMemberRef> member : group.getMethodMembers())
177
+				if (member.member.getTarget().isAbstract() && !implemented.contains(member.member.getTarget()))
178
+					result.add(member.member.getTarget());
179
+		}
180
+		return result;
181
+	}
182
+	
145 183
 	public void addConstructor(FunctionalMemberRef constructor, TypeMemberPriority priority) {
146 184
 		getOrCreateGroup(OperatorType.CONSTRUCTOR).addMethod(constructor, priority);
147 185
 	}

+ 19
- 5
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Wyświetl plik

@@ -82,10 +82,11 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
82 82
 	@Override
83 83
 	public Void visitClass(ClassDefinition definition) {
84 84
 		JavaSourceFileScope scope = createScope(definition);
85
+		JavaSourceClass cls = definition.getTag(JavaSourceClass.class);
85 86
 		
86 87
 		output.append(indent);
87 88
 		convertModifiers(definition.modifiers);
88
-		output.append("class ").append(definition.name);
89
+		output.append("class ").append(cls.getName());
89 90
 		JavaSourceUtils.formatTypeParameters(scope.typeVisitor, output, definition.genericParameters, false);
90 91
 		if (definition.getSuperType() != null) {
91 92
 			output.append(" extends ");
@@ -99,7 +100,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
99 100
 			}
100 101
 		}
101 102
 		
102
-		if (mergedImplementations.size() > 0 || definition.isDestructible()) {
103
+		if (mergedImplementations.size() > 0 || cls.destructible) {
103 104
 			output.append(" implements ");
104 105
 			boolean first = true;
105 106
 			for (int i = 0; i < mergedImplementations.size(); i++) {
@@ -112,7 +113,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
112 113
 				output.append(scope.type(implementation.type));
113 114
 			}
114 115
 			
115
-			if (definition.isDestructible()) {
116
+			if (cls.destructible) {
116 117
 				if (first)
117 118
 					first = false;
118 119
 				else
@@ -132,15 +133,28 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
132 133
 	@Override
133 134
 	public Void visitInterface(InterfaceDefinition definition) {
134 135
 		JavaSourceFileScope scope = createScope(definition);
136
+		JavaSourceClass cls = definition.getTag(JavaSourceClass.class);
135 137
 		
136 138
 		output.append(indent);
137 139
 		convertModifiers(definition.modifiers | Modifiers.VIRTUAL); // to prevent 'final'
138
-		output.append("interface ").append(definition.name);
140
+		output.append("interface ").append(cls.getName());
139 141
 		JavaSourceUtils.formatTypeParameters(scope.typeVisitor, output, definition.genericParameters, false);
140
-			
142
+		
143
+		boolean firstExtends = true;
141 144
 		if (definition.isDestructible()) {
142 145
 			output.append(" extends ");
143 146
 			output.append(scope.importer.importType(new JavaSourceClass("java.lang", "AutoCloseable")));
147
+			firstExtends = false;
148
+		}
149
+		
150
+		for (ITypeID base : definition.baseInterfaces) {
151
+			if (firstExtends) {
152
+				firstExtends = false;
153
+				output.append(" extends ");
154
+			} else {
155
+				output.append(", ");
156
+			}
157
+			output.append(scope.type(base));
144 158
 		}
145 159
 		
146 160
 		output.append(" {\n");

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java Wyświetl plik

@@ -129,7 +129,7 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
129 129
 
130 130
 	@Override
131 131
 	public Void visitDestructor(DestructorMember member) {
132
-		throw new UnsupportedOperationException("Expansions cannot declare destructors");
132
+		return null; // ignore
133 133
 	}
134 134
 
135 135
 	@Override

+ 9
- 8
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Wyświetl plik

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 15
 import org.openzen.zenscript.codemodel.Modifiers;
16
+import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
16 17
 import org.openzen.zenscript.codemodel.member.CallerMember;
17 18
 import org.openzen.zenscript.codemodel.member.CasterMember;
18 19
 import org.openzen.zenscript.codemodel.member.ConstMember;
@@ -29,6 +30,7 @@ import org.openzen.zenscript.codemodel.member.MethodMember;
29 30
 import org.openzen.zenscript.codemodel.member.OperatorMember;
30 31
 import org.openzen.zenscript.codemodel.member.SetterMember;
31 32
 import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
33
+import org.openzen.zenscript.codemodel.statement.BlockStatement;
32 34
 import org.openzen.zenscript.codemodel.statement.EmptyStatement;
33 35
 import org.openzen.zenscript.codemodel.statement.Statement;
34 36
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -166,7 +168,12 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
166 168
 		
167 169
 		output.append(indent).append("@Override\n");
168 170
 		output.append(indent).append("public void close()");
169
-		compileBody(member.body, member.header);
171
+		
172
+		Statement body = member.body;
173
+		if ((body == null || body instanceof EmptyStatement) && !(definition instanceof InterfaceDefinition))
174
+			body = new BlockStatement(member.position, Collections.emptyList());
175
+		
176
+		compileBody(body, member.header);
170 177
 		return null;
171 178
 	}
172 179
 
@@ -263,12 +270,6 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
263 270
 	}
264 271
 	
265 272
 	public void finish() {
266
-		// TODO: needs to be moved elsewhere (normalization stage?)
267
-		for (FieldMember field : fields) {
268
-			if (field.autoGetter != null)
269
-				visitGetter(field.autoGetter);
270
-			if (field.autoSetter != null)
271
-				visitSetter(field.autoSetter);
272
-		}
273
+		
273 274
 	}
274 275
 }

+ 4
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Wyświetl plik

@@ -1680,7 +1680,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1680 1680
 					throw new UnsupportedOperationException("Not yet supported!");
1681 1681
 				}
1682 1682
 			}
1683
-			case ARRAY_CONSTRUCTOR_PROJECTED_INDEXED:
1683
+			case ARRAY_CONSTRUCTOR_PROJECTED_INDEXED: {
1684 1684
 				ArrayTypeID type = (ArrayTypeID) expression.type;
1685 1685
 				
1686 1686
 				if (type.dimension == 1) {
@@ -1759,6 +1759,9 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1759 1759
 					// TODO: implement
1760 1760
 					throw new UnsupportedOperationException("Not yet supported!");
1761 1761
 				}
1762
+			}
1763
+			case CLASS_DEFAULT_CONSTRUCTOR:
1764
+				return new ExpressionString("new " + scope.type(expression.type) + "()", JavaOperator.NEW);
1762 1765
 		}
1763 1766
 		
1764 1767
 		throw new UnsupportedOperationException("Unknown builtin constructor: " + expression.constructor.getBuiltin());

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaNativeClass.java Wyświetl plik

@@ -17,9 +17,15 @@ import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
17 17
 public class JavaNativeClass {
18 18
 	public final JavaSourceClass cls;
19 19
 	private final Map<String, JavaSourceMethod> methods = new HashMap<>();
20
+	public final boolean nonDestructible;
20 21
 	
21 22
 	public JavaNativeClass(JavaSourceClass cls) {
23
+		this(cls, false);
24
+	}
25
+	
26
+	public JavaNativeClass(JavaSourceClass cls, boolean nonDestructible) {
22 27
 		this.cls = cls;
28
+		this.nonDestructible = nonDestructible;
23 29
 	}
24 30
 	
25 31
 	public void addMethod(String key, JavaSourceMethod method) {

+ 46
- 6
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java Wyświetl plik

@@ -25,6 +25,7 @@ import org.openzen.zenscript.codemodel.member.MethodMember;
25 25
 import org.openzen.zenscript.codemodel.member.OperatorMember;
26 26
 import org.openzen.zenscript.codemodel.member.SetterMember;
27 27
 import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
28
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
28 29
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
29 30
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
30 31
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
@@ -36,19 +37,32 @@ import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
36 37
  * @author Hoofdgebruiker
37 38
  */
38 39
 public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void> {
40
+	private static final boolean DEBUG_EMPTY = true;
41
+	
42
+	private final JavaSourcePrepareDefinitionVisitor definitionPreparer;
39 43
 	private final String filename;
40 44
 	private final JavaSourceClass cls;
41 45
 	private final JavaNativeClass nativeClass;
42 46
 	
43
-	public JavaSourcePrepareClassMethodVisitor(String filename, JavaSourceClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
47
+	public JavaSourcePrepareClassMethodVisitor(
48
+			JavaSourcePrepareDefinitionVisitor definitionPreparer,
49
+			String filename,
50
+			JavaSourceClass cls,
51
+			JavaNativeClass nativeClass,
52
+			boolean startsEmpty) {
53
+		this.definitionPreparer = definitionPreparer;
44 54
 		this.filename = filename;
45 55
 		this.cls = cls;
46 56
 		this.nativeClass = nativeClass;
57
+		
47 58
 		cls.empty = startsEmpty;
48 59
 	}
49 60
 	
50 61
 	@Override
51 62
 	public Void visitConst(ConstMember member) {
63
+		if (DEBUG_EMPTY && cls.empty)
64
+			System.out.println("Class " + cls.fullName + " not empty because of const " + member.name);
65
+		
52 66
 		cls.empty = false;
53 67
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
54 68
 		return null;
@@ -56,7 +70,6 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
56 70
 	
57 71
 	@Override
58 72
 	public Void visitField(FieldMember member) {
59
-		cls.empty = false;
60 73
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
61 74
 		if (member.hasAutoGetter())
62 75
 			visitGetter(member.autoGetter);
@@ -74,6 +87,9 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
74 87
 
75 88
 	@Override
76 89
 	public Void visitDestructor(DestructorMember member) {
90
+		if (DEBUG_EMPTY && cls.empty)
91
+			System.out.println("Class " + cls.fullName + " not empty because of destructor");
92
+		
77 93
 		cls.empty = false;
78 94
 		return null;
79 95
 	}
@@ -122,16 +138,22 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
122 138
 
123 139
 	@Override
124 140
 	public Void visitImplementation(ImplementationMember member) {
125
-		cls.empty = false;
141
+		definitionPreparer.prepare(member.type);
142
+		
126 143
 		if (canMergeImplementation(member)) {
127 144
 			member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(true, cls));
128 145
 			for (IDefinitionMember m : member.members)
129 146
 				m.accept(this);
130 147
 		} else {
148
+			if (DEBUG_EMPTY && cls.empty)
149
+				System.out.println("Class " + cls.fullName + " not empty because of unmergeable implementation");
150
+			
151
+			cls.empty = false;
152
+			
131 153
 			JavaSourceClass implementationClass = new JavaSourceClass(cls, member.type.accept(new JavaSourceTypeNameVisitor()) + "Implementation");
132 154
 			member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(false, implementationClass));
133 155
 			
134
-			JavaSourcePrepareClassMethodVisitor visitor = new JavaSourcePrepareClassMethodVisitor(filename, implementationClass, null, true);
156
+			JavaSourcePrepareClassMethodVisitor visitor = new JavaSourcePrepareClassMethodVisitor(definitionPreparer, filename, implementationClass, null, true);
135 157
 			for (IDefinitionMember m : member.members)
136 158
 				m.accept(visitor);
137 159
 		}
@@ -147,12 +169,17 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
147 169
 		JavaSourcePrepareDefinitionVisitor innerDefinitionPrepare = new JavaSourcePrepareDefinitionVisitor(filename, cls);
148 170
 		member.innerDefinition.accept(innerDefinitionPrepare);
149 171
 		
172
+		if (DEBUG_EMPTY && cls.empty)
173
+			System.out.println("Class " + cls.fullName + " not empty because of inner definition " + member.innerDefinition.name);
150 174
 		cls.empty = false;
151 175
 		return null;
152 176
 	}
153 177
 
154 178
 	@Override
155 179
 	public Void visitStaticInitializer(StaticInitializerMember member) {
180
+		if (DEBUG_EMPTY && cls.empty)
181
+			System.out.println("Class " + cls.fullName + " not empty because of static initializer");
182
+		
156 183
 		cls.empty = false;
157 184
 		return null;
158 185
 	}
@@ -252,11 +279,24 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
252 279
 		JavaSourceMethod method = null;
253 280
 		if (nativeTag != null && nativeClass != null)
254 281
 			method = nativeClass.getMethod(nativeTag.value);
255
-		if (method == null)
282
+		
283
+		if (member.getOverrides() != null) {
284
+			DefinitionMemberRef base = member.getOverrides();
285
+			JavaSourceMethod baseMethod = base.getTarget().getTag(JavaSourceMethod.class);
286
+			if (baseMethod == null)
287
+				throw new IllegalStateException("Base method not yet prepared!");
288
+			
289
+			method = new JavaSourceMethod(cls, baseMethod.kind, baseMethod.name, true);
290
+		} else if (method == null) {
256 291
 			method = new JavaSourceMethod(cls, getKind(member), name, true);
292
+		}
257 293
 		
258
-		if (method.compile)
294
+		if (method.compile) {
295
+			if (DEBUG_EMPTY && cls.empty)
296
+				System.out.println("Class " + cls.fullName + " not empty because of " + member.describe());
297
+			
259 298
 			cls.empty = false;
299
+		}
260 300
 		
261 301
 		member.setTag(JavaSourceMethod.class, method);
262 302
 	}

+ 64
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java Wyświetl plik

@@ -22,6 +22,8 @@ import org.openzen.zenscript.codemodel.expression.CallExpression;
22 22
 import org.openzen.zenscript.codemodel.expression.CastExpression;
23 23
 import org.openzen.zenscript.codemodel.expression.Expression;
24 24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
25
+import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
26
+import org.openzen.zenscript.codemodel.type.ITypeID;
25 27
 import org.openzen.zenscript.formattershared.ExpressionString;
26 28
 import org.openzen.zenscript.javasource.JavaOperator;
27 29
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
@@ -68,15 +70,30 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
68 70
 			list.addInstanceMethod("insert", "add");
69 71
 			list.addInstanceMethod("remove", "remove");
70 72
 			list.addInstanceMethod("indexOf", "indexOf");
73
+			list.addInstanceMethod("lastIndexOf", "lastIndexOf");
71 74
 			list.addInstanceMethod("getAtIndex", "get");
72 75
 			list.addInstanceMethod("setAtIndex", "set");
73 76
 			list.addInstanceMethod("contains", "contains");
74 77
 			list.addMethod("toArray", new JavaSourceMethod((formatter, call) -> formatter.listToArray((CastExpression)call)));
75
-			list.addInstanceMethod("length", "length");
78
+			list.addInstanceMethod("length", "size");
76 79
 			list.addInstanceMethod("isEmpty", "isEmpty");
80
+			list.addInstanceMethod("iterate", "iterator");
77 81
 			nativeClasses.put("stdlib::List", list);
78 82
 		}
79 83
 		
84
+		{
85
+			JavaNativeClass iterable = new JavaNativeClass(new JavaSourceClass("java.lang", "Iterable"));
86
+			iterable.addInstanceMethod("iterate", "iterator");
87
+			nativeClasses.put("stdlib::Iterable", iterable);
88
+		}
89
+		
90
+		{
91
+			JavaNativeClass iterator = new JavaNativeClass(new JavaSourceClass("java.lang", "Iterator"));
92
+			iterator.addInstanceMethod("hasNext", "hasNext");
93
+			iterator.addInstanceMethod("next", "next");
94
+			nativeClasses.put("stdlib::Iterator", iterator);
95
+		}
96
+		
80 97
 		{
81 98
 			JavaNativeClass comparable = new JavaNativeClass(new JavaSourceClass("java.lang", "Comparable"));
82 99
 			comparable.addInstanceMethod("compareTo", "compareTo");
@@ -184,7 +201,7 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
184 201
 		}
185 202
 		
186 203
 		{
187
-			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "StringReader"));
204
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "StringReader"), true);
188 205
 			cls.addInstanceMethod("constructor", "");
189 206
 			cls.addInstanceMethod("destructor", "close");
190 207
 			cls.addInstanceMethod("readCharacter", "read");
@@ -201,28 +218,58 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
201 218
 		this.outerClass = outerClass;
202 219
 	}
203 220
 	
221
+	private boolean isPrepared(HighLevelDefinition definition) {
222
+		return definition.hasTag(JavaSourceClass.class);
223
+	}
224
+	
225
+	public void prepare(ITypeID type) {
226
+		if (!(type instanceof DefinitionTypeID))
227
+			return;
228
+			
229
+		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
230
+		definition.accept(this);
231
+	}
232
+	
204 233
 	@Override
205 234
 	public JavaSourceClass visitClass(ClassDefinition definition) {
235
+		if (isPrepared(definition))
236
+			return definition.getTag(JavaSourceClass.class);
237
+		
206 238
 		return visitClassCompiled(definition, true);
207 239
 	}
208 240
 
209 241
 	@Override
210 242
 	public JavaSourceClass visitInterface(InterfaceDefinition definition) {
243
+		if (isPrepared(definition))
244
+			return definition.getTag(JavaSourceClass.class);
245
+		
246
+		for (ITypeID baseType : definition.baseInterfaces)
247
+			prepare(baseType);
248
+		
211 249
 		return visitClassCompiled(definition, true);
212 250
 	}
213 251
 
214 252
 	@Override
215 253
 	public JavaSourceClass visitEnum(EnumDefinition definition) {
254
+		if (isPrepared(definition))
255
+			return definition.getTag(JavaSourceClass.class);
256
+		
216 257
 		return visitClassCompiled(definition, false);
217 258
 	}
218 259
 
219 260
 	@Override
220 261
 	public JavaSourceClass visitStruct(StructDefinition definition) {
262
+		if (isPrepared(definition))
263
+			return definition.getTag(JavaSourceClass.class);
264
+		
221 265
 		return visitClassCompiled(definition, true);
222 266
 	}
223 267
 
224 268
 	@Override
225 269
 	public JavaSourceClass visitFunction(FunctionDefinition definition) {
270
+		if (isPrepared(definition))
271
+			return definition.getTag(JavaSourceClass.class);
272
+		
226 273
 		JavaSourceClass cls = new JavaSourceClass(definition.pkg.fullName, filename);
227 274
 		definition.setTag(JavaSourceClass.class, cls);
228 275
 		JavaSourceMethod method = new JavaSourceMethod(cls, JavaSourceMethod.Kind.STATIC, definition.name, true);
@@ -232,6 +279,9 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
232 279
 
233 280
 	@Override
234 281
 	public JavaSourceClass visitExpansion(ExpansionDefinition definition) {
282
+		if (isPrepared(definition))
283
+			return definition.getTag(JavaSourceClass.class);
284
+		
235 285
 		NativeTag nativeTag = definition.getTag(NativeTag.class);
236 286
 		JavaNativeClass nativeClass = null;
237 287
 		if (nativeTag != null) {
@@ -252,6 +302,9 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
252 302
 
253 303
 	@Override
254 304
 	public JavaSourceClass visitVariant(VariantDefinition variant) {
305
+		if (isPrepared(variant))
306
+			return variant.getTag(JavaSourceClass.class);
307
+		
255 308
 		JavaSourceClass cls = new JavaSourceClass(variant.pkg.fullName, variant.name);
256 309
 		variant.setTag(JavaSourceClass.class, cls);
257 310
 		
@@ -265,10 +318,14 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
265 318
 	}
266 319
 	
267 320
 	private JavaSourceClass visitClassCompiled(HighLevelDefinition definition, boolean startsEmpty) {
321
+		if (definition.getSuperType() != null)
322
+			prepare(definition.getSuperType());
323
+		
268 324
 		NativeTag nativeTag = definition.getTag(NativeTag.class);
269 325
 		JavaNativeClass nativeClass = nativeTag == null ? null : nativeClasses.get(nativeTag.value);
270 326
 		if (nativeClass == null) {
271 327
 			JavaSourceClass cls = outerClass == null ? new JavaSourceClass(definition.pkg.fullName, definition.name) : new JavaSourceClass(outerClass, definition.name);
328
+			cls.destructible = definition.isDestructible();
272 329
 			definition.setTag(JavaSourceClass.class, cls);
273 330
 			visitClassMembers(definition, cls, null, startsEmpty);
274 331
 			return cls;
@@ -277,12 +334,16 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
277 334
 			definition.setTag(JavaSourceClass.class, nativeClass.cls);
278 335
 			definition.setTag(JavaNativeClass.class, nativeClass);
279 336
 			visitExpansionMembers(definition, cls, nativeClass);
337
+			
338
+			if (nativeClass.nonDestructible)
339
+				cls.destructible = false;
340
+			
280 341
 			return cls;
281 342
 		}
282 343
 	}
283 344
 	
284 345
 	private void visitClassMembers(HighLevelDefinition definition, JavaSourceClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
285
-		JavaSourcePrepareClassMethodVisitor methodVisitor = new JavaSourcePrepareClassMethodVisitor(filename, cls, nativeClass, startsEmpty);
346
+		JavaSourcePrepareClassMethodVisitor methodVisitor = new JavaSourcePrepareClassMethodVisitor(this, filename, cls, nativeClass, startsEmpty);
286 347
 		for (IDefinitionMember member : definition.members) {
287 348
 			member.accept(methodVisitor);
288 349
 		}

+ 14
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java Wyświetl plik

@@ -36,6 +36,8 @@ import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
36 36
  * @author Hoofdgebruiker
37 37
  */
38 38
 public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Void> {
39
+	private static final boolean DEBUG_EMPTY = true;
40
+	
39 41
 	private final JavaSourceClass cls;
40 42
 	private final JavaNativeClass nativeClass;
41 43
 	
@@ -48,6 +50,10 @@ public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Vo
48 50
 	@Override
49 51
 	public Void visitConst(ConstMember member) {
50 52
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
53
+		
54
+		if (DEBUG_EMPTY && cls.empty)
55
+			System.out.println("Class " + cls.fullName + " not empty because of const");
56
+		
51 57
 		cls.empty = false;
52 58
 		return null;
53 59
 	}
@@ -69,6 +75,9 @@ public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Vo
69 75
 
70 76
 	@Override
71 77
 	public Void visitDestructor(DestructorMember member) {
78
+		if (nativeClass != null && nativeClass.nonDestructible)
79
+			return null;
80
+		
72 81
 		visitFunctional(member, "");
73 82
 		return null;
74 83
 	}
@@ -146,8 +155,12 @@ public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Vo
146 155
 		if (method == null)
147 156
 			method = new JavaSourceMethod(cls, getKind(member), name, true); 
148 157
 		
149
-		if (method.compile)
158
+		if (method.compile) {
159
+			if (DEBUG_EMPTY && cls.empty)
160
+				System.out.println("Class " + cls.fullName + " not empty because of " + member.describe());
161
+			
150 162
 			cls.empty = false;
163
+		}
151 164
 		
152 165
 		member.setTag(JavaSourceMethod.class, method);
153 166
 	}

+ 6
- 4
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java Wyświetl plik

@@ -40,19 +40,19 @@ public class ParsedClass extends BaseParsedDefinition {
40 40
 		return result;
41 41
 	}
42 42
 	
43
-	private final List<ParsedTypeParameter> genericParameters;
43
+	private final List<ParsedTypeParameter> parameters;
44 44
 	private final IParsedType superclass;
45 45
 	
46 46
 	private final ClassDefinition compiled;
47 47
 	
48
-	public ParsedClass(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> genericParameters, IParsedType superclass, HighLevelDefinition outerDefinition) {
48
+	public ParsedClass(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> parameters, IParsedType superclass, HighLevelDefinition outerDefinition) {
49 49
 		super(position, modifiers, annotations);
50 50
 		
51
-		this.genericParameters = genericParameters;
51
+		this.parameters = parameters;
52 52
 		this.superclass = superclass;
53 53
 		
54 54
 		compiled = new ClassDefinition(position, pkg, name, modifiers, outerDefinition);
55
-		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
55
+		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(parameters));
56 56
 	}
57 57
 
58 58
 	@Override
@@ -62,6 +62,8 @@ public class ParsedClass extends BaseParsedDefinition {
62 62
 
63 63
 	@Override
64 64
 	protected void linkTypesLocal(TypeResolutionContext context) {
65
+		ParsedTypeParameter.compile(context, compiled.genericParameters, this.parameters);
66
+		
65 67
 		if (superclass != null)
66 68
 			compiled.setSuperType(superclass.compile(context));
67 69
 		

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java Wyświetl plik

@@ -71,6 +71,7 @@ public class ValidationLogEntry {
71 71
 		OVERRIDE_MISSING_BASE,
72 72
 		INVALID_OVERRIDE,
73 73
 		SUPERTYPE_NOT_DESTRUCTIBLE,
74
-		INVALID_IMPLEMENTATION_TYPE
74
+		INVALID_IMPLEMENTATION_TYPE,
75
+		INCOMPLETE_IMPLEMENTATION
75 76
 	}
76 77
 }

+ 41
- 3
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java Wyświetl plik

@@ -35,6 +35,7 @@ import org.openzen.zenscript.codemodel.statement.VarStatement;
35 35
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
36 36
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
37 37
 import org.openzen.zenscript.codemodel.type.ITypeID;
38
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
38 39
 import org.openzen.zenscript.validator.ValidationLogEntry;
39 40
 import org.openzen.zenscript.validator.Validator;
40 41
 import org.openzen.zenscript.validator.analysis.ExpressionScope;
@@ -151,7 +152,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
151 152
 	public Void visitGetter(GetterMember member) {
152 153
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
153 154
 		member.type.accept(new TypeValidator(validator, member.position));
154
-		validateFunctional(member, new MethodStatementScope(member.header));
155
+		validateProperty(member, new MethodStatementScope(member.header));
155 156
 		return null;
156 157
 	}
157 158
 
@@ -159,7 +160,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
159 160
 	public Void visitSetter(SetterMember member) {
160 161
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
161 162
 		member.type.accept(new TypeValidator(validator, member.position));
162
-		validateFunctional(member, new MethodStatementScope(member.header));
163
+		validateProperty(member, new MethodStatementScope(member.header));
163 164
 		return null;
164 165
 	}
165 166
 	
@@ -191,7 +192,9 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
191 192
 
192 193
 	@Override
193 194
 	public Void visitCustomIterator(CustomIteratorMember member) {
194
-		// TODO: validate iterators
195
+		for (ITypeID type : member.getLoopVariableTypes())
196
+			type.accept(new TypeValidator(validator, member.position));
197
+		validateFunctional(member, new MethodStatementScope(new FunctionHeader(scope.getTypeRegistry().getIterator(member.getLoopVariableTypes()))));
195 198
 		return null;
196 199
 	}
197 200
 
@@ -229,8 +232,29 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
229 232
 			member.accept(memberValidator);
230 233
 		}
231 234
 		
235
+		checkImplementationComplete(implementation);
232 236
 		return null;
233 237
 	}
238
+	
239
+	private void checkImplementationComplete(ImplementationMember implementation) {
240
+		Set<IDefinitionMember> implemented = new HashSet<>();
241
+		for (IDefinitionMember member : implementation.members)
242
+			if (member.getOverrides() != null)
243
+				implemented.add(member.getOverrides().getTarget());
244
+		
245
+		TypeMembers members = scope.getTypeMembers(implementation.type);
246
+		List<IDefinitionMember> unimplemented = members.getUnimplementedMembers(implemented);
247
+		if (unimplemented.size() == 1) {
248
+			validator.logError(ValidationLogEntry.Code.INCOMPLETE_IMPLEMENTATION, implementation.position, unimplemented.get(0).describe() + " not implemented");
249
+		} else if (unimplemented.size() > 1) {
250
+			StringBuilder message = new StringBuilder();
251
+			message.append("Implementation incomplete: ").append(unimplemented.size()).append(" members not yet implemented:");
252
+			for (IDefinitionMember member : unimplemented) {
253
+				message.append("\n").append("  - ").append(member.describe());
254
+			}
255
+			validator.logError(ValidationLogEntry.Code.INCOMPLETE_IMPLEMENTATION, implementation.position, message.toString());
256
+		}
257
+	}
234 258
 
235 259
 	@Override
236 260
 	public Void visitInnerDefinition(InnerDefinitionMember innerDefinition) {
@@ -274,6 +298,20 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
274 298
 		}
275 299
 	}
276 300
 	
301
+	private void validateProperty(FunctionalMember member, StatementScope scope) {
302
+		if (Modifiers.isOverride(member.modifiers) || (context == DefinitionMemberContext.IMPLEMENTATION && !member.isPrivate())) {
303
+			if (member.getOverrides() == null) {
304
+				validator.logError(ValidationLogEntry.Code.OVERRIDE_MISSING_BASE, member.position, "Overridden method not identified");
305
+			}
306
+		}
307
+		
308
+		if (member.body != null) {
309
+			StatementValidator statementValidator = new StatementValidator(validator, scope);
310
+			member.body.accept(statementValidator);
311
+			validateThrow(member);
312
+		}
313
+	}
314
+	
277 315
 	private class FieldInitializerScope implements ExpressionScope {
278 316
 		private final FieldMember field;
279 317
 		

Ładowanie…
Anuluj
Zapisz