adlint 1.10.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/ChangeLog +197 -4
  2. data/MANIFEST +17 -0
  3. data/NEWS +23 -4
  4. data/etc/mesg.d/en_US/messages.yml +14 -1
  5. data/etc/mesg.d/ja_JP/messages.yml +14 -1
  6. data/features/message_detection/W0093.feature +87 -0
  7. data/features/message_detection/W0687.feature +25 -0
  8. data/features/message_detection/W0688.feature +63 -0
  9. data/features/message_detection/W0689.feature +46 -0
  10. data/features/message_detection/W0690.feature +35 -0
  11. data/features/message_detection/W0698.feature +3 -2
  12. data/features/message_detection/W0703.feature +1 -0
  13. data/features/message_detection/W0723.feature +34 -0
  14. data/features/message_detection/W0732.feature +158 -0
  15. data/features/message_detection/W0733.feature +158 -0
  16. data/features/message_detection/W0734.feature +322 -0
  17. data/features/message_detection/W0735.feature +322 -0
  18. data/features/message_detection/W1052.feature +66 -0
  19. data/features/message_detection/W9001.feature +33 -0
  20. data/features/message_detection/W9003.feature +131 -0
  21. data/lib/adlint/c/ctrlexpr.rb +51 -50
  22. data/lib/adlint/c/domain.rb +237 -223
  23. data/lib/adlint/c/expr.rb +6 -8
  24. data/lib/adlint/c/interp.rb +8 -11
  25. data/lib/adlint/c/message.rb +20 -0
  26. data/lib/adlint/c/message_shima.rb +63 -0
  27. data/lib/adlint/c/object.rb +5 -4
  28. data/lib/adlint/c/operator.rb +99 -0
  29. data/lib/adlint/c/parser.rb +2 -2
  30. data/lib/adlint/c/parser.y +2 -2
  31. data/lib/adlint/c/phase.rb +6 -1
  32. data/lib/adlint/c/syntax.rb +442 -30
  33. data/lib/adlint/c/type.rb +449 -363
  34. data/lib/adlint/c/value.rb +96 -25
  35. data/lib/adlint/c.rb +1 -0
  36. data/lib/adlint/prelude.rb +16 -18
  37. data/lib/adlint/version.rb +2 -2
  38. data/share/doc/developers_guide_ja.html +11 -5
  39. data/share/doc/developers_guide_ja.texi +9 -3
  40. data/share/doc/users_guide_en.html +697 -131
  41. data/share/doc/users_guide_en.texi +491 -41
  42. data/share/doc/users_guide_ja.html +709 -139
  43. data/share/doc/users_guide_ja.texi +499 -45
  44. data/spec/adlint/c/ctrlexpr_spec.rb +168 -0
  45. data/spec/adlint/c/domain_spec.rb +835 -0
  46. data/spec/adlint/c/operator_spec.rb +406 -0
  47. data/spec/adlint/c/syntax_spec.rb +717 -0
  48. data/spec/adlint/c/type_spec.rb +55 -30
  49. metadata +19 -2
@@ -34,6 +34,7 @@ require "adlint/c/object"
34
34
  require "adlint/c/mediator"
35
35
  require "adlint/c/expr"
36
36
  require "adlint/c/conv"
37
+ require "adlint/c/operator"
37
38
 
38
39
  module AdLint #:nodoc:
39
40
  module C #:nodoc:
@@ -569,7 +570,7 @@ module C #:nodoc:
569
570
  private
570
571
  def commit_changes(narrowing)
571
572
  narrowing.narrowed_values.each do |variable, narrowed_value|
572
- variable.narrow_value_domain!(:==, narrowed_value)
573
+ variable.narrow_value_domain!(Operator::EQ, narrowed_value)
573
574
  end
574
575
  end
575
576
  end
@@ -578,7 +579,7 @@ module C #:nodoc:
578
579
  private
579
580
  def commit_changes(narrowing)
580
581
  narrowing.narrowed_values.each do |variable, narrowed_value|
