From ab427b8ccedacf94acdc0149fc8fb24f8c58c272 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Sat, 18 Aug 2001 00:14:37 +0000 Subject: Generate correct reprs for Mul, Add, etc. --- Lib/compiler/ast.py | 28 ++++++++-------------------- Tools/compiler/astgen.py | 2 ++ Tools/compiler/compiler/ast.py | 28 ++++++++-------------------- Tools/compiler/compiler/astgen.py | 2 ++ 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py index 7f29770..a160d29 100644 --- a/Lib/compiler/ast.py +++ b/Lib/compiler/ast.py @@ -2,9 +2,6 @@ This file is automatically generated. """ -# XXX performance issues: -# 1. getChildren() could be more efficient for many cases - from types import TupleType, ListType from consts import CO_VARARGS, CO_VARKEYWORDS @@ -193,7 +190,7 @@ class Sub(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Sub(%s, %s)" % (repr(self.left), repr(self.right)) + return "Sub((%s, %s))" % (repr(self.left), repr(self.right)) class ListCompIf(Node): nodes["listcompif"] = "ListCompIf" @@ -212,7 +209,7 @@ class Div(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Div(%s, %s)" % (repr(self.left), repr(self.right)) + return "Div((%s, %s))" % (repr(self.left), repr(self.right)) class Discard(Node): nodes["discard"] = "Discard" @@ -240,7 +237,7 @@ class RightShift(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "RightShift(%s, %s)" % (repr(self.left), repr(self.right)) + return "RightShift((%s, %s))" % (repr(self.left), repr(self.right)) class Continue(Node): nodes["continue"] = "Continue" @@ -280,7 +277,7 @@ class LeftShift(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "LeftShift(%s, %s)" % (repr(self.left), repr(self.right)) + return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right)) class Mul(Node): nodes["mul"] = "Mul" @@ -290,7 +287,7 @@ class Mul(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Mul(%s, %s)" % (repr(self.left), repr(self.right)) + return "Mul((%s, %s))" % (repr(self.left), repr(self.right)) class Yield(Node): nodes["yield"] = "Yield" @@ -368,7 +365,7 @@ class Mod(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Mod(%s, %s)" % (repr(self.left), repr(self.right)) + return "Mod((%s, %s))" % (repr(self.left), repr(self.right)) class Class(Node): nodes["class"] = "Class" @@ -466,7 +463,7 @@ class Power(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Power(%s, %s)" % (repr(self.left), repr(self.right)) + return "Power((%s, %s))" % (repr(self.left), repr(self.right)) class Ellipsis(Node): nodes["ellipsis"] = "Ellipsis" @@ -486,15 +483,6 @@ class Return(Node): def __repr__(self): return "Return(%s)" % (repr(self.value),) -class Yield(Node): - nodes["yield"] = "Yield" - def __init__(self, value): - self.value = value - def _getChildren(self): - return self.value, - def __repr__(self): - return "Yield(%s)" % repr(self.value) - class Add(Node): nodes["add"] = "Add" def __init__(self, (left, right)): @@ -503,7 +491,7 @@ class Add(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Add(%s, %s)" % (repr(self.left), repr(self.right)) + return "Add((%s, %s))" % (repr(self.left), repr(self.right)) class Function(Node): nodes["function"] = "Function" diff --git a/Tools/compiler/astgen.py b/Tools/compiler/astgen.py index 9386bf0..c0eb464 100644 --- a/Tools/compiler/astgen.py +++ b/Tools/compiler/astgen.py @@ -81,6 +81,8 @@ class NodeInfo: print >> buf, " def __repr__(self):" if self.argnames: fmt = COMMA.join(["%s"] * self.nargs) + if '(' in self.args: + fmt = '(%s)' % fmt vals = ["repr(self.%s)" % name for name in self.argnames] vals = COMMA.join(vals) if self.nargs == 1: diff --git a/Tools/compiler/compiler/ast.py b/Tools/compiler/compiler/ast.py index 7f29770..a160d29 100644 --- a/Tools/compiler/compiler/ast.py +++ b/Tools/compiler/compiler/ast.py @@ -2,9 +2,6 @@ This file is automatically generated. """ -# XXX performance issues: -# 1. getChildren() could be more efficient for many cases - from types import TupleType, ListType from consts import CO_VARARGS, CO_VARKEYWORDS @@ -193,7 +190,7 @@ class Sub(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Sub(%s, %s)" % (repr(self.left), repr(self.right)) + return "Sub((%s, %s))" % (repr(self.left), repr(self.right)) class ListCompIf(Node): nodes["listcompif"] = "ListCompIf" @@ -212,7 +209,7 @@ class Div(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Div(%s, %s)" % (repr(self.left), repr(self.right)) + return "Div((%s, %s))" % (repr(self.left), repr(self.right)) class Discard(Node): nodes["discard"] = "Discard" @@ -240,7 +237,7 @@ class RightShift(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "RightShift(%s, %s)" % (repr(self.left), repr(self.right)) + return "RightShift((%s, %s))" % (repr(self.left), repr(self.right)) class Continue(Node): nodes["continue"] = "Continue" @@ -280,7 +277,7 @@ class LeftShift(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "LeftShift(%s, %s)" % (repr(self.left), repr(self.right)) + return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right)) class Mul(Node): nodes["mul"] = "Mul" @@ -290,7 +287,7 @@ class Mul(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Mul(%s, %s)" % (repr(self.left), repr(self.right)) + return "Mul((%s, %s))" % (repr(self.left), repr(self.right)) class Yield(Node): nodes["yield"] = "Yield" @@ -368,7 +365,7 @@ class Mod(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Mod(%s, %s)" % (repr(self.left), repr(self.right)) + return "Mod((%s, %s))" % (repr(self.left), repr(self.right)) class Class(Node): nodes["class"] = "Class" @@ -466,7 +463,7 @@ class Power(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Power(%s, %s)" % (repr(self.left), repr(self.right)) + return "Power((%s, %s))" % (repr(self.left), repr(self.right)) class Ellipsis(Node): nodes["ellipsis"] = "Ellipsis" @@ -486,15 +483,6 @@ class Return(Node): def __repr__(self): return "Return(%s)" % (repr(self.value),) -class Yield(Node): - nodes["yield"] = "Yield" - def __init__(self, value): - self.value = value - def _getChildren(self): - return self.value, - def __repr__(self): - return "Yield(%s)" % repr(self.value) - class Add(Node): nodes["add"] = "Add" def __init__(self, (left, right)): @@ -503,7 +491,7 @@ class Add(Node): def _getChildren(self): return self.left, self.right def __repr__(self): - return "Add(%s, %s)" % (repr(self.left), repr(self.right)) + return "Add((%s, %s))" % (repr(self.left), repr(self.right)) class Function(Node): nodes["function"] = "Function" diff --git a/Tools/compiler/compiler/astgen.py b/Tools/compiler/compiler/astgen.py index 9386bf0..c0eb464 100644 --- a/Tools/compiler/compiler/astgen.py +++ b/Tools/compiler/compiler/astgen.py @@ -81,6 +81,8 @@ class NodeInfo: print >> buf, " def __repr__(self):" if self.argnames: fmt = COMMA.join(["%s"] * self.nargs) + if '(' in self.args: + fmt = '(%s)' % fmt vals = ["repr(self.%s)" % name for name in self.argnames] vals = COMMA.join(vals) if self.nargs == 1: -- cgit v0.12