Browse Source

Refine storage tag implementation

Stan Hebben 6 years ago
parent
commit
5eef4cd9ef
38 changed files with 235 additions and 78 deletions
  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 View File

28
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
28
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
29
 import org.openzen.zenscript.codemodel.type.GenericName;
29
 import org.openzen.zenscript.codemodel.type.GenericName;
30
 import org.openzen.zenscript.codemodel.type.StringTypeID;
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
 	public List<FunctionHeader> getInitializers(BaseScope scope) {
52
 	public List<FunctionHeader> getInitializers(BaseScope scope) {
53
 		return Collections.singletonList(new FunctionHeader(
53
 		return Collections.singletonList(new FunctionHeader(
54
 				BasicTypeID.VOID.stored,
54
 				BasicTypeID.VOID.stored,
55
-				scope.getType(CodePosition.BUILTIN, enforcementLevelName).stored(StaticStorageTag.INSTANCE),
55
+				scope.getType(CodePosition.BUILTIN, enforcementLevelName).stored(ValueStorageTag.INSTANCE),
56
 				BasicTypeID.BOOL.stored,
56
 				BasicTypeID.BOOL.stored,
57
 				StringTypeID.UNIQUE));
57
 				StringTypeID.UNIQUE));
58
 	}
58
 	}

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

16
 import org.openzen.zenscript.codemodel.type.TypeID;
16
 import org.openzen.zenscript.codemodel.type.TypeID;
17
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
17
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
18
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
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
 	
69
 	
69
 	@Override
70
 	@Override
70
 	public StoredType getThisType() {
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 View File

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

11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
 import org.openzen.zenscript.codemodel.type.TypeID;
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
 	public final EnumConstantMember value;
21
 	public final EnumConstantMember value;
22
 	
22
 	
23
 	public EnumConstantExpression(CodePosition position, TypeID type, EnumConstantMember value) {
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
 		this.value = value;
26
 		this.value = value;
27
 	}
27
 	}
28
 	
28
 	
29
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
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
 		this.value = value;
32
 		this.value = value;
33
 	}
33
 	}

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

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

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

34
 import org.openzen.zenscript.codemodel.type.TypeID;
34
 import org.openzen.zenscript.codemodel.type.TypeID;
35
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
35
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
36
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
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
 		Map<TypeParameter, TypeID> typeParameters = new HashMap<>();
60
 		Map<TypeParameter, TypeID> typeParameters = new HashMap<>();
