[pypy-svn] r24119 - in pypy/dist/pypy/translator/squeak: . test
nik at codespeak.net
nik at codespeak.net
Wed Mar 8 18:31:11 CET 2006
Author: nik
Date: Wed Mar 8 18:31:10 2006
New Revision: 24119
Modified:
pypy/dist/pypy/translator/squeak/gensqueak.py
pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py
Log:
avoid another type of nameclash that can occur because underlines need
to be stripped from identifiers in smalltalk.
Modified: pypy/dist/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/gensqueak.py (original)
+++ pypy/dist/pypy/translator/squeak/gensqueak.py Wed Mar 8 18:31:10 2006
@@ -6,6 +6,10 @@
from pypy.translator.unsimplify import remove_direct_loops
from pypy.translator.simplify import simplify_graph
from pypy import conftest
+try:
+ set
+except NameError:
+ from sets import Set as set
def camel_case(str):
words = str.split('_')
@@ -99,6 +103,8 @@
Constant(True).key: 'true',
}
self.seennames = {}
+ self.seen_class_names = set()
+ self.class_name_mapping = {}
self.pendinggraphs = []
self.pendingclasses = []
self.pendingmethods = []
@@ -250,7 +256,18 @@
# never contain user classes.
class_name = "%s_%s" \
% (INSTANCE._package.replace(".", "_"), INSTANCE._name)
- return "Py%s" % camel_case(class_name.capitalize())
+ if self.class_name_mapping.has_key(class_name):
+ squeak_class_name = self.class_name_mapping[class_name]
+ else:
+ class_basename = camel_case(class_name.capitalize())
+ squeak_class_name = class_basename
+ ext = 0
+ while squeak_class_name in self.seen_class_names:
+ squeak_class_name = class_basename + str(ext)
+ ext += 1
+ self.class_name_mapping[class_name] = squeak_class_name
+ self.seen_class_names.add(squeak_class_name)
+ return "Py%s" % squeak_class_name
def nameof__instance(self, _inst):
return self.nameof_Instance(_inst._TYPE)
Modified: pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py (original)
+++ pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py Wed Mar 8 18:31:10 2006
@@ -123,6 +123,16 @@
return A().m(0) + A2().m(0)
assert self.run_on_squeak(f) == "3"
+ def test_nameclash_camel_case(self):
+ class ASomething:
+ def m(self, i): return 1 + i
+ class Asomething:
+ def m(self, i): return 2 + i
+ def f():
+ x = ASomething().m(0) + Asomething().m(0)
+ return x + ASomething().m(0) + Asomething().m(0)
+ assert self.run_on_squeak(f) == "6"
+
class TestSelector:
More information about the Pypy-commit
mailing list