Explorar el Código

- Renamed enum constant index to ordinal

- Added ordinal to variant options
- Added GetMatchingVariantField; from now on values retrieved from variant option fields in a match or case will result in such expression. This may make it easier for compilers.
Stan Hebben hace 6 años
padre
commit
f04850f397
Se han modificado 30 ficheros con 287 adiciones y 200 borrados
  1. 6
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java
  3. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  4. 41
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetMatchingVariantField.java
  5. 2
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/switchvalue/VariantOptionSwitchValue.java
  6. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java
  7. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  8. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  9. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  10. 5
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  11. 7
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  12. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  13. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  14. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  15. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java
  16. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  17. 5
    5
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java
  18. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java
  19. 4
    3
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariantOption.java
  20. 2
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  21. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java
  22. 2
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java
  23. 58
    55
      Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java
  24. 65
    65
      Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java
  25. 22
    32
      Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java
  26. 5
    5
      Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java
  27. 5
    5
      Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java
  28. 2
    2
      Shared/src/main/java/stdlib/Result.java
  29. 2
    1
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  30. 9
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java

+ 6
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java Ver fichero

@@ -45,6 +45,7 @@ import org.openzen.zenscript.codemodel.expression.FunctionExpression;
45 45
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
46 46
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
47 47
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
48
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
48 49
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
49 50
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
50 51
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
@@ -480,6 +481,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
480 481
 	public ExpressionString visitGetLocalVariable(GetLocalVariableExpression expression) {
481 482
 		return new ExpressionString(expression.variable.name, ZenScriptOperator.PRIMARY);
482 483
 	}
484
+	
485
+	@Override
486
+	public ExpressionString visitGetMatchingVariantField(GetMatchingVariantField expression) {
487
+		return new ExpressionString(expression.value.parameters[expression.index], ZenScriptOperator.PRIMARY);
488
+	}
483 489
 
484 490
 	@Override