581
- variable.widen_value_domain!(:==, narrowed_value)
582
+ variable.widen_value_domain!(Operator::EQ, narrowed_value)
582
583
  end
583
584
  end
584
585
  end
@@ -596,7 +597,8 @@ module C #:nodoc:
596
597
  private
597
598
  def commit_changes(narrowing)
598
599
  @branch_group.all_controlling_variables.each do |variable|
599
- variable.narrow_value_domain!(:==, variable.type.arbitrary_value)
600
+ variable.narrow_value_domain!(Operator::EQ,
601
+ variable.type.arbitrary_value)
600
602
  end
601
603
  true
602
604
  end
@@ -615,7 +617,8 @@ module C #:nodoc:
615
617
  private
616
618
  def commit_changes(narrowing)
617
619
  @branch_group.all_controlling_variables.each do |variable|
618
- variable.widen_value_domain!(:==, variable.type.arbitrary_value)
620
+ variable.widen_value_domain!(Operator::EQ,
621
+ variable.type.arbitrary_value)
619
622
  end
620
623
  true
621
624
  end
@@ -658,7 +661,7 @@ module C #:nodoc:
658
661
  def ensure_result_equal_to(value)
659
662
  if @result.variable? && @result.designated_by_lvalue?
660
663
  if @result.value.scalar? && value.scalar?
661
- ensure_relation(@result, :==, value)
664
+ ensure_relation(@result, Operator::EQ, value)
662
665
  end
663
666
  end
664
667
  end
@@ -688,10 +691,14 @@ module C #:nodoc:
688
691
  return lhs_result, rhs_result
689
692
  end
690
693
 
691
- def ensure_relation(variable, operator_symbol, value)
692
- target_value = save_original_value(variable).dup
693
- target_value.narrow_domain!(operator_symbol, value)
694
- update_narrowed_value(variable, target_value)
694
+ def ensure_relation(variable, operator, value)
695
+ # NOTE: To avoid over-narrowing.
696
+ if value.definite? or
697
+ variable.value.contain?(value) && !value.contain?(variable.value)
698
+ target_value = save_original_value(variable).dup
699
+ target_value.narrow_domain!(operator, value)
700
+ update_narrowed_value(variable, target_value)
701
+ end
695
702
  end
696
703
 
697
704
  def save_original_value(variable)
@@ -712,7 +719,7 @@ module C #:nodoc:
712
719
 
713
720
  @narrowed_values = lhs_values.merge(rhs_values) { |key, lhs_val, rhs_val|
714
721
  result = lhs_val.dup
715
- result.narrow_domain!(:==, rhs_val)
722
+ result.narrow_domain!(Operator::EQ, rhs_val)
716
723
  result
717
724
  }
718
725
  end
@@ -723,7 +730,7 @@ module C #:nodoc:
723
730
 
724
731
  @narrowed_values = lhs_values.merge(rhs_values) { |key, lhs_val, rhs_val|
725
732
  result = lhs_val.dup
726
- result.widen_domain!(:==, rhs_val)
733
+ result.widen_domain!(Operator::EQ, rhs_val)
727
734
  result
728
735
  }
729
736
  end
@@ -739,7 +746,7 @@ module C #:nodoc:
739
746
  class ValueComparison < ValueDomainNarrowing
740
747
  def initialize(value_domain_manip, node, lhs_narrowing, rhs_narrowing)
741
748
  super
742
- @operator_symbol = node.operator.type.to_sym
749
+ @operator = ComparisonOperator.new(node.operator)
743
750
  @lhs_narrowing = lhs_narrowing
744
751
  @rhs_narrowing = rhs_narrowing
745
752
  end
@@ -747,59 +754,53 @@ module C #:nodoc:
747
754
  private
748
755
  def do_narrowing
749
756
  @lhs_narrowing.execute!
750
- lhs_variable = object_to_variable(@lhs_narrowing.result)
757
+ lhs_var = object_to_variable(@lhs_narrowing.result)
751
758
 
752
759
  @rhs_narrowing.execute!
