adlint 1.16.0 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/ChangeLog +471 -0
  2. data/MANIFEST +35 -8
  3. data/NEWS +50 -4
  4. data/bin/adlint +7 -7
  5. data/bin/adlint_chk +7 -7
  6. data/bin/adlint_cma +7 -7
  7. data/bin/adlint_sma +7 -7
  8. data/bin/adlintize +5 -5
  9. data/etc/mesg.d/en_US/messages.yml +3 -3
  10. data/etc/mesg.d/ja_JP/messages.yml +3 -3
  11. data/features/message_detection/E0013.feature +34 -0
  12. data/features/message_detection/W0007.feature +2 -0
  13. data/features/message_detection/W0583.feature +1 -2
  14. data/features/message_detection/W0641.feature +132 -0
  15. data/features/message_detection/W0643.feature +1 -1
  16. data/features/message_detection/W0644.feature +529 -0
  17. data/features/message_detection/W0645.feature +1 -1
  18. data/features/message_detection/W0649.feature +277 -0
  19. data/features/message_detection/W0650.feature +208 -0
  20. data/features/message_detection/W0697.feature +6 -0
  21. data/features/message_detection/W0705.feature +350 -0
  22. data/features/message_detection/W0707.feature +223 -0
  23. data/features/message_detection/W0711.feature +113 -0
  24. data/features/message_detection/W0712.feature +113 -0
  25. data/features/message_detection/W0713.feature +110 -0
  26. data/features/message_detection/W0714.feature +118 -0
  27. data/features/message_detection/W0715.feature +118 -0
  28. data/features/message_detection/W0716.feature +1 -0
  29. data/features/message_detection/W0717.feature +1 -0
  30. data/features/message_detection/W0718.feature +1 -0
  31. data/features/message_detection/W0719.feature +154 -0
  32. data/features/message_detection/W0723.feature +1 -2
  33. data/features/message_detection/W0732.feature +3 -0
  34. data/features/message_detection/W0733.feature +3 -0
  35. data/features/message_detection/W0734.feature +4 -0
  36. data/features/message_detection/W0735.feature +4 -0
  37. data/features/message_detection/W0745.feature +132 -0
  38. data/features/message_detection/W0780.feature +68 -0
  39. data/features/message_detection/W0783.feature +95 -0
  40. data/features/message_detection/W0792.feature +124 -0
  41. data/features/message_detection/W0793.feature +153 -0
  42. data/features/message_detection/W0794.feature +90 -0
  43. data/features/message_detection/W0830.feature +65 -0
  44. data/features/message_detection/W0833.feature +220 -0
  45. data/features/message_detection/W0834.feature +189 -0
  46. data/features/message_detection/W1026.feature +105 -0
  47. data/features/message_detection/W1031.feature +17 -34
  48. data/features/message_detection/W1039.feature +268 -0
  49. data/features/message_detection/W1047.feature +163 -0
  50. data/features/message_detection/W1066.feature +1 -0
  51. data/features/message_detection/W1067.feature +1 -0
  52. data/features/message_detection/W1068.feature +1 -0
  53. data/features/message_detection/W1069.feature +5 -0
  54. data/features/message_detection/W1070.feature +5 -0
  55. data/features/message_detection/W1071.feature +83 -0
  56. data/features/message_detection/W1073.feature +3 -2
  57. data/features/message_detection/W9003.feature +7 -12
  58. data/features/step_definitions/message_detection_steps.rb +4 -31
  59. data/features/support/env.rb +117 -2
  60. data/lib/adlint/c/branch.rb +0 -2
  61. data/lib/adlint/c/ctrlexpr.rb +33 -0
  62. data/lib/adlint/c/expr.rb +119 -31
  63. data/lib/adlint/c/interp.rb +44 -3
  64. data/lib/adlint/c/message.rb +1411 -29
  65. data/lib/adlint/c/object.rb +16 -2
  66. data/lib/adlint/c/option.rb +1 -0
  67. data/lib/adlint/c/parser.rb +101 -100
  68. data/lib/adlint/c/parser.y +3 -2
  69. data/lib/adlint/c/phase.rb +18 -0
  70. data/lib/adlint/c/resolver.rb +23 -0
  71. data/lib/adlint/c/syntax.rb +90 -4
  72. data/lib/adlint/c/type.rb +177 -110
  73. data/lib/adlint/cpp/macro.rb +4 -4
  74. data/lib/adlint/version.rb +2 -2
  75. data/share/demo/bad_include/test/"1/".h +0 -0
  76. data/share/doc/developers_guide_ja.html +3 -3
  77. data/share/doc/developers_guide_ja.texi +1 -1
  78. data/share/doc/users_guide_en.html +467 -506
  79. data/share/doc/users_guide_en.texi +95 -125
  80. data/share/doc/users_guide_ja.html +471 -518
  81. data/share/doc/users_guide_ja.texi +95 -133
  82. data/spec/spec_helper.rb +6 -0
  83. metadata +37 -10
