Sfoglia il codice sorgente

Refine storage tag implementation

Stan Hebben 6 anni fa
parent
commit
5eef4cd9ef
38 ha cambiato i file con 235 aggiunte e 78 eliminazioni
  1. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java
  2. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java
  3. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java
  4. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java
  5. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java
  6. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  7. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java
  8. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java
  9. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  10. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  11. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  12. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java
  13. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java
  14. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java
  15. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java
  16. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java
  17. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  18. 8
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java
  19. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StringTypeID.java
  20. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java
  21. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  22. 2
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java
  23. 9
    2
      IDE/src/main/java/org/openzen/zenscript/ide/Arguments.java
  24. 1
    11
      IDE/src/main/java/org/openzen/zenscript/ide/JavaBytecodeMain.java
  25. 14
    3
      IDE/src/main/java/org/openzen/zenscript/ide/Main.java
  26. 12
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java
  27. 15
    5
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnumConstant.java
  28. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java
  29. 4
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java
  30. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryRethrowExpression.java
  31. 11
    3
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedNamedType.java
  32. 1
    1
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  33. 30
    0
      Validator/src/main/java/org/openzen/zenscript/validator/TypeContext.java
  34. 6
    5
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  35. 3
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java
  36. 3
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java
  37. 27
    26
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java
  38. 3
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java Vedi File

@@ -28,7 +28,7 @@ import org.openzen.zenscript.codemodel.statement.Statement;
28 28
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
29 29
 import org.openzen.zenscript.codemodel.type.GenericName;
30 30
 import org.openzen.zenscript.codemodel.type.StringTypeID;
31
-import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
31
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
32 32
 
33 33
 /**
34 34
  *
@@ -52,7 +52,7 @@ public class PreconditionAnnotationDefinition implements AnnotationDefinition {
52 52
 	public List<FunctionHeader> getInitializers(BaseScope scope) {
53 53
 		return Collections.singletonList(new FunctionHeader(
54 54
 				BasicTypeID.VOID.stored,
55
-				scope.getType(CodePosition.BUILTIN, enforcementLevelName).stored(StaticStorageTag.INSTANCE),
55
+				scope.getType(CodePosition.BUILTIN, enforcementLevelName).stored(ValueStorageTag.INSTANCE),
56 56
 				BasicTypeID.BOOL.stored,
57 57
 				StringTypeID.UNIQUE));
58 58
 	}

+ 6
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java Vedi File

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.type.StoredType;
16 16
 import org.openzen.zenscript.codemodel.type.TypeID;
17 17
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
18 18
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
19
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
19 20
 
20 21
 /**
21 22
  *
@@ -68,6 +69,10 @@ public class LocalTypeResolutionContext implements TypeResolutionContext {
68 69
 	
69 70
 	@Override
70 71
 	public StoredType getThisType() {
71
-		return type == null ? null : getTypeRegistry().getForMyDefinition(type.load()).stored(BorrowStorageTag.THIS);
72
+		if (type == null)
73
+			return null;
74
+		
75
+		TypeID self = getTypeRegistry().getForMyDefinition(type.load());
76
+		return self.stored(self.isValueType() ? ValueStorageTag.INSTANCE : BorrowStorageTag.THIS);
72 77
 	}
73 78
 }

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java Vedi File

@@ -11,12 +11,14 @@ import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.Module;
13 13
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
14
+import org.openzen.zenscript.codemodel.type.TypeID;
14 15
 
15 16
 /**
16 17
  *
17 18
  * @author Hoofdgebruiker
18 19
  */
