|
@@ -8,10 +8,14 @@ package org.openzen.zenscript.parser.definitions;
|
8
|
8
|
import java.util.ArrayList;
|
9
|
9
|
import java.util.List;
|
10
|
10
|
import org.openzen.zenscript.codemodel.member.EnumConstantMember;
|
|
11
|
+import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
|
11
|
12
|
import org.openzen.zenscript.lexer.ZSToken;
|
12
|
13
|
import org.openzen.zenscript.lexer.ZSTokenStream;
|
13
|
14
|
import org.openzen.zenscript.lexer.ZSTokenType;
|
|
15
|
+import org.openzen.zenscript.linker.ExpressionScope;
|
|
16
|
+import org.openzen.zenscript.parser.expression.ParsedCallArguments;
|
14
|
17
|
import org.openzen.zenscript.parser.expression.ParsedExpression;
|
|
18
|
+import org.openzen.zenscript.parser.expression.ParsedNewExpression;
|
15
|
19
|
import org.openzen.zenscript.shared.CodePosition;
|
16
|
20
|
|
17
|
21
|
/**
|
|
@@ -19,7 +23,7 @@ import org.openzen.zenscript.shared.CodePosition;
|
19
|
23
|
* @author Hoofdgebruiker
|
20
|
24
|
*/
|
21
|
25
|
public class ParsedEnumConstant {
|
22
|
|
- public static ParsedEnumConstant parse(ZSTokenStream tokens) {
|
|
26
|
+ public static ParsedEnumConstant parse(ZSTokenStream tokens, int value) {
|
23
|
27
|
ZSToken name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected");
|
24
|
28
|
List<ParsedExpression> arguments = new ArrayList<>();
|
25
|
29
|
if (tokens.optional(ZSTokenType.T_BROPEN) != null) {
|
|
@@ -29,7 +33,7 @@ public class ParsedEnumConstant {
|
29
|
33
|
tokens.required(ZSTokenType.T_BRCLOSE, ") expected");
|
30
|
34
|
}
|
31
|
35
|
|
32
|
|
- return new ParsedEnumConstant(name.position, name.content, arguments);
|
|
36
|
+ return new ParsedEnumConstant(name.position, name.content, value, arguments);
|
33
|
37
|
}
|
34
|
38
|
|
35
|
39
|
public final CodePosition position;
|
|
@@ -38,11 +42,20 @@ public class ParsedEnumConstant {
|
38
|
42
|
|
39
|
43
|
private final EnumConstantMember compiled;
|
40
|
44
|
|
41
|
|
- public ParsedEnumConstant(CodePosition position, String name, List<ParsedExpression> arguments) {
|
|
45
|
+ public ParsedEnumConstant(CodePosition position, String name, int value, List<ParsedExpression> arguments) {
|
42
|
46
|
this.position = position;
|
43
|
47
|
this.name = name;
|
44
|
48
|
this.arguments = arguments;
|
45
|
49
|
|
46
|
|
- compiled = new EnumConstantMember(position, name);
|
|
50
|
+ compiled = new EnumConstantMember(position, name, value);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ public EnumConstantMember getCompiled() {
|
|
54
|
+ return compiled;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ public void compileCode(DefinitionTypeID type, ExpressionScope scope) {
|
|
58
|
+ ParsedCallArguments arguments = new ParsedCallArguments(this.arguments);
|
|
59
|
+ compiled.constructor = ParsedNewExpression.compile(position, type, arguments, scope);
|
47
|
60
|
}
|
48
|
61
|
}
|