@@ -1092,7 +1092,8 @@ enum_specifier
1092
1092
  {
1093
1093
  checkpoint(val[0].location)
1094
1094
 
1095
- result = EnumSpecifier.new(create_unnamed_tag_name(val[0]), val[2])
1095
+ result = EnumSpecifier.new(create_unnamed_tag_name(val[0]), val[2],
1096
+ val[3])
1096
1097
  result.head_token = val[0]
1097
1098
  result.tail_token = val[4]
1098
1099
  }
@@ -1100,7 +1101,7 @@ enum_specifier
1100
1101
  {
1101
1102
  checkpoint(val[0].location)
1102
1103
 
1103
- result = EnumSpecifier.new(val[1], val[3])
1104
+ result = EnumSpecifier.new(val[1], val[3], val[4])
1104
1105
  result.head_token = val[0]
1105
1106
  result.tail_token = val[5]
1106
1107
  }
@@ -602,8 +602,12 @@ module C #:nodoc:
602
602
  W0638.new(context),
603
603
  W0639.new(context),
604
604
  W0640.new(context),
605
+ W0641.new(context),
605
606
  W0642.new(context),
607
+ W0644.new(context),
606
608
  W0645.new(context),
609
+ W0649.new(context),
610
+ W0650.new(context),
607
611
  W0653.new(context),
608
612
  W0654.new(context),
609
613
  W0655.new(context),
@@ -646,6 +650,7 @@ module C #:nodoc:
646
650
  W0703.new(context),
647
651
  W0704.new(context),
648
652
  W0705.new(context),
653
+ W0707.new(context),
649
654
  W0708.new(context),
650
655
  W0711.new(context),
651
656
  W0712.new(context),
@@ -655,6 +660,7 @@ module C #:nodoc:
655
660
  W0716.new(context),
656
661
  W0717.new(context),
657
662
  W0718.new(context),
663
+ W0719.new(context),
658
664
  W0720.new(context),
659
665
  W0721.new(context),
660
666
  W0722.new(context),
@@ -709,13 +715,18 @@ module C #:nodoc:
709
715
  W0777.new(context),
710
716
  W0778.new(context),
711
717
  W0779.new(context),
718
+ W0780.new(context),
712
719
  W0781.new(context),
720
+ W0783.new(context),
713
721
  W0785.new(context),
714
722
  W0786.new(context),
715
723
  W0787.new(context),
716
724
  W0788.new(context),
717
725
  W0789.new(context),
718
726
  W0790.new(context),
727
+ W0792.new(context),
728
+ W0793.new(context),
729
+ W0794.new(context),
719
730
  W0795.new(context),
720
731
  W0796.new(context),
721
732
  W0797.new(context),
@@ -727,10 +738,14 @@ module C #:nodoc:
727
738
  W0810.new(context),
728
739
  W0827.new(context),
729
740
  W0828.new(context),
741
+ W0830.new(context),
742
+ W0833.new(context),
743
+ W0834.new(context),
730
744
  W0947.new(context),
731
745
  W0948.new(context),
732
746
  W0949.new(context),
733
747
  W0950.new(context),
748
+ W1026.new(context),
734
749
  W1027.new(context),
735
750
  W1028.new(context),
736
751
  W1029.new(context),
@@ -739,6 +754,8 @@ module C #:nodoc:
739
754
  W1032.new(context),
740
755
  W1033.new(context),
741
756
  W1034.new(context),
757
+ W1039.new(context),
758
+ W1047.new(context),
742
759
  W1049.new(context),
743
760
  W1050.new(context),
744
761
  W1051.new(context),
@@ -761,6 +778,7 @@ module C #:nodoc:
761
778
  W1068.new(context),
762
779
  W1069.new(context),
763
780
  W1070.new(context),
781
+ W1071.new(context),
764
782
  W1072.new(context),
765
783
  W1073.new(context),
766
784
  W1074.new(context),
@@ -123,6 +123,29 @@ module C #:nodoc:
123
123
  node.init_declarator.declarator)
124
124
  end
125
125
 
126
+ def visit_parameter_declaration(node)
127
+ checkpoint(node.location)
128
+ node.declaration_specifiers.accept(self) if node.declaration_specifiers
129
+ node.declarator.accept(self) if node.declarator
130
+
131
+ if declaration_specifiers = node.declaration_specifiers
132
+ type_qualifiers = declaration_specifiers.type_qualifiers
133
+ type_specifiers = declaration_specifiers.type_specifiers
134
+ else
135
+ type_qualifiers = []
136
+ type_specifiers = []
137
+ end
138
+
139
+ type = lookup_variable_type(type_qualifiers, type_specifiers,
140
+ node.declarator)
141
+
142
+ if type.function?
143
+ node.type = @type_table.pointer_type(type)
144
+ else
145
+ node.type = type
146
+ end
147
+ end
148
+
126
149
  def visit_variable_declaration(node)
