Ignore:
Timestamp:
Aug 21, 2014, 11:48:52 AM (5 years ago)
Author:
cameron
Message:

Restructuring; if-test simplification; odd/even ranges for Lu/Ll?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/CC_compiler.py

    r3978 r4071  
    2020        predeclared = [self.bit_var(i) for i in range(0, self.mEncoding.bits)]
    2121        for sym in predeclared: self.common_expression_map[sym] = sym
    22 
    23     def add_symbol_to_map(self, sym):
    24         self.common_expression_map[sym] = sym
     22        self.canonical_sym_map = {}
    2523
    2624    def add_common_expressions(self, enclosing_cgo):
    2725        for sym in enclosing_cgo.common_expression_map.keys():
    2826            self.common_expression_map[sym] = enclosing_cgo.common_expression_map[sym]
     27        for sym in enclosing_cgo.canonical_sym_map.keys():
     28            self.canonical_sym_map[sym] = enclosing_cgo.canonical_sym_map[sym]
    2929
    3030    def bit_var(self, n):
     
    6565                        return self.mEncoding.basis_pattern[2] % (n - 24)
    6666
    67     def make_bitv(self, n):
    68                
     67    def make_bitv(self, n):             
    6968            if self.little_endian == True:
    7069                return Var(self.bit_var(n))
     
    105104              selected_bits &= ~test_bit
    106105              bit_no += 1
    107              
    108106            while len(bit_terms) > 1:
    109107                new_terms = []
     
    112110                if len(bit_terms) % 2 == 1:
    113111                    new_terms.append(bit_terms[-1])
    114                 bit_terms = new_terms
    115            
     112                bit_terms = new_terms     
    116113            return bit_terms[0]
    117114   
    118 
    119115    def char_test_expr(self, chval):
    120116            return self.bit_pattern_expr(chval, self.mEncoding.mask) 
     
    188184                if combine == True:
    189185                    #If charset items are all of the form X1 = X0 + 2.
    190                     for i in range(1 , len(chardef.items) - 1):
     186                    for i in range(len(chardef.items) - 1):
    191187                        curr_item = chardef.items[i]
    192188                        next_item = chardef.items[i+1]
     
    197193                    lo = chardef.items[0][0]
    198194                    hi = chardef.items[-1][0]
     195                    print "Combined odd/even range %x-%x" % (lo, hi)
    199196                    utf_temp = self.mEncoding.mask - 1
    200197                    lo &= utf_temp
    201198                    hi |= (self.mEncoding.mask ^ utf_temp)
    202                     return self.char_or_range_expr((lo, hi))
     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)))
    203201            e1 = self.char_or_range_expr(chardef.items[0])
    204202            for i in range(1, len(chardef.items)):   
     
    208206
    209207    def add_assignment(self, varname, expr):
    210         self.common_expression_map[expr] = varname
    211         #self.generated_code.append('%s%s = %s;\n' % (self.typedecl, varname, expr))
    212         self.generated_code.append('\t%s%s = %s\n' % (self.typedecl, varname, expr))
     208        #if not self.sym_in_map(varname):
     209            self.common_expression_map[expr] = varname       
     210            self.generated_code.append('\t%s%s = %s\n' % (self.typedecl, varname, expr))
     211
     212    # An assignment to a variable name that uniquely specifies the expr
     213    def add_canonical_assignment(self, canonical_var, expr):
     214        if not canonical_var in self.canonical_sym_map.keys():
     215            self.common_expression_map[expr] = canonical_var       
     216            self.canonical_sym_map[canonical_var] = expr
     217            self.generated_code.append('\t%s%s = %s\n' % (self.typedecl, canonical_var, expr))
    213218
    214219    def add_if_stmt(self, test_expr, generated_subcode):
     
    279284    def chardef2py(self, chardef):
    280285            self.add_assignment(chardef.name, self.expr2py(self.charset_expr(chardef)))
     286
     287    def chardef_canonical(self, chardef):
     288            self.add_canonical_assignment(chardef.name, self.expr2py(self.charset_expr(chardef)))
    281289   
    282290    def chardeflist2py(self, chardeflist):
Note: See TracChangeset for help on using the changeset viewer.