60
 		if (definition instanceof ExpansionDefinition) {
61
 		if (definition instanceof ExpansionDefinition) {
61
 			ExpansionDefinition expansion = (ExpansionDefinition)definition;
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
 			for (TypeParameter parameter : expansion.typeParameters) {
65
 			for (TypeParameter parameter : expansion.typeParameters) {
65
 				genericParameters.put(parameter.name, parameter);
66
 				genericParameters.put(parameter.name, parameter);
67
 			}
68
 			}
68
 		} else {
69
 		} else {
69
 			DefinitionTypeID definitionType = outer.getTypeRegistry().getForMyDefinition(definition);
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
 			while (definitionType != null) {
73
 			while (definitionType != null) {
73
 				for (TypeParameter parameter : definitionType.definition.typeParameters) {
74
 				for (TypeParameter parameter : definitionType.definition.typeParameters) {

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

60
 		return false;
60
 		return false;
61
 	}
61
 	}
62
 	
62
 	
63
+	@Override
64
+	public boolean isValueType() {
65
+		return false;
66
+	}
67
+	
63
 	@Override
68
 	@Override
64
 	public boolean isDestructible() {
69
 	public boolean isDestructible() {
65
 		return elementType.type.isDestructible();
70
 		return elementType.type.isDestructible();

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

62
 		return false;
62
 		return false;
63
 	}
63
 	}
64
 	
64
 	
65
+	@Override
66
+	public boolean isValueType() {
67
+		return false;
68
+	}
69
+	
65
 	@Override
70
 	@Override
66
 	public boolean isDestructible() {
71
 	public boolean isDestructible() {
67
 		return keyType.isDestructible() || valueType.isDestructible();
72
 		return keyType.isDestructible() || valueType.isDestructible();

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

81
 		return false;
81
 		return false;
82
 	}
82
 	}
83
 	
83
 	
84
+	@Override
85
+	public boolean isValueType() {
86
+		return true;
87
+	}
88
+	
84
 	@Override
89
 	@Override
85
 	public boolean isDestructible() {
90
 	public boolean isDestructible() {
86
 		return false;
91
 		return false;

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

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

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

61
 		return false;
61
 		return false;
62
 	}
62
 	}
63
 	
63
 	
64
+	@Override
65
+	public boolean isValueType() {
66
+		return false;
67
+	}
68
+	
64
 	@Override
69
 	@Override
65
 	public boolean isDestructible() {
70
 	public boolean isDestructible() {
66
 		return false;
71
 		return false;

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

53
 		return false;
53
 		return false;
54
 	}
54
 	}
55
 	
55
 	
56
+	@Override
57
+	public boolean isValueType() {
58
+		return false;
59
+	}
60
+	
56
 	@Override
61
 	@Override
57
 	public boolean isDestructible() {
62
 	public boolean isDestructible() {
58
 		return value.isDestructible();
63
 		return value.isDestructible();

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

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

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

53
 		return false;
53
 		return false;
54
 	}
54
 	}
55
 	
55
 	
56
+	@Override
57
+	public boolean isValueType() {
58
+		return false;
59
+	}
60
+	
56
 	@Override
61
 	@Override
57
 	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
62
 	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
58
 		return false;
63
 		return false;

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

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

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

70
 		return (modifiers & MODIFIER_CONST) > 0;
70
 		return (modifiers & MODIFIER_CONST) > 0;
71
 	}
71
 	}
72
 	
72
 	
73
+	@Override
74
+	public boolean isValueType() {
75
+		return baseType.isValueType();
76
+	}
77
+	
73
 	@Override
78
 	@Override
74
 	public boolean isDestructible() {
79
 	public boolean isDestructible() {
75
 		return baseType.isDestructible();
80
 		return baseType.isDestructible();

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

66
 		return false;
66
 		return false;
67
 	}
67
 	}
68
 	
68
 	
69
+	@Override
70
+	public boolean isValueType() {
71
+		return baseType.type.isValueType();
72
+	}
73
+	
69
 	@Override
74
 	@Override
70
 	public boolean isDestructible() {
75
 	public boolean isDestructible() {
71
 		return baseType.isDestructible();
76
 		return baseType.isDestructible();

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

12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
14
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
15
+import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
15
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
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
 	public final StorageTag storage;
27
 	public final StorageTag storage;
26
 	
28
 	
27
 	public StoredType(TypeID type, StorageTag storage) {
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
 		this.type = type;
35
 		this.type = type;
29
 		this.storage = storage;
36
 		this.storage = storage;
30
 	}
37
 	}
40
 	
47
 	
41
 	public StoredType instance(GenericMapper mapper) {
48
 	public StoredType instance(GenericMapper mapper) {
42
 		TypeID result = mapper.map(type);
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
 	public boolean isDestructible() {
53
 	public boolean isDestructible() {

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

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

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

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

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

507
 			for (int i = 0; i < constValues.length; i++)
507
 			for (int i = 0; i < constValues.length; i++)
508
 				constValues[i] = new EnumConstantExpression(BUILTIN, definitionType, enumConstants.get(i));
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
 			compare(definition, ENUM_COMPARE, type);
511
 			compare(definition, ENUM_COMPARE, type);
512
 			
512
 			
513
 			if (!members.canCast(StringTypeID.STATIC)) {
513
 			if (!members.canCast(StringTypeID.STATIC)) {

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

92
 	
92
 	
93
 	@Override
93
 	@Override
94
 	public void unmount() {
94
 	public void unmount() {
95
+		context = null;
96
+		
95
 		subSurface.close();
97
 		subSurface.close();
96
 		style.border.close();
98
 		style.border.close();
97
 		
99
 		

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

13
  */
13
  */
14
 public class Arguments {
14
 public class Arguments {
15
 	public final File projectDirectory;
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
 		int positional = 0;
22
 		int positional = 0;
20
 		for (int i = 0; i < arguments.length; i++) {
23
 		for (int i = 0; i < arguments.length; i++) {
21
 			switch (positional) {
24
 			switch (positional) {
22
 				case 0:
25
 				case 0:
23
 					projectDir = new File(arguments[0]);
26
 					projectDir = new File(arguments[0]);
24
 					break;
27
 					break;
28
+				case 1:
29
+					defaultTarget = arguments[1];
30
+					break;
25
 				default:
31
 				default:
26
 					throw new IllegalArgumentException("Too many arguments");
32
 					throw new IllegalArgumentException("Too many arguments");
27
 			}
33
 			}
32
 			projectDir = projectDir.getParentFile();
38
 			projectDir = projectDir.getParentFile();
33
 		
39
 		
34
 		this.projectDirectory = projectDir;
40
 		this.projectDirectory = projectDir;
41
+		this.defaultTarget = defaultTarget;
35
 	}
42
 	}
36
 }
43
 }

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

5
  */
5
  */
6
 package org.openzen.zenscript.ide;
6
 package org.openzen.zenscript.ide;
7
 
7
 
8
-import java.io.File;
9
 import java.io.IOException;
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
      * @param args the command line arguments
16
      * @param args the command line arguments
22
      */
17
      */
23
     public static void main(String[] args) throws IOException {
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 View File

17
     /**
17
     /**
18
      * @param args the command line arguments
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
 		File directory = arguments.projectDirectory;
27
 		File directory = arguments.projectDirectory;
23
 		
28
 		
24
 		Project project = new Project(directory);
29
 		Project project = new Project(directory);
25
 		DevelopmentHost host = new LocalProjectDevelopmentHost(project);
30
 		DevelopmentHost host = new LocalProjectDevelopmentHost(project);
26
-		open(host, "SharedJavaSource");
31
+		open(host, arguments.defaultTarget);
27
     }
32
     }
28
 	
33
 	
29
 	public static void open(DevelopmentHost host, String target) {
34
 	public static void open(DevelopmentHost host, String target) {
30
 		IDEPropertyStore properties = host.getPropertyStore();
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
 		IDEWindow window = new IDEWindow(host, target);
43
 		IDEWindow window = new IDEWindow(host, target);
33
 		WindowView root = new WindowView(window, host);
44
 		WindowView root = new WindowView(window, host);
34
 		
45
 		

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

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

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

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
13
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
13
 import org.openzen.zenscript.codemodel.expression.NewExpression;
14
 import org.openzen.zenscript.codemodel.expression.NewExpression;
17
 import org.openzen.zenscript.lexer.ZSTokenParser;
18
 import org.openzen.zenscript.lexer.ZSTokenParser;
18
 import org.openzen.zenscript.lexer.ZSTokenType;
19
 import org.openzen.zenscript.lexer.ZSTokenType;
19
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
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
 import org.openzen.zenscript.lexer.ParseException;
22
 import org.openzen.zenscript.lexer.ParseException;
22
 import org.openzen.zenscript.parser.expression.ParsedCallArguments;
23
 import org.openzen.zenscript.parser.expression.ParsedCallArguments;
23
 import org.openzen.zenscript.parser.expression.ParsedExpression;
24
 import org.openzen.zenscript.parser.expression.ParsedExpression;
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
 	public final CodePosition position;
55
 	public final CodePosition position;
51
 	public final String name;
56
 	public final String name;
52
 	public final List<ParsedExpression> arguments;
57
 	public final List<ParsedExpression> arguments;
58
+	public final ParsedExpression value;
53
 	
59
 	
54
 	private final EnumConstantMember compiled;
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
 		this.position = position;
63
 		this.position = position;
58
 		this.name = name;
64
 		this.name = name;
59
 		this.arguments = arguments;
65
 		this.arguments = arguments;
66
+		this.value = expressionValue;
60
 		
67
 		
61
 		compiled = new EnumConstantMember(position, definition, name, value);
68
 		compiled = new EnumConstantMember(position, definition, name, value);
62
 	}
69
 	}
65
 		return compiled;
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
 		ParsedCallArguments arguments = new ParsedCallArguments(null, this.arguments);
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 View File

116
 		for (int i = 0; i < parameters.length; i++)
116
 		for (int i = 0; i < parameters.length; i++)
117
 			parameters[i] = this.parameters.get(i).compile(localContext);
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
 		return new FunctionHeader(genericParameters, returnType, thrownType == null ? null : thrownType.compile(context), storage, parameters);
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 View File

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

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

16
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
16
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18
 import org.openzen.zenscript.codemodel.type.StoredType;
18
 import org.openzen.zenscript.codemodel.type.StoredType;
19
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
19
 
20
 
20
 /**
21
 /**
21
  *
22
  *
50
 			if (cSource.type.type instanceof DefinitionTypeID) {
51
 			if (cSource.type.type instanceof DefinitionTypeID) {
51
 				DefinitionTypeID sourceType = (DefinitionTypeID)cSource.type.type;
52
 				DefinitionTypeID sourceType = (DefinitionTypeID)cSource.type.type;
52
 				if (sourceType.definition == result) {
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 View File

18
 import org.openzen.zenscript.codemodel.type.StoredType;
18
 import org.openzen.zenscript.codemodel.type.StoredType;
19
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
19
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
20
 import org.openzen.zenscript.codemodel.type.TypeID;
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
 		for (ParsedNamePart namePart : name)
55
 		for (ParsedNamePart namePart : name)
53
 			genericNames.add(namePart.compile(context));
56
 			genericNames.add(namePart.compile(context));
54
 		
57
 		
55
-		StorageTag storage = this.storage.resolve(position, context);
56
 		TypeID baseType = context.getType(position, genericNames);
58
 		TypeID baseType = context.getType(position, genericNames);
57
 		if (baseType == null)
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
 		TypeID result = context.getTypeRegistry().getModified(modifiers, baseType);
62
 		TypeID result = context.getTypeRegistry().getModified(modifiers, baseType);
61
 		if (result == null)
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
 		return result.stored(storage);
72
 		return result.stored(storage);
65
 	}
73
 	}
66
 	
74
 	

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

148
 				result.append(tokens.getLastWhitespace());
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 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.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 View File

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

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

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

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

22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
23
 import org.openzen.zenscript.codemodel.type.StoredType;
23
 import org.openzen.zenscript.codemodel.type.StoredType;
24
 import org.openzen.zenscript.codemodel.type.StringTypeID;
24
 import org.openzen.zenscript.codemodel.type.StringTypeID;
25
+import org.openzen.zenscript.validator.TypeContext;
25
 import org.openzen.zenscript.validator.ValidationLogEntry;
26
 import org.openzen.zenscript.validator.ValidationLogEntry;
26
 import org.openzen.zenscript.validator.Validator;
27
 import org.openzen.zenscript.validator.Validator;
27
 import org.openzen.zenscript.validator.analysis.ExpressionScope;
28
 import org.openzen.zenscript.validator.analysis.ExpressionScope;
330
 	@Override
331
 	@Override
331
 	public Void visitInterfaceCast(InterfaceCastExpression expression) {
332
 	public Void visitInterfaceCast(InterfaceCastExpression expression) {
332
 		expression.value.accept(this);
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
 		return null;
335
 		return null;
335
 	}
336
 	}
336
 	
337
 	
343
 	@Override
344
 	@Override
344
 	public Void visitIs(IsExpression expression) {
345
 	public Void visitIs(IsExpression expression) {
345
 		expression.value.accept(this);
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
 		return null;
348
 		return null;
348
 	}
349
 	}
349
 
350
 

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

22
 import org.openzen.zenscript.codemodel.type.TypeID;
22
 import org.openzen.zenscript.codemodel.type.TypeID;
23
 import org.openzen.zenscript.validator.ValidationLogEntry;
23
 import org.openzen.zenscript.validator.ValidationLogEntry;
24
 import org.openzen.zenscript.validator.Validator;
24
 import org.openzen.zenscript.validator.Validator;
25
-import org.openzen.zenscript.codemodel.type.TypeVisitor;
25
+import org.openzen.zenscript.codemodel.type.TypeVisitorWithContext;
26
 import org.openzen.zenscript.codemodel.type.storage.InvalidStorageTag;
26
 import org.openzen.zenscript.codemodel.type.storage.InvalidStorageTag;
27
+import org.openzen.zenscript.validator.TypeContext;
27
 
28
 
28
 /**
29
 /**
29
  *
30
  *
30
  * @author Hoofdgebruiker
31
  * @author Hoofdgebruiker
31
  */
32
  */
32
-public class TypeValidator implements TypeVisitor<Void> {
33
+public class TypeValidator implements TypeVisitorWithContext<TypeContext, Void, RuntimeException> {
33
 	private final Validator validator;
34
 	private final Validator validator;
34
 	private final CodePosition position;
35
 	private final CodePosition position;
35
 	
36
 	
38
 		this.position = position;
39
 		this.position = position;
39
 	}
40
 	}
40
 	
41
 	
41
-	public void validate(StoredType type) {
42
+	public void validate(TypeContext context, StoredType type) {
42
 		if (type.storage instanceof InvalidStorageTag) {
43
 		if (type.storage instanceof InvalidStorageTag) {
43
 			InvalidStorageTag storage = (InvalidStorageTag)type.storage;
44
 			InvalidStorageTag storage = (InvalidStorageTag)type.storage;
44
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, storage.position, storage.message);
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
 	@Override
55
 	@Override
55
-	public Void visitBasic(BasicTypeID basic) {
56
+	public Void visitBasic(TypeContext context, BasicTypeID basic) {
56
 		if (basic == BasicTypeID.UNDETERMINED)
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
 		return null;
60
 		return null;
60
 	}
61
 	}
61
 	
62
 	
62
 	@Override
63
 	@Override
63
-	public Void visitString(StringTypeID string) {
64
+	public Void visitString(TypeContext context, StringTypeID string) {
64
 		return null;
65
 		return null;
65
 	}
66
 	}
66
 
67
 
67
 	@Override
68
 	@Override
68
-	public Void visitArray(ArrayTypeID array) {
69
+	public Void visitArray(TypeContext context, ArrayTypeID array) {
69
 		if (array.dimension < 1) {
70
 		if (array.dimension < 1) {
70
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, "array dimension must be at least 1");
71
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, "array dimension must be at least 1");
71
 		} else if (array.dimension > 16) {
72
 		} else if (array.dimension > 16) {
72
 			validator.logError(ValidationLogEntry.Code.INVALID_TYPE, position, "array dimension must be at most 16");
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
 		return null;
77
 		return null;
77
 	}
78
 	}
78
 
79
 
79
 	@Override
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
 		// TODO: does the keytype have == and hashcode operators?
85
 		// TODO: does the keytype have == and hashcode operators?
85
 		return null;
86
 		return null;
86
 	}
87
 	}
87
 	
88
 	
88
 	@Override
89
 	@Override
89
-	public Void visitInvalid(InvalidTypeID type) {
90
+	public Void visitInvalid(TypeContext context, InvalidTypeID type) {
90
 		validator.logError(ValidationLogEntry.Code.INVALID_TYPE, type.position, type.message);
91
 		validator.logError(ValidationLogEntry.Code.INVALID_TYPE, type.position, type.message);
91
 		return null;
92
 		return null;
92
 	}
93
 	}
93
 
94
 
94
 	@Override
95
 	@Override
95
-	public Void visitIterator(IteratorTypeID iterator) {
96
+	public Void visitIterator(TypeContext context, IteratorTypeID iterator) {
96
 		for (StoredType type : iterator.iteratorTypes)
97
 		for (StoredType type : iterator.iteratorTypes)
97
-			validate(type);
98
+			validate(context, type);
98
 		
99
 		
99
 		return null;
100
 		return null;
100
 	}
101
 	}
101
 
102
 
102
 	@Override
103
 	@Override
103
-	public Void visitFunction(FunctionTypeID function) {
104
+	public Void visitFunction(TypeContext context, FunctionTypeID function) {
104
 		ValidationUtils.validateHeader(validator, position, function.header);
105
 		ValidationUtils.validateHeader(validator, position, function.header);
105
 		return null;
106
 		return null;
106
 	}
107
 	}
107
 
108
 
108
 	@Override
109
 	@Override
109
-	public Void visitDefinition(DefinitionTypeID definition) {
110
+	public Void visitDefinition(TypeContext context, DefinitionTypeID definition) {
110
 		ValidationUtils.validateTypeArguments(validator, position, definition.definition.typeParameters, definition.typeArguments);
111
 		ValidationUtils.validateTypeArguments(validator, position, definition.definition.typeParameters, definition.typeArguments);
111
 		return null;
112
 		return null;
112
 	}
113
 	}
113
 
114
 
114
 	@Override
115
 	@Override
115
-	public Void visitGeneric(GenericTypeID generic) {
116
+	public Void visitGeneric(TypeContext context, GenericTypeID generic) {
116
 		return null;
117
 		return null;
117
 	}
118
 	}
118
 
119
 
119
 	@Override
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
 		return null;
123
 		return null;
123
 	}
124
 	}
124
 
125
 
125
 	@Override
126
 	@Override
126
-	public Void visitModified(ModifiedTypeID type) {
127
+	public Void visitModified(TypeContext context, ModifiedTypeID type) {
127
 		// TODO: detect duplicate const
128
 		// TODO: detect duplicate const
128
-		validate(type.baseType);
129
+		validate(context, type.baseType);
129
 		return null;
130
 		return null;
130
 	}
131
 	}
131
 
132
 
132
 	@Override
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
 		return null;
136
 		return null;
136
 	}
137
 	}
137
 }
138
 }

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

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

Loading…
Cancel
Save