Browse Source

Merge remote-tracking branch 'Stan/development' into development

kindlich 6 years ago
parent
commit
e5dd5f08fe
No known key found for this signature in database
100 changed files with 1149 additions and 207 deletions
  1. 2
    2
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java
  2. 80
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  3. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java
  4. 13
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java
  5. 9
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java
  6. 29
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/DummyExpression.java
  7. 10
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  8. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PanicExpression.java
  9. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThrowExpression.java
  10. 16
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java
  11. 12
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java
  12. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java
  13. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  14. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java
  15. 13
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java
  16. 9
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DestructorMember.java
  17. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  18. 1
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  19. 17
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  20. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java
  21. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java
  22. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java
  23. 24
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MethodMember.java
  24. 14
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/OperatorMember.java
  25. 16
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java
  26. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java
  27. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java
  28. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java
  29. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java
  30. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java
  31. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java
  32. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java
  33. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ConstMemberRef.java
  34. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/DefinitionMemberRef.java
  35. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FieldMemberRef.java
  36. 22
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java
  37. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/GetterMemberRef.java
  38. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java
  39. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java
  40. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/SetterMemberRef.java
  41. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java
  42. 7
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java
  43. 1
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  44. 24
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  45. 19
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  46. 1
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  47. 3
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  48. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  49. 0
    22
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceFile.java
  50. 3
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourcePackage.java
  51. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java
  52. 25
    0
      IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeError.java
  53. 41
    0
      IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeSpace.java
  54. 6
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/IDEModule.java
  55. 2
    3
      IDE/src/main/java/org/openzen/zenscript/ide/host/IDESourceFile.java
  56. 10
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java
  57. 3
    2
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalPackage.java
  58. 12
    13
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalSourceFile.java
  59. 5
    5
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  60. 48
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/PathGenerator.java
  61. 42
    24
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java
  62. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourcePosition.java
  63. 10
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenLine.java
  64. 15
    6
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java
  65. 5
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenRelexer.java
  66. 47
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/WavyLine.java
  67. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  68. 5
    6
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  69. 0
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java
  70. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  71. 0
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  72. 9
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  73. 8
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java
  74. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java
  75. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  76. 25
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  77. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  78. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java
  79. 2
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java
  80. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeNameVisitor.java
  81. 0
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  82. 19
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java
  83. 24
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  84. 11
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java
  85. 14
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourceSignatureVisitor.java
  86. 20
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/tags/JavaSourceImplementation.java
  87. 6
    5
      Parser/src/main/java/org/openzen/zenscript/lexer/CountingCharReader.java
  88. 9
    7
      Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java
  89. 7
    6
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenParser.java
  90. 3
    1
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java
  91. 21
    19
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  92. 61
    0
      Parser/src/main/java/org/openzen/zenscript/parser/PrecompilationState.java
  93. 10
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java
  94. 7
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java
  95. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java
  96. 4
    3
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java
  97. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java
  98. 18
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  99. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java
  100. 0
    0
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java

+ 2
- 2
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java View File

78
 			if (parameter.variadic)
78
 			if (parameter.variadic)
79
 				result.append("...");
79
 				result.append("...");
80
 			
80
 			
81
-			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.ANY) {
81
+			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
82
 				result.append(" as ");
82
 				result.append(" as ");
83
 				result.append(header.returnType.accept(typeFormatter));
83
 				result.append(header.returnType.accept(typeFormatter));
84
 			}
84
 			}
86
 			parameterIndex++;
86
 			parameterIndex++;
87
 		}
87
 		}
88
 		result.append(")");
88
 		result.append(")");
89
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.ANY) {
89
+		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.UNDETERMINED) {
90
 			result.append(" as ");
90
 			result.append(" as ");
91
 			result.append(header.returnType.accept(typeFormatter));
91
 			result.append(header.returnType.accept(typeFormatter));
92
 		}
92
 		}

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel;
6
 package org.openzen.zenscript.codemodel;
7
 
7
 
8
+import java.util.Arrays;
9
+import java.util.Collections;
8
 import java.util.HashMap;
10
 import java.util.HashMap;
9
 import java.util.List;
11
 import java.util.List;
10
 import java.util.Map;
12
 import java.util.Map;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.scope.TypeScope;
19
 import org.openzen.zenscript.codemodel.scope.TypeScope;
20
+import org.openzen.zenscript.codemodel.type.GenericTypeID;
18
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
19
 
22
 
20
 /**
23
 /**
31
 	
34
 	
32
 	public final int minParameters;
35
 	public final int minParameters;
33
 	public final int maxParameters;
36
 	public final int maxParameters;
37
+	public final boolean hasUnknowns;
34
 	
38
 	
35
 	public FunctionHeader(ITypeID returnType) {
39
 	public FunctionHeader(ITypeID returnType) {
36
 		if (returnType == null)
40
 		if (returnType == null)
43
 		
47
 		
44
 		minParameters = 0;
48
 		minParameters = 0;
45
 		maxParameters = 0;
49
 		maxParameters = 0;
50
+		hasUnknowns = returnType == BasicTypeID.UNDETERMINED;
46
 	}
51
 	}
47
 	
52
 	
48
 	public FunctionHeader(ITypeID returnType, ITypeID... parameterTypes) {
53
 	public FunctionHeader(ITypeID returnType, ITypeID... parameterTypes) {
59
 		
64
 		
60
 		minParameters = parameterTypes.length;
65
 		minParameters = parameterTypes.length;
61
 		maxParameters = parameterTypes.length;
66
 		maxParameters = parameterTypes.length;
67
+		hasUnknowns = hasUnknowns(parameterTypes);
62
 	}
68
 	}
63
 	
69
 	
64
 	public FunctionHeader(ITypeID returnType, FunctionParameter... parameters) {
70
 	public FunctionHeader(ITypeID returnType, FunctionParameter... parameters) {
72
 		
78
 		
73
 		minParameters = getMinParameters(parameters);
79
 		minParameters = getMinParameters(parameters);
74
 		maxParameters = getMaxParameters(parameters);
80
 		maxParameters = getMaxParameters(parameters);
81
+		hasUnknowns = hasUnknowns(parameters);
75
 	}
82
 	}
76
 	
83
 	
77
 	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
84
 	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
87
 		
94
 		
88
 		minParameters = getMinParameters(parameters);
95
 		minParameters = getMinParameters(parameters);
89
 		maxParameters = getMaxParameters(parameters);
96
 		maxParameters = getMaxParameters(parameters);
97
+		hasUnknowns = hasUnknowns(parameters);
90
 	}
98
 	}
91
 	
99
 	
92
 	public int getNumberOfTypeParameters() {
100
 	public int getNumberOfTypeParameters() {
93
 		return typeParameters.length;
101
 		return typeParameters.length;
94
 	}
102
 	}
95
 	
103
 	
104
+	public FunctionHeader withReturnType(ITypeID returnType) {
105
+		return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
106
+	}
107
+	
108
+	public FunctionHeader inferFromOverride(GlobalTypeRegistry registry, FunctionHeader overridden) {
109
+		TypeParameter[] resultTypeParameters = typeParameters;
110
+		GenericMapper mapper;
111
+		if (resultTypeParameters == TypeParameter.NONE) {
112
+			resultTypeParameters = overridden.typeParameters;
113
+			mapper = new GenericMapper(registry, Collections.emptyMap());
114
+		} else {
115
+			Map<TypeParameter, ITypeID> mapping = new HashMap<>();
116
+			for (int i = 0; i < overridden.typeParameters.length; i++)
117
+				mapping.put(overridden.typeParameters[i], new GenericTypeID(typeParameters[i]));
118
+			mapper = new GenericMapper(registry, mapping);
119
+		}
120
+		
121
+		ITypeID resultReturnType = this.returnType;
122
+		if (resultReturnType == BasicTypeID.UNDETERMINED)
123
+			resultReturnType = overridden.returnType.instance(mapper);
124
+		
125
+		ITypeID resultThrownType = this.thrownType;
126
+		if (resultThrownType == null && overridden.thrownType != null)
127
+			resultThrownType = overridden.thrownType.instance(mapper);
128
+		
129
+		FunctionParameter[] resultParameters = Arrays.copyOf(parameters, parameters.length);
130
+		for (int i = 0; i < resultParameters.length; i++) {
131
+			if (resultParameters[i].type == BasicTypeID.UNDETERMINED) {
132
+				FunctionParameter parameter = resultParameters[i];
133
+				FunctionParameter original = overridden.parameters[i];
134
+				resultParameters[i] = new FunctionParameter(original.type.instance(mapper), parameter.name, parameter.defaultValue, original.variadic);
135
+			}
136
+		}
137
+		
138
+		return new FunctionHeader(resultTypeParameters, resultReturnType, resultThrownType, resultParameters);
139
+	}
140
+	
96
 	public boolean matchesExactly(CallArguments arguments, TypeScope scope) {
141
 	public boolean matchesExactly(CallArguments arguments, TypeScope scope) {
97
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
142
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
98
 			return false;
143
 			return false;
211
 		return true;
256
 		return true;
212
 	}
257
 	}
213
 	
258
 	
259
+	public boolean canOverride(TypeScope scope, FunctionHeader other) {
260
+		if (parameters.length != other.parameters.length)
261
+			return false;
262
+		if (returnType != BasicTypeID.UNDETERMINED && !scope.getTypeMembers(returnType).canCastImplicit(other.returnType))
263
+			return false;
264
+		
265
+		for (int i = 0; i < parameters.length; i++) {
266
+			if (parameters[i].type == BasicTypeID.UNDETERMINED)
267
+				continue;
268
+			
269
+			if (parameters[i].variadic != other.parameters[i].variadic)
270
+				return false;
271
+			if (!scope.getTypeMembers(other.parameters[i].type).canCastImplicit(parameters[i].type))
272
+				return false;
273
+		}
274
+		
275
+		return true;
276
+	}
277
+	
214
 	/**
278
 	/**
215
 	 * Checks if two function headers are equivalent. Functions headers are
279
 	 * Checks if two function headers are equivalent. Functions headers are
216
 	 * equivalent if their types are the same.
280
 	 * equivalent if their types are the same.
361
 		
425
 		
362
 		return parameters[parameters.length - 1].variadic ? Integer.MAX_VALUE : parameters.length;
426
 		return parameters[parameters.length - 1].variadic ? Integer.MAX_VALUE : parameters.length;
363
 	}
427
 	}
428
+	
429
+	private static boolean hasUnknowns(ITypeID[] types) {
430
+		for (ITypeID type : types)
431
+			if (type == BasicTypeID.UNDETERMINED)
432
+				return true;
433
+		
434
+		return false;
435
+	}
436
+	
437
+	private static boolean hasUnknowns(FunctionParameter[] parameters) {
438
+		for (FunctionParameter parameter : parameters)
439
+			if (parameter.type == BasicTypeID.UNDETERMINED)
440
+				return true;
441
+		
442
+		return false;
443
+	}
364
 }
444
 }

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java View File

73
 	public static boolean isExtern(int modifiers) {
73
 	public static boolean isExtern(int modifiers) {
74
 		return (modifiers & EXTERN) > 0;
74
 		return (modifiers & EXTERN) > 0;
75
 	}
75
 	}
76
+	
77
+	public static boolean isOverride(int modifiers) {
78
+		return (modifiers & OVERRIDE) > 0;
79
+	}
76
 }
80
 }

+ 13
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java View File

32
 import org.openzen.zenscript.codemodel.member.OperatorMember;
32
 import org.openzen.zenscript.codemodel.member.OperatorMember;
33
 import org.openzen.zenscript.codemodel.member.SetterMember;
33
 import org.openzen.zenscript.codemodel.member.SetterMember;
34
 import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
34
 import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
35
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
36
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
35
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
37
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
36
 import org.openzen.zenscript.codemodel.scope.FileScope;
38
 import org.openzen.zenscript.codemodel.scope.FileScope;
37
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
39
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
187
 		@Override
189
 		@Override
188
 		public Void visitStaticInitializer(StaticInitializerMember member) {
190
 		public Void visitStaticInitializer(StaticInitializerMember member) {
189
 			StatementScope scope = new FunctionScope(this.scope, new FunctionHeader(BasicTypeID.VOID));
191
 			StatementScope scope = new FunctionScope(this.scope, new FunctionHeader(BasicTypeID.VOID));
190
-			member.body = process(member.body, scope);
192
+			if (member.body == null) {
193
+				throw new IllegalStateException("No body in static initializer @ " + member.position);
194
+			} else {
195
+				member.body = process(member.body, scope);
196
+			}
191
 			return null;
197
 			return null;
192
 		}
198
 		}
193
 		
199
 		
195
 			for (MemberAnnotation annotation : member.annotations)
201
 			for (MemberAnnotation annotation : member.annotations)
196
 				annotation.apply(member, scope);
202
 				annotation.apply(member, scope);
197
 			
203
 			
198
-			if (member.overrides != null) {
199
-				functional(member, member.overrides);
204
+			if (member.getOverrides() != null) {
205
+				functional(member, member.getOverrides());
200
 			}
206
 			}
201
 			
207
 			
202
 			if (member.body == null)
208
 			if (member.body == null)
207
 			return null;
213
 			return null;
208
 		}
214
 		}
209
 		
215
 		
210
-		private void functional(FunctionalMember member, FunctionalMember overrides) {
211
-			for (MemberAnnotation annotation : overrides.annotations)
216
+		private void functional(FunctionalMember member, DefinitionMemberRef overrides) {
217
+			for (MemberAnnotation annotation : overrides.getAnnotations())
212
 				annotation.applyOnOverridingMethod(member, scope);
218
 				annotation.applyOnOverridingMethod(member, scope);
213
 			
219
 			
214
-			if (overrides.overrides != null) {
215
-				functional(member, overrides.overrides);
220
+			if (overrides.getOverrides() != null) {
221
+				functional(member, overrides.getOverrides());
216
 			}
222
 			}
217
 		}
223
 		}
218
 	}
224
 	}

+ 9
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java View File

18
  * @author Hoofdgebruiker
18
  * @author Hoofdgebruiker
19
  */
19
  */
20
 public class CallArguments {
20
 public class CallArguments {
21
-	public static final ITypeID[] NO_TYPE_ARGUMENTS = new ITypeID[0];
22
 	public static final CallArguments EMPTY = new CallArguments(new Expression[0]);
21
 	public static final CallArguments EMPTY = new CallArguments(new Expression[0]);
23
 	
22
 	
24
 	public final ITypeID[] typeArguments;
23
 	public final ITypeID[] typeArguments;
25
 	public final Expression[] arguments;
24
 	public final Expression[] arguments;
26
 	
25
 	
27
 	public CallArguments(Expression... arguments) {
26
 	public CallArguments(Expression... arguments) {
28
-		this.typeArguments = NO_TYPE_ARGUMENTS;
27
+		this.typeArguments = ITypeID.NONE;
29
 		this.arguments = arguments;
28
 		this.arguments = arguments;
30
 	}
29
 	}
31
 	
30
 	
32
 	public CallArguments(ITypeID[] typeArguments, Expression[] arguments) {
31
 	public CallArguments(ITypeID[] typeArguments, Expression[] arguments) {
33
 		if (typeArguments == null)
32
 		if (typeArguments == null)
34
-			typeArguments = NO_TYPE_ARGUMENTS;
33
+			typeArguments = ITypeID.NONE;
35
 		if (arguments == null)
34
 		if (arguments == null)
36
 			throw new IllegalArgumentException("Arguments cannot be null!");
35
 			throw new IllegalArgumentException("Arguments cannot be null!");
37
 		
36
 		
39
 		this.arguments = arguments;
38
 		this.arguments = arguments;
40
 	}
39
 	}
41
 	
40
 	
41
+	public CallArguments(ITypeID... dummy) {
42
+		this.typeArguments = ITypeID.NONE;
43
+		this.arguments = new Expression[dummy.length];
44
+		for (int i = 0; i < dummy.length; i++)
45
+			arguments[i] = new DummyExpression(dummy[i]);
46
+	}
47
+	
42
 	public int getNumberOfTypeArguments() {
48
 	public int getNumberOfTypeArguments() {
43
 		return typeArguments.length;
49
 		return typeArguments.length;
44
 	}
50
 	}

+ 29
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/DummyExpression.java View File

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.codemodel.expression;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DummyExpression extends Expression {
16
+	public DummyExpression(ITypeID type) {
17
+		super(CodePosition.BUILTIN, type, null);
18
+	}
19
+
20
+	@Override
21
+	public <T> T accept(ExpressionVisitor<T> visitor) {
22
+		throw new UnsupportedOperationException("This is a dummy expression");
23
+	}
24
+
25
+	@Override
26
+	public Expression transform(ExpressionTransformer transformer) {
27
+		throw new UnsupportedOperationException("This is a dummy expression");
28
+	}
29
+}

+ 10
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java View File

81
 		return scope.getTypeMembers(type).castImplicit(position, this, asType, true);
81
 		return scope.getTypeMembers(type).castImplicit(position, this, asType, true);
82
 	}
82
 	}
83
 	
83
 	
84
+	/**
85
+	 * Determines if this expression aborts execution; that is, it is either a
86
+	 * throw or a panic expression.
87
+	 * 
88
+	 * @return abort flag
89
+	 */
90
+	public boolean aborts() {
91
+		return false;
92
+	}
93
+	
84
 	@Override
