Selaa lähdekoodia

- 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 vuotta sitten
vanhempi
commit
b1545a872d
100 muutettua tiedostoa jossa 1007 lisäystä ja 96 poistoa
  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 Näytä tiedosto

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

+ 80
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Näytä tiedosto

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel;
7 7
 
8
+import java.util.Arrays;
9
+import java.util.Collections;
8 10
 import java.util.HashMap;
9 11
 import java.util.List;
10 12
 import java.util.Map;
@@ -15,6 +17,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
15 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
17 19
 import org.openzen.zenscript.codemodel.scope.TypeScope;
20
+import org.openzen.zenscript.codemodel.type.GenericTypeID;
18 21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
19 22
 
20 23
 /**
@@ -31,6 +34,7 @@ public class FunctionHeader {
31 34
 	
32 35
 	public final int minParameters;
33 36
 	public final int maxParameters;
37
+	public final boolean hasUnknowns;
34 38
 	
35 39
 	public FunctionHeader(ITypeID returnType) {
36 40
 		if (returnType == null)
@@ -43,6 +47,7 @@ public class FunctionHeader {
43 47
 		
44 48
 		minParameters = 0;
45 49
 		maxParameters = 0;
50
+		hasUnknowns = returnType == BasicTypeID.UNDETERMINED;
46 51
 	}
47 52
 	
48 53
 	public FunctionHeader(ITypeID returnType, ITypeID... parameterTypes) {
@@ -59,6 +64,7 @@ public class FunctionHeader {
59 64
 		
60 65
 		minParameters = parameterTypes.length;
61 66
 		maxParameters = parameterTypes.length;
67
+		hasUnknowns = hasUnknowns(parameterTypes);
62 68
 	}
63 69
 	
64 70
 	public FunctionHeader(ITypeID returnType, FunctionParameter... parameters) {
@@ -72,6 +78,7 @@ public class FunctionHeader {
72 78
 		
73 79
 		minParameters = getMinParameters(parameters);
74 80
 		maxParameters = getMaxParameters(parameters);
81
+		hasUnknowns = hasUnknowns(parameters);
75 82
 	}
76 83
 	
77 84
 	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
@@ -87,12 +94,50 @@ public class FunctionHeader {
87 94
 		
88 95
 		minParameters = getMinParameters(parameters);
89 96
 		maxParameters = getMaxParameters(parameters);
97
+		hasUnknowns = hasUnknowns(parameters);
90 98
 	}
91 99
 	
92 100
 	public int getNumberOfTypeParameters() {
93 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 141
 	public boolean matchesExactly(CallArguments arguments, TypeScope scope) {
97 142
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
98 143
 			return false;
@@ -211,6 +256,25 @@ public class FunctionHeader {
211 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 279
 	 * Checks if two function headers are equivalent. Functions headers are
216 280
 	 * equivalent if their types are the same.
@@ -361,4 +425,20 @@ public class FunctionHeader {
361 425
 		
362 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 Näytä tiedosto

@@ -73,4 +73,8 @@ public class Modifiers {
73 73
 	public static boolean isExtern(int modifiers) {
74 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 Näytä tiedosto

@@ -32,6 +32,8 @@ import org.openzen.zenscript.codemodel.member.MethodMember;
32 32
 import org.openzen.zenscript.codemodel.member.OperatorMember;
33 33
 import org.openzen.zenscript.codemodel.member.SetterMember;
34 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 37
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
36 38
 import org.openzen.zenscript.codemodel.scope.FileScope;
37 39
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
@@ -187,7 +189,11 @@ public class AnnotationProcessor implements ModuleProcessor {
187 189
 		@Override
188 190
 		public Void visitStaticInitializer(StaticInitializerMember member) {
189 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 197
 			return null;
192 198
 		}
193 199
 		
@@ -195,8 +201,8 @@ public class AnnotationProcessor implements ModuleProcessor {
195 201
 			for (MemberAnnotation annotation : member.annotations)
196 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 208
 			if (member.body == null)
@@ -207,12 +213,12 @@ public class AnnotationProcessor implements ModuleProcessor {
207 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 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 Näytä tiedosto

@@ -18,20 +18,19 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
18 18
  * @author Hoofdgebruiker
19 19
  */
