Module: AdLint::Cc1::ValueDomainFactory
- Included in:
- ValueDomain
- Defined in:
- lib/adlint/cc1/domain.rb
Instance Method Summary collapse
- #_create_intersection(lhs_dom, rhs_dom) ⇒ Object
- #_create_union(lhs_dom, rhs_dom) ⇒ Object
- #clear_memos ⇒ Object
- #equal_to(numeric, logical_shr) ⇒ Object
- #greater_than(numeric, logical_shr) ⇒ Object
- #greater_than_or_equal_to(numeric, logical_shr) ⇒ Object
- #less_than(numeric, logical_shr) ⇒ Object
- #less_than_or_equal_to(numeric, logical_shr) ⇒ Object
- #not_equal_to(numeric, logical_shr) ⇒ Object
- #of_ambiguous(undefined, logical_shr) ⇒ Object
- #of_false(logical_shr) ⇒ Object
- #of_intersection(lhs_dom, rhs_dom) ⇒ Object
- #of_nan(logical_shr) ⇒ Object
- #of_nil(logical_shr) ⇒ Object
- #of_true(logical_shr) ⇒ Object
- #of_undefined(dom) ⇒ Object
- #of_union(lhs_dom, rhs_dom) ⇒ Object
- #of_unlimited(logical_shr) ⇒ Object
Instance Method Details
#_create_intersection(lhs_dom, rhs_dom) ⇒ Object
233 234 235 236 237 238 239 240 241 |
# 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) ⇒ Object
244 245 246 247 248 249 250 251 252 |
# 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 ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# 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) ⇒ Object
42 43 44 |
# 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) ⇒ Object
72 73 74 |
# 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) ⇒ Object
92 93 94 |
# 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) ⇒ Object
62 63 64 |
# 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) ⇒ Object
82 83 84 |
# 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) ⇒ Object
52 53 54 |
# 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) ⇒ Object
223 224 225 |
# File 'lib/adlint/cc1/domain.rb', line 223 def of_ambiguous(undefined, logical_shr) AmbiguousValueDomain.new(undefined, logical_shr) end |
#of_false(logical_shr) ⇒ Object
112 113 114 |
# 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) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# 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) ⇒ Object
142 143 144 |
# File 'lib/adlint/cc1/domain.rb', line 142 def of_nan(logical_shr) NaN.new(logical_shr) end |
#of_nil(logical_shr) ⇒ Object
132 133 134 |
# File 'lib/adlint/cc1/domain.rb', line 132 def of_nil(logical_shr) NilValueDomain.new(logical_shr) end |
#of_true(logical_shr) ⇒ Object
102 103 104 |
# File 'lib/adlint/cc1/domain.rb', line 102 def of_true(logical_shr) not_equal_to(0, logical_shr) end |
#of_undefined(dom) ⇒ Object
214 215 216 217 218 219 220 |
# 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) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# 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) ⇒ Object
122 123 124 |
# File 'lib/adlint/cc1/domain.rb', line 122 def of_unlimited(logical_shr) UnlimitedValueDomain.new(logical_shr) end |