Browse Source

- Added support for implementations and method overriding

- Added override method header inference: if a method overrides or implements another method, and types are missing from the header, these will be inherited from the base method. This works with any kind of method (method, operator, getter, setter, caller)
- Added method return type inference, which is automatically inferred from the return value of the contents of the method. This functionality is not yet fully implemented, and will fail with certain expressions (most notably, member expressions and calls). The goal is to make this system work as long as there is no recursion. This works with methods, operators, getters, calls as well as fields and constants with initializers.
- Removed the any type. With return type inference its usefulness has become even more limited, and proper implementation of the any type is expected to be complicated, thus not worth the effort. (this may be revisited later on, as "any" remains a reserved keyword)
- Fixed compilation of throw as panic expressions in lambda function bodies
- Moved name from FunctionalMember to MethodMember, where it makes more sense
- Each method (or functional) is now also aware of the member that it overrides
Stan Hebben 6 years ago
parent
commit
b1545a872d
100 changed files with 1007 additions and 96 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. 10
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  7. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PanicExpression.java
  8. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThrowExpression.java
  9. 16
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java
  10. 12
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java
  11. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java
  12. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  13. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CustomIteratorMember.java
  14. 9
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java
  15. 9
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DestructorMember.java
  16. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  17. 1
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  18. 17
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  19. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java
  20. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java
  21. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java
  22. 24
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MethodMember.java
  23. 14
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/OperatorMember.java
  24. 16
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java
  25. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java
  26. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java
  27. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java
  28. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java
  29. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java
  30. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java
  31. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java
  32. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ConstMemberRef.java
  33. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/DefinitionMemberRef.java
  34. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FieldMemberRef.java
  35. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java
  36. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/GetterMemberRef.java
  37. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java
  38. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java
  39. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/SetterMemberRef.java
  40. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java
  41. 7
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java
  42. 1
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  43. 24
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  44. 19
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  45. 1
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  46. 3
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  47. 0
    6
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  48. 0
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java
  49. 0
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  50. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java
  51. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java
  52. 25
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  53. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java
  54. 2
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java
  55. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeNameVisitor.java
  56. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  57. 19
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java
  58. 2
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java
  59. 14
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourceSignatureVisitor.java
  60. 4
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/tags/JavaSourceImplementation.java
  61. 2
    1
      Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java
  62. 3
    1
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java
  63. 7
    2
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  64. 61
    0
      Parser/src/main/java/org/openzen/zenscript/parser/PrecompilationState.java
  65. 10
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java
  66. 7
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java
  67. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java
  68. 4
    3
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java
  69. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java
  70. 11
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  71. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java
  72. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java
  73. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedStruct.java
  74. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java
  75. 11
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java
  76. 3
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  77. 11
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAndAnd.java
  78. 22
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java
  79. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAssign.java
  80. 19
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBinary.java
  81. 8
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBool.java
  82. 11
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java
  83. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  84. 8
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCast.java
  85. 14
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java
  86. 8
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCompare.java
  87. 11
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionConditional.java
  88. 13
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFloat.java
  89. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  90. 25
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java
  91. 27
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java
  92. 7
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIs.java
  93. 11
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java
  94. 17
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java
  95. 8
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionNull.java
  96. 7
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOpAssign.java
  97. 12
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOrOr.java
  98. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOuter.java
  99. 7
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java
  100. 0
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.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
 	}

+ 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
 }

+ 9
- 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) {
47
 	public boolean isPrivate() {
47
 	public boolean isPrivate() {
48
 		return Modifiers.isPrivate(modifiers);
48
 		return Modifiers.isPrivate(modifiers);
49
 	}
49
 	}
50
+	
51
+	public boolean isPublic() {
52
+		return Modifiers.isPublic(modifiers);
53
+	}
54
+	
55
+	public boolean isProtected() {
56
+		return Modifiers.isProtected(modifiers);
57
+	}
50
 }
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
 }

+ 21
- 0
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
 	}

+ 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
 		

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

773
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
773
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
774
 							javaWriter.checkCast("[Ljava/lang/String;");
774
 							javaWriter.checkCast("[Ljava/lang/String;");
775
 							break;
775
 							break;
776
-						case ANY:
777
-							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
778
-							javaWriter.checkCast("[Lzsynthetic/Any;");
779
-							break;
780
 						default:
776
 						default:
781
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
777
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
782
 					}
778
 					}
822
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
818
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
823
 							break;
819
 							break;
824
 						case STRING:
820
 						case STRING:
825
-						case ANY:
826
 							javaWriter.invokeStatic(ARRAYS_EQUALS_OBJECTS);
821
 							javaWriter.invokeStatic(ARRAYS_EQUALS_OBJECTS);
827
 							break;
822
 							break;
828
 						default:
823
 						default:
1737
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1732
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1738
 							break;
1733
 							break;
1739
 						case STRING:
1734
 						case STRING:
1740
-						case ANY:
1741
 							javaWriter.invokeStatic(ARRAYS_DEEPHASHCODE);
1735
 							javaWriter.invokeStatic(ARRAYS_DEEPHASHCODE);
1742
 							break;
1736
 							break;
1743
 						default:
1737
 						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:

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

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

+ 6
- 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 ");

+ 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
 		}

+ 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
 

+ 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
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java View File

56
 	public String visitBasic(BasicTypeID basic) {
56
 	public String visitBasic(BasicTypeID basic) {
57
 		switch (basic) {
57
 		switch (basic) {
58
 			case VOID: return "void";
58
 			case VOID: return "void";
59
-			case ANY: return "Any";
60
 			case BOOL: return "boolean";
59
 			case BOOL: return "boolean";
61
 			case BYTE: return "byte";
60
 			case BYTE: return "byte";
62
 			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) {

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

117
 
117
 
118
 	@Override
118
 	@Override
119
 	public Void visitImplementation(ImplementationMember member) {
119
 	public Void visitImplementation(ImplementationMember member) {
120
-		// TODO: implementation merge check
121
-		//cls.empty = false; -> TODO: 
122
-		member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(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));
123
 		for (IDefinitionMember implementedMember : member.members)
122
 		for (IDefinitionMember implementedMember : member.members)
124
 			implementedMember.accept(this);
123
 			implementedMember.accept(this);
125
 		
124
 		

+ 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
+}

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

10
  * @author Hoofdgebruiker
10
  * @author Hoofdgebruiker
11
  */
11
  */
12
 public class JavaSourceImplementation {
12
 public class JavaSourceImplementation {
13
-	public boolean inline = true;
13
+	public final boolean inline;
14
+	public final JavaSourceClass implementationClass;
14
 	
15
 	
15
-	public JavaSourceImplementation() {}
16
-	
17
-	public JavaSourceImplementation(boolean inline) {
16
+	public JavaSourceImplementation(boolean inline, JavaSourceClass implementationClass) {
18
 		this.inline = inline;
17
 		this.inline = inline;
18
+		this.implementationClass = implementationClass;
19
 	}
19
 	}
20
 }
20
 }

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java View File

111
 				if (reader.peek() < 0 && value.length() == 0)
111
 				if (reader.peek() < 0 && value.length() == 0)
112
 					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
113
 				
113
 				
114
-				//value.append((char) reader.next());
114
+				if (value.length() == 0)
115
+					value.append((char) reader.next());
115
 				return factory.create(invalid, value.toString());
116
 				return factory.create(invalid, value.toString());
116
             }
117
             }
117
         } catch (IOException ex) {
118
         } catch (IOException ex) {

+ 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
 }

+ 7
- 2
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.util.ArrayList;
10
 import java.util.ArrayList;
12
 import java.util.List;
11
 import java.util.List;
189
 			List<AnnotationDefinition> annotations) {
188
 			List<AnnotationDefinition> annotations) {
190
 		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
189
 		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
191
 		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
+		
192
 		for (ParsedDefinition definition : this.definitions) {
197
 		for (ParsedDefinition definition : this.definitions) {
193
-			definition.compileCode(scope);
198
+			definition.compileCode(scope, state);
194
 		}
199
 		}
195
 		
200
 		
196
 		if (!statements.isEmpty() || postComment != null) {
201
 		if (!statements.isEmpty() || postComment != null) {

+ 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
 	}

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

14
 import org.openzen.zenscript.lexer.ZSTokenParser;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
15
 import org.openzen.zenscript.codemodel.scope.BaseScope;
15
 import org.openzen.zenscript.codemodel.scope.BaseScope;
16
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
16
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
17
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedDefinition;
19
 import org.openzen.zenscript.parser.ParsedDefinition;
20
+import org.openzen.zenscript.parser.PrecompilationState;
19
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
21
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
20
 import org.openzen.zenscript.parser.statements.ParsedStatement;
22
 import org.openzen.zenscript.parser.statements.ParsedStatement;
21
 
23
 
59
 	public void compileMembers(BaseScope scope) {
61
 	public void compileMembers(BaseScope scope) {
60
 		compiled.setHeader(header.compile(scope));
62
 		compiled.setHeader(header.compile(scope));
61
 	}
63
 	}
64
+	
65
+	@Override
66
+	public void listMembers(BaseScope scope, PrecompilationState state) {
67
+		
68
+	}
62
 
69
 
63
 	@Override
70
 	@Override
64
-	public void compileCode(BaseScope scope) {
71
+	public void compileCode(BaseScope scope, PrecompilationState state) {
65
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
72
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
66
 		compiled.setCode(body.compile(innerScope, compiled.header));
73
 		compiled.setCode(body.compile(innerScope, compiled.header));
74
+		
75
+		if (compiled.header.returnType == BasicTypeID.UNDETERMINED)
76
+			compiled.header = compiled.header.withReturnType(body.precompileForResultType(new FunctionScope(scope, compiled.header), state));
67
 	}
77
 	}
68
 }
78
 }

