1.1 --- a/annotate.py Tue Feb 06 00:57:50 2007 +0100
1.2 +++ b/annotate.py Wed Feb 14 01:34:35 2007 +0100
1.3 @@ -344,6 +344,12 @@
1.4 self.module.namespace = self.namespace
1.5 self.namespace.merge_namespace(saved_namespace)
1.6
1.7 + # NOTE: Exception recording.
1.8 +
1.9 + else:
1.10 + test_raises = []
1.11 + combine(test_raises, self.namespace.raises)
1.12 +
1.13 # Process the body clause.
1.14
1.15 conditional.body = self.dispatches(conditional.body)
1.16 @@ -370,10 +376,12 @@
1.17 self.namespace.merge_namespace(else_namespace)
1.18
1.19 # NOTE: Test of exception type pruning based on the test/body.
1.20 + # Note that the checked exceptions are tested for re-raising.
1.21
1.22 if conditional.isolate_test:
1.23 - for exc_type in body_namespace.raises:
1.24 - self.namespace.revoke_exception_type(exc_type)
1.25 + for exc_type in test_raises:
1.26 + if exc_type not in body_namespace.raises:
1.27 + self.namespace.revoke_exception_type(exc_type)
1.28
1.29 return conditional
1.30
1.31 @@ -719,6 +727,10 @@
1.32 pass #raise AnnotationMessage, "Temporary store index '%s' is empty." % index
1.33 return releasetemp
1.34
1.35 + def visitResetExc(self, resetexc):
1.36 + self.namespace.raises = []
1.37 + return resetexc
1.38 +
1.39 def visitReturn(self, return_):
1.40
1.41 """
1.42 @@ -777,6 +789,7 @@
1.43
1.44 storename.expr = self.dispatch(storename.expr)
1.45 self.namespace.store(storename.name, self.namespace.types)
1.46 + self.annotate(storename)
1.47 return storename
1.48
1.49 def visitStoreTemp(self, storetemp):
2.1 --- a/simplified.py Tue Feb 06 00:57:50 2007 +0100
2.2 +++ b/simplified.py Wed Feb 14 01:34:35 2007 +0100
2.3 @@ -366,6 +366,7 @@
2.4 class LoadRef(Node): "Load a reference, typically a subprogram or a constant."
2.5 class LoadExc(Node): "Load a handled exception."
2.6 class CheckExc(Node): "Check a handled exception."
2.7 +class ResetExc(Node): "Reset the exception state."
2.8 class StoreTemp(Node): "Store a temporary value."
2.9 class StoreName(Node): "Associate a name with an object."
2.10 class StoreAttr(Node): "Associate an object's attribute with a value."
3.1 --- a/simplify.py Tue Feb 06 00:57:50 2007 +0100
3.2 +++ b/simplify.py Wed Feb 14 01:34:35 2007 +0100
3.3 @@ -1267,9 +1267,9 @@
3.4 Try (body)
3.5 (else)
3.6 (handler) -> Conditional (test) -> (stmt)
3.7 - (body) -> ...
3.8 + (body) -> ResetExc ...
3.9 (else) -> Conditional (test) -> (stmt)
3.10 - (body) -> ...
3.11 + (body) -> ResetExc ...
3.12 (else) -> ...
3.13 """
3.14
3.15 @@ -1311,7 +1311,7 @@
3.16 )
3.17 )
3.18
3.19 - test.body += self.dispatch(stmt)
3.20 + test.body += [ResetExc()] + self.dispatch(stmt)
3.21 nodes.append(test)
3.22 nodes = test.else_ = []
3.23
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/raise_again.py Wed Feb 14 01:34:35 2007 +0100
4.3 @@ -0,0 +1,10 @@
4.4 +class A:
4.5 + pass
4.6 +
4.7 +def f():
4.8 + try:
4.9 + raise A
4.10 + except A, e:
4.11 + raise A
4.12 +
4.13 +f()
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/raise_nested.py Wed Feb 14 01:34:35 2007 +0100
5.3 @@ -0,0 +1,13 @@
5.4 +class A:
5.5 + pass
5.6 +
5.7 +def f():
5.8 + raise A
5.9 +
5.10 +def g(x):
5.11 + if x:
5.12 + f()
5.13 + else:
5.14 + pass
5.15 +
5.16 +g(1)
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/raise_uncaught.py Wed Feb 14 01:34:35 2007 +0100
6.3 @@ -0,0 +1,13 @@
6.4 +class A:
6.5 + pass
6.6 +
6.7 +class B:
6.8 + pass
6.9 +
6.10 +def f():
6.11 + try:
6.12 + raise A
6.13 + except B:
6.14 + pass
6.15 +
6.16 +f()
7.1 --- a/viewer.py Tue Feb 06 00:57:50 2007 +0100
7.2 +++ b/viewer.py Wed Feb 14 01:34:35 2007 +0100
7.3 @@ -202,8 +202,8 @@
7.4 self.stream.write(",\n")
7.5 self._name_start(base.name)
7.6 self._popup_start()
7.7 + self._scopes([base])
7.8 self._types([base])
7.9 - self._scopes([base])
7.10 self._popup_end()
7.11 self._name_end()
7.12 first = 0
7.13 @@ -569,8 +569,8 @@
7.14 self.stream.write("<span class='attr'>\n")
7.15 self.stream.write(".%s\n" % self._text(node.attrname))
7.16 self._popup_start()
7.17 + self._scopes(targets)
7.18 self._types(targets)
7.19 - self._scopes(targets)
7.20 self._popup_end()
7.21 self.stream.write("</span>\n")
7.22 self.stream.write("</span>\n")
7.23 @@ -587,8 +587,8 @@
7.24 targets = getattr(node, "_nodes", [target])
7.25 self._name_start(target.name)
7.26 self._popup_start()
7.27 - self._types(targets) # target.expr
7.28 self._scopes(targets)
7.29 + self._types(targets)
7.30 self._popup_end()
7.31 self._name_end()
7.32
7.33 @@ -666,8 +666,8 @@
7.34 self.stream.write("<span class='attr'>\n")
7.35 self.stream.write(".%s\n" % self._text(node.attrname))
7.36 self._popup_start()
7.37 + self._scopes(targets)
7.38 self._types(targets)
7.39 - self._scopes(targets)
7.40 self._popup_end()
7.41 self.stream.write("</span>\n")
7.42 self.stream.write("</span>\n")
7.43 @@ -703,8 +703,8 @@
7.44 targets = getattr(node, "_nodes", [target])
7.45 self._name_start(target.name)
7.46 self._popup_start()
7.47 + self._scopes(targets)
7.48 self._types(targets)
7.49 - self._scopes(targets)
7.50 self._popup_end()
7.51 self._name_end()
7.52