Browse Source

- Fixed recursive errors in destructability test

- Fixed some more storage tag issues
- Added methods with storage tag requirements
Stan Hebben 6 years ago
parent
commit
b64fee8856
34 changed files with 191 additions and 44 deletions
  1. 17
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 15
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  3. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  4. 5
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  5. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java
  6. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java
  7. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  8. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  9. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  10. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java
  11. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java
  12. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java
  13. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java
  14. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java
  15. 8
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  16. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java
  17. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StringTypeID.java
  18. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java
  19. 5
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  20. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  21. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/AnyStorageType.java
  22. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/BorrowStorageType.java
  23. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/InvalidStorageTag.java
  24. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageType.java
  25. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StaticStorageType.java
  26. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/UniqueStorageType.java
  27. 19
    5
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java
  28. 6
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  29. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java
  30. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCast.java
  31. 4
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java
  32. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java
  33. 3
    10
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedStorageTag.java
  34. 6
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 17
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.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.member.LocalMemberCache;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.TypeID;
20
 import org.openzen.zenscript.codemodel.type.TypeID;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
21
 
22
 
22
 /**
23
 /**
23
  *
24
  *
28
 	private StoredType returnType;
29
 	private StoredType returnType;
29
 	public final FunctionParameter[] parameters;
30
 	public final FunctionParameter[] parameters;
30
 	public final StoredType thrownType;
31
 	public final StoredType thrownType;
32
+	public final StorageTag storage;
31
 	
33
 	
32
 	public final int minParameters;
34
 	public final int minParameters;
33
 	public final int maxParameters;
35
 	public final int maxParameters;
41
 		this.returnType = returnType;
43
 		this.returnType = returnType;
42
 		this.parameters = FunctionParameter.NONE;
44
 		this.parameters = FunctionParameter.NONE;
43
 		this.thrownType = null;
45
 		this.thrownType = null;
46
+		this.storage = null;
44
 		
47
 		
45
 		minParameters = 0;
48
 		minParameters = 0;
46
 		maxParameters = 0;
49
 		maxParameters = 0;
59
 		this.returnType = returnType;
62
 		this.returnType = returnType;
60
 		this.parameters = new FunctionParameter[parameterTypes.length];
63
 		this.parameters = new FunctionParameter[parameterTypes.length];
61
 		this.thrownType = null;
64
 		this.thrownType = null;
65
+		this.storage = null;
62
 		
66
 		
63
 		for (int i = 0; i < parameterTypes.length; i++)
67
 		for (int i = 0; i < parameterTypes.length; i++)
64
 			parameters[i] = new FunctionParameter(parameterTypes[i], null);
68
 			parameters[i] = new FunctionParameter(parameterTypes[i], null);
80
 		this.returnType = returnType;
84
 		this.returnType = returnType;
81
 		this.parameters = parameters;
85
 		this.parameters = parameters;
82
 		this.thrownType = null;
86
 		this.thrownType = null;
87
+		this.storage = null;
83
 		
88
 		
84
 		minParameters = getMinParameters(parameters);
89
 		minParameters = getMinParameters(parameters);
85
 		maxParameters = getMaxParameters(parameters);
90
 		maxParameters = getMaxParameters(parameters);
90
 		this(returnType.stored, parameters);
95
 		this(returnType.stored, parameters);
91
 	}
96
 	}
92
 	
97
 	
93
-	public FunctionHeader(TypeParameter[] typeParameters, StoredType returnType, StoredType thrownType, FunctionParameter... parameters) {
98
+	public FunctionHeader(TypeParameter[] typeParameters, StoredType returnType, StoredType thrownType, StorageTag storage, FunctionParameter... parameters) {
94
 		if (returnType == null)
99
 		if (returnType == null)
95
 			throw new NullPointerException();
100
 			throw new NullPointerException();
96
 		if (typeParameters == null)
101
 		if (typeParameters == null)
100
 		this.returnType = returnType;
105
 		this.returnType = returnType;
101
 		this.parameters = parameters;
106
 		this.parameters = parameters;
102
 		this.thrownType = thrownType;
107
 		this.thrownType = thrownType;
108
+		this.storage = storage;
103
 		
109
 		
104
 		minParameters = getMinParameters(parameters);
110
 		minParameters = getMinParameters(parameters);
105
 		maxParameters = getMaxParameters(parameters);
111
 		maxParameters = getMaxParameters(parameters);
134
 		FunctionParameter[] normalizedParameters = new FunctionParameter[parameters.length];
140
 		FunctionParameter[] normalizedParameters = new FunctionParameter[parameters.length];
135
 		for (int i = 0; i < normalizedParameters.length; i++)
141
 		for (int i = 0; i < normalizedParameters.length; i++)
136
 			normalizedParameters[i] = parameters[i].normalized(registry);
142
 			normalizedParameters[i] = parameters[i].normalized(registry);
137
-		return new FunctionHeader(typeParameters, returnType.getNormalized(), thrownType == null ? null : thrownType.getNormalized(), normalizedParameters);
143
+		return new FunctionHeader(typeParameters, returnType.getNormalized(), thrownType == null ? null : thrownType.getNormalized(), storage, normalizedParameters);
138
 	}
144
 	}
139
 	
145
 	
140
 	public int getNumberOfTypeParameters() {
146
 	public int getNumberOfTypeParameters() {
150
 	}
156
 	}
151
 	
157
 	
152
 	public FunctionHeader withReturnType(StoredType returnType) {
158
 	public FunctionHeader withReturnType(StoredType returnType) {
153
-		return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
159
+		return new FunctionHeader(typeParameters, returnType, thrownType, storage, parameters);
154
 	}
160
 	}
155
 	
161
 	
156
 	public FunctionHeader inferFromOverride(GlobalTypeRegistry registry, FunctionHeader overridden) {
162
 	public FunctionHeader inferFromOverride(GlobalTypeRegistry registry, FunctionHeader overridden) {
172
 			}
178
 			}
173
 		}
179
 		}
174
 		
180
 		
175
-		return new FunctionHeader(resultTypeParameters, resultReturnType, resultThrownType, resultParameters);
181
+		StorageTag resultStorage = this.storage;
182
+		if (resultStorage == null)
183
+			resultStorage = overridden.storage;
184
+		
185
+		return new FunctionHeader(resultTypeParameters, resultReturnType, resultThrownType, resultStorage, resultParameters);
176
 	}
186
 	}
177
 	
187
 	
178
 	public boolean matchesExactly(CallArguments arguments, TypeScope scope) {
188
 	public boolean matchesExactly(CallArguments arguments, TypeScope scope) {
382
 		for (int i = 0; i < parameters.length; i++) {
392
 		for (int i = 0; i < parameters.length; i++) {
383
 			parameters[i] = this.parameters[i].withGenericArguments(mapper);
393
 			parameters[i] = this.parameters[i].withGenericArguments(mapper);
384
 		}
394
 		}
385
-		return new FunctionHeader(typeParameters, returnType, thrownType == null ? null : thrownType.instance(mapper), parameters);
395
+		return new FunctionHeader(typeParameters, returnType, thrownType == null ? null : thrownType.instance(mapper), storage, parameters);
386
 	}
396
 	}
387
 	
397
 	
388
 	public FunctionHeader fillGenericArguments(GlobalTypeRegistry registry, TypeID[] arguments, GenericMapper typeParameterMapping) {
398
 	public FunctionHeader fillGenericArguments(GlobalTypeRegistry registry, TypeID[] arguments, GenericMapper typeParameterMapping) {
399
 		for (int i = 0; i < parameters.length; i++) {
409
 		for (int i = 0; i < parameters.length; i++) {
400
 			parameters[i] = this.parameters[i].withGenericArguments(mapper);
410
 			parameters[i] = this.parameters[i].withGenericArguments(mapper);
401
 		}
411
 		}
402
-		return new FunctionHeader(TypeParameter.NONE, returnType, thrownType == null ? null : thrownType.instance(mapper), parameters);
412
+		return new FunctionHeader(TypeParameter.NONE, returnType, thrownType == null ? null : thrownType.instance(mapper), storage, parameters);
403
 	}
413
 	}
404
 	
414
 	
405
 	public FunctionHeader forTypeParameterInference() {
415
 	public FunctionHeader forTypeParameterInference() {
411
 		for (int i = 0; i < lambdaHeader.parameters.length; i++)
421
 		for (int i = 0; i < lambdaHeader.parameters.length; i++)
412
 			parameters[i] = new FunctionParameter(this.parameters[i].type, lambdaHeader.parameters[i].name);
422
 			parameters[i] = new FunctionParameter(this.parameters[i].type, lambdaHeader.parameters[i].name);
413
 		
423
 		
414
-		return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
424
+		return new FunctionHeader(typeParameters, returnType, thrownType, storage, parameters);
415
 	}
425
 	}
416
 	
426
 	
417
 	public FunctionParameter getVariadicParameter() {
427
 	public FunctionParameter getVariadicParameter() {

+ 15
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java View File

6
 package org.openzen.zenscript.codemodel;
6
 package org.openzen.zenscript.codemodel;
7
 
7
 
8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
+import java.util.HashSet;
9
 import java.util.List;
10
 import java.util.List;
11
+import java.util.Set;
10
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.Taggable;
13
 import org.openzen.zencode.shared.Taggable;
12
 import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation;
14
 import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation;
113
 	}
115
 	}
114
 	
116
 	
115
 	public boolean isDestructible() {
117
 	public boolean isDestructible() {
118
+		Set<HighLevelDefinition> scanning = new HashSet<>();
119
+		return isDestructible(scanning);
120
+	}
121
+	
122
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
123
+		if (scanning.contains(this))
124
+			return false;
125
+		
126
+		scanning.add(this);
127
+		
116
 		boolean isDestructible = false;
128
 		boolean isDestructible = false;
117
 		for (IDefinitionMember member : members) {
129
 		for (IDefinitionMember member : members) {
118
 			if (member instanceof DestructorMember)
130
 			if (member instanceof DestructorMember)
119
 				isDestructible = true;
131
 				isDestructible = true;
120
 			if (member instanceof FieldMember) {
132
 			if (member instanceof FieldMember) {
121
 				FieldMember field = (FieldMember)member;
133
 				FieldMember field = (FieldMember)member;
122
-				if (!field.type.isDefinition(this) && field.type.isDestructible())
134
+				if (field.type.isDestructible(scanning))
123
 					isDestructible = true;
135
 					isDestructible = true;
124
 			}
136
 			}
125
 			if ((member instanceof ImplementationMember) && ((ImplementationMember)member).type.isDestructible())
137
 			if ((member instanceof ImplementationMember) && ((ImplementationMember)member).type.isDestructible())
126
 				isDestructible = true;
138
 				isDestructible = true;
127
 		}
139
 		}
140
+		
141
+		scanning.remove(this);
128
 		return isDestructible;
142
 		return isDestructible;
129
 	}
143
 	}
130
 	
144
 	

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

38
 				position,
38
 				position,
39
 				definition,
39
 				definition,
40
 				modifiers,
40
 				modifiers,
41
-				new FunctionHeader(header.typeParameters, BasicTypeID.VOID.stored, header.thrownType, header.parameters),
41
+				new FunctionHeader(header.typeParameters, BasicTypeID.VOID.stored, header.thrownType, header.storage, header.parameters),
42
 				builtin);
42
 				builtin);
43
 	}
43
 	}
44
 	
44
 	

+ 5
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java View File

32
 	private final BaseScope outer;
32
 	private final BaseScope outer;
33
 	private final FunctionHeader header;
33
 	private final FunctionHeader header;
34
 	private final GenericMapper typeParameterMap;
34
 	private final GenericMapper typeParameterMap;
35
+	private final StoredType thisType;
35
 	
36
 	
36
 	public FunctionScope(BaseScope outer, FunctionHeader header) {
37
 	public FunctionScope(BaseScope outer, FunctionHeader header) {
37
 		this.outer = outer;
38
 		this.outer = outer;
38
 		this.header = header;
39
 		this.header = header;
40
+		this.thisType = outer.getThisType() == null || header.storage == null ? outer.getThisType() : outer.getThisType().type.stored(header.storage);
41
+		if (header.storage != null)
42
+			System.out.println("Storage is " + header.storage);
39
 		
43
 		
40
 		if (outer.getLocalTypeParameters() == null)
44
 		if (outer.getLocalTypeParameters() == null)
41
 			throw new NullPointerException();
45
 			throw new NullPointerException();
105
 
109
 
106
 	@Override
110
 	@Override
107
 	public StoredType getThisType() {
111
 	public StoredType getThisType() {
108
-		return outer.getThisType();
112
+		return thisType;
109
 	}
113
 	}
110
 
114
 
111
 	@Override
115
 	@Override

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Set;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 
13
 
12
 /**
14
 /**
63
 		return elementType.type.isDestructible();
65
 		return elementType.type.isDestructible();
64
 	}
66
 	}
65
 	
67
 	
68
+	@Override
69
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
70
+		return elementType.type.isDestructible(scanning);
71
+	}
72
+	
66
 	@Override
73
 	@Override
67
 	public ArrayTypeID instanceUnstored(GenericMapper mapper) {
74
 	public ArrayTypeID instanceUnstored(GenericMapper mapper) {
68
 		return mapper.registry.getArray(elementType.instance(mapper), dimension);
75
 		return mapper.registry.getArray(elementType.instance(mapper), dimension);

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Set;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 
13
 
12
 /**
14
 /**
65
 		return keyType.isDestructible() || valueType.isDestructible();
67
 		return keyType.isDestructible() || valueType.isDestructible();
66
 	}
68
 	}
67
 	
69
 	
70
+	@Override
71
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
72
+		return keyType.isDestructible(scanning) || valueType.isDestructible(scanning);
73
+	}
74
+	
68
 	@Override
75
 	@Override
69
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
76
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
70
 		return keyType.hasInferenceBlockingTypeParameters(parameters) || valueType.hasInferenceBlockingTypeParameters(parameters);
77
 		return keyType.hasInferenceBlockingTypeParameters(parameters) || valueType.hasInferenceBlockingTypeParameters(parameters);

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

7
 
7
 
8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
14
 import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
13
 
15
 
83
 	public boolean isDestructible() {
85
 	public boolean isDestructible() {
84
 		return false;
86
 		return false;
85
 	}
87
 	}
88
+	
89
+	@Override
90
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
91
+		return false;
92
+	}
86
 
93
 
87
 	@Override
94
 	@Override
88
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
95
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

10
 import java.util.List;
10
 import java.util.List;
11
 import java.util.Map;
11
 import java.util.Map;
12
 import java.util.Objects;
12
 import java.util.Objects;
13
+import java.util.Set;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
16
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
187
 		return definition.isDestructible();
188
 		return definition.isDestructible();
188
 	}
189
 	}
189
 	
190
 	
191
+	@Override
192
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
193
+		return definition.isDestructible(scanning);
194
+	}
195
+	
190
 	@Override
196
 	@Override
191
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
197
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
192
 		if (hasTypeParameters()) {
198
 		if (hasTypeParameters()) {

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

7
 
7
 
8
 import java.util.Arrays;
8
 import java.util.Arrays;
9
 import java.util.List;
9
 import java.util.List;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
16
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
15
 import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
17
 import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
63
 	public boolean isDestructible() {
65
 	public boolean isDestructible() {
64
 		return false;
66
 		return false;
65
 	}
67
 	}
68
+	
69
+	@Override
70
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
71
+		return false;
72
+	}
66
 
73
 
67
 	@Override
74
 	@Override
68
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
75
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
 import java.util.Objects;
9
 import java.util.Objects;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 
14
 
13
 /**
15
 /**
56
 		return value.isDestructible();
58
 		return value.isDestructible();
57
 	}
59
 	}
58
 	
60
 	
61
+	@Override
62
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
63
+		return value.isDestructible(scanning);
64
+	}
65
+	
59
 	@Override
66
 	@Override
60
 	public TypeID instanceUnstored(GenericMapper mapper) {
67
 	public TypeID instanceUnstored(GenericMapper mapper) {
61
 		return mapper.registry.getGenericMap(value.instance(mapper), key);
68
 		return mapper.registry.getGenericMap(value.instance(mapper), key);

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Set;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
12
 
14
 
60
 		return false; // TODO: actually depends on the type..?
62
 		return false; // TODO: actually depends on the type..?
61
 	}
63
 	}
62
 	
64
 	
65
+	@Override
66
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
67
+		return false; // TODO: actually depends on the type..?
68
+	}
69
+	
63
 	@Override
70
 	@Override
64
 	public boolean isGeneric() {
71
 	public boolean isGeneric() {
65
 		return true;
72
 		return true;

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Set;
9
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
13
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 
15
 
14
 /**
16
 /**
50
 	public boolean isDestructible() {
52
 	public boolean isDestructible() {
51
 		return false;
53
 		return false;
52
 	}
54
 	}
55
+	
56
+	@Override
57
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
58
+		return false;
59
+	}
53
 
60
 
54
 	@Override
61
 	@Override
55
 	public TypeID getNormalizedUnstored() {
62
 	public TypeID getNormalizedUnstored() {

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

7
 
7
 
8
 import java.util.Arrays;
8
 import java.util.Arrays;
9
 import java.util.List;
9
 import java.util.List;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 
14
 
13
 /**
15
 /**
69
 		return false;
71
 		return false;
70
 	}
72
 	}
71
 	
73
 	
74
+	@Override
75
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
76
+		return false;
77
+	}
78
+	
72
 	@Override
79
 	@Override
73
 	public TypeID instanceUnstored(GenericMapper mapper) {
80
 	public TypeID instanceUnstored(GenericMapper mapper) {
74
 		StoredType[] instanced = mapper.map(iteratorTypes);
81
 		StoredType[] instanced = mapper.map(iteratorTypes);

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

7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
 import java.util.Objects;
9
 import java.util.Objects;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13
 
15
 
73
 		return baseType.isDestructible();
75
 		return baseType.isDestructible();
74
 	}
76
 	}
75
 	
77
 	
78
+	@Override
79
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
80
+		return baseType.isDestructible(scanning);
81
+	}
82
+	
76
 	@Override
83
 	@Override
77
 	public TypeID withoutOptional() {
84
 	public TypeID withoutOptional() {
78
 		return without(MODIFIER_OPTIONAL);
85
 		return without(MODIFIER_OPTIONAL);

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Set;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
13
 import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
12
 
14
 
66
 	
68
 	
67
 	@Override
69
 	@Override
68
 	public boolean isDestructible() {
70
 	public boolean isDestructible() {
69
-		return false;
71
+		return baseType.isDestructible();
72
+	}
73
+	
74
+	@Override
75
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
76
+		return baseType.isDestructible(scanning);
70
 	}
77
 	}
71
 
78
 
72
 	@Override
79
 	@Override

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

7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
 import java.util.Objects;
9
 import java.util.Objects;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
46
 		return type.isDestructible() && storage.isDestructible();
47
 		return type.isDestructible() && storage.isDestructible();
47
 	}
48
 	}
48
 	
49
 	
50
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
51
+		return type.isDestructible(scanning) && storage.isDestructible();
52
+	}
53
+	
49
 	public boolean hasDefaultValue() {
54
 	public boolean hasDefaultValue() {
50
 		return type.hasDefaultValue();
55
 		return type.hasDefaultValue();
51
 	}
56
 	}

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Set;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.type.storage.AnyStorageTag;
13
 import org.openzen.zenscript.codemodel.type.storage.AnyStorageTag;
12
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
14
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
53
 	public boolean isDestructible() {
55
 	public boolean isDestructible() {
54
 		return false;
56
 		return false;
55
 	}
57
 	}
58
+	
59
+	@Override
60
+	public boolean isDestructible(Set<HighLevelDefinition> scanning) {
61
+		return false;
62
+	}
56
 
63
 
57
 	@Override
64
 	@Override
58
 	public TypeID instanceUnstored(GenericMapper mapper) {
65
 	public TypeID instanceUnstored(GenericMapper mapper) {

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

7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
 import java.util.Map;
9
 import java.util.Map;
10
+import java.util.Set;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
31
 	
32
 	
32
 	boolean isDestructible();
33
 	boolean isDestructible();
33
 	
34
 	
35
+	boolean isDestructible(Set<HighLevelDefinition> scanning);
36
+	
34
 	boolean hasDefaultValue();
37
 	boolean hasDefaultValue();
35
 	
38
 	
36
 	boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
39
 	boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);

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

291
 					new TypeParameter[] { mappedConstructorParameter },
291
 					new TypeParameter[] { mappedConstructorParameter },
292
 					VOID.stored,
292
 					VOID.stored,
293
 					null,
293
 					null,
294
+					null,
294
 					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter).stored(BorrowStorageTag.INVOCATION), dimension).stored(BorrowStorageTag.INVOCATION), "original"),
295
 					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter).stored(BorrowStorageTag.INVOCATION), dimension).stored(BorrowStorageTag.INVOCATION), "original"),
295
 					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithoutIndex).stored(BorrowStorageTag.INVOCATION), "projection"));
296
 					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithoutIndex).stored(BorrowStorageTag.INVOCATION), "projection"));
296
 			members.addConstructor(new ConstructorMember(
297
 			members.addConstructor(new ConstructorMember(
313
 					new TypeParameter[] { mappedConstructorParameter },
314
 					new TypeParameter[] { mappedConstructorParameter },
314
 					VOID.stored,
315
 					VOID.stored,
315
 					null,
316
 					null,
317
+					null,
316
 					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter).stored(BorrowStorageTag.INVOCATION), dimension).stored(BorrowStorageTag.INVOCATION), "original"),
318
 					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter).stored(BorrowStorageTag.INVOCATION), dimension).stored(BorrowStorageTag.INVOCATION), "original"),
317
 					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithIndex).stored(BorrowStorageTag.INVOCATION), "projection"));
319
 					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithIndex).stored(BorrowStorageTag.INVOCATION), "projection"));
318
 			constructor(definition, ARRAY_CONSTRUCTOR_PROJECTED_INDEXED, mappedConstructorFunctionWithIndex);
320
 			constructor(definition, ARRAY_CONSTRUCTOR_PROJECTED_INDEXED, mappedConstructorFunctionWithIndex);
388
 		Map<TypeParameter, TypeID> parameterFilled = Collections.singletonMap(map.key, registry.getGeneric(functionParameter));
390
 		Map<TypeParameter, TypeID> parameterFilled = Collections.singletonMap(map.key, registry.getGeneric(functionParameter));
389
 		StoredType valueType = map.value.instance(new GenericMapper(registry, parameterFilled));
391
 		StoredType valueType = map.value.instance(new GenericMapper(registry, parameterFilled));
390
 		
392
 		
391
-		FunctionHeader getOptionalHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, registry.getOptional(valueType.type).stored(valueType.storage), null, new FunctionParameter[0]);
392
-		FunctionHeader putHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, VOID.stored, null, new FunctionParameter(valueType));
393
-		FunctionHeader containsHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, BOOL.stored, null, new FunctionParameter[0]);
393
+		FunctionHeader getOptionalHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, registry.getOptional(valueType.type).stored(valueType.storage), null, null, new FunctionParameter[0]);
394
+		FunctionHeader putHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, VOID.stored, null, null, new FunctionParameter(valueType));
395
+		FunctionHeader containsHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, BOOL.stored, null, null, new FunctionParameter[0]);
394
 		
396
 		
395
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT);
397
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT);
396
 		constructor(builtin, GENERICMAP_CONSTRUCTOR);
398
 		constructor(builtin, GENERICMAP_CONSTRUCTOR);

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

492
 				return castEquivalent(position, caster.member.cast(position, value, implicit), toType);
492
 				return castEquivalent(position, caster.member.cast(position, value, implicit), toType);
493
 		}
493
 		}
494
 		for (TypeMember<ImplementationMemberRef> implementation : implementations) {
494
 		for (TypeMember<ImplementationMemberRef> implementation : implementations) {
495
-			if (implementation.member.implementsType.equals(toType))
496
-				return new InterfaceCastExpression(position, value, toType);
495
+			if (implementation.member.implementsType.equals(toType.type))
496
+				return castEquivalent(position, new InterfaceCastExpression(position, value, toType.type.stored(type.storage)), toType);
497
 		}
497
 		}
498
 		if (extendsType(toType.type))
498
 		if (extendsType(toType.type))
499
 			return new SupertypeCastExpression(position, value, toType);
499
 			return new SupertypeCastExpression(position, value, toType);

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

25
 
25
 
26
 	@Override
26
 	@Override
27
 	public StorageTag instance(CodePosition position, String[] arguments) {
27
 	public StorageTag instance(CodePosition position, String[] arguments) {
28
-		if (arguments != null)
28
+		if (arguments.length > 0)
29
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "any storage type doesn't take arguments");
29
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "any storage type doesn't take arguments");
30
 		
30
 		
31
 		return AnyStorageTag.INSTANCE;
31
 		return AnyStorageTag.INSTANCE;

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

24
 
24
 
25
 	@Override
25
 	@Override
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
27
-		if (arguments != null) {
27
+		if (arguments.length > 0) {
28
 			if (arguments.length == 1 && arguments[0].equals("this"))
28
 			if (arguments.length == 1 && arguments[0].equals("this"))
29
 				return BorrowStorageTag.THIS;
29
 				return BorrowStorageTag.THIS;
30
 			
30
 			

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

42
 	public boolean isDestructible() {
42
 	public boolean isDestructible() {
43
 		return false;
43
 		return false;
44
 	}
44
 	}
45
+	
46
+	@Override
47
+	public String toString() {
48
+		return "invalid";
49
+	}
45
 }
50
 }

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

24
 
24
 
25
 	@Override
25
 	@Override
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
27
-		if (arguments != null)
27
+		if (arguments.length > 0)
28
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "shared storage type doesn't take arguments");
28
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "shared storage type doesn't take arguments");
29
 		
29
 		
30
 		return SharedStorageTag.INSTANCE;
30
 		return SharedStorageTag.INSTANCE;

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

24
 
24
 
25
 	@Override
25
 	@Override
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
27
-		if (arguments != null)
27
+		if (arguments.length > 0)
28
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "static storage type doesn't take arguments");
28
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "static storage type doesn't take arguments");
29
 		
29
 		
30
 		return StaticStorageTag.INSTANCE;
30
 		return StaticStorageTag.INSTANCE;

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

24
 
24
 
25
 	@Override
25
 	@Override
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
26
 	public StorageTag instance(CodePosition position, String[] arguments) {
27
-		if (arguments != null)
27
+		if (arguments.length > 0)
28
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "unique storage type doesn't take arguments");
28
 			return new InvalidStorageTag(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "unique storage type doesn't take arguments");
29
 		
29
 		
30
 		return UniqueStorageTag.INSTANCE;
30
 		return UniqueStorageTag.INSTANCE;

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

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.Collections;
9
 import java.util.Collections;
10
 import java.util.List;
10
 import java.util.List;
11
+import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
17
 import org.openzen.zenscript.codemodel.type.StoredType;
18
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
17
 import org.openzen.zenscript.lexer.ParseException;
19
 import org.openzen.zenscript.lexer.ParseException;
18
 import org.openzen.zenscript.lexer.ZSToken;
20
 import org.openzen.zenscript.lexer.ZSToken;
19
 import org.openzen.zenscript.lexer.ZSTokenParser;
21
 import org.openzen.zenscript.lexer.ZSTokenParser;
22
 import org.openzen.zenscript.parser.ParsedAnnotation;
24
 import org.openzen.zenscript.parser.ParsedAnnotation;
23
 import org.openzen.zenscript.parser.expression.ParsedExpression;
25
 import org.openzen.zenscript.parser.expression.ParsedExpression;
24
 import org.openzen.zenscript.parser.type.IParsedType;
26
 import org.openzen.zenscript.parser.type.IParsedType;
27
+import org.openzen.zenscript.parser.type.ParsedStorageTag;
25
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
28
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
26
 
29
 
27
 /**
30
 /**
30
  */
