module AdLint::Cc1::ValueDomainFactory

Constants

COMPOSITE_MAX_COMPLEXITY

NOTE: To avoid huge composite value-domain creation in the interp phase.

Public Instance Methods

_create_intersection(lhs_dom, rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 233
def _create_intersection(lhs_dom, rhs_dom)
  expected = lhs_dom.complexity + rhs_dom.complexity
  if expected < COMPOSITE_MAX_COMPLEXITY
    IntersectionValueDomain.new(lhs_dom, rhs_dom)
  else
    of_ambiguous(lhs_dom.undefined? || rhs_dom.undefined?,
                 lhs_dom.logical_shr? && rhs_dom.logical_shr?)
  end
end
_create_union(lhs_dom, rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 244
def _create_union(lhs_dom, rhs_dom)
  expected = lhs_dom.complexity + rhs_dom.complexity
  if expected < COMPOSITE_MAX_COMPLEXITY
    UnionValueDomain.new(lhs_dom, rhs_dom)
  else
    of_ambiguous(lhs_dom.undefined? || rhs_dom.undefined?,
                 lhs_dom.logical_shr? && rhs_dom.logical_shr?)
  end
end
clear_memos() click to toggle source
# File lib/adlint/cc1/domain.rb, line 255
def clear_memos
  clear_memo_of__equal_to
  clear_memo_of__not_equal_to
  clear_memo_of__less_than
  clear_memo_of__greater_than
  clear_memo_of__less_than_or_equal_to
  clear_memo_of__greater_than_or_equal_to
  clear_memo_of__of_true
  clear_memo_of__of_false
  clear_memo_of__of_unlimited
  clear_memo_of__of_nil
  clear_memo_of__of_nan
  clear_memo_of__of_intersection
  clear_memo_of__of_union
  clear_memo_of__of_undefined
  clear_memo_of__of_ambiguous
  clear_memo_of___create_intersection
  clear_memo_of___create_union
end
equal_to(numeric, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 42
def equal_to(numeric, logical_shr)
  EqualToValueDomain.new(numeric, logical_shr)
end
greater_than(numeric, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 72
def greater_than(numeric, logical_shr)
  GreaterThanValueDomain.new(numeric, logical_shr)
end
greater_than_or_equal_to(numeric, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 92
def greater_than_or_equal_to(numeric, logical_shr)
  greater_than(numeric, logical_shr).union(equal_to(numeric, logical_shr))
end
less_than(numeric, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 62
def less_than(numeric, logical_shr)
  LessThanValueDomain.new(numeric, logical_shr)
end
less_than_or_equal_to(numeric, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 82
def less_than_or_equal_to(numeric, logical_shr)
  less_than(numeric, logical_shr).union(equal_to(numeric, logical_shr))
end
not_equal_to(numeric, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 52
def not_equal_to(numeric, logical_shr)
  equal_to(numeric, logical_shr).inversion
end
of_ambiguous(undefined, logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 223
def of_ambiguous(undefined, logical_shr)
  AmbiguousValueDomain.new(undefined, logical_shr)
end
of_false(logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 112
def of_false(logical_shr)
  equal_to(0, logical_shr)
end
of_intersection(lhs_dom, rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 152
def of_intersection(lhs_dom, rhs_dom)
  case lhs_dom
  when UndefinedValueDomain
    lhs_dom = lhs_dom.domain
    undefined = true
  end

  case rhs_dom
  when UndefinedValueDomain
    rhs_dom = rhs_dom.domain
    undefined = true
  end

  case
  when lhs_dom.empty?
    intersection = lhs_dom
  when rhs_dom.empty?
    intersection = rhs_dom
  when lhs_dom.contain?(rhs_dom)
    intersection = rhs_dom
  when rhs_dom.contain?(lhs_dom)
    intersection = lhs_dom
  when lhs_dom.intersect?(rhs_dom)
    intersection = _create_intersection(lhs_dom, rhs_dom)
  else
    intersection = of_nil(lhs_dom.logical_shr? && rhs_dom.logical_shr?)
  end

  undefined ? of_undefined(intersection) : intersection
end
of_nan(logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 142
def of_nan(logical_shr)
  NaN.new(logical_shr)
end
of_nil(logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 132
def of_nil(logical_shr)
  NilValueDomain.new(logical_shr)
end
of_true(logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 102
def of_true(logical_shr)
  not_equal_to(0, logical_shr)
end
of_undefined(dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 214
def of_undefined(dom)
  if dom.undefined?
    dom
  else
    UndefinedValueDomain.new(dom)
  end
end
of_union(lhs_dom, rhs_dom) click to toggle source
# File lib/adlint/cc1/domain.rb, line 184
def of_union(lhs_dom, rhs_dom)
  case lhs_dom
  when UndefinedValueDomain
    lhs_dom = lhs_dom.domain
    undefined = true
  end

  case rhs_dom
  when UndefinedValueDomain
    rhs_dom = rhs_dom.domain
    undefined = true
  end

  case
  when lhs_dom.empty?
    union = rhs_dom
  when rhs_dom.empty?
    union = lhs_dom
  when lhs_dom.contain?(rhs_dom)
    union = lhs_dom
  when rhs_dom.contain?(lhs_dom)
    union = rhs_dom
  else
    union = _create_union(lhs_dom, rhs_dom)
  end

  undefined ? of_undefined(union) : union
end
of_unlimited(logical_shr) click to toggle source
# File lib/adlint/cc1/domain.rb, line 122
def of_unlimited(logical_shr)
  UnlimitedValueDomain.new(logical_shr)
end