Changeset 2996
 Timestamp:
 Apr 3, 2013, 6:38:32 PM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

proto/charsetcompiler/charset_compiler.py
r2994 r2996 246 246 return options.basis_pattern % n 247 247 def make_bitv(n): 248 return Var(bit_var( n))248 return Var(bit_var(7n)) 249 249 250 250 … … 255 255 for i in range(0, bit_count): 256 256 if (pattern & test_bit) == 0: 257 bit_terms.append(make_not(make_bitv( i)))258 else: bit_terms.append(make_bitv( i))257 bit_terms.append(make_not(make_bitv(7i))) 258 else: bit_terms.append(make_bitv(7i)) 259 259 test_bit >>= 1 260 260 while len(bit_terms) > 1: … … 267 267 return bit_terms[0] 268 268 269 def bit_pattern_expr(pattern, selected_bits): 270 if selected_bits == 0: return TrueLiteral() 271 bit_terms = [] 272 bit_no = 0 273 while selected_bits: 274 test_bit = 1 << bit_no 275 if selected_bits & test_bit: 276 if (pattern & test_bit) == 0: 277 bit_terms = [make_not(make_bitv(bit_no))] + bit_terms 278 else: bit_terms = [make_bitv(bit_no)] + bit_terms 279 else: bit_terms = [TrueLiteral()] + bit_terms 280 # Appending TrueLiteral() for nonselected bits is intended 281 # to keep consistent grouping of variables in the next loop. 282 selected_bits &= ~test_bit 283 bit_no += 1 284 while len(bit_terms) > 1: 285 new_terms = [] 286 for i in range(0, len(bit_terms)/ 2): 287 new_terms.append(make_and(bit_terms[2*i], bit_terms[2*i+1])) 288 if len(bit_terms) % 2 == 1: 289 new_terms.append(bit_terms[1]) 290 bit_terms = new_terms 291 return bit_terms[0] 292 269 293 270 294 def char_test_expr(ch): 271 return make_bit_test(ord(ch), 8)272 #return make_8bit_test(ord(ch))295 #return make_bit_test(ord(ch), 8) 296 return bit_pattern_expr(ord(ch), 0xFF) 273 297 274 298 def GE_Range(N, n): 275 299 if N == 0: return TrueLiteral() 276 300 elif N % 2 == 0 and (n >> (N  2)) == 0: 277 return make_or(make_or(make_bitv( 8N), make_bitv(9N)),301 return make_or(make_or(make_bitv(N1), make_bitv(N2)), 278 302 GE_Range(N  2, n)) 279 303 elif N % 2 == 0 and (n >> (N  2)) == 3: # >= 11xxxx 280 return make_and(make_and(make_bitv( 8N), make_bitv(9N)),304 return make_and(make_and(make_bitv(N1), make_bitv(N2)), 281 305 GE_Range(N  2, n  (3 << (N2)))) 282 306 elif N >= 1: … … 288 312 # is set in the target, the target will certainly be >=. Otherwise, 289 313 # the value of GE_range(N1, lo_bits) is required. 290 return make_or(make_bitv( 8N), lo_range)314 return make_or(make_bitv(N1), lo_range) 291 315 else: 292 316 # If the hi_bit of n is set, then the corresponding bit must be set 293 317 # in the target for >= and GE_range(N1, lo_bits) must also be true. 294 return make_and(make_bitv( 8N), lo_range)318 return make_and(make_bitv(N1), lo_range) 295 319 296 320 def LE_Range(N, n): … … 314 338 diff_bits >>= 1 315 339 if n2 < n1 or diff_count > 8: raise BadRange() 316 mask = 2**(diff_count1)  1 317 common = make_bit_test(n1 >> diff_count, 8  diff_count) 340 mask = 2**(diff_count)  1 341 #common = make_bit_test(n1 >> diff_count, 8  diff_count) 342 common = bit_pattern_expr(n1 & ~mask, 0xFF^mask) 318 343 if diff_count == 0: return common 319 344 mask = 2**(diff_count1)  1 320 345 lo_test = GE_Range(diff_count1, n1 & mask) 321 346 hi_test = LE_Range(diff_count1, n2 & mask) 322 return make_and(common, make_sel(make_bitv( 8diff_count), hi_test, lo_test))347 return make_and(common, make_sel(make_bitv(diff_count1), hi_test, lo_test)) 323 348 324 349 BadCharSetItem = Exception()
Note: See TracChangeset
for help on using the changeset viewer.