ソースを参照

- Fixed validator acting up on type argument validation

- Moved enum constants to enum type, they are no longer type members
- Added override modifier
- Performed some minor fixes during compilation
- Fixed type member registration on optionals
- Expanded arrays with functional methods
-
Stan Hebben 6年前
コミット
e3a1ccbc5c
31個のファイルの変更300行の追加172行の削除
  1. 1
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java
  2. 0
    5
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  3. 0
    9
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  4. 1
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java
  5. 9
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java
  6. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java
  8. 5
    30
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java
  9. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java
  10. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java
  11. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  12. 0
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java
  13. 2
    30
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java
  14. 4
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMember.java
  15. 70
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  16. 1
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberPriority.java
  17. 78
    0
      Constructor/libraries/stdlib/src/Arrays.zs
  18. 8
    0
      Constructor/libraries/stdlib/src/Assoc.zs
  19. 6
    1
      Constructor/libraries/stdlib/src/Strings.zs
  20. 3
    3
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  21. 19
    23
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  22. 15
    6
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  23. 21
    2
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedImport.java
  24. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java
  25. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java
  26. 0
    38
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedImport.java
  27. 4
    0
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java
  28. 4
    2
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  29. 2
    3
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  30. 9
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java
  31. 21
    3
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java ファイルの表示

@@ -105,7 +105,7 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
105 105
 					.append("{\n");
106 106
 		}
107 107
 		
108
-		List<EnumConstantMember> enumConstants = definition.getEnumConstants();
108
+		List<EnumConstantMember> enumConstants = definition.enumConstants;
109 109
 		boolean first = true;
110 110
 		ExpressionFormatter expressionFormatter = new ExpressionFormatter(settings, typeFormatter);