127
150
  checkpoint(node.location)
128
151
  node.declaration_specifiers.accept(self) if node.declaration_specifiers
@@ -1457,7 +1457,10 @@ module C #:nodoc:
1457
1457
  # left-to-right evaluation; there is a sequence point after the
1458
1458
  # evaluation of the first operand. If the first operand compares equal
1459
1459
  # to 0, the second operand is not evaluated.
1460
- @lhs_operand.append_sequence_point!
1460
+ #
1461
+ # NOTE: Sequence point will be reached after lhs value reference.
1462
+ # So, notification should be done by ExpressionEvaluator manually.
1463
+ # @lhs_operand.append_sequence_point!
1461
1464
  end
1462
1465
 
1463
1466
  def have_side_effect?
@@ -1491,7 +1494,10 @@ module C #:nodoc:
1491
1494
  # left-to-right evaluation; there is a sequence point after the
1492
1495
  # evaluation of the first operand. If the first operand compares
1493
1496
  # unequal to 0, the second operand is not evaluated.
1494
- @lhs_operand.append_sequence_point!
1497
+ #
1498
+ # NOTE: Sequence point will be reached after lhs value reference.
1499
+ # So, notification should be done by ExpressionEvaluator manually.
1500
+ # @lhs_operand.append_sequence_point!
1495
1501
  end
1496
1502
 
1497
1503
  def have_side_effect?
@@ -2363,14 +2369,16 @@ module C #:nodoc:
2363
2369
  end
2364
2370
 
2365
2371
  class EnumSpecifier < TypeSpecifier
2366
- def initialize(identifier, enumerators)
2372
+ def initialize(identifier, enumerators, trailing_comma = nil)
2367
2373
  super()
2368
2374
  @identifier = identifier
2369
2375
  @enumerators = enumerators
2376
+ @trailing_comma = trailing_comma
2370
2377
  end
2371
2378
 
2372
2379
  attr_reader :identifier
2373
2380
  attr_reader :enumerators
2381
+ attr_reader :trailing_comma
2374
2382
 
2375
2383
  def location
2376
2384
  @identifier.location
@@ -2509,6 +2517,18 @@ module C #:nodoc:
2509
2517
  def variable?
2510
2518
  !function?
2511
2519
  end
2520
+
2521
+ def parameter_type_list
2522
+ subclass_responsibility
2523
+ end
2524
+
2525
+ def innermost_parameter_type_list
2526
+ subclass_responsibility
2527
+ end
2528
+
2529
+ def identifier_list
2530
+ subclass_responsibility
2531
+ end
2512
2532
  end
2513
2533
 
2514
2534
  class IdentifierDeclarator < Declarator
@@ -2531,6 +2551,10 @@ module C #:nodoc:
2531
2551
  nil
2532
2552
  end
2533
2553
 
2554
+ def innermost_parameter_type_list
2555
+ nil
2556
+ end
2557
+
2534
2558
  def identifier_list
2535
2559
  nil
2536
2560
  end
@@ -2565,6 +2589,10 @@ module C #:nodoc:
2565
2589
  @base.parameter_type_list
2566
2590
  end
2567
2591
 
2592
+ def innermost_parameter_type_list
2593
+ @base.innermost_parameter_type_list
2594
+ end
2595
+
2568
2596
  def identifier_list
2569
2597
  @base.identifier_list
2570
2598
  end
@@ -2602,6 +2630,10 @@ module C #:nodoc:
2602
2630
  @base.parameter_type_list
2603
2631
  end
2604
2632
 
2633
+ def innermost_parameter_type_list
2634
+ @base.innermost_parameter_type_list
2635
+ end
2636
+
2605
2637
  def identifier_list
2606
2638
  @base.identifier_list
2607
2639
  end
@@ -2654,6 +2686,10 @@ module C #:nodoc:
2654
2686
 
2655
2687
  attr_accessor :parameter_type_list
2656
2688
 
2689
+ def innermost_parameter_type_list
2690
+ @base.innermost_parameter_type_list || @parameter_type_list
2691
+ end
2692
+
2657
2693
  def identifier_list
2658
2694
  @base.identifier_list
2659
2695
  end
@@ -2670,6 +2706,10 @@ module C #:nodoc:
2670
2706
  def parameter_type_list
2671
2707
  @base.parameter_type_list
2672
2708
  end
