[pypy-svn] r36619 - in pypy/dist/pypy/rpython/ootypesystem: . test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jan 12 21:14:55 CET 2007
Author: antocuni
Date: Fri Jan 12 21:14:46 2007
New Revision: 36619
Modified:
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py
Log:
Make ootype.Instance record its subclasses. This feature will be used
by the check_virtual_methods backend optimization.
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Fri Jan 12 21:14:46 2007
@@ -46,12 +46,14 @@
_is_root=False, _hints = {}):
self._name = name
self._hints = frozendict(_hints)
+ self._subclasses = []
if _is_root:
self._superclass = None
else:
assert isinstance(superclass, Instance)
self._superclass = superclass
+ self._superclass._add_subclass(self)
self._methods = frozendict()
self._fields = frozendict()
@@ -82,6 +84,10 @@
def __str__(self):
return '%s(%s)' % (self.__class__.__name__, self._name)
+ def _add_subclass(self, INSTANCE):
+ assert isinstance(INSTANCE, Instance)
+ self._subclasses.append(INSTANCE)
+
def _add_fields(self, fields):
fields = fields.copy() # mutated below
for name, defn in fields.iteritems():
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py Fri Jan 12 21:14:46 2007
@@ -423,3 +423,15 @@
# Instance compares by reference
assert not A == B
assert A != B
+
+def test_subclasses():
+ A = Instance("A", ROOT)
+ B = Instance("B", A)
+ C = Instance("C", A)
+ D = Instance("D", C)
+
+ assert A in ROOT._subclasses
+ assert B in A._subclasses
+ assert not B._subclasses
+ assert C in A._subclasses
+ assert D in C._subclasses
More information about the pypy-svn
mailing list