-
-
Notifications
You must be signed in to change notification settings - Fork 467
/
assign.zep
989 lines (867 loc) · 19.2 KB
/
assign.zep
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
/**
* Control Flow
*/
namespace Stub;
class Assign
{
protected testVar { get };
protected myArray { get };
protected static testVarStatic;
public function testAssign1() -> int
{
int a;
let a = 1;
return a;
}
public function testAssign2() -> int
{
int a;
let a = true;
return a;
}
public function testAssign3() -> int
{
int a;
let a = false;
return a;
}
public function testAssign4() -> int
{
int a;
let a = null;
return a;
}
public function testAssign5() -> int
{
int a;
let a = 2.0;
return a;
}
public function testAssign6() -> bool
{
boolean a;
let a = 1;
return a;
}
public function testAssign7() -> bool
{
boolean a;
let a = 1.0;
return a;
}
public function testAssign8() -> bool
{
boolean a;
let a = true;
return a;
}
public function testAssign9() -> bool
{
boolean a;
let a = false;
return a;
}
public function testAssign10() -> bool
{
boolean a;
let a = null;
return a;
}
public function testAssign11() -> double
{
double a;
let a = null;
return a;
}
public function testAssign12() -> double
{
double a;
let a = 4;
return a;
}
public function testAssign13() -> double
{
double a;
let a = false;
return a;
}
public function testAssign14() -> double
{
double a;
let a = true;
return a;
}
public function testAssign15() -> double
{
double a;
let a = 5.0;
return a;
}
public function testAssign16() -> int
{
var a;
let a = 1;
return a;
}
public function testAssign17() -> double
{
var a;
let a = 1.0;
return a;
}
public function testAssign18() -> bool
{
var a;
let a = false;
return a;
}
public function testAssign19() -> bool
{
var a;
let a = true;
return a;
}
public function testAssign20() -> null
{
var a;
let a = null;
return a;
}
public function testAssign21() -> int
{
int a, b;
let a = 1,
b = a;
return b;
}
public function testAssign22() -> double
{
double a, b;
let a = 1.0,
b = a;
return b;
}
public function testAssign23() -> bool
{
boolean a, b;
let a = true,
b = a;
return b;
}
public function testAssign24() -> double
{
int a;
double b;
let a = 1,
b = a;
return b;
}
public function testAssign25() -> double
{
int a;
double b;
let a = 1,
b = a;
return b;
}
public function testAssign26() -> int
{
int b;
double a;
let a = 1,
b = a;
return b;
}
public function testAssign27() -> double
{
int b;
double a;
let b = 1,
a = b;
return a;
}
public function testAssign28() -> bool
{
int b;
boolean a;
let b = 1,
a = b;
return a;
}
public function testAssign29() -> bool
{
double b;
boolean a;
let b = 1.0,
a = b;
return a;
}
public function testAssign30() -> int
{
boolean b;
int a;
let b = false,
a = b;
return a;
}
public function testAssign31() -> double
{
boolean b;
double a;
let b = false,
a = b;
return a;
}
public function testAssign32() -> bool
{
boolean b;
var a;
let b = false,
a = b;
return a;
}
public function testAssign33() -> bool
{
boolean b; var a;
let b = false,
a = b;
return a;
}
public function testAssign34() -> bool
{
int b; var a;
let b = false,
a = b;
return a;
}
public function testAssign35() -> bool
{
double b; var a;
let b = false,
a = b;
return a;
}
public function testAssign36() -> bool
{
var b; var a;
let b = false,
a = b;
return a;
}
public function testAssign37() -> array
{
var v = "abc";
var arr = [];
let arr = [
"a": ["b_key": "b_val", "b": []]
];
let arr["a"]["b"]["d_key"] = "d_val";
let arr["s"] = 1;
let arr["a"]["b"]["c"]["d"]["e"] = "f";
let arr[1] = [
2: [3: 4]
];
let arr[1][2][5] = 6;
let arr[1][2][v] = v;
return arr;
}
public function testAssign38(index) -> array
{
var arr = [];
let arr[index] = "val";
return arr;
}
public function testAssign39() -> int
{
var a, b, c;
// Initialize variables
let a = "hello", b = false;
// Change their values
let a = 10, b = "140";
// Perform operations between them
let c = a + b;
return c;
}
public function testAssign40() -> int
{
var a, b;
// Initialize variables
let b = new \stdClass(), a = [];
// Change their values
let a = "123", b = 7;
// Perform operations between them
return a - b;
}
/**
* @link https://github.com/zephir-lang/zephir/issues/1573
*/
public function testAssign41(int num) -> int
{
var a;
let a = 42;
let a /= num;
return a;
}
/**
* @link https://github.com/zephir-lang/zephir/issues/1573
*/
public function testAssign42(int num) -> int
{
var a;
let a = 2;
let num /= a;
return num;
}
public function testAssign43(int num) -> int
{
var a;
let a = 43;
let a %= num;
return a;
}
public function testAssign44(int num) -> int
{
var a;
let a = 2;
let num %= a;
return num;
}
public function testPropertyAssign1()
{
let this->testVar = 1;
let this->testVar = 1.5;
let this->testVar = null;
let this->testVar = false;
let this->testVar = true;
let this->testVar = 'A';
let this->testVar = "hello";
let this->testVar = [];
return this->testVar;
}
public function testPropertyAssign2()
{
int a = 1;
double b = 1.5;
var c = null;
boolean d = false;
char e = 'A';
array f = [];
let this->testVar = a;
let this->testVar = b;
let this->testVar = c;
let this->testVar = d;
let this->testVar = e;
let this->testVar = f;
return this->testVar;
}
public function testPropertyIncr1()
{
let this->testVar = 1;
let this->testVar++;
return this->testVar;
}
public function testPropertyAddAssign1()
{
let this->testVar = 0;
let this->testVar += 2;
return this->testVar;
}
public function testPropertyAddAssign2()
{
let this->testVar = 1;
let this->testVar += 2;
return this->testVar;
}
public function testPropertyAssignValuePlus1()
{
let this->testVar = 1;
let this->testVar = this->testVar + 1;
return this->testVar;
}
public function testPropertyDecr()
{
let this->testVar = 2;
let this->testVar--;
return this->testVar;
}
public function testPropertySubAssign1()
{
let this->testVar = 0;
let this->testVar -= 2;
return this->testVar;
}
public function testPropertySubAssign2()
{
let this->testVar = 1;
let this->testVar -= 2;
return this->testVar;
}
public function testPropertyMulAssign1()
{
let this->testVar = 1;
let this->testVar *= 2;
return this->testVar;
}
public function testPropertyMulAssign2()
{
let this->testVar = 1;
let this->testVar *= 3;
return this->testVar;
}
public function testPropertyAssignStringConcat()
{
let this->testVar = "test";
let this->testVar .= " string";
return this->testVar;
}
public function testPropertyArray1()
{
let this->myArray = [];
let this->myArray[] = 1;
let this->myArray[] = 1.5;
let this->myArray[] = null;
let this->myArray[] = false;
let this->myArray[] = true;
let this->myArray[] = 'A';
let this->myArray[] = "hello";
let this->myArray[] = [];
return this->myArray;
}
public function testPropertyArray2()
{
int a = 1;
double b = 1.5;
var c = null;
boolean d = false;
char e = 'A';
array f = [];
let this->myArray = [];
let this->myArray[] = a;
let this->myArray[] = b;
let this->myArray[] = c;
let this->myArray[] = d;
let this->myArray[] = e;
let this->myArray[] = f;
return this->myArray;
}
public function testPropertyArray3()
{
let this->myArray = [];
let this->myArray[0] = 1;
let this->myArray[0] = 1.5;
let this->myArray[0] = null;
let this->myArray[0] = false;
let this->myArray[0] = true;
let this->myArray[0] = 'A';
let this->myArray[0] = [];
return this->myArray;
}
public function testPropertyArray4(index)
{
let this->myArray = [];
let this->myArray[index] = 1;
let this->myArray[index] = 1.5;
let this->myArray[index] = null;
let this->myArray[index] = false;
let this->myArray[index] = true;
let this->myArray[index] = 'A';
let this->myArray[index] = [];
return this->myArray;
}
public function testPropertyArray5(string index)
{
let this->myArray = [];
let this->myArray[index] = 1;
let this->myArray[index] = 1.5;
let this->myArray[index] = null;
let this->myArray[index] = false;
let this->myArray[index] = true;
let this->myArray[index] = 'A';
let this->myArray[index] = [];
return this->myArray;
}
public function testPropertyArray6()
{
let this->myArray = [];
let this->myArray[0][1] = 1;
let this->myArray[0][1] = 1.5;
let this->myArray[0][1] = null;
let this->myArray[0][1] = false;
let this->myArray[0][1] = true;
let this->myArray[0][1] = 'A';
let this->myArray[0][1] = "hello";
let this->myArray[0][1] = [];
return this->myArray;
}
public function testPropertyArray7()
{
let this->myArray = [];
let this->myArray["hello"]["hello"] = 1;
let this->myArray["hello"]["hello"] = 1.5;
let this->myArray["hello"]["hello"] = null;
let this->myArray["hello"]["hello"] = false;
let this->myArray["hello"]["hello"] = true;
let this->myArray["hello"]["hello"] = 'A';
let this->myArray["hello"]["hello"] = "hello";
let this->myArray["hello"]["hello"] = [];
return this->myArray;
}
public function testPropertyArray8(index)
{
let this->myArray = [];
let this->myArray[index][index] = 1;
let this->myArray[index][index] = 1.5;
let this->myArray[index][index] = null;
let this->myArray[index][index] = false;
let this->myArray[index][index] = true;
let this->myArray[index][index] = 'A';
let this->myArray[index][index] = "hello";
let this->myArray[index][index] = [];
return this->myArray;
}
public function testPropertyArray9(int index)
{
let this->myArray = [];
let this->myArray[index][index] = 1;
let this->myArray[index][index] = 1.5;
let this->myArray[index][index] = null;
let this->myArray[index][index] = false;
let this->myArray[index][index] = true;
let this->myArray[index][index] = 'A';
let this->myArray[index][index] = "hello";
let this->myArray[index][index] = [];
return this->myArray;
}
public function testPropertyArray10(string index)
{
let this->myArray = [];
let this->myArray[index][index] = 1;
let this->myArray[index][index] = 1.5;
let this->myArray[index][index] = null;
let this->myArray[index][index] = false;
let this->myArray[index][index] = true;
let this->myArray[index][index] = 'A';
let this->myArray[index][index] = "hello";
let this->myArray[index][index] = [];
return this->myArray;
}
public function testPropertyArray11(index)
{
let this->myArray[index][index][] = 1;
let this->myArray[index][index][] = 1.5;
let this->myArray[index][index][] = null;
let this->myArray[index][index][] = false;
let this->myArray[index][index][] = true;
let this->myArray[index][index][] = 'A';
let this->myArray[index][index][] = "hello";
let this->myArray[index][index][] = [];
return this->myArray;
}
public function testPropertyArray12(index)
{
var temp1, temp2, temp3;
let this->myArray[index][index][] = 1;
let this->myArray[index][index][] = 1.5;
let this->myArray[index][index][] = null;
let this->myArray[index][index][] = false;
let temp1 = this->myArray[index], temp2 = this->myArray;
let this->myArray[index][index][] = true;
let this->myArray[index][index][] = 'A';
let this->myArray[index][index][] = "hello";
let this->myArray[index][index][] = [];
let temp3 = count(this->myArray);
return this->myArray;
}
public function testPropertyArray13(index)
{
var temp1, temp2, temp3;
let this->myArray[index][] = 1;
let this->myArray[index][] = 1.5;
let this->myArray[index][] = null;
let this->myArray[index][] = false;
let temp1 = this->myArray[index], temp2 = this->myArray;
let this->myArray[index][] = true;
let this->myArray[index][] = 'A';
let this->myArray[index][] = "hello";
let this->myArray[index][] = [];
let temp3 = count(this->myArray);
return this->myArray;
}
public function testPropertyArray14()
{
var v = "abc";
let this->myArray = [
"a": ["b_key": "b_val"]
];
let this->myArray["a"]["b"]["d_key"] = "d_val";
let this->myArray[1] = [
2: [3: 4]
];
let this->myArray["s"] = 1;
let this->myArray["a"]["b"]["c"]["d"]["e"] = "f";
let this->myArray[1][2][5] = 6;
let this->myArray[1][2][v] = v;
return this->myArray;
}
public function testStaticPropertyAssign1()
{
let self::testVarStatic = 1;
let self::testVarStatic = 1.5;
let self::testVarStatic = null;
let self::testVarStatic = false;
let self::testVarStatic = true;
let self::testVarStatic = 'A';
let self::testVarStatic = "hello";
let self::testVarStatic = [];
let self::testVarStatic = [1, 2, 3];
return self::testVarStatic;
}
public function testStaticPropertyAssign2()
{
int a = 1;
double b = 1.5;
var c = null;
boolean d = false;
char e = 'A';
array f = [];
let self::testVarStatic = a;
let self::testVarStatic = b;
let self::testVarStatic = c;
let self::testVarStatic = d;
let self::testVarStatic = e;
let self::testVarStatic = f;
return self::testVarStatic;
}
public function testStaticPropertyArray1()
{
let self::testVarStatic = [];
let self::testVarStatic[0] = 1;
let self::testVarStatic[0] = 1.5;
let self::testVarStatic[0] = null;
let self::testVarStatic[0] = false;
let self::testVarStatic[0] = true;
let self::testVarStatic[0] = 'A';
let self::testVarStatic[0] = "hello";
let self::testVarStatic[0] = [];
return self::testVarStatic;
}
public function testStaticPropertyArray2()
{
let self::testVarStatic = [];
let self::testVarStatic["hello"] = 1;
let self::testVarStatic["hello"] = 1.5;
let self::testVarStatic["hello"] = null;
let self::testVarStatic["hello"] = false;
let self::testVarStatic["hello"] = true;
let self::testVarStatic["hello"] = 'A';
let self::testVarStatic["hello"] = "hello";
let self::testVarStatic["hello"] = [];
return self::testVarStatic;
}
public function testStaticPropertyArray3(index)
{
let self::testVarStatic = [];
let self::testVarStatic[index] = 1;
let self::testVarStatic[index] = 1.5;
let self::testVarStatic[index] = null;
let self::testVarStatic[index] = false;
let self::testVarStatic[index] = true;
let self::testVarStatic[index] = 'A';
let self::testVarStatic[index] = "hello";
let self::testVarStatic[index] = [];
return self::testVarStatic;
}
public function testStaticPropertyArrayAppend()
{
let self::testVarStatic = [];
let self::testVarStatic[] = "test";
let self::testVarStatic[] = 1;
let self::testVarStatic[] = 1.5;
let self::testVarStatic[] = false;
let self::testVarStatic[] = [];
return self::testVarStatic;
}
public function testStaticPropertyArrayMutli1()
{
let self::testVarStatic = [];
let self::testVarStatic[0][0] = 1;
let self::testVarStatic[0][0] = 1.5;
let self::testVarStatic[0][0] = null;
let self::testVarStatic[0][0] = false;
let self::testVarStatic[0][0] = true;
let self::testVarStatic[0][0] = 'A';
let self::testVarStatic[0][0] = "hello";
let self::testVarStatic[0][0] = [];
return self::testVarStatic;
}
public function testStaticPropertyArrayMutli2()
{
let self::testVarStatic = [];
let self::testVarStatic["hello"]["hello"] = 1;
let self::testVarStatic["hello"]["hello"] = 1.5;
let self::testVarStatic["hello"]["hello"] = null;
let self::testVarStatic["hello"]["hello"] = false;
let self::testVarStatic["hello"]["hello"] = true;
let self::testVarStatic["hello"]["hello"] = 'A';
let self::testVarStatic["hello"]["hello"] = "hello";
let self::testVarStatic["hello"]["hello"] = [];
return self::testVarStatic;
}
public function testStaticPropertyArrayMutli3(index)
{
let self::testVarStatic = [];
let self::testVarStatic[index][index] = 1;
let self::testVarStatic[index][index] = 1.5;
let self::testVarStatic[index][index] = null;
let self::testVarStatic[index][index] = false;
let self::testVarStatic[index][index] = true;
let self::testVarStatic[index][index] = 'A';
let self::testVarStatic[index][index] = "hello";
let self::testVarStatic[index][index] = [];
return self::testVarStatic;
}
public function testStaticPropertyArrayMulti4()
{
var v = "abc";
let self::testVarStatic = [
"a": ["b_key": "b_val"]
];
let self::testVarStatic["a"]["b"]["d_key"] = "d_val";
let self::testVarStatic[1] = [
2: [3: 4]
];
let self::testVarStatic["s"] = 1;
let self::testVarStatic["a"]["b"]["c"]["d"]["e"] = "f";
let self::testVarStatic[1][2][5] = 6;
let self::testVarStatic[1][2][v] = v;
return self::testVarStatic;
}
public function testStaticPropertyArrayAppend1()
{
let self::testVarStatic = [];
let self::testVarStatic[0][] = 1;
let self::testVarStatic[0][] = 1.5;
let self::testVarStatic[0][] = null;
let self::testVarStatic[0][] = false;
let self::testVarStatic[0][] = true;
let self::testVarStatic[0][] = 'A';
let self::testVarStatic[0][] = "hello";
let self::testVarStatic[0][] = [];
return self::testVarStatic;
}
public function testArrayVarAssign1(var index, var value)
{
var a;
let a = [];
let a[index] = value;
return a;
}
public function testArrayVarAssign2(var index, var value)
{
var _POST;
let _POST = [];
let _POST[index] = value;
return _POST;
}
public function testArrayProperty(var index, var value)
{
var _POST;
let _POST = [];
let _POST[index] = value;
return _POST;
}
/**
* @link https://github.com/zephir-lang/zephir/issues/159
*/
public function testGlobalVarAssign(var index, var value)
{
let _POST[index] = value;
}
/**
* @link https://github.com/zephir-lang/zephir/issues/523
*/
public function testConstantKeyAssign()
{
var elements;
let elements = ["abc": 1, ABDAY_1: DAY_1, ABDAY_2: DAY_2];
}
/**
* @link https://github.com/zephir-lang/zephir/issues/746
*
*/
public function testArrayBoolExpressionAssign()
{
var str = "abc";
let this->myArray = [];
let this->myArray["a"] = str == "abc";
let this->myArray["b"] = str != "abc";
return this->myArray;
}
public function testAssignBitwiseX(int a, int b)
{
var op, i;
var result = [];
for op in ["or", "and", "xor", "shiftleft", "shiftright"] {
let i = a;
switch op {
case "or":
let i |= b;
break;
case "and":
let i &= b;
break;
case "xor":
let i ^= b;
break;
case "shiftleft":
let i <<= b;
break;
case "shiftright":
let i >>= b;
break;
}
let result[op] = i;
}
return result;
}
/**
* @link https://github.com/zephir-lang/zephir/issues/725
*/
public function testAssignSuperGlobals()
{
var v = "stest2";
let _GET["steststr"] = "stest";
let _GET["steststr2"] = v;
let _GET["stestint"] = 1;
let _GET["stestint2"] = 2;
let _GET[v] = "testval";
}
/**
* @link https://github.com/zephir-lang/zephir/issues/1917
*/
public function testAssignSuperGlobalsSERVER()
{
let _SERVER = array_merge(_SERVER, ["g1": "aaa", "g2": "bbb"]);
}
/**
* @link https://github.com/zephir-lang/zephir/issues/1917
*/
public function testAssignSuperGlobalsGET()
{
let _GET = array_merge(_GET, ["g1": "aaa", "g2": "bbb"]);
}
public function issue597()
{
if isset _POST["a"] {
if isset _GET["r"] {
// Nothing here
}
}
if isset _GET["s"] {
var s;
let s = _GET["s"] * 5;
let _GET["s"] = s;
return s;
}
}
}