2709
+
2710
+ def innermost_parameter_type_list
2711
+ @base.innermost_parameter_type_list
2712
+ end
2673
2713
  end
2674
2714
 
2675
2715
  class AbbreviatedFunctionDeclarator < FunctionDeclarator
@@ -2677,6 +2717,10 @@ module C #:nodoc:
2677
2717
  @base.parameter_type_list
2678
2718
  end
2679
2719
 
2720
+ def innermost_parameter_type_list
2721
+ @base.innermost_parameter_type_list
2722
+ end
2723
+
2680
2724
  def identifier_list
2681
2725
  @base.identifier_list
2682
2726
  end
@@ -2711,10 +2755,12 @@ module C #:nodoc:
2711
2755
  super()
2712
2756
  @declaration_specifiers = declaration_specifiers
2713
2757
  @declarator = declarator
2758
+ @type = nil
2714
2759
  end
2715
2760
 
2716
2761
  attr_reader :declaration_specifiers
2717
2762
  attr_reader :declarator
2763
+ attr_accessor :type
2718
2764
 
2719
2765
  def location
2720
2766
  @declarator ? @declarator.location : @declaration_specifiers.location
@@ -3487,7 +3533,7 @@ module C #:nodoc:
3487
3533
  def initialize(declaration_specifiers, declarator,
3488
3534
  compound_statement, symbol_table)
3489
3535
  super(declaration_specifiers, declarator,
3490
- create_parameters(declarator.parameter_type_list),
3536
+ create_parameters(declarator.innermost_parameter_type_list),
3491
3537
  compound_statement, symbol_table)
3492
3538
  end
3493
3539
 
@@ -3635,6 +3681,18 @@ module C #:nodoc:
3635
3681
  stack.last == :function
3636
3682
  end
3637
3683
 
3684
+ def parameter_type_list
3685
+ @base.parameter_type_list
3686
+ end
3687
+
3688
+ def innermost_parameter_type_list
3689
+ @base.innermost_parameter_type_list
3690
+ end
3691
+
3692
+ def identifier_list
3693
+ @base.identifier_list
3694
+ end
3695
+
3638
3696
  def inspect(indent = 0)
3639
3697
  " " * indent + short_class_name
3640
3698
  end
@@ -3656,6 +3714,18 @@ module C #:nodoc:
3656
3714
  @base.function?
3657
3715
  end
3658
3716
 
3717
+ def parameter_type_list
3718
+ @base.parameter_type_list
3719
+ end
3720
+
3721
+ def innermost_parameter_type_list
3722
+ @base.innermost_parameter_type_list
3723
+ end
3724
+
3725
+ def identifier_list
3726
+ @base.identifier_list
3727
+ end
3728
+
3659
3729
  def inspect(indent = 0)
3660
3730
  " " * indent + short_class_name
3661
3731
  end
@@ -3683,6 +3753,18 @@ module C #:nodoc:
3683
3753
  stack.last == :function
3684
3754
  end
3685
3755
 
3756
+ def parameter_type_list
3757
+ @base.parameter_type_list
3758
+ end
3759
+
3760
+ def innermost_parameter_type_list
3761
+ @base.innermost_parameter_type_list
3762
+ end
3763
+
3764
+ def identifier_list
3765
+ @base.identifier_list
3766
+ end
3767
+
3686
3768
  def inspect(indent = 0)
3687
3769
  " " * indent + short_class_name
3688
3770
  end
@@ -3710,6 +3792,10 @@ module C #:nodoc:
3710
3792
  stack.last == :function
3711
3793
  end
3712
3794
 
3795
+ def innermost_parameter_type_list
3796
+ @base.innermost_parameter_type_list || @parameter_type_list
3797
+ end
3798
+
3713
3799
  def inspect(indent = 0)
3714
3800
  " " * indent + short_class_name
3715
3801
  end
data/lib/adlint/c/type.rb CHANGED
@@ -31,6 +31,7 @@
31
31
 
32
32
  require "adlint/traits"
33
33
  require "adlint/token"
34
+ require "adlint/util"
34
35
  require "adlint/c/syntax"
35
36
  require "adlint/c/scope"
36
37
  require "adlint/c/object"
@@ -136,6 +137,7 @@ module C #:nodoc:
136
137
  # <--- ParameterType ---------------------------------+
137
138
  class Type
138
139
  include StandardTypeCatalogAccessor
140
+ include Visitable
139
141
 
140
142
  def initialize(type_table, name, type_declarations = [])
141
143
  @type_table = type_table
@@ -877,34 +879,22 @@ module C #:nodoc:
877
879
 
878
880
  def _arithmetic_type_with_undeclared(lhs, rhs = self)
