Browse Source

- 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 6 years ago
parent
commit
f04850f397
30 changed files with 287 additions and 200 deletions
  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 View File

45
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
45
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
47
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
47
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
48
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
48
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
49
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
49
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
50
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
50
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
51
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
480
 	public ExpressionString visitGetLocalVariable(GetLocalVariableExpression expression) {
481
 	public ExpressionString visitGetLocalVariable(GetLocalVariableExpression expression) {
481
 		return new ExpressionString(expression.variable.name, ZenScriptOperator.PRIMARY);
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
 	@Override
490
 	@Override
485
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
491
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {

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

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

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

80
 	
80
 	
81
 	public T visitGetLocalVariable(GetLocalVariableExpression expression);
81
 	public T visitGetLocalVariable(GetLocalVariableExpression expression);
82
 	
82
 	
83
+	public T visitGetMatchingVariantField(GetMatchingVariantField expression);
84
+	
83
 	public T visitGetStaticField(GetStaticFieldExpression expression);
85
 	public T visitGetStaticField(GetStaticFieldExpression expression);
84
 	
86
 	
85
 	public T visitGetter(GetterExpression expression);
87
 	public T visitGetter(GetterExpression expression);

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

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.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 View File

6
 package org.openzen.zenscript.codemodel.expression.switchvalue;
6
 package org.openzen.zenscript.codemodel.expression.switchvalue;
7
 
7
 
8
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
8
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
9
-import org.openzen.zenscript.codemodel.statement.VarStatement;
10
 
9
 
11
 /**
10
 /**
12
  *
11
  *
14
  */
13
  */
15
 public class VariantOptionSwitchValue implements SwitchValue {
14
 public class VariantOptionSwitchValue implements SwitchValue {
16
 	public final VariantOptionRef option;
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
 		this.option = option;
19
 		this.option = option;
21
 		this.parameters = parameters;
20
 		this.parameters = parameters;
22
 	}
21
 	}

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java View File

17
 	public final CodePosition position;
17
 	public final CodePosition position;
18
 	public final HighLevelDefinition definition;
18
 	public final HighLevelDefinition definition;
19
 	public final String name;
19
 	public final String name;
20
-	public final int value;
20
+	public final int ordinal;
21
 	
21
 	
22
 	public NewExpression constructor;
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
 		this.position = position;
25
 		this.position = position;
26
 		this.definition = definition;
26
 		this.definition = definition;
27
 		this.name = name;
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 View File

16
 import org.openzen.zenscript.codemodel.GenericMapper;
16
 import org.openzen.zenscript.codemodel.GenericMapper;
17
 import org.openzen.zenscript.codemodel.expression.Expression;
17
 import org.openzen.zenscript.codemodel.expression.Expression;
18
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
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
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
21
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
20
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
22
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
21
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
23
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
35
 	
37
 	
36
 	public final List<ITypeID> hints;
38
 	public final List<ITypeID> hints;
37
 	public final Map<TypeParameter, ITypeID> genericInferenceMap;
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
 	public ExpressionScope(BaseScope outer) {
42
 	public ExpressionScope(BaseScope outer) {
41
 		this.outer = outer;
43
 		this.outer = outer;
70
 			List<ITypeID> hints,
72
 			List<ITypeID> hints,
71
 			Function<CodePosition, Expression> dollar,
73
 			Function<CodePosition, Expression> dollar,
72
 			Map<TypeParameter, ITypeID> genericInferenceMap,
74
 			Map<TypeParameter, ITypeID> genericInferenceMap,
73
-			Map<String, VarStatement> innerVariables) {
75
+			Map<String, Function<CodePosition, Expression>> innerVariables) {
74
 		this.outer = scope;
76
 		this.outer = scope;
75
 		this.hints = hints;
77
 		this.hints = hints;
76
 		this.dollar = dollar;
78
 		this.dollar = dollar;
79
 	}
81
 	}
80
 	
82
 	
81
 	public void addInnerVariable(VarStatement variable) {
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
 	public List<ITypeID> getResultTypeHints() {
91
 	public List<ITypeID> getResultTypeHints() {
121
 	@Override
127
 	@Override
122
 	public IPartialExpression get(CodePosition position, GenericName name) {
128
 	public IPartialExpression get(CodePosition position, GenericName name) {
123
 		if (name.hasNoArguments() && innerVariables.containsKey(name.name))
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
 		return outer.get(position, name);
132
 		return outer.get(position, name);
127
 	}
133
 	}

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

48
 	
48
 	
49
 	@Override
49
 	@Override
50
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
50
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
51
-		String className = getClassName(definition.position.filename);
51
+		String className = getClassName(definition.position.getFilename());
52
 		JavaScriptFile scriptFile = getScriptFile(className);
52
 		JavaScriptFile scriptFile = getScriptFile(className);
53
 		target.register(definition.name, definition.accept(new JavaDefinitionVisitor(scriptFile.classWriter)));
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 View File

90
     }
90
     }
91
 
91
 
92
     public static String calcClasName(CodePosition position) {
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
     public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
96
     public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
197
 
197
 
198
 		@Override
198
 		@Override
199
 		public Integer acceptEnumConstant(EnumConstantSwitchValue value) {
199
 		public Integer acceptEnumConstant(EnumConstantSwitchValue value) {
200
-			return value.constant.value;
200
+			return value.constant.ordinal;
201
 		}
201
 		}
202
 
202
 
203
 		@Override
203
 		@Override

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

1703
         javaWriter.label(label);
1703
         javaWriter.label(label);
1704
         return null;
1704
         return null;
1705
     }
1705
     }
1706
+	
1707
+	@Override
1708
+	public Void visitGetMatchingVariantField(GetMatchingVariantField expression) {
1709
+		throw new UnsupportedOperationException(); // TODO
1710
+	}
1706
 
1711
 
1707
     @Override
1712
     @Override
1708
     public Void visitGetStaticField(GetStaticFieldExpression expression) {
1713
     public Void visitGetStaticField(GetStaticFieldExpression expression) {

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

42
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
42
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
43
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
44
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
45
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
48
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
276
 		javaWriter.idec(expression.parameter.getTag(JavaParameterInfo.class).index);
277
 		javaWriter.idec(expression.parameter.getTag(JavaParameterInfo.class).index);
277
 		return null;
278
 		return null;
278
 	}
279
 	}
279
-
280
+	
280
 	@Override
281
 	@Override
281
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
282
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
282
 		javaWriter.idec(expression.variable.getTag(JavaLocalVariableInfo.class).local);
283
 		javaWriter.idec(expression.variable.getTag(JavaLocalVariableInfo.class).local);
283
 		return null;
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
 	@Override
292
 	@Override
287
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
293
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
288
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
294
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))

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

42
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
42
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
43
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
44
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
45
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
48
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
288
 		return null;
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
 	@Override
297
 	@Override
292
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
298
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
293
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
299
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))

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

