1.1 --- a/micropython/data.py Sun Nov 22 23:53:30 2009 +0100
1.2 +++ b/micropython/data.py Mon Nov 23 01:22:06 2009 +0100
1.3 @@ -374,20 +374,33 @@
1.4 def _merge_branches(self):
1.5 active = self.attributes_used[-1]
1.6
1.7 + # Take each alternative branch, currently shelved, and find the
1.8 + # intersection of their contributions for each name.
1.9 +
1.10 shelved_defs = self.attribute_shelves.pop()
1.11 - defs = shelved_defs[0]
1.12 + defs = dict(shelved_defs[0])
1.13
1.14 for next_defs in shelved_defs[1:]:
1.15 for name, attrnames in next_defs.items():
1.16 if defs.has_key(name):
1.17 defs[name] = defs[name].intersection(attrnames)
1.18
1.19 + # Intersect the contributions with the previous state for each name.
1.20 +
1.21 for name, attrnames in defs.items():
1.22 if active.has_key(name):
1.23 active[name].intersection_update(attrnames)
1.24 else:
1.25 active[name] = attrnames
1.26
1.27 + # Where each shelved set of definitions is a superset of the eventual
1.28 + # definitions for a name, record these specialised sets of usage.
1.29 +
1.30 + for defs in shelved_defs:
1.31 + for name, attrnames in defs.items():
1.32 + if attrnames.issuperset(active[name]):
1.33 + self.all_attributes_used.append(attrnames)
1.34 +
1.35 # Program data structures. There are two separate kinds of structures: those
1.36 # with context, which are the values manipulated by programs, and those without
1.37 # context, which are typically constant things which are stored alongside the
2.1 --- a/tests/attribute_access_type_restriction.py Sun Nov 22 23:53:30 2009 +0100
2.2 +++ b/tests/attribute_access_type_restriction.py Mon Nov 23 01:22:06 2009 +0100
2.3 @@ -18,15 +18,6 @@
2.4 def h(self):
2.5 return 5
2.6
2.7 -def test_conditional(obj):
2.8 - # obj: C, D, E (f)
2.9 - if obj.f(): # C, D, E (f)
2.10 - obj.g() # D (f, g)
2.11 - # else:
2.12 - # ... # obj: C, D, E (f)
2.13 - # # (f, g) ^ (f)
2.14 - return 2
2.15 -
2.16 def test_new(obj, obj2):
2.17 # obj: C, D, E (f)
2.18 # obj2:
2.19 @@ -62,7 +53,6 @@
2.20 c = C()
2.21 d = D()
2.22 e = E()
2.23 -result1_2 = test_conditional(d)
2.24 result2_2 = test_new(c, d)
2.25 result1_4 = test_neither(c, d)
2.26 result1_5 = test_new_conditional(e, d)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/attribute_access_type_restriction_conditional.py Mon Nov 23 01:22:06 2009 +0100
3.3 @@ -0,0 +1,35 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +class C:
3.7 + def f(self):
3.8 + return 1
3.9 +
3.10 +class D:
3.11 + def f(self):
3.12 + return 2
3.13 +
3.14 + def g(self):
3.15 + return 3
3.16 +
3.17 +class E:
3.18 + def f(self):
3.19 + return 4
3.20 +
3.21 + def h(self):
3.22 + return 5
3.23 +
3.24 +def test_conditional(obj):
3.25 + # obj: C, D, E (f)
3.26 + if obj.f(): # C, D, E (f)
3.27 + obj.g() # D (f, g)
3.28 + # else:
3.29 + # ... # obj: C, D, E (f)
3.30 + # # (f, g) ^ (f)
3.31 + return 2
3.32 +
3.33 +c = C()
3.34 +d = D()
3.35 +e = E()
3.36 +result1_2 = test_conditional(d)
3.37 +
3.38 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/attribute_access_type_restriction_conditional_choice.py Mon Nov 23 01:22:06 2009 +0100
4.3 @@ -0,0 +1,35 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +class C:
4.7 + def f(self):
4.8 + return 1
4.9 +
4.10 +class D:
4.11 + def f(self):
4.12 + return 2
4.13 +
4.14 + def g(self):
4.15 + return 3
4.16 +
4.17 +class E:
4.18 + def f(self):
4.19 + return 4
4.20 +
4.21 + def h(self):
4.22 + return 5
4.23 +
4.24 +def test_conditional(obj):
4.25 + # obj: C, D, E (f)
4.26 + if obj.f(): # C, D, E (f)
4.27 + obj.g() # D (f, g)
4.28 + else:
4.29 + obj.h() # E (f, h)
4.30 + # # (f, g) ^ (f, h)
4.31 + return 2
4.32 +
4.33 +c = C()
4.34 +d = D()
4.35 +e = E()
4.36 +result1_2 = test_conditional(d)
4.37 +
4.38 +# vim: tabstop=4 expandtab shiftwidth=4