From: Jeremy Hylton Date: Mon, 17 Dec 2001 23:58:08 +0000 (+0000) Subject: Backport bugfixes from the trunk. X-Git-Tag: v2.1.2c1~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2dfc9a3add2424c7d903a889ac9ab33c47f9ce76;p=thirdparty%2FPython%2Fcpython.git Backport bugfixes from the trunk. Add __getitem__() to a stack to support visitContinue(). Move mangle() here and define correctly. --- diff --git a/Tools/compiler/compiler/misc.py b/Tools/compiler/compiler/misc.py index 29ff86678025..1727401b2d66 100644 --- a/Tools/compiler/compiler/misc.py +++ b/Tools/compiler/compiler/misc.py @@ -39,3 +39,29 @@ class Stack: self.stack.append(elt) def top(self): return self.stack[-1] + def __getitem__(self, index): # needed by visitContinue() + return self.stack[index] + +MANGLE_LEN = 256 # magic constant from compile.c + +def mangle(name, klass): + if not name.startswith('__'): + return name + if len(name) + 2 >= MANGLE_LEN: + return name + if name.endswith('__'): + return name + try: + i = 0 + while klass[i] == '_': + i = i + 1 + except IndexError: + return name + klass = klass[i:] + + tlen = len(klass) + len(name) + if tlen > MANGLE_LEN: + klass = klass[:MANGLE_LEN-tlen] + + return "_%s%s" % (klass, name) +