879
881
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
880
- # NOTE: Binary operation with UndeclaredType and UndeclaredType
881
- # raises a runtime error.
882
- raise TypeError,
883
- "arithmetic-type of UndeclaredType and UndeclaredType is not defined."
882
+ lhs # NOTREACHED
884
883
  end
885
884
 
886
885
  def _arithmetic_type_with_unresolved(lhs, rhs = self)
887
886
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
888
- # NOTE: Binary operation with UnresolvedType and UndeclaredType
889
- # raises a runtime error.
890
- raise TypeError,
891
- "arithmetic-type of UnresolvedType and UndeclaredType is not defined."
887
+ lhs # NOTREACHED
892
888
  end
893
889
 
894
890
  def _arithmetic_type_with_void(lhs, rhs = self)
895
891
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
896
- # NOTE: Binary operation with `void' and UndeclaredType
897
- # raises a runtime error.
898
- raise TypeError,
899
- "arithmetic-type of `void' and UndeclaredType is not defined."
892
+ lhs # NOTREACHED
900
893
  end
901
894
 
902
895
  def _arithmetic_type_with_function(lhs, rhs = self)
903
896
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
904
- # NOTE: Binary operation with FunctionType and UndeclaredType
905
- # raises a runtime error.
906
- raise TypeError,
907
- "arithmetic-type of FunctionType and UndeclaredType is not defined."
897
+ lhs # NOTREACHED
908
898
  end
909
899
 
910
900
  def _arithmetic_type_with_char(lhs, rhs = self)
@@ -1127,26 +1117,17 @@ module C #:nodoc:
1127
1117
 
1128
1118
  def _arithmetic_type_with_array(lhs, rhs = self)
1129
1119
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
1130
- # NOTE: Binary operation with ArrayType and UndeclaredType
1131
- # raises a runtime error.
1132
- raise TypeError,
1133
- "arithmetic-type of ArrayType and UndeclaredType is not defined."
1120
+ lhs # NOTREACHED
1134
1121
  end
1135
1122
 
1136
1123
  def _arithmetic_type_with_struct(lhs, rhs = self)
1137
1124
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
1138
- # NOTE: Binary operation with StructType and UndeclaredType
1139
- # raises a runtime error.
1140
- raise TypeError,
1141
- "arithmetic-type of StructType and UndeclaredType is not defined."
1125
+ lhs # NOTREACHED
1142
1126
  end
1143
1127
 
1144
1128
  def _arithmetic_type_with_union(lhs, rhs = self)
1145
1129
  # NOTE: An arithmetic operation with UndeclaredType must not be executed!
1146
- # NOTE: Binary operation with UnionType and UndeclaredType
1147
- # raises a runtime error.
1148
- raise TypeError,
1149
- "arithmetic-type of UnionType and UndeclaredType is not defined."
1130
+ lhs # NOTREACHED
1150
1131
  end
1151
1132
 
1152
1133
  def _arithmetic_type_with_extended_big_int(lhs, rhs = self)
@@ -1410,26 +1391,17 @@ module C #:nodoc:
1410
1391
 
1411
1392
  def _arithmetic_type_with_unresolved(lhs, rhs = self)
1412
1393
  # NOTE: An arithmetic operation with UnresolvedType must not be executed!
1413
- # NOTE: Binary operation with UnresolvedType and UnresolvedType
1414
- # raises a runtime error.
1415
- raise TypeError,
1416
- "arithmetic-type of UnresolvedType and UnresolvedType is not defined."
1394
+ lhs # NOTREACHED
1417
1395
  end
1418
1396
 
1419
1397
  def _arithmetic_type_with_void(lhs, rhs = self)
1420
1398
  # NOTE: An arithmetic operation with UnresolvedType must not be executed!
1421
- # NOTE: Binary operation with `void' and UnresolvedType
1422
- # raises a runtime error.
1423
- raise TypeError,
1424
- "arithmetic-type of `void' and UnresolvedType is not defined."
1399
+ lhs # NOTREACHED
1425
1400
  end
1426
1401
 
1427
1402
  def _arithmetic_type_with_function(lhs, rhs = self)
1428
1403
  # NOTE: An arithmetic operation with UnresolvedType must not be executed!
1429
- # NOTE: Binary operation with FunctionType and UnresolvedType
1430
- # raises a runtime error.
1431
- raise TypeError,
1432
- "arithmetic-type of FunctionType and UnresolvedType is not defined."
1404
+ lhs # NOTREACHED
1433
1405
  end
1434
1406
 
1435
1407
  def _arithmetic_type_with_char(lhs, rhs = self)
@@ -1652,26 +1624,17 @@ module C #:nodoc:
1652
1624
 
1653
1625
  def _arithmetic_type_with_array(lhs, rhs = self)
1654
1626
  # NOTE: An arithmetic operation with UnresolvedType must not be executed!
