-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReflection.clcl
More file actions
557 lines (465 loc) · 16.5 KB
/
Reflection.clcl
File metadata and controls
557 lines (465 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
class Field
{
include MObjectBase;
flags:long;
name:String;
resultType:String;
#value:Anonymous;
def initialize() {}
def clone():Field {
result := Field();
result.flags = self.flags;
if(self.name.identifyWith(null).negative()) {
result.name = self.name.clone();
}
if(self.resultType.identifyWith(null).negative()) {
result.resultType = self.resultType.clone();
}
return result;
}
def private():bool {
return (self.flags & Clover.FIELD_FLAGS_PRIVATE).to_bool;
}
def protected():bool {
return (self.flags & Clover.FIELD_FLAGS_PROTECTED).to_bool;
}
}
class MethodParam
{
include MObjectBase;
name:String;
type:String;
def initialize() {}
def clone(): MethodParam {
result := MethodParam();
if(self.name.identifyWith(null).negative()) {
result.name = self.name.clone();
}
if(self.type.identifyWith(null).negative()) {
result.type = self.type.clone();
}
return result;
}
}
class Method
{
include MObjectBase;
flags:long;
name:String;
path:String;
methodNameAndParams:String;
index:int;
params:MethodParam[];
resultType:String;
varNum:int;
genericsParamTypes:String[];
def initialize() {}
def clone(): Method {
result := Method();
result.flags = self.flags;
if(self.name.identifyWith(null).negative()) {
result.name = self.name.clone();
}
if(self.path.identifyWith(null).negative()) {
result.path = self.path.clone();
}
if(self.methodNameAndParams.identifyWith(null).negative()) {
result.methodNameAndParams = self.methodNameAndParams.clone();
}
result.index = self.index;
if(self.params.identifyWith(null).negative()) {
result.params = MethodParam[self.params.length]();
for(i:=0; i<self.params.length; i++) {
result.params[i] = self.params[i].clone();
}
}
if(self.resultType.identifyWith(null).negative()) {
result.resultType = self.resultType.clone();
}
result.varNum = self.varNum;
if(self.genericsParamTypes.identifyWith(null).negative()) {
result.genericsParamTypes = String[self.genericsParamTypes.length]();
for(j:=0; j<self.genericsParamTypes.length; j++) {
result.genericsParamTypes[j] = self.genericsParamTypes[j].clone();
}
}
return result;
}
def toString():String {
return methodNameAndParams;
}
}
class Class
{
include MObjectBase;
className:String;
flags:long;
genericsParamTypes:String[];
genericsParamNames:String[];
numFields:int;
numClassFields:int;
numMethods:int;
JS:bool;
def initialize() {}
def initialize(class_name:String, js:bool=false) {
className = class_name;
flags = Clover.getClassFlags(class_name, js);
genericsParamTypes = Clover.getClassGenericsParamTypes(class_name,js);
genericsParamNames = Clover.getClassGenericsParamNames(class_name,js);
numFields = Clover.getNumFields(class_name,js);
numClassFields = Clover.getNumClassFields(class_name,js);
numMethods = Clover.getNumMethods(class_name,js);
JS = js;
}
def clone():Class {
result := Class();
if(self.className.identifyWith(null).negative()) {
result.className = self.className.clone();
}
result.flags = self.flags;
if(self.genericsParamTypes.identifyWith(null).negative()) {
result.genericsParamTypes = String[self.genericsParamTypes.length]();
for(i:=0; i<self.genericsParamTypes.length; i++) {
result.genericsParamTypes[i] = self.genericsParamTypes[i].clone();
}
}
if(self.genericsParamNames.identifyWith(null).negative()) {
result.genericsParamNames = String[self.genericsParamNames.length]();
for(j:=0; j<self.genericsParamNames.length; j++) {
result.genericsParamNames[j] = self.genericsParamNames[j].clone();
}
}
result.numFields = self.numFields;
result.numClassFields = self.numClassFields;
result.numMethods = self.numMethods;
return result;
}
def equals(right:Class): bool {
return self.className.equals(right.className);
}
def toString(): String {
return self.className;
}
def appendField(name:String, type:String) {
Clover.appendField(className, name, type, JS);
}
def appendMethod(code:String) {
Clover.appendMethod(className, code, JS);
}
def appendMethod(method_index:int, code:String) {
Clover.appendMethod(className, method_index, code, JS);
}
def declareMethod(code:String):int {
return Clover.declareMethod(className, code);
}
def appendClassField(name:String, type:String) {
Clover.appendClassField(className, name, type, JS);
}
def getField(index:int): Field {
return Clover.getField(className, index, JS);
}
def getField(name:String): Field? {
for(i:=0; i<numFields; i++) {
field := getField(i);
if(field.name.equals(name)) {
return field;
}
}
return null;
}
def getClassField(index:int): Field {
return Clover.getClassField(className, index, JS);
}
def getClassField(name:String): Field? {
for(i:=0; i<numClassFields; i++) {
field := getClassField(i);
if(field.name.equals(name)) {
return field;
}
}
return null;
}
def getMethod(index:int): Method {
return Clover.getMethod(className, index, JS);
}
def getMethod(name:String): Method? {
for(i:=numMethods-1; i>=0; i--) { # reverse search for multiple definition
method := getMethod(i);
if(method.name.equals(name)) {
return method;
}
}
return null;
}
def getMethod(name:String, param_num:int, class_method:bool): Method? {
for(i:=numMethods-1; i>=0; i--) { # reverse search for multiple definition
method := getMethod(i);
if(method.name.equals(name) && method.params.length == param_num
&& class_method == (method.flags & Clover.METHOD_FLAGS_CLASS_METHOD).to_bool)
{
return method;
}
}
return null;
}
def getMethods():List<Method> {
result := List<Method>();
for(i:=0; i<numMethods; i++) {
result.add(getMethod(i));
}
return result;
}
def getFields():List<Field> {
result := List<Field>();
for(i:=0; i<numFields; i++) {
result.add(getField(i));
}
return result;
}
def getClassFields():List<Field> {
result := List<Field>();
for(i:=0; i<numClassFields; i++) {
result.add(getClassField(i));
}
return result;
}
def getClassMethods():List<Method> {
result := List<Method>();
for(i:=0; i<numMethods; i++) {
it := getMethod(i);
if((it.flags & Clover.METHOD_FLAGS_CLASS_METHOD).to_bool) {
result.push(it);
}
}
return result;
}
def getNoneClassMethods():List<Method> {
result := List<Method>();
for(i:=0; i<numMethods; i++) {
it := getMethod(i);
if(!((it.flags & Clover.METHOD_FLAGS_CLASS_METHOD).to_bool)) {
result.add(it);
}
}
return result;
}
def createObject(): Anonymous {
return Clover.createObject(className, JS);
}
def createArray(size:int): Anonymous {
return Clover.createArray(className, size);
}
def isInterface():bool {
return (self.flags & Clover.CLASS_FLAGS_INTERFACE).to_bool;
}
}
inherit Clover
{
def appendField(class_name:String, name:String, type:String, js:bool=false):static native throws Exception;
def appendMethod(class_name:String, code:String, js:bool=false): static native throws Exception;
def appendMethod(class_name:String, method_index:int, code:String, js:bool=false): static native throws Exception;
def appendClassField(class_name:String, name:String, type:String, js:bool=false):static native throws Exception;
def appendClass(code:String):static native throws Exception;
def declareMethod(class_name:String, code:String): static native int throws Exception;
def getField(class_name:String, index:int, js:bool=false):static native Field throws Exception;
def getClassField(class_name:String, index:int,js:bool=false):static native Field throws Exception;
def getMethod(class_name:String, index:int, js:bool=false):static native Method throws Exception;
def getClassFlags(class_name:String, js:bool=false): static native long throws Exception;
def getClassGenericsParamTypes(class_name:String, js:bool=false): static native String[] throws Exception;
def getClassGenericsParamNames(class_name:String, js:bool=false): static native String[] throws Exception;
def getNumFields(class_name:String, js:bool=false): static native int throws Exception;
def getNumClassFields(class_name:String, js:bool=false): static native int throws Exception;
def getNumMethods(class_name:String, js:bool=false): static native int throws Exception;
def isLoadedClass(class_name:String, js:bool=false): static native bool throws Exception;
def isDefinedClass(class_name:String, js:bool=false): static native bool throws Exception;
def createObject(class_name:String, js:bool=false): static native Anonymous;
def isTypedefedClass(class_name:String, class_name2:String, js:bool=false): static native bool;
def isPrimitiveClass(name:String):static bool {
return name.equals("int") || isTypedefedClass(name, "int") || name.equals("uint") || isTypedefedClass(name, "uint") || name.equals("byte") || isTypedefedClass(name, "byte") || name.equals("ubyte") || isTypedefedClass(name, "ubyte") || name.equals("short") || isTypedefedClass(name, "short") || name.equals("ushort") || isTypedefedClass(name, "ushort") || name.equals("long") || isTypedefedClass(name, "long") || name.equals("ulong") || isTypedefedClass(name, "ulong") || name.equals("float") || isTypedefedClass(name, "float") || name.equals("double") || isTypedefedClass(name, "double") || name.equals("pointer") || isTypedefedClass(name, "pointer") || name.equals("char") || isTypedefedClass(name, "char") || name.equals("bool") || isTypedefedClass(name, "bool") || name.match(/lambda$|lambda\(\)|lambda\(.*/) || isTypedefedClass(name, "lambda") || name.equals("regex")|| isTypedefedClass(name, "regex") ;
}
def primitiveClassToBoxingClass(name:String):static String {
when(name) {
case ("int") {
return "Integer";
}
case ("uint") {
return "UInteger";
}
case ("byte") {
return "Byte";
}
case ("ubyte") {
return "UByte";
}
case ("short") {
return "Short";
}
case ("ushort") {
return "UShort";
}
case ("long") {
return "Long";
}
case ("ulong") {
return "ULong";
}
case ("float") {
return "Float";
}
case ("double") {
return "Double";
}
case ("pointer") {
return "Pointer";
}
case ("char") {
return "Char";
}
case ("bool") {
return "Bool";
}
else {
return name;
}
}
}
def boxingClassToPrimitiveClass(name:String):static String {
when(name) {
case ("Integer") {
return "int";
}
case ("UInteger") {
return "uint";
}
case ("Byte") {
return "byte";
}
case ("UByte") {
return "ubyte";
}
case ("Short") {
return "short";
}
case ("UShort") {
return "ushort";
}
case ("Long") {
return "long";
}
case ("ULong") {
return "ulong";
}
case ("Float") {
return "float";
}
case ("Double") {
return "double";
}
case ("Pointer") {
return "pointer";
}
case ("Char") {
return "char";
}
case ("Bool") {
return "bool";
}
else {
return name;
}
}
}
def initialize_reflection(): static native;
FIELD_FLAGS_PRIVATE:static long;
FIELD_FLAGS_PROTECTED:static long;
METHOD_FLAGS_NATIVE:static long;
METHOD_FLAGS_CLASS_METHOD:static long;
CLASS_FLAGS_PRIMITIVE:static long;
CLASS_FLAGS_INTERFACE:static long;
CLASS_FLAGS_MODIFIED:static long;
CLASS_FLAGS_ALLOCATED:static long;
CLASS_FLAGS_DYNAMIC_CLASS:static long;
CLASS_FLAGS_NO_FREE_OBJECT:static long;
def initialize():static {
inherit();
Clover.initialize_reflection();
Clover.initializeMethodDefinedClasses = List<Class>();
Clover.cloneMethodDefinedClasses = List<Class>();
Clover.initializeMethodDefinedClassMethodIndexes = List<Integer>();
Clover.cloneMethodDefinedClassMethodIndexes = List<Integer>();
nothingMethodDefinedClasses = List<Class>();
nothingMethodDefinedClassMethodIndexes = List<Integer>();
}
def getAllClassName(): static native String[];
def getModifiedClass(): static EqualableList<Class> {
result := EqualableList<Class>();
getAllClassName().each {
klass := Class(it);
if((klass.flags & CLASS_FLAGS_MODIFIED).to_bool) {
result.add(klass);
}
}
return result;
}
initializeMethodDefinedClasses:static List<Class>;
initializeMethodDefinedClassMethodIndexes:static List<Integer>;
cloneMethodDefinedClasses:static List<Class>;
cloneMethodDefinedClassMethodIndexes:static List<Integer>;
nothingMethodDefinedClasses:static List<Class>;
nothingMethodDefinedClassMethodIndexes:static List<Integer>;
def compileTimeScriptingOnDeclareTime():static {
}
def compileTimeScripting():static {
}
}
inherit Array<T:Object>
{
def clone():Array<T> {
result := Array<T>();
if(!self.items.identifyWith(null)) {
class_name := self.items.className().subString(0, -3);
klass := Class(class_name);
result.items = klass.createArray(self.items.length);
for(i:=0; i<self.items.length; i++) {
result.items[i] = self.items[i];
}
}
return result;
}
}
inherit EqualableArray <T:IEqualable>
{
def initialize(num:int) {
self.items = Clover.createArray("Object", num);
}
def clone():EqualableArray<T> {
result := EqualableArray<T>();
if(!self.items.identifyWith(null)) {
class_name := self.items.className().subString(0, -3);
klass := Class(class_name);
result.items = klass.createArray(self.items.length);
for(i:=0; i<self.items.length; i++) {
result.items[i] = self.items[i].clone();
}
}
return result;
}
}
inherit SortableArray <T:ISortable>
{
def initialize(num:int) {
self.items = Clover.createArray("Object", num);
}
def clone():SortableArray<T> {
result := SortableArray<T>();
if(!self.items.identifyWith(null)) {
class_name := self.items.className().subString(0, -3);
klass := Class(class_name);
result.items = klass.createArray(self.items.length);
for(i:=0; i<self.items.length; i++) {
result.items[i] = self.items[i].clone();
}
}
return result;
}
}