casty 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3012 @@
1
+ ######################################################################
2
+ #
3
+ # Parser routine tests. One test for each grammar rule.
4
+ #
5
+ ######################################################################
6
+
7
+ require 'test_helper'
8
+
9
+ class ParserTest < Test::Unit::TestCase
10
+ def check(s)
11
+ check_ast(s){|inp| @parser.parse(inp)}
12
+ end
13
+
14
+ def setup
15
+ @parser = C::Parser.new
16
+ end
17
+
18
+ def test_features
19
+ assert !@parser.block_expressions_enabled?
20
+ @parser.enable_block_expressions
21
+ assert @parser.block_expressions_enabled?
22
+ @parser.block_expressions_enabled = false
23
+ assert !@parser.block_expressions_enabled?
24
+ end
25
+
26
+ def test_comments
27
+ check <<EOS
28
+ /* blah "blah" 'blah' */
29
+ void f() {
30
+ 1;
31
+ /* " */
32
+ 2;
33
+ /* /* * / */
34
+ 3;
35
+ /*/*/
36
+ 4;
37
+ /* multiline comment
38
+ */
39
+ 5;
40
+ }
41
+ ----
42
+ TranslationUnit
43
+ entities:
44
+ - FunctionDef
45
+ type: Function
46
+ type: Void
47
+ name: "f"
48
+ def: Block
49
+ stmts:
50
+ - ExpressionStatement
51
+ expr: IntLiteral
52
+ val: 1
53
+ - ExpressionStatement
54
+ expr: IntLiteral
55
+ val: 2
56
+ - ExpressionStatement
57
+ expr: IntLiteral
58
+ val: 3
59
+ - ExpressionStatement
60
+ expr: IntLiteral
61
+ val: 4
62
+ - ExpressionStatement
63
+ expr: IntLiteral
64
+ val: 5
65
+ EOS
66
+ #"
67
+ end
68
+
69
+ def test_translation_unit
70
+ check <<EOS
71
+ int i;
72
+ ----
73
+ TranslationUnit
74
+ entities:
75
+ - Declaration
76
+ type: Int
77
+ declarators:
78
+ - Declarator
79
+ name: "i"
80
+ EOS
81
+ check <<EOS
82
+ int i;
83
+ int i;
84
+ ----
85
+ TranslationUnit
86
+ entities:
87
+ - Declaration
88
+ type: Int
89
+ declarators:
90
+ - Declarator
91
+ name: "i"
92
+ - Declaration
93
+ type: Int
94
+ declarators:
95
+ - Declarator
96
+ name: "i"
97
+ EOS
98
+ assert_raise(C::ParseError){C::Parser.new.parse("")}
99
+ assert_raise(C::ParseError){C::Parser.new.parse(";")}
100
+ end
101
+
102
+ def test_external_declaration
103
+ check <<EOS
104
+ int i;
105
+ void f() {}
106
+ ----
107
+ TranslationUnit
108
+ entities:
109
+ - Declaration
110
+ type: Int
111
+ declarators:
112
+ - Declarator
113
+ name: "i"
114
+ - FunctionDef
115
+ type: Function
116
+ type: Void
117
+ name: "f"
118
+ EOS
119
+ end
120
+
121
+ def test_function_def
122
+ check <<EOS
123
+ int main(int, char **) {}
124
+ int main(argc, argv) char **argv; int argc; {}
125
+ ----
126
+ TranslationUnit
127
+ entities:
128
+ - FunctionDef
129
+ type: Function
130
+ type: Int
131
+ params:
132
+ - Parameter
133
+ type: Int
134
+ - Parameter
135
+ type: Pointer
136
+ type: Pointer
137
+ type: Char
138
+ name: "main"
139
+ - FunctionDef (no_prototype)
140
+ type: Function
141
+ type: Int
142
+ params:
143
+ - Parameter
144
+ type: Int
145
+ name: "argc"
146
+ - Parameter
147
+ type: Pointer
148
+ type: Pointer
149
+ type: Char
150
+ name: "argv"
151
+ name: "main"
152
+ EOS
153
+ # non-function type
154
+ assert_raise(C::ParseError){C::Parser.new.parse("int f {}")}
155
+
156
+ # both prototype and declist
157
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
158
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
159
+
160
+ # bad param name
161
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
162
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
163
+
164
+ # type missing
165
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
166
+
167
+ # bad storage
168
+ assert_raise(C::ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
169
+ assert_raise(C::ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
170
+ assert_raise(C::ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
171
+
172
+ # duplicate storages
173
+ assert_raise(C::ParseError){C::Parser.new.parse("static auto int i;")}
174
+ assert_raise(C::ParseError){C::Parser.new.parse("static extern int i;")}
175
+ assert_raise(C::ParseError){C::Parser.new.parse("typedef register int i;")}
176
+
177
+ # `inline' can be repeated
178
+ assert_nothing_raised{C::Parser.new.parse("inline inline int i() {}")}
179
+ end
180
+
181
+ def test_declaration_list
182
+ check <<EOS
183
+ int main(argc, argv) int argc, argv; {}
184
+ int main(argc, argv) int argc, argv; int; {}
185
+ int main(argc, argv) int argc; int argv; int; {}
186
+ int main(argc, argv) int argc, *argv; int; {}
187
+ ----
188
+ TranslationUnit
189
+ entities:
190
+ - FunctionDef (no_prototype)
191
+ type: Function
192
+ type: Int
193
+ params:
194
+ - Parameter
195
+ type: Int
196
+ name: "argc"
197
+ - Parameter
198
+ type: Int
199
+ name: "argv"
200
+ name: "main"
201
+ - FunctionDef (no_prototype)
202
+ type: Function
203
+ type: Int
204
+ params:
205
+ - Parameter
206
+ type: Int
207
+ name: "argc"
208
+ - Parameter
209
+ type: Int
210
+ name: "argv"
211
+ name: "main"
212
+ - FunctionDef (no_prototype)
213
+ type: Function
214
+ type: Int
215
+ params:
216
+ - Parameter
217
+ type: Int
218
+ name: "argc"
219
+ - Parameter
220
+ type: Int
221
+ name: "argv"
222
+ name: "main"
223
+ - FunctionDef (no_prototype)
224
+ type: Function
225
+ type: Int
226
+ params:
227
+ - Parameter
228
+ type: Int
229
+ name: "argc"
230
+ - Parameter
231
+ type: Pointer
232
+ type: Int
233
+ name: "argv"
234
+ name: "main"
235
+ EOS
236
+ end
237
+
238
+ def test_statement
239
+ check <<EOS
240
+ void f() {
241
+ a: ;
242
+ {}
243
+ ;
244
+ if (0);
245
+ while (0);
246
+ return;
247
+ }
248
+ ----
249
+ TranslationUnit
250
+ entities:
251
+ - FunctionDef
252
+ type: Function
253
+ type: Void
254
+ name: "f"
255
+ def: Block
256
+ stmts:
257
+ - ExpressionStatement
258
+ labels:
259
+ - PlainLabel
260
+ name: "a"
261
+ - Block
262
+ - ExpressionStatement
263
+ - If
264
+ cond: IntLiteral
265
+ val: 0
266
+ then: ExpressionStatement
267
+ - While
268
+ cond: IntLiteral
269
+ val: 0
270
+ stmt: ExpressionStatement
271
+ - Return
272
+ EOS
273
+ end
274
+
275
+ def test_labeled_statement
276
+ check <<EOS
277
+ typedef int I;
278
+ void f() {
279
+ a: I: case 1: default: ;
280
+ if (0)
281
+ b: I: case 2: default: ;
282
+ switch (0)
283
+ c: I: case 3: default: {
284
+ d: I: case 4: default: ;
285
+ }
286
+ }
287
+ ----
288
+ TranslationUnit
289
+ entities:
290
+ - Declaration
291
+ storage: typedef
292
+ type: Int
293
+ declarators:
294
+ - Declarator
295
+ name: "I"
296
+ - FunctionDef
297
+ type: Function
298
+ type: Void
299
+ name: "f"
300
+ def: Block
301
+ stmts:
302
+ - ExpressionStatement
303
+ labels:
304
+ - PlainLabel
305
+ name: "a"
306
+ - PlainLabel
307
+ name: "I"
308
+ - Case
309
+ expr: IntLiteral
310
+ val: 1
311
+ - Default
312
+ - If
313
+ cond: IntLiteral
314
+ val: 0
315
+ then: ExpressionStatement
316
+ labels:
317
+ - PlainLabel
318
+ name: "b"
319
+ - PlainLabel
320
+ name: "I"
321
+ - Case
322
+ expr: IntLiteral
323
+ val: 2
324
+ - Default
325
+ - Switch
326
+ cond: IntLiteral
327
+ val: 0
328
+ stmt: Block
329
+ labels:
330
+ - PlainLabel
331
+ name: "c"
332
+ - PlainLabel
333
+ name: "I"
334
+ - Case
335
+ expr: IntLiteral
336
+ val: 3
337
+ - Default
338
+ stmts:
339
+ - ExpressionStatement
340
+ labels:
341
+ - PlainLabel
342
+ name: "d"
343
+ - PlainLabel
344
+ name: "I"
345
+ - Case
346
+ expr: IntLiteral
347
+ val: 4
348
+ - Default
349
+ EOS
350
+ end
351
+
352
+ def test_compound_statement
353
+ check <<EOS
354
+ void f() {
355
+ { }
356
+ {;}
357
+ }
358
+ ----
359
+ TranslationUnit
360
+ entities:
361
+ - FunctionDef
362
+ type: Function
363
+ type: Void
364
+ name: "f"
365
+ def: Block
366
+ stmts:
367
+ - Block
368
+ - Block
369
+ stmts:
370
+ - ExpressionStatement
371
+ EOS
372
+ end
373
+
374
+ def test_block_item_list
375
+ check <<EOS
376
+ void f() {; }
377
+ void f() {;;}
378
+ ----
379
+ TranslationUnit
380
+ entities:
381
+ - FunctionDef
382
+ type: Function
383
+ type: Void
384
+ name: "f"
385
+ def: Block
386
+ stmts:
387
+ - ExpressionStatement
388
+ - FunctionDef
389
+ type: Function
390
+ type: Void
391
+ name: "f"
392
+ def: Block
393
+ stmts:
394
+ - ExpressionStatement
395
+ - ExpressionStatement
396
+ EOS
397
+ end
398
+
399
+ def test_block_item
400
+ check <<EOS
401
+ void f() { ;}
402
+ void f() {int;}
403
+ ----
404
+ TranslationUnit
405
+ entities:
406
+ - FunctionDef
407
+ type: Function
408
+ type: Void
409
+ name: "f"
410
+ def: Block
411
+ stmts:
412
+ - ExpressionStatement
413
+ - FunctionDef
414
+ type: Function
415
+ type: Void
416
+ name: "f"
417
+ def: Block
418
+ stmts:
419
+ - Declaration
420
+ type: Int
421
+ EOS
422
+ end
423
+
424
+ def test_expression_statement
425
+ check <<EOS
426
+ void f() {
427
+ ;
428
+ 1;
429
+ }
430
+ ----
431
+ TranslationUnit
432
+ entities:
433
+ - FunctionDef
434
+ type: Function
435
+ type: Void
436
+ name: "f"
437
+ def: Block
438
+ stmts:
439
+ - ExpressionStatement
440
+ - ExpressionStatement
441
+ expr: IntLiteral
442
+ val: 1
443
+ EOS
444
+ end
445
+
446
+ def test_selection_statement
447
+ check <<EOS
448
+ void f() {
449
+ if (1) ;
450
+ if (1) ; else ;
451
+ if (1) ; else if (2) ; else ;
452
+ if (1) if (2) ; else ;
453
+ if (1) if (2) ; else ; else ;
454
+ }
455
+ ----
456
+ TranslationUnit
457
+ entities:
458
+ - FunctionDef
459
+ type: Function
460
+ type: Void
461
+ name: "f"
462
+ def: Block
463
+ stmts:
464
+ - If
465
+ cond: IntLiteral
466
+ val: 1
467
+ then: ExpressionStatement
468
+ - If
469
+ cond: IntLiteral
470
+ val: 1
471
+ then: ExpressionStatement
472
+ else: ExpressionStatement
473
+ - If
474
+ cond: IntLiteral
475
+ val: 1
476
+ then: ExpressionStatement
477
+ else: If
478
+ cond: IntLiteral
479
+ val: 2
480
+ then: ExpressionStatement
481
+ else: ExpressionStatement
482
+ - If
483
+ cond: IntLiteral
484
+ val: 1
485
+ then: If
486
+ cond: IntLiteral
487
+ val: 2
488
+ then: ExpressionStatement
489
+ else: ExpressionStatement
490
+ - If
491
+ cond: IntLiteral
492
+ val: 1
493
+ then: If
494
+ cond: IntLiteral
495
+ val: 2
496
+ then: ExpressionStatement
497
+ else: ExpressionStatement
498
+ else: ExpressionStatement
499
+ EOS
500
+ check <<EOS
501
+ void f() {
502
+ switch (1)
503
+ case 1:
504
+ x:
505
+ default:
506
+ ;
507
+ switch (1)
508
+ case 1:
509
+ y:
510
+ default:
511
+ if (0) ; else ;
512
+ switch (1) {
513
+ case 1:
514
+ case 2: ;
515
+ z:
516
+ default: ;
517
+ }
518
+ }
519
+ ----
520
+ TranslationUnit
521
+ entities:
522
+ - FunctionDef
523
+ type: Function
524
+ type: Void
525
+ name: "f"
526
+ def: Block
527
+ stmts:
528
+ - Switch
529
+ cond: IntLiteral
530
+ val: 1
531
+ stmt: ExpressionStatement
532
+ labels:
533
+ - Case
534
+ expr: IntLiteral
535
+ val: 1
536
+ - PlainLabel
537
+ name: "x"
538
+ - Default
539
+ - Switch
540
+ cond: IntLiteral
541
+ val: 1
542
+ stmt: If
543
+ labels:
544
+ - Case
545
+ expr: IntLiteral
546
+ val: 1
547
+ - PlainLabel
548
+ name: "y"
549
+ - Default
550
+ cond: IntLiteral
551
+ val: 0
552
+ then: ExpressionStatement
553
+ else: ExpressionStatement
554
+ - Switch
555
+ cond: IntLiteral
556
+ val: 1
557
+ stmt: Block
558
+ stmts:
559
+ - ExpressionStatement
560
+ labels:
561
+ - Case
562
+ expr: IntLiteral
563
+ val: 1
564
+ - Case
565
+ expr: IntLiteral
566
+ val: 2
567
+ - ExpressionStatement
568
+ labels:
569
+ - PlainLabel
570
+ name: "z"
571
+ - Default
572
+ EOS
573
+ end
574
+
575
+ def test_iteration_statement
576
+ check <<EOS
577
+ void f() {
578
+ while (0) ;
579
+ do ; while (0) ;
580
+ }
581
+ ----
582
+ TranslationUnit
583
+ entities:
584
+ - FunctionDef
585
+ type: Function
586
+ type: Void
587
+ name: "f"
588
+ def: Block
589
+ stmts:
590
+ - While
591
+ cond: IntLiteral
592
+ val: 0
593
+ stmt: ExpressionStatement
594
+ - While (do)
595
+ cond: IntLiteral
596
+ val: 0
597
+ stmt: ExpressionStatement
598
+ EOS
599
+ check <<EOS
600
+ void f() {
601
+ for (i = 0; i < 10; ++i) ;
602
+ for (i = 0; i < 10; ) ;
603
+ for (i = 0; ; ++i) ;
604
+ for (i = 0; ; ) ;
605
+ for ( ; i < 10; ++i) ;
606
+ for ( ; i < 10; ) ;
607
+ for ( ; ; ++i) ;
608
+ for ( ; ; ) ;
609
+ for (int i = 0, j = 1; i < 10, j < 10; ++i, ++j) ;
610
+ for (int i = 0, j = 1; i < 10, j < 10; ) ;
611
+ for (int i = 0, j = 1; ; ++i, ++j) ;
612
+ for (int i = 0, j = 1; ; ) ;
613
+ }
614
+ ----
615
+ TranslationUnit
616
+ entities:
617
+ - FunctionDef
618
+ type: Function
619
+ type: Void
620
+ name: "f"
621
+ def: Block
622
+ stmts:
623
+ - For
624
+ init: Assign
625
+ lval: Variable
626
+ name: "i"
627
+ rval: IntLiteral
628
+ val: 0
629
+ cond: Less
630
+ expr1: Variable
631
+ name: "i"
632
+ expr2: IntLiteral
633
+ val: 10
634
+ iter: PreInc
635
+ expr: Variable
636
+ name: "i"
637
+ stmt: ExpressionStatement
638
+ - For
639
+ init: Assign
640
+ lval: Variable
641
+ name: "i"
642
+ rval: IntLiteral
643
+ val: 0
644
+ cond: Less
645
+ expr1: Variable
646
+ name: "i"
647
+ expr2: IntLiteral
648
+ val: 10
649
+ stmt: ExpressionStatement
650
+ - For
651
+ init: Assign
652
+ lval: Variable
653
+ name: "i"
654
+ rval: IntLiteral
655
+ val: 0
656
+ iter: PreInc
657
+ expr: Variable
658
+ name: "i"
659
+ stmt: ExpressionStatement
660
+ - For
661
+ init: Assign
662
+ lval: Variable
663
+ name: "i"
664
+ rval: IntLiteral
665
+ val: 0
666
+ stmt: ExpressionStatement
667
+ - For
668
+ cond: Less
669
+ expr1: Variable
670
+ name: "i"
671
+ expr2: IntLiteral
672
+ val: 10
673
+ iter: PreInc
674
+ expr: Variable
675
+ name: "i"
676
+ stmt: ExpressionStatement
677
+ - For
678
+ cond: Less
679
+ expr1: Variable
680
+ name: "i"
681
+ expr2: IntLiteral
682
+ val: 10
683
+ stmt: ExpressionStatement
684
+ - For
685
+ iter: PreInc
686
+ expr: Variable
687
+ name: "i"
688
+ stmt: ExpressionStatement
689
+ - For
690
+ stmt: ExpressionStatement
691
+ - For
692
+ init: Declaration
693
+ type: Int
694
+ declarators:
695
+ - Declarator
696
+ name: "i"
697
+ init: IntLiteral
698
+ val: 0
699
+ - Declarator
700
+ name: "j"
701
+ init: IntLiteral
702
+ val: 1
703
+ cond: Comma
704
+ exprs:
705
+ - Less
706
+ expr1: Variable
707
+ name: "i"
708
+ expr2: IntLiteral
709
+ val: 10
710
+ - Less
711
+ expr1: Variable
712
+ name: "j"
713
+ expr2: IntLiteral
714
+ val: 10
715
+ iter: Comma
716
+ exprs:
717
+ - PreInc
718
+ expr: Variable
719
+ name: "i"
720
+ - PreInc
721
+ expr: Variable
722
+ name: "j"
723
+ stmt: ExpressionStatement
724
+ - For
725
+ init: Declaration
726
+ type: Int
727
+ declarators:
728
+ - Declarator
729
+ name: "i"
730
+ init: IntLiteral
731
+ val: 0
732
+ - Declarator
733
+ name: "j"
734
+ init: IntLiteral
735
+ val: 1
736
+ cond: Comma
737
+ exprs:
738
+ - Less
739
+ expr1: Variable
740
+ name: "i"
741
+ expr2: IntLiteral
742
+ val: 10
743
+ - Less
744
+ expr1: Variable
745
+ name: "j"
746
+ expr2: IntLiteral
747
+ val: 10
748
+ stmt: ExpressionStatement
749
+ - For
750
+ init: Declaration
751
+ type: Int
752
+ declarators:
753
+ - Declarator
754
+ name: "i"
755
+ init: IntLiteral
756
+ val: 0
757
+ - Declarator
758
+ name: "j"
759
+ init: IntLiteral
760
+ val: 1
761
+ iter: Comma
762
+ exprs:
763
+ - PreInc
764
+ expr: Variable
765
+ name: "i"
766
+ - PreInc
767
+ expr: Variable
768
+ name: "j"
769
+ stmt: ExpressionStatement
770
+ - For
771
+ init: Declaration
772
+ type: Int
773
+ declarators:
774
+ - Declarator
775
+ name: "i"
776
+ init: IntLiteral
777
+ val: 0
778
+ - Declarator
779
+ name: "j"
780
+ init: IntLiteral
781
+ val: 1
782
+ stmt: ExpressionStatement
783
+ EOS
784
+ end
785
+
786
+ def test_jump_statement
787
+ check <<EOS
788
+ typedef int I;
789
+ void f() {
790
+ goto x;
791
+ continue;
792
+ break;
793
+ return 0;
794
+ return;
795
+ goto I;
796
+ }
797
+ ----
798
+ TranslationUnit
799
+ entities:
800
+ - Declaration
801
+ storage: typedef
802
+ type: Int
803
+ declarators:
804
+ - Declarator
805
+ name: "I"
806
+ - FunctionDef
807
+ type: Function
808
+ type: Void
809
+ name: "f"
810
+ def: Block
811
+ stmts:
812
+ - Goto
813
+ target: "x"
814
+ - Continue
815
+ - Break
816
+ - Return
817
+ expr: IntLiteral
818
+ val: 0
819
+ - Return
820
+ - Goto
821
+ target: "I"
822
+ EOS
823
+ end
824
+
825
+ def test_declaration
826
+ check <<EOS
827
+ int;
828
+ int i;
829
+ int i, j;
830
+ ----
831
+ TranslationUnit
832
+ entities:
833
+ - Declaration
834
+ type: Int
835
+ - Declaration
836
+ type: Int
837
+ declarators:
838
+ - Declarator
839
+ name: "i"
840
+ - Declaration
841
+ type: Int
842
+ declarators:
843
+ - Declarator
844
+ name: "i"
845
+ - Declarator
846
+ name: "j"
847
+ EOS
848
+ # duplicate storages
849
+ assert_raise(C::ParseError){C::Parser.new.parse("static auto int ;")}
850
+ assert_raise(C::ParseError){C::Parser.new.parse("static extern int i ;")}
851
+ assert_raise(C::ParseError){C::Parser.new.parse("typedef register int i, j;")}
852
+
853
+ # `inline' can be repeated
854
+ assert_nothing_raised{C::Parser.new.parse("inline inline int f();")}
855
+ end
856
+
857
+ def test_declaration_specifiers
858
+ check <<EOS
859
+ typedef int X;
860
+ int typedef Y;
861
+ const int const i;
862
+ inline int inline i();
863
+ ----
864
+ TranslationUnit
865
+ entities:
866
+ - Declaration
867
+ storage: typedef
868
+ type: Int
869
+ declarators:
870
+ - Declarator
871
+ name: "X"
872
+ - Declaration
873
+ storage: typedef
874
+ type: Int
875
+ declarators:
876
+ - Declarator
877
+ name: "Y"
878
+ - Declaration
879
+ type: Int (const)
880
+ declarators:
881
+ - Declarator
882
+ name: "i"
883
+ - Declaration (inline)
884
+ type: Int
885
+ declarators:
886
+ - Declarator
887
+ indirect_type: Function
888
+ name: "i"
889
+ EOS
890
+ end
891
+
892
+ def test_init_declarator_list
893
+ check <<EOS
894
+ int i;
895
+ int i, j;
896
+ ----
897
+ TranslationUnit
898
+ entities:
899
+ - Declaration
900
+ type: Int
901
+ declarators:
902
+ - Declarator
903
+ name: "i"
904
+ - Declaration
905
+ type: Int
906
+ declarators:
907
+ - Declarator
908
+ name: "i"
909
+ - Declarator
910
+ name: "j"
911
+ EOS
912
+ end
913
+
914
+ def test_init_declarator
915
+ check <<EOS
916
+ int i;
917
+ int i = 0;
918
+ ----
919
+ TranslationUnit
920
+ entities:
921
+ - Declaration
922
+ type: Int
923
+ declarators:
924
+ - Declarator
925
+ name: "i"
926
+ - Declaration
927
+ type: Int
928
+ declarators:
929
+ - Declarator
930
+ name: "i"
931
+ init: IntLiteral
932
+ val: 0
933
+ EOS
934
+ end
935
+
936
+ def test_storage_class_specifier
937
+ check <<EOS
938
+ typedef int I;
939
+ extern int i;
940
+ static int f() {
941
+ auto int i;
942
+ register int j;
943
+ }
944
+ ----
945
+ TranslationUnit
946
+ entities:
947
+ - Declaration
948
+ storage: typedef
949
+ type: Int
950
+ declarators:
951
+ - Declarator
952
+ name: "I"
953
+ - Declaration
954
+ storage: extern
955
+ type: Int
956
+ declarators:
957
+ - Declarator
958
+ name: "i"
959
+ - FunctionDef
960
+ storage: static
961
+ type: Function
962
+ type: Int
963
+ name: "f"
964
+ def: Block
965
+ stmts:
966
+ - Declaration
967
+ storage: auto
968
+ type: Int
969
+ declarators:
970
+ - Declarator
971
+ name: "i"
972
+ - Declaration
973
+ storage: register
974
+ type: Int
975
+ declarators:
976
+ - Declarator
977
+ name: "j"
978
+ EOS
979
+ end
980
+
981
+ def test_type_specifier
982
+ check <<EOS
983
+ void;
984
+
985
+ char;
986
+
987
+ char signed;
988
+
989
+ char unsigned;
990
+
991
+ short;
992
+ int short;
993
+ int short;
994
+ int short signed;
995
+
996
+ short unsigned;
997
+ int short unsigned;
998
+
999
+ int;
1000
+ signed;
1001
+ int signed;
1002
+
1003
+ unsigned;
1004
+ int unsigned;
1005
+
1006
+ long;
1007
+ long signed;
1008
+ int long;
1009
+ int long signed;
1010
+
1011
+ long unsigned;
1012
+ int long unsigned;
1013
+
1014
+ long long;
1015
+ long long signed;
1016
+ int long long;
1017
+ int long long signed;
1018
+
1019
+ long long unsigned;
1020
+ int long long unsigned;
1021
+
1022
+ float;
1023
+
1024
+ double;
1025
+
1026
+ double long;
1027
+
1028
+ _Bool;
1029
+
1030
+ _Complex float;
1031
+
1032
+ _Complex double;
1033
+
1034
+ _Complex long double;
1035
+
1036
+ _Imaginary float;
1037
+
1038
+ _Imaginary double;
1039
+
1040
+ _Imaginary double long;
1041
+
1042
+ struct s;
1043
+ enum e;
1044
+ typedef int I;
1045
+ I;
1046
+ ----
1047
+ TranslationUnit
1048
+ entities:
1049
+ - Declaration
1050
+ type: Void
1051
+ - Declaration
1052
+ type: Char
1053
+ - Declaration
1054
+ type: Char
1055
+ signed: true
1056
+ - Declaration
1057
+ type: Char
1058
+ signed: false
1059
+ - Declaration
1060
+ type: Int
1061
+ longness: -1
1062
+ - Declaration
1063
+ type: Int
1064
+ longness: -1
1065
+ - Declaration
1066
+ type: Int
1067
+ longness: -1
1068
+ - Declaration
1069
+ type: Int
1070
+ longness: -1
1071
+ - Declaration
1072
+ type: Int (unsigned)
1073
+ longness: -1
1074
+ - Declaration
1075
+ type: Int (unsigned)
1076
+ longness: -1
1077
+ - Declaration
1078
+ type: Int
1079
+ - Declaration
1080
+ type: Int
1081
+ - Declaration
1082
+ type: Int
1083
+ - Declaration
1084
+ type: Int (unsigned)
1085
+ - Declaration
1086
+ type: Int (unsigned)
1087
+ - Declaration
1088
+ type: Int
1089
+ longness: 1
1090
+ - Declaration
1091
+ type: Int
1092
+ longness: 1
1093
+ - Declaration
1094
+ type: Int
1095
+ longness: 1
1096
+ - Declaration
1097
+ type: Int
1098
+ longness: 1
1099
+ - Declaration
1100
+ type: Int (unsigned)
1101
+ longness: 1
1102
+ - Declaration
1103
+ type: Int (unsigned)
1104
+ longness: 1
1105
+ - Declaration
1106
+ type: Int
1107
+ longness: 2
1108
+ - Declaration
1109
+ type: Int
1110
+ longness: 2
1111
+ - Declaration
1112
+ type: Int
1113
+ longness: 2
1114
+ - Declaration
1115
+ type: Int
1116
+ longness: 2
1117
+ - Declaration
1118
+ type: Int (unsigned)
1119
+ longness: 2
1120
+ - Declaration
1121
+ type: Int (unsigned)
1122
+ longness: 2
1123
+ - Declaration
1124
+ type: Float
1125
+ - Declaration
1126
+ type: Float
1127
+ longness: 1
1128
+ - Declaration
1129
+ type: Float
1130
+ longness: 2
1131
+ - Declaration
1132
+ type: Bool
1133
+ - Declaration
1134
+ type: Complex
1135
+ - Declaration
1136
+ type: Complex
1137
+ longness: 1
1138
+ - Declaration
1139
+ type: Complex
1140
+ longness: 2
1141
+ - Declaration
1142
+ type: Imaginary
1143
+ - Declaration
1144
+ type: Imaginary
1145
+ longness: 1
1146
+ - Declaration
1147
+ type: Imaginary
1148
+ longness: 2
1149
+ - Declaration
1150
+ type: Struct
1151
+ name: "s"
1152
+ - Declaration
1153
+ type: Enum
1154
+ name: "e"
1155
+ - Declaration
1156
+ storage: typedef
1157
+ type: Int
1158
+ declarators:
1159
+ - Declarator
1160
+ name: "I"
1161
+ - Declaration
1162
+ type: CustomType
1163
+ name: "I"
1164
+ EOS
1165
+ # some illegal combos
1166
+ assert_raise(C::ParseError){C::Parser.new.parse("int float;")}
1167
+ assert_raise(C::ParseError){C::Parser.new.parse("struct s {} int;")}
1168
+ assert_raise(C::ParseError){C::Parser.new.parse("_Complex;")}
1169
+ assert_raise(C::ParseError){C::Parser.new.parse("_Complex _Imaginary float;")}
1170
+ assert_raise(C::ParseError){C::Parser.new.parse("short long;")}
1171
+ assert_raise(C::ParseError){C::Parser.new.parse("signed unsigned char;")}
1172
+ assert_raise(C::ParseError){C::Parser.new.parse("int int;")}
1173
+ assert_raise(C::ParseError){C::Parser.new.parse("long char;")}
1174
+ assert_raise(C::ParseError){C::Parser.new.parse("long long long;")}
1175
+ end
1176
+
1177
+ def test_struct_or_union_specifier
1178
+ check <<EOS
1179
+ struct s { int i; } ;
1180
+ struct { int i; } ;
1181
+ struct s ;
1182
+ typedef int I ;
1183
+ struct I { int i; } ;
1184
+ struct I ;
1185
+ ----
1186
+ TranslationUnit
1187
+ entities:
1188
+ - Declaration
1189
+ type: Struct
1190
+ name: "s"
1191
+ members:
1192
+ - Declaration
1193
+ type: Int
1194
+ declarators:
1195
+ - Declarator
1196
+ name: "i"
1197
+ - Declaration
1198
+ type: Struct
1199
+ members:
1200
+ - Declaration
1201
+ type: Int
1202
+ declarators:
1203
+ - Declarator
1204
+ name: "i"
1205
+ - Declaration
1206
+ type: Struct
1207
+ name: "s"
1208
+ - Declaration
1209
+ storage: typedef
1210
+ type: Int
1211
+ declarators:
1212
+ - Declarator
1213
+ name: "I"
1214
+ - Declaration
1215
+ type: Struct
1216
+ name: "I"
1217
+ members:
1218
+ - Declaration
1219
+ type: Int
1220
+ declarators:
1221
+ - Declarator
1222
+ name: "i"
1223
+ - Declaration
1224
+ type: Struct
1225
+ name: "I"
1226
+ EOS
1227
+ end
1228
+
1229
+ def test_struct_or_union
1230
+ check <<EOS
1231
+ struct s;
1232
+ union u;
1233
+ ----
1234
+ TranslationUnit
1235
+ entities:
1236
+ - Declaration
1237
+ type: Struct
1238
+ name: "s"
1239
+ - Declaration
1240
+ type: Union
1241
+ name: "u"
1242
+ EOS
1243
+ end
1244
+
1245
+ def test_struct_declaration_list
1246
+ check <<EOS
1247
+ struct { int i; } ;
1248
+ struct { int i; int j; } ;
1249
+ ----
1250
+ TranslationUnit
1251
+ entities:
1252
+ - Declaration
1253
+ type: Struct
1254
+ members:
1255
+ - Declaration
1256
+ type: Int
1257
+ declarators:
1258
+ - Declarator
1259
+ name: "i"
1260
+ - Declaration
1261
+ type: Struct
1262
+ members:
1263
+ - Declaration
1264
+ type: Int
1265
+ declarators:
1266
+ - Declarator
1267
+ name: "i"
1268
+ - Declaration
1269
+ type: Int
1270
+ declarators:
1271
+ - Declarator
1272
+ name: "j"
1273
+ EOS
1274
+ end
1275
+
1276
+ def test_struct_declaration
1277
+ check <<EOS
1278
+ struct { int i; };
1279
+ ----
1280
+ TranslationUnit
1281
+ entities:
1282
+ - Declaration
1283
+ type: Struct
1284
+ members:
1285
+ - Declaration
1286
+ type: Int
1287
+ declarators:
1288
+ - Declarator
1289
+ name: "i"
1290
+ EOS
1291
+ end
1292
+
1293
+ def test_specifier_qualifier_list
1294
+ check <<EOS
1295
+ void f() {
1296
+ sizeof(int const);
1297
+ sizeof(const int);
1298
+ }
1299
+ ----
1300
+ TranslationUnit
1301
+ entities:
1302
+ - FunctionDef
1303
+ type: Function
1304
+ type: Void
1305
+ name: "f"
1306
+ def: Block
1307
+ stmts:
1308
+ - ExpressionStatement
1309
+ expr: Sizeof
1310
+ expr: Int (const)
1311
+ - ExpressionStatement
1312
+ expr: Sizeof
1313
+ expr: Int (const)
1314
+ EOS
1315
+ # quals can be repeated
1316
+ assert_nothing_raised{C::Parser.new.parse("void f() {sizeof(const const int);}")}
1317
+ end
1318
+
1319
+ def test_struct_declarator_list
1320
+ check <<EOS
1321
+ struct { int i; };
1322
+ struct { int i, j; };
1323
+ ----
1324
+ TranslationUnit
1325
+ entities:
1326
+ - Declaration
1327
+ type: Struct
1328
+ members:
1329
+ - Declaration
1330
+ type: Int
1331
+ declarators:
1332
+ - Declarator
1333
+ name: "i"
1334
+ - Declaration
1335
+ type: Struct
1336
+ members:
1337
+ - Declaration
1338
+ type: Int
1339
+ declarators:
1340
+ - Declarator
1341
+ name: "i"
1342
+ - Declarator
1343
+ name: "j"
1344
+ EOS
1345
+ end
1346
+
1347
+ def test_struct_declarator
1348
+ check <<EOS
1349
+ struct { int i; };
1350
+ struct { int i : 1; };
1351
+ struct { int : 2; };
1352
+ ----
1353
+ TranslationUnit
1354
+ entities:
1355
+ - Declaration
1356
+ type: Struct
1357
+ members:
1358
+ - Declaration
1359
+ type: Int
1360
+ declarators:
1361
+ - Declarator
1362
+ name: "i"
1363
+ - Declaration
1364
+ type: Struct
1365
+ members:
1366
+ - Declaration
1367
+ type: Int
1368
+ declarators:
1369
+ - Declarator
1370
+ name: "i"
1371
+ num_bits: IntLiteral
1372
+ val: 1
1373
+ - Declaration
1374
+ type: Struct
1375
+ members:
1376
+ - Declaration
1377
+ type: Int
1378
+ declarators:
1379
+ - Declarator
1380
+ num_bits: IntLiteral
1381
+ val: 2
1382
+ EOS
1383
+ end
1384
+
1385
+ def test_enum_specifier
1386
+ check <<EOS
1387
+ enum e { i };
1388
+ enum { i };
1389
+ enum e { i, };
1390
+ enum { i, };
1391
+ enum e ;
1392
+ typedef int E;
1393
+ enum E { i };
1394
+ enum E { i, };
1395
+ enum E ;
1396
+ ----
1397
+ TranslationUnit
1398
+ entities:
1399
+ - Declaration
1400
+ type: Enum
1401
+ name: "e"
1402
+ members:
1403
+ - Enumerator
1404
+ name: "i"
1405
+ - Declaration
1406
+ type: Enum
1407
+ members:
1408
+ - Enumerator
1409
+ name: "i"
1410
+ - Declaration
1411
+ type: Enum
1412
+ name: "e"
1413
+ members:
1414
+ - Enumerator
1415
+ name: "i"
1416
+ - Declaration
1417
+ type: Enum
1418
+ members:
1419
+ - Enumerator
1420
+ name: "i"
1421
+ - Declaration
1422
+ type: Enum
1423
+ name: "e"
1424
+ - Declaration
1425
+ storage: typedef
1426
+ type: Int
1427
+ declarators:
1428
+ - Declarator
1429
+ name: "E"
1430
+ - Declaration
1431
+ type: Enum
1432
+ name: "E"
1433
+ members:
1434
+ - Enumerator
1435
+ name: "i"
1436
+ - Declaration
1437
+ type: Enum
1438
+ name: "E"
1439
+ members:
1440
+ - Enumerator
1441
+ name: "i"
1442
+ - Declaration
1443
+ type: Enum
1444
+ name: "E"
1445
+ EOS
1446
+ end
1447
+
1448
+ def test_enumerator_list
1449
+ check <<EOS
1450
+ enum e { i };
1451
+ enum e { i, j };
1452
+ ----
1453
+ TranslationUnit
1454
+ entities:
1455
+ - Declaration
1456
+ type: Enum
1457
+ name: "e"
1458
+ members:
1459
+ - Enumerator
1460
+ name: "i"
1461
+ - Declaration
1462
+ type: Enum
1463
+ name: "e"
1464
+ members:
1465
+ - Enumerator
1466
+ name: "i"
1467
+ - Enumerator
1468
+ name: "j"
1469
+ EOS
1470
+ end
1471
+
1472
+ def test_enumerator
1473
+ check <<EOS
1474
+ enum e { i };
1475
+ enum e { i=0 };
1476
+ ----
1477
+ TranslationUnit
1478
+ entities:
1479
+ - Declaration
1480
+ type: Enum
1481
+ name: "e"
1482
+ members:
1483
+ - Enumerator
1484
+ name: "i"
1485
+ - Declaration
1486
+ type: Enum
1487
+ name: "e"
1488
+ members:
1489
+ - Enumerator
1490
+ name: "i"
1491
+ val: IntLiteral
1492
+ val: 0
1493
+ EOS
1494
+ end
1495
+
1496
+ def test_type_qualifier
1497
+ check <<EOS
1498
+ const int;
1499
+ restrict int;
1500
+ volatile int;
1501
+ ----
1502
+ TranslationUnit
1503
+ entities:
1504
+ - Declaration
1505
+ type: Int (const)
1506
+ - Declaration
1507
+ type: Int (restrict)
1508
+ - Declaration
1509
+ type: Int (volatile)
1510
+ EOS
1511
+ end
1512
+
1513
+ def test_function_specifier
1514
+ check <<EOS
1515
+ inline int f();
1516
+ ----
1517
+ TranslationUnit
1518
+ entities:
1519
+ - Declaration (inline)
1520
+ type: Int
1521
+ declarators:
1522
+ - Declarator
1523
+ indirect_type: Function
1524
+ name: "f"
1525
+ EOS
1526
+ end
1527
+
1528
+ def test_declarator
1529
+ check <<EOS
1530
+ int *p;
1531
+ int *const restrict volatile p;
1532
+ int i, *volatile restrict const *p[];
1533
+ int *i, *const (*restrict (*volatile p)[])();
1534
+ ----
1535
+ TranslationUnit
1536
+ entities:
1537
+ - Declaration
1538
+ type: Int
1539
+ declarators:
1540
+ - Declarator
1541
+ indirect_type: Pointer
1542
+ name: "p"
1543
+ - Declaration
1544
+ type: Int
1545
+ declarators:
1546
+ - Declarator
1547
+ indirect_type: Pointer (const restrict volatile)
1548
+ name: "p"
1549
+ - Declaration
1550
+ type: Int
1551
+ declarators:
1552
+ - Declarator
1553
+ name: "i"
1554
+ - Declarator
1555
+ indirect_type: Array
1556
+ type: Pointer
1557
+ type: Pointer (const restrict volatile)
1558
+ name: "p"
1559
+ - Declaration
1560
+ type: Int
1561
+ declarators:
1562
+ - Declarator
1563
+ indirect_type: Pointer
1564
+ name: "i"
1565
+ - Declarator
1566
+ indirect_type: Pointer (volatile)
1567
+ type: Array
1568
+ type: Pointer (restrict)
1569
+ type: Function
1570
+ type: Pointer (const)
1571
+ name: "p"
1572
+ EOS
1573
+ end
1574
+
1575
+ def test_direct_declarator
1576
+ # TODO
1577
+ end
1578
+
1579
+ def test_pointer
1580
+ check <<EOS
1581
+ int *const p;
1582
+ int * p;
1583
+ int *const *p;
1584
+ int * *p;
1585
+ ----
1586
+ TranslationUnit
1587
+ entities:
1588
+ - Declaration
1589
+ type: Int
1590
+ declarators:
1591
+ - Declarator
1592
+ indirect_type: Pointer (const)
1593
+ name: "p"
1594
+ - Declaration
1595
+ type: Int
1596
+ declarators:
1597
+ - Declarator
1598
+ indirect_type: Pointer
1599
+ name: "p"
1600
+ - Declaration
1601
+ type: Int
1602
+ declarators:
1603
+ - Declarator
1604
+ indirect_type: Pointer
1605
+ type: Pointer (const)
1606
+ name: "p"
1607
+ - Declaration
1608
+ type: Int
1609
+ declarators:
1610
+ - Declarator
1611
+ indirect_type: Pointer
1612
+ type: Pointer
1613
+ name: "p"
1614
+ EOS
1615
+ end
1616
+
1617
+ def test_type_qualifier_list
1618
+ check <<EOS
1619
+ int *const p;
1620
+ int *const restrict p;
1621
+ ----
1622
+ TranslationUnit
1623
+ entities:
1624
+ - Declaration
1625
+ type: Int
1626
+ declarators:
1627
+ - Declarator
1628
+ indirect_type: Pointer (const)
1629
+ name: "p"
1630
+ - Declaration
1631
+ type: Int
1632
+ declarators:
1633
+ - Declarator
1634
+ indirect_type: Pointer (const restrict)
1635
+ name: "p"
1636
+ EOS
1637
+ end
1638
+
1639
+ def test_parameter_type_list
1640
+ check <<EOS
1641
+ void f(int i) {}
1642
+ void f(int i, ...) {}
1643
+ ----
1644
+ TranslationUnit
1645
+ entities:
1646
+ - FunctionDef
1647
+ type: Function
1648
+ type: Void
1649
+ params:
1650
+ - Parameter
1651
+ type: Int
1652
+ name: "i"
1653
+ name: "f"
1654
+ - FunctionDef
1655
+ type: Function (var_args)
1656
+ type: Void
1657
+ params:
1658
+ - Parameter
1659
+ type: Int
1660
+ name: "i"
1661
+ name: "f"
1662
+ EOS
1663
+ end
1664
+
1665
+ def test_parameter_list
1666
+ check <<EOS
1667
+ void f(int i) {}
1668
+ void f(int i, int j) {}
1669
+ ----
1670
+ TranslationUnit
1671
+ entities:
1672
+ - FunctionDef
1673
+ type: Function
1674
+ type: Void
1675
+ params:
1676
+ - Parameter
1677
+ type: Int
1678
+ name: "i"
1679
+ name: "f"
1680
+ - FunctionDef
1681
+ type: Function
1682
+ type: Void
1683
+ params:
1684
+ - Parameter
1685
+ type: Int
1686
+ name: "i"
1687
+ - Parameter
1688
+ type: Int
1689
+ name: "j"
1690
+ name: "f"
1691
+ EOS
1692
+ end
1693
+
1694
+ def test_parameter_declaration
1695
+ check <<EOS
1696
+ void f(int i);
1697
+ void f(int *);
1698
+ void f(int );
1699
+ ----
1700
+ TranslationUnit
1701
+ entities:
1702
+ - Declaration
1703
+ type: Void
1704
+ declarators:
1705
+ - Declarator
1706
+ indirect_type: Function
1707
+ params:
1708
+ - Parameter
1709
+ type: Int
1710
+ name: "i"
1711
+ name: "f"
1712
+ - Declaration
1713
+ type: Void
1714
+ declarators:
1715
+ - Declarator
1716
+ indirect_type: Function
1717
+ params:
1718
+ - Parameter
1719
+ type: Pointer
1720
+ type: Int
1721
+ name: "f"
1722
+ - Declaration
1723
+ type: Void
1724
+ declarators:
1725
+ - Declarator
1726
+ indirect_type: Function
1727
+ params:
1728
+ - Parameter
1729
+ type: Int
1730
+ name: "f"
1731
+ EOS
1732
+ end
1733
+
1734
+ def test_identifier_list
1735
+ check <<EOS
1736
+ void f(i);
1737
+ void f(i, j);
1738
+ ----
1739
+ TranslationUnit
1740
+ entities:
1741
+ - Declaration
1742
+ type: Void
1743
+ declarators:
1744
+ - Declarator
1745
+ indirect_type: Function
1746
+ params:
1747
+ - Parameter
1748
+ name: "i"
1749
+ name: "f"
1750
+ - Declaration
1751
+ type: Void
1752
+ declarators:
1753
+ - Declarator
1754
+ indirect_type: Function
1755
+ params:
1756
+ - Parameter
1757
+ name: "i"
1758
+ - Parameter
1759
+ name: "j"
1760
+ name: "f"
1761
+ EOS
1762
+ end
1763
+
1764
+ def test_type_name
1765
+ check <<EOS
1766
+ void f() {
1767
+ sizeof(int *);
1768
+ sizeof(int );
1769
+ }
1770
+ ----
1771
+ TranslationUnit
1772
+ entities:
1773
+ - FunctionDef
1774
+ type: Function
1775
+ type: Void
1776
+ name: "f"
1777
+ def: Block
1778
+ stmts:
1779
+ - ExpressionStatement
1780
+ expr: Sizeof
1781
+ expr: Pointer
1782
+ type: Int
1783
+ - ExpressionStatement
1784
+ expr: Sizeof
1785
+ expr: Int
1786
+ EOS
1787
+ end
1788
+
1789
+ def test_abstract_declarator
1790
+ check <<EOS
1791
+ void f(int * );
1792
+ void f(int *[]);
1793
+ void f(int []);
1794
+ ----
1795
+ TranslationUnit
1796
+ entities:
1797
+ - Declaration
1798
+ type: Void
1799
+ declarators:
1800
+ - Declarator
1801
+ indirect_type: Function
1802
+ params:
1803
+ - Parameter
1804
+ type: Pointer
1805
+ type: Int
1806
+ name: "f"
1807
+ - Declaration
1808
+ type: Void
1809
+ declarators:
1810
+ - Declarator
1811
+ indirect_type: Function
1812
+ params:
1813
+ - Parameter
1814
+ type: Array
1815
+ type: Pointer
1816
+ type: Int
1817
+ name: "f"
1818
+ - Declaration
1819
+ type: Void
1820
+ declarators:
1821
+ - Declarator
1822
+ indirect_type: Function
1823
+ params:
1824
+ - Parameter
1825
+ type: Array
1826
+ type: Int
1827
+ name: "f"
1828
+ EOS
1829
+ end
1830
+
1831
+ def test_direct_abstract_declarator
1832
+ # TODO
1833
+ end
1834
+
1835
+ def test_typedef_name
1836
+ check <<EOS
1837
+ typedef int I;
1838
+ I;
1839
+ ----
1840
+ TranslationUnit
1841
+ entities:
1842
+ - Declaration
1843
+ storage: typedef
1844
+ type: Int
1845
+ declarators:
1846
+ - Declarator
1847
+ name: "I"
1848
+ - Declaration
1849
+ type: CustomType
1850
+ name: "I"
1851
+ EOS
1852
+ end
1853
+
1854
+ def test_initializer
1855
+ check <<EOS
1856
+ int x = 1 ;
1857
+ int x = {1 };
1858
+ int x = {1,};
1859
+ ----
1860
+ TranslationUnit
1861
+ entities:
1862
+ - Declaration
1863
+ type: Int
1864
+ declarators:
1865
+ - Declarator
1866
+ name: "x"
1867
+ init: IntLiteral
1868
+ val: 1
1869
+ - Declaration
1870
+ type: Int
1871
+ declarators:
1872
+ - Declarator
1873
+ name: "x"
1874
+ init: CompoundLiteral
1875
+ member_inits:
1876
+ - MemberInit
1877
+ init: IntLiteral
1878
+ val: 1
1879
+ - Declaration
1880
+ type: Int
1881
+ declarators:
1882
+ - Declarator
1883
+ name: "x"
1884
+ init: CompoundLiteral
1885
+ member_inits:
1886
+ - MemberInit
1887
+ init: IntLiteral
1888
+ val: 1
1889
+ EOS
1890
+ end
1891
+
1892
+ def test_initializer_list
1893
+ check <<EOS
1894
+ int x = {.x = 1};
1895
+ int x = { 1};
1896
+ int x = {1, .x = 1};
1897
+ int x = {1, 1};
1898
+ ----
1899
+ TranslationUnit
1900
+ entities:
1901
+ - Declaration
1902
+ type: Int
1903
+ declarators:
1904
+ - Declarator
1905
+ name: "x"
1906
+ init: CompoundLiteral
1907
+ member_inits:
1908
+ - MemberInit
1909
+ member:
1910
+ - Member
1911
+ name: "x"
1912
+ init: IntLiteral
1913
+ val: 1
1914
+ - Declaration
1915
+ type: Int
1916
+ declarators:
1917
+ - Declarator
1918
+ name: "x"
1919
+ init: CompoundLiteral
1920
+ member_inits:
1921
+ - MemberInit
1922
+ init: IntLiteral
1923
+ val: 1
1924
+ - Declaration
1925
+ type: Int
1926
+ declarators:
1927
+ - Declarator
1928
+ name: "x"
1929
+ init: CompoundLiteral
1930
+ member_inits:
1931
+ - MemberInit
1932
+ init: IntLiteral
1933
+ val: 1
1934
+ - MemberInit
1935
+ member:
1936
+ - Member
1937
+ name: "x"
1938
+ init: IntLiteral
1939
+ val: 1
1940
+ - Declaration
1941
+ type: Int
1942
+ declarators:
1943
+ - Declarator
1944
+ name: "x"
1945
+ init: CompoundLiteral
1946
+ member_inits:
1947
+ - MemberInit
1948
+ init: IntLiteral
1949
+ val: 1
1950
+ - MemberInit
1951
+ init: IntLiteral
1952
+ val: 1
1953
+ EOS
1954
+ end
1955
+
1956
+ def test_designation
1957
+ check <<EOS
1958
+ int x = {.x = 1};
1959
+ ----
1960
+ TranslationUnit
1961
+ entities:
1962
+ - Declaration
1963
+ type: Int
1964
+ declarators:
1965
+ - Declarator
1966
+ name: "x"
1967
+ init: CompoundLiteral
1968
+ member_inits:
1969
+ - MemberInit
1970
+ member:
1971
+ - Member
1972
+ name: "x"
1973
+ init: IntLiteral
1974
+ val: 1
1975
+ EOS
1976
+ end
1977
+
1978
+ def test_designator_list
1979
+ check <<EOS
1980
+ int x = {.x = 1};
1981
+ int x = {.x .y = 1};
1982
+ ----
1983
+ TranslationUnit
1984
+ entities:
1985
+ - Declaration
1986
+ type: Int
1987
+ declarators:
1988
+ - Declarator
1989
+ name: "x"
1990
+ init: CompoundLiteral
1991
+ member_inits:
1992
+ - MemberInit
1993
+ member:
1994
+ - Member
1995
+ name: "x"
1996
+ init: IntLiteral
1997
+ val: 1
1998
+ - Declaration
1999
+ type: Int
2000
+ declarators:
2001
+ - Declarator
2002
+ name: "x"
2003
+ init: CompoundLiteral
2004
+ member_inits:
2005
+ - MemberInit
2006
+ member:
2007
+ - Member
2008
+ name: "x"
2009
+ - Member
2010
+ name: "y"
2011
+ init: IntLiteral
2012
+ val: 1
2013
+ EOS
2014
+ end
2015
+
2016
+ def test_designator
2017
+ check <<EOS
2018
+ int x = {.x = 1};
2019
+ int x = {[0] = 1};
2020
+ ----
2021
+ TranslationUnit
2022
+ entities:
2023
+ - Declaration
2024
+ type: Int
2025
+ declarators:
2026
+ - Declarator
2027
+ name: "x"
2028
+ init: CompoundLiteral
2029
+ member_inits:
2030
+ - MemberInit
2031
+ member:
2032
+ - Member
2033
+ name: "x"
2034
+ init: IntLiteral
2035
+ val: 1
2036
+ - Declaration
2037
+ type: Int
2038
+ declarators:
2039
+ - Declarator
2040
+ name: "x"
2041
+ init: CompoundLiteral
2042
+ member_inits:
2043
+ - MemberInit
2044
+ member:
2045
+ - IntLiteral
2046
+ val: 0
2047
+ init: IntLiteral
2048
+ val: 1
2049
+ EOS
2050
+ end
2051
+
2052
+ def test_primary_expression
2053
+ check <<EOS
2054
+ void f() {
2055
+ x;
2056
+ 1;
2057
+ "";
2058
+ (1);
2059
+ }
2060
+ ----
2061
+ TranslationUnit
2062
+ entities:
2063
+ - FunctionDef
2064
+ type: Function
2065
+ type: Void
2066
+ name: "f"
2067
+ def: Block
2068
+ stmts:
2069
+ - ExpressionStatement
2070
+ expr: Variable
2071
+ name: "x"
2072
+ - ExpressionStatement
2073
+ expr: IntLiteral
2074
+ val: 1
2075
+ - ExpressionStatement
2076
+ expr: StringLiteral
2077
+ val: ""
2078
+ - ExpressionStatement
2079
+ expr: IntLiteral
2080
+ val: 1
2081
+ EOS
2082
+ end
2083
+
2084
+ def test_primary_expression_block_expression
2085
+ src = <<EOS
2086
+ void f() {
2087
+ ({;});
2088
+ }
2089
+ EOS
2090
+ assert_raise(C::ParseError){@parser.parse(src)}
2091
+
2092
+ @parser.enable_block_expressions
2093
+ check <<EOS
2094
+ #{src}
2095
+ ----
2096
+ TranslationUnit
2097
+ entities:
2098
+ - FunctionDef
2099
+ type: Function
2100
+ type: Void
2101
+ name: "f"
2102
+ def: Block
2103
+ stmts:
2104
+ - ExpressionStatement
2105
+ expr: BlockExpression
2106
+ block: Block
2107
+ stmts:
2108
+ - ExpressionStatement
2109
+ EOS
2110
+ end
2111
+
2112
+ def test_postfix_expression
2113
+ check <<EOS
2114
+ void f() {
2115
+ x;
2116
+ x[1];
2117
+ x(1);
2118
+ x();
2119
+ x.a;
2120
+ x->a;
2121
+ x++;
2122
+ x--;
2123
+ (int){1};
2124
+ (int){1,};
2125
+ }
2126
+ ----
2127
+ TranslationUnit
2128
+ entities:
2129
+ - FunctionDef
2130
+ type: Function
2131
+ type: Void
2132
+ name: "f"
2133
+ def: Block
2134
+ stmts:
2135
+ - ExpressionStatement
2136
+ expr: Variable
2137
+ name: "x"
2138
+ - ExpressionStatement
2139
+ expr: Index
2140
+ expr: Variable
2141
+ name: "x"
2142
+ index: IntLiteral
2143
+ val: 1
2144
+ - ExpressionStatement
2145
+ expr: Call
2146
+ expr: Variable
2147
+ name: "x"
2148
+ args:
2149
+ - IntLiteral
2150
+ val: 1
2151
+ - ExpressionStatement
2152
+ expr: Call
2153
+ expr: Variable
2154
+ name: "x"
2155
+ - ExpressionStatement
2156
+ expr: Dot
2157
+ expr: Variable
2158
+ name: "x"
2159
+ member: Member
2160
+ name: "a"
2161
+ - ExpressionStatement
2162
+ expr: Arrow
2163
+ expr: Variable
2164
+ name: "x"
2165
+ member: Member
2166
+ name: "a"
2167
+ - ExpressionStatement
2168
+ expr: PostInc
2169
+ expr: Variable
2170
+ name: "x"
2171
+ - ExpressionStatement
2172
+ expr: PostDec
2173
+ expr: Variable
2174
+ name: "x"
2175
+ - ExpressionStatement
2176
+ expr: CompoundLiteral
2177
+ type: Int
2178
+ member_inits:
2179
+ - MemberInit
2180
+ init: IntLiteral
2181
+ val: 1
2182
+ - ExpressionStatement
2183
+ expr: CompoundLiteral
2184
+ type: Int
2185
+ member_inits:
2186
+ - MemberInit
2187
+ init: IntLiteral
2188
+ val: 1
2189
+ EOS
2190
+ end
2191
+
2192
+ def test_argument_expression_list
2193
+ check <<EOS
2194
+ void f() {
2195
+ x(1);
2196
+ x(int);
2197
+ x(1, int);
2198
+ }
2199
+ ----
2200
+ TranslationUnit
2201
+ entities:
2202
+ - FunctionDef
2203
+ type: Function
2204
+ type: Void
2205
+ name: "f"
2206
+ def: Block
2207
+ stmts:
2208
+ - ExpressionStatement
2209
+ expr: Call
2210
+ expr: Variable
2211
+ name: "x"
2212
+ args:
2213
+ - IntLiteral
2214
+ val: 1
2215
+ - ExpressionStatement
2216
+ expr: Call
2217
+ expr: Variable
2218
+ name: "x"
2219
+ args:
2220
+ - Int
2221
+ - ExpressionStatement
2222
+ expr: Call
2223
+ expr: Variable
2224
+ name: "x"
2225
+ args:
2226
+ - IntLiteral
2227
+ val: 1
2228
+ - Int
2229
+ EOS
2230
+ end
2231
+
2232
+ def test_argument_expression
2233
+ check <<EOS
2234
+ void f() {
2235
+ x(a = 1);
2236
+ x(int*);
2237
+ x(const struct s[]);
2238
+ }
2239
+ ----
2240
+ TranslationUnit
2241
+ entities:
2242
+ - FunctionDef
2243
+ type: Function
2244
+ type: Void
2245
+ name: "f"
2246
+ def: Block
2247
+ stmts:
2248
+ - ExpressionStatement
2249
+ expr: Call
2250
+ expr: Variable
2251
+ name: "x"
2252
+ args:
2253
+ - Assign
2254
+ lval: Variable
2255
+ name: "a"
2256
+ rval: IntLiteral
2257
+ val: 1
2258
+ - ExpressionStatement
2259
+ expr: Call
2260
+ expr: Variable
2261
+ name: "x"
2262
+ args:
2263
+ - Pointer
2264
+ type: Int
2265
+ - ExpressionStatement
2266
+ expr: Call
2267
+ expr: Variable
2268
+ name: "x"
2269
+ args:
2270
+ - Array
2271
+ type: Struct (const)
2272
+ name: "s"
2273
+ EOS
2274
+ end
2275
+
2276
+ def test_unary_expression
2277
+ check <<EOS
2278
+ void f() {
2279
+ x;
2280
+ ++x;
2281
+ --x;
2282
+ &x;
2283
+ sizeof x;
2284
+ sizeof(int);
2285
+ }
2286
+ ----
2287
+ TranslationUnit
2288
+ entities:
2289
+ - FunctionDef
2290
+ type: Function
2291
+ type: Void
2292
+ name: "f"
2293
+ def: Block
2294
+ stmts:
2295
+ - ExpressionStatement
2296
+ expr: Variable
2297
+ name: "x"
2298
+ - ExpressionStatement
2299
+ expr: PreInc
2300
+ expr: Variable
2301
+ name: "x"
2302
+ - ExpressionStatement
2303
+ expr: PreDec
2304
+ expr: Variable
2305
+ name: "x"
2306
+ - ExpressionStatement
2307
+ expr: Address
2308
+ expr: Variable
2309
+ name: "x"
2310
+ - ExpressionStatement
2311
+ expr: Sizeof
2312
+ expr: Variable
2313
+ name: "x"
2314
+ - ExpressionStatement
2315
+ expr: Sizeof
2316
+ expr: Int
2317
+ EOS
2318
+ end
2319
+
2320
+ def test_unary_operator
2321
+ check <<EOS
2322
+ void f() {
2323
+ &x;
2324
+ *x;
2325
+ +x;
2326
+ -x;
2327
+ ~x;
2328
+ !x;
2329
+ }
2330
+ ----
2331
+ TranslationUnit
2332
+ entities:
2333
+ - FunctionDef
2334
+ type: Function
2335
+ type: Void
2336
+ name: "f"
2337
+ def: Block
2338
+ stmts:
2339
+ - ExpressionStatement
2340
+ expr: Address
2341
+ expr: Variable
2342
+ name: "x"
2343
+ - ExpressionStatement
2344
+ expr: Dereference
2345
+ expr: Variable
2346
+ name: "x"
2347
+ - ExpressionStatement
2348
+ expr: Positive
2349
+ expr: Variable
2350
+ name: "x"
2351
+ - ExpressionStatement
2352
+ expr: Negative
2353
+ expr: Variable
2354
+ name: "x"
2355
+ - ExpressionStatement
2356
+ expr: BitNot
2357
+ expr: Variable
2358
+ name: "x"
2359
+ - ExpressionStatement
2360
+ expr: Not
2361
+ expr: Variable
2362
+ name: "x"
2363
+ EOS
2364
+ end
2365
+
2366
+ def test_cast_expression
2367
+ check <<EOS
2368
+ void f() {
2369
+ x;
2370
+ (int)x;
2371
+ }
2372
+ ----
2373
+ TranslationUnit
2374
+ entities:
2375
+ - FunctionDef
2376
+ type: Function
2377
+ type: Void
2378
+ name: "f"
2379
+ def: Block
2380
+ stmts:
2381
+ - ExpressionStatement
2382
+ expr: Variable
2383
+ name: "x"
2384
+ - ExpressionStatement
2385
+ expr: Cast
2386
+ type: Int
2387
+ expr: Variable
2388
+ name: "x"
2389
+ EOS
2390
+ end
2391
+
2392
+ def test_multiplicative_expression
2393
+ check <<EOS
2394
+ void f() {
2395
+ x;
2396
+ x * x;
2397
+ x / x;
2398
+ x % x;
2399
+ }
2400
+ ----
2401
+ TranslationUnit
2402
+ entities:
2403
+ - FunctionDef
2404
+ type: Function
2405
+ type: Void
2406
+ name: "f"
2407
+ def: Block
2408
+ stmts:
2409
+ - ExpressionStatement
2410
+ expr: Variable
2411
+ name: "x"
2412
+ - ExpressionStatement
2413
+ expr: Multiply
2414
+ expr1: Variable
2415
+ name: "x"
2416
+ expr2: Variable
2417
+ name: "x"
2418
+ - ExpressionStatement
2419
+ expr: Divide
2420
+ expr1: Variable
2421
+ name: "x"
2422
+ expr2: Variable
2423
+ name: "x"
2424
+ - ExpressionStatement
2425
+ expr: Mod
2426
+ expr1: Variable
2427
+ name: "x"
2428
+ expr2: Variable
2429
+ name: "x"
2430
+ EOS
2431
+ end
2432
+
2433
+ def test_additive_expression
2434
+ check <<EOS
2435
+ void f() {
2436
+ x;
2437
+ x + x;
2438
+ x - x;
2439
+ }
2440
+ ----
2441
+ TranslationUnit
2442
+ entities:
2443
+ - FunctionDef
2444
+ type: Function
2445
+ type: Void
2446
+ name: "f"
2447
+ def: Block
2448
+ stmts:
2449
+ - ExpressionStatement
2450
+ expr: Variable
2451
+ name: "x"
2452
+ - ExpressionStatement
2453
+ expr: Add
2454
+ expr1: Variable
2455
+ name: "x"
2456
+ expr2: Variable
2457
+ name: "x"
2458
+ - ExpressionStatement
2459
+ expr: Subtract
2460
+ expr1: Variable
2461
+ name: "x"
2462
+ expr2: Variable
2463
+ name: "x"
2464
+ EOS
2465
+ end
2466
+
2467
+ def test_shift_expression
2468
+ check <<EOS
2469
+ void f() {
2470
+ x;
2471
+ x << x;
2472
+ x >> x;
2473
+ }
2474
+ ----
2475
+ TranslationUnit
2476
+ entities:
2477
+ - FunctionDef
2478
+ type: Function
2479
+ type: Void
2480
+ name: "f"
2481
+ def: Block
2482
+ stmts:
2483
+ - ExpressionStatement
2484
+ expr: Variable
2485
+ name: "x"
2486
+ - ExpressionStatement
2487
+ expr: ShiftLeft
2488
+ expr1: Variable
2489
+ name: "x"
2490
+ expr2: Variable
2491
+ name: "x"
2492
+ - ExpressionStatement
2493
+ expr: ShiftRight
2494
+ expr1: Variable
2495
+ name: "x"
2496
+ expr2: Variable
2497
+ name: "x"
2498
+ EOS
2499
+ end
2500
+
2501
+ def test_relational_expression
2502
+ check <<EOS
2503
+ void f() {
2504
+ x;
2505
+ x < x;
2506
+ x > x;
2507
+ x <= x;
2508
+ x >= x;
2509
+ }
2510
+ ----
2511
+ TranslationUnit
2512
+ entities:
2513
+ - FunctionDef
2514
+ type: Function
2515
+ type: Void
2516
+ name: "f"
2517
+ def: Block
2518
+ stmts:
2519
+ - ExpressionStatement
2520
+ expr: Variable
2521
+ name: "x"
2522
+ - ExpressionStatement
2523
+ expr: Less
2524
+ expr1: Variable
2525
+ name: "x"
2526
+ expr2: Variable
2527
+ name: "x"
2528
+ - ExpressionStatement
2529
+ expr: More
2530
+ expr1: Variable
2531
+ name: "x"
2532
+ expr2: Variable
2533
+ name: "x"
2534
+ - ExpressionStatement
2535
+ expr: LessOrEqual
2536
+ expr1: Variable
2537
+ name: "x"
2538
+ expr2: Variable
2539
+ name: "x"
2540
+ - ExpressionStatement
2541
+ expr: MoreOrEqual
2542
+ expr1: Variable
2543
+ name: "x"
2544
+ expr2: Variable
2545
+ name: "x"
2546
+ EOS
2547
+ end
2548
+
2549
+ def test_equality_expression
2550
+ check <<EOS
2551
+ void f() {
2552
+ x;
2553
+ x == x;
2554
+ x != x;
2555
+ }
2556
+ ----
2557
+ TranslationUnit
2558
+ entities:
2559
+ - FunctionDef
2560
+ type: Function
2561
+ type: Void
2562
+ name: "f"
2563
+ def: Block
2564
+ stmts:
2565
+ - ExpressionStatement
2566
+ expr: Variable
2567
+ name: "x"
2568
+ - ExpressionStatement
2569
+ expr: Equal
2570
+ expr1: Variable
2571
+ name: "x"
2572
+ expr2: Variable
2573
+ name: "x"
2574
+ - ExpressionStatement
2575
+ expr: NotEqual
2576
+ expr1: Variable
2577
+ name: "x"
2578
+ expr2: Variable
2579
+ name: "x"
2580
+ EOS
2581
+ end
2582
+
2583
+ def test_and_expression
2584
+ check <<EOS
2585
+ void f() {
2586
+ x;
2587
+ x & x;
2588
+ }
2589
+ ----
2590
+ TranslationUnit
2591
+ entities:
2592
+ - FunctionDef
2593
+ type: Function
2594
+ type: Void
2595
+ name: "f"
2596
+ def: Block
2597
+ stmts:
2598
+ - ExpressionStatement
2599
+ expr: Variable
2600
+ name: "x"
2601
+ - ExpressionStatement
2602
+ expr: BitAnd
2603
+ expr1: Variable
2604
+ name: "x"
2605
+ expr2: Variable
2606
+ name: "x"
2607
+ EOS
2608
+ end
2609
+
2610
+ def test_exclusive_or_expression
2611
+ check <<EOS
2612
+ void f() {
2613
+ x;
2614
+ x ^ x;
2615
+ }
2616
+ ----
2617
+ TranslationUnit
2618
+ entities:
2619
+ - FunctionDef
2620
+ type: Function
2621
+ type: Void
2622
+ name: "f"
2623
+ def: Block
2624
+ stmts:
2625
+ - ExpressionStatement
2626
+ expr: Variable
2627
+ name: "x"
2628
+ - ExpressionStatement
2629
+ expr: BitXor
2630
+ expr1: Variable
2631
+ name: "x"
2632
+ expr2: Variable
2633
+ name: "x"
2634
+ EOS
2635
+ end
2636
+
2637
+ def test_inclusive_or_expression
2638
+ check <<EOS
2639
+ void f() {
2640
+ x;
2641
+ x | x;
2642
+ }
2643
+ ----
2644
+ TranslationUnit
2645
+ entities:
2646
+ - FunctionDef
2647
+ type: Function
2648
+ type: Void
2649
+ name: "f"
2650
+ def: Block
2651
+ stmts:
2652
+ - ExpressionStatement
2653
+ expr: Variable
2654
+ name: "x"
2655
+ - ExpressionStatement
2656
+ expr: BitOr
2657
+ expr1: Variable
2658
+ name: "x"
2659
+ expr2: Variable
2660
+ name: "x"
2661
+ EOS
2662
+ end
2663
+
2664
+ def test_logical_and_expression
2665
+ check <<EOS
2666
+ void f() {
2667
+ x;
2668
+ x && x;
2669
+ }
2670
+ ----
2671
+ TranslationUnit
2672
+ entities:
2673
+ - FunctionDef
2674
+ type: Function
2675
+ type: Void
2676
+ name: "f"
2677
+ def: Block
2678
+ stmts:
2679
+ - ExpressionStatement
2680
+ expr: Variable
2681
+ name: "x"
2682
+ - ExpressionStatement
2683
+ expr: And
2684
+ expr1: Variable
2685
+ name: "x"
2686
+ expr2: Variable
2687
+ name: "x"
2688
+ EOS
2689
+ end
2690
+
2691
+ def test_logical_or_expression
2692
+ check <<EOS
2693
+ void f() {
2694
+ x;
2695
+ x || x;
2696
+ }
2697
+ ----
2698
+ TranslationUnit
2699
+ entities:
2700
+ - FunctionDef
2701
+ type: Function
2702
+ type: Void
2703
+ name: "f"
2704
+ def: Block
2705
+ stmts:
2706
+ - ExpressionStatement
2707
+ expr: Variable
2708
+ name: "x"
2709
+ - ExpressionStatement
2710
+ expr: Or
2711
+ expr1: Variable
2712
+ name: "x"
2713
+ expr2: Variable
2714
+ name: "x"
2715
+ EOS
2716
+ end
2717
+
2718
+ def test_conditional_expression
2719
+ check <<EOS
2720
+ void f() {
2721
+ x;
2722
+ x ? x : x;
2723
+ }
2724
+ ----
2725
+ TranslationUnit
2726
+ entities:
2727
+ - FunctionDef
2728
+ type: Function
2729
+ type: Void
2730
+ name: "f"
2731
+ def: Block
2732
+ stmts:
2733
+ - ExpressionStatement
2734
+ expr: Variable
2735
+ name: "x"
2736
+ - ExpressionStatement
2737
+ expr: Conditional
2738
+ cond: Variable
2739
+ name: "x"
2740
+ then: Variable
2741
+ name: "x"
2742
+ else: Variable
2743
+ name: "x"
2744
+ EOS
2745
+ end
2746
+
2747
+ def test_assignment_expression
2748
+ check <<EOS
2749
+ void f() {
2750
+ x;
2751
+ x = x;
2752
+ }
2753
+ ----
2754
+ TranslationUnit
2755
+ entities:
2756
+ - FunctionDef
2757
+ type: Function
2758
+ type: Void
2759
+ name: "f"
2760
+ def: Block
2761
+ stmts:
2762
+ - ExpressionStatement
2763
+ expr: Variable
2764
+ name: "x"
2765
+ - ExpressionStatement
2766
+ expr: Assign
2767
+ lval: Variable
2768
+ name: "x"
2769
+ rval: Variable
2770
+ name: "x"
2771
+ EOS
2772
+ end
2773
+
2774
+ def test_assignment_operator
2775
+ check <<EOS
2776
+ void f() {
2777
+ x = x;
2778
+ x *= x;
2779
+ x /= x;
2780
+ x %= x;
2781
+ x += x;
2782
+ x -= x;
2783
+ x <<= x;
2784
+ x >>= x;
2785
+ x &= x;
2786
+ x ^= x;
2787
+ x |= x;
2788
+ }
2789
+ ----
2790
+ TranslationUnit
2791
+ entities:
2792
+ - FunctionDef
2793
+ type: Function
2794
+ type: Void
2795
+ name: "f"
2796
+ def: Block
2797
+ stmts:
2798
+ - ExpressionStatement
2799
+ expr: Assign
2800
+ lval: Variable
2801
+ name: "x"
2802
+ rval: Variable
2803
+ name: "x"
2804
+ - ExpressionStatement
2805
+ expr: MultiplyAssign
2806
+ lval: Variable
2807
+ name: "x"
2808
+ rval: Variable
2809
+ name: "x"
2810
+ - ExpressionStatement
2811
+ expr: DivideAssign
2812
+ lval: Variable
2813
+ name: "x"
2814
+ rval: Variable
2815
+ name: "x"
2816
+ - ExpressionStatement
2817
+ expr: ModAssign
2818
+ lval: Variable
2819
+ name: "x"
2820
+ rval: Variable
2821
+ name: "x"
2822
+ - ExpressionStatement
2823
+ expr: AddAssign
2824
+ lval: Variable
2825
+ name: "x"
2826
+ rval: Variable
2827
+ name: "x"
2828
+ - ExpressionStatement
2829
+ expr: SubtractAssign
2830
+ lval: Variable
2831
+ name: "x"
2832
+ rval: Variable
2833
+ name: "x"
2834
+ - ExpressionStatement
2835
+ expr: ShiftLeftAssign
2836
+ lval: Variable
2837
+ name: "x"
2838
+ rval: Variable
2839
+ name: "x"
2840
+ - ExpressionStatement
2841
+ expr: ShiftRightAssign
2842
+ lval: Variable
2843
+ name: "x"
2844
+ rval: Variable
2845
+ name: "x"
2846
+ - ExpressionStatement
2847
+ expr: BitAndAssign
2848
+ lval: Variable
2849
+ name: "x"
2850
+ rval: Variable
2851
+ name: "x"
2852
+ - ExpressionStatement
2853
+ expr: BitXorAssign
2854
+ lval: Variable
2855
+ name: "x"
2856
+ rval: Variable
2857
+ name: "x"
2858
+ - ExpressionStatement
2859
+ expr: BitOrAssign
2860
+ lval: Variable
2861
+ name: "x"
2862
+ rval: Variable
2863
+ name: "x"
2864
+ EOS
2865
+ end
2866
+
2867
+ def test_expression
2868
+ check <<EOS
2869
+ void f() {
2870
+ a;
2871
+ a, b;
2872
+ a, b, c;
2873
+ }
2874
+ ----
2875
+ TranslationUnit
2876
+ entities:
2877
+ - FunctionDef
2878
+ type: Function
2879
+ type: Void
2880
+ name: "f"
2881
+ def: Block
2882
+ stmts:
2883
+ - ExpressionStatement
2884
+ expr: Variable
2885
+ name: "a"
2886
+ - ExpressionStatement
2887
+ expr: Comma
2888
+ exprs:
2889
+ - Variable
2890
+ name: "a"
2891
+ - Variable
2892
+ name: "b"
2893
+ - ExpressionStatement
2894
+ expr: Comma
2895
+ exprs:
2896
+ - Variable
2897
+ name: "a"
2898
+ - Variable
2899
+ name: "b"
2900
+ - Variable
2901
+ name: "c"
2902
+ EOS
2903
+ end
2904
+
2905
+ def test_constant_expression
2906
+ check <<EOS
2907
+ void f() {
2908
+ 1;
2909
+ }
2910
+ ----
2911
+ TranslationUnit
2912
+ entities:
2913
+ - FunctionDef
2914
+ type: Function
2915
+ type: Void
2916
+ name: "f"
2917
+ def: Block
2918
+ stmts:
2919
+ - ExpressionStatement
2920
+ expr: IntLiteral
2921
+ val: 1
2922
+ EOS
2923
+ end
2924
+
2925
+ def test_identifier
2926
+ check <<EOS
2927
+ void f() {
2928
+ _abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890;
2929
+ }
2930
+ ----
2931
+ TranslationUnit
2932
+ entities:
2933
+ - FunctionDef
2934
+ type: Function
2935
+ type: Void
2936
+ name: "f"
2937
+ def: Block
2938
+ stmts:
2939
+ - ExpressionStatement
2940
+ expr: Variable
2941
+ name: "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
2942
+ EOS
2943
+ end
2944
+
2945
+ def test_constant
2946
+ check <<EOS
2947
+ void f() {
2948
+ 1;
2949
+ 1.0;
2950
+ 'a';
2951
+ }
2952
+ ----
2953
+ TranslationUnit
2954
+ entities:
2955
+ - FunctionDef
2956
+ type: Function
2957
+ type: Void
2958
+ name: "f"
2959
+ def: Block
2960
+ stmts:
2961
+ - ExpressionStatement
2962
+ expr: IntLiteral
2963
+ val: 1
2964
+ - ExpressionStatement
2965
+ expr: FloatLiteral
2966
+ val: 1.0
2967
+ - ExpressionStatement
2968
+ expr: CharLiteral
2969
+ val: "a"
2970
+ EOS
2971
+ end
2972
+
2973
+ def test_enumeration_constant
2974
+ check <<EOS
2975
+ void f() {
2976
+ a;
2977
+ }
2978
+ ----
2979
+ TranslationUnit
2980
+ entities:
2981
+ - FunctionDef
2982
+ type: Function
2983
+ type: Void
2984
+ name: "f"
2985
+ def: Block
2986
+ stmts:
2987
+ - ExpressionStatement
2988
+ expr: Variable
2989
+ name: "a"
2990
+ EOS
2991
+ end
2992
+
2993
+ def test_string_literal
2994
+ check <<EOS
2995
+ void f() {
2996
+ "";
2997
+ }
2998
+ ----
2999
+ TranslationUnit
3000
+ entities:
3001
+ - FunctionDef
3002
+ type: Function
3003
+ type: Void
3004
+ name: "f"
3005
+ def: Block
3006
+ stmts:
3007
+ - ExpressionStatement
3008
+ expr: StringLiteral
3009
+ val: ""
3010
+ EOS
3011
+ end
3012
+ end