94
 	@Override
85
 	public List<ITypeID>[] predictCallTypes(TypeScope scope, List<ITypeID> hints, int arguments) {
95
 	public List<ITypeID>[] predictCallTypes(TypeScope scope, List<ITypeID> hints, int arguments) {
86
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).predictCallTypes(scope, hints, arguments);
96
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).predictCallTypes(scope, hints, arguments);

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PanicExpression.java View File

20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}
23
+	
24
+	@Override
25
+	public boolean aborts() {
26
+		return true;
27
+	}
23
 
28
 
24
 	@Override
29
 	@Override
25
 	public <T> T accept(ExpressionVisitor<T> visitor) {
30
 	public <T> T accept(ExpressionVisitor<T> visitor) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThrowExpression.java View File

20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}
23
+	
24
+	@Override
25
+	public boolean aborts() {
26
+		return true;
27
+	}
23
 
28
 
24
 	@Override
29
 	@Override
25
 	public <T> T accept(ExpressionVisitor<T> visitor) {
30
 	public <T> T accept(ExpressionVisitor<T> visitor) {

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

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
  * @author Hoofdgebruiker
21
  * @author Hoofdgebruiker
19
  */
22
  */
20
 public class CallerMember extends FunctionalMember {
23
 public class CallerMember extends FunctionalMember {
24
+	public FunctionalMemberRef overrides;
25
+	
21
 	public CallerMember(
26
 	public CallerMember(
22
 			CodePosition position,
27
 			CodePosition position,
23
 			HighLevelDefinition definition,
28
 			HighLevelDefinition definition,
25
 			FunctionHeader header,
30
 			FunctionHeader header,
26
 			BuiltinID builtin)
31
 			BuiltinID builtin)
27
 	{
32
 	{
28
-		super(position, definition, modifiers, "()", header, builtin);
33
+		super(position, definition, modifiers, header, builtin);
29
 	}
34
 	}
30
 	
35
 	
31
 	@Override
36
 	@Override
52
 	public <T> T accept(MemberVisitor<T> visitor) {
57
 	public <T> T accept(MemberVisitor<T> visitor) {
53
 		return visitor.visitCaller(this);
58
 		return visitor.visitCaller(this);
54
 	}
59
 	}
60
+	
61
+	public void setOverrides(GlobalTypeRegistry registry, FunctionalMemberRef overrides) {
62
+		this.overrides = overrides;
63
+		header = header.inferFromOverride(registry, overrides.getHeader());
64
+	}
65
+
66
+	@Override
67
+	public DefinitionMemberRef getOverrides() {
68
+		return overrides;
69
+	}
55
 }
70
 }

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

11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.Modifiers;
12
 import org.openzen.zenscript.codemodel.Modifiers;
13
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
22
  */
23
  */
23
 public class CasterMember extends FunctionalMember {
24
 public class CasterMember extends FunctionalMember {
24
 	public final ITypeID toType;
25
 	public final ITypeID toType;
26
+	public CasterMemberRef overrides;
25
 	
27
 	
26
 	public CasterMember(
28
 	public CasterMember(
27
 			CodePosition position,
29
 			CodePosition position,
30
 			ITypeID toType,
32
 			ITypeID toType,
31
 			BuiltinID builtin)
33
 			BuiltinID builtin)
32
 	{
34
 	{
33
-		super(position, definition, modifiers, "as", new FunctionHeader(toType), builtin);
35
+		super(position, definition, modifiers, new FunctionHeader(toType), builtin);
34
 		
36
 		
35
 		this.toType = toType;
37
 		this.toType = toType;
36
 	}
38
 	}
67
 	public <T> T accept(MemberVisitor<T> visitor) {
69
 	public <T> T accept(MemberVisitor<T> visitor) {
68
 		return visitor.visitCaster(this);
70
 		return visitor.visitCaster(this);
69
 	}
71
 	}
72
+	
73
+	public void setOverrides(GlobalTypeRegistry registry, CasterMemberRef overrides) {
74
+		this.overrides = overrides;
75
+	}
76
+
77
+	@Override
78
+	public CasterMemberRef getOverrides() {
79
+		return overrides;
80
+	}
70
 }
81
 }

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

10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
12
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
13
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
21
  */
22
  */
22
 public class ConstMember extends DefinitionMember {
23
 public class ConstMember extends DefinitionMember {
23
 	public final String name;
24
 	public final String name;
24
-	public final ITypeID type;
25
+	public ITypeID type;
25
 	public Expression value;
26
 	public Expression value;
26
 	public final BuiltinID builtin;
27
 	public final BuiltinID builtin;
27
 	
28
 	
52
 	public <T> T accept(MemberVisitor<T> visitor) {
53
 	public <T> T accept(MemberVisitor<T> visitor) {
53
 		return visitor.visitConst(this);
54
 		return visitor.visitConst(this);
54
 	}
55
 	}
56
+
57
+	@Override
58
+	public DefinitionMemberRef getOverrides() {
59
+		return null;
60
+	}
55
 }
61
 }

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

11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
12
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
13
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
13
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
15
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
15
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
16
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
34
 				position,
35
 				position,
35
 				definition,
36
 				definition,
36
 				modifiers,
37
 				modifiers,
37
-				"this",
38
 				new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.thrownType, header.parameters),
38
 				new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.thrownType, header.parameters),
39
 				builtin);
39
 				builtin);
40
 	}
40
 	}
79
 	public <T> T accept(MemberVisitor<T> visitor) {
79
 	public <T> T accept(MemberVisitor<T> visitor) {
80
 		return visitor.visitConstructor(this);
80
 		return visitor.visitConstructor(this);
81
 	}
81
 	}
82
+
83
+	@Override
84
+	public DefinitionMemberRef getOverrides() {
85
+		return null;
86
+	}
82
 }
87
 }

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java View File

9
 import org.openzen.zenscript.codemodel.GenericMapper;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
13
 import org.openzen.zenscript.codemodel.statement.Statement;
14
 import org.openzen.zenscript.codemodel.statement.Statement;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
 public class CustomIteratorMember extends DefinitionMember implements IIteratorMember {
24
 public class CustomIteratorMember extends DefinitionMember implements IIteratorMember {
24
 	private final ITypeID[] iteratorTypes;
25
 	private final ITypeID[] iteratorTypes;
25
 	public Statement body;
26
 	public Statement body;
27
+	public IteratorMemberRef overrides;
26
 	
28
 	
27
 	public CustomIteratorMember(CodePosition position, HighLevelDefinition definition, int modifiers, ITypeID[] iteratorTypes) {
29
 	public CustomIteratorMember(CodePosition position, HighLevelDefinition definition, int modifiers, ITypeID[] iteratorTypes) {
28
 		super(position, definition, modifiers);
30
 		super(position, definition, modifiers);
68
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
70
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
69
 		return visitor.visitCustomIterator();
71
 		return visitor.visitCustomIterator();
70
 	}
72
 	}
73
+	
74
+	public void setOverrides(IteratorMemberRef overrides) {
75
+		this.overrides = overrides;
76
+	}
77
+
78
+	@Override
79
+	public DefinitionMemberRef getOverrides() {
80
+		return overrides;
81
+	}
71
 }
82
 }

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

18
 public abstract class DefinitionMember extends Taggable implements IDefinitionMember {
18
 public abstract class DefinitionMember extends Taggable implements IDefinitionMember {
19
 	public final CodePosition position;
19
 	public final CodePosition position;
20
 	public final HighLevelDefinition definition;
20
 	public final HighLevelDefinition definition;
21
-	public final int modifiers;
21
+	public int modifiers;
22
 	public MemberAnnotation[] annotations = MemberAnnotation.NONE;
22
 	public MemberAnnotation[] annotations = MemberAnnotation.NONE;
23
 	
23
 	
24
 	public DefinitionMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
24
 	public DefinitionMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
43
 	public boolean isExtern() {
43
 	public boolean isExtern() {
44
 		return Modifiers.isExtern(modifiers);
44
 		return Modifiers.isExtern(modifiers);
45
 	}
45
 	}
46
+	
47
+	public boolean isPrivate() {
48
+		return Modifiers.isPrivate(modifiers);
49
+	}
50
+	
51
+	public boolean isPublic() {
52
+		return Modifiers.isPublic(modifiers);
53
+	}
54
+	
55
+	public boolean isProtected() {
56
+		return Modifiers.isProtected(modifiers);
57
+	}
46
 }
58
 }

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

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
12
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
19
  */
21
  */
20
 public class DestructorMember extends FunctionalMember {
22
 public class DestructorMember extends FunctionalMember {
21
 	private static final FunctionHeader HEADER = new FunctionHeader(BasicTypeID.VOID);
23
 	private static final FunctionHeader HEADER = new FunctionHeader(BasicTypeID.VOID);
24
+	public FunctionalMemberRef overrides;
22
 	
25
 	
23
 	public DestructorMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
26
 	public DestructorMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
24
-		super(position, definition, modifiers, "~this", HEADER, null);
27
+		super(position, definition, modifiers, HEADER, null);
25
 	}
28
 	}
26
 	
29
 	
27
 	@Override
30
 	@Override
49
 	public <T> T accept(MemberVisitor<T> visitor) {
52
 	public <T> T accept(MemberVisitor<T> visitor) {
50
 		return visitor.visitDestructor(this);
53
 		return visitor.visitDestructor(this);
51
 	}
54
 	}
55
+
56
+	@Override
57
+	public DefinitionMemberRef getOverrides() {
58
+		return overrides;
59
+	}
52
 }
60
 }

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

13
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
13
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
14
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
14
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
15
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
15
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
16
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
16
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
17
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
17
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
18
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
18
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
19
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
29
  */
30
  */
30
 public class FieldMember extends DefinitionMember {
31
 public class FieldMember extends DefinitionMember {
31
 	public final String name;
32
 	public final String name;
32
-	public final ITypeID type;
33
+	public ITypeID type;
33
 	public Expression initializer;
34
 	public Expression initializer;
34
 	public final int autoGetterAccess;
35
 	public final int autoGetterAccess;
35
 	public final int autoSetterAccess;
36
 	public final int autoSetterAccess;
138
 	public <T> T accept(MemberVisitor<T> visitor) {
139
 	public <T> T accept(MemberVisitor<T> visitor) {
139
 		return visitor.visitField(this);
140
 		return visitor.visitField(this);
140
 	}
141
 	}
142
+
143
+	@Override
144
+	public DefinitionMemberRef getOverrides() {
145
+		return null;
146
+	}
141
 }
147
 }

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

18
  * @author Hoofdgebruiker
18
  * @author Hoofdgebruiker
19
  */
19
  */
20
 public abstract class FunctionalMember extends DefinitionMember {
20
 public abstract class FunctionalMember extends DefinitionMember {
21
-	public final FunctionHeader header;
22
-	public final String name;
21
+	public FunctionHeader header;
23
 	public final BuiltinID builtin;
22
 	public final BuiltinID builtin;
24
 	public Statement body = null;
23
 	public Statement body = null;
25
-	public FunctionalMember overrides = null;
26
 	
24
 	
27
 	public FunctionalMember(
25
 	public FunctionalMember(
28
 			CodePosition position,
26
 			CodePosition position,
29
 			HighLevelDefinition definition,
27
 			HighLevelDefinition definition,
30
 			int modifiers,
28
 			int modifiers,
31
-			String name,
32
 			FunctionHeader header,
29
 			FunctionHeader header,
33
 			BuiltinID builtin) {
30
 			BuiltinID builtin) {
34
 		super(position, definition, modifiers);
31
 		super(position, definition, modifiers);
35
 		
32
 		
36
-		this.name = name;
37
 		this.header = header;
33
 		this.header = header;
38
 		this.builtin = builtin;
34
 		this.builtin = builtin;
39
 	}
35
 	}

+ 17
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java View File

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
21
  */
23
  */
22
 public class GetterMember extends FunctionalMember {
24
 public class GetterMember extends FunctionalMember {
23
 	public final String name;
25
 	public final String name;
24
-	public final ITypeID type;
26
+	public ITypeID type;
27
+	private GetterMemberRef overrides;
25
 	
28
 	
26
 	public GetterMember(
29
 	public GetterMember(
27
 			CodePosition position,
30
 			CodePosition position,
30
 			String name,
33
 			String name,
31
 			ITypeID type,
34
 			ITypeID type,
32
 			BuiltinID builtin) {
35
 			BuiltinID builtin) {
33
-		super(position, definition, modifiers, name, new FunctionHeader(type), builtin);
36
+		super(position, definition, modifiers, new FunctionHeader(type), builtin);
34
 		
37
 		
35
 		this.name = name;
38
 		this.name = name;
36
 		this.type = type;
39
 		this.type = type;
60
 	public <T> T accept(MemberVisitor<T> visitor) {
63
 	public <T> T accept(MemberVisitor<T> visitor) {
61
 		return visitor.visitGetter(this);
64
 		return visitor.visitGetter(this);
62
 	}
65
 	}
66
+
67
+	@Override
68
+	public GetterMemberRef getOverrides() {
69
+		return overrides;
70
+	}
71
+	
72
+	public void setOverrides(GetterMemberRef override) {
73
+		this.overrides = override;
74
+		
75
+		if (type == BasicTypeID.UNDETERMINED)
76
+			type = override.type;
77
+	}
63
 }
78
 }

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java View File

6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
10
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
12
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
11
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
12
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
31
 	public <T> void setTag(Class<T> tag, T value);
33
 	public <T> void setTag(Class<T> tag, T value);
32
 
34
 
33
 	<T> boolean hasTag(Class<T> tag);
35
 	<T> boolean hasTag(Class<T> tag);
36
+	
37
+	DefinitionMemberRef getOverrides();
34
 }
38
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java View File

10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.ImplementationMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.ImplementationMemberRef;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
57
 	public <T> T accept(MemberVisitor<T> visitor) {
58
 	public <T> T accept(MemberVisitor<T> visitor) {
58
 		return visitor.visitImplementation(this);
59
 		return visitor.visitImplementation(this);
59
 	}
60
 	}
61
+
62
+	@Override
63
+	public DefinitionMemberRef getOverrides() {
64
+		return null;
65
+	}
60
 }
66
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java View File

8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
11
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
12
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
12
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
48
 	public <T> T accept(MemberVisitor<T> visitor) {
49
 	public <T> T accept(MemberVisitor<T> visitor) {
49
 		return visitor.visitInnerDefinition(this);
50
 		return visitor.visitInnerDefinition(this);
50
 	}
51
 	}
52
+
53
+	@Override
54
+	public DefinitionMemberRef getOverrides() {
55
+		return null;
56
+	}
51
 }
57
 }

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

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Modifiers;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
  * @author Hoofdgebruiker
21
  * @author Hoofdgebruiker
19
  */
22
  */
20
 public class MethodMember extends FunctionalMember {
23
 public class MethodMember extends FunctionalMember {
24
+	public final String name;
25
+	private FunctionalMemberRef overrides;
26
+	
21
 	public MethodMember(CodePosition position, HighLevelDefinition definition, int modifiers, String name, FunctionHeader header, BuiltinID builtin) {
27
 	public MethodMember(CodePosition position, HighLevelDefinition definition, int modifiers, String name, FunctionHeader header, BuiltinID builtin) {
22
-		super(position, definition, modifiers, name, header, builtin);
28
+		super(position, definition, modifiers, header, builtin);
29
+		
30
+		this.name = name;
23
 	}
31
 	}
24
 	
32
 	
25
 	@Override
33
 	@Override
46
 	public <T> T accept(MemberVisitor<T> visitor) {
54
 	public <T> T accept(MemberVisitor<T> visitor) {
47
 		return visitor.visitMethod(this);
55
 		return visitor.visitMethod(this);
48
 	}
56
 	}
57
+
58
+	@Override
59
+	public FunctionalMemberRef getOverrides() {
60
+		return overrides;
61
+	}
62
+	
63
+	public void setOverrides(GlobalTypeRegistry registry, FunctionalMemberRef overrides) {
64
+		this.overrides = overrides;
65
+		header = header.inferFromOverride(registry, overrides.header);
66
+		
67
+		if (overrides.getTarget().isPublic())
68
+			modifiers |= Modifiers.PUBLIC;
69
+		if (overrides.getTarget().isProtected())
70
+			modifiers |= Modifiers.PROTECTED;
71
+	}
49
 }
72
 }

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

10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.OperatorType;
12
 import org.openzen.zenscript.codemodel.OperatorType;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
20
  */
22
  */