1655
- # NOTE: Binary operation with ArrayType and UnresolvedType
1656
- # raises a runtime error.
1657
- raise TypeError,
1658
- "arithmetic-type of ArrayType and UnresolvedType is not defined."
1627
+ lhs # NOTREACHED
1659
1628
  end
1660
1629
 
1661
1630
  def _arithmetic_type_with_struct(lhs, rhs = self)
1662
1631
  # NOTE: An arithmetic operation with UnresolvedType must not be executed!
1663
- # NOTE: Binary operation with StructType and UnresolvedType
1664
- # raises a runtime error.
1665
- raise TypeError,
1666
- "arithmetic-type of StructType and UnresolvedType is not defined."
1632
+ lhs # NOTREACHED
1667
1633
  end
1668
1634
 
1669
1635
  def _arithmetic_type_with_union(lhs, rhs = self)
1670
1636
  # NOTE: An arithmetic operation with UnresolvedType must not be executed!
1671
- # NOTE: Binary operation with UnionType and UnresolvedType
1672
- # raises a runtime error.
1673
- raise TypeError,
1674
- "arithmetic-type of UnionType and UnresolvedType is not defined."
1637
+ lhs # NOTREACHED
1675
1638
  end
1676
1639
 
1677
1640
  def _arithmetic_type_with_extended_big_int(lhs, rhs = self)
@@ -2274,17 +2237,12 @@ module C #:nodoc:
2274
2237
 
2275
2238
  def _arithmetic_type_with_void(lhs, rhs = self)
2276
2239
  # NOTE: An arithmetic operation with `void' must not be executed!
2277
- # NOTE: Binary operation with `void' and `void' raises a runtime error.
2278
- raise TypeError,
2279
- "arithmetic-type of `void' and `void' is not defined."
2240
+ lhs # NOTREACHED
2280
2241
  end
2281
2242
 
2282
2243
  def _arithmetic_type_with_function(lhs, rhs = self)
2283
2244
  # NOTE: An arithmetic operation with `void' must not be executed!
2284
- # NOTE: Binary operation with FunctionType and `void'
2285
- # raises a runtime error.
2286
- raise TypeError,
2287
- "arithmetic-type of FunctionType and `void' is not defined."
2245
+ lhs # NOTREACHED
2288
2246
  end
2289
2247
 
2290
2248
  def _arithmetic_type_with_char(lhs, rhs = self)
@@ -2502,26 +2460,17 @@ module C #:nodoc:
2502
2460
 
2503
2461
  def _arithmetic_type_with_array(lhs, rhs = self)
2504
2462
  # NOTE: An arithmetic operation with `void' must not be executed!
2505
- # NOTE: Binary operation with ArrayType and `void'
2506
- # raises a runtime error.
2507
- raise TypeError,
2508
- "arithmetic-type of ArrayType and `void' is not defined."
2463
+ lhs # NOTREACHED
2509
2464
  end
2510
2465
 
2511
2466
  def _arithmetic_type_with_struct(lhs, rhs = self)
2512
2467
  # NOTE: An arithmetic operation with `void' must not be executed!
2513
- # NOTE: Binary operation with StructType and `void'
2514
- # raises a runtime error.
2515
- raise TypeError,
2516
- "arithmetic-type of StructType and `void' is not defined."
2468
+ lhs # NOTREACHED
2517
2469
  end
2518
2470
 
2519
2471
  def _arithmetic_type_with_union(lhs, rhs = self)
2520
2472
  # NOTE: An arithmetic operation with `void' must not be executed!
2521
- # NOTE: Binary operation with UnionType and `void'
2522
- # raises a runtime error.
2523
- raise TypeError,
2524
- "arithmetic-type of UnionType and `void' is not defined."
2473
+ lhs # NOTREACHED
2525
2474
  end
2526
2475
 
2527
2476
  def _arithmetic_type_with_extended_big_int(lhs, rhs = self)
@@ -2599,8 +2548,9 @@ module C #:nodoc:
2599
2548
  end
2600
2549
 
2601
2550
  def incomplete?
2602
- @return_type.incomplete? || @parameter_types.empty? ||
2603
- @parameter_types.any? { |type| type.incomplete? }
2551
+ @return_type.incomplete? && !@return_type.void? or
2552
+ @parameter_types.empty? ||
2553
+ @parameter_types.any? { |type| type.incomplete? && !type.void? }
2604
2554
  end
2605
2555
 
2606
2556
  def compatible?(to_type)
@@ -2803,10 +2753,7 @@ module C #:nodoc:
2803
2753
 
2804
2754
  def _arithmetic_type_with_function(lhs, rhs = self)
2805
2755
  # NOTE: An arithmetic operation with FunctionType must not be executed!
