2011/1/25 Stefan Behnel <stefan...@behnel.de>:
> Vitja Makarov, 25.01.2011 10:01:
>> 2011/1/25 Stefan Behnel:
>>>      def x():
>>>          do_some_stuff()
>>>
>>>          return # disable rest of code, e.g. during debugging
>>>
>>>          unreachable_code()
>>>
>>> Cython shouldn't bother generating dead code here (even if the C compiler
>>> would drop it anyway).
>>
>> That should be rather easy to do: remove all the nodes in StatList
>> after: break, continue, return, raise, something else?
>
> Careful, this may involve recursive propagation through helper nodes. The
> tree isn't always as simple as that.
>
> I think an attribute "is_terminator" on Nodes might do the job. It's set to
> False by default and to True on all nodes you mentioned above, and is
> inherited by StatListNode if its last node is a terminator (while dropping
> its remaining child nodes at the same time) and by all helper nodes that
> contain StatListNodes. This could be done in analyse_types() (or maybe
> earlier?).
>

May be it could be placed in StatNodeList.analyse_flow_control()?

I've tried this, and as side effect some error tests doesn't work as
code after first return is removed:

======================================================================
FAIL: compiling (c) e_return
----------------------------------------------------------------------
Traceback (most recent call last):
  File "runtests.py", line 306, in runTest
    self.runCompileTest()
  File "runtests.py", line 310, in runCompileTest
    self.test_directory, self.expect_errors, self.annotate)
  File "runtests.py", line 449, in compile
    self.assertEquals(expected_error, None)
AssertionError: u"8:17: Cannot assign type 'int *' to 'int'" != None

======================================================================
FAIL: compiling (c) e_while
----------------------------------------------------------------------
Traceback (most recent call last):
  File "runtests.py", line 306, in runTest
    self.runCompileTest()
  File "runtests.py", line 310, in runCompileTest
    self.test_directory, self.expect_errors, self.annotate)
  File "runtests.py", line 449, in compile
    self.assertEquals(expected_error, None)
AssertionError: u'4:1: continue statement not inside loop' != None




-- 
vitja.
_______________________________________________
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to