33
  */
31
 public class ParsedFunctionHeader {
34
 public class ParsedFunctionHeader {
32
 	public static ParsedFunctionHeader parse(ZSTokenParser tokens) throws ParseException {
35
 	public static ParsedFunctionHeader parse(ZSTokenParser tokens) throws ParseException {
36
+		CodePosition position = tokens.getPosition();
37
+		
38
+		ParsedStorageTag storage = ParsedStorageTag.parse(tokens);
39
+		
33
 		List<ParsedTypeParameter> genericParameters = null;
40
 		List<ParsedTypeParameter> genericParameters = null;
34
 		if (tokens.optional(ZSTokenType.T_LESS) != null) {
41
 		if (tokens.optional(ZSTokenType.T_LESS) != null) {
35
 			genericParameters = new ArrayList<>();
42
 			genericParameters = new ArrayList<>();
71
 			thrownType = IParsedType.parse(tokens);
78
 			thrownType = IParsedType.parse(tokens);
72
 		}
79
 		}
73
 		
80
 		
74
-		return new ParsedFunctionHeader(genericParameters, parameters, returnType, thrownType);
81
+		return new ParsedFunctionHeader(position, genericParameters, parameters, returnType, thrownType, storage);
75
 	}
82
 	}
76
 	
83
 	
84
+	public final CodePosition position;
77
 	public final List<ParsedTypeParameter> genericParameters;
85
 	public final List<ParsedTypeParameter> genericParameters;
78
 	public final List<ParsedFunctionParameter> parameters;
86
 	public final List<ParsedFunctionParameter> parameters;
79
 	public final IParsedType returnType;
87
 	public final IParsedType returnType;
80
 	public final IParsedType thrownType;
88
 	public final IParsedType thrownType;
89
+	public final ParsedStorageTag storage;
81
 	
90
 	
82
-	public ParsedFunctionHeader(List<ParsedFunctionParameter> parameters, IParsedType returnType, IParsedType thrownType) {
91
+	public ParsedFunctionHeader(CodePosition position, List<ParsedFunctionParameter> parameters, IParsedType returnType) {
92
+		this.position = position;
83
 		this.genericParameters = Collections.emptyList();
93
 		this.genericParameters = Collections.emptyList();
84
 		this.parameters = parameters;
94
 		this.parameters = parameters;
85
 		this.returnType = returnType;
95
 		this.returnType = returnType;
86
-		this.thrownType = thrownType;
96
+		this.thrownType = null;
97
+		this.storage = ParsedStorageTag.NULL;
87
 	}
98
 	}
88
 	
99
 	
89
-	public ParsedFunctionHeader(List<ParsedTypeParameter> genericParameters, List<ParsedFunctionParameter> parameters, IParsedType returnType, IParsedType thrownType) {
100
+	public ParsedFunctionHeader(CodePosition position, List<ParsedTypeParameter> genericParameters, List<ParsedFunctionParameter> parameters, IParsedType returnType, IParsedType thrownType, ParsedStorageTag storage) {
101
+		this.position = position;
90
 		this.genericParameters = genericParameters;
102
 		this.genericParameters = genericParameters;
91
 		this.parameters = parameters;
103
 		this.parameters = parameters;
92
 		this.returnType = returnType;
104
 		this.returnType = returnType;
93
 		this.thrownType = thrownType;
105
 		this.thrownType = thrownType;
106
+		this.storage = storage;
94
 	}
107
 	}
95
 	
108
 	
96
 	public FunctionHeader compile(TypeResolutionContext context) {
109
 	public FunctionHeader compile(TypeResolutionContext context) {
103
 		for (int i = 0; i < parameters.length; i++)
116
 		for (int i = 0; i < parameters.length; i++)
104
 			parameters[i] = this.parameters.get(i).compile(localContext);
117
 			parameters[i] = this.parameters.get(i).compile(localContext);
105
 		
118
 		
106
-		return new FunctionHeader(genericParameters, returnType, thrownType == null ? null : thrownType.compile(context), parameters);
119
+		StorageTag storage = this.storage.resolve(position, context);
120
+		return new FunctionHeader(genericParameters, returnType, thrownType == null ? null : thrownType.compile(context), storage, parameters);
107
 	}
121
 	}
108
 }
122
 }