2806
- # NOTE: Binary operation with FunctionType and FunctionType
2807
- # raises a runtime error.
2808
- raise TypeError,
2809
- "arithmetic-type of FunctionType and FunctionType is not defined."
2756
+ lhs # NOTREACHED
2810
2757
  end
2811
2758
 
2812
2759
  def _arithmetic_type_with_char(lhs, rhs = self)
@@ -3029,26 +2976,17 @@ module C #:nodoc:
3029
2976
 
3030
2977
  def _arithmetic_type_with_array(lhs, rhs = self)
3031
2978
  # NOTE: An arithmetic operation with FunctionType must not be executed!
3032
- # NOTE: Binary operation with ArrayType and FunctionType
3033
- # raises a runtime error.
3034
- raise TypeError,
3035
- "arithmetic-type of ArrayType and FunctionType is not defined."
2979
+ lhs # NOTREACHED
3036
2980
  end
3037
2981
 
3038
2982
  def _arithmetic_type_with_struct(lhs, rhs = self)
3039
2983
  # NOTE: An arithmetic operation with FunctionType must not be executed!
3040
- # NOTE: Binary operation with StructType and FunctionType
3041
- # raises a runtime error.
3042
- raise TypeError,
3043
- "arithmetic-type of StructType and FunctionType is not defined."
2984
+ lhs # NOTREACHED
3044
2985
  end
3045
2986
 
3046
2987
  def _arithmetic_type_with_union(lhs, rhs = self)
3047
2988
  # NOTE: An arithmetic operation with FunctionType must not be executed!
3048
- # NOTE: Binary operation with UnionType and FunctionType
3049
- # raises a runtime error.
3050
- raise TypeError,
3051
- "arithmetic-type of UnionType and FunctionType is not defined."
2989
+ lhs # NOTREACHED
3052
2990
  end
3053
2991
 
3054
2992
  def _arithmetic_type_with_extended_big_int(lhs, rhs = self)
@@ -5231,7 +5169,9 @@ module C #:nodoc:
5231
5169
  end
5232
5170
 
5233
5171
  def undeclared?
5234
- @base_type.undeclared?
5172
+ # NOTE: To avoid the infinite recursive call of #undeclared? when the
5173
+ # composite type contains the pointer to it's owner type.
5174
+ @base_type.kind_of?(UndeclaredType)
5235
5175
  end
5236
5176
 
5237
5177
  def unresolved?
@@ -6129,26 +6069,17 @@ module C #:nodoc:
6129
6069
 
6130
6070
  def _arithmetic_type_with_array(lhs, rhs = self)
6131
6071
  # NOTE: An arithmetic operation with ArrayType must not be executed!
6132
- # NOTE: Binary operation with ArrayType and ArrayType
6133
- # raises a runtime error.
6134
- raise TypeError,
6135
- "arithmetic-type of ArrayType and ArrayType is not defined."
6072
+ lhs # NOTREACHED
6136
6073
  end
6137
6074
 
6138
6075
  def _arithmetic_type_with_struct(lhs, rhs = self)
6139
6076
  # NOTE: An arithmetic operation with ArrayType must not be executed!
6140
- # NOTE: Binary operation with StructType and ArrayType
6141
- # raises a runtime error.
6142
- raise TypeError,
6143
- "arithmetic-type of StructType and ArrayType is not defined."
6077
+ lhs # NOTREACHED
6144
6078
  end
6145
6079
 
6146
6080
  def _arithmetic_type_with_union(lhs, rhs = self)
6147
6081
  # NOTE: An arithmetic operation with ArrayType must not be executed!
6148
- # NOTE: Binary operation with UnionType and ArrayType
6149
- # raises a runtime error.
6150
- raise TypeError,
6151
- "arithmetic-type of UnionType and ArrayType is not defined."
6082
+ lhs # NOTREACHED
6152
6083
  end
6153
6084
 
6154
6085
  def _arithmetic_type_with_extended_big_int(lhs, rhs = self)
@@ -6716,19 +6647,13 @@ module C #:nodoc:
6716
6647
  def _arithmetic_type_with_struct(lhs, rhs = self)
6717
6648
  # NOTE: An arithmetic operation with CompositeDataType must not be
6718
6649
  # executed!
6719
- # NOTE: Binary operation with StructType and CompositeDataType raises a
6720
- # runtime error.
6721
- raise TypeError,
6722
- "arithmetic-type of StructType and CompositeDataType is not defined."
6650
+ lhs # NOTREACHED
6723
6651
  end
6724
6652
 
6725
6653
  def _arithmetic_type_with_union(lhs, rhs = self)
6726
6654
  # NOTE: An arithmetic operation with CompositeDataType must not be
6727
6655
  # executed!
