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