+ 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
 		}

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

39
 		
39
 		
40
 		ParsedInterface result = new ParsedInterface(pkg, position, modifiers, annotations, name, genericParameters, superInterfaces, outerDefinition);
40
 		ParsedInterface result = new ParsedInterface(pkg, position, modifiers, annotations, name, genericParameters, superInterfaces, outerDefinition);
41
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
41
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
42
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled));
42
+			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
43
 		}
43
 		}
44
 		return result;
44
 		return result;
45
 	}
45
 	}

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

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

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

48
 		
48
 		
49
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
49
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
50
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
50
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
51
-				result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled));
51
+				result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
52
 			}
52
 			}
53
 		} else {
53
 		} else {
54
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
54
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");

+ 11
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java View File

12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.parser.PrecompilationState;
15
 
17
 
16
 /**
18
 /**
17
  *
19
  *
35
 	public boolean hasStrongType() {
37
 	public boolean hasStrongType() {
36
 		return true;
38
 		return true;
37
 	}
39
 	}
40
+
41
+	@Override
42
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
43
+		Function<CodePosition, Expression> dollar = scope.getDollar();
44
+		if (dollar == null)
45
+			return null;
46
+		
47
+		return dollar.apply(position).type;
48
+	}
38
 }
49
 }

+ 3
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java View File

27
 import org.openzen.zenscript.lexer.ZSTokenParser;
27
 import org.openzen.zenscript.lexer.ZSTokenParser;
28
 import org.openzen.zenscript.codemodel.scope.BaseScope;
28
 import org.openzen.zenscript.codemodel.scope.BaseScope;
29
 import org.openzen.zenscript.parser.ParseException;
29
 import org.openzen.zenscript.parser.ParseException;
30
+import org.openzen.zenscript.parser.PrecompilationState;
30
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
32
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
32
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
33
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
595
 	}
596
 	}
596
 	
597
 	
597
 	public abstract boolean hasStrongType();
598
 	public abstract boolean hasStrongType();
599
+	
600
+	public abstract ITypeID precompileForType(ExpressionScope scope, PrecompilationState state);
598
 }
601
 }

+ 11
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAndAnd.java View File

14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17
 
18
 
18
 /**
19
 /**
19
  *
20
  *
52
 	public boolean hasStrongType() {
53
 	public boolean hasStrongType() {
53
 		return left.hasStrongType() && right.hasStrongType();
54
 		return left.hasStrongType() && right.hasStrongType();
54
 	}
55
 	}
56
+
57
+	@Override
58
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
59
+		ITypeID leftType = left.precompileForType(scope, state);
60
+		ITypeID rightType = right.precompileForType(scope, state);
61
+		if (leftType == null || rightType == null)
62
+			return null;
63
+		
64
+		return scope.getTypeMembers(leftType).union(rightType);
65
+	}
55
 }
66
 }

+ 22
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java View File

8
 
8
 
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
12
+import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zenscript.codemodel.expression.ArrayExpression;
13
 import org.openzen.zenscript.codemodel.expression.ArrayExpression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
15
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
+import org.openzen.zenscript.parser.PrecompilationState;
18
 
20
 
19
 /**
21
 /**
20
  *
22
  *
31
 
33
 
32
 	@Override
34
 	@Override
33
 	public IPartialExpression compile(ExpressionScope scope) {
35
 	public IPartialExpression compile(ExpressionScope scope) {
34
-		ITypeID asBaseType = BasicTypeID.ANY;
35
-		ArrayTypeID asType = scope.getTypeRegistry().getArray(asBaseType, 1);
36
+		ITypeID asBaseType = null;
37
+		ArrayTypeID asType = null;
36
 		boolean couldHintType = false;
38
 		boolean couldHintType = false;
37
 		
39
 		
38
 		for (ITypeID hint : scope.hints) {
40
 		for (ITypeID hint : scope.hints) {
53
 			for (int i = 0; i < contents.size(); i++)
55
 			for (int i = 0; i < contents.size(); i++)
54
 				cContents[i] = contents.get(i).compile(contentScope).eval().castImplicit(position, scope, asBaseType);
56
 				cContents[i] = contents.get(i).compile(contentScope).eval().castImplicit(position, scope, asBaseType);
55
 		} else if (contents.isEmpty()) {
57
 		} else if (contents.isEmpty()) {
56
-			return new ArrayExpression(position, cContents, asType);
58
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_ARRAY, "Empty array with unknown type");
57
 		} else {
59
 		} else {
58
 			ExpressionScope contentScope = scope.withoutHints();
60
 			ExpressionScope contentScope = scope.withoutHints();
59
 			ITypeID resultType = null;
61
 			ITypeID resultType = null;
81
 	public boolean hasStrongType() {
83
 	public boolean hasStrongType() {
82
 		return false;
84
 		return false;
83
 	}
85
 	}
86
+
87
+	@Override
88
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
89
+		if (contents.isEmpty())
90
+			return null;
91
+		
92
+		ITypeID type = contents.get(0).precompileForType(scope, state);
93
+		if (type == null)
94
+			return null;
95
+		
96
+		for (int i = 1; i < contents.size(); i++) {
97
+			ITypeID itemType = contents.get(i).precompileForType(scope, state);
98
+			type = scope.getTypeMembers(type).union(itemType);
99
+		}
100
+		return type;
101
+	}
84
 }
102
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAssign.java View File

12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.parser.PrecompilationState;
15
 
16
 
16
 /**
17
 /**
17
  *
18
  *
41
 	public boolean hasStrongType() {
42
 	public boolean hasStrongType() {
42
 		return right.hasStrongType();
43
 		return right.hasStrongType();
43
 	}
44
 	}
45
+
46
+	@Override
47
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
48
+		return left.precompileForType(scope, state);
49
+	}
44
 }
50
 }

+ 19
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBinary.java View File

10
 import org.openzen.zenscript.codemodel.OperatorType;
10
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
15
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.codemodel.type.ITypeID;
18
+import org.openzen.zenscript.parser.PrecompilationState;
16
 
19
 
17
 /**
20
 /**
18
  *
21
  *
44
 	public boolean hasStrongType() {
47
 	public boolean hasStrongType() {
45
 		return left.hasStrongType() && right.hasStrongType();
48
 		return left.hasStrongType() && right.hasStrongType();
46
 	}
49
 	}
50
+
51
+	@Override
52
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
53
+		ITypeID leftType = left.precompileForType(scope, state);
54
+		if (leftType == null)
55
+			return null;
56
+		
57
+		DefinitionMemberGroup members = scope.getTypeMembers(leftType).getOrCreateGroup(this.operator);
58
+		ExpressionScope innerScope = scope.withHints(members.predictCallTypes(scope, scope.getResultTypeHints(), 1)[0]);
59
+		ITypeID rightType = right.precompileForType(innerScope, state);
60
+		FunctionalMemberRef method = members.selectMethod(position, scope, new CallArguments(rightType), true, false);
61
+		if (!state.precompile(method.getTarget()))
62
+			return null;
63
+		
64
+		return method.getTarget().header.returnType; // TODO: this will not work properly for methods with type parameters
65
+	}
47
 }
66
 }

+ 8
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBool.java View File

10
 import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
10
 import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
+import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.parser.PrecompilationState;
13
 
16
 
14
 /**
17
 /**
15
  *
18
  *
33
 	public boolean hasStrongType() {
36
 	public boolean hasStrongType() {
34
 		return true;
37
 		return true;
35
 	}
38
 	}
39
+
40
+	@Override
41
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
42
+		return BasicTypeID.BOOL;
43
+	}
36
 }
44
 }

+ 11
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java View File

12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.parser.PrecompilationState;
15
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
16
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
18
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
17
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
19
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
44
 		for (ParsedExpression expression : expressions)
46
 		for (ParsedExpression expression : expressions)
45
 			parameters.add(expression.toLambdaParameter());
47
 			parameters.add(expression.toLambdaParameter());
46
 		
48
 		
47
-		return new ParsedFunctionHeader(parameters, ParsedTypeBasic.ANY, null);
49
+		return new ParsedFunctionHeader(parameters, ParsedTypeBasic.UNDETERMINED, null);
48
 	}
50
 	}
49
 
51
 
50
 	@Override
52
 	@Override
51
 	public boolean hasStrongType() {
53
 	public boolean hasStrongType() {
52
 		return expressions.get(0).hasStrongType();
54
 		return expressions.get(0).hasStrongType();
53
 	}
55
 	}
56
+
57
+	@Override
58
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
59
+		if (expressions.size() != 1)
60
+			return null;
61
+		
62
+		return expressions.get(0).precompileForType(scope, state);
63
+	}
54
 }
64
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java View File

27
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
27
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
28
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
28
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
29
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
29
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
30
+import org.openzen.zenscript.parser.PrecompilationState;
30
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
31
 
32
 
32
 /**
33
 /**
120
 	public boolean hasStrongType() {
121
 	public boolean hasStrongType() {
121
 		return true;
122
 		return true;
122
 	}
123
 	}
124
+
125
+	@Override
126
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
127
+		return null; // TODO: add support for this...
128
+	}
123
 }
129
 }

+ 8
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCast.java View File

13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
 import org.openzen.zenscript.parser.ParsedAnnotation;
15
 import org.openzen.zenscript.parser.ParsedAnnotation;
16
+import org.openzen.zenscript.parser.PrecompilationState;
16
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
18
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
18
 import org.openzen.zenscript.parser.type.IParsedType;
19
 import org.openzen.zenscript.parser.type.IParsedType;
49
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Not a valid lambda header");
50
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Not a valid lambda header");
50
 		
51
 		
51
 		ParsedFunctionHeader header = value.toLambdaHeader();
52
 		ParsedFunctionHeader header = value.toLambdaHeader();
52
-		if (header.returnType != ParsedTypeBasic.ANY)
53
+		if (header.returnType != ParsedTypeBasic.UNDETERMINED)
53
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Lambda parameter already has a return type");
54
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Lambda parameter already has a return type");
54
 		
55
 		
55
 		return new ParsedFunctionHeader(header.genericParameters, header.parameters, type, null);
56
 		return new ParsedFunctionHeader(header.genericParameters, header.parameters, type, null);
61
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Not a valid lambda header");
62
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Not a valid lambda header");
62
 		
63
 		
63
 		ParsedFunctionParameter parameter = value.toLambdaParameter();
64
 		ParsedFunctionParameter parameter = value.toLambdaParameter();
64
-		if (parameter.type != ParsedTypeBasic.ANY)
65
+		if (parameter.type != ParsedTypeBasic.UNDETERMINED)
65
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Lambda parameter already has a type");
66
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Lambda parameter already has a type");
66
 		
67
 		
67
 		return new ParsedFunctionParameter(ParsedAnnotation.NONE, parameter.name, type, null, false);
68
 		return new ParsedFunctionParameter(ParsedAnnotation.NONE, parameter.name, type, null, false);
71
 	public boolean hasStrongType() {
72
 	public boolean hasStrongType() {
72
 		return true;
73
 		return true;
73
 	}
74
 	}
75
+
76
+	@Override
77
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
78
+		return type.compile(scope);
79
+	}
74
 }
80
 }

+ 14
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java View File

14
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17
 
18
 
18
 /**
19
 /**
19
  *
20
  *
52
 	public boolean hasStrongType() {
53
 	public boolean hasStrongType() {
53
 		return left.hasStrongType();
54
 		return left.hasStrongType();
54
 	}
55
 	}
56
+
57
+	@Override
58
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
59
+		ITypeID leftType = left.precompileForType(scope, state);
60
+		if (leftType == null)
61
+			return null;
62
+		
63
+		ITypeID resultType = leftType.getOptionalBase();
64
+		ITypeID rightType = right.precompileForType(scope.withHint(resultType), state);
65
+		
66
+		TypeMembers resultTypeMembers = scope.getTypeMembers(resultType);
67
+		return resultTypeMembers.union(rightType);
68
+	}
55
 }
69
 }

+ 8
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCompare.java View File

11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
+import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.parser.PrecompilationState;
14
 
17
 
15
 /**
18
 /**
16
  *
19
  *
44
 	public boolean hasStrongType() {
47
 	public boolean hasStrongType() {
45
 		return true;
48
 		return true;
46
 	}
49
 	}
50
+
51
+	@Override
52
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
53
+		return BasicTypeID.BOOL;
54
+	}
47
 }
55
 }

+ 11
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionConditional.java View File

16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
+import org.openzen.zenscript.parser.PrecompilationState;
19
 
20
 
20
 /**
21
 /**
21
  *
22
  *
72
 	public boolean hasStrongType() {
73
 	public boolean hasStrongType() {
73
 		return ifThen.hasStrongType() && ifElse.hasStrongType();
74
 		return ifThen.hasStrongType() && ifElse.hasStrongType();
74
 	}
75
 	}
76
+
77
+	@Override
78
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
79
+		ITypeID thenType = ifThen.precompileForType(scope, state);
80
+		ITypeID elseType = ifElse.precompileForType(scope, state);
81
+		if (thenType == null || elseType == null)
82
+			return null;
83
+		
84
+		return scope.getTypeMembers(thenType).union(elseType);
85
+	}
75
 }
86
 }

+ 13
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFloat.java View File

14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17
 
18
 
18
 /**
19
 /**
19
  *
20
  *
55
 	public boolean hasStrongType() {
56
 	public boolean hasStrongType() {
56
 		return false;
57
 		return false;
57
 	}
58
 	}
59
+
60
+	@Override
61
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
62
+		for (ITypeID hint : scope.hints) {
63
+			if (hint == BasicTypeID.DOUBLE)
64
+				return hint;
65
+			else if (hint == BasicTypeID.FLOAT)
66
+				return hint;
67
+		}
68
+		
69
+		return BasicTypeID.DOUBLE;
70
+	}
58
 }
71
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java View File

24
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
24
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25
 import org.openzen.zenscript.codemodel.scope.LambdaScope;
25
 import org.openzen.zenscript.codemodel.scope.LambdaScope;
26
 import org.openzen.zenscript.codemodel.scope.StatementScope;
26
 import org.openzen.zenscript.codemodel.scope.StatementScope;
27
+import org.openzen.zenscript.parser.PrecompilationState;
27
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
28
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
28
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
29
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
29
 
30
 
96
 	public boolean hasStrongType() {
97
 	public boolean hasStrongType() {
97
 		return false;
98
 		return false;
98
 	}
99
 	}
100
+
101
+	@Override
102
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
103
+		return null; // TODO: meh...
104
+	}
99
 }
105
 }

+ 25
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java View File

12
 import org.openzen.zenscript.codemodel.OperatorType;
12
 import org.openzen.zenscript.codemodel.OperatorType;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.scope.TypeScope;
17
 import org.openzen.zenscript.codemodel.scope.TypeScope;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
20
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
20
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
21
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
22
+import org.openzen.zenscript.parser.PrecompilationState;
21
 
23
 
22
 /**
24
 /**
23
  *
25
  *
43
 	public boolean hasStrongType() {
45
 	public boolean hasStrongType() {
44
 		return true;
46
 		return true;
45
 	}
47
 	}
48
+
49
+	@Override
50
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
51
+		ITypeID target = value.precompileForType(scope, state);
52
+		if (target == null)
53
+			return null;
54
+		
55
+		DefinitionMemberGroup members = scope.getTypeMembers(target).getOrCreateGroup(OperatorType.INDEXGET);
56
+		List<ITypeID>[] predicted = members.predictCallTypes(scope, scope.getResultTypeHints(), indexes.size());
57
+		
58
+		ITypeID[] indexTypes = new ITypeID[indexes.size()];
59
+		for (int i = 0; i < indexTypes.length; i++) {
60
+			indexTypes[i] = indexes.get(i).precompileForType(scope.withHints(predicted[i]), state);
61
+			if (indexTypes[i] == null)
62
+				return null;
63
+		}
64
+		
65
+		FunctionalMemberRef method = members.selectMethod(position, scope, new CallArguments(indexTypes), true, false);
66
+		if (!state.precompile(method.getTarget()))
67
+			return null;
68
+		
69
+		return method.getTarget().header.returnType; // TODO: this will not work properly for methods with type parameters
70
+	}
46
 	
71
 	
47
 	private class PartialIndexedExpression implements IPartialExpression {
72
 	private class PartialIndexedExpression implements IPartialExpression {
48
 		private final ExpressionScope scope;
73
 		private final ExpressionScope scope;

+ 27
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java View File

23
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
23
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
24
 import org.openzen.zenscript.codemodel.type.ITypeID;
24
 import org.openzen.zenscript.codemodel.type.ITypeID;
25
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
26
+import org.openzen.zenscript.parser.PrecompilationState;
26
 
27
 
27
 /**
28
 /**
28
  *
29
  *
83
 	public boolean hasStrongType() {
84
 	public boolean hasStrongType() {
84
 		return false;
85
 		return false;
85
 	}
86
 	}
87
+
88
+	@Override
89
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
90
+		for (ITypeID hint : scope.hints) {
91
+			if (hint instanceof BasicTypeID) {
92
+				switch ((BasicTypeID) hint) {
93
+					case SBYTE:
94
+					case BYTE:
95
+					case SHORT:
96
+					case USHORT:
97
+					case INT:
98
+					case UINT:
99
+					case LONG:
100
+					case ULONG:
101
+					case CHAR:
102
+						return hint;
103
+					default:
104
+				}
105
+			}
106
+		}
107
+		
108
+		if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE)
109
+			return BasicTypeID.INT;
110
+		else
111
+			return BasicTypeID.LONG;
112
+	}
86
 }
113
 }

+ 7
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIs.java View File

11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
+import org.openzen.zenscript.parser.PrecompilationState;
14
 import org.openzen.zenscript.parser.type.IParsedType;
16
 import org.openzen.zenscript.parser.type.IParsedType;
15
 
17
 
16
 /**
18
 /**
39
 	public boolean hasStrongType() {
41
 	public boolean hasStrongType() {
40
 		return true;
42
 		return true;
41
 	}
43
 	}
44
+
45
+	@Override
46
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
47
+		return BasicTypeID.BOOL;
48
+	}
42
 }
49
 }

+ 11
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java View File

19
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
19
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
20
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
21
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
21
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
22
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
23
 import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
22
 import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
24
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
 import org.openzen.zenscript.codemodel.type.ITypeID;
25
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
24
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25
+import org.openzen.zenscript.parser.PrecompilationState;
26
 
26
 
27
 /**
27
 /**
28
  *
28
  *
75
 				return new NewExpression(position, assocHint, constructor, CallArguments.EMPTY);
75
 				return new NewExpression(position, assocHint, constructor, CallArguments.EMPTY);
76
 		}
76
 		}
77
 		
77
 		
78
-		if (!hasAssocHint && scope.hints.size() == 1 && scope.hints.get(0) != BasicTypeID.ANY) {
78
+		if (!hasAssocHint && scope.hints.size() == 1) {
79
 			// compile as constructor call
79
 			// compile as constructor call
80
 			ITypeID hint = scope.hints.get(0);
80
 			ITypeID hint = scope.hints.get(0);
81
 			for (int i = 0; i < keys.size(); i++) {
81
 			for (int i = 0; i < keys.size(); i++) {
109
 			}
109
 			}
110
 		}
110
 		}
111
 		if (keyType == null)
111
 		if (keyType == null)
112
-			keyType = BasicTypeID.ANY;
112
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
113
+		
113
 		for (int i = 0; i < cKeys.length; i++)
114
 		for (int i = 0; i < cKeys.length; i++)
114
 			cKeys[i] = cKeys[i].castImplicit(position, scope, keyType);
115
 			cKeys[i] = cKeys[i].castImplicit(position, scope, keyType);
115
 		
116
 		
125
 			}
126
 			}
126
 		}
127
 		}
127
 		if (valueType == null)
128
 		if (valueType == null)
128
-			valueType = BasicTypeID.ANY;
129
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
130
+		
129
 		for (int i = 0; i < cValues.length; i++)
131
 		for (int i = 0; i < cValues.length; i++)
130
 			cValues[i] = cValues[i].castImplicit(position, scope, valueType);
132
 			cValues[i] = cValues[i].castImplicit(position, scope, valueType);
131
 		
133
 		
137
 	public boolean hasStrongType() {
139
 	public boolean hasStrongType() {
138
 		return false;
140
 		return false;
139
 	}
141
 	}
142
+
143
+	@Override
144
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
145
+		return null; // TODO: fill this later
146
+	}
140
 }
147
 }

+ 17
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java View File

14
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17
 import org.openzen.zenscript.parser.type.IParsedType;
18
 import org.openzen.zenscript.parser.type.IParsedType;
18
 
19
 
19
 /**
20
 /**
51
 	public boolean hasStrongType() {
52
 	public boolean hasStrongType() {
52
 		return true;
53
 		return true;
53
 	}
54
 	}
55
+
56
+	@Override
57
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
58
+		IPartialExpression cValue = value.compile(scope.withoutHints());
59
+		ITypeID[] typeParameters = IParsedType.compileList(genericParameters, scope);
60
+		// TODO: proper precompilation
61
+		IPartialExpression member = cValue.getMember(
62
+				position,
63
+				scope,
64
+				scope.hints,
65
+				new GenericName(this.member, typeParameters));
66
+		if (member == null)
67
+			return null;
68
+		
69
+		return member.eval().type;
70
+	}
54
 }
71
 }

+ 8
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionNull.java View File

10
 import org.openzen.zenscript.codemodel.expression.NullExpression;
10
 import org.openzen.zenscript.codemodel.expression.NullExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
+import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.parser.PrecompilationState;
13
 
16
 
14
 /**
17
 /**
15
  *
18
  *
29
 	public boolean hasStrongType() {
32
 	public boolean hasStrongType() {
30
 		return false;
33
 		return false;
31
 	}
34
 	}
35
+
36
+	@Override
37
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
38
+		return BasicTypeID.BOOL;
39
+	}
32
 }
40
 }

+ 7
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOpAssign.java View File

14
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
14
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.codemodel.type.ITypeID;
18
+import org.openzen.zenscript.parser.PrecompilationState;
17
 
19
 
18
 /**
20
 /**
19
  *
21
  *
52
 	public boolean hasStrongType() {
54
 	public boolean hasStrongType() {
53
 		return right.hasStrongType();
55
 		return right.hasStrongType();
54
 	}
56
 	}
57
+
58
+	@Override
59
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
60
+		return left.precompileForType(scope, state);
61
+	}
55
 }
62
 }

+ 12
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOrOr.java View File

12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.parser.PrecompilationState;
15
 
17
 
16
 /**
18
 /**
17
  *
19
  *
39
 	public boolean hasStrongType() {
41
 	public boolean hasStrongType() {
40
 		return left.hasStrongType() && right.hasStrongType();
42
 		return left.hasStrongType() && right.hasStrongType();
41
 	}
43
 	}
44
+
45
+	@Override
46
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
47
+		ITypeID leftType = left.precompileForType(scope, state);
48
+		ITypeID rightType = right.precompileForType(scope, state);
49
+		if (leftType == null || rightType == null)
50
+			return null;
51
+		
52
+		return scope.getTypeMembers(leftType).union(rightType);
53
+	}
42
 }
54
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOuter.java View File

12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.parser.PrecompilationState;
15
 
16
 
16
 /**
17
 /**
17
  *
18
  *
39
 	public boolean hasStrongType() {
40
 	public boolean hasStrongType() {
40
 		return value.hasStrongType();
41
 		return value.hasStrongType();
41
 	}
42
 	}
43
+
44
+	@Override
45
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
46
+		return null; // TODO: how will this be handled?
47
+	}
42
 }
48
 }

+ 7
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java View File

11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
+import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.parser.PrecompilationState;
14
 
16
 
15
 /**
17
 /**
16
  *
18
  *
37
 	public boolean hasStrongType() {
39
 	public boolean hasStrongType() {
38
 		return value.hasStrongType();
40
 		return value.hasStrongType();
39
 	}
41
 	}
42
+
43
+	@Override
44
+	public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
45
+		return value.precompileForType(scope, state);
46
+	}
40
 }
47
 }

+ 0
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.java View File


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

Loading…
Cancel
Save