|
@@ -0,0 +1,320 @@
|
|
1
|
+package org.openzen.zenscript.scriptingexample.writer;
|
|
2
|
+
|
|
3
|
+import org.objectweb.asm.Type;
|
|
4
|
+import org.openzen.zenscript.codemodel.expression.*;
|
|
5
|
+import org.openzen.zenscript.scriptingexample.NativeFieldMember;
|
|
6
|
+import org.openzen.zenscript.scriptingexample.NativeMethodMember;
|
|
7
|
+
|
|
8
|
+public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
|
|
9
|
+
|
|
10
|
+ private final JavaWriter javaWriter;
|
|
11
|
+
|
|
12
|
+ public JavaExpressionVisitor(final JavaWriter javaWriter) {
|
|
13
|
+ this.javaWriter = javaWriter;
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ @Override
|
|
17
|
+ public Void visitAndAnd(AndAndExpression expression) {
|
|
18
|
+ return null;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @Override
|
|
22
|
+ public Void visitArray(ArrayExpression expression) {
|
|
23
|
+ return null;
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ @Override
|
|
27
|
+ public Void visitCompare(BasicCompareExpression expression) {
|
|
28
|
+ return null;
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Override
|
|
32
|
+ public Void visitCall(CallExpression expression) {
|
|
33
|
+
|
|
34
|
+ expression.target.accept(this);
|
|
35
|
+ for (Expression argument : expression.arguments.arguments) {
|
|
36
|
+ argument.accept(this);
|
|
37
|
+ }
|
|
38
|
+ if (expression.member instanceof NativeMethodMember) {
|
|
39
|
+ javaWriter.invokeVirtual(((NativeMethodMember) expression.member).className.replaceFirst("L", "").replace(";", ""), ((NativeMethodMember) expression.member).name, ((NativeMethodMember) expression.member).signature);
|
|
40
|
+ }
|
|
41
|
+ return null;
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ @Override
|
|
45
|
+ public Void visitCallStatic(CallStaticExpression expression) {
|
|
46
|
+ return null;
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Override
|
|
50
|
+ public Void visitCapturedClosure(CapturedClosureExpression expression) {
|
|
51
|
+ return null;
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ @Override
|
|
55
|
+ public Void visitCapturedDirect(CapturedDirectExpression expression) {
|
|
56
|
+ return null;
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ @Override
|
|
60
|
+ public Void visitCapturedLocalVariable(CapturedLocalVariableExpression expression) {
|
|
61
|
+ return null;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Override
|
|
65
|
+ public Void visitCapturedParameter(CapturedParameterExpression expression) {
|
|
66
|
+ return null;
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ @Override
|
|
70
|
+ public Void visitCapturedThis(CapturedThisExpression expression) {
|
|
71
|
+ return null;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ @Override
|
|
75
|
+ public Void visitCheckNull(CheckNullExpression expression) {
|
|
76
|
+ return null;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ @Override
|
|
80
|
+ public Void visitCoalesce(CoalesceExpression expression) {
|
|
81
|
+ return null;
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ @Override
|
|
85
|
+ public Void visitConditional(ConditionalExpression expression) {
|
|
86
|
+ return null;
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ @Override
|
|
90
|
+ public Void visitConstantBool(ConstantBoolExpression expression) {
|
|
91
|
+ javaWriter.constant(expression.value);
|
|
92
|
+ return null;
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ @Override
|
|
96
|
+ public Void visitConstantByte(ConstantByteExpression expression) {
|
|
97
|
+ javaWriter.biPush(expression.value);
|
|
98
|
+ return null;
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ @Override
|
|
102
|
+ public Void visitConstantChar(ConstantCharExpression expression) {
|
|
103
|
+ javaWriter.constant(expression.value);
|
|
104
|
+ return null;
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ @Override
|
|
108
|
+ public Void visitConstantDouble(ConstantDoubleExpression expression) {
|
|
109
|
+ javaWriter.constant(expression.value);
|
|
110
|
+ return null;
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ @Override
|
|
114
|
+ public Void visitConstantFloat(ConstantFloatExpression expression) {
|
|
115
|
+ javaWriter.constant(expression.value);
|
|
116
|
+ return null;
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ @Override
|
|
120
|
+ public Void visitConstantInt(ConstantIntExpression expression) {
|
|
121
|
+ javaWriter.constant(expression.value);
|
|
122
|
+ return null;
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ @Override
|
|
126
|
+ public Void visitConstantLong(ConstantLongExpression expression) {
|
|
127
|
+ javaWriter.constant(expression.value);
|
|
128
|
+ return null;
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ @Override
|
|
132
|
+ public Void visitConstantSByte(ConstantSByteExpression expression) {
|
|
133
|
+ javaWriter.constant(expression.value);
|
|
134
|
+ return null;
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ @Override
|
|
138
|
+ public Void visitConstantShort(ConstantShortExpression expression) {
|
|
139
|
+ javaWriter.siPush(expression.value);
|
|
140
|
+ return null;
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ @Override
|
|
144
|
+ public Void visitConstantString(ConstantStringExpression expression) {
|
|
145
|
+ javaWriter.constant(expression.value);
|
|
146
|
+ return null;
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ @Override
|
|
150
|
+ public Void visitConstantUInt(ConstantUIntExpression expression) {
|
|
151
|
+ javaWriter.constant(expression.value);
|
|
152
|
+ return null;
|
|
153
|
+ }
|
|
154
|
+
|
|
155
|
+ @Override
|
|
156
|
+ public Void visitConstantULong(ConstantULongExpression expression) {
|
|
157
|
+ javaWriter.constant(expression.value);
|
|
158
|
+ return null;
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ @Override
|
|
162
|
+ public Void visitConstantUShort(ConstantUShortExpression expression) {
|
|
163
|
+ javaWriter.constant(expression.value);
|
|
164
|
+ return null;
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ @Override
|
|
168
|
+ public Void visitConstructorCall(ConstructorCallExpression expression) {
|
|
169
|
+ return null;
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ @Override
|
|
173
|
+ public Void visitEnumConstant(EnumConstantExpression expression) {
|
|
174
|
+ return null;
|
|
175
|
+ }
|
|
176
|
+
|
|
177
|
+ @Override
|
|
178
|
+ public Void visitEquals(EqualsExpression expression) {
|
|
179
|
+ return null;
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ @Override
|
|
183
|
+ public Void visitFunction(FunctionExpression expression) {
|
|
184
|
+ return null;
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ @Override
|
|
188
|
+ public Void visitGenericCompare(GenericCompareExpression expression) {
|
|
189
|
+ return null;
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ @Override
|
|
193
|
+ public Void visitGetField(GetFieldExpression expression) {
|
|
194
|
+ return null;
|
|
195
|
+ }
|
|
196
|
+
|
|
197
|
+ @Override
|
|
198
|
+ public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
|
|
199
|
+ return null;
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ @Override
|
|
203
|
+ public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
|
|
204
|
+ return null;
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ @Override
|
|
208
|
+ public Void visitGetStaticField(GetStaticFieldExpression expression) {
|
|
209
|
+
|
|
210
|
+ if (expression.field instanceof NativeFieldMember)
|
|
211
|
+
|
|
212
|
+ javaWriter.getStaticField(((NativeFieldMember) expression.field).className, expression.field.name, Type.getType(expression.type.accept(new JavaTypeVisitor())).getDescriptor());
|
|
213
|
+ return null;
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ @Override
|
|
217
|
+ public Void visitGetter(GetterExpression expression) {
|
|
218
|
+ return null;
|
|
219
|
+ }
|
|
220
|
+
|
|
221
|
+ @Override
|
|
222
|
+ public Void visitInterfaceCast(InterfaceCastExpression expression) {
|
|
223
|
+ return null;
|
|
224
|
+ }
|
|
225
|
+
|
|
226
|
+ @Override
|
|
227
|
+ public Void visitIs(IsExpression expression) {
|
|
228
|
+ return null;
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ @Override
|
|
232
|
+ public Void visitMakeConst(MakeConstExpression expression) {
|
|
233
|
+ return null;
|
|
234
|
+ }
|
|
235
|
+
|
|
236
|
+ @Override
|
|
237
|
+ public Void visitMap(MapExpression expression) {
|
|
238
|
+ return null;
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ @Override
|
|
242
|
+ public Void visitNew(NewExpression expression) {
|
|
243
|
+ return null;
|
|
244
|
+ }
|
|
245
|
+
|
|
246
|
+ @Override
|
|
247
|
+ public Void visitNot(NotExpression expression) {
|
|
248
|
+ return null;
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ @Override
|
|
252
|
+ public Void visitNull(NullExpression expression) {
|
|
253
|
+ return null;
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ @Override
|
|
257
|
+ public Void visitOrOr(OrOrExpression expression) {
|
|
258
|
+ return null;
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ @Override
|
|
262
|
+ public Void visitRange(RangeExpression expression) {
|
|
263
|
+ return null;
|
|
264
|
+ }
|
|
265
|
+
|
|
266
|
+ @Override
|
|
267
|
+ public Void visitSetField(SetFieldExpression expression) {
|
|
268
|
+ return null;
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ @Override
|
|
272
|
+ public Void visitSetFunctionParameter(SetFunctionParameterExpression expression) {
|
|
273
|
+ return null;
|
|
274
|
+ }
|
|
275
|
+
|
|
276
|
+ @Override
|
|
277
|
+ public Void visitSetLocalVariable(SetLocalVariableExpression expression) {
|
|
278
|
+ return null;
|
|
279
|
+ }
|
|
280
|
+
|
|
281
|
+ @Override
|
|
282
|
+ public Void visitSetStaticField(SetStaticFieldExpression expression) {
|
|
283
|
+ return null;
|
|
284
|
+ }
|
|
285
|
+
|
|
286
|
+ @Override
|
|
287
|
+ public Void visitSetter(SetterExpression expression) {
|
|
288
|
+ return null;
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ @Override
|
|
292
|
+ public Void visitStaticGetter(StaticGetterExpression expression) {
|
|
293
|
+ return null;
|
|
294
|
+ }
|
|
295
|
+
|
|
296
|
+ @Override
|
|
297
|
+ public Void visitStaticSetter(StaticSetterExpression expression) {
|
|
298
|
+ return null;
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ @Override
|
|
302
|
+ public Void visitStringConcat(StringConcatExpression expression) {
|
|
303
|
+ return null;
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+ @Override
|
|
307
|
+ public Void visitSubstring(SubstringExpression expression) {
|
|
308
|
+ return null;
|
|
309
|
+ }
|
|
310
|
+
|
|
311
|
+ @Override
|
|
312
|
+ public Void visitThis(ThisExpression expression) {
|
|
313
|
+ return null;
|
|
314
|
+ }
|
|
315
|
+
|
|
316
|
+ @Override
|
|
317
|
+ public Void visitWrapOptional(WrapOptionalExpression expression) {
|
|
318
|
+ return null;
|
|
319
|
+ }
|
|
320
|
+}
|