21
 public class OperatorMember extends FunctionalMember {
23
 public class OperatorMember extends FunctionalMember {
22
 	public final OperatorType operator;
24
 	public final OperatorType operator;
25
+	private FunctionalMemberRef overrides;
23
 	
26
 	
24
 	public OperatorMember(
27
 	public OperatorMember(
25
 			CodePosition position,
28
 			CodePosition position,
29
 			FunctionHeader header,
32
 			FunctionHeader header,
30
 			BuiltinID builtin)
33
 			BuiltinID builtin)
31
 	{
34
 	{
32
-		super(position, definition, modifiers, operator.operator, header, builtin);
35
+		super(position, definition, modifiers, header, builtin);
33
 		
36
 		
34
 		this.operator = operator;
37
 		this.operator = operator;
35
 	}
38
 	}
58
 	public <T> T accept(MemberVisitor<T> visitor) {
61
 	public <T> T accept(MemberVisitor<T> visitor) {
59
 		return visitor.visitOperator(this);
62
 		return visitor.visitOperator(this);
60
 	}
63
 	}
64
+
65
+	@Override
66
+	public FunctionalMemberRef getOverrides() {
67
+		return overrides;
68
+	}
69
+	
70
+	public void setOverrides(GlobalTypeRegistry registry, FunctionalMemberRef overrides) {
71
+		this.overrides = overrides;
72
+		header = header.inferFromOverride(registry, overrides.header);
73
+	}
61
 }
74
 }

+ 16
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java View File

22
  * @author Hoofdgebruiker
22
  * @author Hoofdgebruiker
23
  */
23
  */
24
 public class SetterMember extends FunctionalMember {
24
 public class SetterMember extends FunctionalMember {
25
-	public final ITypeID type;
25
+	public ITypeID type;
26
+	public final String name;
27
+	private SetterMemberRef overrides;
26
 	
28
 	
27
 	public SetterMember(
29
 	public SetterMember(
28
 			CodePosition position,
30
 			CodePosition position,
35
 		super(position,
37
 		super(position,
36
 				definition,
38
 				definition,
37
 				modifiers,
39
 				modifiers,
38
-				name,
39
 				new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(type, "$")),
40
 				new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(type, "$")),
40
 				builtin);
41
 				builtin);
41
 		
42
 		
42
 		this.type = type;
43
 		this.type = type;
44
+		this.name = name;
43
 	}
45
 	}
44
 	
46
 	
45
 	@Override
47
 	@Override
66
 	public <T> T accept(MemberVisitor<T> visitor) {
68
 	public <T> T accept(MemberVisitor<T> visitor) {
67
 		return visitor.visitSetter(this);
69
 		return visitor.visitSetter(this);
68
 	}
70
 	}
71
+
72
+	@Override
73
+	public SetterMemberRef getOverrides() {
74
+		return overrides;
75
+	}
76
+	
77
+	public void setOverrides(SetterMemberRef overrides) {
78
+		this.overrides = overrides;
79
+		
80
+		if (type == BasicTypeID.UNDETERMINED)
81
+			type = overrides.type;
82
+	}
69
 }
83
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java View File

9
 import org.openzen.zencode.shared.Taggable;
9
 import org.openzen.zencode.shared.Taggable;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12
 import org.openzen.zenscript.codemodel.statement.Statement;
13
 import org.openzen.zenscript.codemodel.statement.Statement;
13
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
14
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
51
 	public <T> T accept(MemberVisitor<T> visitor) {
52
 	public <T> T accept(MemberVisitor<T> visitor) {
52
 		return visitor.visitStaticInitializer(this);
53
 		return visitor.visitStaticInitializer(this);
53
 	}
54
 	}
55
+
56
+	@Override
57
+	public DefinitionMemberRef getOverrides() {
58
+		return null;
59
+	}
54
 }
60
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java View File

11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
75
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
76
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
76
 		return visitor.visitArrayKeyValueIterator();
77
 		return visitor.visitArrayKeyValueIterator();
77
 	}
78
 	}
79
+
80
+	@Override
81
+	public DefinitionMemberRef getOverrides() {
82
+		return null;
83
+	}
78
 }
84
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java View File

11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
70
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
71
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
71
 		return visitor.visitArrayValueIterator();
72
 		return visitor.visitArrayValueIterator();
72
 	}
73
 	}
74
+
75
+	@Override
76
+	public DefinitionMemberRef getOverrides() {
77
+		return null;
78
+	}
73
 }
79
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java View File

11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
16
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
73
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
74
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
74
 		return visitor.visitAssocKeyValueIterator();
75
 		return visitor.visitAssocKeyValueIterator();
75
 	}
76
 	}
77
+
78
+	@Override
79
+	public DefinitionMemberRef getOverrides() {
80
+		return null;
81
+	}
76
 }
82
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java View File

11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
81
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
82
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
82
 		return visitor.visitIntRange();
83
 		return visitor.visitIntRange();
83
 	}
84
 	}
85
+
86
+	@Override
87
+	public DefinitionMemberRef getOverrides() {
88
+		return null;
89
+	}
84
 }
90
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java View File

11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
64
 	public <T> T accept(MemberVisitor<T> visitor) {
65
 	public <T> T accept(MemberVisitor<T> visitor) {
65
 		throw new UnsupportedOperationException("Not a compilable member");
66
 		throw new UnsupportedOperationException("Not a compilable member");
66
 	}
67
 	}
68
+
69
+	@Override
70
+	public DefinitionMemberRef getOverrides() {
71
+		return null;
72
+	}
67
 }
73
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.Modifiers;
10
 import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
10
 import org.openzen.zenscript.codemodel.expression.CastExpression;
12
 import org.openzen.zenscript.codemodel.expression.CastExpression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.member.CasterMember;
14
 import org.openzen.zenscript.codemodel.member.CasterMember;
47
 	public boolean isImplicit() {
49
 	public boolean isImplicit() {
48
 		return Modifiers.isImplicit(member.modifiers);
50
 		return Modifiers.isImplicit(member.modifiers);
49
 	}
51
 	}
52
+
53
+	@Override
54
+	public DefinitionMemberRef getOverrides() {
55
+		return member.getOverrides();
56
+	}
57
+
58
+	@Override
59
+	public FunctionHeader getHeader() {
60
+		return member.header;
61
+	}
62
+
63
+	@Override
64
+	public MemberAnnotation[] getAnnotations() {
65
+		return member.annotations;
66
+	}
50
 }
67
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ConstMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9
 import org.openzen.zenscript.codemodel.member.ConstMember;
11
 import org.openzen.zenscript.codemodel.member.ConstMember;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 
13
 
36
 	public <T> T getTag(Class<T> type) {
38
 	public <T> T getTag(Class<T> type) {
37
 		return member.getTag(type);
39
 		return member.getTag(type);
38
 	}
40
 	}
41
+
42
+	@Override
43
+	public DefinitionMemberRef getOverrides() {
44
+		return null;
45
+	}
46
+
47
+	@Override
48
+	public FunctionHeader getHeader() {
49
+		return null;
50
+	}
51
+
52
+	@Override
53
+	public MemberAnnotation[] getAnnotations() {
54
+		return member.annotations;
55
+	}
39
 }
56
 }

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

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9
 
11
 
10
 /**
12
 /**
11
  *
13
  *
17
 	String describe();
19
 	String describe();
18
 	
20
 	
19
 	<T> T getTag(Class<T> type);
21
 	<T> T getTag(Class<T> type);
22
+	
23
+	DefinitionMemberRef getOverrides();
24
+	
25
+	FunctionHeader getHeader();
26
+	
27
+	MemberAnnotation[] getAnnotations();
20
 }
28
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FieldMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9
 import org.openzen.zenscript.codemodel.member.FieldMember;
11
 import org.openzen.zenscript.codemodel.member.FieldMember;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 
13
 
44
 	public boolean isFinal() {
46
 	public boolean isFinal() {
45
 		return member.isFinal();
47
 		return member.isFinal();
46
 	}
48
 	}
49
+
50
+	@Override
51
+	public DefinitionMemberRef getOverrides() {
52
+		return null;
53
+	}
54
+
55
+	@Override
56
+	public FunctionHeader getHeader() {
57
+		return null;
58
+	}
59
+
60
+	@Override
61
+	public MemberAnnotation[] getAnnotations() {
62
+		return member.annotations;
63
+	}
47
 }
64
 }

+ 22
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java View File

9
 import org.openzen.zenscript.codemodel.CompareType;
9
 import org.openzen.zenscript.codemodel.CompareType;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
12
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13
 import org.openzen.zenscript.codemodel.expression.CallExpression;
14
 import org.openzen.zenscript.codemodel.expression.CallExpression;
14
 import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
15
 import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
40
 		return target.position;
41
 		return target.position;
41
 	}
42
 	}
42
 	
43
 	
44
+	public FunctionalMember getTarget() {
45
+		return target;
46
+	}
47
+	
43
 	public String getCanonicalName() {
48
 	public String getCanonicalName() {
44
 		return target.getCanonicalName();
49
 		return target.getCanonicalName();
45
 	}
50
 	}
49
 		return target.describe();
54
 		return target.describe();
50
 	}
55
 	}
51
 	
56
 	
57
+	@Override
52
 	public <T> T getTag(Class<T> cls) {
58
 	public <T> T getTag(Class<T> cls) {
53
 		return target.getTag(cls);
59
 		return target.getTag(cls);
54
 	}
60
 	}
55
 	
61
 	
62
+	@Override
63
+	public MemberAnnotation[] getAnnotations() {
64
+		return target.annotations;
65
+	}
66
+	
67
+	@Override
68
+	public DefinitionMemberRef getOverrides() {
69
+		return target.getOverrides();
70
+	}
71
+
72
+	@Override
73
+	public FunctionHeader getHeader() {
74
+		return header;
75
+	}
76
+	
56
 	public BuiltinID getBuiltin() {
77
 	public BuiltinID getBuiltin() {
57
 		return target.builtin;
78
 		return target.builtin;
58
 	}
79
 	}
79
 	}
100
 	}
80
 	
101
 	
81
 	public String getMethodName() {
102
 	public String getMethodName() {
82
-		//FIXME
83
-		return (target).name;
103
+		return ((MethodMember) target).name;
84
 	}
104
 	}
85
 	
105
 	
86
 	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
106
 	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/GetterMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
12
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
11
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
13
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
51
 	public Expression getStatic(CodePosition position) {
53
 	public Expression getStatic(CodePosition position) {
52
 		return new StaticGetterExpression(position, this);
54
 		return new StaticGetterExpression(position, this);
53
 	}
55
 	}
56
+
57
+	@Override
58
+	public DefinitionMemberRef getOverrides() {
59
+		return member.getOverrides();
60
+	}
61
+
62
+	@Override
63
+	public FunctionHeader getHeader() {
64
+		return member.header;
65
+	}
66
+
67
+	@Override
68
+	public MemberAnnotation[] getAnnotations() {
69
+		return member.annotations;
70
+	}
54
 }
71
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
11
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 
13
 
36
 	public <T> T getTag(Class<T> type) {
38
 	public <T> T getTag(Class<T> type) {
37
 		return member.getTag(type);
39
 		return member.getTag(type);
38
 	}
40
 	}
41
+
42
+	@Override
43
+	public DefinitionMemberRef getOverrides() {
44
+		return null;
45
+	}
46
+
47
+	@Override
48
+	public FunctionHeader getHeader() {
49
+		return null;
50
+	}
51
+
52
+	@Override
53
+	public MemberAnnotation[] getAnnotations() {
54
+		return member.annotations;
55
+	}
39
 }
56
 }

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11
+import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
9
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 
14
 
40
 	public int getLoopVariableCount() {
43
 	public int getLoopVariableCount() {
41
 		return types.length;
44
 		return types.length;
42
 	}
45
 	}
46
+
47
+	@Override
48
+	public DefinitionMemberRef getOverrides() {
49
+		return target.getOverrides();
50
+	}
51
+
52
+	@Override
53
+	public FunctionHeader getHeader() {
54
+		return null; // TODO
55
+	}
56
+
57
+	@Override
58
+	public MemberAnnotation[] getAnnotations() {
59
+		if (target instanceof CustomIteratorMember) {
60
+			return ((CustomIteratorMember)target).annotations;
61
+		} else {
62
+			return null;
63
+		}
64
+	}
43
 }
65
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/SetterMemberRef.java View File

6
 package org.openzen.zenscript.codemodel.member.ref;
6
 package org.openzen.zenscript.codemodel.member.ref;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9
 import org.openzen.zenscript.codemodel.member.SetterMember;
11
 import org.openzen.zenscript.codemodel.member.SetterMember;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 
13
 
40
 	public boolean isStatic() {
42
 	public boolean isStatic() {
41
 		return member.isStatic();
43
 		return member.isStatic();
42
 	}
44
 	}
45
+
46
+	@Override
47
+	public DefinitionMemberRef getOverrides() {
48
+		return member.getOverrides();
49
+	}
50
+
51
+	@Override
52
+	public FunctionHeader getHeader() {
53
+		return member.header;
54
+	}
55
+
56
+	@Override
57
+	public MemberAnnotation[] getAnnotations() {
58
+		return member.annotations;
59
+	}
43
 }
60
 }

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java View File

23
  * @author Hoofdgebruiker
23
  * @author Hoofdgebruiker
24
  */
24
  */
25
 public abstract class BaseScope implements TypeScope {
25
 public abstract class BaseScope implements TypeScope {
26
-	public abstract LocalMemberCache getMemberCache();
27
-	
28
 	public abstract IPartialExpression get(CodePosition position, GenericName name);
26
 	public abstract IPartialExpression get(CodePosition position, GenericName name);
29
 	
27
 	
30
 	public abstract ITypeID getType(CodePosition position, List<GenericName> name);
28
 	public abstract ITypeID getType(CodePosition position, List<GenericName> name);

+ 7
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java View File

16
  * @author Hoofdgebruiker
16
  * @author Hoofdgebruiker
17
  */
17
  */
18
 public interface TypeScope {
18
 public interface TypeScope {
19
-	public GlobalTypeRegistry getTypeRegistry();
20
-	
21
 	public LocalMemberCache getMemberCache();
19
 	public LocalMemberCache getMemberCache();
22
 	
20
 	
23
-	public TypeMembers getTypeMembers(ITypeID type);
21
+	default TypeMembers getTypeMembers(ITypeID type) {
22
+		return getMemberCache().get(type);
23
+	}
24
+	
25
+	default GlobalTypeRegistry getTypeRegistry() {
26
+		return getMemberCache().getRegistry();
27
+	}
24
 	
28
 	
25
 	public AnnotationDefinition getAnnotation(String name);
29
 	public AnnotationDefinition getAnnotation(String name);
26
 }
30
 }

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

17
 public enum BasicTypeID implements ITypeID {
17
 public enum BasicTypeID implements ITypeID {
18
 	VOID("void"),
18
 	VOID("void"),
19
 	NULL("null"),
19
 	NULL("null"),
20
-	ANY("any"),
21
 	BOOL("bool"),
20
 	BOOL("bool"),
22
 	BYTE("byte"),
21
 	BYTE("byte"),
23
 	SBYTE("sbyte"),
22
 	SBYTE("sbyte"),
74
 	
73
 	
75
 	@Override
74
 	@Override
76
 	public boolean isObjectType() {
75
 	public boolean isObjectType() {
77
-		return this == ANY || this == STRING;
76
+		return this == STRING;
78
 	}
77
 	}
79
 
78
 
80
 	@Override
79
 	@Override

+ 24
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java View File

27
 import org.openzen.zenscript.codemodel.GenericMapper;
27
 import org.openzen.zenscript.codemodel.GenericMapper;
28
 import org.openzen.zenscript.codemodel.expression.ConstExpression;
28
 import org.openzen.zenscript.codemodel.expression.ConstExpression;
29
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
29
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
30
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
30
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
31
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
31
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
32
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
32
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
33
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
84
 		return this.setter == null ? null : this.setter.member;
85
 		return this.setter == null ? null : this.setter.member;
85
 	}
86
 	}
86
 	
87
 	
88
+	public FunctionalMemberRef getUnaryMethod() {
89
+		for (TypeMember<FunctionalMemberRef> method : methods)
90
+			if (method.member.header.parameters.length == 0)
91
+				return method.member;
92
+		
93
+		return null;
94
+	}
95
+	
87
 	public boolean hasMethods() {
96
 	public boolean hasMethods() {
88
 		return !methods.isEmpty();
97
 		return !methods.isEmpty();
89
 	}
98
 	}
350
 		
359
 		
351
 		return selected;
360
 		return selected;
352
 	}
361
 	}
362
+	
363
+	public FunctionalMemberRef getOverride(CodePosition position, TypeScope scope, FunctionalMember member) {
364
+		List<FunctionalMemberRef> candidates = new ArrayList<>();
365
+		for (TypeMember<FunctionalMemberRef> method : methods) {
366
+			if (member.header.canOverride(scope, method.member.header))
367
+				candidates.add(method.member);
368
+		}
369
+		
370
+		if (candidates.isEmpty())
371
+			return null;
372
+		if (candidates.size() == 1)
373
+			return candidates.get(0);
374
+		
375
+		throw new CompileException(position, CompileExceptionCode.OVERRIDE_AMBIGUOUS, "Ambiguous override: has " + candidates.size() + " base candidates");
376
+	}
353
 }
377
 }

+ 19
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java View File

23
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
23
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
24
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
24
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
25
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
25
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
26
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
26
 import org.openzen.zenscript.codemodel.member.InnerDefinition;
27
 import org.openzen.zenscript.codemodel.member.InnerDefinition;
28
+import org.openzen.zenscript.codemodel.member.MethodMember;
29
+import org.openzen.zenscript.codemodel.member.OperatorMember;
27
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
30
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
28
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
31
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
29
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
32
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
306
 	
309
 	
