Changeset 4349 for proto/charsetcompiler


Ignore:
Timestamp:
Dec 19, 2014, 10:21:35 AM (5 years ago)
Author:
cameron
Message:

Bug fix for odd/even ranges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/CC_compiler.py

    r4071 r4349  
    7171                return Var(self.bit_var((self.mEncoding.bits - 1) -n))
    7272               
    73     def make_bit_test(self, pattern, bit_count):
    74             if bit_count == 0: return TrueLiteral()
    75             bit_terms = []
    76             test_bit = 2**(bit_count - 1)
    77             for i in range(0, bit_count):
    78                 if (pattern & test_bit) == 0:
    79                     bit_terms.append(make_not(self.make_bitv((self.mEncoding.bits - 1)-i)))   
    80                 else: bit_terms.append(self.make_bitv((self.mEncoding.bits - 1)-i))           
    81                 test_bit >>= 1
    82             while len(bit_terms) > 1:
    83                 new_terms = []
    84                 for i in range(0, len(bit_terms)/ 2):
    85                     new_terms.append(make_and(bit_terms[2*i], bit_terms[2*i+1]))
    86                 if len(bit_terms) % 2 == 1:
    87                     new_terms.append(bit_terms[-1])
    88                 bit_terms = new_terms
    89             return bit_terms[0]
    90 
    9173    def bit_pattern_expr(self, pattern, selected_bits):
    9274            if selected_bits == 0: return TrueLiteral()
     
    156138            if n2 < n1 or diff_count > self.mEncoding.bits: raise Exception("Bad range: (%x, %x)." % (n1, n2))
    157139            mask = 2**(diff_count) - 1
    158             #common = make_bit_test(n1 >> diff_count, 8 - diff_count)
    159140            common = self.bit_pattern_expr(n1 & ~mask, self.mEncoding.mask^mask)   
    160141            if diff_count == 0: return common
     
    194175                    hi = chardef.items[-1][0]
    195176                    print "Combined odd/even range %x-%x" % (lo, hi)
    196                     utf_temp = self.mEncoding.mask - 1
    197                     lo &= utf_temp
    198                     hi |= (self.mEncoding.mask ^ utf_temp)
    199                     if lo & 1 == 1: return make_and(self.char_or_range_expr((lo, hi)), self.make_bitv(0))
    200                     else: return make_and(self.char_or_range_expr((lo, hi)), make_not(self.make_bitv(0)))
     177                    #
     178                    if lo & 1 == 1: return make_and(self.char_or_range_expr((lo&~1, hi)), self.make_bitv(0))
     179                    else: return make_and(self.char_or_range_expr((lo, hi|1)), make_not(self.make_bitv(0)))
    201180            e1 = self.char_or_range_expr(chardef.items[0])
    202181            for i in range(1, len(chardef.items)):   
Note: See TracChangeset for help on using the changeset viewer.