753
- rhs_variable = object_to_variable(@rhs_narrowing.result)
760
+ rhs_var = object_to_variable(@rhs_narrowing.result)
754
761
 
755
- unless lhs_variable.type.scalar? && rhs_variable.type.scalar?
762
+ unless lhs_var.type.scalar? && rhs_var.type.scalar?
756
763
  return temporary_variable(int_type)
757
764
  end
758
765
 
759
- unless lhs_variable.value.scalar? && rhs_variable.value.scalar?
766
+ unless lhs_var.value.scalar? && rhs_var.value.scalar?
760
767
  return temporary_variable(int_type)
761
768
  end
762
769
 
763
- lhs_converted, rhs_converted =
764
- do_logical_arithmetic_conversion(@node, lhs_variable, rhs_variable)
765
-
766
- case @operator_symbol
767
- when :==
768
- result = temporary_variable(int_type,
769
- lhs_converted.value == rhs_converted.value)
770
- when :!=
771
- result = temporary_variable(int_type,
772
- lhs_converted.value != rhs_converted.value)
773
- when :<
774
- result = temporary_variable(int_type,
775
- lhs_converted.value < rhs_converted.value)
776
- when :>
777
- result = temporary_variable(int_type,
778
- lhs_converted.value > rhs_converted.value)
779
- when :<=
780
- result = temporary_variable(int_type,
781
- lhs_converted.value <= rhs_converted.value)
782
- when :>=
783
- result = temporary_variable(int_type,
784
- lhs_converted.value >= rhs_converted.value)
770
+ lhs_conv, rhs_conv =
771
+ do_logical_arithmetic_conversion(@node, lhs_var, rhs_var)
772
+
773
+ case @operator
774
+ when Operator::EQ
775
+ result = temporary_variable(int_type, lhs_conv.value == rhs_conv.value)
776
+ when Operator::NE
777
+ result = temporary_variable(int_type, lhs_conv.value != rhs_conv.value)
778
+ when Operator::LT
779
+ result = temporary_variable(int_type, lhs_conv.value < rhs_conv.value)
780
+ when Operator::GT
781
+ result = temporary_variable(int_type, lhs_conv.value > rhs_conv.value)
782
+ when Operator::LE
783
+ result = temporary_variable(int_type, lhs_conv.value <= rhs_conv.value)
784
+ when Operator::GE
785
+ result = temporary_variable(int_type, lhs_conv.value >= rhs_conv.value)
785
786
  else
786
- # NOTREACHED
787
+ __NOTREACHED__
787
788
  end
788
789
 
789
- case @operator_symbol
790
- when :==, :!=
791
- notify_equality_expr_evaled(@node,
792
- lhs_converted, rhs_converted, result)
793
- when :<, :>, :<=, :>=
794
- notify_relational_expr_evaled(@node,
795
- lhs_converted, rhs_converted, result)
790
+ case @operator
791
+ when Operator::EQ, Operator::NE
792
+ notify_equality_expr_evaled(@node, lhs_conv, rhs_conv, result)
793
+ when Operator::LT, Operator::GT, Operator::LE, Operator::GE
794
+ notify_relational_expr_evaled(@node, lhs_conv, rhs_conv, result)
795
+ else
796
+ __NOTREACHED__
796
797
  end
797
798
 
798
799
  case
799
- when lhs_converted.designated_by_lvalue?
800
- ensure_relation(lhs_converted, @operator_symbol, rhs_converted.value)
801
- when rhs_converted.designated_by_lvalue?
802
- ensure_relation(rhs_converted, @operator_symbol, lhs_converted.value)
800
+ when lhs_conv.designated_by_lvalue?
801
+ ensure_relation(lhs_conv, @operator, rhs_conv.value)
802
+ when rhs_conv.designated_by_lvalue?
803
+ ensure_relation(rhs_conv, @operator.for_commutation, lhs_conv.value)
803
804
  else
804
805
  # NOTE: Domain of the rvalue should not be narrowed.
805
806
  end