adlint 2.4.6 → 2.4.10
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.
- data/ChangeLog +163 -0
- data/MANIFEST +12 -0
- data/NEWS +20 -4
- data/etc/conf.d/x86_64-ubuntu_12.04/cinit-gcc_4.6.3.erb +2 -2
- data/etc/mesg.d/c_builtin/en_US/messages.yml +1 -1
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +1 -1
- data/etc/mesg.d/core/en_US/messages.yml +1 -1
- data/etc/mesg.d/core/ja_JP/messages.yml +1 -1
- data/features/code_check/E0013.feature +0 -2
- data/features/code_check/W0001.feature +0 -2
- data/features/code_check/W0002.feature +0 -2
- data/features/code_check/W0003.feature +0 -2
- data/features/code_check/W0007.feature +0 -2
- data/features/code_check/W0010.feature +1 -3
- data/features/code_check/W0013.feature +0 -2
- data/features/code_check/W0016.feature +0 -2
- data/features/code_check/W0017.feature +0 -2
- data/features/code_check/W0025.feature +0 -2
- data/features/code_check/W0026.feature +0 -2
- data/features/code_check/W0070.feature +0 -2
- data/features/code_check/W0071.feature +0 -2
- data/features/code_check/W0093.feature +0 -2
- data/features/code_check/W0104.feature +0 -2
- data/features/code_check/W0109.feature +0 -2
- data/features/code_check/W0119.feature +0 -2
- data/features/code_check/W0120.feature +0 -2
- data/features/code_check/W0121.feature +0 -2
- data/features/code_check/W0122.feature +0 -2
- data/features/code_check/W0123.feature +0 -2
- data/features/code_check/W0124.feature +0 -2
- data/features/code_check/W0125.feature +0 -2
- data/features/code_check/W0126.feature +0 -2
- data/features/code_check/W0127.feature +0 -2
- data/features/code_check/W0128.feature +0 -2
- data/features/code_check/W0129.feature +0 -2
- data/features/code_check/W0130.feature +0 -2
- data/features/code_check/W0131.feature +0 -2
- data/features/code_check/W0132.feature +0 -2
- data/features/code_check/W0133.feature +0 -2
- data/features/code_check/W0134.feature +0 -2
- data/features/code_check/W0135.feature +0 -2
- data/features/code_check/W0136.feature +0 -2
- data/features/code_check/W0137.feature +0 -2
- data/features/code_check/W0138.feature +0 -2
- data/features/code_check/W0139.feature +0 -2
- data/features/code_check/W0140.feature +0 -2
- data/features/code_check/W0141.feature +0 -2
- data/features/code_check/W0142.feature +0 -2
- data/features/code_check/W0143.feature +0 -2
- data/features/code_check/W0144.feature +0 -2
- data/features/code_check/W0145.feature +0 -2
- data/features/code_check/W0146.feature +0 -2
- data/features/code_check/W0147.feature +0 -2
- data/features/code_check/W0148.feature +0 -2
- data/features/code_check/W0149.feature +0 -2
- data/features/code_check/W0150.feature +0 -2
- data/features/code_check/W0151.feature +0 -2
- data/features/code_check/W0152.feature +0 -2
- data/features/code_check/W0153.feature +0 -2
- data/features/code_check/W0154.feature +0 -2
- data/features/code_check/W0155.feature +0 -2
- data/features/code_check/W0156.feature +0 -2
- data/features/code_check/W0157.feature +0 -2
- data/features/code_check/W0158.feature +0 -2
- data/features/code_check/W0159.feature +0 -2
- data/features/code_check/W0160.feature +0 -2
- data/features/code_check/W0161.feature +0 -2
- data/features/code_check/W0162.feature +0 -2
- data/features/code_check/W0163.feature +0 -2
- data/features/code_check/W0164.feature +0 -2
- data/features/code_check/W0165.feature +0 -2
- data/features/code_check/W0166.feature +0 -2
- data/features/code_check/W0167.feature +0 -2
- data/features/code_check/W0168.feature +0 -2
- data/features/code_check/W0169.feature +0 -2
- data/features/code_check/W0170.feature +0 -2
- data/features/code_check/W0171.feature +0 -2
- data/features/code_check/W0172.feature +0 -2
- data/features/code_check/W0173.feature +0 -2
- data/features/code_check/W0174.feature +0 -2
- data/features/code_check/W0175.feature +0 -2
- data/features/code_check/W0176.feature +0 -2
- data/features/code_check/W0177.feature +0 -2
- data/features/code_check/W0178.feature +0 -2
- data/features/code_check/W0179.feature +0 -2
- data/features/code_check/W0180.feature +0 -2
- data/features/code_check/W0181.feature +0 -2
- data/features/code_check/W0182.feature +0 -2
- data/features/code_check/W0183.feature +0 -2
- data/features/code_check/W0184.feature +0 -2
- data/features/code_check/W0185.feature +0 -2
- data/features/code_check/W0186.feature +0 -2
- data/features/code_check/W0187.feature +0 -2
- data/features/code_check/W0188.feature +0 -2
- data/features/code_check/W0189.feature +0 -2
- data/features/code_check/W0190.feature +0 -2
- data/features/code_check/W0191.feature +0 -2
- data/features/code_check/W0192.feature +0 -2
- data/features/code_check/W0193.feature +0 -2
- data/features/code_check/W0194.feature +0 -2
- data/features/code_check/W0195.feature +0 -2
- data/features/code_check/W0196.feature +0 -2
- data/features/code_check/W0197.feature +0 -2
- data/features/code_check/W0198.feature +0 -2
- data/features/code_check/W0199.feature +0 -2
- data/features/code_check/W0200.feature +0 -2
- data/features/code_check/W0201.feature +0 -2
- data/features/code_check/W0202.feature +0 -2
- data/features/code_check/W0203.feature +0 -2
- data/features/code_check/W0204.feature +0 -2
- data/features/code_check/W0205.feature +0 -2
- data/features/code_check/W0206.feature +0 -2
- data/features/code_check/W0207.feature +0 -2
- data/features/code_check/W0208.feature +0 -2
- data/features/code_check/W0209.feature +0 -2
- data/features/code_check/W0210.feature +0 -2
- data/features/code_check/W0211.feature +0 -2
- data/features/code_check/W0212.feature +0 -2
- data/features/code_check/W0213.feature +0 -2
- data/features/code_check/W0214.feature +0 -2
- data/features/code_check/W0215.feature +0 -2
- data/features/code_check/W0216.feature +0 -2
- data/features/code_check/W0217.feature +0 -2
- data/features/code_check/W0218.feature +0 -2
- data/features/code_check/W0219.feature +0 -2
- data/features/code_check/W0220.feature +0 -2
- data/features/code_check/W0221.feature +0 -2
- data/features/code_check/W0222.feature +0 -2
- data/features/code_check/W0223.feature +0 -2
- data/features/code_check/W0224.feature +0 -2
- data/features/code_check/W0225.feature +0 -2
- data/features/code_check/W0226.feature +0 -2
- data/features/code_check/W0227.feature +0 -2
- data/features/code_check/W0228.feature +0 -2
- data/features/code_check/W0229.feature +0 -2
- data/features/code_check/W0230.feature +0 -2
- data/features/code_check/W0231.feature +0 -2
- data/features/code_check/W0232.feature +0 -2
- data/features/code_check/W0233.feature +0 -2
- data/features/code_check/W0234.feature +0 -2
- data/features/code_check/W0235.feature +0 -2
- data/features/code_check/W0236.feature +0 -2
- data/features/code_check/W0237.feature +0 -2
- data/features/code_check/W0238.feature +0 -2
- data/features/code_check/W0239.feature +0 -2
- data/features/code_check/W0240.feature +0 -2
- data/features/code_check/W0241.feature +0 -2
- data/features/code_check/W0242.feature +0 -2
- data/features/code_check/W0243.feature +0 -2
- data/features/code_check/W0244.feature +0 -2
- data/features/code_check/W0245.feature +0 -2
- data/features/code_check/W0246.feature +0 -2
- data/features/code_check/W0247.feature +0 -2
- data/features/code_check/W0248.feature +0 -2
- data/features/code_check/W0249.feature +0 -2
- data/features/code_check/W0250.feature +0 -2
- data/features/code_check/W0251.feature +0 -2
- data/features/code_check/W0252.feature +0 -2
- data/features/code_check/W0253.feature +0 -2
- data/features/code_check/W0254.feature +0 -2
- data/features/code_check/W0425.feature +0 -2
- data/features/code_check/W0431.feature +0 -2
- data/features/code_check/W0432.feature +0 -2
- data/features/code_check/W0477.feature +0 -2
- data/features/code_check/W0478.feature +0 -2
- data/features/code_check/W0479.feature +0 -2
- data/features/code_check/W0480.feature +0 -2
- data/features/code_check/W0481.feature +0 -2
- data/features/code_check/W0482.feature +0 -2
- data/features/code_check/W0483.feature +0 -2
- data/features/code_check/W0488.feature +132 -0
- data/features/code_check/W0489.feature +78 -0
- data/features/code_check/W0490.feature +83 -0
- data/features/code_check/W0495.feature +60 -0
- data/features/code_check/W0496.feature +63 -0
- data/features/code_check/W0497.feature +65 -0
- data/features/code_check/W0498.feature +120 -0
- data/features/code_check/W0499.feature +63 -0
- data/features/code_check/W0500.feature +66 -0
- data/features/code_check/W0501.feature +69 -0
- data/features/code_check/W0502.feature +64 -0
- data/features/code_check/W0573.feature +0 -2
- data/features/code_check/W0583.feature +0 -2
- data/features/code_check/W0606.feature +0 -2
- data/features/code_check/W0635.feature +0 -2
- data/features/code_check/W0641.feature +0 -2
- data/features/code_check/W0643.feature +0 -2
- data/features/code_check/W0644.feature +0 -2
- data/features/code_check/W0645.feature +0 -2
- data/features/code_check/W0646.feature +0 -2
- data/features/code_check/W0649.feature +0 -2
- data/features/code_check/W0650.feature +0 -2
- data/features/code_check/W0655.feature +43 -0
- data/features/code_check/W0685.feature +0 -2
- data/features/code_check/W0686.feature +0 -2
- data/features/code_check/W0687.feature +0 -2
- data/features/code_check/W0688.feature +0 -2
- data/features/code_check/W0689.feature +0 -2
- data/features/code_check/W0690.feature +0 -2
- data/features/code_check/W0691.feature +0 -2
- data/features/code_check/W0692.feature +0 -2
- data/features/code_check/W0694.feature +0 -2
- data/features/code_check/W0695.feature +0 -2
- data/features/code_check/W0697.feature +0 -2
- data/features/code_check/W0698.feature +0 -2
- data/features/code_check/W0699.feature +0 -2
- data/features/code_check/W0700.feature +0 -2
- data/features/code_check/W0703.feature +0 -2
- data/features/code_check/W0705.feature +6 -2
- data/features/code_check/W0707.feature +4 -2
- data/features/code_check/W0711.feature +0 -2
- data/features/code_check/W0712.feature +0 -2
- data/features/code_check/W0713.feature +0 -2
- data/features/code_check/W0714.feature +0 -2
- data/features/code_check/W0715.feature +0 -2
- data/features/code_check/W0716.feature +0 -2
- data/features/code_check/W0717.feature +0 -2
- data/features/code_check/W0718.feature +0 -2
- data/features/code_check/W0719.feature +0 -2
- data/features/code_check/W0723.feature +0 -2
- data/features/code_check/W0726.feature +0 -2
- data/features/code_check/W0732.feature +0 -2
- data/features/code_check/W0733.feature +0 -2
- data/features/code_check/W0734.feature +0 -2
- data/features/code_check/W0735.feature +0 -2
- data/features/code_check/W0745.feature +1 -2
- data/features/code_check/W0747.feature +0 -2
- data/features/code_check/W0748.feature +0 -2
- data/features/code_check/W0749.feature +0 -2
- data/features/code_check/W0750.feature +0 -2
- data/features/code_check/W0751.feature +0 -2
- data/features/code_check/W0752.feature +0 -2
- data/features/code_check/W0753.feature +0 -2
- data/features/code_check/W0754.feature +0 -2
- data/features/code_check/W0755.feature +0 -2
- data/features/code_check/W0756.feature +0 -2
- data/features/code_check/W0757.feature +0 -2
- data/features/code_check/W0758.feature +0 -2
- data/features/code_check/W0759.feature +0 -2
- data/features/code_check/W0760.feature +0 -2
- data/features/code_check/W0761.feature +0 -2
- data/features/code_check/W0762.feature +0 -2
- data/features/code_check/W0763.feature +0 -2
- data/features/code_check/W0764.feature +0 -2
- data/features/code_check/W0765.feature +0 -2
- data/features/code_check/W0766.feature +0 -2
- data/features/code_check/W0767.feature +0 -2
- data/features/code_check/W0768.feature +0 -2
- data/features/code_check/W0769.feature +0 -2
- data/features/code_check/W0780.feature +0 -2
- data/features/code_check/W0781.feature +0 -2
- data/features/code_check/W0783.feature +0 -2
- data/features/code_check/W0787.feature +0 -2
- data/features/code_check/W0792.feature +0 -2
- data/features/code_check/W0793.feature +0 -2
- data/features/code_check/W0794.feature +0 -2
- data/features/code_check/W0801.feature +0 -2
- data/features/code_check/W0805.feature +0 -2
- data/features/code_check/W0806.feature +0 -2
- data/features/code_check/W0807.feature +0 -2
- data/features/code_check/W0808.feature +0 -2
- data/features/code_check/W0809.feature +0 -2
- data/features/code_check/W0811.feature +0 -2
- data/features/code_check/W0830.feature +0 -2
- data/features/code_check/W0833.feature +0 -2
- data/features/code_check/W0834.feature +1 -3
- data/features/code_check/W1026.feature +0 -2
- data/features/code_check/W1030.feature +0 -2
- data/features/code_check/W1031.feature +0 -2
- data/features/code_check/W1039.feature +0 -2
- data/features/code_check/W1040.feature +0 -2
- data/features/code_check/W1041.feature +0 -2
- data/features/code_check/W1046.feature +0 -2
- data/features/code_check/W1047.feature +0 -2
- data/features/code_check/W1052.feature +0 -2
- data/features/code_check/W1066.feature +0 -2
- data/features/code_check/W1067.feature +0 -2
- data/features/code_check/W1068.feature +0 -2
- data/features/code_check/W1069.feature +0 -2
- data/features/code_check/W1070.feature +0 -2
- data/features/code_check/W1071.feature +0 -2
- data/features/code_check/W1072.feature +0 -2
- data/features/code_check/W1073.feature +1 -3
- data/features/code_check/W1074.feature +3 -4
- data/features/code_check/W1075.feature +0 -2
- data/features/code_check/W1076.feature +0 -2
- data/features/code_check/W1077.feature +0 -2
- data/features/code_check/W9001.feature +0 -2
- data/features/code_check/W9003.feature +3 -3
- data/lib/adlint/c/branch.rb +2 -2
- data/lib/adlint/c/environ.rb +3 -3
- data/lib/adlint/c/expr.rb +67 -39
- data/lib/adlint/c/interp.rb +10 -1
- data/lib/adlint/c/object.rb +6 -4
- data/lib/adlint/c/parser.rb +1 -1
- data/lib/adlint/c/value.rb +27 -10
- data/lib/adlint/cpp/constexpr.rb +1 -1
- data/lib/adlint/exam/c_builtin/c_check.rb +502 -420
- data/lib/adlint/version.rb +2 -2
- data/share/doc/developers_guide_ja.html +3 -3
- data/share/doc/developers_guide_ja.texi +1 -1
- data/share/doc/users_guide_en.html +10 -10
- data/share/doc/users_guide_en.texi +8 -8
- data/share/doc/users_guide_ja.html +10 -10
- data/share/doc/users_guide_ja.texi +8 -8
- metadata +15 -3
|
@@ -2782,7 +2782,7 @@ module CBuiltin #:nodoc:
|
|
|
2782
2782
|
end
|
|
2783
2783
|
|
|
2784
2784
|
class W0120 < W0119
|
|
2785
|
-
def_registrant_phase C::Prepare2Phase
|
|
2785
|
+
def_registrant_phase C::Prepare2Phase
|
|
2786
2786
|
|
|
2787
2787
|
private
|
|
2788
2788
|
def from_type
|
|
@@ -7835,6 +7835,10 @@ module CBuiltin #:nodoc:
|
|
|
7835
7835
|
class W0488 < PassiveCodeCheck
|
|
7836
7836
|
def_registrant_phase C::Prepare2Phase
|
|
7837
7837
|
|
|
7838
|
+
# NOTE: W0488 may be duplicative when problematic operators appear thrice
|
|
7839
|
+
# or more in an expression.
|
|
7840
|
+
ensure_uniqueness_of :W0488
|
|
7841
|
+
|
|
7838
7842
|
def initialize(context)
|
|
7839
7843
|
super
|
|
7840
7844
|
visitor = context[:c_visitor]
|
|
@@ -7906,11 +7910,10 @@ module CBuiltin #:nodoc:
|
|
|
7906
7910
|
def initialize(context, expression)
|
|
7907
7911
|
@context = context
|
|
7908
7912
|
@expression = expression
|
|
7909
|
-
@
|
|
7910
|
-
@
|
|
7911
|
-
@
|
|
7912
|
-
@
|
|
7913
|
-
@ungrouped_member_access_expr = 0
|
|
7913
|
+
@enclosure_expr_stack = [expression]
|
|
7914
|
+
@ary_subscript_exprs = Hash.new(0)
|
|
7915
|
+
@function_call_exprs = Hash.new(0)
|
|
7916
|
+
@member_access_exprs = Hash.new(0)
|
|
7914
7917
|
end
|
|
7915
7918
|
|
|
7916
7919
|
def execute
|
|
@@ -7918,20 +7921,20 @@ module CBuiltin #:nodoc:
|
|
|
7918
7921
|
end
|
|
7919
7922
|
|
|
7920
7923
|
def visit_grouped_expression(node)
|
|
7921
|
-
@
|
|
7924
|
+
@enclosure_expr_stack.push(node)
|
|
7922
7925
|
super
|
|
7923
|
-
@
|
|
7926
|
+
@enclosure_expr_stack.pop
|
|
7924
7927
|
end
|
|
7925
7928
|
|
|
7926
7929
|
def visit_array_subscript_expression(node)
|
|
7927
7930
|
node.expression.accept(self)
|
|
7928
|
-
@
|
|
7931
|
+
@ary_subscript_exprs[current_enclosure_expr] += 1
|
|
7929
7932
|
AmbiguousExpressionDetector.new(@context, node.array_subscript).execute
|
|
7930
7933
|
end
|
|
7931
7934
|
|
|
7932
7935
|
def visit_function_call_expression(node)
|
|
7933
7936
|
node.expression.accept(self)
|
|
7934
|
-
@
|
|
7937
|
+
@function_call_exprs[current_enclosure_expr] += 1
|
|
7935
7938
|
node.argument_expressions.each do |expr|
|
|
7936
7939
|
AmbiguousExpressionDetector.new(@context, expr).execute
|
|
7937
7940
|
end
|
|
@@ -7939,49 +7942,53 @@ module CBuiltin #:nodoc:
|
|
|
7939
7942
|
|
|
7940
7943
|
def visit_member_access_by_value_expression(node)
|
|
7941
7944
|
super
|
|
7942
|
-
@
|
|
7945
|
+
@member_access_exprs[current_enclosure_expr] += 1
|
|
7943
7946
|
end
|
|
7944
7947
|
|
|
7945
7948
|
def visit_member_access_by_pointer_expression(node)
|
|
7946
7949
|
super
|
|
7947
|
-
@
|
|
7950
|
+
@member_access_exprs[current_enclosure_expr] += 1
|
|
7948
7951
|
end
|
|
7949
7952
|
|
|
7950
7953
|
def visit_bit_access_by_value_expression(node)
|
|
7951
7954
|
super
|
|
7952
|
-
@
|
|
7955
|
+
@member_access_exprs[current_enclosure_expr] += 1
|
|
7953
7956
|
end
|
|
7954
7957
|
|
|
7955
7958
|
def visit_bit_access_by_pointer_expression(node)
|
|
7956
7959
|
super
|
|
7957
|
-
@
|
|
7960
|
+
@member_access_exprs[current_enclosure_expr] += 1
|
|
7958
7961
|
end
|
|
7959
7962
|
|
|
7960
7963
|
def visit_logical_and_expression(node)
|
|
7961
7964
|
super
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
W(:W0488, @expression.head_location)
|
|
7965
|
-
@already_warned = true
|
|
7966
|
-
end
|
|
7965
|
+
if include_ambiguous_expr?
|
|
7966
|
+
W(:W0488, current_enclosure_expr.head_location)
|
|
7967
7967
|
end
|
|
7968
7968
|
end
|
|
7969
7969
|
|
|
7970
7970
|
def visit_logical_or_expression(node)
|
|
7971
7971
|
super
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
W(:W0488, @expression.head_location)
|
|
7975
|
-
@already_warned = true
|
|
7976
|
-
end
|
|
7972
|
+
if include_ambiguous_expr?
|
|
7973
|
+
W(:W0488, current_enclosure_expr.head_location)
|
|
7977
7974
|
end
|
|
7978
7975
|
end
|
|
7979
7976
|
|
|
7977
|
+
def visit_conditional_expression(node)
|
|
7978
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
7979
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
7980
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
7981
|
+
end
|
|
7982
|
+
|
|
7980
7983
|
private
|
|
7981
7984
|
def include_ambiguous_expr?
|
|
7982
|
-
@
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
+
@ary_subscript_exprs[current_enclosure_expr] > 0 or
|
|
7986
|
+
@function_call_exprs[current_enclosure_expr] > 0 or
|
|
7987
|
+
@member_access_exprs[current_enclosure_expr] > 0
|
|
7988
|
+
end
|
|
7989
|
+
|
|
7990
|
+
def current_enclosure_expr
|
|
7991
|
+
@enclosure_expr_stack.last
|
|
7985
7992
|
end
|
|
7986
7993
|
|
|
7987
7994
|
def report
|
|
@@ -7994,6 +8001,10 @@ module CBuiltin #:nodoc:
|
|
|
7994
8001
|
class W0489 < PassiveCodeCheck
|
|
7995
8002
|
def_registrant_phase C::Prepare2Phase
|
|
7996
8003
|
|
|
8004
|
+
# NOTE: W0489 may be duplicative when operators of the same priority are
|
|
8005
|
+
# used thrice or more.
|
|
8006
|
+
ensure_uniqueness_of :W0489
|
|
8007
|
+
|
|
7997
8008
|
def initialize(context)
|
|
7998
8009
|
super
|
|
7999
8010
|
visitor = context[:c_visitor]
|
|
@@ -8065,9 +8076,8 @@ module CBuiltin #:nodoc:
|
|
|
8065
8076
|
def initialize(context, expression)
|
|
8066
8077
|
@context = context
|
|
8067
8078
|
@expression = expression
|
|
8068
|
-
@
|
|
8069
|
-
@
|
|
8070
|
-
@ungrouped_unary_expr = 0
|
|
8079
|
+
@enclosure_expr_stack = [expression]
|
|
8080
|
+
@unary_exprs = Hash.new(0)
|
|
8071
8081
|
end
|
|
8072
8082
|
|
|
8073
8083
|
def execute
|
|
@@ -8075,84 +8085,88 @@ module CBuiltin #:nodoc:
|
|
|
8075
8085
|
end
|
|
8076
8086
|
|
|
8077
8087
|
def visit_grouped_expression(node)
|
|
8078
|
-
@
|
|
8088
|
+
@enclosure_expr_stack.push(node)
|
|
8079
8089
|
super
|
|
8080
|
-
@
|
|
8090
|
+
@enclosure_expr_stack.pop
|
|
8081
8091
|
end
|
|
8082
8092
|
|
|
8083
8093
|
def visit_postfix_increment_expression(node)
|
|
8084
8094
|
super
|
|
8085
|
-
@
|
|
8095
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8086
8096
|
end
|
|
8087
8097
|
|
|
8088
8098
|
def visit_postfix_decrement_expression(node)
|
|
8089
8099
|
super
|
|
8090
|
-
@
|
|
8100
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8091
8101
|
end
|
|
8092
8102
|
|
|
8093
8103
|
def visit_prefix_increment_expression(node)
|
|
8094
8104
|
super
|
|
8095
|
-
@
|
|
8105
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8096
8106
|
end
|
|
8097
8107
|
|
|
8098
8108
|
def visit_prefix_decrement_expression(node)
|
|
8099
8109
|
super
|
|
8100
|
-
@
|
|
8110
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8101
8111
|
end
|
|
8102
8112
|
|
|
8103
8113
|
def visit_address_expression(node)
|
|
8104
8114
|
super
|
|
8105
|
-
@
|
|
8115
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8106
8116
|
end
|
|
8107
8117
|
|
|
8108
8118
|
def visit_indirection_expression(node)
|
|
8109
8119
|
super
|
|
8110
|
-
@
|
|
8120
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8111
8121
|
end
|
|
8112
8122
|
|
|
8113
8123
|
def visit_unary_arithmetic_expression(node)
|
|
8114
8124
|
super
|
|
8115
|
-
@
|
|
8125
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8116
8126
|
end
|
|
8117
8127
|
|
|
8118
8128
|
def visit_sizeof_expression(node)
|
|
8119
8129
|
super
|
|
8120
|
-
@
|
|
8130
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8121
8131
|
end
|
|
8122
8132
|
|
|
8123
8133
|
def visit_alignof_expression(node)
|
|
8124
8134
|
super
|
|
8125
|
-
@
|
|
8135
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8126
8136
|
end
|
|
8127
8137
|
|
|
8128
8138
|
def visit_cast_expression(node)
|
|
8129
8139
|
node.operand.accept(self)
|
|
8130
|
-
@
|
|
8140
|
+
@unary_exprs[current_enclosure_expr] += 1
|
|
8131
8141
|
end
|
|
8132
8142
|
|
|
8133
8143
|
def visit_logical_and_expression(node)
|
|
8134
8144
|
super
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
W(:W0489, @expression.head_location)
|
|
8138
|
-
@already_warned = true
|
|
8139
|
-
end
|
|
8145
|
+
if include_ambiguous_expr?
|
|
8146
|
+
W(:W0489, current_enclosure_expr.head_location)
|
|
8140
8147
|
end
|
|
8141
8148
|
end
|
|
8142
8149
|
|
|
8143
8150
|
def visit_logical_or_expression(node)
|
|
8144
8151
|
super
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
W(:W0489, @expression.head_location)
|
|
8148
|
-
@already_warned = true
|
|
8149
|
-
end
|
|
8152
|
+
if include_ambiguous_expr?
|
|
8153
|
+
W(:W0489, current_enclosure_expr.head_location)
|
|
8150
8154
|
end
|
|
8151
8155
|
end
|
|
8152
8156
|
|
|
8157
|
+
def visit_conditional_expression(node)
|
|
8158
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
8159
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
8160
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
8161
|
+
end
|
|
8162
|
+
|
|
8153
8163
|
private
|
|
8154
8164
|
def include_ambiguous_expr?
|
|
8155
|
-
@
|
|
8165
|
+
@unary_exprs[current_enclosure_expr] > 0
|
|
8166
|
+
end
|
|
8167
|
+
|
|
8168
|
+
def current_enclosure_expr
|
|
8169
|
+
@enclosure_expr_stack.last
|
|
8156
8170
|
end
|
|
8157
8171
|
|
|
8158
8172
|
def report
|
|
@@ -8165,6 +8179,10 @@ module CBuiltin #:nodoc:
|
|
|
8165
8179
|
class W0490 < PassiveCodeCheck
|
|
8166
8180
|
def_registrant_phase C::Prepare2Phase
|
|
8167
8181
|
|
|
8182
|
+
# NOTE: W0490 may be duplicative when problematic operators appear thrice
|
|
8183
|
+
# or more in an expression.
|
|
8184
|
+
ensure_uniqueness_of :W0490
|
|
8185
|
+
|
|
8168
8186
|
def initialize(context)
|
|
8169
8187
|
super
|
|
8170
8188
|
visitor = context[:c_visitor]
|
|
@@ -8236,10 +8254,9 @@ module CBuiltin #:nodoc:
|
|
|
8236
8254
|
def initialize(context, expression)
|
|
8237
8255
|
@context = context
|
|
8238
8256
|
@expression = expression
|
|
8239
|
-
@
|
|
8240
|
-
@
|
|
8241
|
-
@
|
|
8242
|
-
@ungrouped_logical_and_expr = 0
|
|
8257
|
+
@enclosure_expr_stack = [expression]
|
|
8258
|
+
@highprec_binary_exprs = Hash.new(0)
|
|
8259
|
+
@logical_and_exprs = Hash.new(0)
|
|
8243
8260
|
end
|
|
8244
8261
|
|
|
8245
8262
|
def execute
|
|
@@ -8247,9 +8264,9 @@ module CBuiltin #:nodoc:
|
|
|
8247
8264
|
end
|
|
8248
8265
|
|
|
8249
8266
|
def visit_grouped_expression(node)
|
|
8250
|
-
@
|
|
8267
|
+
@enclosure_expr_stack.push(node)
|
|
8251
8268
|
super
|
|
8252
|
-
@
|
|
8269
|
+
@enclosure_expr_stack.pop
|
|
8253
8270
|
end
|
|
8254
8271
|
|
|
8255
8272
|
def visit_array_subscript_expression(node)
|
|
@@ -8266,67 +8283,72 @@ module CBuiltin #:nodoc:
|
|
|
8266
8283
|
|
|
8267
8284
|
def visit_multiplicative_expression(node)
|
|
8268
8285
|
super
|
|
8269
|
-
@
|
|
8286
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8270
8287
|
end
|
|
8271
8288
|
|
|
8272
8289
|
def visit_additive_expression(node)
|
|
8273
8290
|
super
|
|
8274
|
-
@
|
|
8291
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8275
8292
|
end
|
|
8276
8293
|
|
|
8277
8294
|
def visit_shift_expression(node)
|
|
8278
8295
|
super
|
|
8279
|
-
@
|
|
8296
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8280
8297
|
end
|
|
8281
8298
|
|
|
8282
8299
|
def visit_relational_expression(node)
|
|
8283
8300
|
super
|
|
8284
|
-
@
|
|
8301
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8285
8302
|
end
|
|
8286
8303
|
|
|
8287
8304
|
def visit_equality_expression(node)
|
|
8288
8305
|
super
|
|
8289
|
-
@
|
|
8306
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8290
8307
|
end
|
|
8291
8308
|
|
|
8292
8309
|
def visit_and_expression(node)
|
|
8293
8310
|
super
|
|
8294
|
-
@
|
|
8311
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8295
8312
|
end
|
|
8296
8313
|
|
|
8297
8314
|
def visit_exclusive_or_expression(node)
|
|
8298
8315
|
super
|
|
8299
|
-
@
|
|
8316
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8300
8317
|
end
|
|
8301
8318
|
|
|
8302
8319
|
def visit_inclusive_or_expression(node)
|
|
8303
8320
|
super
|
|
8304
|
-
@
|
|
8321
|
+
@highprec_binary_exprs[current_enclosure_expr] += 1
|
|
8305
8322
|
end
|
|
8306
8323
|
|
|
8307
8324
|
def visit_logical_and_expression(node)
|
|
8308
8325
|
super
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
W(:W0490, @expression.head_location)
|
|
8314
|
-
@already_warned = true
|
|
8315
|
-
end
|
|
8326
|
+
current_enclosure = current_enclosure_expr
|
|
8327
|
+
@logical_and_exprs[current_enclosure] += 1
|
|
8328
|
+
if @highprec_binary_exprs[current_enclosure] > 0
|
|
8329
|
+
W(:W0490, current_enclosure.head_location)
|
|
8316
8330
|
end
|
|
8317
8331
|
end
|
|
8318
8332
|
|
|
8319
8333
|
def visit_logical_or_expression(node)
|
|
8320
8334
|
super
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
@already_warned = true
|
|
8325
|
-
end
|
|
8335
|
+
encl = current_enclosure_expr
|
|
8336
|
+
if @highprec_binary_exprs[encl] + @logical_and_exprs[encl] > 0
|
|
8337
|
+
W(:W0490, encl.head_location)
|
|
8326
8338
|
end
|
|
8327
8339
|
end
|
|
8328
8340
|
|
|
8341
|
+
def visit_conditional_expression(node)
|
|
8342
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
8343
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
8344
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
8345
|
+
end
|
|
8346
|
+
|
|
8329
8347
|
private
|
|
8348
|
+
def current_enclosure_expr
|
|
8349
|
+
@enclosure_expr_stack.last
|
|
8350
|
+
end
|
|
8351
|
+
|
|
8330
8352
|
def report
|
|
8331
8353
|
@context.report
|
|
8332
8354
|
end
|
|
@@ -8705,6 +8727,10 @@ module CBuiltin #:nodoc:
|
|
|
8705
8727
|
class W0495 < PassiveCodeCheck
|
|
8706
8728
|
def_registrant_phase C::Prepare2Phase
|
|
8707
8729
|
|
|
8730
|
+
# NOTE: W0495 may be duplicative when problematic operators appear thrice
|
|
8731
|
+
# or more in an expression.
|
|
8732
|
+
ensure_uniqueness_of :W0495
|
|
8733
|
+
|
|
8708
8734
|
def initialize(context)
|
|
8709
8735
|
super
|
|
8710
8736
|
visitor = context[:c_visitor]
|
|
@@ -8776,12 +8802,12 @@ module CBuiltin #:nodoc:
|
|
|
8776
8802
|
def initialize(context, expression)
|
|
8777
8803
|
@context = context
|
|
8778
8804
|
@expression = expression
|
|
8779
|
-
@
|
|
8780
|
-
@
|
|
8781
|
-
@
|
|
8782
|
-
@
|
|
8783
|
-
@
|
|
8784
|
-
@
|
|
8805
|
+
@enclosure_expr_stack = [expression]
|
|
8806
|
+
@add_exprs = Hash.new(0)
|
|
8807
|
+
@sub_exprs = Hash.new(0)
|
|
8808
|
+
@mul_exprs = Hash.new(0)
|
|
8809
|
+
@div_exprs = Hash.new(0)
|
|
8810
|
+
@mod_exprs = Hash.new(0)
|
|
8785
8811
|
end
|
|
8786
8812
|
|
|
8787
8813
|
def execute
|
|
@@ -8789,9 +8815,9 @@ module CBuiltin #:nodoc:
|
|
|
8789
8815
|
end
|
|
8790
8816
|
|
|
8791
8817
|
def visit_grouped_expression(node)
|
|
8792
|
-
@
|
|
8818
|
+
@enclosure_expr_stack.push(node)
|
|
8793
8819
|
super
|
|
8794
|
-
@
|
|
8820
|
+
@enclosure_expr_stack.pop
|
|
8795
8821
|
end
|
|
8796
8822
|
|
|
8797
8823
|
def visit_array_subscript_expression(node)
|
|
@@ -8805,51 +8831,56 @@ module CBuiltin #:nodoc:
|
|
|
8805
8831
|
end
|
|
8806
8832
|
|
|
8807
8833
|
def visit_additive_expression(node)
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
if include_ambiguous_expr?
|
|
8818
|
-
W(:W0495, @expression.head_location)
|
|
8819
|
-
else
|
|
8820
|
-
super
|
|
8834
|
+
current_enclosure = current_enclosure_expr
|
|
8835
|
+
case node.operator.type
|
|
8836
|
+
when "+"
|
|
8837
|
+
@add_exprs[current_enclosure] += 1
|
|
8838
|
+
W(:W0495, current_enclosure.head_location) if include_ambiguous_expr?
|
|
8839
|
+
when "-"
|
|
8840
|
+
@sub_exprs[current_enclosure] += 1
|
|
8841
|
+
W(:W0495, current_enclosure.head_location) if include_ambiguous_expr?
|
|
8821
8842
|
end
|
|
8843
|
+
super
|
|
8822
8844
|
end
|
|
8823
8845
|
|
|
8824
8846
|
def visit_multiplicative_expression(node)
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8847
|
+
current_enclosure = current_enclosure_expr
|
|
8848
|
+
case node.operator.type
|
|
8849
|
+
when "*"
|
|
8850
|
+
@mul_exprs[current_enclosure] += 1
|
|
8851
|
+
W(:W0495, current_enclosure.head_location) if include_ambiguous_expr?
|
|
8852
|
+
when "/"
|
|
8853
|
+
@div_exprs[current_enclosure] += 1
|
|
8854
|
+
W(:W0495, current_enclosure.head_location) if include_ambiguous_expr?
|
|
8855
|
+
when "%"
|
|
8856
|
+
@mod_exprs[current_enclosure] += 1
|
|
8857
|
+
W(:W0495, current_enclosure.head_location) if include_ambiguous_expr?
|
|
8834
8858
|
end
|
|
8859
|
+
super
|
|
8860
|
+
end
|
|
8835
8861
|
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
end
|
|
8862
|
+
def visit_conditional_expression(node)
|
|
8863
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
8864
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
8865
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
8841
8866
|
end
|
|
8842
8867
|
|
|
8843
8868
|
private
|
|
8844
8869
|
def include_ambiguous_expr?
|
|
8845
|
-
|
|
8870
|
+
enclosure = current_enclosure_expr
|
|
8871
|
+
return false if @mod_exprs[enclosure] == 0
|
|
8846
8872
|
|
|
8847
|
-
|
|
8848
|
-
@
|
|
8873
|
+
additive_exprs =
|
|
8874
|
+
@add_exprs[enclosure] + @sub_exprs[enclosure]
|
|
8875
|
+
multiplicative_exprs =
|
|
8876
|
+
@mul_exprs[enclosure] + @div_exprs[enclosure] + @mod_exprs[enclosure]
|
|
8849
8877
|
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8878
|
+
additive_exprs > 0 && multiplicative_exprs > 0 or
|
|
8879
|
+
multiplicative_exprs > 1
|
|
8880
|
+
end
|
|
8881
|
+
|
|
8882
|
+
def current_enclosure_expr
|
|
8883
|
+
@enclosure_expr_stack.last
|
|
8853
8884
|
end
|
|
8854
8885
|
|
|
8855
8886
|
def report
|
|
@@ -8862,6 +8893,10 @@ module CBuiltin #:nodoc:
|
|
|
8862
8893
|
class W0496 < PassiveCodeCheck
|
|
8863
8894
|
def_registrant_phase C::Prepare2Phase
|
|
8864
8895
|
|
|
8896
|
+
# NOTE: W0496 may be duplicative when problematic operators appear thrice
|
|
8897
|
+
# or more in an expression.
|
|
8898
|
+
ensure_uniqueness_of :W0496
|
|
8899
|
+
|
|
8865
8900
|
def initialize(context)
|
|
8866
8901
|
super
|
|
8867
8902
|
visitor = context[:c_visitor]
|
|
@@ -8935,9 +8970,8 @@ module CBuiltin #:nodoc:
|
|
|
8935
8970
|
def initialize(context, expression)
|
|
8936
8971
|
@context = context
|
|
8937
8972
|
@expression = expression
|
|
8938
|
-
@
|
|
8939
|
-
@
|
|
8940
|
-
@ungrouped_conditional_expr = 0
|
|
8973
|
+
@enclosure_expr_stack = [expression]
|
|
8974
|
+
@conditional_exprs = Hash.new(0)
|
|
8941
8975
|
end
|
|
8942
8976
|
|
|
8943
8977
|
def execute
|
|
@@ -8945,23 +8979,25 @@ module CBuiltin #:nodoc:
|
|
|
8945
8979
|
end
|
|
8946
8980
|
|
|
8947
8981
|
def visit_grouped_expression(node)
|
|
8948
|
-
@
|
|
8982
|
+
@enclosure_expr_stack.push(node)
|
|
8949
8983
|
super
|
|
8950
|
-
@
|
|
8984
|
+
@enclosure_expr_stack.pop
|
|
8951
8985
|
end
|
|
8952
8986
|
|
|
8953
8987
|
def visit_conditional_expression(node)
|
|
8954
8988
|
super
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
@already_warned = true
|
|
8959
|
-
end
|
|
8989
|
+
current_enclosure = current_enclosure_expr
|
|
8990
|
+
if @conditional_exprs[current_enclosure] > 0
|
|
8991
|
+
W(:W0496, current_enclosure.head_location)
|
|
8960
8992
|
end
|
|
8961
|
-
@
|
|
8993
|
+
@conditional_exprs[current_enclosure] += 1
|
|
8962
8994
|
end
|
|
8963
8995
|
|
|
8964
8996
|
private
|
|
8997
|
+
def current_enclosure_expr
|
|
8998
|
+
@enclosure_expr_stack.last
|
|
8999
|
+
end
|
|
9000
|
+
|
|
8965
9001
|
def report
|
|
8966
9002
|
@context.report
|
|
8967
9003
|
end
|
|
@@ -8972,6 +9008,10 @@ module CBuiltin #:nodoc:
|
|
|
8972
9008
|
class W0497 < PassiveCodeCheck
|
|
8973
9009
|
def_registrant_phase C::Prepare2Phase
|
|
8974
9010
|
|
|
9011
|
+
# NOTE: W0497 may be duplicative when problematic operators appear thrice
|
|
9012
|
+
# or more in an expression.
|
|
9013
|
+
ensure_uniqueness_of :W0497
|
|
9014
|
+
|
|
8975
9015
|
def initialize(context)
|
|
8976
9016
|
super
|
|
8977
9017
|
visitor = context[:c_visitor]
|
|
@@ -9043,15 +9083,15 @@ module CBuiltin #:nodoc:
|
|
|
9043
9083
|
def initialize(context, expression)
|
|
9044
9084
|
@context = context
|
|
9045
9085
|
@expression = expression
|
|
9046
|
-
@
|
|
9047
|
-
@
|
|
9048
|
-
@
|
|
9049
|
-
@
|
|
9050
|
-
@
|
|
9051
|
-
@
|
|
9052
|
-
@
|
|
9053
|
-
@
|
|
9054
|
-
@
|
|
9086
|
+
@enclosure_expr_stack = [expression]
|
|
9087
|
+
@shr_exprs = Hash.new(0)
|
|
9088
|
+
@shl_exprs = Hash.new(0)
|
|
9089
|
+
@lt_exprs = Hash.new(0)
|
|
9090
|
+
@gt_exprs = Hash.new(0)
|
|
9091
|
+
@le_exprs = Hash.new(0)
|
|
9092
|
+
@ge_exprs = Hash.new(0)
|
|
9093
|
+
@eq_exprs = Hash.new(0)
|
|
9094
|
+
@ne_exprs = Hash.new(0)
|
|
9055
9095
|
end
|
|
9056
9096
|
|
|
9057
9097
|
def execute
|
|
@@ -9059,9 +9099,9 @@ module CBuiltin #:nodoc:
|
|
|
9059
9099
|
end
|
|
9060
9100
|
|
|
9061
9101
|
def visit_grouped_expression(node)
|
|
9062
|
-
@
|
|
9102
|
+
@enclosure_expr_stack.push(node)
|
|
9063
9103
|
super
|
|
9064
|
-
@
|
|
9104
|
+
@enclosure_expr_stack.pop
|
|
9065
9105
|
end
|
|
9066
9106
|
|
|
9067
9107
|
def visit_array_subscript_expression(node)
|
|
@@ -9075,66 +9115,67 @@ module CBuiltin #:nodoc:
|
|
|
9075
9115
|
end
|
|
9076
9116
|
|
|
9077
9117
|
def visit_shift_expression(node)
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
if include_ambiguous_expr?
|
|
9088
|
-
W(:W0497, @expression.head_location)
|
|
9089
|
-
else
|
|
9090
|
-
super
|
|
9118
|
+
current_enclosure = current_enclosure_expr
|
|
9119
|
+
case node.operator.type
|
|
9120
|
+
when "<<"
|
|
9121
|
+
@shl_exprs[current_enclosure] += 1
|
|
9122
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9123
|
+
when ">>"
|
|
9124
|
+
@shr_exprs[current_enclosure] += 1
|
|
9125
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9091
9126
|
end
|
|
9127
|
+
super
|
|
9092
9128
|
end
|
|
9093
9129
|
|
|
9094
9130
|
def visit_relational_expression(node)
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
W(:W0497, @expression.head_location)
|
|
9110
|
-
else
|
|
9111
|
-
super
|
|
9131
|
+
current_enclosure = current_enclosure_expr
|
|
9132
|
+
case node.operator.type
|
|
9133
|
+
when "<"
|
|
9134
|
+
@lt_exprs[current_enclosure] += 1
|
|
9135
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9136
|
+
when ">"
|
|
9137
|
+
@gt_exprs[current_enclosure] += 1
|
|
9138
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9139
|
+
when "<="
|
|
9140
|
+
@le_exprs[current_enclosure] += 1
|
|
9141
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9142
|
+
when ">="
|
|
9143
|
+
@ge_exprs[current_enclosure] += 1
|
|
9144
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9112
9145
|
end
|
|
9146
|
+
super
|
|
9113
9147
|
end
|
|
9114
9148
|
|
|
9115
9149
|
def visit_equality_expression(node)
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9150
|
+
current_enclosure = current_enclosure_expr
|
|
9151
|
+
case node.operator.type
|
|
9152
|
+
when "=="
|
|
9153
|
+
@eq_exprs[current_enclosure] += 1
|
|
9154
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9155
|
+
when "!="
|
|
9156
|
+
@ne_exprs[current_enclosure] += 1
|
|
9157
|
+
W(:W0497, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9123
9158
|
end
|
|
9159
|
+
super
|
|
9160
|
+
end
|
|
9124
9161
|
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
end
|
|
9162
|
+
def visit_conditional_expression(node)
|
|
9163
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
9164
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
9165
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
9130
9166
|
end
|
|
9131
9167
|
|
|
9132
9168
|
private
|
|
9133
9169
|
def include_ambiguous_expr?
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
@
|
|
9137
|
-
@
|
|
9170
|
+
enclosure = current_enclosure_expr
|
|
9171
|
+
@shl_exprs[enclosure] > 1 || @shr_exprs[enclosure] > 1 ||
|
|
9172
|
+
@lt_exprs[enclosure] > 1 || @gt_exprs[enclosure] > 1 ||
|
|
9173
|
+
@le_exprs[enclosure] > 1 || @ge_exprs[enclosure] > 1 ||
|
|
9174
|
+
@eq_exprs[enclosure] > 1 || @ne_exprs[enclosure] > 1
|
|
9175
|
+
end
|
|
9176
|
+
|
|
9177
|
+
def current_enclosure_expr
|
|
9178
|
+
@enclosure_expr_stack.last
|
|
9138
9179
|
end
|
|
9139
9180
|
|
|
9140
9181
|
def report
|
|
@@ -9147,6 +9188,10 @@ module CBuiltin #:nodoc:
|
|
|
9147
9188
|
class W0498 < PassiveCodeCheck
|
|
9148
9189
|
def_registrant_phase C::Prepare2Phase
|
|
9149
9190
|
|
|
9191
|
+
# NOTE: W0498 may be duplicative when operators of the same priority are
|
|
9192
|
+
# used thrice or more.
|
|
9193
|
+
ensure_uniqueness_of :W0498
|
|
9194
|
+
|
|
9150
9195
|
def initialize(context)
|
|
9151
9196
|
super
|
|
9152
9197
|
visitor = context[:c_visitor]
|
|
@@ -9218,11 +9263,11 @@ module CBuiltin #:nodoc:
|
|
|
9218
9263
|
def initialize(context, expression)
|
|
9219
9264
|
@context = context
|
|
9220
9265
|
@expression = expression
|
|
9221
|
-
@
|
|
9222
|
-
@
|
|
9223
|
-
@
|
|
9224
|
-
@
|
|
9225
|
-
@
|
|
9266
|
+
@enclosure_expr_stack = [expression]
|
|
9267
|
+
@add_exprs = Hash.new(0)
|
|
9268
|
+
@sub_exprs = Hash.new(0)
|
|
9269
|
+
@mul_exprs = Hash.new(0)
|
|
9270
|
+
@div_exprs = Hash.new(0)
|
|
9226
9271
|
end
|
|
9227
9272
|
|
|
9228
9273
|
def execute
|
|
@@ -9230,9 +9275,9 @@ module CBuiltin #:nodoc:
|
|
|
9230
9275
|
end
|
|
9231
9276
|
|
|
9232
9277
|
def visit_grouped_expression(node)
|
|
9233
|
-
@
|
|
9278
|
+
@enclosure_expr_stack.push(node)
|
|
9234
9279
|
super
|
|
9235
|
-
@
|
|
9280
|
+
@enclosure_expr_stack.pop
|
|
9236
9281
|
end
|
|
9237
9282
|
|
|
9238
9283
|
def visit_array_subscript_expression(node)
|
|
@@ -9246,43 +9291,46 @@ module CBuiltin #:nodoc:
|
|
|
9246
9291
|
end
|
|
9247
9292
|
|
|
9248
9293
|
def visit_additive_expression(node)
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
if include_ambiguous_expr?
|
|
9259
|
-
W(:W0498, @expression.head_location)
|
|
9260
|
-
else
|
|
9261
|
-
super
|
|
9294
|
+
current_enclosure = current_enclosure_expr
|
|
9295
|
+
case node.operator.type
|
|
9296
|
+
when "+"
|
|
9297
|
+
@add_exprs[current_enclosure] += 1
|
|
9298
|
+
W(:W0498, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9299
|
+
when "-"
|
|
9300
|
+
@sub_exprs[current_enclosure] += 1
|
|
9301
|
+
W(:W0498, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9262
9302
|
end
|
|
9303
|
+
super
|
|
9263
9304
|
end
|
|
9264
9305
|
|
|
9265
9306
|
def visit_multiplicative_expression(node)
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9307
|
+
current_enclosure = current_enclosure_expr
|
|
9308
|
+
case node.operator.type
|
|
9309
|
+
when "*"
|
|
9310
|
+
@mul_exprs[current_enclosure] += 1
|
|
9311
|
+
W(:W0498, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9312
|
+
when "/"
|
|
9313
|
+
@div_exprs[current_enclosure] += 1
|
|
9314
|
+
W(:W0498, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9273
9315
|
end
|
|
9316
|
+
super
|
|
9317
|
+
end
|
|
9274
9318
|
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
end
|
|
9319
|
+
def visit_conditional_expression(node)
|
|
9320
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
9321
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
9322
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
9280
9323
|
end
|
|
9281
9324
|
|
|
9282
9325
|
private
|
|
9283
9326
|
def include_ambiguous_expr?
|
|
9284
|
-
|
|
9285
|
-
@
|
|
9327
|
+
enclosure = current_enclosure_expr
|
|
9328
|
+
@add_exprs[enclosure] > 0 && @sub_exprs[enclosure] > 0 or
|
|
9329
|
+
@mul_exprs[enclosure] > 0 && @div_exprs[enclosure] > 0
|
|
9330
|
+
end
|
|
9331
|
+
|
|
9332
|
+
def current_enclosure_expr
|
|
9333
|
+
@enclosure_expr_stack.last
|
|
9286
9334
|
end
|
|
9287
9335
|
|
|
9288
9336
|
def report
|
|
@@ -9295,6 +9343,10 @@ module CBuiltin #:nodoc:
|
|
|
9295
9343
|
class W0499 < PassiveCodeCheck
|
|
9296
9344
|
def_registrant_phase C::Prepare2Phase
|
|
9297
9345
|
|
|
9346
|
+
# NOTE: W0499 may be duplicative when operators of the same priority are
|
|
9347
|
+
# used thrice or more.
|
|
9348
|
+
ensure_uniqueness_of :W0499
|
|
9349
|
+
|
|
9298
9350
|
def initialize(context)
|
|
9299
9351
|
super
|
|
9300
9352
|
visitor = context[:c_visitor]
|
|
@@ -9366,15 +9418,15 @@ module CBuiltin #:nodoc:
|
|
|
9366
9418
|
def initialize(context, expression)
|
|
9367
9419
|
@context = context
|
|
9368
9420
|
@expression = expression
|
|
9369
|
-
@
|
|
9370
|
-
@
|
|
9371
|
-
@
|
|
9372
|
-
@
|
|
9373
|
-
@
|
|
9374
|
-
@
|
|
9375
|
-
@
|
|
9376
|
-
@
|
|
9377
|
-
@
|
|
9421
|
+
@enclosure_expr_stack = [expression]
|
|
9422
|
+
@shr_exprs = Hash.new(0)
|
|
9423
|
+
@shl_exprs = Hash.new(0)
|
|
9424
|
+
@lt_exprs = Hash.new(0)
|
|
9425
|
+
@gt_exprs = Hash.new(0)
|
|
9426
|
+
@le_exprs = Hash.new(0)
|
|
9427
|
+
@ge_exprs = Hash.new(0)
|
|
9428
|
+
@eq_exprs = Hash.new(0)
|
|
9429
|
+
@ne_exprs = Hash.new(0)
|
|
9378
9430
|
end
|
|
9379
9431
|
|
|
9380
9432
|
def execute
|
|
@@ -9382,9 +9434,9 @@ module CBuiltin #:nodoc:
|
|
|
9382
9434
|
end
|
|
9383
9435
|
|
|
9384
9436
|
def visit_grouped_expression(node)
|
|
9385
|
-
@
|
|
9437
|
+
@enclosure_expr_stack.push(node)
|
|
9386
9438
|
super
|
|
9387
|
-
@
|
|
9439
|
+
@enclosure_expr_stack.pop
|
|
9388
9440
|
end
|
|
9389
9441
|
|
|
9390
9442
|
def visit_array_subscript_expression(node)
|
|
@@ -9398,72 +9450,77 @@ module CBuiltin #:nodoc:
|
|
|
9398
9450
|
end
|
|
9399
9451
|
|
|
9400
9452
|
def visit_shift_expression(node)
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
if include_ambiguous_expr?
|
|
9411
|
-
W(:W0499, @expression.head_location)
|
|
9412
|
-
else
|
|
9413
|
-
super
|
|
9453
|
+
current_enclosure = current_enclosure_expr
|
|
9454
|
+
case node.operator.type
|
|
9455
|
+
when "<<"
|
|
9456
|
+
@shl_exprs[current_enclosure] += 1
|
|
9457
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9458
|
+
when ">>"
|
|
9459
|
+
@shr_exprs[current_enclosure] += 1
|
|
9460
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9414
9461
|
end
|
|
9462
|
+
super
|
|
9415
9463
|
end
|
|
9416
9464
|
|
|
9417
9465
|
def visit_relational_expression(node)
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
W(:W0499, @expression.head_location)
|
|
9433
|
-
else
|
|
9434
|
-
super
|
|
9466
|
+
current_enclosure = current_enclosure_expr
|
|
9467
|
+
case node.operator.type
|
|
9468
|
+
when "<"
|
|
9469
|
+
@lt_exprs[current_enclosure] += 1
|
|
9470
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9471
|
+
when ">"
|
|
9472
|
+
@gt_exprs[current_enclosure] += 1
|
|
9473
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9474
|
+
when "<="
|
|
9475
|
+
@le_exprs[current_enclosure] += 1
|
|
9476
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9477
|
+
when ">="
|
|
9478
|
+
@ge_exprs[current_enclosure] += 1
|
|
9479
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9435
9480
|
end
|
|
9481
|
+
super
|
|
9436
9482
|
end
|
|
9437
9483
|
|
|
9438
9484
|
def visit_equality_expression(node)
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9485
|
+
current_enclosure = current_enclosure_expr
|
|
9486
|
+
case node.operator.type
|
|
9487
|
+
when "=="
|
|
9488
|
+
@eq_exprs[current_enclosure] += 1
|
|
9489
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9490
|
+
when "!="
|
|
9491
|
+
@ne_exprs[current_enclosure] += 1
|
|
9492
|
+
W(:W0499, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9446
9493
|
end
|
|
9494
|
+
super
|
|
9495
|
+
end
|
|
9447
9496
|
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
end
|
|
9497
|
+
def visit_conditional_expression(node)
|
|
9498
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
9499
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
9500
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
9453
9501
|
end
|
|
9454
9502
|
|
|
9455
9503
|
private
|
|
9456
9504
|
def include_ambiguous_expr?
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9505
|
+
shl_expr_num = @shl_exprs[current_enclosure_expr]
|
|
9506
|
+
shr_expr_num = @shr_exprs[current_enclosure_expr]
|
|
9507
|
+
lt_expr_num = @lt_exprs[current_enclosure_expr]
|
|
9508
|
+
gt_expr_num = @gt_exprs[current_enclosure_expr]
|
|
9509
|
+
le_expr_num = @le_exprs[current_enclosure_expr]
|
|
9510
|
+
ge_expr_num = @ge_exprs[current_enclosure_expr]
|
|
9511
|
+
eq_expr_num = @eq_exprs[current_enclosure_expr]
|
|
9512
|
+
ne_expr_num = @ne_exprs[current_enclosure_expr]
|
|
9513
|
+
|
|
9514
|
+
shl_expr_num > 0 && shr_expr_num > 0 or
|
|
9515
|
+
lt_expr_num > 0 && (gt_expr_num + le_expr_num + ge_expr_num) > 0 or
|
|
9516
|
+
gt_expr_num > 0 && (lt_expr_num + le_expr_num + ge_expr_num) > 0 or
|
|
9517
|
+
le_expr_num > 0 && (lt_expr_num + gt_expr_num + ge_expr_num) > 0 or
|
|
9518
|
+
ge_expr_num > 0 && (lt_expr_num + gt_expr_num + le_expr_num) > 0 or
|
|
9519
|
+
eq_expr_num > 0 && ne_expr_num > 0
|
|
9520
|
+
end
|
|
9521
|
+
|
|
9522
|
+
def current_enclosure_expr
|
|
9523
|
+
@enclosure_expr_stack.last
|
|
9467
9524
|
end
|
|
9468
9525
|
|
|
9469
9526
|
def report
|
|
@@ -9476,6 +9533,10 @@ module CBuiltin #:nodoc:
|
|
|
9476
9533
|
class W0500 < PassiveCodeCheck
|
|
9477
9534
|
def_registrant_phase C::Prepare2Phase
|
|
9478
9535
|
|
|
9536
|
+
# NOTE: W0500 may be duplicative when operators of the different priority
|
|
9537
|
+
# are used thrice or more.
|
|
9538
|
+
ensure_uniqueness_of :W0500
|
|
9539
|
+
|
|
9479
9540
|
def initialize(context)
|
|
9480
9541
|
super
|
|
9481
9542
|
visitor = context[:c_visitor]
|
|
@@ -9547,11 +9608,11 @@ module CBuiltin #:nodoc:
|
|
|
9547
9608
|
def initialize(context, expression)
|
|
9548
9609
|
@context = context
|
|
9549
9610
|
@expression = expression
|
|
9550
|
-
@
|
|
9551
|
-
@
|
|
9552
|
-
@
|
|
9553
|
-
@
|
|
9554
|
-
@
|
|
9611
|
+
@enclosure_expr_stack = [expression]
|
|
9612
|
+
@add_exprs = Hash.new(0)
|
|
9613
|
+
@sub_exprs = Hash.new(0)
|
|
9614
|
+
@mul_exprs = Hash.new(0)
|
|
9615
|
+
@div_exprs = Hash.new(0)
|
|
9555
9616
|
end
|
|
9556
9617
|
|
|
9557
9618
|
def execute
|
|
@@ -9559,15 +9620,9 @@ module CBuiltin #:nodoc:
|
|
|
9559
9620
|
end
|
|
9560
9621
|
|
|
9561
9622
|
def visit_grouped_expression(node)
|
|
9562
|
-
@
|
|
9623
|
+
@enclosure_expr_stack.push(node)
|
|
9563
9624
|
super
|
|
9564
|
-
@
|
|
9565
|
-
end
|
|
9566
|
-
|
|
9567
|
-
def visit_conditional_expression(node)
|
|
9568
|
-
@group_depth += 1
|
|
9569
|
-
super
|
|
9570
|
-
@group_depth -= 1
|
|
9625
|
+
@enclosure_expr_stack.pop
|
|
9571
9626
|
end
|
|
9572
9627
|
|
|
9573
9628
|
def visit_array_subscript_expression(node)
|
|
@@ -9581,43 +9636,46 @@ module CBuiltin #:nodoc:
|
|
|
9581
9636
|
end
|
|
9582
9637
|
|
|
9583
9638
|
def visit_multiplicative_expression(node)
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
if include_ambiguous_expr?
|
|
9594
|
-
W(:W0500, @expression.head_location)
|
|
9595
|
-
else
|
|
9596
|
-
super
|
|
9639
|
+
current_enclosure = current_enclosure_expr
|
|
9640
|
+
case node.operator.type
|
|
9641
|
+
when "*"
|
|
9642
|
+
@mul_exprs[current_enclosure] += 1
|
|
9643
|
+
W(:W0500, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9644
|
+
when "/"
|
|
9645
|
+
@div_exprs[current_enclosure] += 1
|
|
9646
|
+
W(:W0500, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9597
9647
|
end
|
|
9648
|
+
super
|
|
9598
9649
|
end
|
|
9599
9650
|
|
|
9600
9651
|
def visit_additive_expression(node)
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9652
|
+
current_enclosure = current_enclosure_expr
|
|
9653
|
+
case node.operator.type
|
|
9654
|
+
when "+"
|
|
9655
|
+
@add_exprs[current_enclosure] += 1
|
|
9656
|
+
W(:W0500, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9657
|
+
when "-"
|
|
9658
|
+
@sub_exprs[current_enclosure] += 1
|
|
9659
|
+
W(:W0500, current_enclosure.head_location) if include_ambiguous_expr?
|
|
9608
9660
|
end
|
|
9661
|
+
super
|
|
9662
|
+
end
|
|
9609
9663
|
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
end
|
|
9664
|
+
def visit_conditional_expression(node)
|
|
9665
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
9666
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
9667
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
9615
9668
|
end
|
|
9616
9669
|
|
|
9617
9670
|
private
|
|
9618
9671
|
def include_ambiguous_expr?
|
|
9619
|
-
|
|
9620
|
-
|
|
9672
|
+
current_enclosure = current_enclosure_expr
|
|
9673
|
+
(@add_exprs[current_enclosure] + @sub_exprs[current_enclosure]) > 0 &&
|
|
9674
|
+
(@mul_exprs[current_enclosure] + @div_exprs[current_enclosure]) > 0
|
|
9675
|
+
end
|
|
9676
|
+
|
|
9677
|
+
def current_enclosure_expr
|
|
9678
|
+
@enclosure_expr_stack.last
|
|
9621
9679
|
end
|
|
9622
9680
|
|
|
9623
9681
|
def report
|
|
@@ -9630,6 +9688,10 @@ module CBuiltin #:nodoc:
|
|
|
9630
9688
|
class W0501 < PassiveCodeCheck
|
|
9631
9689
|
def_registrant_phase C::Prepare2Phase
|
|
9632
9690
|
|
|
9691
|
+
# NOTE: W0501 may be duplicative when problematic operators appear thrice
|
|
9692
|
+
# or more in an expression.
|
|
9693
|
+
ensure_uniqueness_of :W0501
|
|
9694
|
+
|
|
9633
9695
|
def initialize(context)
|
|
9634
9696
|
super
|
|
9635
9697
|
visitor = context[:c_visitor]
|
|
@@ -9703,7 +9765,6 @@ module CBuiltin #:nodoc:
|
|
|
9703
9765
|
def initialize(context, expression)
|
|
9704
9766
|
@context = context
|
|
9705
9767
|
@expression = expression
|
|
9706
|
-
@already_warned = false
|
|
9707
9768
|
@group_depth = 0
|
|
9708
9769
|
@ungrouped_binary_expr = 0
|
|
9709
9770
|
end
|
|
@@ -9781,12 +9842,7 @@ module CBuiltin #:nodoc:
|
|
|
9781
9842
|
private
|
|
9782
9843
|
def check_binary_expression
|
|
9783
9844
|
@ungrouped_binary_expr += 1 if @group_depth == 0
|
|
9784
|
-
|
|
9785
|
-
if include_ambiguous_expr?
|
|
9786
|
-
W(:W0501, @expression.head_location)
|
|
9787
|
-
@already_warned = true
|
|
9788
|
-
end
|
|
9789
|
-
end
|
|
9845
|
+
W(:W0501, @expression.location) if include_ambiguous_expr?
|
|
9790
9846
|
end
|
|
9791
9847
|
|
|
9792
9848
|
def include_ambiguous_expr?
|
|
@@ -9803,6 +9859,10 @@ module CBuiltin #:nodoc:
|
|
|
9803
9859
|
class W0502 < PassiveCodeCheck
|
|
9804
9860
|
def_registrant_phase C::Prepare2Phase
|
|
9805
9861
|
|
|
9862
|
+
# NOTE: W0502 may be duplicative when operators of the different priority
|
|
9863
|
+
# are used thrice or more.
|
|
9864
|
+
ensure_uniqueness_of :W0502
|
|
9865
|
+
|
|
9806
9866
|
def initialize(context)
|
|
9807
9867
|
super
|
|
9808
9868
|
visitor = context[:c_visitor]
|
|
@@ -9874,18 +9934,17 @@ module CBuiltin #:nodoc:
|
|
|
9874
9934
|
def initialize(context, expression)
|
|
9875
9935
|
@context = context
|
|
9876
9936
|
@expression = expression
|
|
9877
|
-
@
|
|
9878
|
-
@
|
|
9879
|
-
@
|
|
9880
|
-
@
|
|
9881
|
-
@
|
|
9882
|
-
@
|
|
9883
|
-
@
|
|
9884
|
-
@
|
|
9885
|
-
@
|
|
9886
|
-
@
|
|
9887
|
-
@
|
|
9888
|
-
@ungrouped_logical_or_expr = 0
|
|
9937
|
+
@enclosure_expr_stack = [expression]
|
|
9938
|
+
@multiplicative_exprs = Hash.new(0)
|
|
9939
|
+
@additive_exprs = Hash.new(0)
|
|
9940
|
+
@shift_exprs = Hash.new(0)
|
|
9941
|
+
@relational_exprs = Hash.new(0)
|
|
9942
|
+
@equality_exprs = Hash.new(0)
|
|
9943
|
+
@and_exprs = Hash.new(0)
|
|
9944
|
+
@xor_exprs = Hash.new(0)
|
|
9945
|
+
@or_exprs = Hash.new(0)
|
|
9946
|
+
@logical_and_exprs = Hash.new(0)
|
|
9947
|
+
@logical_or_exprs = Hash.new(0)
|
|
9889
9948
|
end
|
|
9890
9949
|
|
|
9891
9950
|
def execute
|
|
@@ -9893,134 +9952,157 @@ module CBuiltin #:nodoc:
|
|
|
9893
9952
|
end
|
|
9894
9953
|
|
|
9895
9954
|
def visit_grouped_expression(node)
|
|
9896
|
-
@
|
|
9955
|
+
@enclosure_expr_stack.push(node)
|
|
9897
9956
|
super
|
|
9898
|
-
@
|
|
9957
|
+
@enclosure_expr_stack.pop
|
|
9958
|
+
end
|
|
9959
|
+
|
|
9960
|
+
def visit_array_subscript_expression(node)
|
|
9961
|
+
AmbiguousExpressionDetector.new(@context, node.array_subscript).execute
|
|
9962
|
+
end
|
|
9963
|
+
|
|
9964
|
+
def visit_function_call_expression(node)
|
|
9965
|
+
node.argument_expressions.each do |expr|
|
|
9966
|
+
AmbiguousExpressionDetector.new(@context, expr).execute
|
|
9967
|
+
end
|
|
9899
9968
|
end
|
|
9900
9969
|
|
|
9901
9970
|
def visit_multiplicative_expression(node)
|
|
9902
9971
|
super
|
|
9903
|
-
@
|
|
9972
|
+
@multiplicative_exprs[current_enclosure_expr] += 1
|
|
9904
9973
|
end
|
|
9905
9974
|
|
|
9906
9975
|
def visit_additive_expression(node)
|
|
9907
9976
|
super
|
|
9908
|
-
@
|
|
9977
|
+
@additive_exprs[current_enclosure_expr] += 1
|
|
9909
9978
|
end
|
|
9910
9979
|
|
|
9911
9980
|
def visit_shift_expression(node)
|
|
9912
9981
|
super
|
|
9913
|
-
@
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
if @ungrouped_multiplicative_expr + @ungrouped_additive_expr > 0
|
|
9917
|
-
W(:W0502, @expression.head_location)
|
|
9918
|
-
@already_warned = true
|
|
9919
|
-
end
|
|
9982
|
+
@shift_exprs[current_enclosure_expr] += 1
|
|
9983
|
+
if current_multiplicative_exprs + current_additive_exprs > 0
|
|
9984
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
9920
9985
|
end
|
|
9921
9986
|
end
|
|
9922
9987
|
|
|
9923
9988
|
def visit_relational_expression(node)
|
|
9924
9989
|
super
|
|
9925
|
-
@
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
@ungrouped_shift_expr > 0
|
|
9930
|
-
W(:W0502, @expression.head_location)
|
|
9931
|
-
@already_warned = true
|
|
9932
|
-
end
|
|
9990
|
+
@relational_exprs[current_enclosure_expr] += 1
|
|
9991
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
9992
|
+
current_shift_exprs > 0
|
|
9993
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
9933
9994
|
end
|
|
9934
9995
|
end
|
|
9935
9996
|
|
|
9936
9997
|
def visit_equality_expression(node)
|
|
9937
9998
|
super
|
|
9938
|
-
@
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
@ungrouped_shift_expr + @ungrouped_relational_expr > 0
|
|
9943
|
-
W(:W0502, @expression.head_location)
|
|
9944
|
-
@already_warned = true
|
|
9945
|
-
end
|
|
9999
|
+
@equality_exprs[current_enclosure_expr] += 1
|
|
10000
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
10001
|
+
current_shift_exprs + current_relational_exprs > 0
|
|
10002
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
9946
10003
|
end
|
|
9947
10004
|
end
|
|
9948
10005
|
|
|
9949
10006
|
def visit_and_expression(node)
|
|
9950
10007
|
super
|
|
9951
|
-
@
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
@ungrouped_equality_expr > 0
|
|
9957
|
-
W(:W0502, @expression.head_location)
|
|
9958
|
-
@already_warned = true
|
|
9959
|
-
end
|
|
10008
|
+
@and_exprs[current_enclosure_expr] += 1
|
|
10009
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
10010
|
+
current_shift_exprs + current_relational_exprs +
|
|
10011
|
+
current_equality_exprs > 0
|
|
10012
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
9960
10013
|
end
|
|
9961
10014
|
end
|
|
9962
10015
|
|
|
9963
10016
|
def visit_exclusive_or_expression(node)
|
|
9964
10017
|
super
|
|
9965
|
-
@
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
@ungrouped_equality_expr + @ungrouped_and_expr > 0
|
|
9971
|
-
W(:W0502, @expression.head_location)
|
|
9972
|
-
@already_warned = true
|
|
9973
|
-
end
|
|
10018
|
+
@xor_exprs[current_enclosure_expr] += 1
|
|
10019
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
10020
|
+
current_shift_exprs + current_relational_exprs +
|
|
10021
|
+
current_equality_exprs + current_and_exprs > 0
|
|
10022
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
9974
10023
|
end
|
|
9975
10024
|
end
|
|
9976
10025
|
|
|
9977
10026
|
def visit_inclusive_or_expression(node)
|
|
9978
10027
|
super
|
|
9979
|
-
@
|
|
9980
|
-
|
|
9981
|
-
|
|
9982
|
-
|
|
9983
|
-
|
|
9984
|
-
@ungrouped_equality_expr + @ungrouped_and_expr +
|
|
9985
|
-
@ungrouped_xor_expr > 0
|
|
9986
|
-
W(:W0502, @expression.head_location)
|
|
9987
|
-
@already_warned = true
|
|
9988
|
-
end
|
|
10028
|
+
@or_exprs[current_enclosure_expr] += 1
|
|
10029
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
10030
|
+
current_shift_exprs + current_relational_exprs +
|
|
10031
|
+
current_equality_exprs + current_and_exprs + current_xor_exprs > 0
|
|
10032
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
9989
10033
|
end
|
|
9990
10034
|
end
|
|
9991
10035
|
|
|
9992
10036
|
def visit_logical_and_expression(node)
|
|
9993
10037
|
super
|
|
9994
|
-
@
|
|
9995
|
-
|
|
9996
|
-
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
@ungrouped_xor_expr + @ungrouped_or_expr > 0
|
|
10001
|
-
W(:W0502, @expression.head_location)
|
|
10002
|
-
@already_warned = true
|
|
10003
|
-
end
|
|
10038
|
+
@logical_and_exprs[current_enclosure_expr] += 1
|
|
10039
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
10040
|
+
current_shift_exprs + current_relational_exprs +
|
|
10041
|
+
current_equality_exprs + current_and_exprs +
|
|
10042
|
+
current_xor_exprs + current_or_exprs > 0
|
|
10043
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
10004
10044
|
end
|
|
10005
10045
|
end
|
|
10006
10046
|
|
|
10007
10047
|
def visit_logical_or_expression(node)
|
|
10008
10048
|
super
|
|
10009
|
-
@
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
@ungrouped_logical_and_expr > 0
|
|
10017
|
-
W(:W0502, @expression.head_location)
|
|
10018
|
-
@already_warned = true
|
|
10019
|
-
end
|
|
10049
|
+
@logical_or_exprs[current_enclosure_expr] += 1
|
|
10050
|
+
if current_multiplicative_exprs + current_additive_exprs +
|
|
10051
|
+
current_shift_exprs + current_relational_exprs +
|
|
10052
|
+
current_equality_exprs + current_and_exprs +
|
|
10053
|
+
current_xor_exprs + current_or_exprs +
|
|
10054
|
+
current_logical_and_exprs > 0
|
|
10055
|
+
W(:W0502, current_enclosure_expr.head_location)
|
|
10020
10056
|
end
|
|
10021
10057
|
end
|
|
10022
10058
|
|
|
10059
|
+
def visit_conditional_expression(node)
|
|
10060
|
+
AmbiguousExpressionDetector.new(@context, node.condition).execute
|
|
10061
|
+
AmbiguousExpressionDetector.new(@context, node.then_expression).execute
|
|
10062
|
+
AmbiguousExpressionDetector.new(@context, node.else_expression).execute
|
|
10063
|
+
end
|
|
10064
|
+
|
|
10023
10065
|
private
|
|
10066
|
+
def current_multiplicative_exprs
|
|
10067
|
+
@multiplicative_exprs[current_enclosure_expr]
|
|
10068
|
+
end
|
|
10069
|
+
|
|
10070
|
+
def current_additive_exprs
|
|
10071
|
+
@additive_exprs[current_enclosure_expr]
|
|
10072
|
+
end
|
|
10073
|
+
|
|
10074
|
+
def current_shift_exprs
|
|
10075
|
+
@shift_exprs[current_enclosure_expr]
|
|
10076
|
+
end
|
|
10077
|
+
|
|
10078
|
+
def current_relational_exprs
|
|
10079
|
+
@relational_exprs[current_enclosure_expr]
|
|
10080
|
+
end
|
|
10081
|
+
|
|
10082
|
+
def current_equality_exprs
|
|
10083
|
+
@equality_exprs[current_enclosure_expr]
|
|
10084
|
+
end
|
|
10085
|
+
|
|
10086
|
+
def current_and_exprs
|
|
10087
|
+
@and_exprs[current_enclosure_expr]
|
|
10088
|
+
end
|
|
10089
|
+
|
|
10090
|
+
def current_xor_exprs
|
|
10091
|
+
@xor_exprs[current_enclosure_expr]
|
|
10092
|
+
end
|
|
10093
|
+
|
|
10094
|
+
def current_or_exprs
|
|
10095
|
+
@or_exprs[current_enclosure_expr]
|
|
10096
|
+
end
|
|
10097
|
+
|
|
10098
|
+
def current_logical_and_exprs
|
|
10099
|
+
@logical_and_exprs[current_enclosure_expr]
|
|
10100
|
+
end
|
|
10101
|
+
|
|
10102
|
+
def current_enclosure_expr
|
|
10103
|
+
@enclosure_expr_stack.last
|
|
10104
|
+
end
|
|
10105
|
+
|
|
10024
10106
|
def report
|
|
10025
10107
|
@context.report
|
|
10026
10108
|
end
|