307
 	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) {
310
 	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) {
308
 		DefinitionMemberGroup members = getOrCreateGroup(operator);
311
 		DefinitionMemberGroup members = getOrCreateGroup(operator);
309
-		return members.call(position, scope, value, new CallArguments(), false);
312
+		return members.call(position, scope, value, new CallArguments(Expression.NONE), false);
310
 	}
313
 	}
311
 	
314
 	
312
 	public Expression ternary(CodePosition position, TypeScope scope, OperatorType operator, Expression a, Expression b, Expression c) {
315
 	public Expression ternary(CodePosition position, TypeScope scope, OperatorType operator, Expression a, Expression b, Expression c) {
335
 			return true;
338
 			return true;
336
 		if (toType == null)
339
 		if (toType == null)
337
 			throw new NullPointerException();
340
 			throw new NullPointerException();
338
-		if (type == BasicTypeID.ANY || toType == BasicTypeID.ANY || toType == BasicTypeID.UNDETERMINED)
339
-			return true;
340
 		
341
 		
341
 		if (type == BasicTypeID.NULL && toType.isOptional())
342
 		if (type == BasicTypeID.NULL && toType.isOptional())
342
 			return true;
343
 			return true;
347
 		if (type.isOptional() && type.unwrap() == toType)
348
 		if (type.isOptional() && type.unwrap() == toType)
348
 			return true;
349
 			return true;
349
 		
350
 		
351
+		return getImplicitCaster(toType) != null || extendsOrImplements(toType);
352
+	}
353
+	
354
+	public CasterMemberRef getImplicitCaster(ITypeID toType) {
350
 		for (TypeMember<CasterMemberRef> caster : casters) {
355
 		for (TypeMember<CasterMemberRef> caster : casters) {
351
 			if (caster.member.isImplicit() && toType == caster.member.toType)
356
 			if (caster.member.isImplicit() && toType == caster.member.toType)
352
-				return true;
357
+				return caster.member;
358
+		}
359
+		
360
+		return null;
361
+	}
362
+	
363
+	public CasterMemberRef getCaster(ITypeID toType) {
364
+		for (TypeMember<CasterMemberRef> caster : casters) {
365
+			if (toType == caster.member.toType)
366
+				return caster.member;
353
 		}
367
 		}
354
 		
368
 		
355
-		return extendsOrImplements(toType);
369
+		return null;
356
 	}
370
 	}
357
 	
371
 	
358
 	public boolean canCast(ITypeID toType) {
372
 	public boolean canCast(ITypeID toType) {

+ 1
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

98
 		if (state != State.NORMALIZED)
98
 		if (state != State.NORMALIZED)
99
 			throw new IllegalStateException("Module is not yet normalized");
99
 			throw new IllegalStateException("Module is not yet normalized");
100
 		
100
 		
101
-		Validator validator = new Validator();
101
+		Validator validator = new Validator(compilationUnit.globalTypeRegistry, expansions, annotations);
102
 		for (ScriptBlock script : scripts) {
102
 		for (ScriptBlock script : scripts) {
103
 			validator.validate(script);
103
 			validator.validate(script);
104
 		}
104
 		}

+ 3
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java View File

130
 			}
130
 			}
131
 		}
131
 		}
132
 		
132
 		
133
+		if (failed)
134
+			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
135
+		
133
 		if (failed)
136
 		if (failed)
134
 			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
137
 			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
135
 		
138
 		

+ 2
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java View File

14
 import org.json.JSONArray;
14
 import org.json.JSONArray;
15
 import org.json.JSONObject;
15
 import org.json.JSONObject;
16
 import org.openzen.zencode.shared.CompileException;
16
 import org.openzen.zencode.shared.CompileException;
17
+import org.openzen.zencode.shared.FileSourceFile;
17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
 import org.openzen.zenscript.compiler.CompilationUnit;
19
 import org.openzen.zenscript.compiler.CompilationUnit;
19
 import org.openzen.zenscript.constructor.ConstructorException;
20
 import org.openzen.zenscript.constructor.ConstructorException;
112
 			if (file.isDirectory()) {
113
 			if (file.isDirectory()) {
113
 				pkg.addPackage(loadPackage(file.getName(), file));
114
 				pkg.addPackage(loadPackage(file.getName(), file));
114
 			} else if (file.isFile() && file.getName().toLowerCase().endsWith(".zs")) {
115
 			} else if (file.isFile() && file.getName().toLowerCase().endsWith(".zs")) {
115
-				pkg.addFile(new SourceFile(file.getName(), file));
116
+				pkg.addFile(new FileSourceFile(file.getName(), file));
116
 			}
117
 			}
117
 		}
118
 		}
118
 		
119
 		

+ 0
- 22
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceFile.java View File

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.constructor.module;
7
-
8
-import java.io.File;
9
-
10
-/**
11
- *
12
- * @author Hoofdgebruiker
13
- */
14
-public class SourceFile {
15
-	public final String name;
16
-	public final File file;
17
-	
18
-	public SourceFile(String name, File file) {
19
-		this.name = name;
20
-		this.file = file;
21
-	}
22
-}

+ 3
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourcePackage.java View File

8
 import java.io.File;
8
 import java.io.File;
9
 import java.util.HashMap;
9
 import java.util.HashMap;
10
 import java.util.Map;
10
 import java.util.Map;
11
+import org.openzen.zencode.shared.FileSourceFile;
12
+import org.openzen.zencode.shared.SourceFile;
11
 
13
 
12
 /**
14
 /**
13
  *
15
  *
29
 	}
31
 	}
30
 	
32
 	
31
 	public void addFile(SourceFile file) {
33
 	public void addFile(SourceFile file) {
32
-		sourceFiles.put(file.name, file);
34
+		sourceFiles.put(file.getFilename(), file);
33
 	}
35
 	}
34
 }
36
 }

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java View File

83
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
83
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
84
 		}
84
 		}
85
 		
85
 		
86
-		long start = System.currentTimeMillis();
86
+		//long start = System.currentTimeMillis();
87
 		Rectangle clipBounds = g.getClipBounds();
87
 		Rectangle clipBounds = g.getClipBounds();
88
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
88
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
89
 		Graphics2D g2d = (Graphics2D) g;
89
 		Graphics2D g2d = (Graphics2D) g;
91
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
91
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
92
 		surface.paint(g2d, clipBounds2);
92
 		surface.paint(g2d, clipBounds2);
93
 		
93
 		
94
-		System.out.println("Paint in " + (System.currentTimeMillis() - start) + " ms, bounds: " + clipBounds.toString());
94
+		//System.out.println("Paint in " + (System.currentTimeMillis() - start) + " ms, bounds: " + clipBounds.toString());
95
 	}
95
 	}
96
 
96
 
97
 	@Override
97
 	@Override

+ 25
- 0
IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeError.java View File

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.ide.codemodel;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.ide.host.IDESourceFile;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class IDECodeError {
16
+	public final IDESourceFile file;
17
+	public final CodePosition position;
18
+	public final String message;
19
+	
20
+	public IDECodeError(IDESourceFile file, CodePosition position, String message) {
21
+		this.file = file;
22
+		this.position = position;
23
+		this.message = message;
24
+	}
25
+}

+ 41
- 0
IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeSpace.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.codemodel;
6
 package org.openzen.zenscript.ide.codemodel;
7
 
7
 
8
+import java.io.File;
9
+import java.util.ArrayList;
10
+import java.util.Collections;
11
+import java.util.HashMap;
12
+import java.util.HashSet;
13
+import java.util.List;
14
+import java.util.Map;
15
+import java.util.Set;
16
+import java.util.function.Consumer;
17
+import org.openzen.zenscript.compiler.CompilationUnit;
18
+import org.openzen.zenscript.compiler.SemanticModule;
19
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
20
+import org.openzen.zenscript.constructor.Library;
21
+import org.openzen.zenscript.constructor.ModuleLoader;
22
+import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
23
+import org.openzen.zenscript.constructor.module.ModuleReference;
8
 import org.openzen.zenscript.ide.host.DevelopmentHost;
24
 import org.openzen.zenscript.ide.host.DevelopmentHost;
25
+import org.openzen.zenscript.ide.host.IDEModule;
9
 import org.openzen.zenscript.ide.host.IDESourceFile;
26
 import org.openzen.zenscript.ide.host.IDESourceFile;
27
+import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
28
+import org.openzen.zenscript.ide.ui.view.output.OutputLine;
29
+import org.openzen.zenscript.validator.ValidationLogEntry;
30
+import stdlib.Strings;
10
 
31
 
11
 /**
32
 /**
12
  *
33
  *
14
  */
35
  */
15
 public class IDECodeSpace {
36
 public class IDECodeSpace {
16
 	private final DevelopmentHost host;
37
 	private final DevelopmentHost host;
38
+	private final Map<IDESourceFile, List<IDECodeError>> sourceFileErrors = new HashMap<>();
17
 	
39
 	
18
 	public IDECodeSpace(DevelopmentHost host) {
40
 	public IDECodeSpace(DevelopmentHost host) {
19
 		this.host = host;
41
 		this.host = host;
42
+		
43
+		ModuleLoader loader = new ModuleLoader(new CompilationUnit(), exception -> {
44
+			
45
+		});
46
+		for (IDEModule module : host.getModules()) {
47
+			module.prebuild(loader, this::addError);
48
+		}
20
 	}
49
 	}
21
 	
50
 	
22
 	public void onSaved(IDESourceFile file) {
51
 	public void onSaved(IDESourceFile file) {
23
 		
52
 		
24
 	}
53
 	}
54
+	
55
+	public List<IDECodeError> getErrors(IDESourceFile file) {
56
+		return sourceFileErrors.getOrDefault(file, Collections.emptyList());
57
+	}
58
+	
59
+	private void addError(IDECodeError error) {
60
+		if (error.file == null)
61
+			return;
62
+		if (!sourceFileErrors.containsKey(error.file))
63
+			sourceFileErrors.put(error.file, new ArrayList<>());
64
+		sourceFileErrors.get(error.file).add(error);
65
+	}
25
 }
66
 }

+ 6
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/IDEModule.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host;
6
 package org.openzen.zenscript.ide.host;
7
 
7
 
8
+import java.util.function.Consumer;
9
+import org.openzen.zenscript.constructor.ModuleLoader;
10
+import org.openzen.zenscript.ide.codemodel.IDECodeError;
11
+
8
 /**
12
 /**
9
  *
13
  *
10
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public String getName();
17
 	public String getName();
14
 	
18
 	
15
 	public IDEPackage getRootPackage();
19
 	public IDEPackage getRootPackage();
20
+	
21
+	void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors);
16
 }
22
 }

+ 2
- 3
IDE/src/main/java/org/openzen/zenscript/ide/host/IDESourceFile.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host;
6
 package org.openzen.zenscript.ide.host;
7
 
7
 
8
-import java.io.IOException;
9
-import java.io.Reader;
10
 import org.openzen.drawablegui.live.LiveString;
8
 import org.openzen.drawablegui.live.LiveString;
9
+import org.openzen.zencode.shared.SourceFile;
11
 
10
 
12
 /**
11
 /**
13
  *
12
  *
16
 public interface IDESourceFile {
15
 public interface IDESourceFile {
17
 	public LiveString getName();
16
 	public LiveString getName();
18
 	
17
 	
19
-	public Reader read() throws IOException;
18
+	public SourceFile getFile();
20
 	
19
 	
21
 	public void update(String content);
20
 	public void update(String content);
22
 }
21
 }

+ 10
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
+import java.util.function.Consumer;
9
+import org.openzen.zenscript.compiler.SemanticModule;
10
+import org.openzen.zenscript.constructor.ModuleLoader;
8
 import org.openzen.zenscript.constructor.module.ModuleReference;
11
 import org.openzen.zenscript.constructor.module.ModuleReference;
12
+import org.openzen.zenscript.ide.codemodel.IDECodeError;
9
 import org.openzen.zenscript.ide.host.IDEModule;
13
 import org.openzen.zenscript.ide.host.IDEModule;
10
 import org.openzen.zenscript.ide.host.IDEPackage;
14
 import org.openzen.zenscript.ide.host.IDEPackage;
11
 
15
 
31
 	public IDEPackage getRootPackage() {
35
 	public IDEPackage getRootPackage() {
32
 		return rootPackage;
36
 		return rootPackage;
33
 	}
37
 	}
38
+	
39
+	@Override
40
+	public void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors) {
41
+		SemanticModule module = loader.getModule(this.module.getName());
42
+		module.validate(entry -> errors.accept(new IDECodeError(null, entry.position, entry.message)));
43
+	}
34
 }
44
 }

+ 3
- 2
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalPackage.java View File

12
 import org.openzen.drawablegui.live.LiveList;
12
 import org.openzen.drawablegui.live.LiveList;
13
 import org.openzen.drawablegui.live.MutableLiveList;
13
 import org.openzen.drawablegui.live.MutableLiveList;
14
 import org.openzen.drawablegui.live.SortedLiveList;
14
 import org.openzen.drawablegui.live.SortedLiveList;
15
-import org.openzen.zenscript.constructor.module.SourceFile;
15
+import org.openzen.zencode.shared.FileSourceFile;
16
+import org.openzen.zencode.shared.SourceFile;
16
 import org.openzen.zenscript.constructor.module.SourcePackage;
17
 import org.openzen.zenscript.constructor.module.SourcePackage;
17
 import org.openzen.zenscript.ide.host.IDEPackage;
18
 import org.openzen.zenscript.ide.host.IDEPackage;
18
 import org.openzen.zenscript.ide.host.IDESourceFile;
19
 import org.openzen.zenscript.ide.host.IDESourceFile;
87
 			ex.printStackTrace(); // TODO
88
 			ex.printStackTrace(); // TODO
88
 		}
89
 		}
89
 		
90
 		
90
-		SourceFile sourceFile = new SourceFile(name, file);
91
+		FileSourceFile sourceFile = new FileSourceFile(name, file);
91
 		IDESourceFile localSourceFile = new LocalSourceFile(sourceFile);
92
 		IDESourceFile localSourceFile = new LocalSourceFile(sourceFile);
92
 		this.pkg.sourceFiles.put(name, sourceFile);
93
 		this.pkg.sourceFiles.put(name, sourceFile);
93
 		sourceFiles.add(localSourceFile);
94
 		sourceFiles.add(localSourceFile);

+ 12
- 13
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalSourceFile.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
-import java.io.BufferedInputStream;
9
 import java.io.BufferedOutputStream;
8
 import java.io.BufferedOutputStream;
10
-import java.io.FileInputStream;
11
 import java.io.FileOutputStream;
9
 import java.io.FileOutputStream;
12
 import java.io.IOException;
10
 import java.io.IOException;
13
-import java.io.InputStreamReader;
14
 import java.io.OutputStreamWriter;
11
 import java.io.OutputStreamWriter;
15
-import java.io.Reader;
16
 import java.io.Writer;
12
 import java.io.Writer;
17
 import java.nio.charset.StandardCharsets;
13
 import java.nio.charset.StandardCharsets;
18
 import org.openzen.drawablegui.live.LiveString;
14
 import org.openzen.drawablegui.live.LiveString;
19
 import org.openzen.drawablegui.live.MutableLiveString;
15
 import org.openzen.drawablegui.live.MutableLiveString;
20
 import org.openzen.drawablegui.live.SimpleLiveString;
16
 import org.openzen.drawablegui.live.SimpleLiveString;
21
-import org.openzen.zenscript.constructor.module.SourceFile;
17
+import org.openzen.zencode.shared.FileSourceFile;
18
+import org.openzen.zencode.shared.SourceFile;
22
 import org.openzen.zenscript.ide.host.IDESourceFile;
19
 import org.openzen.zenscript.ide.host.IDESourceFile;
23
 
20
 
24
 /**
21
 /**
31
 	
28
 	
32
 	public LocalSourceFile(SourceFile file) {
29
 	public LocalSourceFile(SourceFile file) {
33
 		this.file = file;
30
 		this.file = file;
34
-		this.name = new SimpleLiveString(file.name);
31
+		this.name = new SimpleLiveString(file.getFilename());
35
 	}
32
 	}
36
 
33
 
37
 	@Override
34
 	@Override
40
 	}
37
 	}
41
 
38
 
42
 	@Override
39
 	@Override
43
-	public Reader read() throws IOException {
44
-		return new InputStreamReader(
45
-				new BufferedInputStream(new FileInputStream(file.file)),
46
-				StandardCharsets.UTF_8);
40
+	public SourceFile getFile() {
41
+		return file;
47
 	}
42
 	}
48
 
43
 
49
 	@Override
44
 	@Override
50
 	public void update(String content) {
45
 	public void update(String content) {
51
 		try {
46
 		try {
52
-			Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file.file)), StandardCharsets.UTF_8);
53
-			writer.write(content);
54
-			writer.close();
47
+			if (file instanceof FileSourceFile) {
48
+				Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(((FileSourceFile)file).file)), StandardCharsets.UTF_8);
49
+				writer.write(content);
50
+				writer.close();
51
+			} else {
52
+				throw new UnsupportedOperationException("Cannot write to a non-file source file!");
53
+			}
55
 		} catch (IOException ex) {
54
 		} catch (IOException ex) {
56
 			ex.printStackTrace();
55
 			ex.printStackTrace();
57
 		}
56
 		}

+ 5
- 5
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java View File

133
 				continue;
133
 				continue;
134
 			
134
 			
135
 			SemanticModule dependencyModule = loader.getModule(dependency);
135
 			SemanticModule dependencyModule = loader.getModule(dependency);
136
-			module = module.normalize();
137
-			module.validate(logger);
138
-			if (!module.isValid())
136
+			dependencyModule = dependencyModule.normalize();
137
+			dependencyModule.validate(logger);
138
+			if (!dependencyModule.isValid())
139
 				return false;
139
 				return false;
140
 			
140
 			
141
 			if (!compileDependencies(loader, compiler, compiledModules, dependencyModule, logger))
141
 			if (!compileDependencies(loader, compiler, compiledModules, dependencyModule, logger))
142
 				return false;
142
 				return false;
143
 			
143
 			
144
-			module.compile(compiler);
145
-			compiledModules.add(module.name);
144
+			dependencyModule.compile(compiler);
145
+			compiledModules.add(dependencyModule.name);
146
 		}
146
 		}
147
 		
147
 		
148
 		return true;
148
 		return true;

+ 48
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/PathGenerator.java View File

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.ide.ui.view.editor;
7
+
8
+import org.openzen.drawablegui.DPath;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class PathGenerator {
15
+	private PathGenerator() {}
16
+	
17
+	public static class CubicBezierCurve {
18
+		public final float p1x;
19
+		public final float p1y;
20
+		public final float p2x;
21
+		public final float p2y;
22
+		public final float p3x;
23
+		public final float p3y;
24
+		public final float p4x;
25
+		public final float p4y;
26
+		
27
+		public CubicBezierCurve(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, float p4x, float p4y) {
28
+			this.p1x = p1x;
29
+			this.p1y = p1y;
30
+			this.p2x = p2x;
31
+			this.p2y = p2y;
32
+			this.p3x = p3x;
33
+			this.p3y = p3y;
34
+			this.p4x = p4x;
35
+			this.p4y = p4y;
36
+		}
37
+		
38
+		public void cut(float t0, float t1) {
39
+			// https://stackoverflow.com/questions/11703283/cubic-bezier-curve-segment
40
+			// P'1 = u0u0u0 P1 + (t0u0u0 + u0t0u0 + u0u0t0) P2 + (t0t0u0 + u0t0t0 + t0u0t0) P3 + t0t0t0 P4
41
+			// P'2 = u0u0u1 P1 + (t0u0u1 + u0t0u1 + u0u0t1) P2 + (t0t0u1 + u0t0t1 + t0u0t1) P3 + t0t0t1 P4
42
+			// P'3 = u0u1u1 P1 + (t0u1u1 + u0t1u1 + u0u1t1) P2 + (t0t1u1 + u0t1t1 + t0u1t1) P3 + t0t1t1 P4
43
+			// P'4 = u1u1u1 P1 + (t1u1u1 + u1t1u1 + u1u1t1) P2 + (t1t1u1 + u1t1t1 + t1u1t1) P3 + t1t1t1 P4
44
+			// u0 = 1 − t0 and u1 = 1 − t1
45
+			
46
+		}
47
+	}
48
+}

+ 42
- 24
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java View File

6
 package org.openzen.zenscript.ide.ui.view.editor;
6
 package org.openzen.zenscript.ide.ui.view.editor;
7
 
7
 
8
 import java.io.IOException;
8
 import java.io.IOException;
9
+import java.io.Reader;
9
 import java.util.ArrayList;
10
 import java.util.ArrayList;
10
 import java.util.List;
11
 import java.util.List;
11
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
29
 import org.openzen.zenscript.lexer.ZSTokenParser;
30
 import org.openzen.zenscript.lexer.ZSTokenParser;
30
 import org.openzen.zenscript.lexer.ZSTokenType;
31
 import org.openzen.zenscript.lexer.ZSTokenType;
31
 import org.openzen.drawablegui.DUIContext;
32
 import org.openzen.drawablegui.DUIContext;
33
+import org.openzen.drawablegui.Destructible;
32
 import org.openzen.drawablegui.draw.DDrawSurface;
34
 import org.openzen.drawablegui.draw.DDrawSurface;
33
 import org.openzen.drawablegui.draw.DDrawnRectangle;
35
 import org.openzen.drawablegui.draw.DDrawnRectangle;
34
 import org.openzen.drawablegui.draw.DDrawnShape;
36
 import org.openzen.drawablegui.draw.DDrawnShape;
95
 	private final List<DDrawnText> lineNumbers = new ArrayList<>();
97
 	private final List<DDrawnText> lineNumbers = new ArrayList<>();
96
 	private final List<List<DDrawnText>> drawnTokens = new ArrayList<>();
98
 	private final List<List<DDrawnText>> drawnTokens = new ArrayList<>();
97
 	
99
 	
100
+	//private DDrawnShape test;
101
+	
98
 	public SourceEditor(DStyleClass styleClass, IDEWindow window, IDESourceFile sourceFile) {
102
 	public SourceEditor(DStyleClass styleClass, IDEWindow window, IDESourceFile sourceFile) {
99
 		this.styleClass = styleClass;
103
 		this.styleClass = styleClass;
100
 		this.window = window;
104
 		this.window = window;
101
 		this.sourceFile = sourceFile;
105
 		this.sourceFile = sourceFile;
102
 		
106
 		
103
-		tokens = new TokenModel(sourceFile.getName().getValue(), tab.length());
107
+		tokens = new TokenModel(sourceFile.getFile(), tab.length());
104
 		tokenListener = tokens.addListener(new TokenListener());
108
 		tokenListener = tokens.addListener(new TokenListener());
105
 		
109
 		
106
 		editToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, ShadedSaveIcon.PURPLE, SaveIcon.GREY, unchanged, new ImmutableLiveString("Save file"), e -> save()));
110
 		editToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, ShadedSaveIcon.PURPLE, SaveIcon.GREY, unchanged, new ImmutableLiveString("Save file"), e -> save()));
107
 		updated = new InverseLiveBool(unchanged);
111
 		updated = new InverseLiveBool(unchanged);
108
 		
112
 		
109
 		try {
113
 		try {
114
+			Reader reader = sourceFile.getFile().open();
110
 			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(
115
 			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(
111
-					sourceFile.getName().getValue(),
112
-					new ReaderCharReader(sourceFile.read()),
116
+					sourceFile.getFile(),
117
+					new ReaderCharReader(reader),
113
 					tab.length());
118
 					tab.length());
114
 			tokens.set(parser);
119
 			tokens.set(parser);
120
+			reader.close();
115
 		} catch (IOException ex) {
121
 		} catch (IOException ex) {
116
 			ex.printStackTrace();
122
 			ex.printStackTrace();
117
 		}
123
 		}
188
 			cursor = null;
194
 			cursor = null;
189
 		}
195
 		}
190
 		
196
 		
197
+		/*if (test != null) {
198
+			test.close();
199
+			test = null;
200
+		}*/
201
+		
191
 		if (blinkTimer != null)
