diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-08-27 22:56:16 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-08-27 22:56:16 (GMT) |
commit | c59e22000082722655517942d7662eec5a4a70ce (patch) | |
tree | 9657ac8cb34b3b319ac0333ae0f5fe0239f8ccd0 /Lib/compiler/symbols.py | |
parent | e7d8322630f82d22984987a97c11371ddacba59e (diff) | |
download | cpython-c59e22000082722655517942d7662eec5a4a70ce.zip cpython-c59e22000082722655517942d7662eec5a4a70ce.tar.gz cpython-c59e22000082722655517942d7662eec5a4a70ce.tar.bz2 |
Handle private names
(Hard to believe these were never handled before)
Add misc.mangle() that mangles based on the rules in compile.c.
XXX Need to test the corner cases
Update CodeGenerator with a class_name attribute bound to None. If a
particular instance is created within a class scope, the instance's
class_name is bound to that class's name.
Add mangle() method to CodeGenerator that mangles if the class_name
has a class_name in it.
Modify the FunctionCodeGenerator family to handle an extra argument--
the class_name.
Wrap all name ops and attrnames in calls to self.mangle()
Diffstat (limited to 'Lib/compiler/symbols.py')
-rw-r--r-- | Lib/compiler/symbols.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Lib/compiler/symbols.py b/Lib/compiler/symbols.py index 0ef0d12..40fd127 100644 --- a/Lib/compiler/symbols.py +++ b/Lib/compiler/symbols.py @@ -2,8 +2,10 @@ from compiler import ast from compiler.consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL, SC_UNKNOWN +from compiler.misc import mangle import types + import sys MANGLE_LEN = 256 @@ -36,13 +38,7 @@ class Scope: def mangle(self, name): if self.klass is None: return name - if not name.startswith('__'): - return name - if len(name) + 2 >= MANGLE_LEN: - return name - if name.endswith('__'): - return name - return "_%s%s" % (self.klass, name) + return mangle(name, self.klass) def add_def(self, name): self.defs[self.mangle(name)] = 1 |