cast 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1301 @@
1
+ ###
2
+ ### ##################################################################
3
+ ###
4
+ ### All those Node classes.
5
+ ###
6
+ ### ##################################################################
7
+ ###
8
+
9
+ module C
10
+ ###
11
+ ### ==================================================================
12
+ ###
13
+ ### Class declarations
14
+ ###
15
+ ### ==================================================================
16
+ ###
17
+ class Statement < Node ; abstract; end
18
+ class Label < Node ; abstract; end
19
+ class Expression < Node ; abstract; end
20
+ class UnaryExpression < Expression ; abstract; end
21
+ class PostfixExpression < UnaryExpression; abstract; end
22
+ class PrefixExpression < UnaryExpression; abstract; end
23
+ class BinaryExpression < Expression ; abstract; end
24
+ class AssignmentExpression < Expression ; abstract; end
25
+ class Literal < Expression ; abstract; end
26
+ class Type < Node ; abstract; end
27
+ class IndirectType < Type ; abstract; end
28
+ class DirectType < Type ; abstract; end
29
+ class PrimitiveType < DirectType ; abstract; end
30
+
31
+ class TranslationUnit < Node ; end
32
+ class Declaration < Node ; end
33
+ class Declarator < Node ; end
34
+ class FunctionDef < Node ; end
35
+ class Parameter < Node ; end
36
+ class Enumerator < Node ; end
37
+ class MemberInit < Node ; end
38
+ class Member < Node ; end
39
+
40
+ class Block < Statement ; end
41
+ class If < Statement ; end
42
+ class Switch < Statement ; end
43
+ class While < Statement ; end
44
+ class For < Statement ; end
45
+ class Goto < Statement ; end
46
+ class Continue < Statement ; end
47
+ class Break < Statement ; end
48
+ class Return < Statement ; end
49
+ class ExpressionStatement < Statement ; end
50
+
51
+ class PlainLabel < Label ; end
52
+ class Default < Label ; end
53
+ class Case < Label ; end
54
+
55
+ class Comma < Expression ; end
56
+ class Conditional < Expression ; end
57
+ class Variable < Expression ; end
58
+
59
+ class Index < PostfixExpression ; end
60
+ class Call < PostfixExpression ; end
61
+ class Dot < PostfixExpression ; end
62
+ class Arrow < PostfixExpression ; end
63
+ class PostInc < PostfixExpression ; end
64
+ class PostDec < PostfixExpression ; end
65
+
66
+ class Cast < PrefixExpression ; end
67
+ class Address < PrefixExpression ; end
68
+ class Dereference < PrefixExpression ; end
69
+ class Sizeof < PrefixExpression ; end
70
+ class Positive < PrefixExpression ; end
71
+ class Negative < PrefixExpression ; end
72
+ class PreInc < PrefixExpression ; end
73
+ class PreDec < PrefixExpression ; end
74
+ class BitNot < PrefixExpression ; end
75
+ class Not < PrefixExpression ; end
76
+
77
+ class Add < BinaryExpression ; end
78
+ class Subtract < BinaryExpression ; end
79
+ class Multiply < BinaryExpression ; end
80
+ class Divide < BinaryExpression ; end
81
+ class Mod < BinaryExpression ; end
82
+ class Equal < BinaryExpression ; end
83
+ class NotEqual < BinaryExpression ; end
84
+ class Less < BinaryExpression ; end
85
+ class More < BinaryExpression ; end
86
+ class LessOrEqual < BinaryExpression ; end
87
+ class MoreOrEqual < BinaryExpression ; end
88
+ class BitAnd < BinaryExpression ; end
89
+ class BitOr < BinaryExpression ; end
90
+ class BitXor < BinaryExpression ; end
91
+ class ShiftLeft < BinaryExpression ; end
92
+ class ShiftRight < BinaryExpression ; end
93
+ class And < BinaryExpression ; end
94
+ class Or < BinaryExpression ; end
95
+
96
+ class Assign < AssignmentExpression; end
97
+ class MultiplyAssign < AssignmentExpression; end
98
+ class DivideAssign < AssignmentExpression; end
99
+ class ModAssign < AssignmentExpression; end
100
+ class AddAssign < AssignmentExpression; end
101
+ class SubtractAssign < AssignmentExpression; end
102
+ class ShiftLeftAssign < AssignmentExpression; end
103
+ class ShiftRightAssign < AssignmentExpression; end
104
+ class BitAndAssign < AssignmentExpression; end
105
+ class BitXorAssign < AssignmentExpression; end
106
+ class BitOrAssign < AssignmentExpression; end
107
+
108
+ class StringLiteral < Literal ; end
109
+ class CharLiteral < Literal ; end
110
+ class CompoundLiteral < Literal ; end
111
+ class IntLiteral < Literal ; end
112
+ class FloatLiteral < Literal ; end
113
+
114
+ class Pointer < IndirectType ; end
115
+ class Array < IndirectType ; end
116
+ class Function < IndirectType ; end
117
+
118
+ class Struct < DirectType ; end
119
+ class Union < DirectType ; end
120
+ class Enum < DirectType ; end
121
+ class CustomType < DirectType ; end
122
+
123
+ class Void < PrimitiveType ; end
124
+ class Int < PrimitiveType ; end
125
+ class Float < PrimitiveType ; end
126
+ class Char < PrimitiveType ; end
127
+ class Bool < PrimitiveType ; end
128
+ class Complex < PrimitiveType ; end
129
+ class Imaginary < PrimitiveType ; end
130
+
131
+ ###
132
+ ### ==================================================================
133
+ ###
134
+ ### Class implementations
135
+ ###
136
+ ### ==================================================================
137
+ ###
138
+
139
+ ###
140
+ ### Node
141
+ ###
142
+ class Node
143
+ initializer
144
+ end
145
+ ###
146
+ ### TranslationUnit
147
+ ###
148
+ class TranslationUnit
149
+ child :entities, lambda{NodeChain.new}
150
+ initializer :entities
151
+ end
152
+ ###
153
+ ### Declaration
154
+ ###
155
+ class Declaration
156
+ field :storage
157
+ child :type
158
+ child :declarators, lambda{NodeArray.new}
159
+ field :inline?
160
+ initializer :type, :declarators
161
+ def typedef?
162
+ storage.equal? :typedef
163
+ end
164
+ def extern?
165
+ storage.equal? :extern
166
+ end
167
+ def static?
168
+ storage.equal? :static
169
+ end
170
+ def auto?
171
+ storage.equal? :auto
172
+ end
173
+ def register?
174
+ storage.equal? :register
175
+ end
176
+ end
177
+ ###
178
+ ### Declarator
179
+ ###
180
+ class Declarator
181
+ child :indirect_type
182
+ field :name
183
+ child :init
184
+ child :num_bits
185
+ initializer :indirect_type, :name, :init, :num_bits
186
+ def declaration
187
+ parent and parent.parent
188
+ end
189
+ ###
190
+ ### Return (a copy of) the type of the variable this Declarator
191
+ ### declares.
192
+ ###
193
+ def type
194
+ if indirect_type
195
+ ret = indirect_type.clone
196
+ ret.direct_type = declaration.type.clone
197
+ return ret
198
+ else
199
+ declaration.type.clone
200
+ end
201
+ end
202
+ end
203
+ ###
204
+ ### FunctionDef
205
+ ###
206
+ class FunctionDef
207
+ field :storage
208
+ field :inline?
209
+ child :type
210
+ field :name
211
+ child :def, lambda{Block.new}
212
+ field :no_prototype?
213
+ initializer :type, :name, :def
214
+ def extern?
215
+ storage.equal? :extern
216
+ end
217
+ def static?
218
+ storage.equal? :static
219
+ end
220
+ def prototype= val
221
+ self.no_prototype = !val
222
+ end
223
+ def prototype?
224
+ !no_prototype?
225
+ end
226
+ end
227
+ ###
228
+ ### Parameter
229
+ ###
230
+ class Parameter
231
+ field :register?
232
+ child :type
233
+ field :name
234
+ initializer :type, :name
235
+ end
236
+ ###
237
+ ### Enumerator
238
+ ###
239
+ class Enumerator
240
+ field :name
241
+ child :val
242
+ initializer :name, :val
243
+ end
244
+ ###
245
+ ### MemberInit
246
+ ###
247
+ class MemberInit
248
+ ## member is a _NodeList_ of:
249
+ ## -- Member (for struct/union members)
250
+ ## -- Expression (for array members)
251
+ child :member
252
+ child :init
253
+ initializer :member, :init
254
+ end
255
+ ###
256
+ ### Member
257
+ ###
258
+ class Member
259
+ field :name
260
+ initializer :name
261
+ end
262
+
263
+ ###
264
+ ### ----------------------------------------------------------------
265
+ ### Statements
266
+ ### ----------------------------------------------------------------
267
+
268
+ ###
269
+ ### Block
270
+ ###
271
+ class Block
272
+ child :labels, lambda{NodeArray.new}
273
+ child :stmts, lambda{NodeChain.new}
274
+ initializer :stmts
275
+ end
276
+ ###
277
+ ### If
278
+ ###
279
+ class If
280
+ child :labels, lambda{NodeArray.new}
281
+ child :cond
282
+ child :then
283
+ child :else
284
+ initializer :cond, :then, :else
285
+ end
286
+ ###
287
+ ### Switch
288
+ ###
289
+ class Switch
290
+ child :labels, lambda{NodeArray.new}
291
+ child :cond
292
+ child :stmt
293
+ initializer :cond, :stmt
294
+ end
295
+ ###
296
+ ### While
297
+ ###
298
+ class While
299
+ child :labels, lambda{NodeArray.new}
300
+ field :do?
301
+ child :cond
302
+ child :stmt
303
+ initializer :cond, :stmt, :do?
304
+ end
305
+ ###
306
+ ### For
307
+ ###
308
+ class For
309
+ child :labels, lambda{NodeArray.new}
310
+ child :init
311
+ child :cond
312
+ child :iter
313
+ child :stmt
314
+ initializer :init, :cond, :iter, :stmt
315
+ end
316
+ ###
317
+ ### Goto
318
+ ###
319
+ class Goto
320
+ child :labels, lambda{NodeArray.new}
321
+ field :target
322
+ initializer :target
323
+ end
324
+ ###
325
+ ### Continue
326
+ ###
327
+ class Continue
328
+ child :labels, lambda{NodeArray.new}
329
+ end
330
+ ###
331
+ ### Break
332
+ ###
333
+ class Break
334
+ child :labels, lambda{NodeArray.new}
335
+ end
336
+ ###
337
+ ### Return
338
+ ###
339
+ class Return
340
+ child :labels, lambda{NodeArray.new}
341
+ child :expr
342
+ initializer :expr
343
+ end
344
+ ###
345
+ ### ExpressionStatement
346
+ ###
347
+ class ExpressionStatement
348
+ child :labels, lambda{NodeArray.new}
349
+ child :expr
350
+ initializer :expr
351
+ end
352
+
353
+ ###
354
+ ### ----------------------------------------------------------------
355
+ ### Labels
356
+ ### ----------------------------------------------------------------
357
+ ###
358
+
359
+ ###
360
+ ### PlainLabel
361
+ ###
362
+ class PlainLabel
363
+ field :name
364
+ initializer :name
365
+ end
366
+
367
+ ###
368
+ ### Default
369
+ ###
370
+ class Default
371
+ end
372
+
373
+ ###
374
+ ### Case
375
+ ###
376
+ class Case
377
+ child :expr
378
+ initializer :expr
379
+ end
380
+
381
+ ###
382
+ ### ----------------------------------------------------------------
383
+ ### Expressions
384
+ ### ----------------------------------------------------------------
385
+ ###
386
+
387
+ ###
388
+ ### Comma
389
+ ###
390
+ class Comma
391
+ child :exprs, lambda{NodeArray.new}
392
+ initializer :exprs
393
+ end
394
+ ###
395
+ ### Conditional
396
+ ###
397
+ class Conditional
398
+ child :cond
399
+ child :then
400
+ child :else
401
+ initializer :cond, :then, :else
402
+ end
403
+ ###
404
+ ### Sizeof
405
+ ###
406
+ class Sizeof
407
+ child :expr
408
+ initializer :expr
409
+ end
410
+ ###
411
+ ### Variable
412
+ ###
413
+ class Variable
414
+ field :name
415
+ initializer :name
416
+ end
417
+
418
+ ###
419
+ ### ----------------------------------------------------------------
420
+ ### PrefixExpressions
421
+ ### ----------------------------------------------------------------
422
+ ###
423
+
424
+ ###
425
+ ### Cast
426
+ ###
427
+ class Cast
428
+ child :type
429
+ child :expr
430
+ initializer :type, :expr
431
+ end
432
+ ###
433
+ ### Address
434
+ ###
435
+ class Address
436
+ child :expr
437
+ initializer :expr
438
+ end
439
+ ###
440
+ ### Dereference
441
+ ###
442
+ class Dereference
443
+ child :expr
444
+ initializer :expr
445
+ end
446
+ ###
447
+ ### Positive
448
+ ###
449
+ class Positive
450
+ child :expr
451
+ initializer :expr
452
+ end
453
+ ###
454
+ ### Negative
455
+ ###
456
+ class Negative
457
+ child :expr
458
+ initializer :expr
459
+ end
460
+ ###
461
+ ### PreInc
462
+ ###
463
+ class PreInc
464
+ child :expr
465
+ initializer :expr
466
+ end
467
+ ###
468
+ ### PreDec
469
+ ###
470
+ class PreDec
471
+ child :expr
472
+ initializer :expr
473
+ end
474
+ ###
475
+ ### BitNot
476
+ ###
477
+ class BitNot
478
+ child :expr
479
+ initializer :expr
480
+ end
481
+ ###
482
+ ### Not
483
+ ###
484
+ class Not
485
+ child :expr
486
+ initializer :expr
487
+ end
488
+
489
+ ###
490
+ ### ----------------------------------------------------------------
491
+ ### PostfixExpressions
492
+ ### ----------------------------------------------------------------
493
+ ###
494
+
495
+ ###
496
+ ### Index
497
+ ###
498
+ class Index
499
+ child :expr
500
+ child :index
501
+ initializer :expr, :index
502
+ end
503
+ ###
504
+ ### Call
505
+ ###
506
+ class Call
507
+ child :expr
508
+ child :args, lambda{NodeArray.new}
509
+ initializer :expr, :args
510
+ end
511
+ ###
512
+ ### Dot
513
+ ###
514
+ class Dot
515
+ child :expr
516
+ child :member
517
+ initializer :expr, :member
518
+ end
519
+ ###
520
+ ### Arrow
521
+ ###
522
+ class Arrow
523
+ child :expr
524
+ child :member
525
+ initializer :expr, :member
526
+ end
527
+ ###
528
+ ### PostInc
529
+ ###
530
+ class PostInc
531
+ child :expr
532
+ initializer :expr
533
+ end
534
+ ###
535
+ ### PostDec
536
+ ###
537
+ class PostDec
538
+ child :expr
539
+ initializer :expr
540
+ end
541
+
542
+ ###
543
+ ### ----------------------------------------------------------------
544
+ ### BinaryExpressions
545
+ ### ----------------------------------------------------------------
546
+ ###
547
+
548
+ ###
549
+ ### BinaryExpression (abstract)
550
+ ###
551
+ class BinaryExpression
552
+ class << self
553
+ ###
554
+ ### The operator (a String) pertaining to the class (e.g.,
555
+ ### Add.operator is '+').
556
+ ###
557
+ attr_accessor :operator
558
+ end
559
+ end
560
+ ###
561
+ ### Add
562
+ ###
563
+ class Add
564
+ child :expr1
565
+ child :expr2
566
+ initializer :expr1, :expr2
567
+ self.operator = '+'
568
+ end
569
+ ###
570
+ ### Subtract
571
+ ###
572
+ class Subtract
573
+ child :expr1
574
+ child :expr2
575
+ initializer :expr1, :expr2
576
+ self.operator = '-'
577
+ end
578
+ ###
579
+ ### Multiply
580
+ ###
581
+ class Multiply
582
+ child :expr1
583
+ child :expr2
584
+ initializer :expr1, :expr2
585
+ self.operator = '*'
586
+ end
587
+ ###
588
+ ### Divide
589
+ ###
590
+ class Divide
591
+ child :expr1
592
+ child :expr2
593
+ initializer :expr1, :expr2
594
+ self.operator = '/'
595
+ end
596
+ ###
597
+ ### Mod
598
+ ###
599
+ class Mod
600
+ child :expr1
601
+ child :expr2
602
+ initializer :expr1, :expr2
603
+ self.operator = '%'
604
+ end
605
+ ###
606
+ ### Equal
607
+ ###
608
+ class Equal
609
+ child :expr1
610
+ child :expr2
611
+ initializer :expr1, :expr2
612
+ self.operator = '=='
613
+ end
614
+ ###
615
+ ### NotEqual
616
+ ###
617
+ class NotEqual
618
+ child :expr1
619
+ child :expr2
620
+ initializer :expr1, :expr2
621
+ self.operator = '!='
622
+ end
623
+ ###
624
+ ### Less
625
+ ###
626
+ class Less
627
+ child :expr1
628
+ child :expr2
629
+ initializer :expr1, :expr2
630
+ self.operator = '<'
631
+ end
632
+ ###
633
+ ### More
634
+ ###
635
+ class More
636
+ child :expr1
637
+ child :expr2
638
+ initializer :expr1, :expr2
639
+ self.operator = '>'
640
+ end
641
+ ###
642
+ ### LessOrEqual
643
+ ###
644
+ class LessOrEqual
645
+ child :expr1
646
+ child :expr2
647
+ initializer :expr1, :expr2
648
+ self.operator = '<='
649
+ end
650
+ ###
651
+ ### MoreOrEqual
652
+ ###
653
+ class MoreOrEqual
654
+ child :expr1
655
+ child :expr2
656
+ initializer :expr1, :expr2
657
+ self.operator = '>='
658
+ end
659
+ ###
660
+ ### BitAnd
661
+ ###
662
+ class BitAnd
663
+ child :expr1
664
+ child :expr2
665
+ initializer :expr1, :expr2
666
+ self.operator = '&'
667
+ end
668
+ ###
669
+ ### BitOr
670
+ ###
671
+ class BitOr
672
+ child :expr1
673
+ child :expr2
674
+ initializer :expr1, :expr2
675
+ self.operator = '|'
676
+ end
677
+ ###
678
+ ### BitXor
679
+ ###
680
+ class BitXor
681
+ child :expr1
682
+ child :expr2
683
+ initializer :expr1, :expr2
684
+ self.operator = '^'
685
+ end
686
+ ###
687
+ ### ShiftLeft
688
+ ###
689
+ class ShiftLeft
690
+ child :expr1
691
+ child :expr2
692
+ initializer :expr1, :expr2
693
+ self.operator = '<<'
694
+ end
695
+ ###
696
+ ### ShiftRight
697
+ ###
698
+ class ShiftRight
699
+ child :expr1
700
+ child :expr2
701
+ initializer :expr1, :expr2
702
+ self.operator = '>>'
703
+ end
704
+ ###
705
+ ### And
706
+ ###
707
+ class And
708
+ child :expr1
709
+ child :expr2
710
+ initializer :expr1, :expr2
711
+ self.operator = '&&'
712
+ end
713
+ ###
714
+ ### Or
715
+ ###
716
+ class Or
717
+ child :expr1
718
+ child :expr2
719
+ initializer :expr1, :expr2
720
+ self.operator = '||'
721
+ end
722
+
723
+ ###
724
+ ### ----------------------------------------------------------------
725
+ ### AssignmentExpressions
726
+ ### ----------------------------------------------------------------
727
+ ###
728
+
729
+ ###
730
+ ### AssignmentExpression (abstract)
731
+ ###
732
+ class AssignmentExpression
733
+ class << self
734
+ ###
735
+ ### The operator (a String) pertaining to the class (e.g.,
736
+ ### Assign.operator is '=').
737
+ ###
738
+ attr_accessor :operator
739
+ end
740
+ end
741
+ ###
742
+ ### Assign
743
+ ###
744
+ class Assign
745
+ child :lval
746
+ child :rval
747
+ initializer :lval, :rval
748
+ self.operator = '='
749
+ end
750
+ ###
751
+ ### MultiplyAssign
752
+ ###
753
+ class MultiplyAssign
754
+ child :lval
755
+ child :rval
756
+ initializer :lval, :rval
757
+ self.operator = '*='
758
+ end
759
+ ###
760
+ ### DivideAssign
761
+ ###
762
+ class DivideAssign
763
+ child :lval
764
+ child :rval
765
+ initializer :lval, :rval
766
+ self.operator = '/='
767
+ end
768
+ ###
769
+ ### ModAssign
770
+ ###
771
+ class ModAssign
772
+ child :lval
773
+ child :rval
774
+ initializer :lval, :rval
775
+ self.operator = '%='
776
+ end
777
+ ###
778
+ ### AddAssign
779
+ ###
780
+ class AddAssign
781
+ child :lval
782
+ child :rval
783
+ initializer :lval, :rval
784
+ self.operator = '+='
785
+ end
786
+ ###
787
+ ### SubtractAssign
788
+ ###
789
+ class SubtractAssign
790
+ child :lval
791
+ child :rval
792
+ initializer :lval, :rval
793
+ self.operator = '-='
794
+ end
795
+ ###
796
+ ### ShiftLeftAssign
797
+ ###
798
+ class ShiftLeftAssign
799
+ child :lval
800
+ child :rval
801
+ initializer :lval, :rval
802
+ self.operator = '<<='
803
+ end
804
+ ###
805
+ ### ShiftRightAssign
806
+ ###
807
+ class ShiftRightAssign
808
+ child :lval
809
+ child :rval
810
+ initializer :lval, :rval
811
+ self.operator = '>>='
812
+ end
813
+ ###
814
+ ### BitAndAssign
815
+ ###
816
+ class BitAndAssign
817
+ child :lval
818
+ child :rval
819
+ initializer :lval, :rval
820
+ self.operator = '&='
821
+ end
822
+ ###
823
+ ### BitXorAssign
824
+ ###
825
+ class BitXorAssign
826
+ child :lval
827
+ child :rval
828
+ initializer :lval, :rval
829
+ self.operator = '^='
830
+ end
831
+ ###
832
+ ### BitOrAssign
833
+ ###
834
+ class BitOrAssign
835
+ child :lval
836
+ child :rval
837
+ initializer :lval, :rval
838
+ self.operator = '|='
839
+ end
840
+
841
+ ###
842
+ ### ----------------------------------------------------------------
843
+ ### Literals
844
+ ### ----------------------------------------------------------------
845
+ ###
846
+
847
+ ###
848
+ ### StringLiteral
849
+ ###
850
+ class StringLiteral
851
+ field :val
852
+ initializer :val
853
+ end
854
+ ###
855
+ ### CharLiteral
856
+ ###
857
+ class CharLiteral
858
+ field :val
859
+ initializer :val
860
+ end
861
+ ###
862
+ ### CompoundLiteral
863
+ ###
864
+ class CompoundLiteral
865
+ child :type
866
+ child :member_inits, lambda{NodeArray.new}
867
+ initializer :type, :member_inits
868
+ end
869
+ ###
870
+ ### IntLiteral
871
+ ###
872
+ class IntLiteral
873
+ field :val
874
+ field :format, :dec
875
+ initializer :val
876
+ def dec?
877
+ format.equal? :dec
878
+ end
879
+ def hex?
880
+ format.equal? :hex
881
+ end
882
+ def oct?
883
+ format.equal? :oct
884
+ end
885
+ end
886
+ ###
887
+ ### FloatLiteral
888
+ ###
889
+ class FloatLiteral
890
+ field :val
891
+ initializer :val
892
+ end
893
+
894
+ ###
895
+ ### ----------------------------------------------------------------
896
+ ### Types
897
+ ### ----------------------------------------------------------------
898
+ ###
899
+
900
+ ###
901
+ ### DirectType (abstract)
902
+ ###
903
+ class DirectType
904
+ def direct_type
905
+ self
906
+ end
907
+ def indirect_type
908
+ nil
909
+ end
910
+ end
911
+ ###
912
+ ### IndirectType (abstract)
913
+ ###
914
+ class IndirectType
915
+ def direct_type
916
+ if type.is_a? IndirectType
917
+ type.direct_type
918
+ else
919
+ type
920
+ end
921
+ end
922
+ def direct_type= val
923
+ if type.is_a? IndirectType
924
+ type.direct_type = val
925
+ else
926
+ self.type = val
927
+ end
928
+ end
929
+ def indirect_type
930
+ ret = self.clone
931
+ t = ret
932
+ while t.type.is_a? IndirectType
933
+ t = t.type
934
+ end
935
+ t.type = nil
936
+ return ret
937
+ end
938
+ end
939
+ ###
940
+ ### Pointer
941
+ ###
942
+ class Pointer
943
+ field :const?
944
+ field :restrict?
945
+ field :volatile?
946
+ child :type
947
+ initializer :type
948
+ end
949
+ ###
950
+ ### Array
951
+ ###
952
+ class Array
953
+ field :const?
954
+ field :restrict?
955
+ field :volatile?
956
+ child :type
957
+ child :length
958
+ initializer :type, :length
959
+ end
960
+ ###
961
+ ### Function
962
+ ###
963
+ class Function
964
+ field :const?
965
+ field :restrict?
966
+ field :volatile?
967
+ child :type
968
+ child :params
969
+ field :var_args?
970
+ initializer :type, :params
971
+ end
972
+ ###
973
+ ### Struct
974
+ ###
975
+ class Struct
976
+ field :const?
977
+ field :restrict?
978
+ field :volatile?
979
+ field :name
980
+ child :members
981
+ initializer :name, :members
982
+ end
983
+ ###
984
+ ### Union
985
+ ###
986
+ class Union
987
+ field :const?
988
+ field :restrict?
989
+ field :volatile?
990
+ field :name
991
+ child :members
992
+ initializer :name, :members
993
+ end
994
+ ###
995
+ ### Enum
996
+ ###
997
+ class Enum
998
+ field :const?
999
+ field :restrict?
1000
+ field :volatile?
1001
+ field :name
1002
+ child :members
1003
+ initializer :name, :members
1004
+ end
1005
+ ###
1006
+ ### CustomType
1007
+ ###
1008
+ class CustomType
1009
+ field :const?
1010
+ field :restrict?
1011
+ field :volatile?
1012
+ field :name
1013
+ initializer :name
1014
+ end
1015
+ ###
1016
+ ### Void
1017
+ ###
1018
+ class Void
1019
+ field :const?
1020
+ field :restrict?
1021
+ field :volatile?
1022
+ end
1023
+ ###
1024
+ ### Int
1025
+ ###
1026
+ class Int
1027
+ field :const?
1028
+ field :restrict?
1029
+ field :volatile?
1030
+ field :longness, 0
1031
+ field :unsigned?, false
1032
+ initializer :longness
1033
+ def signed?
1034
+ !unsigned?
1035
+ end
1036
+ def signed= val
1037
+ self.unsigned = !val
1038
+ end
1039
+ def short?
1040
+ longness.equal? -1
1041
+ end
1042
+ def plain?
1043
+ longness.equal? 0
1044
+ end
1045
+ def long?
1046
+ longness.equal? 1
1047
+ end
1048
+ def long_long?
1049
+ longness.equal? 2
1050
+ end
1051
+ end
1052
+ ###
1053
+ ### Float
1054
+ ###
1055
+ class Float
1056
+ field :const?
1057
+ field :restrict?
1058
+ field :volatile?
1059
+ field :longness, 0
1060
+ initializer :longness
1061
+ def plain?
1062
+ longness.equal? 0
1063
+ end
1064
+ def double?
1065
+ longness.equal? 1
1066
+ end
1067
+ def long_double?
1068
+ longness.equal? 2
1069
+ end
1070
+ end
1071
+ ###
1072
+ ### Char
1073
+ ###
1074
+ class Char
1075
+ field :const?
1076
+ field :restrict?
1077
+ field :volatile?
1078
+ ## 6.2.5p15: `char', `signed char', and `unsigned char' are
1079
+ ## distinct types
1080
+ field :signed
1081
+ def signed?
1082
+ signed.equal? true
1083
+ end
1084
+ def unsigned?
1085
+ signed.equal? false
1086
+ end
1087
+ def plain?
1088
+ signed.nil?
1089
+ end
1090
+ end
1091
+ ###
1092
+ ### Bool
1093
+ ###
1094
+ class Bool
1095
+ field :const?
1096
+ field :restrict?
1097
+ field :volatile?
1098
+ end
1099
+ ###
1100
+ ### Complex
1101
+ ###
1102
+ class Complex
1103
+ field :const?
1104
+ field :restrict?
1105
+ field :volatile?
1106
+ field :longness, 0
1107
+ initializer :longness
1108
+ def plain?
1109
+ longness.equal? 0
1110
+ end
1111
+ def double?
1112
+ longness.equal? 1
1113
+ end
1114
+ def long_double?
1115
+ longness.equal? 2
1116
+ end
1117
+ end
1118
+ ###
1119
+ ### Imaginary
1120
+ ###
1121
+ class Imaginary
1122
+ field :const?
1123
+ field :restrict?
1124
+ field :volatile?
1125
+ field :longness, 0
1126
+ initializer :longness
1127
+ def plain?
1128
+ longness.equal? 0
1129
+ end
1130
+ def double?
1131
+ longness.equal? 1
1132
+ end
1133
+ def long_double?
1134
+ longness.equal? 2
1135
+ end
1136
+ end
1137
+
1138
+ ###
1139
+ ### ================================================================
1140
+ ###
1141
+ ### Tag classes
1142
+ ###
1143
+ ### ================================================================
1144
+ ###
1145
+
1146
+ ## classify the node classes by including modules
1147
+ tagger = lambda do |included, *includers|
1148
+ includers.each{|mod| mod.send(:include, included)}
1149
+ end
1150
+
1151
+ ## expression classes
1152
+ module ArithmeticExpression; end
1153
+ module BitwiseExpression ; end
1154
+ module LogicalExpression ; end
1155
+ module RelationalExpression; end
1156
+ module ShiftExpression ; end
1157
+ ##
1158
+ tagger.call(ArithmeticExpression,
1159
+ PostInc, PostDec, Positive, Negative, PreInc, PreDec, Add,
1160
+ Subtract, Multiply, Divide, Mod)
1161
+ tagger.call(BitwiseExpression,
1162
+ BitNot, BitAnd, BitOr, BitXor)
1163
+ tagger.call(LogicalExpression,
1164
+ Not, And, Or)
1165
+ tagger.call(RelationalExpression,
1166
+ Equal, NotEqual, Less, More, LessOrEqual, MoreOrEqual)
1167
+ tagger.call(ShiftExpression,
1168
+ ShiftLeft, ShiftRight)
1169
+
1170
+ ###
1171
+ ### ================================================================
1172
+ ###
1173
+ ### CORE_C_NODE_CLASSES
1174
+ ###
1175
+ ### ================================================================
1176
+ ###
1177
+
1178
+ CORE_C_NODE_CLASSES = [
1179
+ TranslationUnit,
1180
+ Declaration,
1181
+ Declarator,
1182
+ FunctionDef,
1183
+ Parameter,
1184
+ Enumerator,
1185
+ MemberInit,
1186
+ Member,
1187
+
1188
+ Block,
1189
+ If,
1190
+ Switch,
1191
+ While,
1192
+ For,
1193
+ Goto,
1194
+ Continue,
1195
+ Break,
1196
+ Return,
1197
+ ExpressionStatement,
1198
+
1199
+ PlainLabel,
1200
+ Default,
1201
+ Case,
1202
+
1203
+ Comma,
1204
+ Conditional,
1205
+ Variable,
1206
+
1207
+ Index,
1208
+ Call,
1209
+ Dot,
1210
+ Arrow,
1211
+ PostInc,
1212
+ PostDec,
1213
+
1214
+ Cast,
1215
+ Address,
1216
+ Dereference,
1217
+ Sizeof,
1218
+ Positive,
1219
+ Negative,
1220
+ PreInc,
1221
+ PreDec,
1222
+ BitNot,
1223
+ Not,
1224
+
1225
+ Add,
1226
+ Subtract,
1227
+ Multiply,
1228
+ Divide,
1229
+ Mod,
1230
+ Equal,
1231
+ NotEqual,
1232
+ Less,
1233
+ More,
1234
+ LessOrEqual,
1235
+ MoreOrEqual,
1236
+ BitAnd,
1237
+ BitOr,
1238
+ BitXor,
1239
+ ShiftLeft,
1240
+ ShiftRight,
1241
+ And,
1242
+ Or,
1243
+
1244
+ Assign,
1245
+ MultiplyAssign,
1246
+ DivideAssign,
1247
+ ModAssign,
1248
+ AddAssign,
1249
+ SubtractAssign,
1250
+ ShiftLeftAssign,
1251
+ ShiftRightAssign,
1252
+ BitAndAssign,
1253
+ BitXorAssign,
1254
+ BitOrAssign,
1255
+
1256
+ StringLiteral,
1257
+ CharLiteral,
1258
+ CompoundLiteral,
1259
+ IntLiteral,
1260
+ FloatLiteral,
1261
+
1262
+ Pointer,
1263
+ Array,
1264
+ Function,
1265
+
1266
+ Struct,
1267
+ Union,
1268
+ Enum,
1269
+ CustomType,
1270
+
1271
+ Void,
1272
+ Int,
1273
+ Float,
1274
+ Char,
1275
+ Bool,
1276
+ Complex,
1277
+ Imaginary
1278
+ ]
1279
+
1280
+ ## check we didn't miss any
1281
+ expected_classes = Node.subclasses_recursive.sort_by{|c| c.name}
1282
+ expected_classes -= NodeList.subclasses_recursive
1283
+ expected_classes -= [NodeList]
1284
+ expected_classes -= [
1285
+ Statement,
1286
+ Label,
1287
+ Expression,
1288
+ UnaryExpression,
1289
+ PostfixExpression,
1290
+ PrefixExpression,
1291
+ BinaryExpression,
1292
+ AssignmentExpression,
1293
+ Literal,
1294
+ Type,
1295
+ IndirectType,
1296
+ DirectType,
1297
+ PrimitiveType
1298
+ ]
1299
+ ##
1300
+ CORE_C_NODE_CLASSES.sort_by{|c| c.name} == expected_classes or raise
1301
+ end