202
 		if (blinkTimer != null)
192
 			blinkTimer.close();
203
 			blinkTimer.close();
193
 		
204
 		
251
 					bounds.y + style.selectionPaddingTop + i * fullLineHeight + fontMetrics.getAscent());
262
 					bounds.y + style.selectionPaddingTop + i * fullLineHeight + fontMetrics.getAscent());
252
 		}
263
 		}
253
 		
264
 		
265
+		//test = surface.strokePath(z + 4, new WavyLine(bounds.x + 50, bounds.y + 50, 100, surface.getContext().dp(2), surface.getContext().dp(3)), DTransform2D.IDENTITY, IDEStyling.ERROR_RED, surface.getScale());
266
+		
254
 		layoutLines(0);
267
 		layoutLines(0);
255
 	}
268
 	}
256
 	
269
 	
287
 		}
300
 		}
288
 	}
301
 	}
289
 	
302
 	
303
+	private void setCursor(SourcePosition position) {
304
+		setCursor(position, position);
305
+	}
306
+	
290
 	private void setCursor(SourcePosition start, SourcePosition end) {
307
 	private void setCursor(SourcePosition start, SourcePosition end) {
291
 		cursorStart = start;
308
 		cursorStart = start;
292
 		cursorEnd = end;
309
 		cursorEnd = end;
563
 		if (value.equals("{")) {
580
 		if (value.equals("{")) {
564
 			String indent = tokens.getLine(cursorEnd.line).getIndent();
581
 			String indent = tokens.getLine(cursorEnd.line).getIndent();
565
 			tokens.insert(cursorEnd, "{\n" + indent + "\t\n" + indent + "}");
582
 			tokens.insert(cursorEnd, "{\n" + indent + "\t\n" + indent + "}");
566
-			
567
-			SourcePosition position = new SourcePosition(tokens, cursorEnd.line + 1, indent.length() + 1);
568
-			setCursor(position, position);
569
-		} else if (value.equals(";")) {
570
-			String indent = tokens.getLine(cursorEnd.line).getIndent();
571
-			tokens.insert(cursorEnd, ";\n" + indent);
572
-			
573
-			SourcePosition position = new SourcePosition(tokens, cursorEnd.line + 1, indent.length());
574
-			setCursor(position, position);
583
+			setCursor(new SourcePosition(tokens, cursorEnd.line + 1, indent.length() + 1));
584
+		} else if (value.equals("\"")) {
585
+			if (!tokens.extract(cursorEnd, cursorEnd.advance(1)).equals("\""))
586
+				tokens.insert(cursorEnd, "\"\"");
587
+			setCursor(cursorEnd.advance(1));
588
+		} else if (value.equals("(")) {
589
+			tokens.insert(cursorEnd, "()");
590
+			setCursor(cursorEnd.advance(1));
591
+		} else if (value.equals(")") && tokens.extract(cursorEnd, cursorEnd.advance(1)).equals(")")){
592
+			setCursor(cursorEnd.advance(1));
593
+		} else if (value.equals("[")) {
594
+			tokens.insert(cursorEnd, "[]");
595
+			setCursor(cursorEnd.advance(1));
596
+		} else if (value.equals("]") && tokens.extract(cursorEnd, cursorEnd.advance(1)).equals("]")) {
597
+			setCursor(cursorEnd.advance(1));
575
 		} else {
598
 		} else {
576
 			tokens.insert(cursorEnd, value);
599
 			tokens.insert(cursorEnd, value);
577
-			
578
-			SourcePosition position = new SourcePosition(tokens, cursorEnd.line, cursorEnd.offset + value.length());
579
-			setCursor(position, position);
600
+			setCursor(cursorEnd.advance(value.length()));
580
 		}
601
 		}
581
 		
602
 		
582
 		unchanged.setValue(false);
603
 		unchanged.setValue(false);
734
 		@Override
755
 		@Override
735
 		public void onLineChanged(int index) {
756
 		public void onLineChanged(int index) {
736
 			if (bounds != null) {
757
 			if (bounds != null) {
737
-				removeLineTokens(drawnTokens.get(index));
738
-				drawnTokens.get(index).clear();
739
-				drawnTokens.get(index).addAll(lineToTokens(tokens.getLine(index)));
758
+				Destructible.close(drawnTokens.get(index));
759
+				drawnTokens.set(index, lineToTokens(tokens.getLine(index)));
740
 				layoutLine(index);
760
 				layoutLine(index);
741
 			}
761
 			}
742
 		}
762
 		}
745
 		public void onLineDeleted(int index) {
765
 		public void onLineDeleted(int index) {
746
 			onLinesUpdated();
766
 			onLinesUpdated();
747
 			
767
 			
768
+			if (index >= lineNumbers.size())
769
+				return;
770
+			
748
 			if (bounds != null) {
771
 			if (bounds != null) {
749
 				lineNumbers.remove(lineNumbers.size() - 1).close();
772
 				lineNumbers.remove(lineNumbers.size() - 1).close();
750
-				removeLineTokens(drawnTokens.remove(index));
773
+				Destructible.close(drawnTokens.remove(index));
751
 				layoutLines(index);
774
 				layoutLines(index);
752
 			}
775
 			}
753
 		}
776
 		}
754
-		
755
-		private void removeLineTokens(List<DDrawnText> tokens) {
756
-			for (DDrawnText token : tokens)
757
-				token.close();
758
-		}
759
 	}
777
 	}
760
 	
778
 	
761
 	private enum TokenClass {
779
 	private enum TokenClass {

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourcePosition.java View File

18
 	private TokenModel.Position position;
18
 	private TokenModel.Position position;
19
 
19
 
20
 	public SourcePosition(TokenModel tokens, int line, int offset) {
20
 	public SourcePosition(TokenModel tokens, int line, int offset) {
21
+		if (line < 0)
22
+			throw new IllegalArgumentException("line cannot be negative");
23
+		if (offset < 0)
24
+			throw new IllegalArgumentException("offset cannot be negative");
25
+		
21
 		this.tokens = tokens;
26
 		this.tokens = tokens;
22
 		this.line = line;
27
 		this.line = line;
23
 		this.offset = offset;
28
 		this.offset = offset;

+ 10
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenLine.java View File

54
 		}
54
 		}
55
 		return indent.toString();
55
 		return indent.toString();
56
 	}
56
 	}
57
+	
58
+	/**
59
+	 * Adds a temporary token. This token must be relexed later using the relexer.
60
+	 * 
61
+	 * @param token 
62
+	 */
63
+	public void addTemporary(ZSToken token) {
64
+		tokens.add(token);
65
+		length += token.content.length();
66
+	}
57
 
67
 
