class AdLint::Cc1::IntersectionValueDomain

Public Instance Methods

!() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6457
def !
  new_sub_doms = domain_pair.map { |dom| !dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
&(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6428
def &(rhs_dom)
  if rhs_max = rhs_dom.max_value
    ValueDomain.greater_than_or_equal_to(0, logical_shr?).intersection(
      ValueDomain.less_than_or_equal_to(rhs_max, logical_shr?))
  else
    ValueDomain.greater_than_or_equal_to(0, logical_shr?)
  end
end
*(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6343
def *(rhs_dom)
  # NOTE: Multiplication of LessThanValueDomain or GreaterThanValueDomain
  #       always makes UnlimitedValueDomain when the domain contains both
  #       positive and negative values.
  #       So, multiplication of IntersectionValueDomain cannot be defined
  #       in the same manner as other arithmetics.
  if rhs_dom.kind_of?(IntersectionValueDomain)
    lhs_dom = self

    lval = [
      (n = lhs_dom.min_value).integer? ? n - 1 : n - Float::EPSILON,
      (n = lhs_dom.max_value).integer? ? n + 1 : n + Float::EPSILON
    ]
    labs = lval.map { |val| val.abs }.sort

    rval = [
      (n = rhs_dom.min_value).integer? ? n - 1 : n - Float::EPSILON,
      (n = rhs_dom.max_value).integer? ? n + 1 : n + Float::EPSILON
    ]
    rabs = rval.map { |val| val.abs }.sort

    comp = lambda { |op, nums| nums.all? { |num| num.__send__(op, 0) } }
    only_negative, only_positive = comp.curry[:<], comp.curry[:>=]

    case lval
    when only_positive
      case rval
      when only_positive
        _mul_only_positive_and_only_positive(lval, labs, rval, rabs)
      when only_negative
        _mul_only_positive_and_only_negative(lval, labs, rval, rabs)
      else
        _mul_only_positive_and_positive_negative(lval, labs, rval, rabs)
      end
    when only_negative
      case rval
      when only_positive
        _mul_only_positive_and_only_negative(rval, rabs, lval, labs)
      when only_negative
        _mul_only_negative_and_only_negative(lval, labs, rval, rabs)
      else
        _mul_only_negative_and_positive_negative(lval, labs, rval, rabs)
      end
    else
      _mul_positive_negative_and_positive_negative(lval, labs, rval, rabs)
    end
  else
    rhs_dom * self
  end
end
+(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6338
def +(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs + rhs_dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
+@() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6328
def +@
  new_sub_doms = domain_pair.map { |dom| +dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
-@() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6333
def -@
  new_sub_doms = domain_pair.map { |dom| -dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
/(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6423
def /(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs / rhs_dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
<(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6462
def <(rhs_dom)
  # NOTE: The intersection value domain must be a close-domain (--<===>--).
  if intersect?(rhs_dom)
    if rhs_dom.max_value && rhs_dom.max_value == min_value
      ValueDomain.of_false(logical_shr?)
    else
      ValueDomain.of_unlimited(logical_shr?)
    end
  else
    # NOTE: When value domains are not intersected, the RHS value domain is
    #       in the left or right of the LHS intersection value domain.
    if rhs_dom.min_value && max_value < rhs_dom.min_value
      # NOTE: The RHS value domain is in the right of the LHS intersection
      #       value domain.
      ValueDomain.of_true(logical_shr?)
    else
      # NOTE: The RHS value domain is in the left of the LHS intersection
      #       value domain.
      ValueDomain.of_false(logical_shr?)
    end
  end
end
<<(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6447
def <<(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs << rhs_dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
>>(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6452
def >>(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs >> rhs_dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
^(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6442
def ^(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs ^ rhs_dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
_contain_equal_to?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6283
def _contain_equal_to?(lhs_dom, rhs_dom = self)
  rhs_dom.domain_pair.any? { |rhs| lhs_dom.contain_value_domain?(rhs) }
end
_contain_greater_than?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6291
def _contain_greater_than?(lhs_dom, rhs_dom = self)
  rhs_dom.domain_pair.any? { |rhs| lhs_dom.contain_value_domain?(rhs) }
end
_contain_intersection?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6295
def _contain_intersection?(lhs_dom, rhs_dom = self)
  lhs_fst, lhs_snd = lhs_dom.domain_pair
  rhs_fst, rhs_snd = rhs_dom.domain_pair
  case
  when lhs_fst.contain_value_domain?(rhs_fst) &&
       lhs_snd.contain_value_domain?(rhs_snd)
    true
  when lhs_fst.contain_value_domain?(rhs_snd) &&
       lhs_snd.contain_value_domain?(rhs_fst)
    true
  else
    false
  end
end
_contain_less_than?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6287
def _contain_less_than?(lhs_dom, rhs_dom = self)
  rhs_dom.domain_pair.any? { |rhs| lhs_dom.contain_value_domain?(rhs) }
end
_contain_nil?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6275
def _contain_nil?(lhs_dom, rhs_dom = self)
  false
end
_contain_union?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6310
def _contain_union?(lhs_dom, rhs_dom = self)
  lhs_dom.domain_pair.any? { |lhs| lhs.contain_value_domain?(rhs_dom) }
end
_contain_unlimited?(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6279
def _contain_unlimited?(lhs_dom, rhs_dom = self)
  true
end
_mul_equal_to(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6408
def _mul_equal_to(lhs_dom, rhs_dom = self)
  new_sub_doms = rhs_dom.domain_pair.map { |rhs| lhs_dom * rhs }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
_mul_greater_than(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6418
def _mul_greater_than(lhs_dom, rhs_dom = self)
  new_sub_doms = rhs_dom.domain_pair.map { |rhs| lhs_dom * rhs }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
_mul_less_than(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6413
def _mul_less_than(lhs_dom, rhs_dom = self)
  new_sub_doms = rhs_dom.domain_pair.map { |rhs| lhs_dom * rhs }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
_mul_nil(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6394
def _mul_nil(lhs_dom, rhs_dom = self)
  # NOTE: NilValueDomain contains no values.
  #       So, any arithmetic operation with NilValueDomain makes
  #       NilValueDomain.
  lhs_dom
end
_mul_unlimited(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6401
def _mul_unlimited(lhs_dom, rhs_dom = self)
  # NOTE: UnlimitedValueDomain contains everything.
  #       So, this arithmetic operation with UnlimitedValueDomain makes
  #       UnlimitedValueDomain.
  lhs_dom
end
coerce_to_integer() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6522
def coerce_to_integer
  new_sub_doms = domain_pair.map { |dom| dom.coerce_to_integer }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
coerce_to_real() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6527
def coerce_to_real
  new_sub_doms = domain_pair.map { |dom| dom.coerce_to_real }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
contain_value_domain?(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6271
def contain_value_domain?(rhs_dom)
  rhs_dom._contain_intersection?(self)
end
each_sample() { |sample| ... } click to toggle source
# File lib/adlint/cc1/domain.rb, line 6546
def each_sample
  return to_enum(:each_sample) unless block_given?
  domain_pair.map { |d| d.each_sample.to_a }.flatten.uniq.each do |sample|
    yield(sample) if contain?(sample)
  end
end
intersect?(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6314
def intersect?(rhs_dom)
  domain_pair.all? { |lhs| lhs.intersect?(rhs_dom) }
end
intersection(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6495
def intersection(rhs_dom)
  if rhs_dom.kind_of?(UnionValueDomain)
    return rhs_dom.intersection(self)
  end

  case
  when contain_value_domain?(rhs_dom)
    rhs_dom
  when rhs_dom.contain_value_domain?(self)
    self
  else
    new_sub_doms = domain_pair.map { |lhs| lhs.intersection(rhs_dom) }
    ValueDomain.of_intersection(*new_sub_doms)
  end
end
inversion() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6318
def inversion
  new_sub_doms = domain_pair.map { |dom| dom.inversion }
  new_sub_doms.first.union(new_sub_doms.last)
end
logical_and(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6485
def logical_and(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs.logical_and(rhs_dom) }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
logical_or(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6490
def logical_or(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs.logical_or(rhs_dom) }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
max_value() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6539
def max_value
  # NOTE: Intersection-value-domain must be a close-domain (---<=====>---).
  #       So, max-value is defined by the higher lower-than value domain.
  domain_pair.map { |dom| dom.max_value }.compact.max
end
min_value() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6532
def min_value
  # NOTE: Intersection-value-domain must be a close-domain (---<=====>---).
  #       So, min-value is defined by the lower greater-than value domain.
  domain_pair.map { |dom| dom.min_value }.compact.min
end
to_s() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6553
def to_s
  "(#{domain_pair.first.to_s} && #{domain_pair.last.to_s})"
end
union(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6511
def union(rhs_dom)
  case
  when contain_value_domain?(rhs_dom)
    self
  when rhs_dom.contain_value_domain?(self)
    rhs_dom
  else
    ValueDomain.of_union(self, rhs_dom)
  end
end
|(rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6437
def |(rhs_dom)
  new_sub_doms = domain_pair.map { |lhs| lhs | rhs_dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
~() click to toggle source
# File lib/adlint/cc1/domain.rb, line 6323
def ~
  new_sub_doms = domain_pair.map { |dom| ~dom }
  new_sub_doms.first.intersection(new_sub_doms.last)
end

Private Instance Methods

_div(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6625
def _div(lhs_dom, rhs_dom = self)
  new_sub_doms = rhs_dom.domain_pair.map { |rhs| lhs_dom / rhs }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
_equal(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6649
def _equal(lhs_dom, rhs_dom = self)
  # NOTE: The intersection value domain must be a close-domain (--<===>--).
  #       If one of the sub domains is not equal to LHS, result should be
  #       false.
  comp_dom = rhs_dom.domain_pair.map { |rhs| lhs_dom == rhs }
  if comp_dom.any? { |dom| dom.eql?(ValueDomain.of_false(logical_shr?)) }
    ValueDomain.of_false(logical_shr?)
  else
    comp_dom.first.intersection(comp_dom.last)
  end
end
_less(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6640
def _less(lhs_dom, rhs_dom = self)
  comp_dom = rhs_dom.domain_pair.map { |rhs| lhs_dom < rhs }
  if comp_dom.any? { |dom| dom.eql?(ValueDomain.of_false(logical_shr?)) }
    ValueDomain.of_false(logical_shr?)
  else
    comp_dom.first.intersection(comp_dom.last)
  end
end
_mul_only_negative_and_only_negative(lval, labs, rval, rabs) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6592
def _mul_only_negative_and_only_negative(lval, labs, rval, rabs)
  # NOTE: (--) * (--) makes a new IntersectionValueDomain;
  #         upper bound: (labs.min * rabs.min)
  #         lower bound: (labs.max * rabs.max)
  ValueDomain.greater_than(
    labs.first * rabs.first, logical_shr?
  ).intersection(ValueDomain.less_than(
    labs.last * rabs.last, logical_shr?
  ))
end
_mul_only_negative_and_positive_negative(lval, labs, rval, rabs) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6603
def _mul_only_negative_and_positive_negative(lval, labs, rval, rabs)
  # NOTE: (--) * (-+) makes a new IntersectionValueDomain;
  #         lower bound: -(labs.max * rval.max)
  #         upper_bound: -(labs.max * rval.min)
  ValueDomain.greater_than(
    -(labs.last * rval.last), logical_shr?
  ).intersection(ValueDomain.less_than(
    -(labs.last * rval.first), logical_shr?
  ))
end
_mul_only_positive_and_only_negative(lval, labs, rval, rabs) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6570
def _mul_only_positive_and_only_negative(lval, labs, rval, rabs)
  # NOTE: (++) * (--) makes a new IntersectionValueDomain;
  #         lower bound: -(labs.max * rabs.max)
  #         upper bound: -(labs.min * rabs.min)
  ValueDomain.greater_than(
    -(labs.last * rabs.last), logical_shr?
  ).intersection(ValueDomain.less_than(
    -(labs.first * rabs.first), logical_shr?
  ))
end
_mul_only_positive_and_only_positive(lval, labs, rval, rabs) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6559
def _mul_only_positive_and_only_positive(lval, labs, rval, rabs)
  # NOTE: (++) * (++) makes a new IntersectionValueDomain;
  #         lower bound: (labs.min * rabs.min)
  #         upper bound: (labs.max * rabs.max)
  ValueDomain.greater_than(
    labs.first * rabs.first, logical_shr?
  ).intersection(ValueDomain.less_than(
    labs.last * rabs.last, logical_shr?
  ))
end
_mul_only_positive_and_positive_negative(lval, labs, rval, rabs) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6581
def _mul_only_positive_and_positive_negative(lval, labs, rval, rabs)
  # NOTE: (++) * (-+) makes a new IntersectionValueDomain;
  #         lower bound: (labs.max * rval.min)
  #         upper bound: (labs.max * rval.max)
  ValueDomain.greater_than(
    labs.last * rval.first, logical_shr?
  ).intersection(ValueDomain.less_than(
    labs.last * rval.last, logical_shr?
  ))
end
_mul_positive_negative_and_positive_negative(lval, labs, rval, rabs) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6614
def _mul_positive_negative_and_positive_negative(lval, labs, rval, rabs)
  # NOTE: (-+) * (-+) makes a new IntersectionValueDomain;
  #         lower bound: ([lval.min * rval.max, lval.max * rval.min].min)
  #         upper bound: ([lval.min * rval.min, lval.max * rval.max].max)
  ValueDomain.greater_than(
    [lval.first * rval.last, lval.last * rval.first].min, logical_shr?
  ).intersection(ValueDomain.less_than(
    [lval.first * rval.first, lval.last, rval.last].max, logical_shr?
  ))
end
_not_equal(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6661
def _not_equal(lhs_dom, rhs_dom = self)
  # NOTE: The intersection value domain must be a close-domain (--<===>--).
  #       If one of the sub domains is not equal to LHS, result should be
  #       true.
  comp_dom = rhs_dom.domain_pair.map { |rhs| lhs_dom != rhs }
  if comp_dom.any? { |dom| dom.eql?(ValueDomain.of_false(logical_shr?)) }
    ValueDomain.of_false(logical_shr?)
  else
    comp_dom.first.intersection(comp_dom.last)
  end
end
_shl(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6630
def _shl(lhs_dom, rhs_dom = self)
  new_sub_doms = rhs_dom.domain_pair.map { |rhs| lhs_dom << rhs }
  new_sub_doms.first.intersection(new_sub_doms.last)
end
_shr(lhs_dom, rhs_dom = self) click to toggle source
# File lib/adlint/cc1/domain.rb, line 6635
def _shr(lhs_dom, rhs_dom = self)
  new_sub_doms = rhs_dom.domain_pair.map { |rhs| lhs_dom >> rhs }
  new_sub_doms.first.intersection(new_sub_doms.last)
end