merged in latest cython-devel
authorStefan Behnel <scoder@users.berlios.de>
Wed, 28 Apr 2010 16:52:44 +0000 (18:52 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 28 Apr 2010 16:52:44 +0000 (18:52 +0200)
1  2 
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py
Cython/Compiler/Optimize.py

Simple merge
index 66cbcb5dfd17fdf97e4791f67f8369eca66dea3f,00ac446326b46780f6201afbfb033de1720abc5e..a0de3210c5a705801fe5c858758458555b1cc07c
@@@ -4038,24 -3871,36 +4038,42 @@@ class IfStatNode(StatNode)
              if_clause.analyse_expressions(env)
          if self.else_clause:
              self.else_clause.analyse_expressions(env)
-     
+         # eliminate dead code based on constant condition results
+         if_clauses = []
+         condition_result = None
+         for if_clause in self.if_clauses:
+             condition_result = if_clause.get_constant_condition_result()
+             if condition_result != False:
+                 if_clauses.append(if_clause)
+                 if condition_result == True:
+                     # other conditions can no longer apply
+                     self.else_clause = None
+                     break
+         self.if_clauses = if_clauses
+         # FIXME: if only one active code body is left here, we can
+         # replace the whole node
      def generate_execution_code(self, code):
          code.mark_pos(self.pos)
-         end_label = code.new_label()
-         for if_clause in self.if_clauses:
-             if_clause.generate_execution_code(code, end_label)
-         if self.else_clause:
-             code.putln("/*else*/ {")
+         if self.if_clauses:
+             end_label = code.new_label()
+             for if_clause in self.if_clauses:
+                 if_clause.generate_execution_code(code, end_label)
+             if self.else_clause:
+                 code.putln("/*else*/ {")
+                 self.else_clause.generate_execution_code(code)
+                 code.putln("}")
+             code.put_label(end_label)
+         elif self.else_clause:
              self.else_clause.generate_execution_code(code)
-             code.putln("}")
-         code.put_label(end_label)
  
-         
 +    def generate_function_definitions(self, env, code):
 +        for clause in self.if_clauses:
 +            clause.generate_function_definitions(env, code)
 +        if self.else_clause is not None:
 +            self.else_clause.generate_function_definitions(env, code)
++
      def annotate(self, code):
          for if_clause in self.if_clauses:
              if_clause.annotate(code)
Simple merge