58
 	public void add(ZSToken token) {
68
 	public void add(ZSToken token) {
59
 		insert(tokens.size(), token);
69
 		insert(tokens.size(), token);

+ 15
- 6
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java View File

13
 import java.util.Set;
13
 import java.util.Set;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
 import org.openzen.drawablegui.listeners.ListenerList;
15
 import org.openzen.drawablegui.listeners.ListenerList;
16
+import org.openzen.zencode.shared.SourceFile;
16
 import org.openzen.zenscript.lexer.ZSToken;
17
 import org.openzen.zenscript.lexer.ZSToken;
17
 import org.openzen.zenscript.lexer.ZSTokenType;
18
 import org.openzen.zenscript.lexer.ZSTokenType;
18
 
19
 
23
 public class TokenModel {
24
 public class TokenModel {
24
 	private final ListenerList<Listener> listeners = new ListenerList<>();
25
 	private final ListenerList<Listener> listeners = new ListenerList<>();
25
 	
26
 	
26
-	private final String filename;
27
+	private final SourceFile file;
27
 	private final int spacesPerTab;
28
 	private final int spacesPerTab;
28
 	private final List<TokenLine> lines = new ArrayList<>();
29
 	private final List<TokenLine> lines = new ArrayList<>();
29
 	private long version = 0;
30
 	private long version = 0;
30
 	
31
 	
31
-	public TokenModel(String filename, int spacesPerTab) {
32
-		this.filename = filename;
32
+	public TokenModel(SourceFile file, int spacesPerTab) {
33
+		this.file = file;
33
 		this.spacesPerTab = spacesPerTab;
34
 		this.spacesPerTab = spacesPerTab;
34
 	}
35
 	}
35
 	
36
 	
193
 		if (!remainder.isEmpty())
194
 		if (!remainder.isEmpty())
194
 			getLine(fromT.line).insert(fromT.token, new ZSToken(ZSTokenType.INVALID, remainder));
195
 			getLine(fromT.line).insert(fromT.token, new ZSToken(ZSTokenType.INVALID, remainder));
195
 		
196
 		
196
-		relex(fromT.line, Math.max(0, fromT.token - 1), fromT.line, fromT.token + 1);
197
+		relex(fromT.line, Math.max(0, fromT.token - 1), fromT.line, Math.min(lines.get(fromT.line).getTokenCount(), fromT.token + 1));
197
 	}
198
 	}
198
 	
199
 	
199
 	public void insert(SourcePosition position, String value) {
200
 	public void insert(SourcePosition position, String value) {
201
 		Position tokenPosition = position.asTokenPosition();
202
 		Position tokenPosition = position.asTokenPosition();
202
 		ZSToken token = getTokenAt(tokenPosition);
203
 		ZSToken token = getTokenAt(tokenPosition);
203
 		if (token == null) {
204
 		if (token == null) {
204
-			line.add(new ZSToken(ZSTokenType.INVALID, value));
205
+			line.addTemporary(new ZSToken(ZSTokenType.INVALID, value));
205
 		} else {
206
 		} else {
206
 			token = token.insert(tokenPosition.offset, value);
207
 			token = token.insert(tokenPosition.offset, value);
207
 			line.replace(tokenPosition.token, token);
208
 			line.replace(tokenPosition.token, token);
210
 	}
211
 	}
211
 	
212
 	
212
 	private void relex(int fromLine, int fromToken, int toLine, int toToken) {
213
 	private void relex(int fromLine, int fromToken, int toLine, int toToken) {
213
-		TokenRelexer reparser = new TokenRelexer(filename, lines, fromLine, fromToken, toLine, toToken, spacesPerTab);
214
+		TokenRelexer reparser = new TokenRelexer(file, lines, fromLine, fromToken, toLine, toToken, spacesPerTab);
214
 		List<ZSToken> tokens = reparser.relex();
215
 		List<ZSToken> tokens = reparser.relex();
215
 		replaceTokens(fromLine, fromToken, reparser.getLine(), reparser.getToken(), tokens);
216
 		replaceTokens(fromLine, fromToken, reparser.getLine(), reparser.getToken(), tokens);
216
 	}
217
 	}
257
 		TokenLine currentLine = lines.get(line);
258
 		TokenLine currentLine = lines.get(line);
258
 		Set<Integer> insertedLines = new HashSet<>();
259
 		Set<Integer> insertedLines = new HashSet<>();
259
 		Set<Integer> modifiedLines = new HashSet<>();
260
 		Set<Integer> modifiedLines = new HashSet<>();
261
+		modifiedLines.add(line);
260
 		while (tokens.hasNext()) {
262
 		while (tokens.hasNext()) {
261
 			ZSToken token = tokens.next();
263
 			ZSToken token = tokens.next();
262
 			if (token.type.multiline && token.content.indexOf('\n') >= 0) {
264
 			if (token.type.multiline && token.content.indexOf('\n') >= 0) {
336
 		public final int offset;
338
 		public final int offset;
337
 		
339
 		
338
 		public Position(int line, int token, int offset) {
340
 		public Position(int line, int token, int offset) {
341
+			if (line < 0)
342
+				throw new IllegalArgumentException("line cannot be negative");
343
+			if (token < 0)
344
+				throw new IllegalArgumentException("token cannot be negative");
345
+			if (offset < 0)
346
+				throw new IllegalArgumentException("offset cannot be negative");
347
+			
339
 			this.line = line;
348
 			this.line = line;
340
 			this.token = token;
349
 			this.token = token;
341
 			this.offset = offset;
350
 			this.offset = offset;

+ 5
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenRelexer.java View File

8
 import java.io.IOException;
8
 import java.io.IOException;
9
 import java.util.ArrayList;
9
 import java.util.ArrayList;
10
 import java.util.List;
10
 import java.util.List;
11
+import org.openzen.zencode.shared.SourceFile;
11
 import org.openzen.zenscript.lexer.CharReader;
12
 import org.openzen.zenscript.lexer.CharReader;
12
 import org.openzen.zenscript.lexer.TokenParser;
13
 import org.openzen.zenscript.lexer.TokenParser;
13
 import org.openzen.zenscript.lexer.ZSToken;
14
 import org.openzen.zenscript.lexer.ZSToken;
20
  */
21
  */
21
 public class TokenRelexer {
22
 public class TokenRelexer {
22
 	private final List<TokenLine> lines;
23
 	private final List<TokenLine> lines;
23
-	private final String filename;
24
+	private final SourceFile file;
24
 	private final int toLine;
25
 	private final int toLine;
25
 	private final int toToken;
26
 	private final int toToken;
26
 	private final int spacesPerTab;
27
 	private final int spacesPerTab;
28
 	private int lineIndex;
29
 	private int lineIndex;
29
 	private int token;
30
 	private int token;
30
 	
31
 	
31
-	public TokenRelexer(String filename, List<TokenLine> lines, int fromLine, int fromToken, int toLine, int toToken, int spacesPerTab) {
32
+	public TokenRelexer(SourceFile file, List<TokenLine> lines, int fromLine, int fromToken, int toLine, int toToken, int spacesPerTab) {
32
 		if (fromToken < 0 || toToken < 0)
33
 		if (fromToken < 0 || toToken < 0)
33
 			throw new IllegalArgumentException("fromToken or toToken cannot be < 0");
34
 			throw new IllegalArgumentException("fromToken or toToken cannot be < 0");
34
 		
35
 		
35
 		this.lines = lines;
36
 		this.lines = lines;
36
-		this.filename = filename;
37
+		this.file = file;
37
 		this.toLine = toLine;
38
 		this.toLine = toLine;
38
 		this.toToken = toToken;
39
 		this.toToken = toToken;
39
 		
40
 		
44
 	
45
 	
45
 	public List<ZSToken> relex() {
46
 	public List<ZSToken> relex() {
46
 		RelexCharReader reader = new RelexCharReader();
47
 		RelexCharReader reader = new RelexCharReader();
47
-		TokenParser<ZSToken, ZSTokenType> reparser = ZSTokenParser.createRaw(filename, reader, spacesPerTab);
48
+		TokenParser<ZSToken, ZSTokenType> reparser = ZSTokenParser.createRaw(file, reader, spacesPerTab);
48
 		List<ZSToken> result = new ArrayList<>();
49
 		List<ZSToken> result = new ArrayList<>();
49
 		while ((lineIndex < toLine || token < toToken || !reader.isAtTokenBoundary()) && reparser.hasNext())
50
 		while ((lineIndex < toLine || token < toToken || !reader.isAtTokenBoundary()) && reparser.hasNext())
50
 			result.add(reparser.next());
51
 			result.add(reparser.next());

+ 47
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/WavyLine.java View File

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.ide.ui.view.editor;
7
+
8
+import org.openzen.drawablegui.DPath;
9
+import org.openzen.drawablegui.DPathTracer;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class WavyLine implements DPath {
16
+	private final int x;
17
+	private final int y;
18
+	private final int width;
19
+	private final int height;
20
+	private final float stride;
21
+	
22
+	public WavyLine(int x, int y, int width, int height, float stride) {
23
+		this.x = x;
24
+		this.y = y;
25
+		this.width = width;
26
+		this.height = height;
27
+		this.stride = stride;
28
+	}
29
+	
30
+	@Override
31
+	public void trace(DPathTracer tracer) {
32
+		tracer.moveTo(x, y);
33
+		for (int i = 0; i < (width / stride); i++) {
34
+			if ((i % 2) == 0) {
35
+				tracer.bezierCubic(
36
+						x + (i + 0.5f) * stride, y,
37
+						x + (i + 0.5f) * stride, y + height,
38
+						x + (i + 1) * stride, y + height);
39
+			} else {
40
+				tracer.bezierCubic(
41
+						x + (i + 0.5f) * stride, y + height,
42
+						x + (i + 0.5f) * stride, y,
43
+						x + (i + 1) * stride, y);
44
+			}
45
+		}
46
+	}
47
+}

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

56
 	@Override
56
 	@Override
57
 	public void addScriptBlock(ScriptBlock script) {
57
 	public void addScriptBlock(ScriptBlock script) {
58
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
58
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
59
-		final String className = getClassName(sourceFile == null ? null : sourceFile.filename);
59
+		final String className = getClassName(sourceFile == null ? null : sourceFile.getFilename());
60
 		JavaScriptFile scriptFile = getScriptFile(className);
60
 		JavaScriptFile scriptFile = getScriptFile(className);
61
 		
61
 		
62
 		String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();
62
 		String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();

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

1
 package org.openzen.zenscript.javabytecode.compiler;
1
 package org.openzen.zenscript.javabytecode.compiler;
2
 
2
 
3
+import java.util.Arrays;
4
+import java.util.Collection;
5
+import java.util.Comparator;
6
+import java.util.Map;
7
+import java.util.StringJoiner;
3
 import org.objectweb.asm.ClassWriter;
8
 import org.objectweb.asm.ClassWriter;
4
 import org.objectweb.asm.Label;
9
 import org.objectweb.asm.Label;
5
 import org.objectweb.asm.Opcodes;
10
 import org.objectweb.asm.Opcodes;
772
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
777
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
773
 							javaWriter.checkCast("[Ljava/lang/String;");
778
 							javaWriter.checkCast("[Ljava/lang/String;");
774
 							break;
779
 							break;
775
-						case ANY:
776
-							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
777
-							javaWriter.checkCast("[Lzsynthetic/Any;");
778
-							break;
779
 						default:
780
 						default:
780
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
781
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
781
 					}
782
 					}
821
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
822
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
822
 							break;
823
 							break;
823
 						case STRING:
824
 						case STRING:
824
-						case ANY:
825
 							javaWriter.invokeStatic(ARRAYS_EQUALS_OBJECTS);
825
 							javaWriter.invokeStatic(ARRAYS_EQUALS_OBJECTS);
826
 							break;
826
 							break;
827
 						default:
827
 						default:
1864
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1864
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1865
 							break;
1865
 							break;
1866
 						case STRING:
1866
 						case STRING:
1867
-						case ANY:
1868
 							javaWriter.invokeStatic(ARRAYS_DEEPHASHCODE);
1867
 							javaWriter.invokeStatic(ARRAYS_DEEPHASHCODE);
1869
 							break;
1868
 							break;
1870
 						default:
1869
 						default:

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

36
 				return void.class;
36
 				return void.class;
37
 			case NULL:
37
 			case NULL:
38
 				return Object.class;
38
 				return Object.class;
39
-			case ANY:
40
-				return Object.class; // TODO
41
 			case BOOL:
39
 			case BOOL:
42
 				return Boolean.class;
40
 				return Boolean.class;
43
 			case BYTE:
41
 			case BYTE:

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

278
 
278
 
279
         Type type = statement.type.accept(JavaTypeVisitor.INSTANCE);
279
         Type type = statement.type.accept(JavaTypeVisitor.INSTANCE);
280
         int local = javaWriter.local(type);
280
         int local = javaWriter.local(type);
281
-        if(statement.initializer != null)
281
+        if (statement.initializer != null)
282
             javaWriter.store(type, local);
282
             javaWriter.store(type, local);
283
         final Label variableStart = new Label();
283
         final Label variableStart = new Label();
284
         javaWriter.label(variableStart);
284
         javaWriter.label(variableStart);

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

17
         switch (basic) {
17
         switch (basic) {
18
             case VOID:
18
             case VOID:
19
                 return void.class;
19
                 return void.class;
20
-            case ANY:
21
             case NULL:
20
             case NULL:
22
             case UNDETERMINED:
21
             case UNDETERMINED:
23
                 return Object.class;
22
                 return Object.class;

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

11
 import java.util.HashMap;
11
 import java.util.HashMap;
12
 import java.util.List;
12
 import java.util.List;
13
 import java.util.Map;
13
 import java.util.Map;
14
-
14
+import org.objectweb.asm.*;
15
 import static org.objectweb.asm.Opcodes.*;
15
 import static org.objectweb.asm.Opcodes.*;
16
+import org.objectweb.asm.commons.LocalVariablesSorter;
17
+import org.openzen.zencode.shared.CodePosition;
18
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
+import org.openzen.zenscript.javabytecode.JavaClassInfo;
20
+import org.openzen.zenscript.javabytecode.JavaFieldInfo;
21
+import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
22
+import org.openzen.zenscript.javabytecode.JavaMethodInfo;
23
+import org.openzen.zenscript.javabytecode.JavaParameterInfo;
16
 
24
 
17
 public class JavaWriter {
25
 public class JavaWriter {
18
     private static final JavaClassInfo T_STRING = new JavaClassInfo("java/lang/String");
26
     private static final JavaClassInfo T_STRING = new JavaClassInfo("java/lang/String");

+ 8
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java View File

68
 		this.currentElementType = type;
68
 		this.currentElementType = type;
69
 	}
69
 	}
70
 	
70
 	
71
+	protected void override(boolean override) {
72
+		if (override) {
73
+			output.append(indent).append("@Override\n");
74
+		}
75
+	}
76
+	
71
 	protected void modifiers(int modifiers) {
77
 	protected void modifiers(int modifiers) {
72
 		if (Modifiers.isPublic(modifiers))
78
 		if (Modifiers.isPublic(modifiers))
73
 			output.append("public ");
79
 			output.append("public ");
75
 			output.append("protected ");
81
 			output.append("protected ");
76
 		if (Modifiers.isPrivate(modifiers))
82
 		if (Modifiers.isPrivate(modifiers))
77
 			output.append("private ");
83
 			output.append("private ");
84
+		if (Modifiers.isAbstract(modifiers))
85
+			output.append("abstract ");
78
 		if (Modifiers.isStatic(modifiers))
86
 		if (Modifiers.isStatic(modifiers))
79
 			output.append("static ");
87
 			output.append("static ");
80
 		if (Modifiers.isFinal(modifiers))
88
 		if (Modifiers.isFinal(modifiers))

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java View File

64
 			if (parameter.variadic)
64
 			if (parameter.variadic)
65
 				result.append("...");
65
 				result.append("...");
66
 			
66
 			
67
-			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.ANY) {
67
+			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
68
 				result.append(" as ");
68
 				result.append(" as ");
69
 				result.append(header.returnType.accept(typeFormatter));
69
 				result.append(header.returnType.accept(typeFormatter));
70
 			}
70
 			}
72
 			parameterIndex++;
72
 			parameterIndex++;
73
 		}
73
 		}
74
 		result.append(")");
74
 		result.append(")");
75
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.ANY) {
75
+		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.UNDETERMINED) {
76
 			result.append(" as ");
76
 			result.append(" as ");
77
 			result.append(header.returnType.accept(typeFormatter));
77
 			result.append(header.returnType.accept(typeFormatter));
78
 		}
78
 		}

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java View File

86
 		}
86
 		}
87
 		
87
 		
88
 		if (mergedImplementations.size() > 0) {
88
 		if (mergedImplementations.size() > 0) {
89
-			output.append("implements ");
89
+			output.append(" implements ");
90
 			for (int i = 0; i < mergedImplementations.size(); i++) {
90
 			for (int i = 0; i < mergedImplementations.size(); i++) {
91
 				if (i > 0)
91
 				if (i > 0)
92
 					output.append(", ");
92
 					output.append(", ");
289
 			output.append("static ");
289
 			output.append("static ");
290
 		if (Modifiers.isAbstract(modifiers))
290
 		if (Modifiers.isAbstract(modifiers))
291
 			output.append("abstract ");
291
 			output.append("abstract ");
292
-		if (!Modifiers.isVirtual(modifiers))
292
+		if (!Modifiers.isVirtual(modifiers) && !Modifiers.isAbstract(modifiers))
293
 			output.append("final ");
293
 			output.append("final ");
294
 	}
294
 	}
295
 	
295
 	

+ 25
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java View File

20
 import org.openzen.zenscript.codemodel.member.DestructorMember;
20
 import org.openzen.zenscript.codemodel.member.DestructorMember;
21
 import org.openzen.zenscript.codemodel.member.FieldMember;
21
 import org.openzen.zenscript.codemodel.member.FieldMember;
22
 import org.openzen.zenscript.codemodel.member.GetterMember;
22
 import org.openzen.zenscript.codemodel.member.GetterMember;
23
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
23
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
24
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
24
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
25
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
25
 import org.openzen.zenscript.codemodel.member.MethodMember;
26
 import org.openzen.zenscript.codemodel.member.MethodMember;
30
 import org.openzen.zenscript.codemodel.statement.Statement;
31
 import org.openzen.zenscript.codemodel.statement.Statement;
31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
33
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
34
+import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
33
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
35
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
34
 
36
 
35
 /**
37
 /**
67
 			
69
 			
68
 		
70
 		
69
 		begin(ElementType.METHOD);
71
 		begin(ElementType.METHOD);
72
+		override(member.getOverrides() != null);
70
 		output.append(indent);
73
 		output.append(indent);
71
 		if (isInterface && hasBody)
74
 		if (isInterface && hasBody)
72
 			output.append("default ");
75
 			output.append("default ");
196
 
199
 
197
 	@Override
200
 	@Override
198
 	public Void visitImplementation(ImplementationMember member) {
201
 	public Void visitImplementation(ImplementationMember member) {
199
-		// TODO
202
+		JavaSourceImplementation implementation = member.getTag(JavaSourceImplementation.class);
203
+		if (implementation.inline) {
204
+			for (IDefinitionMember m : member.members) {
205
+				m.accept(this);
206
+			}
207
+		} else {
208
+			String interfaceName = member.type.accept(new JavaSourceTypeNameVisitor());
209
+			String implementationName = interfaceName + "Implementation";
210
+			
211
+			begin(ElementType.FIELD);
212
+			output.append(indent);
213
+			modifiers(member.modifiers);
214
+			output.append("final ").append(scope.type(member.type)).append(" as").append(interfaceName).append(" = new ").append(implementationName).append("();\n");
215
+			
216
+			begin(ElementType.INNERCLASS);
217
+			output.append("private class ").append(implementationName).append(" implements ").append(scope.type(member.type)).append(" {\n");
218
+			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(settings, indent + settings.indent, output, scope, isInterface, definition);
219
+			for (IDefinitionMember m : member.members) {
220
+				m.accept(memberCompiler);
221
+			}
222
+			output.append(indent).append("}\n");
223
+		}
200
 		return null;
224
 		return null;
201
 	}
225
 	}
202
 
226
 

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java View File

93
 	private String getFilename(HighLevelDefinition definition) {
93
 	private String getFilename(HighLevelDefinition definition) {
94
 		SourceFile source = definition.getTag(SourceFile.class);
94
 		SourceFile source = definition.getTag(SourceFile.class);
95
 		if (source != null) {
95
 		if (source != null) {
96
-			int slash = Math.max(source.filename.lastIndexOf('/'), source.filename.lastIndexOf('\\'));
97
-			String filename = source.filename.substring(slash < 0 ? 0 : slash + 1);
96
+			int slash = Math.max(source.getFilename().lastIndexOf('/'), source.getFilename().lastIndexOf('\\'));
97
+			String filename = source.getFilename().substring(slash < 0 ? 0 : slash + 1);
98
 			filename = filename.substring(0, filename.lastIndexOf('.'));
98
 			filename = filename.substring(0, filename.lastIndexOf('.'));
99
 			return filename;
99
 			return filename;
100
 		} else {
100
 		} else {

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java View File

20
 	public String visitBasic(BasicTypeID basic) {
20
 	public String visitBasic(BasicTypeID basic) {
21
 		switch (basic) {
21
 		switch (basic) {
22
 			case VOID: return "Void";
22
 			case VOID: return "Void";
23
-			case ANY: return "Any";
24
 			case BOOL: return "Boolean";
23
 			case BOOL: return "Boolean";
25
 			case BYTE: return "Byte";
24
 			case BYTE: return "Byte";
26
 			case SBYTE: return "Byte";
25
 			case SBYTE: return "Byte";

+ 2
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java View File

119
 	public void formatReturn(StatementFormattingTarget target, ReturnStatement statement) {
119
 	public void formatReturn(StatementFormattingTarget target, ReturnStatement statement) {
120
 		if (statement.value == null)
120
 		if (statement.value == null)
121
 			target.writeLine("return;");
121
 			target.writeLine("return;");
122
+		else if (statement.value.aborts()) // throw or panic
123
+			target.writeLine(scope.expression(target, statement.value).value + ";");
122
 		else
124
 		else
123
 			target.writeLine("return " + scope.expression(target, statement.value).value + ";");
125
 			target.writeLine("return " + scope.expression(target, statement.value).value + ";");
124
 	}
126
 	}

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeNameVisitor.java View File

29
 	@Override
29
 	@Override
30
 	public String visitBasic(BasicTypeID basic) {
30
 	public String visitBasic(BasicTypeID basic) {
31
 		switch (basic) {
31
 		switch (basic) {
32
-			case ANY: return "Any";
33
 			case VOID: return "Void";
32
 			case VOID: return "Void";
34
 			case BOOL: return "Bool";
33
 			case BOOL: return "Bool";
35
 			case BYTE: return "Byte";
34
 			case BYTE: return "Byte";

+ 0
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java View File

21
 import org.openzen.zenscript.codemodel.type.OptionalTypeID;
21
 import org.openzen.zenscript.codemodel.type.OptionalTypeID;
22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
23
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
23
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
24
-import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
25
 
24
 
26
 /**
25
 /**
27
  *
26
  *
57
 	public String visitBasic(BasicTypeID basic) {
56
 	public String visitBasic(BasicTypeID basic) {
58
 		switch (basic) {
57
 		switch (basic) {
59
 			case VOID: return "void";
58
 			case VOID: return "void";
60
-			case ANY: return "Any";
61
 			case BOOL: return "boolean";
59
 			case BOOL: return "boolean";
62
 			case BYTE: return "byte";
60
 			case BYTE: return "byte";
63
 			case SBYTE: return "byte";
61
 			case SBYTE: return "byte";

+ 19
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java View File

17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
18
 import org.openzen.zenscript.codemodel.member.FieldMember;
18
 import org.openzen.zenscript.codemodel.member.FieldMember;
19
 import org.openzen.zenscript.codemodel.member.GetterMember;
19
 import org.openzen.zenscript.codemodel.member.GetterMember;
20
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
23
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
27
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
30
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
31
+import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
30
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
32
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
31
 
33
 
32
 /**
34
 /**
64
 
66
 
65
 	@Override
67
 	@Override
66
 	public Void visitConstructor(ConstructorMember member) {
68
 	public Void visitConstructor(ConstructorMember member) {
67
-		visitFunctional(member, member.name);
69
+		visitFunctional(member, "<init>");
68
 		return null;
70
 		return null;
69
 	}
71
 	}
70
 
72
 
118
 
120
 
119
 	@Override
121
 	@Override
120
 	public Void visitImplementation(ImplementationMember member) {
122
 	public Void visitImplementation(ImplementationMember member) {
121
-		// TODO: implementation merge check
122
 		cls.empty = false;
123
 		cls.empty = false;
124
+		if (canMergeImplementation(member)) {
125
+			member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(true, cls));
126
+			for (IDefinitionMember m : member.members)
127
+				m.accept(this);
128
+		} else {
129
+			JavaSourceClass implementationClass = new JavaSourceClass(cls.pkg + "." + cls.name, member.type.accept(new JavaSourceTypeNameVisitor()) + "Implementation");
130
+			member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(false, implementationClass));
131
+			
132
+			JavaSourcePrepareClassMethodVisitor visitor = new JavaSourcePrepareClassMethodVisitor(implementationClass, null, true);
133
+			for (IDefinitionMember m : member.members)
134
+				m.accept(visitor);
135
+		}
123
 		return null;
136
 		return null;
124
 	}
137
 	}
138
+	
139
+	private boolean canMergeImplementation(ImplementationMember member) {
140
+		return true; // TODO: implementation merge check
141
+	}
125
 
142
 
126
 	@Override
143
 	@Override
127
 	public Void visitInnerDefinition(InnerDefinitionMember member) {
144
 	public Void visitInnerDefinition(InnerDefinitionMember member) {

+ 24
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java View File

22
 import org.openzen.zenscript.codemodel.expression.CastExpression;
22
 import org.openzen.zenscript.codemodel.expression.CastExpression;
23
 import org.openzen.zenscript.codemodel.expression.Expression;
23
 import org.openzen.zenscript.codemodel.expression.Expression;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
25
-import org.openzen.zenscript.codemodel.type.ArrayTypeID;
26
 import org.openzen.zenscript.formattershared.ExpressionString;
25
 import org.openzen.zenscript.formattershared.ExpressionString;
27
 import org.openzen.zenscript.javasource.JavaOperator;
26
 import org.openzen.zenscript.javasource.JavaOperator;
28
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
27
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
168
 			cls.addConstructor("constructorWithCause", "");
167
 			cls.addConstructor("constructorWithCause", "");
169
 			nativeClasses.put("stdlib::Exception", cls);
168
 			nativeClasses.put("stdlib::Exception", cls);
170
 		}
169
 		}
170
+		
171
+		{
172
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "IOException"));
173
+			cls.addConstructor("constructor", "");
174
+			nativeClasses.put("io::IOException", cls);
175
+		}
176
+		
177
+		{
178
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "Reader"));
179
+			cls.addInstanceMethod("destruct", "close");
180
+			cls.addInstanceMethod("readCharacter", "read");
181
+			cls.addInstanceMethod("readArray", "read");
182
+			cls.addInstanceMethod("readArraySlice", "read");
183
+			nativeClasses.put("io::Reader", cls);
184
+		}
185
+		
186
+		{
187
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "StringReader"));
188
+			cls.addInstanceMethod("constructor", "");
189
+			cls.addInstanceMethod("destructor", "close");
190
+			cls.addInstanceMethod("readCharacter", "read");
191
+			cls.addInstanceMethod("readSlice", "read");
192
+			nativeClasses.put("io::StringReader", cls);
193
+		}
171
 	}
194
 	}
172
 	
195
 	
173
 	private final String filename;
196
 	private final String filename;

+ 11
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java View File

17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
18
 import org.openzen.zenscript.codemodel.member.FieldMember;
18
 import org.openzen.zenscript.codemodel.member.FieldMember;
19
 import org.openzen.zenscript.codemodel.member.GetterMember;
19
 import org.openzen.zenscript.codemodel.member.GetterMember;
20
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
23
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
27
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
30
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
31
+import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
30
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
32
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
31
 
33
 
32
 /**
34
 /**
54
 	public Void visitField(FieldMember member) {
56
 	public Void visitField(FieldMember member) {
55
 		// TODO: expansion fields
57
 		// TODO: expansion fields
56
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
58
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
57
-		cls.empty = false;
59
+		if (member.hasAutoGetter() || member.hasAutoSetter())
60
+			cls.empty = false;
58
 		return null;
61
 		return null;
59
 	}
62
 	}
60
 
63
 
66
 
69
 
67
 	@Override
70
 	@Override
68
 	public Void visitDestructor(DestructorMember member) {
71
 	public Void visitDestructor(DestructorMember member) {
69
-		throw new UnsupportedOperationException("Destructors not allowed on expansions");
72
+		visitFunctional(member, "");
73
+		return null;
70
 	}
74
 	}
71
 
75
 
72
 	@Override
76
 	@Override
113
 
117
 
114
 	@Override
118
 	@Override
115
 	public Void visitImplementation(ImplementationMember member) {
119
 	public Void visitImplementation(ImplementationMember member) {
116
-		// TODO: implementation merge check
117
-		cls.empty = false;
120
+		JavaSourceClass implementationClass = new JavaSourceClass(cls.pkg + "." + cls.name, member.type.accept(new JavaSourceTypeNameVisitor()) + "Implementation");
121
+		member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(false, implementationClass));
122
+		for (IDefinitionMember implementedMember : member.members)
123
+			implementedMember.accept(this);
124
+		
118
 		return null;
125
 		return null;
119
 	}
126
 	}
120
 
127
 

+ 14
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourceSignatureVisitor.java View File

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.javasource.prepare;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class JavaSourceSignatureVisitor {
13
+	
14
+}

+ 20
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/tags/JavaSourceImplementation.java View File

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.javasource.tags;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class JavaSourceImplementation {
13
+	public final boolean inline;
14
+	public final JavaSourceClass implementationClass;
15
+	
16
+	public JavaSourceImplementation(boolean inline, JavaSourceClass implementationClass) {
17
+		this.inline = inline;
18
+		this.implementationClass = implementationClass;
19
+	}
20
+}

+ 6
- 5
Parser/src/main/java/org/openzen/zenscript/lexer/CountingCharReader.java View File

2
 
2
 
3
 import java.io.IOException;
3
 import java.io.IOException;
4
 import org.openzen.zencode.shared.CodePosition;
4
 import org.openzen.zencode.shared.CodePosition;
5
+import org.openzen.zencode.shared.SourceFile;
5
 
6
 
6
 /*
7
 /*
7
  * To change this license header, choose License Headers in Project Properties.
8
  * To change this license header, choose License Headers in Project Properties.
15
  */
16
  */
16
 public class CountingCharReader implements CharReader {
17
 public class CountingCharReader implements CharReader {
17
 	private final CharReader reader;
18
 	private final CharReader reader;
18
-	private final String filename;
19
+	private final SourceFile file;
19
 	private final int tabSize;
20
 	private final int tabSize;
20
 	
21
 	
21
 	private int line;
22
 	private int line;
22
 	private int lineOffset;
23
 	private int lineOffset;
23
-
24
-	public CountingCharReader(CharReader reader, String filename, int tabSize)
24
+	
25
+	public CountingCharReader(CharReader reader, SourceFile file, int tabSize)
25
 	{
26
 	{
26
 		this.reader = reader;
27
 		this.reader = reader;
27
-		this.filename = filename;
28
+		this.file = file;
28
 		this.tabSize = tabSize;
29
 		this.tabSize = tabSize;
29
 		
30
 		
30
 		line = 1;
31
 		line = 1;
32
 	}
33
 	}
33
 	
34
 	
34
 	public CodePosition getPosition() {
35
 	public CodePosition getPosition() {
35
-		return new CodePosition(filename, line, lineOffset, line, lineOffset);
36
+		return new CodePosition(file, line, lineOffset, line, lineOffset);
36
 	}
37
 	}
37
 
38
 
38
 	@Override
39
 	@Override

+ 9
- 7
Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java View File

6
 import org.openzen.zencode.shared.CodePosition;
6
 import org.openzen.zencode.shared.CodePosition;
7
 import org.openzen.zencode.shared.CompileException;
7
 import org.openzen.zencode.shared.CompileException;
8
 import org.openzen.zencode.shared.CompileExceptionCode;
8
 import org.openzen.zencode.shared.CompileExceptionCode;
9
+import org.openzen.zencode.shared.SourceFile;
9
 
10
 
10
 /**
11
 /**
11
  * Represents a token stream. A token stream reads characters from a reader and
12
  * Represents a token stream. A token stream reads characters from a reader and
28
     /**
29
     /**
29
      * Creates a token stream using the specified reader and DFA.
30
      * Creates a token stream using the specified reader and DFA.
30
      *
31
      *
31
-	 * @param filename filename
32
+	 * @param file filename
32
      * @param reader reader to read characters from
33
      * @param reader reader to read characters from
33
      * @param dfa DFA to tokenize the stream
34
      * @param dfa DFA to tokenize the stream
34
 	 * @param eof end of file token type
35
 	 * @param eof end of file token type
35
      */
36
      */
36
     public TokenParser(
37
     public TokenParser(
37
-			String filename,
38
+			SourceFile file,
38
 			CharReader reader, 
39
 			CharReader reader, 
39
 			CompiledDFA<TT> dfa,
40
 			CompiledDFA<TT> dfa,
40
 			TT eof,
41
 			TT eof,
44
 		if (eof.isWhitespace()) // important for the advance() method
45
 		if (eof.isWhitespace()) // important for the advance() method
45
 			throw new IllegalArgumentException("EOF cannot be whitespace");
46
 			throw new IllegalArgumentException("EOF cannot be whitespace");
46
 		
47
 		
47
-        this.reader = new CountingCharReader(reader, filename, 4);
48
+        this.reader = new CountingCharReader(reader, file, 4);
48
         this.dfa = dfa;
49
         this.dfa = dfa;
49
 		this.eof = eof;
50
 		this.eof = eof;
50
 		this.invalid = invalid;
51
 		this.invalid = invalid;
54
     /**
55
     /**
55
      * Creates a token stream which reads data from the specified string.
56
      * Creates a token stream which reads data from the specified string.
56
      *
57
      *
57
-	 * @param filename filename
58
+	 * @param file filename
58
      * @param data data to read
59
      * @param data data to read
59
      * @param dfa DFA to tokenize the stream
60
      * @param dfa DFA to tokenize the stream
60
 	 * @param eof end of file token type
61
 	 * @param eof end of file token type
61
      */
62
      */
62
-    public TokenParser(String filename, String data, CompiledDFA<TT> dfa, TT eof, TT invalid, TokenFactory<T, TT> factory)
63
+    public TokenParser(SourceFile file, String data, CompiledDFA<TT> dfa, TT eof, TT invalid, TokenFactory<T, TT> factory)
63
 	{
64
 	{
64
-        this(filename, new StringCharReader(data), dfa, eof, invalid, factory);
65
+        this(file, new StringCharReader(data), dfa, eof, invalid, factory);
65
     }
66
     }
66
 	
67
 	
67
 	@Override
68
 	@Override
110
 				if (reader.peek() < 0 && value.length() == 0)
111
 				if (reader.peek() < 0 && value.length() == 0)
111
 					return factory.create(eof, ""); // happens on comments at the end of files
112
 					return factory.create(eof, ""); // happens on comments at the end of files
112
 				
113
 				
113
-				//value.append((char) reader.next());
114
+				if (value.length() == 0)
115
+					value.append((char) reader.next());
114
 				return factory.create(invalid, value.toString());
116
 				return factory.create(invalid, value.toString());
115
             }
117
             }
116
         } catch (IOException ex) {
118
         } catch (IOException ex) {

+ 7
- 6
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenParser.java View File

7
 
7
 
8
 import java.io.IOException;
8
 import java.io.IOException;
9
 import java.io.Reader;
9
 import java.io.Reader;
10
+import org.openzen.zencode.shared.SourceFile;
10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
11
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
11
 
12
 
12
 /**
13
 /**
16
 public class ZSTokenParser extends LLParserTokenStream<ZSTokenType, ZSToken> {
17
 public class ZSTokenParser extends LLParserTokenStream<ZSTokenType, ZSToken> {
17
 	private static final CompiledDFA DFA = CompiledDFA.createLexerDFA(ZSTokenType.values(), ZSTokenType.class);
18
 	private static final CompiledDFA DFA = CompiledDFA.createLexerDFA(ZSTokenType.values(), ZSTokenType.class);
18
 	
19
 	
19
-	public static TokenParser<ZSToken, ZSTokenType> createRaw(String filename, CharReader reader, int spacesPerTab) {
20
+	public static TokenParser<ZSToken, ZSTokenType> createRaw(SourceFile file, CharReader reader, int spacesPerTab) {
20
 		return new TokenParser<>(
21
 		return new TokenParser<>(
21
-				filename,
22
+				file,
22
 				reader,
23
 				reader,
23
 				DFA,
24
 				DFA,
24
 				ZSTokenType.EOF,
25
 				ZSTokenType.EOF,
26
 				new ZSTokenFactory(spacesPerTab));
27
 				new ZSTokenFactory(spacesPerTab));
27
 	}
28
 	}
28
 	
29
 	
29
-	public static ZSTokenParser create(String filename, Reader reader, int spacesPerTab) throws IOException {
30
-		return new ZSTokenParser(createRaw(filename, new ReaderCharReader(reader), spacesPerTab));
30
+	public static ZSTokenParser create(SourceFile file, int spacesPerTab) throws IOException {
31
+		return new ZSTokenParser(createRaw(file, new ReaderCharReader(file.open()), spacesPerTab));
31
 	}
32
 	}
32
 	
33
 	
33
 	public ZSTokenParser(TokenStream<ZSTokenType, ZSToken> parser) {
34
 	public ZSTokenParser(TokenStream<ZSTokenType, ZSToken> parser) {
34
 		super(parser);
35
 		super(parser);
35
 	}
36
 	}
36
 	
37
 	
37
-	public String getFilename() {
38
-		return getPosition().filename;
38
+	public SourceFile getFile() {
39
+		return getPosition().file;
39
 	}
40
 	}
40
 	
41
 	
41
 	public WhitespaceInfo collectWhitespaceInfo(String whitespace, boolean skipLineBefore) {
42
 	public WhitespaceInfo collectWhitespaceInfo(String whitespace, boolean skipLineBefore) {

+ 3
- 1
Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java View File

76
 	
76
 	
77
 	public abstract void compileMembers(BaseScope scope);
77
 	public abstract void compileMembers(BaseScope scope);
78
 	
78
 	
79
-	public abstract void compileCode(BaseScope scope);
79
+	public abstract void listMembers(BaseScope scope, PrecompilationState state);
80
+	
81
+	public abstract void compileCode(BaseScope scope, PrecompilationState state);
80
 }
82
 }

+ 21
- 19
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

6
 package org.openzen.zenscript.parser;
6
 package org.openzen.zenscript.parser;
7
 
7
 
8
 import java.io.File;
8
 import java.io.File;
9
-import java.io.FileReader;
10
 import java.io.IOException;
9
 import java.io.IOException;
11
-import java.io.Reader;
12
-import java.io.StringReader;
13
 import java.util.ArrayList;
10
 import java.util.ArrayList;
14
 import java.util.List;
11
 import java.util.List;
15
 import java.util.Map;
12
 import java.util.Map;
16
 import org.openzen.zencode.shared.CodePosition;
13
 import org.openzen.zencode.shared.CodePosition;
17
 import org.openzen.zencode.shared.CompileException;
14
 import org.openzen.zencode.shared.CompileException;
18
 import org.openzen.zencode.shared.CompileExceptionCode;
15
 import org.openzen.zencode.shared.CompileExceptionCode;
16
+import org.openzen.zencode.shared.FileSourceFile;
17
+import org.openzen.zencode.shared.LiteralSourceFile;
19
 import org.openzen.zencode.shared.SourceFile;
18
 import org.openzen.zencode.shared.SourceFile;
20
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
19
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
21
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
42
  */
41
  */
43
 public class ParsedFile {
42
 public class ParsedFile {
44
 	public static ParsedFile parse(ZSPackage pkg, File file) throws IOException {
43
 	public static ParsedFile parse(ZSPackage pkg, File file) throws IOException {
45
-		String filename = file.toString();
46
-		try (FileReader reader = new FileReader(file)) {
47
-			return parse(pkg, filename, reader);
48
-		}
44
+		return parse(pkg, new FileSourceFile(file.getName(), file));
49
 	}
45
 	}
50
 	
46
 	
51
 	public static ParsedFile parse(ZSPackage pkg, String filename, String content) {
47
 	public static ParsedFile parse(ZSPackage pkg, String filename, String content) {
52
-		try (StringReader reader = new StringReader(content)) {
53
-			return parse(pkg, filename, reader);
48
+		try {
49
+			return parse(pkg, new LiteralSourceFile(filename, content));
54
 		} catch (IOException ex) {
50
 		} catch (IOException ex) {
55
-			throw new AssertionError(); // supposed to never happen in a StringReader
51
+			throw new AssertionError(); // shouldn't happen
56
 		}
52
 		}
57
 	}
53
 	}
58
 	
54
 	
59
-	public static ParsedFile parse(ZSPackage pkg, String filename, Reader reader) throws IOException {
60
-		ZSTokenParser tokens = ZSTokenParser.create(filename, reader, 4);
55
+	public static ParsedFile parse(ZSPackage pkg, SourceFile file) throws IOException {
56
+		ZSTokenParser tokens = ZSTokenParser.create(file, 4);
61
 		return parse(pkg, tokens);
57
 		return parse(pkg, tokens);
62
 	}
58
 	}
63
 	
59
 	
64
 	public static ParsedFile parse(ZSPackage pkg, ZSTokenParser tokens) {
60
 	public static ParsedFile parse(ZSPackage pkg, ZSTokenParser tokens) {
65
-		ParsedFile result = new ParsedFile(tokens.getFilename());
61
+		ParsedFile result = new ParsedFile(tokens.getFile());
66
 		ZSToken eof = null;
62
 		ZSToken eof = null;
67
 
63
 
68
 		while (true) {
64
 		while (true) {
124
 		return result;
120
 		return result;
125
 	}
121
 	}
126
 	
122
 	
127
-	public final String filename;
123
+	public final SourceFile file;
128
 	
124
 	
129
 	private final List<ParsedImport> imports = new ArrayList<>();
125
 	private final List<ParsedImport> imports = new ArrayList<>();
130
 	private final List<ParsedDefinition> definitions = new ArrayList<>();
126
 	private final List<ParsedDefinition> definitions = new ArrayList<>();
131
 	private final List<ParsedStatement> statements = new ArrayList<>();
127
 	private final List<ParsedStatement> statements = new ArrayList<>();
132
 	private WhitespacePostComment postComment = null;
128
 	private WhitespacePostComment postComment = null;
133
 	
129
 	
134
-	public ParsedFile(String filename) {
135
-		this.filename = filename;
130
+	public ParsedFile(SourceFile file) {
131
+		this.file = file;
136
 	}
132
 	}
137
 	
133
 	
138
 	public boolean hasErrors() {
134
 	public boolean hasErrors() {
145
 	
141
 	
146
 	public void listDefinitions(PackageDefinitions definitions) {
142
 	public void listDefinitions(PackageDefinitions definitions) {
147
 		for (ParsedDefinition definition : this.definitions) {
143
 		for (ParsedDefinition definition : this.definitions) {
148
-			definition.getCompiled().setTag(SourceFile.class, new SourceFile(filename));
144
+			definition.getCompiled().setTag(SourceFile.class, file);
149
 			definitions.add(definition.getCompiled());
145
 			definitions.add(definition.getCompiled());
150
 			definition.linkInnerTypes();
146
 			definition.linkInnerTypes();
151
 		}
147
 		}
192
 			List<AnnotationDefinition> annotations) {
188
 			List<AnnotationDefinition> annotations) {
193
 		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
189
 		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
194
 		loadImports(scope, rootPackage, modulePackage);
190
 		loadImports(scope, rootPackage, modulePackage);
191
+		
192
+		PrecompilationState state = new PrecompilationState();
193
+		for (ParsedDefinition definition : this.definitions) {
194
+			definition.listMembers(scope, state);
195
+		}
196
+		
195
 		for (ParsedDefinition definition : this.definitions) {
197
 		for (ParsedDefinition definition : this.definitions) {
196
-			definition.compileCode(scope);
198
+			definition.compileCode(scope, state);
197
 		}
199
 		}
198
 		
200
 		
199
 		if (!statements.isEmpty() || postComment != null) {
201
 		if (!statements.isEmpty() || postComment != null) {
204
 			}
206
 			}
205
 			
207
 			
206
 			ScriptBlock block = new ScriptBlock(statements);
208
 			ScriptBlock block = new ScriptBlock(statements);
207
-			block.setTag(SourceFile.class, new SourceFile(filename));
209
+			block.setTag(SourceFile.class, file);
208
 			block.setTag(WhitespacePostComment.class, postComment);
210
 			block.setTag(WhitespacePostComment.class, postComment);
209
 			scripts.add(block);
211
 			scripts.add(block);
210
 		}
212
 		}

+ 61
- 0
Parser/src/main/java/org/openzen/zenscript/parser/PrecompilationState.java View File

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.parser;
7
+
8
+import java.util.HashMap;
9
+import java.util.HashSet;
10
+import java.util.Map;
11
+import java.util.Set;
12
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
13
+import org.openzen.zenscript.codemodel.scope.BaseScope;
14
+import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class PrecompilationState {
21
+	private final Map<IDefinitionMember, CompilableMember> members = new HashMap<>();
22
+	private final Set<ParsedDefinitionMember> compilingMembers = new HashSet<>();
23
+	
24
+	public PrecompilationState() {
25
+		
26
+	}
27
+	
28
+	public void register(BaseScope definitionScope, ParsedDefinitionMember member) {
29
+		members.put(member.getCompiled(), new CompilableMember(member, definitionScope));
30
+	}
31
+	
32
+	public boolean precompile(IDefinitionMember member) {
33
+		if (!members.containsKey(member))
34
+			return true;
35
+		
36
+		CompilableMember cMember = members.get(member);
37
+		if (compilingMembers.contains(cMember.member))
38
+			return false;
39
+		
40
+		compilingMembers.add(cMember.member);
41
+		if (!cMember.member.inferHeaders(cMember.definitionScope, this))
42
+			return false;
43
+		
44
+		compilingMembers.remove(cMember.member);
45
+		return true;
46
+	}
47
+	
48
+	public void end(ParsedDefinitionMember member) {
49
+		compilingMembers.remove(member);
50
+	}
51
+	
52
+	private class CompilableMember {
53
+		private final ParsedDefinitionMember member;
54
+		private final BaseScope definitionScope;
55
+		
56
+		public CompilableMember(ParsedDefinitionMember member, BaseScope definitionScope) {
57
+			this.member = member;
58
+			this.definitionScope = definitionScope;
59
+		}
60
+	}
61
+}

+ 10
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java View File

12
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
12
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
13
 import org.openzen.zenscript.parser.ParsedAnnotation;
13
 import org.openzen.zenscript.parser.ParsedAnnotation;
14
 import org.openzen.zenscript.parser.ParsedDefinition;
14
 import org.openzen.zenscript.parser.ParsedDefinition;
15
+import org.openzen.zenscript.parser.PrecompilationState;
15
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
16
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
16
 
17
 
17
 /**
18
 /**
45
 			getCompiled().addMember(member.getCompiled());
46
 			getCompiled().addMember(member.getCompiled());
46
 		}
47
 		}
47
 	}
48
 	}
49
+	
50
+	@Override
51
+	public void listMembers(BaseScope scope, PrecompilationState state) {
52
+		DefinitionScope innerScope = new DefinitionScope(scope, getCompiled());
53
+		for (ParsedDefinitionMember member : members)
54
+			state.register(innerScope, member);
55
+	}
48
 
56
 
49
 	@Override
57
 	@Override
50
-	public void compileCode(BaseScope scope) {
58
+	public void compileCode(BaseScope scope, PrecompilationState state) {
51
 		DefinitionScope innerScope = new DefinitionScope(scope, getCompiled());
59
 		DefinitionScope innerScope = new DefinitionScope(scope, getCompiled());
52
 		for (ParsedDefinitionMember member : members)
60
 		for (ParsedDefinitionMember member : members)
53
-			member.compile(innerScope);
61
+			member.compile(innerScope, state);
54
 	}
62
 	}
55
 }
63
 }

+ 7
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java View File

17
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
17
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
19
 import org.openzen.zenscript.parser.ParsedDefinition;
19
 import org.openzen.zenscript.parser.ParsedDefinition;
20
+import org.openzen.zenscript.parser.PrecompilationState;
20
 import org.openzen.zenscript.parser.type.IParsedType;
21
 import org.openzen.zenscript.parser.type.IParsedType;
21
 
22
 
22
 /**
23
 /**
73
 		
74
 		
74
 		compiled.setType(type.compile(innerScope));
75
 		compiled.setType(type.compile(innerScope));
75
 	}
76
 	}
77
+	
78
+	@Override
79
+	public void listMembers(BaseScope scope, PrecompilationState state) {
80
+		// nothing to do
81
+	}
76
 
82
 
77
 	@Override
83
 	@Override
78
-	public void compileCode(BaseScope scope) {
84
+	public void compileCode(BaseScope scope, PrecompilationState state) {
79
 		// nothing to do
85
 		// nothing to do
80
 	}
86
 	}
81
 
87
 

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java View File

36
 		
36
 		
37
 		ParsedClass result = new ParsedClass(pkg, position, modifiers, annotations, name, genericParameters, superclass, outerDefinition);
37
 		ParsedClass result = new ParsedClass(pkg, position, modifiers, annotations, name, genericParameters, superclass, outerDefinition);
38
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
38
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
39
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled));
39
+			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
40
 		}
40
 		}
41
 		return result;
41
 		return result;
42
 	}
42
 	}

+ 4
- 3
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java View File

18
 import org.openzen.zenscript.codemodel.scope.BaseScope;
18
 import org.openzen.zenscript.codemodel.scope.BaseScope;
19
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20
 import org.openzen.zenscript.parser.ParsedAnnotation;
20
 import org.openzen.zenscript.parser.ParsedAnnotation;
21
+import org.openzen.zenscript.parser.PrecompilationState;
21
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
22
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
22
 
23
 
23
 /**
24
 /**
39
 		
40
 		
40
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
41
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
41
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
42
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
42
-				result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled));
43
+				result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
43
 			}
44
 			}
44
 		} else {
45
 		} else {
45
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
46
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
76
 	}
77
 	}
77
 
78
 
78
 	@Override
79
 	@Override
79
-	public void compileCode(BaseScope scope) {
80
-		super.compileCode(scope);
80
+	public void compileCode(BaseScope scope, PrecompilationState state) {
81
+		super.compileCode(scope, state);
81
 		
82
 		
82
 		DefinitionTypeID type = new DefinitionTypeID(compiled, new ITypeID[0]);
83
 		DefinitionTypeID type = new DefinitionTypeID(compiled, new ITypeID[0]);
83
 		ExpressionScope evalScope = new ExpressionScope(scope);
84
 		ExpressionScope evalScope = new ExpressionScope(scope);

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java View File

30
 		
30
 		
31
 		ParsedExpansion result = new ParsedExpansion(pkg, position, modifiers, annotations, parameters, target, outerDefinition);
31
 		ParsedExpansion result = new ParsedExpansion(pkg, position, modifiers, annotations, parameters, target, outerDefinition);
32
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
32
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
33
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled));
33
+			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
34
 		}
34
 		}
35
 		return result;
35
 		return result;
36
 	}
36
 	}

+ 18
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java View File

7
 package org.openzen.zenscript.parser.definitions;
7
 package org.openzen.zenscript.parser.definitions;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
+import org.openzen.zencode.shared.CompileExceptionCode;
10
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
12
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
14
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
16
 import org.openzen.zenscript.lexer.ZSTokenParser;
15
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
16
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
19
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
20
+import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
21
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedDefinition;
22
 import org.openzen.zenscript.parser.ParsedDefinition;
23
+import org.openzen.zenscript.parser.PrecompilationState;
19
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
24
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
20
 import org.openzen.zenscript.parser.statements.ParsedStatement;
25
 import org.openzen.zenscript.parser.statements.ParsedStatement;
21
 
26
 
59
 	public void compileMembers(BaseScope scope) {
64
 	public void compileMembers(BaseScope scope) {
60
 		compiled.setHeader(header.compile(scope));
65
 		compiled.setHeader(header.compile(scope));
61
 	}
66
 	}
67
+	
68
+	@Override
69
+	public void listMembers(BaseScope scope, PrecompilationState state) {
70
+		
71
+	}
62
 
72
 
63
 	@Override
73
 	@Override
64
-	public void compileCode(BaseScope scope) {
74
+	public void compileCode(BaseScope scope, PrecompilationState state) {
65
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
75
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
66
 		compiled.setCode(body.compile(innerScope, compiled.header));
76
 		compiled.setCode(body.compile(innerScope, compiled.header));
77
+		
78
+		if (compiled.header.returnType == BasicTypeID.UNDETERMINED) {
79
+			ITypeID result = body.precompileForResultType(new FunctionScope(scope, compiled.header), state);
80
+			if (result == null)
81
+				throw new CompileException(position, CompileExceptionCode.PRECOMPILE_FAILED, "Could not determine return type for method " + compiled.name);
82
+			compiled.header = compiled.header.withReturnType(result);
83
+		}
67
 	}
84
 	}
68
 }
85
 }

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java View File

47
 				ZSToken argName = tokens.required(T_IDENTIFIER, "identifier expected");
47
 				ZSToken argName = tokens.required(T_IDENTIFIER, "identifier expected");
48
 				boolean variadic = tokens.optional(T_DOT3) != null;
48
 				boolean variadic = tokens.optional(T_DOT3) != null;
49
 				
49
 				
50
-				IParsedType type = ParsedTypeBasic.ANY;
50
+				IParsedType type = ParsedTypeBasic.UNDETERMINED;
51
 				if (tokens.optional(K_AS) != null) {
51
 				if (tokens.optional(K_AS) != null) {
52
 					type = IParsedType.parse(tokens);
52
 					type = IParsedType.parse(tokens);
53
 				}
53
 				}
60
 			tokens.required(T_BRCLOSE, ") expected");
60
 			tokens.required(T_BRCLOSE, ") expected");
61
 		}
61
 		}
62
 
62
 
63
-		IParsedType returnType = ParsedTypeBasic.ANY;
63
+		IParsedType returnType = ParsedTypeBasic.UNDETERMINED;
64
 		if (tokens.optional(K_AS) != null) {
64
 		if (tokens.optional(K_AS) != null) {
65
 			returnType = IParsedType.parse(tokens);
65
 			returnType = IParsedType.parse(tokens);
66
 		}
66
 		}

+ 0
- 0
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save