Ignore:
Timestamp:
Dec 24, 2014, 11:09:52 AM (5 years ago)
Author:
cameron
Message:

Improve if-test generation, eliminate some redundancies

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/CC_compiler.py

    r4349 r4355  
    2323
    2424    def add_common_expressions(self, enclosing_cgo):
    25         for sym in enclosing_cgo.common_expression_map.keys():
    26             self.common_expression_map[sym] = enclosing_cgo.common_expression_map[sym]
     25        for expr in enclosing_cgo.common_expression_map.keys():
     26            self.common_expression_map[expr] = enclosing_cgo.common_expression_map[expr]
    2727        for sym in enclosing_cgo.canonical_sym_map.keys():
    2828            self.canonical_sym_map[sym] = enclosing_cgo.canonical_sym_map[sym]
     
    184184            else: return e1
    185185
    186     def add_assignment(self, varname, expr):
    187         #if not self.sym_in_map(varname):
    188             self.common_expression_map[expr] = varname       
    189             self.generated_code.append('\t%s%s = %s\n' % (self.typedecl, varname, expr))
     186    def add_assignment(self, varname, expr_string):
     187        if self.common_expression_map.has_key(expr_string):
     188                assigned = self.common_expression_map[expr_string]
     189                if assigned == varname: return
     190        else:
     191            self.common_expression_map[expr_string] = varname
     192            assigned = expr_string   
     193        self.generated_code.append('\t%s%s = %s\n' % (self.typedecl, varname, assigned))
    190194
    191195    # An assignment to a variable name that uniquely specifies the expr
    192196    def add_canonical_assignment(self, canonical_var, expr):
    193197        if not canonical_var in self.canonical_sym_map.keys():
    194             self.common_expression_map[expr] = canonical_var       
    195             self.canonical_sym_map[canonical_var] = expr
    196             self.generated_code.append('\t%s%s = %s\n' % (self.typedecl, canonical_var, expr))
     198            self.add_assignment(canonical_var, expr)
     199            self.common_expression_map[expr] = canonical_var       
     200            self.canonical_sym_map[canonical_var] = expr       
    197201
    198202    def add_if_stmt(self, test_expr, generated_subcode):
Note: See TracChangeset for help on using the changeset viewer.