+ 6
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java View File

434
 						position,
434
 						position,
435
 						parser.next().content);
435
 						parser.next().content);
436
 			case T_STRING_SQ:
436
 			case T_STRING_SQ:
437
-			case T_STRING_DQ:
437
+			case T_STRING_DQ: {
438
+				String quoted = parser.next().content;
438
 				return new ParsedExpressionString(
439
 				return new ParsedExpressionString(
439
 						position,
440
 						position,
440
-						StringExpansion.unescape(parser.next().content).orElse(error -> {
441
+						StringExpansion.unescape(quoted).orElse(error -> {
441
 							return "INVALID_STRING";
442
 							return "INVALID_STRING";
442
-						}));
443
+						}),
444
+						quoted.charAt(0) == '\'');
445
+			}
443
 			case T_IDENTIFIER: {
446
 			case T_IDENTIFIER: {
444
 				String name = parser.next().content;
447
 				String name = parser.next().content;
445
 				List<IParsedType> genericParameters = IParsedType.parseTypeArguments(parser);
448
 				List<IParsedType> genericParameters = IParsedType.parseTypeArguments(parser);

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

15
 import org.openzen.zenscript.lexer.ParseException;
15
 import org.openzen.zenscript.lexer.ParseException;
16
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
16
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
18
+import org.openzen.zenscript.parser.type.ParsedStorageTag;
18
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
19
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
19
 
20
 
20
 /**
21
 /**
45
 		for (ParsedExpression expression : expressions)
46
 		for (ParsedExpression expression : expressions)
46
 			parameters.add(expression.toLambdaParameter());
47
 			parameters.add(expression.toLambdaParameter());
47
 		
48
 		
48
-		return new ParsedFunctionHeader(parameters, ParsedTypeBasic.UNDETERMINED, null);
49
+		return new ParsedFunctionHeader(position, parameters, ParsedTypeBasic.UNDETERMINED);
49
 	}
50
 	}
50
 
51
 
51
 	@Override
52
 	@Override

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

16
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
16
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
17
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
18
 import org.openzen.zenscript.parser.type.IParsedType;
18
 import org.openzen.zenscript.parser.type.IParsedType;
19
+import org.openzen.zenscript.parser.type.ParsedStorageTag;
19
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
20
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
20
 
21
 
21
 /**
22
 /**
52
 		if (header.returnType != ParsedTypeBasic.UNDETERMINED)
53
 		if (header.returnType != ParsedTypeBasic.UNDETERMINED)
53
 			throw new ParseException(position, "Lambda parameter already has a return type");
54
 			throw new ParseException(position, "Lambda parameter already has a return type");
54
 		
55
 		
55
-		return new ParsedFunctionHeader(header.genericParameters, header.parameters, type, null);
56
+		return new ParsedFunctionHeader(position, header.genericParameters, header.parameters, type, null, ParsedStorageTag.NULL);
56
 	}
57
 	}
57
 	
58
 	
58
 	@Override
59
 	@Override

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

25
  */
25
  */
26
 public class ParsedExpressionString extends ParsedExpression {
26
 public class ParsedExpressionString extends ParsedExpression {
27
 	public final String value;
27
 	public final String value;
28
+	public final boolean singleQuote;
28
 	
29
 	
29
-	public ParsedExpressionString(CodePosition position, String value) {
30
+	public ParsedExpressionString(CodePosition position, String value, boolean singleQuote) {
30
 		super(position);
31
 		super(position);
31
 		
32
 		
32
 		this.value = value;
33
 		this.value = value;
34
+		this.singleQuote = singleQuote;
33
 	}
35
 	}
34
 
36
 
35
 	@Override
37
 	@Override
36
 	public IPartialExpression compile(ExpressionScope scope) {
38
 	public IPartialExpression compile(ExpressionScope scope) {
37
-		if (value.length() == 1 && scope.hints.contains(BasicTypeID.CHAR.stored))
39
+		if (value.length() == 1 && (singleQuote || scope.hints.contains(BasicTypeID.CHAR.stored)))
38
 			return new ConstantCharExpression(position, value.charAt(0));
40
 			return new ConstantCharExpression(position, value.charAt(0));
39
 		
41
 		
40
 		return new ConstantStringExpression(position, value);
42
 		return new ConstantStringExpression(position, value);

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

30
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
30
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionParameter;
32
 import org.openzen.zenscript.parser.type.IParsedType;
32
 import org.openzen.zenscript.parser.type.IParsedType;
33
+import org.openzen.zenscript.parser.type.ParsedStorageTag;
33
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
34
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
34
 
35
 
35
 /**
36
 /**
105
 	
106
 	
106
 	@Override
107
 	@Override
107
 	public ParsedFunctionHeader toLambdaHeader() {
108
 	public ParsedFunctionHeader toLambdaHeader() {
108
-		return new ParsedFunctionHeader(Collections.singletonList(toLambdaParameter()), ParsedTypeBasic.UNDETERMINED, null);
109
+		return new ParsedFunctionHeader(position, Collections.singletonList(toLambdaParameter()), ParsedTypeBasic.UNDETERMINED);
109
 	}
110
 	}
110
 	
111
 	
111
 	@Override
112
 	@Override

+ 3
- 10
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedStorageTag.java View File

27
 			return NULL;
27
 			return NULL;
28
 		
28
 		
29
 		String name = parser.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
29
 		String name = parser.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
30
-		List<String> arguments = null;
31
-		if (parser.optional(ZSTokenType.T_BROPEN) != null) {
32
-			arguments = new ArrayList<>();
33
-			if (parser.optional(ZSTokenType.T_BRCLOSE) == null) {
34
-				do {
35
-					arguments.add(parser.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content);
36
-				} while (parser.optional(ZSTokenType.T_COMMA) == null);
37
-				parser.required(ZSTokenType.T_BRCLOSE, ") expected");
38
-			}
39
-		}
30
+		List<String> arguments = new ArrayList<>();
31
+		while (parser.optional(ZSTokenType.T_COLON) != null)
32
+			arguments.add(parser.next().content);
40
 		
33
 		
41
 		return new ParsedStorageTag(name, arguments.toArray(new String[arguments.size()]));
34
 		return new ParsedStorageTag(name, arguments.toArray(new String[arguments.size()]));
42
 	}
35
 	}

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

28
 import org.openzen.zenscript.validator.Validator;
28
 import org.openzen.zenscript.validator.Validator;
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
 
32
 
32
 /**
33
 /**
33
  *
34
  *
53
 		TypeValidator typeValidator = new TypeValidator(target, position);
54
 		TypeValidator typeValidator = new TypeValidator(target, position);
54
 		typeValidator.validate(header.getReturnType());
55
 		typeValidator.validate(header.getReturnType());
55
 		
56
 		
57
+		if (header.storage instanceof InvalidStorageTag) {
58
+			InvalidStorageTag invalid = (InvalidStorageTag)header.storage;
59
+			target.logError(INVALID_TYPE, invalid.position, invalid.message);
60
+		}
61
+		
56
 		Set<String> parameterNames = new HashSet<>();
62
 		Set<String> parameterNames = new HashSet<>();
57
 		int i = 0;
63
 		int i = 0;
58
 		for (FunctionParameter parameter : header.parameters) {
64
 		for (FunctionParameter parameter : header.parameters) {

Loading…
Cancel
Save