19 20
 public class EnumDefinition extends HighLevelDefinition {
21
+	public TypeID asType;
20 22
 	public List<EnumConstantMember> enumConstants = new ArrayList<>();
21 23
 	
22 24
 	public EnumDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java Vedi File

@@ -11,7 +11,7 @@ import org.openzen.zenscript.codemodel.member.EnumConstantMember;
11 11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 13
 import org.openzen.zenscript.codemodel.type.TypeID;
14
-import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
14
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
15 15
 
16 16
 /**
17 17
  *
@@ -21,13 +21,13 @@ public class EnumConstantExpression extends Expression {
21 21
 	public final EnumConstantMember value;
22 22
 	
23 23
 	public EnumConstantExpression(CodePosition position, TypeID type, EnumConstantMember value) {
24
-		super(position, type.stored(StaticStorageTag.INSTANCE), null);
24
+		super(position, type.stored(ValueStorageTag.INSTANCE), null);
25 25
 		
26 26
 		this.value = value;
27 27
 	}
28 28
 	
29 29
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
30
-		super(position, registry.getForDefinition(type).stored(StaticStorageTag.INSTANCE), null);
30
+		super(position, registry.getForDefinition(type).stored(ValueStorageTag.INSTANCE), null);
31 31
 		
32 32
 		this.value = value;
33 33
 	}

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

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.member;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.expression.Expression;
10 11
 import org.openzen.zenscript.codemodel.expression.NewExpression;
11 12
 
12 13
 /**
@@ -19,7 +20,8 @@ public class EnumConstantMember {
19 20
 	public final String name;
20 21
 	public final int ordinal;
21 22
 	
22
-	public NewExpression constructor;
23
+	public Expression value = null;
24
+	public NewExpression constructor = null;
23 25
 	
24 26
 	public EnumConstantMember(CodePosition position, HighLevelDefinition definition, String name, int ordinal) {
25 27
 		this.position = position;

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java Vedi File

@@ -34,6 +34,7 @@ import org.openzen.zenscript.codemodel.type.storage.StorageTag;
34 34
 import org.openzen.zenscript.codemodel.type.TypeID;
35 35
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
36 36
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
37
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
37 38
 
38 39
 /**
39 40
  *
@@ -59,7 +60,7 @@ public class DefinitionScope extends BaseScope {
59 60
 		Map<TypeParameter, TypeID> typeParameters = new HashMap<>();
60 61
 		if (definition instanceof ExpansionDefinition) {
61 62
 			ExpansionDefinition expansion = (ExpansionDefinition)definition;
62
-			type = expansion.target.stored(BorrowStorageTag.THIS);
63
+			type = expansion.target.stored(expansion.target.isValueType() ? ValueStorageTag.INSTANCE : BorrowStorageTag.THIS);
63 64
 			
64 65
 			for (TypeParameter parameter : expansion.typeParameters) {
65 66
 				genericParameters.put(parameter.name, parameter);
@@ -67,7 +68,7 @@ public class DefinitionScope extends BaseScope {
67 68
 			}
68 69
 		} else {
69 70
 			DefinitionTypeID definitionType = outer.getTypeRegistry().getForMyDefinition(definition);
70
-			type = definitionType.stored(BorrowStorageTag.THIS);
71
+			type = definitionType.stored(definitionType.isValueType() ? ValueStorageTag.INSTANCE : BorrowStorageTag.THIS);
71 72
 			
72 73
 			while (definitionType != null) {
73 74
 				for (TypeParameter parameter : definitionType.definition.typeParameters) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java Vedi File

@@ -60,6 +60,11 @@ public class ArrayTypeID implements TypeID {
60 60
 		return false;
61 61
 	}
62 62
 	
63
+	@Override
64
+	public boolean isValueType() {
65
+		return false;
66
+	}
67
+	
63 68
 	@Override
64 69
 	public boolean isDestructible() {
65 70
 		return elementType.type.isDestructible();

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java Vedi File

@@ -62,6 +62,11 @@ public class AssocTypeID implements TypeID {
62 62
 		return false;
63 63
 	}
64 64
 	
65
+	@Override
66
+	public boolean isValueType() {
67
+		return false;
68
+	}
69
+	
65 70
 	@Override
66 71
 	public boolean isDestructible() {
67 72
 		return keyType.isDestructible() || valueType.isDestructible();

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java Vedi File

@@ -81,6 +81,11 @@ public enum BasicTypeID implements TypeID {
81 81
 		return false;
82 82
 	}
83 83
 	
84
+	@Override
85
+	public boolean isValueType() {
86
+		return true;
87
+	}
88
+	
84 89
 	@Override
85 90
 	public boolean isDestructible() {
86 91
 		return false;

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java Vedi File

@@ -15,6 +15,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
15 15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
16 16
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
17 17
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
18
+import org.openzen.zenscript.codemodel.definition.StructDefinition;
18 19
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
19 20
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
20 21
 
@@ -172,6 +173,11 @@ public class DefinitionTypeID implements TypeID {
172 173
 	public boolean isConst() {
173 174
 		return false;
174 175
 	}
176
+	
177
+	@Override
178
+	public boolean isValueType() {
179
+		return definition instanceof StructDefinition || definition instanceof EnumDefinition;
180
+	}
175 181
 
176 182
 	@Override
177 183
 	public boolean isEnum() {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java Vedi File

@@ -61,6 +61,11 @@ public class FunctionTypeID implements TypeID {
61 61
 		return false;
62 62
 	}
63 63
 	
64
+	@Override
65
+	public boolean isValueType() {
66
+		return false;
67
+	}
68
+	
64 69
 	@Override
65 70
 	public boolean isDestructible() {
66 71
 		return false;

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java Vedi File

@@ -53,6 +53,11 @@ public class GenericMapTypeID implements TypeID {
53 53
 		return false;
54 54
 	}
55 55
 	
56
+	@Override
57
+	public boolean isValueType() {
58
+		return false;
59
+	}
60
+	
56 61
 	@Override
57 62
 	public boolean isDestructible() {
58 63
 		return value.isDestructible();

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java Vedi File

@@ -57,6 +57,11 @@ public class GenericTypeID implements TypeID {
57 57
 		return false;
58 58
 	}
59 59
 	
60
+	@Override
61
+	public boolean isValueType() {
62
+		return false;
63
+	}
64
+	
60 65
 	@Override
61 66
 	public boolean isDestructible() {
62 67
 		return false; // TODO: actually depends on the type..?

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java Vedi File

@@ -53,6 +53,11 @@ public class InvalidTypeID implements TypeID {
53 53
 		return false;
54 54
 	}
55 55
 	
56
+	@Override
57
+	public boolean isValueType() {
58
+		return false;
59
+	}
60
+	
56 61
 	@Override
57 62
 	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
58 63
 		return false;

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java Vedi File

@@ -76,6 +76,11 @@ public class IteratorTypeID implements TypeID {
76 76
 		return false;
77 77
 	}
78 78
 	
79
+	@Override
80
+	public boolean isValueType() {
81
+		return false;
82
+	}
83
+	
79 84
 	@Override
80 85
 	public TypeID instanceUnstored(GenericMapper mapper) {
81 86
 		StoredType[] instanced = mapper.map(iteratorTypes);

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java Vedi File

@@ -70,6 +70,11 @@ public class ModifiedTypeID implements TypeID {
70 70
 		return (modifiers & MODIFIER_CONST) > 0;
71 71
 	}
72 72
 	
73
+	@Override
74
+	public boolean isValueType() {
75
+		return baseType.isValueType();
76
+	}
77
+	
73 78
 	@Override
74 79
 	public boolean isDestructible() {
75 80
 		return baseType.isDestructible();

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java Vedi File

@@ -66,6 +66,11 @@ public class RangeTypeID implements TypeID {
66 66
 		return false;
67 67
 	}
68 68
 	
69
+	@Override
70
+	public boolean isValueType() {
71
+		return baseType.type.isValueType();
72
+	}
73
+	
69 74
 	@Override
70 75
 	public boolean isDestructible() {
71 76
 		return baseType.isDestructible();

+ 8
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java Vedi File

@@ -12,7 +12,9 @@ import org.openzen.zenscript.codemodel.GenericMapper;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14 14
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
15
+import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
15 16
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
17
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
16 18
 
17 19
 /**
18 20
  *
@@ -25,6 +27,11 @@ public class StoredType {
25 27
 	public final StorageTag storage;
26 28
 	
27 29
 	public StoredType(TypeID type, StorageTag storage) {
30
+		if (type.isValueType() && storage != ValueStorageTag.INSTANCE && storage != StaticExpressionStorageTag.INSTANCE)
31
+			throw new IllegalArgumentException("storage of a value type must be value");
32
+		if (!type.isValueType() && storage == ValueStorageTag.INSTANCE)
33
+			throw new IllegalArgumentException("storage of a nonvalue type cannot be value");
34
+		
28 35
 		this.type = type;
29 36
 		this.storage = storage;
30 37
 	}
@@ -40,7 +47,7 @@ public class StoredType {
40 47
 	
41 48
 	public StoredType instance(GenericMapper mapper) {
42 49
 		TypeID result = mapper.map(type);
43
-		return result == type ? this : new StoredType(result, storage);
50
+		return result == type ? this : new StoredType(result, result.isValueType() ? ValueStorageTag.INSTANCE : storage);
44 51
 	}
45 52
 	
46 53
 	public boolean isDestructible() {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StringTypeID.java Vedi File

@@ -60,6 +60,11 @@ public class StringTypeID implements TypeID {
60 60
 	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
61 61
 		return false;
62 62
 	}
63
+	
64
+	@Override
65
+	public boolean isValueType() {
66
+		return false;
67
+	}
63 68
 
64 69
 	@Override
65 70
 	public TypeID instanceUnstored(GenericMapper mapper) {

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java Vedi File

@@ -70,6 +70,8 @@ public interface TypeID {
70 70
 		return false;
71 71
 	}
72 72
 	
73
+	boolean isValueType();
74
+	
73 75
 	default TypeID withoutOptional() {
74 76
 		throw new UnsupportedOperationException("Not an optional type");
75 77
 	}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java Vedi File

@@ -507,7 +507,7 @@ public class TypeMemberBuilder implements TypeVisitorWithContext<Void, Void, Run
507 507
 			for (int i = 0; i < constValues.length; i++)
508 508
 				constValues[i] = new EnumConstantExpression(BUILTIN, definitionType, enumConstants.get(i));
509 509
 			
510
-			constant(definition, ENUM_VALUES, "values", new ArrayExpression(BUILTIN, constValues, registry.getArray(definitionType.stored(StaticStorageTag.INSTANCE), 1).stored(StaticStorageTag.INSTANCE)));
510
+			constant(definition, ENUM_VALUES, "values", new ArrayExpression(BUILTIN, constValues, registry.getArray(definitionType.stored(ValueStorageTag.INSTANCE), 1).stored(StaticStorageTag.INSTANCE)));
511 511
 			compare(definition, ENUM_COMPARE, type);
512 512
 			
513 513
 			if (!members.canCast(StringTypeID.STATIC)) {

+ 2
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java Vedi File

@@ -92,6 +92,8 @@ public class DScrollPane implements DComponent, DScrollContext {
92 92
 	
93 93
 	@Override
94 94
 	public void unmount() {
95
+		context = null;
96
+		
95 97
 		subSurface.close();
96 98
 		style.border.close();
97 99
 		

+ 9
- 2
IDE/src/main/java/org/openzen/zenscript/ide/Arguments.java Vedi File

@@ -13,15 +13,21 @@ import java.io.File;
13 13
  */
14 14
 public class Arguments {
15 15
 	public final File projectDirectory;
16
+	public final String defaultTarget;
16 17
 	
17
-	public Arguments(String[] arguments, File defaultProjectDir) {
18
-		File projectDir = defaultProjectDir;
18
+	public Arguments(String[] arguments) {
19
+		File projectDir = null;
20
+		String defaultTarget = null;
21
+		
19 22
 		int positional = 0;
20 23
 		for (int i = 0; i < arguments.length; i++) {
21 24
 			switch (positional) {
22 25
 				case 0:
23 26
 					projectDir = new File(arguments[0]);
24 27
 					break;
28
+				case 1:
29
+					defaultTarget = arguments[1];
30
+					break;
25 31
 				default:
26 32
 					throw new IllegalArgumentException("Too many arguments");
27 33
 			}
@@ -32,5 +38,6 @@ public class Arguments {
32 38
 			projectDir = projectDir.getParentFile();
33 39
 		
34 40
 		this.projectDirectory = projectDir;
41
+		this.defaultTarget = defaultTarget;
35 42
 	}
36 43
 }

+ 1
- 11
IDE/src/main/java/org/openzen/zenscript/ide/JavaBytecodeMain.java Vedi File

@@ -5,12 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide;
7 7
 
8
-import java.io.File;
9 8
 import java.io.IOException;
10
-import org.openzen.zenscript.constructor.Project;
11
-import static org.openzen.zenscript.ide.Main.open;
12
-import org.openzen.zenscript.ide.host.DevelopmentHost;
13
-import org.openzen.zenscript.ide.host.local.LocalProjectDevelopmentHost;
14 9
 
15 10
 /**
16 11
  *
@@ -21,11 +16,6 @@ public class JavaBytecodeMain {
21 16
      * @param args the command line arguments
22 17
      */
23 18
     public static void main(String[] args) throws IOException {
24
-		Arguments arguments = new Arguments(args, new File("../../ZenCode")); // TODO: remove this and open a project chooser/creator instead
25
-		File directory = arguments.projectDirectory;
26
-		
27
-		Project project = new Project(directory);
28
-		DevelopmentHost host = new LocalProjectDevelopmentHost(project);
29
-		open(host, "SharedJavaBytecode");
19
+		Main.main("../../ZenCode", "SharedJavaBytecode");
30 20
     }
31 21
 }

+ 14
- 3
IDE/src/main/java/org/openzen/zenscript/ide/Main.java Vedi File

@@ -17,18 +17,29 @@ public class Main {
17 17
     /**
18 18
      * @param args the command line arguments
19 19
      */
20
-    public static void main(String[] args) throws IOException {
21
-		Arguments arguments = new Arguments(args, new File("../../ZenCode")); // TODO: remove this and open a project chooser/creator instead
20
+    public static void main(String... args) throws IOException {
21
+		if (args.length == 0) {
22
+			// testing environment - TODO project chooser/creator
23
+			args = new String[] { "../../ZenCode", "SharedJavaSource" };
24
+		}
25
+		
26
+		Arguments arguments = new Arguments(args);
22 27
 		File directory = arguments.projectDirectory;
23 28
 		
24 29
 		Project project = new Project(directory);
25 30
 		DevelopmentHost host = new LocalProjectDevelopmentHost(project);
26
-		open(host, "SharedJavaSource");
31
+		open(host, arguments.defaultTarget);
27 32
     }
28 33
 	
29 34
 	public static void open(DevelopmentHost host, String target) {
30 35
 		IDEPropertyStore properties = host.getPropertyStore();
31 36
 		
37
+		IDEPropertyDirectory runState = properties.getRoot().getSubdirectory("runState");
38
+		if (target == null)
39
+			target = runState.getString("target", null);
40
+		if (target == null && host.getTargets().size() > 0)
41
+			target = host.getTargets().get(0).getName();
42
+		
32 43
 		IDEWindow window = new IDEWindow(host, target);
33 44
 		WindowView root = new WindowView(window, host);
34 45
 		

+ 12
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java Vedi File

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.TypeID;
22 22
 import org.openzen.zenscript.lexer.ParseException;
23 23
 import org.openzen.zenscript.parser.ParsedAnnotation;
24 24
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
25
+import org.openzen.zenscript.parser.type.IParsedType;
25 26
 
26 27
 /**
27 28
  *
@@ -30,9 +31,13 @@ import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
30 31
 public class ParsedEnum extends BaseParsedDefinition {
31 32
 	public static ParsedEnum parseEnum(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) throws ParseException {
32 33
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
34
+		IParsedType asType = null;
35
+		if (tokens.optional(ZSTokenType.K_AS) != null)
36
+			asType = IParsedType.parse(tokens);
37
+		
33 38
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
34 39
 		
35
-		ParsedEnum result = new ParsedEnum(pkg, position, modifiers, annotations, name, outerDefinition);
40
+		ParsedEnum result = new ParsedEnum(pkg, position, modifiers, annotations, name, outerDefinition, asType);
36 41
 		
37 42
 		while (!tokens.isNext(ZSTokenType.T_ACLOSE) && !tokens.isNext(ZSTokenType.T_SEMICOLON)) {
38 43
 			result.addEnumValue(ParsedEnumConstant.parse(tokens, result.compiled, result.enumValues.size()));
@@ -57,11 +62,13 @@ public class ParsedEnum extends BaseParsedDefinition {
57 62
 	
58 63
 	private final List<ParsedEnumConstant> enumValues = new ArrayList<>();
59 64
 	
65
+	private final IParsedType asType;
60 66
 	private final EnumDefinition compiled;
61 67
 	
62
-	public ParsedEnum(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, HighLevelDefinition outerDefinition) {
68
+	public ParsedEnum(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, HighLevelDefinition outerDefinition, IParsedType asType) {
63 69
 		super(position, modifiers, pkg, annotations);
64 70
 		
71
+		this.asType = asType;
65 72
 		compiled = new EnumDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
66 73
 	}
67 74
 	
@@ -76,6 +83,9 @@ public class ParsedEnum extends BaseParsedDefinition {
76 83
 	
77 84
 	@Override
78 85
 	protected void linkTypesLocal(TypeResolutionContext context) {
86
+		if (asType != null)
87
+			compiled.asType = asType.compileUnstored(context);
88
+		
79 89
 		for (ParsedEnumConstant constant : enumValues) {
80 90
 			compiled.addEnumConstant(constant.getCompiled());
81 91
 		}

+ 15
- 5
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnumConstant.java Vedi File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.parser.definitions;
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 13
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
13 14
 import org.openzen.zenscript.codemodel.expression.NewExpression;
@@ -17,7 +18,7 @@ import org.openzen.zenscript.lexer.ZSToken;
17 18
 import org.openzen.zenscript.lexer.ZSTokenParser;
18 19
 import org.openzen.zenscript.lexer.ZSTokenType;
19 20
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20
-import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
21
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
21 22
 import org.openzen.zenscript.lexer.ParseException;
22 23
 import org.openzen.zenscript.parser.expression.ParsedCallArguments;
23 24
 import org.openzen.zenscript.parser.expression.ParsedExpression;
@@ -44,19 +45,25 @@ public class ParsedEnumConstant {
44 45
 			}
45 46
 		}
46 47
 		
47
-		return new ParsedEnumConstant(position, definition, name.content, value, arguments);
48
+		ParsedExpression valueExpression = null;
49
+		if (tokens.optional(ZSTokenType.T_ASSIGN) != null)
50
+			valueExpression = ParsedExpression.parse(tokens);
51
+		
52
+		return new ParsedEnumConstant(position, definition, name.content, value, arguments, valueExpression);
48 53
 	}
49 54
 	
50 55
 	public final CodePosition position;
51 56
 	public final String name;
52 57
 	public final List<ParsedExpression> arguments;
58
+	public final ParsedExpression value;
53 59
 	
54 60
 	private final EnumConstantMember compiled;
55 61
 	
56
-	public ParsedEnumConstant(CodePosition position, HighLevelDefinition definition, String name, int value, List<ParsedExpression> arguments) {
62
+	public ParsedEnumConstant(CodePosition position, HighLevelDefinition definition, String name, int value, List<ParsedExpression> arguments, ParsedExpression expressionValue) {
57 63
 		this.position = position;
58 64
 		this.name = name;
59 65
 		this.arguments = arguments;
66
+		this.value = expressionValue;
60 67
 		
61 68
 		compiled = new EnumConstantMember(position, definition, name, value);
62 69
 	}
@@ -65,8 +72,11 @@ public class ParsedEnumConstant {
65 72
 		return compiled;
66 73
 	}
67 74
 	
68
-	public void compileCode(DefinitionTypeID type, ExpressionScope scope) {
75
+	public void compileCode(DefinitionTypeID type, ExpressionScope scope) throws CompileException {
69 76
 		ParsedCallArguments arguments = new ParsedCallArguments(null, this.arguments);
70
-		compiled.constructor = (NewExpression)ParsedNewExpression.compile(position, type.stored(StaticStorageTag.INSTANCE), arguments, scope);
77
+		compiled.constructor = (NewExpression)ParsedNewExpression.compile(position, type.stored(ValueStorageTag.INSTANCE), arguments, scope);
78
+		
79
+		if (value != null)
80
+			compiled.value = value.compile(scope).eval();
71 81
 	}
72 82
 }

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java Vedi File

@@ -116,7 +116,7 @@ public class ParsedFunctionHeader {
116 116
 		for (int i = 0; i < parameters.length; i++)
117 117
 			parameters[i] = this.parameters.get(i).compile(localContext);
118 118
 		
119
-		StorageTag storage = this.storage.resolve(position, context);
119
+		StorageTag storage = this.storage == ParsedStorageTag.NULL ? null : this.storage.resolve(position, context);
120 120
 		return new FunctionHeader(genericParameters, returnType, thrownType == null ? null : thrownType.compile(context), storage, parameters);
121 121
 	}
122 122
 }

+ 4
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java Vedi File

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16 16
 import org.openzen.zenscript.codemodel.type.TypeID;
17
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17 18
 import org.openzen.zenscript.parser.type.IParsedType;
18 19
 
19 20
 /**
@@ -42,8 +43,10 @@ public class ParsedExpressionMember extends ParsedExpression {
42 43
 				scope,
43 44
 				scope.hints,
44 45
 				new GenericName(this.member, typeParameters));
45
-		if (member == null)
46
+		if (member == null) {
47
+			TypeMembers members = scope.getTypeMembers(cValue.eval().type);
46 48
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
49
+		}
47 50
 		
48 51
 		return member;
49 52
 	}

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryRethrowExpression.java Vedi File

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 16
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
17 17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18 18
 import org.openzen.zenscript.codemodel.type.StoredType;
19
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
19 20
 
20 21
 /**
21 22
  *
@@ -50,7 +51,7 @@ public class ParsedTryRethrowExpression extends ParsedExpression {
50 51
 			if (cSource.type.type instanceof DefinitionTypeID) {
51 52
 				DefinitionTypeID sourceType = (DefinitionTypeID)cSource.type.type;
52 53
 				if (sourceType.definition == result) {
53
-					return new TryRethrowAsResultExpression(position, sourceType.typeArguments[0].stored(cSource.type.storage), cSource);
54
+					return new TryRethrowAsResultExpression(position, sourceType.typeArguments[0].stored(sourceType.typeArguments[0].isValueType() ? ValueStorageTag.INSTANCE : cSource.type.storage), cSource);
54 55
 				}
55 56
 			}
56 57
 			

+ 11
- 3
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedNamedType.java Vedi File

@@ -18,6 +18,9 @@ import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
18 18
 import org.openzen.zenscript.codemodel.type.StoredType;
19 19
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
20 20
 import org.openzen.zenscript.codemodel.type.TypeID;
21
+import org.openzen.zenscript.codemodel.type.storage.SharedStorageTag;
22
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
23
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageType;
21 24
 
22 25
 /**
23 26
  *
@@ -52,15 +55,20 @@ public class ParsedNamedType implements IParsedType {
52 55
 		for (ParsedNamePart namePart : name)
53 56
 			genericNames.add(namePart.compile(context));
54 57
 		
55
-		StorageTag storage = this.storage.resolve(position, context);
56 58
 		TypeID baseType = context.getType(position, genericNames);
57 59
 		if (baseType == null)
58
-			return new InvalidTypeID(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString()).stored(storage);
60
+			return new InvalidTypeID(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString()).stored(ValueStorageTag.INSTANCE);
59 61
 		
60 62
 		TypeID result = context.getTypeRegistry().getModified(modifiers, baseType);
61 63
 		if (result == null)
62
-			return new InvalidTypeID(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString()).stored(storage);
64
+			return new InvalidTypeID(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString()).stored(ValueStorageTag.INSTANCE);
63 65
 		
66
+		StorageTag storage;
67
+		if (this.storage == ParsedStorageTag.NULL) {
68
+			storage = result.isValueType() ? ValueStorageTag.INSTANCE : SharedStorageTag.INSTANCE;
69
+		} else {
70
+			storage = this.storage.resolve(position, context);
71
+		}
64 72
 		return result.stored(storage);
65 73
 	}
66 74
 	

+ 1
- 1
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java Vedi File

@@ -148,7 +148,7 @@ public class Main {
148 148
 				result.append(tokens.getLastWhitespace());
149 149
 			}
150 150
 			
151
-			return new ParsedExpressionString(position.until(tokens.getPosition()), result.toString());
151
+			return new ParsedExpressionString(position.until(tokens.getPosition()), result.toString(), false);
152 152
 		}
153 153
 	}
154 154
 }

+ 30
- 0
Validator/src/main/java/org/openzen/zenscript/validator/TypeContext.java Vedi File

@@ -0,0 +1,30 @@
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.validator;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public enum TypeContext {
13
+	PARAMETER_TYPE("parameter type"),
14
+	RETURN_TYPE("return type"),
15
+	FIELD_TYPE("field type"),
16
+	GETTER_TYPE("getter type"),
17
+	SETTER_TYPE("setter type"),
18
+	CASTER_TYPE("caster type"),
19
+	ITERATOR_TYPE("iterator type"),
20
+	EXPANSION_TARGET_TYPE("expansion target type"),
21
+	OPTION_MEMBER_TYPE("option member type"),
22
+	CAST_TARGET_TYPE("cast target type"),
23
+	TYPE_CHECK_TYPE("type check type");
24
+	
25
+	public final String display;
26
+	
27
+	TypeContext(String display) {
28
+		this.display = display;
29
+	}
30
+}

+ 6
- 5
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java Vedi File

@@ -45,6 +45,7 @@ import org.openzen.zenscript.validator.Validator;
45 45
 import org.openzen.zenscript.validator.analysis.ExpressionScope;
46 46
 import org.openzen.zenscript.validator.analysis.StatementScope;
47 47
 import org.openzen.zenscript.codemodel.type.TypeID;
48
+import org.openzen.zenscript.validator.TypeContext;
48 49
 
49 50
 /**
50 51
  *
@@ -97,7 +98,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
97 98
 					"Duplicate field name: " + member.name);
98 99
 		}
99 100
 		fieldNames.add(member.name);
100
-		new TypeValidator(validator, member.position).validate(member.type);
101
+		new TypeValidator(validator, member.position).validate(TypeContext.FIELD_TYPE, member.type);
101 102
 		
102 103
 		if (member.initializer != null) {
103 104
 			member.initializer.accept(new ExpressionValidator(validator, new FieldInitializerScope(member)));
@@ -156,7 +157,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
156 157
 	@Override
157 158
 	public Void visitGetter(GetterMember member) {
158 159
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
159
-		new TypeValidator(validator, member.position).validate(member.type);
160
+		new TypeValidator(validator, member.position).validate(TypeContext.GETTER_TYPE, member.type);
160 161
 		validateGetter(member, new MethodStatementScope(new FunctionHeader(member.type)));
161 162
 		return null;
162 163
 	}
@@ -164,7 +165,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
164 165
 	@Override
165 166
 	public Void visitSetter(SetterMember member) {
166 167
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
167
-		new TypeValidator(validator, member.position).validate(member.type);
168
+		new TypeValidator(validator, member.position).validate(TypeContext.SETTER_TYPE, member.type);
168 169
 		validateSetter(member, new MethodStatementScope(new FunctionHeader(BasicTypeID.VOID, member.parameter)));
169 170
 		return null;
170 171
 	}
@@ -190,7 +191,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
190 191
 
191 192
 	@Override
192 193
 	public Void visitCaster(CasterMember member) {
193
-		new TypeValidator(validator, member.position).validate(member.toType);
194
+		new TypeValidator(validator, member.position).validate(TypeContext.CASTER_TYPE, member.toType);
194 195
 		validateFunctional(member, new MethodStatementScope(member.header));
195 196
 		return null;
196 197
 	}
@@ -199,7 +200,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
199 200
 	public Void visitCustomIterator(IteratorMember member) {
200 201
 		TypeValidator typeValidator = new TypeValidator(validator, member.position);
201 202
 		for (StoredType type : member.getLoopVariableTypes())
202
-			typeValidator.validate(type);
203
+			typeValidator.validate(TypeContext.ITERATOR_TYPE, type);
203 204
 		
204 205
 		validateFunctional(member, new MethodStatementScope(new FunctionHeader(scope.getTypeRegistry().getIterator(member.getLoopVariableTypes()).stored(UniqueStorageTag.INSTANCE))));
205 206
 		return null;

+ 3
- 2
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java Vedi File

@@ -33,6 +33,7 @@ import org.openzen.zenscript.codemodel.type.TypeID;
33 33
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
34 34
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
35 35
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
36
+import org.openzen.zenscript.validator.TypeContext;
36 37
 import org.openzen.zenscript.validator.Validator;
37 38
 import org.openzen.zenscript.validator.analysis.StatementScope;
38 39
 
@@ -149,7 +150,7 @@ public class DefinitionValidator implements DefinitionVisitor<Void> {
149 150
 				definition.position,
150 151
 				"Invalid expansion modifier");
151 152
 		
152
-		definition.target.accept(new TypeValidator(validator, definition.position));
153
+		new TypeValidator(validator, definition.position).validate(TypeContext.EXPANSION_TARGET_TYPE, definition.target);
153 154
 		validateMembers(definition, DefinitionMemberContext.EXPANSION);
154 155
 		return null;
155 156
 	}
@@ -207,7 +208,7 @@ public class DefinitionValidator implements DefinitionVisitor<Void> {
207 208
 		ValidationUtils.validateIdentifier(validator, option.position, option.name);
208 209
 		TypeValidator typeValidator = new TypeValidator(validator, option.position);
209 210
 		for (StoredType type : option.types)
210
-			typeValidator.validate(type);
211
+			typeValidator.validate(TypeContext.OPTION_MEMBER_TYPE, type);
211 212
 	}
212 213
 	
213 214
 	private class SimpleTypeScope implements TypeScope {

+ 3
- 2
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java Vedi File

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
22 22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
23 23
 import org.openzen.zenscript.codemodel.type.StoredType;
24 24
 import org.openzen.zenscript.codemodel.type.StringTypeID;
25
+import org.openzen.zenscript.validator.TypeContext;
25 26
 import org.openzen.zenscript.validator.ValidationLogEntry;
26 27
 import org.openzen.zenscript.validator.Validator;
27 28
 import org.openzen.zenscript.validator.analysis.ExpressionScope;
@@ -330,7 +331,7 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
330 331
 	@Override
331 332
 	public Void visitInterfaceCast(InterfaceCastExpression expression) {
332 333
 		expression.value.accept(this);
333
-		new TypeValidator(validator, expression.position).validate(expression.type);
334
+		new TypeValidator(validator, expression.position).validate(TypeContext.CAST_TARGET_TYPE, expression.type);
334 335
 		return null;
335 336
 	}
336 337
 	
@@ -343,7 +344,7 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
343 344
 	@Override
344 345
 	public Void visitIs(IsExpression expression) {
345 346
 		expression.value.accept(this);
346
-		expression.isType.accept(new TypeValidator(validator, expression.position));
347
+		new TypeValidator(validator, expression.position).validate(TypeContext.TYPE_CHECK_TYPE, expression.isType);
347 348
 		return null;
348 349
 	}
349 350
 

+ 27
- 26
Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java Vedi File

@@ -22,14 +22,15 @@ import org.openzen.zenscript.codemodel.type.StringTypeID;
22 22
 import org.openzen.zenscript.codemodel.type.TypeID;
23 23
 import org.openzen.zenscript.validator.ValidationLogEntry;
24 24
 import org.openzen.zenscript.validator.Validator;
25
-import org.openzen.zenscript.codemodel.type.TypeVisitor;
25
+import org.openzen.zenscript.codemodel.type.TypeVisitorWithContext;
26 26
 import org.openzen.zenscript.codemodel.type.storage.InvalidStorageTag;
27
+import org.openzen.zenscript.validator.TypeContext;
27 28
 
28 29
 /**
29 30
  *
30 31
  * @author Hoofdgebruiker
31 32
  */
32
-public class TypeValidator implements TypeVisitor<Void> {
33
+public class TypeValidator implements TypeVisitorWithContext<TypeContext, Void, RuntimeException> {
33 34
 	private final Validator validator;
34 35
 	private final CodePosition position;
35 36
 	
@@ -38,100 +39,100 @@ public class TypeValidator implements TypeVisitor<Void> {
38 39
 		this.position = position;
39 40
 	}
40 41
 	
41
-	public void validate(StoredType type) {
42
+	public void validate(TypeContext context, StoredType type) {
42 43
 		if (type.storage instanceof InvalidStorageTag) {
43 44
 			InvalidStorageTag storage = (InvalidStorageTag)type.storage;
44 45
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, storage.position, storage.message);
45 46
 		}
46 47
 		
47
-		validate(type.type);
48
+		validate(context, type.type);
48 49
 	}
49 50
 	
50
-	public void validate(TypeID type) {
51
-		type.accept(this);
51
+	public void validate(TypeContext context, TypeID type) {
52
+		type.accept(context, this);
52 53
 	}
53 54
 
54 55
 	@Override
55
-	public Void visitBasic(BasicTypeID basic) {
56
+	public Void visitBasic(TypeContext context, BasicTypeID basic) {
56 57
 		if (basic == BasicTypeID.UNDETERMINED)
57
-			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, "type could not be determined");
58
+			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, context.display + " could not be determined");
58 59
 		
59 60
 		return null;
60 61
 	}
61 62
 	
62 63
 	@Override
63
-	public Void visitString(StringTypeID string) {
64
+	public Void visitString(TypeContext context, StringTypeID string) {
64 65
 		return null;
65 66
 	}
66 67
 
67 68
 	@Override
68
-	public Void visitArray(ArrayTypeID array) {
69
+	public Void visitArray(TypeContext context, ArrayTypeID array) {
69 70
 		if (array.dimension < 1) {
70 71
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, "array dimension must be at least 1");
71 72
 		} else if (array.dimension > 16) {
72 73
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, "array dimension must be at most 16");
73 74
 		}
74 75
 		
75
-		validate(array.elementType);
76
+		validate(context, array.elementType);
76 77
 		return null;
77 78
 	}
78 79
 
79 80
 	@Override
80
-	public Void visitAssoc(AssocTypeID assoc) {
81
-		validate(assoc.keyType);
82
-		validate(assoc.valueType);
81
+	public Void visitAssoc(TypeContext context, AssocTypeID assoc) {
82
+		validate(context, assoc.keyType);
83
+		validate(context, assoc.valueType);
83 84
 		
84 85
 		// TODO: does the keytype have == and hashcode operators?
85 86
 		return null;
86 87
 	}
87 88
 	
88 89
 	@Override
89
-	public Void visitInvalid(InvalidTypeID type) {
90
+	public Void visitInvalid(TypeContext context, InvalidTypeID type) {
90 91
 		validator.logError(ValidationLogEntry.Code.INVALID_TYPE, type.position, type.message);
91 92
 		return null;
92 93
 	}
93 94
 
94 95
 	@Override
95
-	public Void visitIterator(IteratorTypeID iterator) {
96
+	public Void visitIterator(TypeContext context, IteratorTypeID iterator) {
96 97
 		for (StoredType type : iterator.iteratorTypes)
97
-			validate(type);
98
+			validate(context, type);
98 99
 		
99 100
 		return null;
100 101
 	}
101 102
 
102 103
 	@Override
103
-	public Void visitFunction(FunctionTypeID function) {
104
+	public Void visitFunction(TypeContext context, FunctionTypeID function) {
104 105
 		ValidationUtils.validateHeader(validator, position, function.header);
105 106
 		return null;
106 107
 	}
107 108
 
108 109
 	@Override
109
-	public Void visitDefinition(DefinitionTypeID definition) {
110
+	public Void visitDefinition(TypeContext context, DefinitionTypeID definition) {
110 111
 		ValidationUtils.validateTypeArguments(validator, position, definition.definition.typeParameters, definition.typeArguments);
111 112
 		return null;
112 113
 	}
113 114
 
114 115
 	@Override
115
-	public Void visitGeneric(GenericTypeID generic) {
116
+	public Void visitGeneric(TypeContext context, GenericTypeID generic) {
116 117
 		return null;
117 118
 	}
118 119
 
119 120
 	@Override
120
-	public Void visitRange(RangeTypeID range) {
121
-		validate(range.baseType);
121
+	public Void visitRange(TypeContext context, RangeTypeID range) {
122
+		validate(context, range.baseType);
122 123
 		return null;
123 124
 	}
124 125
 
125 126
 	@Override
126
-	public Void visitModified(ModifiedTypeID type) {
127
+	public Void visitModified(TypeContext context, ModifiedTypeID type) {
127 128
 		// TODO: detect duplicate const
128
-		validate(type.baseType);
129
+		validate(context, type.baseType);
129 130
 		return null;
130 131
 	}
131 132
 
132 133
 	@Override
133
-	public Void visitGenericMap(GenericMapTypeID map) {
134
-		validate(map.value);
134
+	public Void visitGenericMap(TypeContext context, GenericMapTypeID map) {
135
+		validate(context, map.value);
135 136
 		return null;
136 137
 	}
137 138
 }

+ 3
- 2
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java Vedi File

@@ -29,6 +29,7 @@ import org.openzen.zenscript.validator.Validator;
29 29
 import org.openzen.zenscript.validator.analysis.ExpressionScope;
30 30
 import org.openzen.zenscript.codemodel.type.TypeID;
31 31
 import org.openzen.zenscript.codemodel.type.storage.InvalidStorageTag;
32
+import org.openzen.zenscript.validator.TypeContext;
32 33
 
33 34
 /**
34 35
  *
@@ -52,7 +53,7 @@ public class ValidationUtils {
52 53
 	
53 54
 	public static void validateHeader(Validator target, CodePosition position, FunctionHeader header) {
54 55
 		TypeValidator typeValidator = new TypeValidator(target, position);
55
-		typeValidator.validate(header.getReturnType());
56
+		typeValidator.validate(TypeContext.RETURN_TYPE, header.getReturnType());
56 57
 		
57 58
 		if (header.storage instanceof InvalidStorageTag) {
58 59
 			InvalidStorageTag invalid = (InvalidStorageTag)header.storage;
@@ -67,7 +68,7 @@ public class ValidationUtils {
67 68
 			}
68 69
 			
69 70
 			parameterNames.add(parameter.name);
70
-			typeValidator.validate(parameter.type);
71
+			typeValidator.validate(TypeContext.PARAMETER_TYPE, parameter.type);
71 72
 			
72 73
 			if (parameter.defaultValue != null) {
73 74
 				parameter.defaultValue.accept(new ExpressionValidator(target, new DefaultParameterValueExpressionScope()));

Loading…
Annulla
Salva