20 20
 public class CallArguments {
21
-	public static final ITypeID[] NO_TYPE_ARGUMENTS = new ITypeID[0];
22 21
 	public static final CallArguments EMPTY = new CallArguments(new Expression[0]);
23 22
 	
24 23
 	public final ITypeID[] typeArguments;
25 24
 	public final Expression[] arguments;
26 25
 	
27 26
 	public CallArguments(Expression... arguments) {
28
-		this.typeArguments = NO_TYPE_ARGUMENTS;
27
+		this.typeArguments = ITypeID.NONE;
29 28
 		this.arguments = arguments;
30 29
 	}
31 30
 	
32 31
 	public CallArguments(ITypeID[] typeArguments, Expression[] arguments) {
33 32
 		if (typeArguments == null)
34
-			typeArguments = NO_TYPE_ARGUMENTS;
33
+			typeArguments = ITypeID.NONE;
35 34
 		if (arguments == null)
36 35
 			throw new IllegalArgumentException("Arguments cannot be null!");
37 36
 		
@@ -39,6 +38,13 @@ public class CallArguments {
39 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 48
 	public int getNumberOfTypeArguments() {
43 49
 		return typeArguments.length;
44 50
 	}

+ 10
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java Näytä tiedosto

@@ -81,6 +81,16 @@ public abstract class Expression implements IPartialExpression {
81 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 94
 	@Override
85 95
 	public List<ITypeID>[] predictCallTypes(TypeScope scope, List<ITypeID> hints, int arguments) {
86 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 Näytä tiedosto

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThrowExpression.java Näytä tiedosto

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

+ 16
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java Näytä tiedosto

@@ -9,6 +9,9 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.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 15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
13 16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14 17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -18,6 +21,8 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18 21
  * @author Hoofdgebruiker
19 22
  */
20 23
 public class CallerMember extends FunctionalMember {
24
+	public FunctionalMemberRef overrides;
25
+	
21 26
 	public CallerMember(
22 27
 			CodePosition position,
23 28
 			HighLevelDefinition definition,
@@ -25,7 +30,7 @@ public class CallerMember extends FunctionalMember {
25 30
 			FunctionHeader header,
26 31
 			BuiltinID builtin)
27 32
 	{
28
-		super(position, definition, modifiers, "()", header, builtin);
33
+		super(position, definition, modifiers, header, builtin);
29 34
 	}
30 35
 	
31 36
 	@Override
@@ -52,4 +57,14 @@ public class CallerMember extends FunctionalMember {
52 57
 	public <T> T accept(MemberVisitor<T> visitor) {
53 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.Modifiers;
13 13
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14 15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
@@ -22,6 +23,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
22 23
  */
23 24
 public class CasterMember extends FunctionalMember {
24 25
 	public final ITypeID toType;
26
+	public CasterMemberRef overrides;
25 27
 	
26 28
 	public CasterMember(
27 29
 			CodePosition position,
@@ -30,7 +32,7 @@ public class CasterMember extends FunctionalMember {
30 32
 			ITypeID toType,
31 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 37
 		this.toType = toType;
36 38
 	}
@@ -67,4 +69,13 @@ public class CasterMember extends FunctionalMember {
67 69
 	public <T> T accept(MemberVisitor<T> visitor) {
68 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 Näytä tiedosto

@@ -10,6 +10,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
10 10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
13
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13 14
 import org.openzen.zenscript.codemodel.type.ITypeID;
14 15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15 16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
@@ -21,7 +22,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
21 22
  */
22 23
 public class ConstMember extends DefinitionMember {
23 24
 	public final String name;
24
-	public final ITypeID type;
25
+	public ITypeID type;
25 26
 	public Expression value;
26 27
 	public final BuiltinID builtin;
27 28
 	
@@ -52,4 +53,9 @@ public class ConstMember extends DefinitionMember {
52 53
 	public <T> T accept(MemberVisitor<T> visitor) {
53 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
13 13
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14 15
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
15 16
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
16 17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -34,7 +35,6 @@ public class ConstructorMember extends FunctionalMember {
34 35
 				position,
35 36
 				definition,
36 37
 				modifiers,
37
-				"this",
38 38
 				new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.thrownType, header.parameters),
39 39
 				builtin);
40 40
 	}
@@ -79,4 +79,9 @@ public class ConstructorMember extends FunctionalMember {
79 79
 	public <T> T accept(MemberVisitor<T> visitor) {
80 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 Näytä tiedosto

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.GenericMapper;
10 10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11 11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12 13
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
13 14
 import org.openzen.zenscript.codemodel.statement.Statement;
14 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -23,6 +24,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
23 24
 public class CustomIteratorMember extends DefinitionMember implements IIteratorMember {
24 25
 	private final ITypeID[] iteratorTypes;
25 26
 	public Statement body;
27
+	public IteratorMemberRef overrides;
26 28
 	
27 29
 	public CustomIteratorMember(CodePosition position, HighLevelDefinition definition, int modifiers, ITypeID[] iteratorTypes) {
28 30
 		super(position, definition, modifiers);
@@ -68,4 +70,13 @@ public class CustomIteratorMember extends DefinitionMember implements IIteratorM
68 70
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
69 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 Näytä tiedosto

@@ -18,7 +18,7 @@ import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
18 18
 public abstract class DefinitionMember extends Taggable implements IDefinitionMember {
19 19
 	public final CodePosition position;
20 20
 	public final HighLevelDefinition definition;
21
-	public final int modifiers;
21
+	public int modifiers;
22 22
 	public MemberAnnotation[] annotations = MemberAnnotation.NONE;
23 23
 	
24 24
 	public DefinitionMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
@@ -47,4 +47,12 @@ public abstract class DefinitionMember extends Taggable implements IDefinitionMe
47 47
 	public boolean isPrivate() {
48 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 Näytä tiedosto

@@ -9,6 +9,8 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
12 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13 15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14 16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -19,9 +21,10 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
19 21
  */
20 22
 public class DestructorMember extends FunctionalMember {
21 23
 	private static final FunctionHeader HEADER = new FunctionHeader(BasicTypeID.VOID);
24
+	public FunctionalMemberRef overrides;
22 25
 	
23 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 30
 	@Override
@@ -49,4 +52,9 @@ public class DestructorMember extends FunctionalMember {
49 52
 	public <T> T accept(MemberVisitor<T> visitor) {
50 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 Näytä tiedosto

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
13 13
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
15 15
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
16
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
16 17
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
17 18
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
18 19
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
@@ -29,7 +30,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
29 30
  */
30 31
 public class FieldMember extends DefinitionMember {
31 32
 	public final String name;
32
-	public final ITypeID type;
33
+	public ITypeID type;
33 34
 	public Expression initializer;
34 35
 	public final int autoGetterAccess;
35 36
 	public final int autoSetterAccess;
@@ -138,4 +139,9 @@ public class FieldMember extends DefinitionMember {
138 139
 	public <T> T accept(MemberVisitor<T> visitor) {
139 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 Näytä tiedosto

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

+ 17
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java Näytä tiedosto

@@ -9,7 +9,9 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12 13
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
13 15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
14 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
15 17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
@@ -21,7 +23,8 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
21 23
  */
22 24
 public class GetterMember extends FunctionalMember {
23 25
 	public final String name;
24
-	public final ITypeID type;
26
+	public ITypeID type;
27
+	private GetterMemberRef overrides;
25 28
 	
26 29
 	public GetterMember(
27 30
 			CodePosition position,
@@ -30,7 +33,7 @@ public class GetterMember extends FunctionalMember {
30 33
 			String name,
31 34
 			ITypeID type,
32 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 38
 		this.name = name;
36 39
 		this.type = type;
@@ -60,4 +63,16 @@ public class GetterMember extends FunctionalMember {
60 63
 	public <T> T accept(MemberVisitor<T> visitor) {
61 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 Näytä tiedosto

@@ -6,7 +6,9 @@
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
10 12
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
11 13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
12 14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -31,4 +33,6 @@ public interface IDefinitionMember {
31 33
 	public <T> void setTag(Class<T> tag, T value);
32 34
 
33 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 Näytä tiedosto

@@ -10,6 +10,7 @@ import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.GenericMapper;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13 14
 import org.openzen.zenscript.codemodel.member.ref.ImplementationMemberRef;
14 15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -57,4 +58,9 @@ public class ImplementationMember extends DefinitionMember {
57 58
 	public <T> T accept(MemberVisitor<T> visitor) {
58 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 Näytä tiedosto

@@ -8,6 +8,7 @@ package org.openzen.zenscript.codemodel.member;
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.GenericMapper;
10 10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
11 12
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
12 13
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
13 14
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -48,4 +49,9 @@ public class InnerDefinitionMember extends DefinitionMember {
48 49
 	public <T> T accept(MemberVisitor<T> visitor) {
49 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 Näytä tiedosto

@@ -9,6 +9,9 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.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 15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
13 16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14 17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -18,8 +21,13 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18 21
  * @author Hoofdgebruiker
19 22
  */
20 23
 public class MethodMember extends FunctionalMember {
24
+	public final String name;
25
+	private FunctionalMemberRef overrides;
26
+	
21 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 33
 	@Override
@@ -46,4 +54,19 @@ public class MethodMember extends FunctionalMember {
46 54
 	public <T> T accept(MemberVisitor<T> visitor) {
47 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 Näytä tiedosto

@@ -10,6 +10,8 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.OperatorType;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 15
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
14 16
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
15 17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -20,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
20 22
  */
21 23
 public class OperatorMember extends FunctionalMember {
22 24
 	public final OperatorType operator;
25
+	private FunctionalMemberRef overrides;
23 26
 	
24 27
 	public OperatorMember(
25 28
 			CodePosition position,
@@ -29,7 +32,7 @@ public class OperatorMember extends FunctionalMember {
29 32
 			FunctionHeader header,
30 33
 			BuiltinID builtin)
31 34
 	{
32
-		super(position, definition, modifiers, operator.operator, header, builtin);
35
+		super(position, definition, modifiers, header, builtin);
33 36
 		
34 37
 		this.operator = operator;
35 38
 	}
@@ -58,4 +61,14 @@ public class OperatorMember extends FunctionalMember {
58 61
 	public <T> T accept(MemberVisitor<T> visitor) {
59 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 Näytä tiedosto

@@ -22,7 +22,9 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
22 22
  * @author Hoofdgebruiker
23 23
  */
24 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 29
 	public SetterMember(
28 30
 			CodePosition position,
@@ -35,11 +37,11 @@ public class SetterMember extends FunctionalMember {
35 37
 		super(position,
36 38
 				definition,
37 39
 				modifiers,
38
-				name,
39 40
 				new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(type, "$")),
40 41
 				builtin);
41 42
 		
42 43
 		this.type = type;
44
+		this.name = name;
43 45
 	}
44 46
 	
45 47
 	@Override
@@ -66,4 +68,16 @@ public class SetterMember extends FunctionalMember {
66 68
 	public <T> T accept(MemberVisitor<T> visitor) {
67 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 Näytä tiedosto

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zencode.shared.Taggable;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12 13
 import org.openzen.zenscript.codemodel.statement.Statement;
13 14
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
14 15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
@@ -51,4 +52,9 @@ public class StaticInitializerMember extends Taggable implements IDefinitionMemb
51 52
 	public <T> T accept(MemberVisitor<T> visitor) {
52 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12 12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13 13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14 15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15 16
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -75,4 +76,9 @@ public class ArrayIteratorKeyValues extends Taggable implements IIteratorMember
75 76
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
76 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12 12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13 13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14 15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15 16
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -70,4 +71,9 @@ public class ArrayIteratorValues extends Taggable implements IIteratorMember {
70 71
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
71 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12 12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13 13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14 15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15 16
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -73,4 +74,9 @@ public class AssocIterator extends Taggable implements IIteratorMember {
73 74
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
74 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12 12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13 13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14 15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15 16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -81,4 +82,9 @@ public class RangeIterator extends Taggable implements IIteratorMember {
81 82
 	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
82 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 Näytä tiedosto

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
12 12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
13 13
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14 15
 import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
15 16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -64,4 +65,9 @@ public class StringCharIterator extends Taggable implements IIteratorMember {
64 65
 	public <T> T accept(MemberVisitor<T> visitor) {
65 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 Näytä tiedosto

@@ -6,7 +6,9 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9 10
 import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
10 12
 import org.openzen.zenscript.codemodel.expression.CastExpression;
11 13
 import org.openzen.zenscript.codemodel.expression.Expression;
12 14
 import org.openzen.zenscript.codemodel.member.CasterMember;
@@ -47,4 +49,19 @@ public class CasterMemberRef implements DefinitionMemberRef {
47 49
 	public boolean isImplicit() {
48 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 Näytä tiedosto

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9 11
 import org.openzen.zenscript.codemodel.member.ConstMember;
10 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 13
 
@@ -36,4 +38,19 @@ public class ConstMemberRef implements DefinitionMemberRef {
36 38
 	public <T> T getTag(Class<T> type) {
37 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 Näytä tiedosto

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 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,4 +19,10 @@ public interface DefinitionMemberRef {
17 19
 	String describe();
18 20
 	
19 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 Näytä tiedosto

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9 11
 import org.openzen.zenscript.codemodel.member.FieldMember;
10 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 13
 
@@ -44,4 +46,19 @@ public class FieldMemberRef implements DefinitionMemberRef {
44 46
 	public boolean isFinal() {
45 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 Näytä tiedosto

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.CompareType;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.OperatorType;
12
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12 13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13 14
 import org.openzen.zenscript.codemodel.expression.CallExpression;
14 15
 import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
@@ -40,6 +41,10 @@ public class FunctionalMemberRef implements DefinitionMemberRef {
40 41
 		return target.position;
41 42
 	}
42 43
 	
44
+	public FunctionalMember getTarget() {
45
+		return target;
46
+	}
47
+	
43 48
 	public String getCanonicalName() {
44 49
 		return target.getCanonicalName();
45 50
 	}
@@ -49,10 +54,26 @@ public class FunctionalMemberRef implements DefinitionMemberRef {
49 54
 		return target.describe();
50 55
 	}
51 56
 	
57
+	@Override
52 58
 	public <T> T getTag(Class<T> cls) {
53 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 77
 	public BuiltinID getBuiltin() {
57 78
 		return target.builtin;
58 79
 	}

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/GetterMemberRef.java Näytä tiedosto

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9 11
 import org.openzen.zenscript.codemodel.expression.Expression;
10 12
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
11 13
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
@@ -51,4 +53,19 @@ public class GetterMemberRef implements DefinitionMemberRef {
51 53
 	public Expression getStatic(CodePosition position) {
52 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 Näytä tiedosto

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9 11
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
10 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 13
 
@@ -36,4 +38,19 @@ public class ImplementationMemberRef implements DefinitionMemberRef {
36 38
 	public <T> T getTag(Class<T> type) {
37 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 Näytä tiedosto

@@ -6,6 +6,9 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 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 12
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
10 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 14
 
@@ -40,4 +43,23 @@ public class IteratorMemberRef implements DefinitionMemberRef {
40 43
 	public int getLoopVariableCount() {
41 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 Näytä tiedosto

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9 11
 import org.openzen.zenscript.codemodel.member.SetterMember;
10 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 13
 
@@ -40,4 +42,19 @@ public class SetterMemberRef implements DefinitionMemberRef {
40 42
 	public boolean isStatic() {
41 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 Näytä tiedosto

@@ -23,8 +23,6 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
23 23
  * @author Hoofdgebruiker
24 24
  */
25 25
 public abstract class BaseScope implements TypeScope {
26
-	public abstract LocalMemberCache getMemberCache();
27
-	
28 26
 	public abstract IPartialExpression get(CodePosition position, GenericName name);
29 27
 	
30 28
 	public abstract ITypeID getType(CodePosition position, List<GenericName> name);

+ 7
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java Näytä tiedosto

@@ -16,11 +16,15 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16 16
  * @author Hoofdgebruiker
17 17
  */
18 18
 public interface TypeScope {
19
-	public GlobalTypeRegistry getTypeRegistry();
20
-	
21 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 29
 	public AnnotationDefinition getAnnotation(String name);
26 30
 }

+ 1
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java Näytä tiedosto

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

+ 24
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java Näytä tiedosto

@@ -27,6 +27,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
27 27
 import org.openzen.zenscript.codemodel.GenericMapper;
28 28
 import org.openzen.zenscript.codemodel.expression.ConstExpression;
29 29
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
30
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
30 31
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
31 32
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
32 33
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
@@ -84,6 +85,14 @@ public class DefinitionMemberGroup {
84 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 96
 	public boolean hasMethods() {
88 97
 		return !methods.isEmpty();
89 98
 	}
@@ -350,4 +359,19 @@ public class DefinitionMemberGroup {
350 359
 		
351 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 Näytä tiedosto

@@ -23,7 +23,10 @@ import org.openzen.zenscript.codemodel.expression.NullExpression;
23 23
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
24 24
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
25 25
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
26
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
26 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 30
 import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
28 31
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
29 32
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
@@ -306,7 +309,7 @@ public final class TypeMembers {
306 309
 	
307 310
 	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) {
308 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 315
 	public Expression ternary(CodePosition position, TypeScope scope, OperatorType operator, Expression a, Expression b, Expression c) {
@@ -335,8 +338,6 @@ public final class TypeMembers {
335 338
 			return true;
336 339
 		if (toType == null)
337 340
 			throw new NullPointerException();
338
-		if (type == BasicTypeID.ANY || toType == BasicTypeID.ANY || toType == BasicTypeID.UNDETERMINED)
339
-			return true;
340 341
 		
341 342
 		if (type == BasicTypeID.NULL && toType.isOptional())
342 343
 			return true;
@@ -347,12 +348,25 @@ public final class TypeMembers {
347 348
 		if (type.isOptional() && type.unwrap() == toType)
348 349
 			return true;
349 350
 		
351
+		return getImplicitCaster(toType) != null || extendsOrImplements(toType);
352
+	}
353
+	
354
+	public CasterMemberRef getImplicitCaster(ITypeID toType) {
350 355
 		for (TypeMember<CasterMemberRef> caster : casters) {
351 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 372
 	public boolean canCast(ITypeID toType) {

+ 1
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java Näytä tiedosto

@@ -98,7 +98,7 @@ public class SemanticModule {
98 98
 		if (state != State.NORMALIZED)
99 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 102
 		for (ScriptBlock script : scripts) {
103 103
 			validator.validate(script);
104 104
 		}

+ 3
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java Näytä tiedosto

@@ -130,6 +130,9 @@ public class Module {
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 136
 		if (failed)
134 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 Näytä tiedosto

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

+ 0
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java Näytä tiedosto

@@ -36,8 +36,6 @@ public class JavaOptionalTypeClassVisitor implements ITypeVisitor<Class> {
36 36
 				return void.class;
37 37
 			case NULL:
38 38
 				return Object.class;
39
-			case ANY:
40
-				return Object.class; // TODO
41 39
 			case BOOL:
42 40
 				return Boolean.class;
43 41
 			case BYTE:

+ 0
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java Näytä tiedosto

@@ -16,7 +16,6 @@ public class JavaTypeClassVisitor implements ITypeVisitor<Class> {
16 16
         switch (basic) {
17 17
             case VOID:
18 18
                 return void.class;
19
-            case ANY:
20 19
             case NULL:
21 20
             case UNDETERMINED:
22 21
                 return Object.class;

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java Näytä tiedosto

@@ -68,6 +68,12 @@ public abstract class BaseMemberCompiler implements MemberVisitor<Void> {
68 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 77
 	protected void modifiers(int modifiers) {
72 78
 		if (Modifiers.isPublic(modifiers))
73 79
 			output.append("public ");

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java Näytä tiedosto

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

+ 25
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Näytä tiedosto

@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.member.DefinitionMember;
20 20
 import org.openzen.zenscript.codemodel.member.DestructorMember;
21 21
 import org.openzen.zenscript.codemodel.member.FieldMember;
22 22
 import org.openzen.zenscript.codemodel.member.GetterMember;
23
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
23 24
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
24 25
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
25 26
 import org.openzen.zenscript.codemodel.member.MethodMember;
@@ -30,6 +31,7 @@ import org.openzen.zenscript.codemodel.statement.EmptyStatement;
30 31
 import org.openzen.zenscript.codemodel.statement.Statement;
31 32
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32 33
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
34
+import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
33 35
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
34 36
 
35 37
 /**
@@ -67,6 +69,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
67 69
 			
68 70
 		
69 71
 		begin(ElementType.METHOD);
72
+		override(member.getOverrides() != null);
70 73
 		output.append(indent);
71 74
 		if (isInterface && hasBody)
72 75
 			output.append("default ");
@@ -196,7 +199,28 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
196 199
 
197 200
 	@Override
198 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 224
 		return null;
201 225
 	}
202 226
 

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java Näytä tiedosto

@@ -20,7 +20,6 @@ public class JavaSourceObjectTypeVisitor extends JavaSourceTypeVisitor {
20 20
 	public String visitBasic(BasicTypeID basic) {
21 21
 		switch (basic) {
22 22
 			case VOID: return "Void";
23
-			case ANY: return "Any";
24 23
 			case BOOL: return "Boolean";
25 24
 			case BYTE: return "Byte";
26 25
 			case SBYTE: return "Byte";

+ 2
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java Näytä tiedosto

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

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeNameVisitor.java Näytä tiedosto

@@ -29,7 +29,6 @@ public class JavaSourceTypeNameVisitor implements ITypeVisitor<String> {
29 29
 	@Override
30 30
 	public String visitBasic(BasicTypeID basic) {
31 31
 		switch (basic) {
32
-			case ANY: return "Any";
33 32
 			case VOID: return "Void";
34 33
 			case BOOL: return "Bool";
35 34
 			case BYTE: return "Byte";

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java Näytä tiedosto

@@ -56,7 +56,6 @@ public class JavaSourceTypeVisitor implements ITypeVisitor<String>, GenericParam
56 56
 	public String visitBasic(BasicTypeID basic) {
57 57
 		switch (basic) {
58 58
 			case VOID: return "void";
59
-			case ANY: return "Any";
60 59
 			case BOOL: return "boolean";
61 60
 			case BYTE: return "byte";
62 61
 			case SBYTE: return "byte";

+ 19
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java Näytä tiedosto

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.member.DefinitionMember;
17 17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
18 18
 import org.openzen.zenscript.codemodel.member.FieldMember;
19 19
 import org.openzen.zenscript.codemodel.member.GetterMember;
20
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20 21
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21 22
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22 23
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
@@ -27,6 +28,7 @@ import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
27 28
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28 29
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29 30
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
31
+import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
30 32
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
31 33
 
32 34
 /**
@@ -64,7 +66,7 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
64 66
 
65 67
 	@Override
66 68
 	public Void visitConstructor(ConstructorMember member) {
67
-		visitFunctional(member, member.name);
69
+		visitFunctional(member, "<init>");
68 70
 		return null;
69 71
 	}
70 72
 
@@ -118,10 +120,25 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
118 120
 
119 121
 	@Override
120 122
 	public Void visitImplementation(ImplementationMember member) {
121
-		// TODO: implementation merge check
122 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 136
 		return null;
124 137
 	}
138
+	
139
+	private boolean canMergeImplementation(ImplementationMember member) {
140
+		return true; // TODO: implementation merge check
141
+	}
125 142
 
126 143
 	@Override
127 144
 	public Void visitInnerDefinition(InnerDefinitionMember member) {

+ 2
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java Näytä tiedosto

@@ -117,9 +117,8 @@ public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Vo
117 117
 
118 118
 	@Override
119 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 122
 		for (IDefinitionMember implementedMember : member.members)
124 123
 			implementedMember.accept(this);
125 124
 		

+ 14
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourceSignatureVisitor.java Näytä tiedosto

@@ -0,0 +1,14 @@
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 Näytä tiedosto

@@ -10,11 +10,11 @@ package org.openzen.zenscript.javasource.tags;
10 10
  * @author Hoofdgebruiker
11 11
  */
12 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 17
 		this.inline = inline;
18
+		this.implementationClass = implementationClass;
19 19
 	}
20 20
 }

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java Näytä tiedosto

@@ -111,7 +111,8 @@ public class TokenParser<T extends Token<TT>, TT extends TokenType> implements I
111 111
 				if (reader.peek() < 0 && value.length() == 0)
112 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 116
 				return factory.create(invalid, value.toString());
116 117
             }
117 118
         } catch (IOException ex) {

+ 3
- 1
Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java Näytä tiedosto

@@ -76,5 +76,7 @@ public abstract class ParsedDefinition {
76 76
 	
77 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 Näytä tiedosto

@@ -6,7 +6,6 @@
6 6
 package org.openzen.zenscript.parser;
7 7
 
8 8
 import java.io.File;
9
-import java.io.FileReader;
10 9
 import java.io.IOException;
11 10
 import java.util.ArrayList;
12 11
 import java.util.List;
@@ -189,8 +188,14 @@ public class ParsedFile {
189 188
 			List<AnnotationDefinition> annotations) {
190 189
 		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
191 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 197
 		for (ParsedDefinition definition : this.definitions) {
193
-			definition.compileCode(scope);
198
+			definition.compileCode(scope, state);
194 199
 		}
195 200
 		
196 201
 		if (!statements.isEmpty() || postComment != null) {

+ 61
- 0
Parser/src/main/java/org/openzen/zenscript/parser/PrecompilationState.java Näytä tiedosto

@@ -0,0 +1,61 @@
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 Näytä tiedosto

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.scope.BaseScope;
12 12
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
13 13
 import org.openzen.zenscript.parser.ParsedAnnotation;
14 14
 import org.openzen.zenscript.parser.ParsedDefinition;
15
+import org.openzen.zenscript.parser.PrecompilationState;
15 16
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
16 17
 
17 18
 /**
@@ -45,11 +46,18 @@ public abstract class BaseParsedDefinition extends ParsedDefinition {
45 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 57
 	@Override
50
-	public void compileCode(BaseScope scope) {
58
+	public void compileCode(BaseScope scope, PrecompilationState state) {
51 59
 		DefinitionScope innerScope = new DefinitionScope(scope, getCompiled());
52 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 Näytä tiedosto

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.scope.BaseScope;
17 17
 import org.openzen.zenscript.codemodel.scope.DefinitionScope;
18 18
 import org.openzen.zenscript.parser.ParsedAnnotation;
19 19
 import org.openzen.zenscript.parser.ParsedDefinition;
20
+import org.openzen.zenscript.parser.PrecompilationState;
20 21
 import org.openzen.zenscript.parser.type.IParsedType;
21 22
 
22 23
 /**
@@ -73,9 +74,14 @@ public class ParsedAlias extends ParsedDefinition {
73 74
 		
74 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 83
 	@Override
78
-	public void compileCode(BaseScope scope) {
84
+	public void compileCode(BaseScope scope, PrecompilationState state) {
79 85
 		// nothing to do
80 86
 	}
81 87
 

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java Näytä tiedosto

@@ -36,7 +36,7 @@ public class ParsedClass extends BaseParsedDefinition {
36 36
 		
37 37
 		ParsedClass result = new ParsedClass(pkg, position, modifiers, annotations, name, genericParameters, superclass, outerDefinition);
38 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 41
 		return result;
42 42
 	}

+ 4
- 3
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java Näytä tiedosto

@@ -18,6 +18,7 @@ import org.openzen.zenscript.lexer.ZSTokenType;
18 18
 import org.openzen.zenscript.codemodel.scope.BaseScope;
19 19
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20 20
 import org.openzen.zenscript.parser.ParsedAnnotation;
21
+import org.openzen.zenscript.parser.PrecompilationState;
21 22
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
22 23
 
23 24
 /**
@@ -39,7 +40,7 @@ public class ParsedEnum extends BaseParsedDefinition {
39 40
 		
40 41
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
41 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 45
 		} else {
45 46
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
@@ -76,8 +77,8 @@ public class ParsedEnum extends BaseParsedDefinition {
76 77
 	}
77 78
 
78 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 83
 		DefinitionTypeID type = new DefinitionTypeID(compiled, new ITypeID[0]);
83 84
 		ExpressionScope evalScope = new ExpressionScope(scope);

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java Näytä tiedosto

@@ -30,7 +30,7 @@ public class ParsedExpansion extends BaseParsedDefinition {
30 30
 		
31 31
 		ParsedExpansion result = new ParsedExpansion(pkg, position, modifiers, annotations, parameters, target, outerDefinition);
32 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 35
 		return result;
36 36
 	}

+ 11
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java Näytä tiedosto

@@ -14,8 +14,10 @@ import org.openzen.zenscript.codemodel.definition.ZSPackage;
14 14
 import org.openzen.zenscript.lexer.ZSTokenParser;
15 15
 import org.openzen.zenscript.codemodel.scope.BaseScope;
16 16
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
17
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
17 18
 import org.openzen.zenscript.parser.ParsedAnnotation;
18 19
 import org.openzen.zenscript.parser.ParsedDefinition;
20
+import org.openzen.zenscript.parser.PrecompilationState;
19 21
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
20 22
 import org.openzen.zenscript.parser.statements.ParsedStatement;
21 23
 
@@ -59,10 +61,18 @@ public class ParsedFunction extends ParsedDefinition {
59 61
 	public void compileMembers(BaseScope scope) {
60 62
 		compiled.setHeader(header.compile(scope));
61 63
 	}
64
+	
65
+	@Override
66
+	public void listMembers(BaseScope scope, PrecompilationState state) {
67
+		
68
+	}
62 69
 
63 70
 	@Override
64
-	public void compileCode(BaseScope scope) {
71
+	public void compileCode(BaseScope scope, PrecompilationState state) {
65 72
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
66 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 Näytä tiedosto

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

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java Näytä tiedosto

@@ -39,7 +39,7 @@ public class ParsedInterface extends BaseParsedDefinition {
39 39
 		
40 40
 		ParsedInterface result = new ParsedInterface(pkg, position, modifiers, annotations, name, genericParameters, superInterfaces, outerDefinition);
41 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 44
 		return result;
45 45
 	}

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedStruct.java Näytä tiedosto

@@ -29,7 +29,7 @@ public class ParsedStruct extends BaseParsedDefinition {
29 29
 		
30 30
 		ParsedStruct result = new ParsedStruct(pkg, position, modifiers, annotations, name, parameters, outerDefinition);
31 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 34
 		return result;
35 35
 	}

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java Näytä tiedosto

@@ -48,7 +48,7 @@ public class ParsedVariant extends BaseParsedDefinition {
48 48
 		
49 49
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
50 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 53
 		} else {
54 54
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");

+ 11
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java Näytä tiedosto

@@ -12,6 +12,8 @@ import org.openzen.zencode.shared.CompileExceptionCode;
12 12
 import org.openzen.zenscript.codemodel.expression.Expression;
13 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 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,4 +37,13 @@ public class ParsedDollarExpression extends ParsedExpression {
35 37
 	public boolean hasStrongType() {
36 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 Näytä tiedosto

@@ -27,6 +27,7 @@ import org.openzen.zenscript.lexer.ZSToken;
27 27
 import org.openzen.zenscript.lexer.ZSTokenParser;
28 28
 import org.openzen.zenscript.codemodel.scope.BaseScope;
29 29
 import org.openzen.zenscript.parser.ParseException;
30
+import org.openzen.zenscript.parser.PrecompilationState;
30 31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
31 32
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
32 33
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
@@ -595,4 +596,6 @@ public abstract class ParsedExpression {
595 596
 	}
596 597
 	
597 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 Näytä tiedosto

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
14 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17 18
 
18 19
 /**
19 20
  *
@@ -52,4 +53,14 @@ public class ParsedExpressionAndAnd extends ParsedExpression {
52 53
 	public boolean hasStrongType() {
53 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 Näytä tiedosto

@@ -8,13 +8,15 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
12
+import org.openzen.zencode.shared.CompileExceptionCode;
11 13
 import org.openzen.zenscript.codemodel.expression.ArrayExpression;
12 14
 import org.openzen.zenscript.codemodel.expression.Expression;
13 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 16
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
15
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
17 18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
+import org.openzen.zenscript.parser.PrecompilationState;
18 20
 
19 21
 /**
20 22
  *
@@ -31,8 +33,8 @@ public class ParsedExpressionArray extends ParsedExpression {
31 33
 
32 34
 	@Override
33 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 38
 		boolean couldHintType = false;
37 39
 		
38 40
 		for (ITypeID hint : scope.hints) {
@@ -53,7 +55,7 @@ public class ParsedExpressionArray extends ParsedExpression {
53 55
 			for (int i = 0; i < contents.size(); i++)
54 56
 				cContents[i] = contents.get(i).compile(contentScope).eval().castImplicit(position, scope, asBaseType);
55 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 59
 		} else {
58 60
 			ExpressionScope contentScope = scope.withoutHints();
59 61
 			ITypeID resultType = null;
@@ -81,4 +83,20 @@ public class ParsedExpressionArray extends ParsedExpression {
81 83
 	public boolean hasStrongType() {
82 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 Näytä tiedosto

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14 14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.parser.PrecompilationState;
15 16
 
16 17
 /**
17 18
  *
@@ -41,4 +42,9 @@ public class ParsedExpressionAssign extends ParsedExpression {
41 42
 	public boolean hasStrongType() {
42 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 Näytä tiedosto

@@ -10,9 +10,12 @@ import org.openzen.zencode.shared.CodePosition;
10 10
 import org.openzen.zenscript.codemodel.OperatorType;
11 11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
13 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 15
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
15 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,4 +47,20 @@ public class ParsedExpressionBinary extends ParsedExpression {
44 47
 	public boolean hasStrongType() {
45 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 Näytä tiedosto

@@ -10,6 +10,9 @@ import org.openzen.zencode.shared.CodePosition;
10 10
 import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
11 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12 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,4 +36,9 @@ public class ParsedExpressionBool extends ParsedExpression {
33 36
 	public boolean hasStrongType() {
34 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 Näytä tiedosto

@@ -12,6 +12,8 @@ import org.openzen.zencode.shared.CompileException;
12 12
 import org.openzen.zencode.shared.CompileExceptionCode;
13 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 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
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
16 18
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
17 19
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
@@ -44,11 +46,19 @@ public class ParsedExpressionBracket extends ParsedExpression {
44 46
 		for (ParsedExpression expression : expressions)
45 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 52
 	@Override
51 53
 	public boolean hasStrongType() {
52 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 Näytä tiedosto

@@ -27,6 +27,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
27 27
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
28 28
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
29 29
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
30
+import org.openzen.zenscript.parser.PrecompilationState;
30 31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
31 32
 
32 33
 /**
@@ -120,4 +121,9 @@ public class ParsedExpressionCall extends ParsedExpression {
120 121
 	public boolean hasStrongType() {
121 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 Näytä tiedosto

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14 14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15 15
 import org.openzen.zenscript.parser.ParsedAnnotation;
16
+import org.openzen.zenscript.parser.PrecompilationState;
16 17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
17 18
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
18 19
 import org.openzen.zenscript.parser.type.IParsedType;
@@ -49,7 +50,7 @@ public class ParsedExpressionCast extends ParsedExpression {
49 50
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Not a valid lambda header");
50 51
 		
51 52
 		ParsedFunctionHeader header = value.toLambdaHeader();
52
-		if (header.returnType != ParsedTypeBasic.ANY)
53
+		if (header.returnType != ParsedTypeBasic.UNDETERMINED)
53 54
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Lambda parameter already has a return type");
54 55
 		
55 56
 		return new ParsedFunctionHeader(header.genericParameters, header.parameters, type, null);
@@ -61,7 +62,7 @@ public class ParsedExpressionCast extends ParsedExpression {
61 62
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Not a valid lambda header");
62 63
 		
63 64
 		ParsedFunctionParameter parameter = value.toLambdaParameter();
64
-		if (parameter.type != ParsedTypeBasic.ANY)
65
+		if (parameter.type != ParsedTypeBasic.UNDETERMINED)
65 66
 			throw new CompileException(position, CompileExceptionCode.LAMBDA_HEADER_INVALID, "Lambda parameter already has a type");
66 67
 		
67 68
 		return new ParsedFunctionParameter(ParsedAnnotation.NONE, parameter.name, type, null, false);
@@ -71,4 +72,9 @@ public class ParsedExpressionCast extends ParsedExpression {
71 72
 	public boolean hasStrongType() {
72 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 Näytä tiedosto

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.type.ITypeID;
15 15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16 16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17 18
 
18 19
 /**
19 20
  *
@@ -52,4 +53,17 @@ public class ParsedExpressionCoalesce extends ParsedExpression {
52 53
 	public boolean hasStrongType() {
53 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 Näytä tiedosto

@@ -11,6 +11,9 @@ import org.openzen.zenscript.codemodel.CompareType;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 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,4 +47,9 @@ public class ParsedExpressionCompare extends ParsedExpression {
44 47
 	public boolean hasStrongType() {
45 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 Näytä tiedosto

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17 17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18 18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
+import org.openzen.zenscript.parser.PrecompilationState;
19 20
 
20 21
 /**
21 22
  *
@@ -72,4 +73,14 @@ public class ParsedExpressionConditional extends ParsedExpression {
72 73
 	public boolean hasStrongType() {
73 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 Näytä tiedosto

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17 18
 
18 19
 /**
19 20
  *
@@ -55,4 +56,16 @@ public class ParsedExpressionFloat extends ParsedExpression {
55 56
 	public boolean hasStrongType() {
56 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 Näytä tiedosto

@@ -24,6 +24,7 @@ import org.openzen.zenscript.codemodel.scope.BaseScope;
24 24
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25 25
 import org.openzen.zenscript.codemodel.scope.LambdaScope;
26 26
 import org.openzen.zenscript.codemodel.scope.StatementScope;
27
+import org.openzen.zenscript.parser.PrecompilationState;
27 28
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
28 29
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
29 30
 
@@ -96,4 +97,9 @@ public class ParsedExpressionFunction extends ParsedExpression {
96 97
 	public boolean hasStrongType() {
97 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 Näytä tiedosto

@@ -12,12 +12,14 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
12 12
 import org.openzen.zenscript.codemodel.OperatorType;
13 13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14 14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
15 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 17
 import org.openzen.zenscript.codemodel.scope.TypeScope;
17 18
 import org.openzen.zenscript.codemodel.type.GenericName;
18 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 20
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
20 21
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
22
+import org.openzen.zenscript.parser.PrecompilationState;
21 23
 
22 24
 /**
23 25
  *
@@ -43,6 +45,29 @@ public class ParsedExpressionIndex extends ParsedExpression {
43 45
 	public boolean hasStrongType() {
44 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 72
 	private class PartialIndexedExpression implements IPartialExpression {
48 73
 		private final ExpressionScope scope;

+ 27
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java Näytä tiedosto

@@ -23,6 +23,7 @@ import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
23 23
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
24 24
 import org.openzen.zenscript.codemodel.type.ITypeID;
25 25
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
26
+import org.openzen.zenscript.parser.PrecompilationState;
26 27
 
27 28
 /**
28 29
  *
@@ -83,4 +84,30 @@ public class ParsedExpressionInt extends ParsedExpression {
83 84
 	public boolean hasStrongType() {
84 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 Näytä tiedosto

@@ -11,6 +11,8 @@ import org.openzen.zenscript.codemodel.expression.IsExpression;
11 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13 13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
+import org.openzen.zenscript.parser.PrecompilationState;
14 16
 import org.openzen.zenscript.parser.type.IParsedType;
15 17
 
16 18
 /**
@@ -39,4 +41,9 @@ public class ParsedExpressionIs extends ParsedExpression {
39 41
 	public boolean hasStrongType() {
40 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 Näytä tiedosto

@@ -19,10 +19,10 @@ import org.openzen.zenscript.codemodel.expression.NewExpression;
19 19
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
20 20
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
21 21
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
22
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
23 22
 import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
24 23
 import org.openzen.zenscript.codemodel.type.ITypeID;
25 24
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25
+import org.openzen.zenscript.parser.PrecompilationState;
26 26
 
27 27
 /**
28 28
  *
@@ -75,7 +75,7 @@ public class ParsedExpressionMap extends ParsedExpression {
75 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 79
 			// compile as constructor call
80 80
 			ITypeID hint = scope.hints.get(0);
81 81
 			for (int i = 0; i < keys.size(); i++) {
@@ -109,7 +109,8 @@ public class ParsedExpressionMap extends ParsedExpression {
109 109
 			}
110 110
 		}
111 111
 		if (keyType == null)
112
-			keyType = BasicTypeID.ANY;
112
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
113
+		
113 114
 		for (int i = 0; i < cKeys.length; i++)
114 115
 			cKeys[i] = cKeys[i].castImplicit(position, scope, keyType);
115 116
 		
@@ -125,7 +126,8 @@ public class ParsedExpressionMap extends ParsedExpression {
125 126
 			}
126 127
 		}
127 128
 		if (valueType == null)
128
-			valueType = BasicTypeID.ANY;
129
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
130
+		
129 131
 		for (int i = 0; i < cValues.length; i++)
130 132
 			cValues[i] = cValues[i].castImplicit(position, scope, valueType);
131 133
 		
@@ -137,4 +139,9 @@ public class ParsedExpressionMap extends ParsedExpression {
137 139
 	public boolean hasStrongType() {
138 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 Näytä tiedosto

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.parser.PrecompilationState;
17 18
 import org.openzen.zenscript.parser.type.IParsedType;
18 19
 
19 20
 /**
@@ -51,4 +52,20 @@ public class ParsedExpressionMember extends ParsedExpression {
51 52
 	public boolean hasStrongType() {
52 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 Näytä tiedosto

@@ -10,6 +10,9 @@ import org.openzen.zencode.shared.CodePosition;
10 10
 import org.openzen.zenscript.codemodel.expression.NullExpression;
11 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12 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,4 +32,9 @@ public class ParsedExpressionNull extends ParsedExpression {
29 32
 	public boolean hasStrongType() {
30 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 Näytä tiedosto

@@ -14,6 +14,8 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
15 15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16 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,4 +54,9 @@ public class ParsedExpressionOpAssign extends ParsedExpression {
52 54
 	public boolean hasStrongType() {
53 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 Näytä tiedosto

@@ -12,6 +12,8 @@ import org.openzen.zenscript.codemodel.expression.OrOrExpression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 13
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14 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,4 +41,14 @@ public class ParsedExpressionOrOr extends ParsedExpression {
39 41
 	public boolean hasStrongType() {
40 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 Näytä tiedosto

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12 12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14 14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.parser.PrecompilationState;
15 16
 
16 17
 /**
17 18
  *
@@ -39,4 +40,9 @@ public class ParsedExpressionOuter extends ParsedExpression {
39 40
 	public boolean hasStrongType() {
40 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 Näytä tiedosto

@@ -11,6 +11,8 @@ import org.openzen.zenscript.codemodel.OperatorType;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 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,4 +39,9 @@ public class ParsedExpressionPostCall extends ParsedExpression {
37 39
 	public boolean hasStrongType() {
38 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 Näytä tiedosto


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

Loading…
Peruuta
Tallenna