6728
- # NOTE: Binary operation with UnionType and CompositeDataType raises a
6729
- # runtime error.
6730
- raise TypeError,
6731
- "arithmetic-type of UnionType and CompositeDataType is not defined."
6656
+ lhs # NOTREACHED
6732
6657
  end
6733
6658
 
6734
6659
  def _arithmetic_type_with_extended_big_int(lhs, rhs = self)
@@ -6995,6 +6920,7 @@ module C #:nodoc:
6995
6920
  @declaration_or_definition = declaration_or_definition
6996
6921
  end
6997
6922
 
6923
+ attr_reader :type
6998
6924
  attr_reader :param_name
6999
6925
 
7000
6926
  extend Forwardable
@@ -7771,5 +7697,146 @@ module C #:nodoc:
7771
7697
  end
7772
7698
  end
7773
7699
 
7700
+ class TypeVisitor
7701
+ def visit_undeclared_type(type)
7702
+ end
7703
+
7704
+ def visit_unresolved_type(type)
7705
+ end
7706
+
7707
+ def visit_qualified_type(type)
7708
+ type.base_type.accept(self)
7709
+ end
7710
+
7711
+ def visit_void_type(type)
7712
+ end
7713
+
7714
+ def visit_function_type(type)
7715
+ type.return_type.accept(self)
7716
+ type.parameter_types.each { |ptype| ptype.accept(self) }
7717
+ end
7718
+
7719
+ def visit_char_type(type)
7720
+ end
7721
+
7722
+ def visit_signed_char_type(type)
7723
+ end
7724
+
7725
+ def visit_unsigned_char_type(type)
7726
+ end
7727
+
7728
+ def visit_short_type(type)
7729
+ end
7730
+
7731
+ def visit_signed_short_type(type)
7732
+ end
7733
+
7734
+ def visit_unsigned_short_type(type)
7735
+ end
7736
+
7737
+ def visit_short_int_type(type)
7738
+ end
7739
+
7740
+ def visit_signed_short_int_type(type)
7741
+ end
7742
+
7743
+ def visit_unsigned_short_int_type(type)
7744
+ end
7745
+
7746
+ def visit_int_type(type)
7747
+ end
7748
+
7749
+ def visit_signed_type(type)
7750
+ end
7751
+
7752
+ def visit_signed_int_type(type)
7753
+ end
7754
+
7755
+ def visit_unsigned_type(type)
7756
+ end
7757
+
7758
+ def visit_unsigned_int_type(type)
7759
+ end
7760
+
7761
+ def visit_long_type(type)
7762
+ end
7763
+
7764
+ def visit_signed_long_type(type)
7765
+ end
7766
+
7767
+ def visit_unsigned_long_type(type)
7768
+ end
7769
+
7770
+ def visit_long_int_type(type)
7771
+ end
7772
+
7773
+ def visit_signed_long_int_type(type)
7774
+ end
7775
+
7776
+ def visit_unsigned_long_int_type(type)
7777
+ end
7778
+
7779
+ def visit_long_long_type(type)
7780
+ end
7781
+
7782
+ def visit_signed_long_long_type(type)
7783
+ end
7784
+
7785
+ def visit_unsigned_long_long_type(type)
7786
+ end
7787
+
7788
+ def visit_long_long_int_type(type)
7789
+ end
7790
+
7791
+ def visit_signed_long_long_int_type(type)
7792
+ end
7793
+
7794
+ def visit_unsigned_long_long_int_type(type)
7795
+ end
7796
+
7797
+ def visit_extended_big_int_type(type)
7798
+ end
7799
+
7800
+ def visit_bitfield_type(type)
7801
+ type.base_type.accept(self)
7802
+ end
7803
+
7804
+ def visit_enum_type(type)
7805
+ end
7806
+
7807
+ def visit_pointer_type(type)
7808
+ type.base_type.accept(self)
7809
+ end
7810
+
7811
+ def visit_float_type(type)
7812
+ end
7813
+
7814
+ def visit_double_type(type)
7815
+ end
7816
+
7817
+ def visit_long_double_type(type)
7818
+ end
7819
+
7820
+ def visit_array_type(type)
7821
+ type.base_type.accept(self)
7822
+ end
7823
+
7824
+ def visit_struct_type(type)
7825
+ type.members.each { |memb| memb.type.accept(self) }
7826
+ end
7827
+
7828
+ def visit_union_type(type)
7829
+ type.members.each { |memb| memb.type.accept(self) }
7830
+ end
7831
+
7832
+ def visit_user_type(type)
7833
+ type.real_type.accept(self)
7834
+ end
7835
+
7836
+ def visit_parameter_type(type)
7837
+ type.type.accept(self)
7838
+ end
7839
+ end
7840
+
7774
7841
  end
7775
7842
  end