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