|
@@ -10,52 +10,168 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
|
10
|
10
|
import org.openzen.zenscript.codemodel.Modifiers;
|
11
|
11
|
import org.openzen.zenscript.codemodel.OperatorType;
|
12
|
12
|
import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
|
|
13
|
+import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
|
13
|
14
|
import org.openzen.zenscript.codemodel.member.CasterMember;
|
|
15
|
+import org.openzen.zenscript.codemodel.member.GetterMember;
|
|
16
|
+import org.openzen.zenscript.codemodel.member.MethodMember;
|
14
|
17
|
import org.openzen.zenscript.codemodel.member.OperatorMember;
|
15
|
18
|
import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
|
16
|
|
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
|
|
19
|
+import static org.openzen.zenscript.codemodel.type.BasicTypeID.*;
|
|
20
|
+import org.openzen.zenscript.codemodel.type.ITypeID;
|
17
|
21
|
import org.openzen.zenscript.shared.CodePosition;
|
|
22
|
+import static org.openzen.zenscript.shared.CodePosition.BUILTIN;
|
18
|
23
|
|
19
|
24
|
/**
|
20
|
25
|
*
|
21
|
26
|
* @author Hoofdgebruiker
|
22
|
27
|
*/
|
23
|
28
|
public class BuiltinTypeMembers {
|
|
29
|
+ private BuiltinTypeMembers() {}
|
|
30
|
+
|
24
|
31
|
public static final ConstantGetterMember INT_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantIntExpression(position, Integer.MIN_VALUE));
|
25
|
32
|
public static final ConstantGetterMember INT_GET_MAX_VALUE = new ConstantGetterMember("MAX_VALUE", position -> new ConstantIntExpression(position, Integer.MAX_VALUE));
|
26
|
33
|
|
27
|
|
- public static final OperatorMember INT_ADD_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
|
28
|
|
- public static final OperatorMember INT_ADD_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
|
29
|
|
- public static final OperatorMember INT_ADD_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
|
30
|
|
- public static final OperatorMember INT_ADD_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
|
31
|
|
-
|
32
|
|
- public static final OperatorMember INT_SUB_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
|
33
|
|
- public static final OperatorMember INT_SUB_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
|
34
|
|
- public static final OperatorMember INT_SUB_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
|
35
|
|
- public static final OperatorMember INT_SUB_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
|
36
|
|
-
|
37
|
|
- public static final OperatorMember INT_MUL_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
|
38
|
|
- public static final OperatorMember INT_MUL_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
|
39
|
|
- public static final OperatorMember INT_MUL_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
|
40
|
|
- public static final OperatorMember INT_MUL_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
|
41
|
|
-
|
42
|
|
- public static final OperatorMember INT_DIV_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
|
43
|
|
- public static final OperatorMember INT_DIV_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
|
44
|
|
- public static final OperatorMember INT_DIV_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
|
45
|
|
- public static final OperatorMember INT_DIV_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
|
46
|
|
-
|
47
|
|
- public static final OperatorMember INT_MOD_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MOD, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
|
48
|
|
- public static final OperatorMember INT_MOD_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MOD, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
|
49
|
|
-
|
50
|
|
- public static final CasterMember INT_TO_BYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.BYTE);
|
51
|
|
- public static final CasterMember INT_TO_SBYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SBYTE);
|
52
|
|
- public static final CasterMember INT_TO_SHORT = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SHORT);
|
53
|
|
- public static final CasterMember INT_TO_USHORT = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.USHORT);
|
54
|
|
- public static final CasterMember INT_TO_UINT = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.UINT);
|
55
|
|
- public static final CasterMember INT_TO_LONG = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.LONG);
|
56
|
|
- public static final CasterMember INT_TO_ULONG = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.ULONG);
|
57
|
|
- public static final CasterMember INT_TO_FLOAT = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.FLOAT);
|
58
|
|
- public static final CasterMember INT_TO_DOUBLE = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.DOUBLE);
|
59
|
|
- public static final CasterMember INT_TO_CHAR = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.CHAR);
|
60
|
|
- public static final CasterMember INT_TO_STRING = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.STRING);
|
|
34
|
+ public static final ConstantGetterMember LONG_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantLongExpression(position, Long.MIN_VALUE));
|
|
35
|
+ public static final ConstantGetterMember LONG_GET_MAX_VALUE = new ConstantGetterMember("MAX_VALUE", position -> new ConstantLongExpression(position, Long.MAX_VALUE));
|
|
36
|
+
|
|
37
|
+ public static final OperatorMember BOOL_NOT = not(BOOL);
|
|
38
|
+
|
|
39
|
+ public static final OperatorMember BYTE_NOT = not(BYTE);
|
|
40
|
+ public static final OperatorMember SBYTE_NOT = not(SBYTE);
|
|
41
|
+ public static final OperatorMember SHORT_NOT = not(SHORT);
|
|
42
|
+ public static final OperatorMember USHORT_NOT = not(USHORT);
|
|
43
|
+ public static final OperatorMember INT_NOT = not(INT);
|
|
44
|
+ public static final OperatorMember UINT_NOT = not(UINT);
|
|
45
|
+ public static final OperatorMember LONG_NOT = not(LONG);
|
|
46
|
+ public static final OperatorMember ULONG_NOT = not(ULONG);
|
|
47
|
+
|
|
48
|
+ public static final OperatorMember BYTE_NEG = neg(BYTE);
|
|
49
|
+ public static final OperatorMember SBYTE_NEG = neg(SBYTE);
|
|
50
|
+ public static final OperatorMember SHORT_NEG = neg(SHORT);
|
|
51
|
+ public static final OperatorMember USHORT_NEG = neg(USHORT);
|
|
52
|
+ public static final OperatorMember INT_NEG = neg(INT);
|
|
53
|
+ public static final OperatorMember UINT_NEG = neg(UINT);
|
|
54
|
+ public static final OperatorMember LONG_NEG = neg(LONG);
|
|
55
|
+ public static final OperatorMember ULONG_NEG = neg(ULONG);
|
|
56
|
+ public static final OperatorMember FLOAT_NEG = neg(FLOAT);
|
|
57
|
+ public static final OperatorMember DOUBLE_NEG = neg(DOUBLE);
|
|
58
|
+
|
|
59
|
+ public static final OperatorMember BYTE_ADD_BYTE = add(BYTE, BYTE);
|
|
60
|
+ public static final OperatorMember SBYTE_ADD_SBYTE = add(SBYTE, SBYTE);
|
|
61
|
+ public static final OperatorMember SHORT_ADD_SHORT = add(SHORT, SHORT);
|
|
62
|
+ public static final OperatorMember USHORT_ADD_USHORT = add(USHORT, USHORT);
|
|
63
|
+ public static final OperatorMember INT_ADD_INT = add(INT, INT);
|
|
64
|
+ public static final OperatorMember UINT_ADD_UINT = add(UINT, UINT);
|
|
65
|
+ public static final OperatorMember LONG_ADD_LONG = add(LONG, LONG);
|
|
66
|
+ public static final OperatorMember ULONG_ADD_ULONG = add(ULONG, ULONG);
|
|
67
|
+ public static final OperatorMember FLOAT_ADD_FLOAT = add(FLOAT, FLOAT);
|
|
68
|
+ public static final OperatorMember DOUBLE_ADD_DOUBLE = add(DOUBLE, DOUBLE);
|
|
69
|
+ public static final OperatorMember STRING_ADD_STRING = add(STRING, STRING);
|
|
70
|
+
|
|
71
|
+ public static final OperatorMember BYTE_SUB_BYTE = sub(BYTE, BYTE);
|
|
72
|
+ public static final OperatorMember SBYTE_SUB_SBYTE = sub(SBYTE, SBYTE);
|
|
73
|
+ public static final OperatorMember SHORT_SUB_SHORT = sub(SHORT, SHORT);
|
|
74
|
+ public static final OperatorMember USHORT_SUB_USHORT = sub(USHORT, USHORT);
|
|
75
|
+ public static final OperatorMember INT_SUB_INT = sub(INT, INT);
|
|
76
|
+ public static final OperatorMember UINT_SUB_UINT = sub(UINT, UINT);
|
|
77
|
+ public static final OperatorMember LONG_SUB_LONG = sub(LONG, LONG);
|
|
78
|
+ public static final OperatorMember ULONG_SUB_ULONG = sub(ULONG, ULONG);
|
|
79
|
+ public static final OperatorMember FLOAT_SUB_FLOAT = sub(FLOAT, FLOAT);
|
|
80
|
+ public static final OperatorMember DOUBLE_SUB_DOUBLE = sub(DOUBLE, DOUBLE);
|
|
81
|
+
|
|
82
|
+ public static final OperatorMember BYTE_MUL_BYTE = mul(BYTE, BYTE);
|
|
83
|
+ public static final OperatorMember SBYTE_MUL_SBYTE = mul(SBYTE, SBYTE);
|
|
84
|
+ public static final OperatorMember SHORT_MUL_SHORT = mul(SHORT, SHORT);
|
|
85
|
+ public static final OperatorMember USHORT_MUL_USHORT = mul(USHORT, USHORT);
|
|
86
|
+ public static final OperatorMember INT_MUL_INT = mul(INT, INT);
|
|
87
|
+ public static final OperatorMember UINT_MUL_UINT = mul(UINT, UINT);
|
|
88
|
+ public static final OperatorMember LONG_MUL_LONG = mul(LONG, LONG);
|
|
89
|
+ public static final OperatorMember ULONG_MUL_ULONG = mul(ULONG, ULONG);
|
|
90
|
+ public static final OperatorMember FLOAT_MUL_FLOAT = mul(FLOAT, FLOAT);
|
|
91
|
+ public static final OperatorMember DOUBLE_MUL_DOUBLE = mul(DOUBLE, DOUBLE);
|
|
92
|
+
|
|
93
|
+ public static final OperatorMember BYTE_DIV_BYTE = div(BYTE, BYTE);
|
|
94
|
+ public static final OperatorMember SBYTE_DIV_SBYTE = div(SBYTE, SBYTE);
|
|
95
|
+ public static final OperatorMember SHORT_DIV_SHORT = div(SHORT, SHORT);
|
|
96
|
+ public static final OperatorMember USHORT_DIV_USHORT = div(USHORT, USHORT);
|
|
97
|
+ public static final OperatorMember INT_DIV_INT = div(INT, INT);
|
|
98
|
+ public static final OperatorMember UINT_DIV_UINT = div(UINT, UINT);
|
|
99
|
+ public static final OperatorMember LONG_DIV_LONG = div(LONG, LONG);
|
|
100
|
+ public static final OperatorMember ULONG_DIV_ULONG = div(ULONG, ULONG);
|
|
101
|
+ public static final OperatorMember FLOAT_DIV_FLOAT = div(FLOAT, FLOAT);
|
|
102
|
+ public static final OperatorMember DOUBLE_DIV_DOUBLE = div(DOUBLE, DOUBLE);
|
|
103
|
+
|
|
104
|
+ public static final OperatorMember BYTE_MOD_BYTE = mod(BYTE, BYTE);
|
|
105
|
+ public static final OperatorMember SBYTE_MOD_SBYTE = mod(SBYTE, SBYTE);
|
|
106
|
+ public static final OperatorMember SHORT_MOD_SHORT = mod(SHORT, SHORT);
|
|
107
|
+ public static final OperatorMember USHORT_MOD_USHORT = mod(USHORT, USHORT);
|
|
108
|
+ public static final OperatorMember INT_MOD_INT = mod(INT, INT);
|
|
109
|
+ public static final OperatorMember UINT_MOD_UINT = mod(UINT, UINT);
|
|
110
|
+ public static final OperatorMember LONG_MOD_LONG = mod(LONG, LONG);
|
|
111
|
+ public static final OperatorMember ULONG_MOD_ULONG = mod(ULONG, ULONG);
|
|
112
|
+
|
|
113
|
+ public static final CasterMember INT_TO_BYTE = castExplicit(BYTE);
|
|
114
|
+ public static final CasterMember INT_TO_SBYTE = castExplicit(SBYTE);
|
|
115
|
+ public static final CasterMember INT_TO_SHORT = castExplicit(SHORT);
|
|
116
|
+ public static final CasterMember INT_TO_USHORT = castExplicit(USHORT);
|
|
117
|
+ public static final CasterMember INT_TO_UINT = castImplicit(UINT);
|
|
118
|
+ public static final CasterMember INT_TO_LONG = castImplicit(LONG);
|
|
119
|
+ public static final CasterMember INT_TO_ULONG = castImplicit(ULONG);
|
|
120
|
+ public static final CasterMember INT_TO_FLOAT = castImplicit(FLOAT);
|
|
121
|
+ public static final CasterMember INT_TO_DOUBLE = castImplicit(DOUBLE);
|
|
122
|
+ public static final CasterMember INT_TO_CHAR = castExplicit(CHAR);
|
|
123
|
+ public static final CasterMember INT_TO_STRING = castImplicit(STRING);
|
|
124
|
+
|
|
125
|
+ public static final CasterMember LONG_TO_BYTE = castExplicit(BYTE);
|
|
126
|
+ public static final CasterMember LONG_TO_SBYTE = castExplicit(SBYTE);
|
|
127
|
+ public static final CasterMember LONG_TO_SHORT = castExplicit(SHORT);
|
|
128
|
+ public static final CasterMember LONG_TO_USHORT = castExplicit(USHORT);
|
|
129
|
+ public static final CasterMember LONG_TO_INT = castExplicit(INT);
|
|
130
|
+ public static final CasterMember LONG_TO_UINT = castExplicit(UINT);
|
|
131
|
+ public static final CasterMember LONG_TO_ULONG = castImplicit(ULONG);
|
|
132
|
+ public static final CasterMember LONG_TO_FLOAT = castImplicit(FLOAT);
|
|
133
|
+ public static final CasterMember LONG_TO_DOUBLE = castImplicit(DOUBLE);
|
|
134
|
+ public static final CasterMember LONG_TO_CHAR = castExplicit(CHAR);
|
|
135
|
+ public static final CasterMember LONG_TO_STRING = castImplicit(STRING);
|
|
136
|
+
|
|
137
|
+ public static final GetterMember FLOAT_BITS = new GetterMember(BUILTIN, 0, "bits", UINT);
|
|
138
|
+ public static final GetterMember DOUBLE_BITS = new GetterMember(BUILTIN, 0, "bits", ULONG);
|
|
139
|
+ public static final MethodMember FLOAT_FROMBITS = new MethodMember(BUILTIN, Modifiers.MODIFIER_STATIC, "fromBits", new FunctionHeader(FLOAT, new FunctionParameter(UINT)));
|
|
140
|
+ public static final MethodMember DOUBLE_FROMBITS = new MethodMember(BUILTIN, Modifiers.MODIFIER_STATIC, "fromBits", new FunctionHeader(DOUBLE, new FunctionParameter(ULONG)));
|
|
141
|
+
|
|
142
|
+ private static OperatorMember not(ITypeID result) {
|
|
143
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.NOT, new FunctionHeader(result));
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ private static OperatorMember neg(ITypeID result) {
|
|
147
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.NEG, new FunctionHeader(result));
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ private static OperatorMember add(ITypeID operand, ITypeID result) {
|
|
151
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.ADD, new FunctionHeader(result, new FunctionParameter(operand)));
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ private static OperatorMember sub(ITypeID operand, ITypeID result) {
|
|
155
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.SUB, new FunctionHeader(result, new FunctionParameter(operand)));
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ private static OperatorMember mul(ITypeID operand, ITypeID result) {
|
|
159
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.MUL, new FunctionHeader(result, new FunctionParameter(operand)));
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ private static OperatorMember div(ITypeID operand, ITypeID result) {
|
|
163
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.DIV, new FunctionHeader(result, new FunctionParameter(operand)));
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ private static OperatorMember mod(ITypeID operand, ITypeID result) {
|
|
167
|
+ return new OperatorMember(BUILTIN, 0, OperatorType.MOD, new FunctionHeader(result, new FunctionParameter(operand)));
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+ private static CasterMember castExplicit(ITypeID result) {
|
|
171
|
+ return new CasterMember(CodePosition.BUILTIN, 0, result);
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ private static CasterMember castImplicit(ITypeID result) {
|
|
175
|
+ return new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, result);
|
|
176
|
+ }
|
61
|
177
|
}
|