From 16e4fbd6c800851614549bb436ec58b369a5f95c Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 27 Apr 2010 21:31:20 +0200 Subject: [PATCH] more dead code removal for conditionals --- Cython/Compiler/ExprNodes.py | 8 ++++++-- tests/errors/break_outside_loop.pyx | 5 ++++- tests/errors/continue_outside_loop.pyx | 4 +++- tests/errors/literal_lists.pyx | 5 ++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 778ef394..36b4e560 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -327,8 +327,9 @@ class ExprNode(Node): # time we get the result. self.analyse_types(env) bool = self.coerce_to_boolean(env) - temp_bool = bool.coerce_to_temp(env) - return temp_bool + if not bool.is_simple(): + bool = bool.coerce_to_temp(env) + return bool # --------------- Type Inference ----------------- @@ -6383,6 +6384,7 @@ class CoerceToTempNode(CoercionNode): def __init__(self, arg, env): CoercionNode.__init__(self, arg) self.type = self.arg.type + self.constant_result = self.arg.constant_result self.is_temp = 1 if self.type.is_pyobject: self.result_ctype = py_object_type @@ -6395,6 +6397,8 @@ class CoerceToTempNode(CoercionNode): def coerce_to_boolean(self, env): self.arg = self.arg.coerce_to_boolean(env) + if self.arg.is_simple(): + return self.arg self.type = self.arg.type self.result_ctype = self.type return self diff --git a/tests/errors/break_outside_loop.pyx b/tests/errors/break_outside_loop.pyx index 07ccfeac..c2814423 100644 --- a/tests/errors/break_outside_loop.pyx +++ b/tests/errors/break_outside_loop.pyx @@ -16,11 +16,14 @@ except: pass try: break finally: pass -if True: +if bool_result(): break else: break +def bool_result(): + return True + _ERRORS = u''' 2:0: break statement not inside loop diff --git a/tests/errors/continue_outside_loop.pyx b/tests/errors/continue_outside_loop.pyx index 8c3a38d3..f8309158 100644 --- a/tests/errors/continue_outside_loop.pyx +++ b/tests/errors/continue_outside_loop.pyx @@ -16,11 +16,13 @@ except: pass try: continue finally: pass -if True: +if bool_result(): continue else: continue +def bool_result(): + return True _ERRORS = u''' 2:0: continue statement not inside loop diff --git a/tests/errors/literal_lists.pyx b/tests/errors/literal_lists.pyx index adbff03c..7c49f961 100644 --- a/tests/errors/literal_lists.pyx +++ b/tests/errors/literal_lists.pyx @@ -1,8 +1,11 @@ def f(): cdef int* p - if False: + if false(): p = [1, 2, 3] +def false(): + return False + _ERRORS = u""" 4:10: Literal list must be assigned to pointer at time of declaration """ -- 2.26.2