485 491
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {

+ 3
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java Ver fichero

@@ -32,10 +32,12 @@ public class VariantDefinition extends HighLevelDefinition {
32 32
 	
33 33
 	public static class Option extends Taggable {
34 34
 		public final String name;
35
+		public final int ordinal;
35 36
 		public final ITypeID[] types;
36 37
 		
37
-		public Option(String name, ITypeID[] types) {
38
+		public Option(String name, int ordinal, ITypeID[] types) {
38 39
 			this.name = name;
40
+			this.ordinal = ordinal;
39 41
 			this.types = types;
40 42
 		}
41 43
 		

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java Ver fichero

@@ -80,6 +80,8 @@ public interface ExpressionVisitor<T> {
80 80
 	
81 81
 	public T visitGetLocalVariable(GetLocalVariableExpression expression);
82 82
 	
83
+	public T visitGetMatchingVariantField(GetMatchingVariantField expression);
84
+	
83 85
 	public T visitGetStaticField(GetStaticFieldExpression expression);
84 86
 	
85 87
 	public T visitGetter(GetterExpression expression);

+ 41
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetMatchingVariantField.java Ver fichero

@@ -0,0 +1,41 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class GetMatchingVariantField extends Expression {
17
+	public final VariantOptionSwitchValue value;
18
+	public final int index;
19
+	
20
+	public GetMatchingVariantField(CodePosition position, VariantOptionSwitchValue value, int index) {
21
+		super(position, value.option.types[index], null);
22
+		
23
+		this.value = value;
24
+		this.index = index;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(ExpressionVisitor<T> visitor) {
29
+		return visitor.visitGetMatchingVariantField(this);
30
+	}
31
+
32
+	@Override
33
+	public Expression transform(ExpressionTransformer transformer) {
34
+		return this;
35
+	}
36
+
37
+	@Override
38
+	public Expression normalize(TypeScope scope) {
39
+		return this;
40
+	}
41
+}

+ 2
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/switchvalue/VariantOptionSwitchValue.java Ver fichero

@@ -6,7 +6,6 @@
6 6
 package org.openzen.zenscript.codemodel.expression.switchvalue;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
9
-import org.openzen.zenscript.codemodel.statement.VarStatement;
10 9
 
11 10
 /**
12 11
  *
@@ -14,9 +13,9 @@ import org.openzen.zenscript.codemodel.statement.VarStatement;
14 13
  */
15 14
 public class VariantOptionSwitchValue implements SwitchValue {
16 15
 	public final VariantOptionRef option;
17
-	public final VarStatement[] parameters;
16
+	public final String[] parameters;
18 17
 	
19
-	public VariantOptionSwitchValue(VariantOptionRef option, VarStatement[] parameters) {
18
+	public VariantOptionSwitchValue(VariantOptionRef option, String[] parameters) {
20 19
 		this.option = option;
21 20
 		this.parameters = parameters;
22 21
 	}

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java Ver fichero

@@ -17,14 +17,14 @@ public class EnumConstantMember {
17 17
 	public final CodePosition position;
18 18
 	public final HighLevelDefinition definition;
19 19
 	public final String name;
20
-	public final int value;
20
+	public final int ordinal;
21 21
 	
22 22
 	public NewExpression constructor;
23 23
 	
24
-	public EnumConstantMember(CodePosition position, HighLevelDefinition definition, String name, int value) {
24
+	public EnumConstantMember(CodePosition position, HighLevelDefinition definition, String name, int ordinal) {
25 25
 		this.position = position;
26 26
 		this.definition = definition;
27 27
 		this.name = name;
28
-		this.value = value;
28
+		this.ordinal = ordinal;
29 29
 	}
30 30
 }

+ 10
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java Ver fichero

@@ -16,6 +16,8 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
16 16
 import org.openzen.zenscript.codemodel.GenericMapper;
17 17
 import org.openzen.zenscript.codemodel.expression.Expression;
18 18
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
19
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
20
+import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
19 21
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
20 22
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
21 23
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
@@ -35,7 +37,7 @@ public class ExpressionScope extends BaseScope {
35 37
 	
36 38
 	public final List<ITypeID> hints;
37 39
 	public final Map<TypeParameter, ITypeID> genericInferenceMap;
38
-	public final Map<String, VarStatement> innerVariables = new HashMap<>();
40
+	public final Map<String, Function<CodePosition, Expression>> innerVariables = new HashMap<>();
39 41
 	
40 42
 	public ExpressionScope(BaseScope outer) {
41 43
 		this.outer = outer;
@@ -70,7 +72,7 @@ public class ExpressionScope extends BaseScope {
70 72
 			List<ITypeID> hints,
71 73
 			Function<CodePosition, Expression> dollar,
72 74
 			Map<TypeParameter, ITypeID> genericInferenceMap,
73
-			Map<String, VarStatement> innerVariables) {
75
+			Map<String, Function<CodePosition, Expression>> innerVariables) {
74 76
 		this.outer = scope;
75 77
 		this.hints = hints;
76 78
 		this.dollar = dollar;
@@ -79,7 +81,11 @@ public class ExpressionScope extends BaseScope {
79 81
 	}
80 82
 	
81 83
 	public void addInnerVariable(VarStatement variable) {
82
-		innerVariables.put(variable.name, variable);
84
+		innerVariables.put(variable.name, position -> new GetLocalVariableExpression(position, variable));
85
+	}
86
+	
87
+	public void addMatchingVariantOption(String name, int index, VariantOptionSwitchValue value) {
88
+		innerVariables.put(name, position -> new GetMatchingVariantField(position, value, index));
83 89
 	}
84 90
 	
85 91
 	public List<ITypeID> getResultTypeHints() {
@@ -121,7 +127,7 @@ public class ExpressionScope extends BaseScope {
121 127
 	@Override
122 128
 	public IPartialExpression get(CodePosition position, GenericName name) {
123 129
 		if (name.hasNoArguments() && innerVariables.containsKey(name.name))
124
-			return new GetLocalVariableExpression(position, innerVariables.get(name.name));
130
+			return innerVariables.get(name.name).apply(position);
125 131
 		
126 132
 		return outer.get(position, name);
127 133
 	}

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Ver fichero

@@ -48,7 +48,7 @@ public class JavaCompiler implements ZenCodeCompiler {
48 48
 	
49 49
 	@Override
50 50
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
51
-		String className = getClassName(definition.position.filename);
51
+		String className = getClassName(definition.position.getFilename());
52 52
 		JavaScriptFile scriptFile = getScriptFile(className);
53 53
 		target.register(definition.name, definition.accept(new JavaDefinitionVisitor(scriptFile.classWriter)));
54 54
 	}

+ 2
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java Ver fichero

@@ -90,7 +90,7 @@ public class CompilerUtils {
90 90
     }
91 91
 
92 92
     public static String calcClasName(CodePosition position) {
93
-        return position.filename.substring(0, position.filename.lastIndexOf('.')).replace("/", "_");
93
+        return position.getFilename().substring(0, position.getFilename().lastIndexOf('.')).replace("/", "_");
94 94
     }
95 95
 
96 96
     public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
@@ -197,7 +197,7 @@ public class CompilerUtils {
197 197
 
198 198
 		@Override
199 199
 		public Integer acceptEnumConstant(EnumConstantSwitchValue value) {
200
-			return value.constant.value;
200
+			return value.constant.ordinal;
201 201
 		}
202 202
 
203 203
 		@Override

+ 5
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Ver fichero

@@ -1703,6 +1703,11 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1703 1703
         javaWriter.label(label);
1704 1704
         return null;
1705 1705
     }
1706
+	
1707
+	@Override
1708
+	public Void visitGetMatchingVariantField(GetMatchingVariantField expression) {
1709
+		throw new UnsupportedOperationException(); // TODO
1710
+	}
1706 1711
 
1707 1712
     @Override
1708 1713
     public Void visitGetStaticField(GetStaticFieldExpression expression) {

+ 7
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java Ver fichero

@@ -42,6 +42,7 @@ import org.openzen.zenscript.codemodel.expression.FunctionExpression;
42 42
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43 43
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44 44
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
45 46
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46 47
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
47 48
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
@@ -276,13 +277,18 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
276 277
 		javaWriter.idec(expression.parameter.getTag(JavaParameterInfo.class).index);
277 278
 		return null;
278 279
 	}
279
-
280
+	
280 281
 	@Override
281 282
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
282 283
 		javaWriter.idec(expression.variable.getTag(JavaLocalVariableInfo.class).local);
283 284
 		return null;
284 285
 	}
285 286
 
287
+	@Override
288
+	public Void visitGetMatchingVariantField(GetMatchingVariantField expression) {
289
+		throw new UnsupportedOperationException("Invalid increment target");
290
+	}
291
+
286 292
 	@Override
287 293
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
288 294
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))

+ 6
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java Ver fichero

@@ -42,6 +42,7 @@ import org.openzen.zenscript.codemodel.expression.FunctionExpression;
42 42
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43 43
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44 44
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
45 46
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46 47
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
47 48
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
@@ -288,6 +289,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
288 289
 		return null;
289 290
 	}
290 291
 
292
+	@Override
293
+	public Void visitGetMatchingVariantField(GetMatchingVariantField expression) {
294
+		throw new UnsupportedOperationException("Invalid increment target");
295
+	}
296
+
291 297
 	@Override
292 298
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
293 299
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Ver fichero

@@ -83,7 +83,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
83 83
 
84 84
     @Override
85 85
     public byte[] visitEnum(EnumDefinition definition) {
86
-		System.out.println("Compiling enum " + definition.name + " in " + definition.position.filename);
86
+		System.out.println("Compiling enum " + definition.name + " in " + definition.position.getFilename());
87 87
 		
88 88
         final Type superType;
89 89
         if (definition.getSuperType() == null)

+ 2
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java Ver fichero

@@ -215,7 +215,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
215 215
 				clinitWriter.newObject(internalName);
216 216
 				clinitWriter.dup();
217 217
 				clinitWriter.constant(constant.name);
218
-				clinitWriter.constant(constant.value);
218
+				clinitWriter.constant(constant.ordinal);
219 219
 				for (Expression argument : constant.constructor.arguments.arguments) {
220 220
 					argument.accept(clinitStatementVisitor.expressionVisitor);
221 221
 				}
@@ -233,7 +233,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
233 233
 
234 234
             for (EnumConstantMember enumConstant : enumConstants) {
235 235
                 clinitWriter.dup();
236
-                clinitWriter.constant(enumConstant.value);
236
+                clinitWriter.constant(enumConstant.ordinal);
237 237
                 clinitWriter.getStaticField(definition.name, enumConstant.name, "L" + definition.name + ";");
238 238
                 clinitWriter.arrayStore(Type.getType("L" + definition.name + ";"));
239 239
             }

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java Ver fichero

@@ -41,6 +41,7 @@ import org.openzen.zenscript.codemodel.expression.FunctionExpression;
41 41
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
42 42
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
43 43
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
44
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
44 45
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
45 46
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
46 47
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
@@ -257,6 +258,11 @@ public class ExpressionHoistingChecker implements ExpressionVisitor<Boolean> {
257 258
 		return false;
258 259
 	}
259 260
 
261
+	@Override
262
+	public Boolean visitGetMatchingVariantField(GetMatchingVariantField expression) {
263
+		return false;
264
+	}
265
+
260 266
 	@Override
261 267
 	public Boolean visitGetStaticField(GetStaticFieldExpression expression) {
262 268
 		return false;

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Ver fichero

@@ -49,6 +49,7 @@ import org.openzen.zenscript.codemodel.expression.FunctionExpression;
49 49
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
50 50
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
51 51
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
52
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
52 53
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
53 54
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
54 55
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
@@ -421,6 +422,11 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
421 422
 		return new ExpressionString(expression.variable.name, JavaOperator.PRIMARY);
422 423
 	}
423 424
 
425
+	@Override
426
+	public ExpressionString visitGetMatchingVariantField(GetMatchingVariantField expression) {
427
+		return new ExpressionString(expression.value.parameters[expression.index], JavaOperator.PRIMARY);
428
+	}
429
+
424 430
 	@Override
425 431
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
426 432
 		JavaSourceField field = expression.field.getTag(JavaSourceField.class);

+ 5
- 5
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java Ver fichero

@@ -140,15 +140,15 @@ public class JavaSourceStatementFormatter implements StatementFormatter.Formatte
140 140
 				String header = switchValue == null ? "default:" : "case " + switchValue.option.getName() + ":";
141 141
 				List<String> statements = new ArrayList<>();
142 142
 				if (switchValue != null) {
143
-					for (VarStatement var : switchValue.parameters) {
143
+					for (int i = 0; i < switchValue.parameters.length; i++) {
144 144
 						StringBuilder statementOutput = new StringBuilder();
145
-						statementOutput.append(scope.type(var.type)).append(" ").append(var.name).append(" = ((").append(variantTypeName).append(".").append(switchValue.option.getName());
145
+						statementOutput.append(scope.type(switchValue.option.types[i])).append(" ").append(switchValue.parameters[i]).append(" = ((").append(variantTypeName).append(".").append(switchValue.option.getName());
146 146
 						if (variant.genericParameters != null && variant.genericParameters.length > 0) {
147 147
 							statementOutput.append("<");
148
-							for (int i = 0; i < variantType.typeParameters.length; i++) {
149
-								if (i > 0)
148
+							for (int j = 0; j < variantType.typeParameters.length; j++) {
149
+								if (j > 0)
150 150
 									statementOutput.append(", ");
151
-								statementOutput.append(scope.type(variantType.typeParameters[i]));
151
+								statementOutput.append(scope.type(variantType.typeParameters[j]));
152 152
 							}
153 153
 							statementOutput.append(">");
154 154
 						}

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java Ver fichero

@@ -30,6 +30,7 @@ public class ParsedVariant extends BaseParsedDefinition {
30 30
 		
31 31
 		ParsedVariant result = new ParsedVariant(pkg, position, modifiers, annotations, name, typeParameters, outerDefinition);
32 32
 		
33
+		int ordinal = 0;
33 34
 		while (!tokens.isNext(ZSTokenType.T_ACLOSE) && !tokens.isNext(ZSTokenType.T_SEMICOLON)) {
34 35
 			String optionName = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
35 36
 			List<IParsedType> types = new ArrayList<>();
@@ -40,7 +41,7 @@ public class ParsedVariant extends BaseParsedDefinition {
40 41
 				}
41 42
 				tokens.required(ZSTokenType.T_BRCLOSE, ") expected");
42 43
 			}
43
-			result.addVariant(new ParsedVariantOption(optionName, types));
44
+			result.addVariant(new ParsedVariantOption(optionName, ordinal++, types));
44 45
 			if (tokens.optional(ZSTokenType.T_COMMA) == null)
45 46
 				break;
46 47
 		}

+ 4
- 3
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariantOption.java Ver fichero

@@ -9,7 +9,6 @@ import java.util.List;
9 9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10 10
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
-import org.openzen.zenscript.codemodel.scope.BaseScope;
13 12
 import org.openzen.zenscript.parser.type.IParsedType;
14 13
 
15 14
 /**
@@ -18,10 +17,12 @@ import org.openzen.zenscript.parser.type.IParsedType;
18 17
  */
19 18
 public class ParsedVariantOption {
20 19
 	public final String name;
20
+	public final int ordinal;
21 21
 	public final List<IParsedType> types;
22 22
 	
23
-	public ParsedVariantOption(String name, List<IParsedType> types) {
23
+	public ParsedVariantOption(String name, int ordinal, List<IParsedType> types) {
24 24
 		this.name = name;
25
+		this.ordinal = ordinal;
25 26
 		this.types = types;
26 27
 	}
27 28
 	
@@ -30,6 +31,6 @@ public class ParsedVariantOption {
30 31
 		for (int i = 0; i < cTypes.length; i++)
31 32
 			cTypes[i] = types.get(i).compile(context);
32 33
 		
33
-		return new VariantDefinition.Option(name, cTypes);
34
+		return new VariantDefinition.Option(name, ordinal, cTypes);
34 35
 	}
35 36
 }

+ 2
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java Ver fichero

@@ -21,7 +21,6 @@ import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitc
21 21
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
22 22
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
23 23
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
24
-import org.openzen.zenscript.codemodel.statement.VarStatement;
25 24
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26 25
 import org.openzen.zenscript.codemodel.type.ITypeID;
27 26
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
@@ -103,11 +102,11 @@ public class ParsedExpressionCall extends ParsedExpression {
103 102
 			if (option == null)
104 103
 				throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Variant option does not exist: " + name);
105 104
 			
106
-			VarStatement[] values = new VarStatement[arguments.arguments.size()];
105
+			String[] values = new String[arguments.arguments.size()];
107 106
 			for (int i = 0; i < values.length; i++) {
108 107
 				ParsedExpression argument = arguments.arguments.get(i);
109 108
 				ParsedFunctionParameter lambdaHeader = argument.toLambdaParameter();
110
-				values[i] = new VarStatement(argument.position, lambdaHeader.name, option.types[i], null, true);
109
+				values[i] = lambdaHeader.name;
111 110
 			}
112 111
 			
113 112
 			return new VariantOptionSwitchValue(option, values);

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java Ver fichero

@@ -97,7 +97,7 @@ public class ParsedExpressionVariable extends ParsedExpression {
97 97
 			if (option.types.length > 0)
98 98
 				throw new CompileException(position, CompileExceptionCode.MISSING_VARIANT_CASEPARAMETERS, "Variant case is missing parameters");
99 99
 			
100
-			return new VariantOptionSwitchValue(option, new VarStatement[0]);
100
+			return new VariantOptionSwitchValue(option, new String[0]);
101 101
 		} else {
102 102
 			throw new CompileException(position, CompileExceptionCode.INVALID_SWITCH_CASE, "Invalid switch case");
103 103
 		}

+ 2
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java Ver fichero

@@ -14,10 +14,8 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
15 15
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
16 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
-import org.openzen.zenscript.codemodel.statement.VarStatement;
18 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20
-import org.openzen.zenscript.parser.PrecompilationState;
21 19
 
22 20
 /**
23 21
  *
@@ -80,8 +78,8 @@ public class ParsedMatchExpression extends ParsedExpression {
80 78
 			if (switchValue instanceof VariantOptionSwitchValue) {
81 79
 				VariantOptionSwitchValue variantSwitchValue = (VariantOptionSwitchValue)switchValue;
82 80
 				
83
-				for (VarStatement var : variantSwitchValue.parameters)
84
-					innerScope.addInnerVariable(var);
81
+				for (int i = 0; i < variantSwitchValue.parameters.length; i++)
82
+					innerScope.addMatchingVariantOption(variantSwitchValue.parameters[i], i, variantSwitchValue);
85 83
 			}
86 84
 			
87 85
 			Expression value = this.value.compile(innerScope).eval();

+ 58
- 55
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Ver fichero

@@ -1,61 +1,64 @@
1 1
 package org.openzen.zencode.shared;
2 2
 
3 3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.VirtualSourceFile;
4 5
 
5 6
 public final class CodePosition {
6
-	public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
7
-	public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
8
-	public final String filename;
9
-	public final SourceFile file;
10
-	public final int fromLine;
11
-	public final int fromLineOffset;
12
-	public final int toLine;
13
-	public final int toLineOffset;
14
-	
15
-	public CodePosition(SourceFile file, int fromLine, int fromLineOffset, int toLine, int toLineOffset) {
16
-		this.file = file;
17
-	    this.filename = file.getFilename();
18
-	    this.fromLine = fromLine;
19
-	    this.fromLineOffset = fromLineOffset;
20
-	    this.toLine = toLine;
21
-	    this.toLineOffset = toLineOffset;
22
-	}
23
-	
24
-	public String toShortString() {
25
-	    int lastSeparator = filename.lastIndexOf('/');
26
-	    String shortFilename = lastSeparator >= 0 ? filename.substring(lastSeparator + 1, (filename).length()) : filename;
27
-	    if (fromLine == 0 && fromLineOffset == 0)
28
-	        return shortFilename;
29
-	    return shortFilename + ":" + Integer.toString(fromLine) + ":" + Integer.toString(fromLineOffset);
30
-	}
31
-	
32
-	public CodePosition until(CodePosition to) {
33
-	    if (!filename.equals(to.filename))
34
-	        throw new AssertionError("From and to positions must be in the same file!");
35
-	    return new CodePosition(file, fromLine, fromLineOffset, to.toLine, to.toLineOffset);
36
-	}
37
-	
38
-	public String toString() {
39
-	    return fromLine == 0 && fromLineOffset == 0 ? filename : filename + ":" + Integer.toString(fromLine) + ":" + Integer.toString(fromLineOffset);
40
-	}
41
-	
42
-	public String getFilename() {
43
-	    return filename;
44
-	}
45
-	
46
-	public int getFromLine() {
47
-	    return fromLine;
48
-	}
49
-	
50
-	public int getFromLineOffset() {
51
-	    return fromLineOffset;
52
-	}
53
-	
54
-	public int getToLine() {
55
-	    return toLine;
56
-	}
57
-	
58
-	public int getToLineOffset() {
59
-	    return toLineOffset;
60
-	}
7
+    public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
8
+    public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
9
+    public final SourceFile file;
10
+    public final int fromLine;
11
+    public final int fromLineOffset;
12
+    public final int toLine;
13
+    public final int toLineOffset;
14
+    
15
+    public CodePosition(SourceFile file, int fromLine, int fromLineOffset, int toLine, int toLineOffset) {
16
+        this.file = file;
17
+        this.fromLine = fromLine;
18
+        this.fromLineOffset = fromLineOffset;
19
+        this.toLine = toLine;
20
+        this.toLineOffset = toLineOffset;
21
+    }
22
+    
23
+    public String getFilename() {
24
+        return file.getFilename();
25
+    }
26
+    
27
+    public String toShortString() {
28
+        int lastSeparator = file.getFilename().lastIndexOf('/');
29
+        String shortFilename = lastSeparator >= 0 ? file.getFilename().substring(lastSeparator + 1, (file.getFilename()).length()) : file.getFilename();
30
+        if (fromLine == 0 && fromLineOffset == 0)
31
+            return shortFilename;
32
+        return shortFilename + ":" + Integer.toString(fromLine) + ":" + Integer.toString(fromLineOffset);
33
+    }
34
+    
35
+    public CodePosition until(CodePosition to) {
36
+        if (!(file == to.file))
37
+            throw new AssertionError("From and to positions must be in the same file!");
38
+        return new CodePosition(file, fromLine, fromLineOffset, to.toLine, to.toLineOffset);
39
+    }
40
+    
41
+    public String toString() {
42
+        return fromLine == 0 && fromLineOffset == 0 ? file.getFilename() : file.getFilename() + ":" + Integer.toString(fromLine) + ":" + Integer.toString(fromLineOffset);
43
+    }
44
+    
45
+    public SourceFile getFile() {
46
+        return file;
47
+    }
48
+    
49
+    public int getFromLine() {
50
+        return fromLine;
51
+    }
52
+    
53
+    public int getFromLineOffset() {
54
+        return fromLineOffset;
55
+    }
56
+    
57
+    public int getToLine() {
58
+        return toLine;
59
+    }
60
+    
61
+    public int getToLineOffset() {
62
+        return toLineOffset;
63
+    }
61 64
 }

+ 65
- 65
Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java Ver fichero

@@ -1,69 +1,69 @@
1 1
 package org.openzen.zencode.shared;
2 2
 
3 3
 public enum CompileExceptionCode {
4
-	UNEXPECTED_TOKEN,
5
-	IMPORT_NOT_FOUND,
6
-	NO_OUTER_BECAUSE_NOT_INNER,
7
-	NO_OUTER_BECAUSE_STATIC,
8
-	NO_OUTER_BECAUSE_OUTSIDE_TYPE,
9
-	TYPE_ARGUMENTS_INVALID_NUMBER,
10
-	TYPE_ARGUMENTS_NOT_INFERRABLE,
11
-	USING_STATIC_ON_INSTANCE,
12
-	CANNOT_ASSIGN,
13
-	UNAVAILABLE_IN_CLOSURE,
14
-	USING_PACKAGE_AS_EXPRESSION,
15
-	USING_PACKAGE_AS_CALL_TARGET,
16
-	USING_TYPE_AS_EXPRESSION,
17
-	MEMBER_NO_SETTER,
18
-	MEMBER_NO_GETTER,
19
-	MEMBER_NOT_STATIC,
20
-	MEMBER_IS_FINAL,
21
-	MEMBER_DUPLICATE,
22
-	CALL_AMBIGUOUS,
23
-	CALL_NO_VALID_METHOD,
24
-	ENUM_VALUE_DUPLICATE,
25
-	INVALID_CAST,
26
-	NO_SUCH_INNER_TYPE,
27
-	NO_DOLLAR_HERE,
28
-	UNSUPPORTED_XML_EXPRESSIONS,
29
-	UNSUPPORTED_NAMED_ARGUMENTS,
30
-	TYPE_CANNOT_UNITE,
31
-	BRACKET_MULTIPLE_EXPRESSIONS,
32
-	SUPER_CALL_NO_SUPERCLASS,
33
-	LAMBDA_HEADER_INVALID,
34
-	COALESCE_TARGET_NOT_OPTIONAL,
35
-	MULTIPLE_MATCHING_HINTS,
36
-	MISSING_MAP_KEY,
37
-	NO_SUCH_MEMBER,
38
-	USING_THIS_OUTSIDE_TYPE,
39
-	USING_THIS_STATIC,
40
-	UNDEFINED_VARIABLE,
41
-	METHOD_BODY_REQUIRED,
42
-	BREAK_OUTSIDE_LOOP,
43
-	CONTINUE_OUTSIDE_LOOP,
44
-	NO_SUCH_ITERATOR,
45
-	NO_SUCH_TYPE,
46
-	RETURN_VALUE_REQUIRED,
47
-	RETURN_VALUE_VOID,
48
-	INVALID_CONDITION,
49
-	INTERNAL_ERROR,
50
-	CANNOT_SET_FINAL_VARIABLE,
51
-	MISSING_PARAMETER,
52
-	STATEMENT_OUTSIDE_SWITCH_CASE,
53
-	MISSING_VARIANT_CASEPARAMETERS,
54
-	INVALID_SWITCH_CASE,
55
-	TRY_CONVERT_OUTSIDE_FUNCTION,
56
-	TRY_CONVERT_ILLEGAL_TARGET,
57
-	TRY_RETHROW_NOT_A_RESULT,
58
-	DIFFERENT_EXCEPTIONS,
59
-	UNKNOWN_ANNOTATION,
60
-	OVERRIDE_WITHOUT_BASE,
61
-	OVERRIDE_AMBIGUOUS,
62
-	OVERRIDE_CONSTRUCTOR,
63
-	PRECOMPILE_FAILED,
64
-	UNTYPED_EMPTY_ARRAY,
65
-	UNTYPED_EMPTY_MAP,
66
-	VAR_WITHOUT_TYPE_OR_INITIALIZER,
67
-	NO_BRACKET_PARSER,
68
-	INVALID_BRACKET_EXPRESSION
4
+	UNEXPECTED_TOKEN(),
5
+	IMPORT_NOT_FOUND(),
6
+	NO_OUTER_BECAUSE_NOT_INNER(),
7
+	NO_OUTER_BECAUSE_STATIC(),
8
+	NO_OUTER_BECAUSE_OUTSIDE_TYPE(),
9
+	TYPE_ARGUMENTS_INVALID_NUMBER(),
10
+	TYPE_ARGUMENTS_NOT_INFERRABLE(),
11
+	USING_STATIC_ON_INSTANCE(),
12
+	CANNOT_ASSIGN(),
13
+	UNAVAILABLE_IN_CLOSURE(),
14
+	USING_PACKAGE_AS_EXPRESSION(),
15
+	USING_PACKAGE_AS_CALL_TARGET(),
16
+	USING_TYPE_AS_EXPRESSION(),
17
+	MEMBER_NO_SETTER(),
18
+	MEMBER_NO_GETTER(),
19
+	MEMBER_NOT_STATIC(),
20
+	MEMBER_IS_FINAL(),
21
+	MEMBER_DUPLICATE(),
22
+	CALL_AMBIGUOUS(),
23
+	CALL_NO_VALID_METHOD(),
24
+	ENUM_VALUE_DUPLICATE(),
25
+	INVALID_CAST(),
26
+	NO_SUCH_INNER_TYPE(),
27
+	NO_DOLLAR_HERE(),
28
+	UNSUPPORTED_XML_EXPRESSIONS(),
29
+	UNSUPPORTED_NAMED_ARGUMENTS(),
30
+	TYPE_CANNOT_UNITE(),
31
+	BRACKET_MULTIPLE_EXPRESSIONS(),
32
+	SUPER_CALL_NO_SUPERCLASS(),
33
+	LAMBDA_HEADER_INVALID(),
34
+	COALESCE_TARGET_NOT_OPTIONAL(),
35
+	MULTIPLE_MATCHING_HINTS(),
36
+	MISSING_MAP_KEY(),
37
+	NO_SUCH_MEMBER(),
38
+	USING_THIS_OUTSIDE_TYPE(),
39
+	USING_THIS_STATIC(),
40
+	UNDEFINED_VARIABLE(),
41
+	METHOD_BODY_REQUIRED(),
42
+	BREAK_OUTSIDE_LOOP(),
43
+	CONTINUE_OUTSIDE_LOOP(),
44
+	NO_SUCH_ITERATOR(),
45
+	NO_SUCH_TYPE(),
46
+	RETURN_VALUE_REQUIRED(),
47
+	RETURN_VALUE_VOID(),
48
+	INVALID_CONDITION(),
49
+	INTERNAL_ERROR(),
50
+	CANNOT_SET_FINAL_VARIABLE(),
51
+	MISSING_PARAMETER(),
52
+	STATEMENT_OUTSIDE_SWITCH_CASE(),
53
+	MISSING_VARIANT_CASEPARAMETERS(),
54
+	INVALID_SWITCH_CASE(),
55
+	TRY_CONVERT_OUTSIDE_FUNCTION(),
56
+	TRY_CONVERT_ILLEGAL_TARGET(),
57
+	TRY_RETHROW_NOT_A_RESULT(),
58
+	DIFFERENT_EXCEPTIONS(),
59
+	UNKNOWN_ANNOTATION(),
60
+	OVERRIDE_WITHOUT_BASE(),
61
+	OVERRIDE_AMBIGUOUS(),
62
+	OVERRIDE_CONSTRUCTOR(),
63
+	PRECOMPILE_FAILED(),
64
+	UNTYPED_EMPTY_ARRAY(),
65
+	UNTYPED_EMPTY_MAP(),
66
+	VAR_WITHOUT_TYPE_OR_INITIALIZER(),
67
+	NO_BRACKET_PARSER(),
68
+	INVALID_BRACKET_EXPRESSION()
69 69
 }

+ 22
- 32
Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java Ver fichero

@@ -1,39 +1,29 @@
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 1
 package org.openzen.zencode.shared;
7 2
 
8 3
 import java.io.IOException;
9 4
 import java.io.Reader;
10 5
 import java.io.StringReader;
11 6
 
12
-/**
13
- *
14
- * @author Hoofdgebruiker
15
- */
16
-public class LiteralSourceFile implements SourceFile {
17
-	private final String filename;
18
-	private final String contents;
19
-	
20
-	public LiteralSourceFile(String filename, String contents) {
21
-		this.filename = filename;
22
-		this.contents = contents;
23
-	}
24
-
25
-	@Override
26
-	public String getFilename() {
27
-		return filename;
28
-	}
29
-
30
-	@Override
31
-	public Reader open() throws IOException {
32
-		return new StringReader(contents);
33
-	}
34
-
35
-	@Override
36
-	public void update(String content) throws IOException {
37
-		throw new UnsupportedOperationException("Cannot update literal source files");
38
-	}
7
+public final class LiteralSourceFile implements SourceFile {
8
+    public final String filename;
9
+    private final String contents;
10
+    
11
+    public LiteralSourceFile(String filename, String contents) {
12
+        this.filename = filename;
13
+        this.contents = contents;
14
+    }
15
+    
16
+    @Override
17
+    public Reader open() throws IOException {
18
+        return new StringReader(contents);
19
+    }
20
+    
21
+    @Override
22
+    public void update(String contents) throws IOException {
23
+        throw new AssertionError("Cannot update literal source files");
24
+    }
25
+    
26
+    public String getFilename() {
27
+        return filename;
28
+    }
39 29
 }

+ 5
- 5
Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java Ver fichero

@@ -4,9 +4,9 @@ import java.io.IOException;
4 4
 import java.io.Reader;
5 5
 
6 6
 public interface SourceFile {
7
-	String getFilename();
8
-	
9
-	Reader open() throws IOException;
10
-	
11
-	void update(String content) throws IOException;
7
+    String getFilename();
8
+    
9
+    Reader open() throws IOException;
10
+    
11
+    void update(String content) throws IOException;
12 12
 }

+ 5
- 5
Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java Ver fichero

@@ -15,12 +15,12 @@ public final class VirtualSourceFile implements SourceFile {
15 15
         throw new AssertionError("Cannot open virtual source files");
16 16
     }
17 17
     
18
+    @Override
19
+    public void update(String content) throws IOException {
20
+        throw new AssertionError("Cannot write to virtual source files");
21
+    }
22
+    
18 23
     public String getFilename() {
19 24
         return filename;
20 25
     }
21
-
22
-	@Override
23
-	public void update(String content) throws IOException {
24
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
25
-	}
26 26
 }

+ 2
- 2
Shared/src/main/java/stdlib/Result.java Ver fichero

@@ -100,7 +100,7 @@ public abstract class Result<T, E> {
100 100
     public static class Ok<T, E> extends Result<T, E> {
101 101
         public final T value;
102 102
         
103
-        public Ok(T value){
103
+        public Ok(T value) {
104 104
             this.value = value;
105 105
         }
106 106
         
@@ -113,7 +113,7 @@ public abstract class Result<T, E> {
113 113
     public static class Error<T, E> extends Result<T, E> {
114 114
         public final E value;
115 115
         
116
-        public Error(E value){
116
+        public Error(E value) {
117 117
             this.value = value;
118 118
         }
119 119
         

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java Ver fichero

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

+ 9
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java Ver fichero

@@ -46,6 +46,7 @@ import org.openzen.zenscript.codemodel.expression.FunctionExpression;
46 46
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
47 47
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
48 48
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
49
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
49 50
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
50 51
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
51 52
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
@@ -353,6 +354,14 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
353 354
 		}
354 355
 		return null;
355 356
 	}
357
+	
358
+	@Override
359
+	public Void visitGetMatchingVariantField(GetMatchingVariantField expression) {
360
+		if (expression.index >= expression.value.parameters.length) {
361
+			validator.logError(ValidationLogEntry.Code.MATCHING_VARIANT_FIELD_INVALID, expression.position, "Invalid matching variant field");
362
+		}
363
+		return null;
364
+	}
356 365
 
357 366
 	@Override
358 367
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {

Loading…
Cancelar
Guardar