83
 
83
 
84
     @Override
84
     @Override
85
     public byte[] visitEnum(EnumDefinition definition) {
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
         final Type superType;
88
         final Type superType;
89
         if (definition.getSuperType() == null)
89
         if (definition.getSuperType() == null)

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

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

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java View File

41
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
41
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
42
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
42
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
43
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
43
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
44
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
44
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
45
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
45
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
46
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
47
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
257
 		return false;
258
 		return false;
258
 	}
259
 	}
259
 
260
 
261
+	@Override
262
+	public Boolean visitGetMatchingVariantField(GetMatchingVariantField expression) {
263
+		return false;
264
+	}
265
+
260
 	@Override
266
 	@Override
261
 	public Boolean visitGetStaticField(GetStaticFieldExpression expression) {
267
 	public Boolean visitGetStaticField(GetStaticFieldExpression expression) {
262
 		return false;
268
 		return false;

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java View File

49
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
49
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
50
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
50
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
51
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
51
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
52
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
52
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
53
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
53
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
54
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
54
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
55
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
421
 		return new ExpressionString(expression.variable.name, JavaOperator.PRIMARY);
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
 	@Override
430
 	@Override
425
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
431
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
426
 		JavaSourceField field = expression.field.getTag(JavaSourceField.class);
432
 		JavaSourceField field = expression.field.getTag(JavaSourceField.class);

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

140
 				String header = switchValue == null ? "default:" : "case " + switchValue.option.getName() + ":";
140
 				String header = switchValue == null ? "default:" : "case " + switchValue.option.getName() + ":";
141
 				List<String> statements = new ArrayList<>();
141
 				List<String> statements = new ArrayList<>();
142
 				if (switchValue != null) {
142
 				if (switchValue != null) {
143
-					for (VarStatement var : switchValue.parameters) {
143
+					for (int i = 0; i < switchValue.parameters.length; i++) {
144
 						StringBuilder statementOutput = new StringBuilder();
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
 						if (variant.genericParameters != null && variant.genericParameters.length > 0) {
146
 						if (variant.genericParameters != null && variant.genericParameters.length > 0) {
147
 							statementOutput.append("<");
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
 									statementOutput.append(", ");
150
 									statementOutput.append(", ");
151
-								statementOutput.append(scope.type(variantType.typeParameters[i]));
151
+								statementOutput.append(scope.type(variantType.typeParameters[j]));
152
 							}
152
 							}
153
 							statementOutput.append(">");
153
 							statementOutput.append(">");
154
 						}
154
 						}

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

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

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

9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
10
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
-import org.openzen.zenscript.codemodel.scope.BaseScope;
13
 import org.openzen.zenscript.parser.type.IParsedType;
12
 import org.openzen.zenscript.parser.type.IParsedType;
14
 
13
 
15
 /**
14
 /**
18
  */
17
  */
19
 public class ParsedVariantOption {
18
 public class ParsedVariantOption {
20
 	public final String name;
19
 	public final String name;
20
+	public final int ordinal;
21
 	public final List<IParsedType> types;
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
 		this.name = name;
24
 		this.name = name;
25
+		this.ordinal = ordinal;
25
 		this.types = types;
26
 		this.types = types;
26
 	}
27
 	}
27
 	
28
 	
30
 		for (int i = 0; i < cTypes.length; i++)
31
 		for (int i = 0; i < cTypes.length; i++)
31
 			cTypes[i] = types.get(i).compile(context);
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 View File

21
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
21
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
22
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
22
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
23
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
23
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
24
-import org.openzen.zenscript.codemodel.statement.VarStatement;
25
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
24
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26
 import org.openzen.zenscript.codemodel.type.ITypeID;
25
 import org.openzen.zenscript.codemodel.type.ITypeID;
27
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
26
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
103
 			if (option == null)
102
 			if (option == null)
104
 				throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Variant option does not exist: " + name);
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
 			for (int i = 0; i < values.length; i++) {
106
 			for (int i = 0; i < values.length; i++) {
108
 				ParsedExpression argument = arguments.arguments.get(i);
107
 				ParsedExpression argument = arguments.arguments.get(i);
109
 				ParsedFunctionParameter lambdaHeader = argument.toLambdaParameter();
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
 			return new VariantOptionSwitchValue(option, values);
112
 			return new VariantOptionSwitchValue(option, values);

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

97
 			if (option.types.length > 0)
97
 			if (option.types.length > 0)
98
 				throw new CompileException(position, CompileExceptionCode.MISSING_VARIANT_CASEPARAMETERS, "Variant case is missing parameters");
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
 		} else {
101
 		} else {
102
 			throw new CompileException(position, CompileExceptionCode.INVALID_SWITCH_CASE, "Invalid switch case");
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 View File

14
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
14
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
15
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
15
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
-import org.openzen.zenscript.codemodel.statement.VarStatement;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20
-import org.openzen.zenscript.parser.PrecompilationState;
21
 
19
 
22
 /**
20
 /**
23
  *
21
  *
80
 			if (switchValue instanceof VariantOptionSwitchValue) {
78
 			if (switchValue instanceof VariantOptionSwitchValue) {
81
 				VariantOptionSwitchValue variantSwitchValue = (VariantOptionSwitchValue)switchValue;
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
 			Expression value = this.value.compile(innerScope).eval();
85
 			Expression value = this.value.compile(innerScope).eval();

+ 58
- 55
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
 import org.openzen.zencode.shared.CodePosition;
3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.VirtualSourceFile;
4
 
5
 
5
 public final class CodePosition {
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 View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
 public enum CompileExceptionCode {
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 View File

1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
7
 
2
 
8
 import java.io.IOException;
3
 import java.io.IOException;
9
 import java.io.Reader;
4
 import java.io.Reader;
10
 import java.io.StringReader;
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 View File

4
 import java.io.Reader;
4
 import java.io.Reader;
5
 
5
 
6
 public interface SourceFile {
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 View File

15
         throw new AssertionError("Cannot open virtual source files");
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
     public String getFilename() {
23
     public String getFilename() {
19
         return filename;
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 View File

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

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java View File

72
 		INVALID_OVERRIDE,
72
 		INVALID_OVERRIDE,
73
 		SUPERTYPE_NOT_DESTRUCTIBLE,
73
 		SUPERTYPE_NOT_DESTRUCTIBLE,
74
 		INVALID_IMPLEMENTATION_TYPE,
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 View File

46
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
46
 import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
47
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
47
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
48
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
48
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
49
+import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
49
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
50
 import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
50
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
51
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
51
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
52
 import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
353
 		}
354
 		}
354
 		return null;
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
 	@Override
366
 	@Override
358
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
367
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {

Loading…
Cancel
Save