111 111
 		for (EnumConstantMember enumConstant : enumConstants) {

+ 0
- 5
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java ファイルの表示

@@ -125,11 +125,6 @@ public class MemberFormatter implements MemberVisitor<Void> {
125 125
 		return null;
126 126
 	}
127 127
 
128
-	@Override
129
-	public Void visitEnumConstant(EnumConstantMember member) {
130
-		return null; // TODO: handle separately
131
-	}
132
-
133 128
 	@Override
134 129
 	public Void visitOperator(OperatorMember member) {
135 130
 		visit(false);

+ 0
- 9
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java ファイルの表示

@@ -74,15 +74,6 @@ public abstract class HighLevelDefinition extends Taggable {
74 74
 		return fields;
75 75
 	}
76 76
 	
77
-	public List<EnumConstantMember> getEnumConstants() {
78
-		List<EnumConstantMember> enumMembers = new ArrayList<>();
79
-		for (IDefinitionMember member : members)
80
-            if (member instanceof EnumConstantMember)
81
-				enumMembers.add((EnumConstantMember) member);
82
-		
83
-		return enumMembers;
84
-	}
85
-	
86 77
 	public boolean hasEmptyConstructor() {
87 78
 		for (IDefinitionMember member : members) {
88 79
 			if (member instanceof ConstructorMember) {

+ 1
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Modifiers.java ファイルの表示

@@ -24,6 +24,7 @@ public class Modifiers {
24 24
 	public static final int IMPLICIT = 512;
25 25
 	public static final int VIRTUAL = 1024;
26 26
 	public static final int EXTERN = 2048;
27
+	public static final int OVERRIDE = 4096;
27 28
 	
28 29
 	public static boolean isPublic(int modifiers) {
29 30
 		return (modifiers & PUBLIC) > 0;

+ 9
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java ファイルの表示

@@ -5,7 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.definition;
7 7
 
8
+import java.util.ArrayList;
9
+import java.util.List;
8 10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
9 12
 import org.openzen.zenscript.shared.CodePosition;
10 13
 
11 14
 /**
@@ -13,6 +16,8 @@ import org.openzen.zenscript.shared.CodePosition;
13 16
  * @author Hoofdgebruiker
14 17
  */
15 18
 public class EnumDefinition extends HighLevelDefinition {
19
+	public List<EnumConstantMember> enumConstants = new ArrayList<>();
20
+	
16 21
 	public EnumDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
17 22
 		super(position, pkg, name, modifiers, outerDefinition);
18 23
 	}
@@ -21,4 +26,8 @@ public class EnumDefinition extends HighLevelDefinition {
21 26
 	public <T> T accept(DefinitionVisitor<T> visitor) {
22 27
 		return visitor.visitEnum(this);
23 28
 	}
29
+	
30
+	public void addEnumConstant(EnumConstantMember constant) {
31
+		enumConstants.add(constant);
32
+	}
24 33
 }

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java ファイルの表示

@@ -8,9 +8,7 @@ package org.openzen.zenscript.codemodel.definition;
8 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10 10
 import org.openzen.zenscript.codemodel.Modifiers;
11
-import org.openzen.zenscript.codemodel.OperatorType;
12 11
 import org.openzen.zenscript.codemodel.member.CallerMember;
13
-import org.openzen.zenscript.codemodel.member.OperatorMember;
14 12
 import org.openzen.zenscript.codemodel.statement.Statement;
15 13
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
16 14
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java ファイルの表示

@@ -28,7 +28,7 @@ public class ParameterTypeBound extends GenericParameterBound {
28 28
 
29 29
 	@Override
30 30
 	public void registerMembers(LocalMemberCache cache, TypeMembers type) {
31
-		cache.get(this.type).copyMembersTo(position, type, TypeMemberPriority.SPECIFIED);
31
+		cache.get(this.type).copyMembersTo(position, type, TypeMemberPriority.FROM_TYPE_BOUNDS);
32 32
 	}
33 33
 
34 34
 	@Override

+ 5
- 30
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EnumConstantMember.java ファイルの表示

@@ -5,51 +5,26 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8
-import java.util.Map;
9 8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
-import org.openzen.zenscript.codemodel.Modifiers;
11 9
 import org.openzen.zenscript.codemodel.expression.NewExpression;
12
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
-import org.openzen.zenscript.codemodel.type.ITypeID;
15
-import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
-import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17 10
 import org.openzen.zenscript.shared.CodePosition;
18 11
 
19 12
 /**
20 13
  *
21 14
  * @author Hoofdgebruiker
22 15
  */
23
-public class EnumConstantMember extends DefinitionMember {
16
+public class EnumConstantMember {
17
+	public final CodePosition position;
18
+	public final HighLevelDefinition definition;
24 19
 	public final String name;
25 20
 	public final int value;
26 21
 	
27 22
 	public NewExpression constructor;
28 23
 	
29 24
 	public EnumConstantMember(CodePosition position, HighLevelDefinition definition, String name, int value) {
30
-		super(position, definition, Modifiers.STATIC);
31
-		
25
+		this.position = position;
26
+		this.definition = definition;
32 27
 		this.name = name;
33 28
 		this.value = value;
34 29
 	}
35
-
36
-	@Override
37
-	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
38
-		type.addEnumMember(this, priority);
39
-	}
40
-
41
-	@Override
42
-	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
43
-		throw new UnsupportedOperationException("Enums can't have type parameters");
44
-	}
45
-
46
-	@Override
47
-	public String describe() {
48
-		return "enum member " + name;
49
-	}
50
-
51
-	@Override
52
-	public <T> T accept(MemberVisitor<T> visitor) {
53
-		return visitor.visitEnumConstant(this);
54
-	}
55 30
 }

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java ファイルの表示

@@ -22,8 +22,6 @@ public interface MemberVisitor<T> {
22 22
 	
23 23
 	public T visitSetter(SetterMember member);
24 24
 	
25
-	public T visitEnumConstant(EnumConstantMember member);
26
-	
27 25
 	public T visitOperator(OperatorMember member);
28 26
 	
29 27
 	public T visitCaster(CasterMember member);

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java ファイルの表示

@@ -53,8 +53,8 @@ public class PartialMemberGroupExpression implements IPartialExpression {
53 53
 	
54 54
 	@Override
55 55
 	public List<ITypeID> getAssignHints() {
56
-		if (group.getGetter() != null)
57
-			return Collections.singletonList(group.getGetter().getType());
56
+		if (group.getSetter() != null)
57
+			return Collections.singletonList(group.getSetter().type);
58 58
 		if (group.getField() != null)
59 59
 			return Collections.singletonList(group.getField().type);
60 60
 		

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java ファイルの表示

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.partial;
7 7
 
8
+import java.util.Collections;
8 9
 import java.util.List;
9 10
 import java.util.stream.Collectors;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
@@ -78,4 +79,14 @@ public class PartialStaticMemberGroupExpression implements IPartialExpression {
78 79
 	public ITypeID[] getGenericCallTypes() {
79 80
 		return typeArguments;
80 81
 	}
82
+	
83
+	@Override
84
+	public List<ITypeID> getAssignHints() {
85
+		if (group.getSetter() != null)
86
+			return Collections.singletonList(group.getSetter().type);
87
+		if (group.getField() != null)
88
+			return Collections.singletonList(group.getField().type);
89
+		
90
+		return Collections.emptyList();
91
+	}
81 92
 }

+ 0
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java ファイルの表示

@@ -7,7 +7,6 @@ package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.Arrays;
9 9
 import java.util.Map;
10
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11 10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 11
 
13 12
 /**

+ 2
- 30
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java ファイルの表示

@@ -6,18 +6,13 @@
6 6
 package org.openzen.zenscript.codemodel.type.member;
7 7
 
8 8
 import java.util.ArrayList;
9
-import java.util.Collections;
10 9
 import java.util.HashMap;
11 10
 import java.util.List;
12 11
 import java.util.Map;
13 12
 import org.openzen.zenscript.codemodel.AccessScope;
14 13
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
15
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
-import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17 14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
18 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
-import org.openzen.zenscript.shared.CompileException;
20
-import org.openzen.zenscript.shared.CompileExceptionCode;
21 16
 
22 17
 /**
23 18
  *
@@ -55,32 +50,9 @@ public class LocalMemberCache {
55 50
 	
56 51
 	private void registerMembers(TypeMembers members) {
57 52
 		members.type.accept(new TypeMemberBuilder(registry, members, this));
58
-		
59
-		for (ExpansionDefinition expansion : expansions) {
60
-			if (expansion.target == null)
61
-				throw new CompileException(expansion.position, CompileExceptionCode.INTERNAL_ERROR, "Missing expansion target");
62
-			
63
-			Map<TypeParameter, ITypeID> mapping = matchType(members.type, expansion.target);
64
-			if (mapping != null) {
65
-				if (mapping.isEmpty()) {
66
-					for (IDefinitionMember member : expansion.members)
67
-						member.registerTo(members, TypeMemberPriority.SPECIFIED);
68
-				} else {
69
-					for (IDefinitionMember member : expansion.members)
70
-						member.instance(registry, mapping).registerTo(members, TypeMemberPriority.SPECIFIED);
71
-				}
72
-			}
73
-		}
74 53
 	}
75 54
 	
76
-	private Map<TypeParameter, ITypeID> matchType(ITypeID type, ITypeID pattern) {
77
-		if (type == pattern)
78
-			return Collections.emptyMap();
79
-		
80
-		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
81
-		if (pattern.inferTypeParameters(this, type, mapping))
82
-			return mapping;
83
-		
84
-		return null;
55
+	public List<ExpansionDefinition> getExpansions() {
56
+		return expansions;
85 57
 	}
86 58
 }

+ 4
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMember.java ファイルの表示

@@ -24,7 +24,10 @@ public class TypeMember<T extends IDefinitionMember> {
24 24
 	
25 25
 	public TypeMember<T> resolve(TypeMember<T> other) {
26 26
 		if (priority == other.priority)
27
-			throw new CompileException(other.member.getPosition(), CompileExceptionCode.MEMBER_DUPLICATE, "Duplicate " + other.member.describe());
27
+			if (priority == TypeMemberPriority.SPECIFIED)
28
+				throw new CompileException(other.member.getPosition(), CompileExceptionCode.MEMBER_DUPLICATE, "Duplicate " + other.member.describe());
29
+			else
30
+				return this;
28 31
 		
29 32
 		if (priority.compareTo(other.priority) < 0) {
30 33
 			return other;

+ 70
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java ファイルの表示

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.member;
7 7
 
8
+import java.util.Collections;
8 9
 import java.util.HashMap;
9 10
 import java.util.List;
10 11
 import java.util.Map;
@@ -15,6 +16,7 @@ import org.openzen.zenscript.codemodel.Modifiers;
15 16
 import org.openzen.zenscript.codemodel.OperatorType;
16 17
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
17 18
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
19
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
18 20
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
19 21
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
20 22
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
@@ -26,6 +28,7 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
26 28
 import org.openzen.zenscript.codemodel.member.CallerMember;
27 29
 import org.openzen.zenscript.codemodel.member.CasterMember;
28 30
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
31
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
29 32
 import org.openzen.zenscript.codemodel.member.EqualsMember;
30 33
 import org.openzen.zenscript.codemodel.member.FieldMember;
31 34
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
@@ -58,6 +61,8 @@ import org.openzen.zenscript.codemodel.type.OptionalTypeID;
58 61
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
59 62
 import static org.openzen.zenscript.codemodel.type.member.BuiltinTypeMembers.*;
60 63
 import static org.openzen.zenscript.shared.CodePosition.BUILTIN;
64
+import org.openzen.zenscript.shared.CompileException;
65
+import org.openzen.zenscript.shared.CompileExceptionCode;
61 66
 
62 67
 /**
63 68
  *
@@ -77,6 +82,35 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
77 82
 			members.addOperator(OperatorType.EQUALS, new EqualsMember(members.type), TypeMemberPriority.BUILTIN_DEFAULT);
78 83
 		}
79 84
 	}
85
+	
86
+	private void registerExpansions(ITypeID type) {
87
+		for (ExpansionDefinition expansion : cache.getExpansions()) {
88
+			if (expansion.target == null)
89
+				throw new CompileException(expansion.position, CompileExceptionCode.INTERNAL_ERROR, "Missing expansion target");
90
+			
91
+			Map<TypeParameter, ITypeID> mapping = matchType(type, expansion.target);
92
+			if (mapping != null) {
93
+				if (mapping.isEmpty()) {
94
+					for (IDefinitionMember member : expansion.members)
95
+						member.registerTo(members, TypeMemberPriority.SPECIFIED);
96
+				} else {
97
+					for (IDefinitionMember member : expansion.members)
98
+						member.instance(registry, mapping).registerTo(members, TypeMemberPriority.SPECIFIED);
99
+				}
100
+			}
101
+		}
102
+	}
103
+	
104
+	private Map<TypeParameter, ITypeID> matchType(ITypeID type, ITypeID pattern) {
105
+		if (type == pattern)
106
+			return Collections.emptyMap();
107
+		
108
+		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
109
+		if (pattern.inferTypeParameters(cache, type, mapping))
110
+			return mapping;
111
+		
112
+		return null;
113
+	}
80 114
 
81 115
 	@Override
82 116
 	public Void visitBasic(BasicTypeID basic) {
@@ -103,6 +137,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
103 137
 				visitString();
104 138
 				break;
105 139
 		}
140
+		
141
+		registerExpansions(basic);
106 142
 		return null;
107 143
 	}
108 144
 
@@ -166,6 +202,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
166 202
 		members.addIterator(new ArrayIteratorKeyValues(array), TypeMemberPriority.SPECIFIED);
167 203
 		members.addIterator(new ArrayIteratorValues(array), TypeMemberPriority.SPECIFIED);
168 204
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "clear", new FunctionHeader(VOID)), TypeMemberPriority.SPECIFIED);
205
+		
206
+		registerExpansions(array);
169 207
 		return null;
170 208
 	}
171 209
 
@@ -195,6 +233,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
195 233
 		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
196 234
 		
197 235
 		members.addIterator(new AssocIterator(assoc), TypeMemberPriority.SPECIFIED);
236
+		
237
+		registerExpansions(assoc);
198 238
 		return null;
199 239
 	}
200 240
 	
@@ -208,6 +248,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
208 248
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, null, new FunctionParameter(valueType))));
209 249
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, null, new FunctionParameter[0])));
210 250
 		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
251
+		
252
+		registerExpansions(map);
211 253
 		return null;
212 254
 	}
213 255
 	
@@ -220,6 +262,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
220 262
 	public Void visitFunction(FunctionTypeID function) {
221 263
 		FunctionDefinition definition = new FunctionDefinition(BUILTIN, null, "", Modifiers.EXPORT, function.header);
222 264
 		members.addCaller(new CallerMember(BUILTIN, definition, 0, function.header), TypeMemberPriority.SPECIFIED);
265
+		
266
+		registerExpansions(function);
223 267
 		return null;
224 268
 	}
225 269
 
@@ -260,6 +304,13 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
260 304
 					members.addVariantOption(option);
261 305
 			}
262 306
 		}
307
+		
308
+		if (definition instanceof EnumDefinition) {
309
+			EnumDefinition enumDef = (EnumDefinition) definition;
310
+			for (EnumConstantMember constant : enumDef.enumConstants) {
311
+				members.addEnumMember(constant, TypeMemberPriority.SPECIFIED);
312
+			}
313
+		}
263 314
 
264 315
 		DefinitionMemberGroup constructors = members.getOrCreateGroup(OperatorType.CONSTRUCTOR);
265 316
 		if (constructors.getMethodMembers().isEmpty()) {
@@ -286,15 +337,22 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
286 337
 		}
287 338
 		
288 339
 		if (definition instanceof EnumDefinition) {
289
-			members.addGetter(new GetterMember(BUILTIN, definition, 0, "name", BasicTypeID.STRING), TypeMemberPriority.SPECIFIED);
290
-			members.addGetter(new GetterMember(BUILTIN, definition, 0, "ordinal", BasicTypeID.INT), TypeMemberPriority.SPECIFIED);
340
+			members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC, "name", BasicTypeID.STRING), TypeMemberPriority.SPECIFIED);
341
+			members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC, "ordinal", BasicTypeID.INT), TypeMemberPriority.SPECIFIED);
342
+			members.addField(new FieldMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.STATIC, "VALUES", registry.getArray(type, 1)));
291 343
 			
292 344
 			if (!members.canCast(BasicTypeID.STRING)) {
293 345
 				members.addCaster(new CasterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN | Modifiers.IMPLICIT, BasicTypeID.STRING));
294 346
 			}
295 347
 		}
296 348
 		
297
-		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
349
+		if (type.superType != null) {
350
+			cache.get(type.superType).copyMembersTo(type.definition.position, members, TypeMemberPriority.INHERITED);
351
+		} else {
352
+			members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
353
+		}
354
+		
355
+		registerExpansions(type);
298 356
 		return null;
299 357
 	}
300 358
 
@@ -305,6 +363,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
305 363
 		for (GenericParameterBound bound : parameter.bounds) {
306 364
 			bound.registerMembers(cache, members);
307 365
 		}
366
+		
308 367
 		return null;
309 368
 	}
310 369
 
@@ -326,17 +385,23 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
326 385
 				|| range.from == BasicTypeID.ULONG)) {
327 386
 			members.addIterator(new RangeIterator(range), TypeMemberPriority.SPECIFIED);
328 387
 		}
388
+		
389
+		registerExpansions(range);
329 390
 		return null;
330 391
 	}
331 392
 
332 393
 	@Override
333 394
 	public Void visitConst(ConstTypeID type) {
334
-		return type.baseType.accept(this);
395
+		type.baseType.accept(this);
396
+		registerExpansions(type);
397
+		return null;
335 398
 	}
336 399
 
337 400
 	@Override
338 401
 	public Void visitOptional(OptionalTypeID optional) {
339
-		return optional.baseType.accept(this);
402
+		optional.baseType.accept(this);
403
+		registerExpansions(optional);
404
+		return null;
340 405
 	}
341 406
 	
342 407
 	private void visitBool() {

+ 1
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberPriority.java ファイルの表示

@@ -11,6 +11,7 @@ package org.openzen.zenscript.codemodel.type.member;
11 11
  */
12 12
 public enum TypeMemberPriority {
13 13
 	BUILTIN_DEFAULT,
14
+	FROM_TYPE_BOUNDS,
14 15
 	INTERFACE,
15 16
 	INHERITED,
16 17
 	SPECIFIED;

+ 78
- 0
Constructor/libraries/stdlib/src/Arrays.zs ファイルの表示

@@ -16,4 +16,82 @@ export expand <T> T[] {
16 16
 	public extern copy() as T[];
17 17
 	public extern copy(newSize as int) as T[];
18 18
 	public extern copyTo(target as T[], sourceOffset as int, targetOffset as int, length as int) as void;
19
+	
20
+	public get first as T?;
21
+	public get last as T?;
22
+	
23
+	public map<U>(projection as function(value as T) as U) as U[] {
24
+		val result as U[] = new U[](this.length);
25
+		for i, value in this
26
+			result[i] = projection(value);
27
+		return result;
28
+	}
29
+	
30
+	public map<U>(projection as function(index as int, value as T) as U) as U[] {
31
+		val result as U[] = new U[](this.length);
32
+		for i, value in this
33
+			result[i] = projection(i, value);
34
+		return result;
35
+	}
36
+	
37
+	public extern filter(predicate as function(value as T) as bool) as T[];
38
+	public extern filter(predicate as function(index as int, value as T) as bool) as T[];
39
+	
40
+	public each(consumer as function(value as T) as void) as void {
41
+		for value in this
42
+			consumer(value);
43
+	}
44
+	
45
+	public each(consumer as function(index as int, value as T) as void) as void {
46
+		for i, value in this
47
+			consumer(i, value);
48
+	}
49
+	
50
+	public contains(predicate as function(value as T) as bool) as bool {
51
+		for value in this
52
+			if predicate(value)
53
+				return true;
54
+		
55
+		return false;
56
+	}
57
+	
58
+	public contains(predicate as function(index as int, value as T) as bool) as bool {
59
+		for i, value in this
60
+			if predicate(i, value)
61
+				return true;
62
+		
63
+		return false;
64
+	}
65
+	
66
+	public all(predicate as function(value as T) as bool) as bool {
67
+		for value in this
68
+			if !predicate(value)
69
+				return false;
70
+		
71
+		return true;
72
+	}
73
+	
74
+	public all(predicate as function(i as int, value as T) as bool) as bool {
75
+		for i, value in this
76
+			if !predicate(i, value)
77
+				return false;
78
+		
79
+		return true;
80
+	}
81
+	
82
+	public count(predicate as function(value as T) as bool) as int {
83
+		var result = 0;
84
+		for value in this
85
+			if predicate(value)
86
+				result++;
87
+		return result;
88
+	}
89
+	
90
+	public count(predicate as function(index as int, value as T) as bool) as int {
91
+		var result = 0;
92
+		for i, value in this
93
+			if predicate(i, value)
94
+				result++;
95
+		return result;
96
+	}
19 97
 }

+ 8
- 0
Constructor/libraries/stdlib/src/Assoc.zs ファイルの表示

@@ -0,0 +1,8 @@
1
+export expand <K, V> V[K] {
2
+	mapValues<W>(projection as function(value as V) as W) as W[K] {
3
+		val result = new W[K];
4
+		for k, v in this
5
+			result[k] = projection(v);
6
+		return result;
7
+	}
8
+}

+ 6
- 1
Constructor/libraries/stdlib/src/Strings.zs ファイルの表示

@@ -1,5 +1,8 @@
1 1
 export expand string {
2
-	public get isEmpty as bool => length == 0;
2
+	public get empty as bool => length == 0;
3
+	
4
+	public const in(c as char)as bool
5
+		=> indexOf(c) >= 0;
3 6
 	
4 7
 	public const indexOf(c as char) as int {
5 8
 		for i in 0 .. length {
@@ -54,6 +57,8 @@ export expand string {
54 57
 		return result;
55 58
 	}
56 59
 	
60
+	public const extern trim() as string;
61
+	
57 62
 	public const lpad(length as int, c as char) as string
58 63
 		=> this.length >= length ? this : c.times(length - this.length) + this;
59 64
 	

+ 3
- 3
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java ファイルの表示

@@ -92,7 +92,7 @@ public class Module {
92 92
 			// respective definitions, such as fields, constructors, methods...
93 93
 			// It doesn't yet compile the method contents.
94 94
 			try {
95
-				file.compileTypes(rootPackage, definitions, registry.typeRegistry, expansions, globals);
95
+				file.compileTypes(rootPackage, pkg, definitions, registry.typeRegistry, expansions, globals);
96 96
 			} catch (CompileException ex) {
97 97
 				System.out.println(ex.getMessage());
98 98
 				failed = true;
@@ -107,7 +107,7 @@ public class Module {
107 107
 			// respective definitions, such as fields, constructors, methods...
108 108
 			// It doesn't yet compile the method contents.
109 109
 			try {
110
-				file.compileMembers(rootPackage, definitions, registry.typeRegistry, expansions, globals);
110
+				file.compileMembers(rootPackage, pkg, definitions, registry.typeRegistry, expansions, globals);
111 111
 			} catch (CompileException ex) {
112 112
 				System.out.println(ex.getMessage());
113 113
 				failed = true;
@@ -124,7 +124,7 @@ public class Module {
124 124
 			// into semantic code. This semantic code can then be compiled
125 125
 			// to various targets.
126 126
 			try {
127
-				file.compileCode(rootPackage, definitions, registry.typeRegistry, expansions, scripts, globals);
127
+				file.compileCode(rootPackage, pkg, definitions, registry.typeRegistry, expansions, scripts, globals);
128 128
 			} catch (CompileException ex) {
129 129
 				System.out.println(ex.getMessage());
130 130
 				failed = true;

+ 19
- 23
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java ファイルの表示

@@ -160,28 +160,6 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
160 160
         return null;
161 161
     }
162 162
 
163
-    @Override
164
-    public Void visitEnumConstant(EnumConstantMember member) {
165
-        writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM, member.name, "L" + definition.name + ";", null, null).visitEnd();
166
-        final String internalName = member.constructor.type.accept(JavaTypeVisitor.INSTANCE).getInternalName();
167
-        final JavaWriter clinitWriter = clinitStatementVisitor.getJavaWriter();
168
-        clinitWriter.newObject(internalName);
169
-        clinitWriter.dup();
170
-        clinitWriter.constant(member.name);
171
-        clinitWriter.constant(member.value);
172
-        for (Expression argument : member.constructor.arguments.arguments) {
173
-            argument.accept(clinitStatementVisitor.expressionVisitor);
174
-        }
175
-
176
-        clinitWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(member.constructor.constructor.header, true));
177
-        clinitWriter.putStaticField(internalName, member.name, "L" + internalName + ";");
178
-
179
-
180
-        enumDefinition = (EnumDefinition) member.definition;
181
-
182
-        return null;
183
-    }
184
-
185 163
     @Override
186 164
     public Void visitOperator(OperatorMember member) {
187 165
         return null;
@@ -221,8 +199,26 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
221 199
     public void end() {
222 200
 
223 201
         if (enumDefinition != null) {
202
+			for (EnumConstantMember constant : enumDefinition.enumConstants) {
203
+				writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM, constant.name, "L" + definition.name + ";", null, null).visitEnd();
204
+				final String internalName = constant.constructor.type.accept(JavaTypeVisitor.INSTANCE).getInternalName();
205
+				final JavaWriter clinitWriter = clinitStatementVisitor.getJavaWriter();
206
+				clinitWriter.newObject(internalName);
207
+				clinitWriter.dup();
208
+				clinitWriter.constant(constant.name);
209
+				clinitWriter.constant(constant.value);
210
+				for (Expression argument : constant.constructor.arguments.arguments) {
211
+					argument.accept(clinitStatementVisitor.expressionVisitor);
212
+				}
213
+
214
+				clinitWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(constant.constructor.constructor.header, true));
215
+				clinitWriter.putStaticField(internalName, constant.name, "L" + internalName + ";");
216
+				
217
+				enumDefinition = (EnumDefinition) constant.definition;
218
+			}
219
+			
224 220
             final JavaWriter clinitWriter = clinitStatementVisitor.getJavaWriter();
225
-            final List<EnumConstantMember> enumConstants = enumDefinition.getEnumConstants();
221
+            final List<EnumConstantMember> enumConstants = enumDefinition.enumConstants;
226 222
             clinitWriter.constant(enumConstants.size());
227 223
             clinitWriter.newArray(Type.getType("L" + definition.name + ";"));
228 224
 

+ 15
- 6
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java ファイルの表示

@@ -150,12 +150,13 @@ public class ParsedFile {
150 150
 	
151 151
 	public void compileTypes(
152 152
 			ZSPackage rootPackage,
153
+			ZSPackage modulePackage,
153 154
 			PackageDefinitions packageDefinitions,
154 155
 			GlobalTypeRegistry globalRegistry,
155 156
 			List<ExpansionDefinition> expansions,
156 157
 			Map<String, ISymbol> globalSymbols) {
157 158
 		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols);
158
-		loadImports(scope, rootPackage);
159
+		loadImports(scope, rootPackage, modulePackage);
159 160
 		for (ParsedDefinition definition : this.definitions) {
160 161
 			definition.compileTypes(scope);
161 162
 		}
@@ -163,12 +164,13 @@ public class ParsedFile {
163 164
 	
164 165
 	public void compileMembers(
165 166
 			ZSPackage rootPackage,
167
+			ZSPackage modulePackage,
166 168
 			PackageDefinitions packageDefinitions,
167 169
 			GlobalTypeRegistry globalRegistry,
168 170
 			List<ExpansionDefinition> expansions,
169 171
 			Map<String, ISymbol> globalSymbols) {
170 172
 		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols);
171
-		loadImports(scope, rootPackage);
173
+		loadImports(scope, rootPackage, modulePackage);
172 174
 		for (ParsedDefinition definition : this.definitions) {
173 175
 			definition.compileMembers(scope);
174 176
 		}
@@ -176,13 +178,14 @@ public class ParsedFile {
176 178
 	
177 179
 	public void compileCode(
178 180
 			ZSPackage rootPackage,
181
+			ZSPackage modulePackage,
179 182
 			PackageDefinitions packageDefinitions,
180 183
 			GlobalTypeRegistry globalRegistry,
181 184
 			List<ExpansionDefinition> expansions,
182 185
 			List<ScriptBlock> scripts,
183 186
 			Map<String, ISymbol> globalSymbols) {
184 187
 		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols);
185
-		loadImports(scope, rootPackage);
188
+		loadImports(scope, rootPackage, modulePackage);
186 189
 		for (ParsedDefinition definition : this.definitions) {
187 190
 			definition.compileCode(scope);
188 191
 		}
@@ -201,11 +204,17 @@ public class ParsedFile {
201 204
 		}
202 205
 	}
203 206
 	
204
-	private void loadImports(FileScope scope, ZSPackage rootPackage) {
207
+	private void loadImports(FileScope scope, ZSPackage rootPackage, ZSPackage modulePackage) {
205 208
 		for (ParsedImport importEntry : imports) {
206
-			HighLevelDefinition definition = rootPackage.getImport(importEntry.getPath(), 0);
209
+			HighLevelDefinition definition;
210
+			if (importEntry.isRelative()) {
211
+				definition = modulePackage.getImport(importEntry.getPath(), 0);
212
+			} else {
213
+				definition = rootPackage.getImport(importEntry.getPath(), 0);
214
+			}
215
+			
207 216
 			if (definition == null)
208
-				throw new CompileException(importEntry.position, CompileExceptionCode.IMPORT_NOT_FOUND, "Could not find type");
217
+				throw new CompileException(importEntry.position, CompileExceptionCode.IMPORT_NOT_FOUND, "Could not find type " + importEntry.toString());
209 218
 			
210 219
 			scope.register(importEntry.getName(), definition);
211 220
 		}

+ 21
- 2
Parser/src/main/java/org/openzen/zenscript/parser/ParsedImport.java ファイルの表示

@@ -18,6 +18,8 @@ import static org.openzen.zenscript.lexer.ZSTokenType.*;
18 18
  */
19 19
 public class ParsedImport {
20 20
 	public static ParsedImport parse(CodePosition position, ZSTokenStream tokens) {
21
+		boolean relative = tokens.optional(T_DOT) != null;
22
+		
21 23
 		List<String> importName = new ArrayList<>();
22 24
 		ZSToken tName = tokens.required(T_IDENTIFIER, "identifier expected");
23 25
 		importName.add(tName.content);
@@ -34,15 +36,17 @@ public class ParsedImport {
34 36
 		}
35 37
 
36 38
 		tokens.required(T_SEMICOLON, "; expected");
37
-		return new ParsedImport(position, importName, rename);
39
+		return new ParsedImport(position, relative, importName, rename);
38 40
 	}
39 41
 	
40 42
 	public final CodePosition position;
43
+	private final boolean relative;
41 44
 	private final List<String> importName;
42 45
 	private final String rename;
43 46
 	
44
-	public ParsedImport(CodePosition position, List<String> importName, String rename) {
47
+	public ParsedImport(CodePosition position, boolean relative, List<String> importName, String rename) {
45 48
 		this.position = position;
49
+		this.relative = relative;
46 50
 		this.importName = importName;
47 51
 		this.rename = rename;
48 52
 	}
@@ -51,7 +55,22 @@ public class ParsedImport {
51 55
 		return rename == null ? importName.get(importName.size() - 1) : rename;
52 56
 	}
53 57
 	
58
+	public boolean isRelative() {
59
+		return relative;
60
+	}
61
+	
54 62
 	public List<String> getPath() {
55 63
 		return importName;
56 64
 	}
65
+	
66
+	@Override
67
+	public String toString() {
68
+		StringBuilder result = new StringBuilder();
69
+		for (int i = 0; i < importName.size(); i++) {
70
+			if (i > 0)
71
+				result.append('.');
72
+			result.append(importName.get(i));
73
+		}
74
+		return result.toString();
75
+	}
57 76
 }

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java ファイルの表示

@@ -70,7 +70,7 @@ public class ParsedEnum extends BaseParsedDefinition {
70 70
 		super.compileMembers(scope);
71 71
 		
72 72
 		for (ParsedEnumConstant constant : enumValues) {
73
-			compiled.addMember(constant.getCompiled());
73
+			compiled.addEnumConstant(constant.getCompiled());
74 74
 		}
75 75
 	}
76 76
 

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java ファイルの表示

@@ -43,6 +43,8 @@ public class ParsedFunctionHeader {
43 43
 		if (tokens.optional(T_BRCLOSE) == null) {
44 44
 			do {
45 45
 				ZSToken argName = tokens.required(T_IDENTIFIER, "identifier expected");
46
+				boolean variadic = tokens.optional(T_DOT3) != null;
47
+				
46 48
 				IParsedType type = ParsedTypeBasic.ANY;
47 49
 				if (tokens.optional(K_AS) != null) {
48 50
 					type = IParsedType.parse(tokens);
@@ -51,7 +53,6 @@ public class ParsedFunctionHeader {
51 53
 				if (tokens.optional(T_ASSIGN) != null) {
52 54
 					defaultValue = ParsedExpression.parse(tokens);
53 55
 				}
54
-				boolean variadic = tokens.optional(T_DOT3) != null;
55 56
 				parameters.add(new ParsedFunctionParameter(argName.content, type, defaultValue, variadic));
56 57
 			} while (tokens.optional(T_COMMA) != null);
57 58
 			tokens.required(T_BRCLOSE, ") expected");

+ 0
- 38
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedImport.java ファイルの表示

@@ -1,38 +0,0 @@
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
-
7
-package org.openzen.zenscript.parser.definitions;
8
-
9
-import java.util.List;
10
-import org.openzen.zenscript.shared.CodePosition;
11
-
12
-/**
13
- *
14
- * @author Stanneke
15
- */
16
-public class ParsedImport {
17
-	private final CodePosition position;
18
-	private final List<String> name;
19
-	private final String rename;
20
-
21
-	public ParsedImport(CodePosition position, List<String> name, String rename) {
22
-		this.position = position;
23
-		this.name = name;
24
-		this.rename = rename;
25
-	}
26
-
27
-	public CodePosition getPosition() {
28
-		return position;
29
-	}
30
-
31
-	public List<String> getName() {
32
-		return name;
33
-	}
34
-
35
-	public String getRename() {
36
-		return rename == null ? name.get(name.size() - 1) : rename;
37
-	}
38
-}

+ 4
- 0
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java ファイルの表示

@@ -81,6 +81,10 @@ public abstract class ParsedDefinitionMember {
81 81
 					tokens.next();
82 82
 					modifiers |= Modifiers.EXTERN;
83 83
 					break;
84
+				case K_OVERRIDE:
85
+					tokens.next();
86
+					modifiers |= Modifiers.OVERRIDE;
87
+					break;
84 88
 				default:
85 89
 					break outer;
86 90
 			}

+ 4
- 2
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java ファイルの表示

@@ -95,6 +95,8 @@ public class Main {
95 95
 	}
96 96
 	
97 97
 	private static SemanticModule compileSyntaxToSemantic(ParsedFile[] files, GlobalRegistry registry) {
98
+		ZSPackage modulePackage = new ZSPackage(null);
99
+		
98 100
 		// We are considering all these files to be in the same package, so make
99 101
 		// a single PackageDefinition instance. If these files were in multiple
100 102
 		// packages, we'd need an instance for every package.
@@ -115,7 +117,7 @@ public class Main {
115 117
 			// compileMembers will register all definition members to their
116 118
 			// respective definitions, such as fields, constructors, methods...
117 119
 			// It doesn't yet compile the method contents.
118
-			file.compileMembers(rootPackage, definitions, globalRegistry, expansions, globals);
120
+			file.compileMembers(rootPackage, modulePackage, definitions, globalRegistry, expansions, globals);
119 121
 		}
120 122
 		
121 123
 		// scripts will store all the script blocks encountered in the files
@@ -124,7 +126,7 @@ public class Main {
124 126
 			// compileCode will convert the parsed statements and expressions
125 127
 			// into semantic code. This semantic code can then be compiled
126 128
 			// to various targets.
127
-			file.compileCode(rootPackage, definitions, globalRegistry, expansions, scripts, globals);
129
+			file.compileCode(rootPackage, modulePackage, definitions, globalRegistry, expansions, scripts, globals);
128 130
 		}
129 131
 		
130 132
 		Validator validator = new Validator();

+ 2
- 3
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java ファイルの表示

@@ -159,9 +159,8 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
159 159
 		
160 160
 		return isValid;
161 161
 	}
162
-
163
-	@Override
164
-	public Boolean visitEnumConstant(EnumConstantMember member) {
162
+	
163
+	public boolean visitEnumConstant(EnumConstantMember member) {
165 164
 		boolean isValid = true;
166 165
 		isValid &= ValidationUtils.validateIdentifier(validator, member.position, member.name);
167 166
 		if (member.constructor != null) {

+ 9
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java ファイルの表示

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.validator.visitors;
7 7
 
8
+import java.util.HashSet;
9
+import java.util.Set;
8 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
9 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10 12
 import static org.openzen.zenscript.codemodel.Modifiers.*;
@@ -17,7 +19,9 @@ import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
17 19
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
18 20
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
19 21
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
22
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
20 23
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
24
+import org.openzen.zenscript.validator.ValidationLogEntry;
21 25
 import org.openzen.zenscript.validator.Validator;
22 26
 import org.openzen.zenscript.validator.analysis.StatementScope;
23 27
 
@@ -168,6 +172,11 @@ public class DefinitionValidator implements DefinitionVisitor<Boolean> {
168 172
 		for (IDefinitionMember member : definition.members) {
169 173
 			isValid &= member.accept(memberValidator);
170 174
 		}
175
+		if (definition instanceof EnumDefinition) {
176
+			for (EnumConstantMember constant : ((EnumDefinition) definition).enumConstants) {
177
+				isValid &= memberValidator.visitEnumConstant(constant);
178
+			}
179
+		}
171 180
 		return isValid;
172 181
 	}
173 182
 

+ 21
- 3
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java ファイルの表示

@@ -148,10 +148,28 @@ public class ValidationUtils {
148 148
 			TypeParameter[] typeParameters,
149 149
 			ITypeID[] typeArguments)
150 150
 	{
151
-		if (typeParameters == null)
152
-			return typeArguments == null;
153
-		if (typeArguments == null)
151
+		if (typeParameters == null || typeParameters.length == 0) {
152
+			if (typeArguments == null || typeArguments.length == 0) {
153
+				return true;
154
+			} else {
155
+				target.logError(
156
+					ValidationLogEntry.Code.INVALID_TYPE_ARGUMENT,
157
+					position,
158
+					"Invalid number of type arguments: "
159
+							+ typeArguments.length
160
+							+ " arguments given but none expected");
161
+				return false;
162
+			}
163
+		}
164
+		if (typeArguments == null || typeArguments.length == 0) {
165
+			target.logError(
166
+					ValidationLogEntry.Code.INVALID_TYPE_ARGUMENT,
167
+					position,
168
+					"Invalid number of type arguments: "
169
+							+ typeParameters.length
170
+							+ " arguments expected but none given");
154 171
 			return false;
172
+		}
155 173
 		
156 174
 		if (typeParameters.length != typeArguments.length) {
157 175
 			target.logError(

読み込み中…
キャンセル
保存