summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-08-18 00:14:37 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-08-18 00:14:37 (GMT)
commitab427b8ccedacf94acdc0149fc8fb24f8c58c272 (patch)
tree34d58e081f96a0db82ca42805ee30147bfb2bd65 /Tools
parentec5bfd13cada33ed36f93fd76b1355ce9ee2710f (diff)
downloadcpython-ab427b8ccedacf94acdc0149fc8fb24f8c58c272.zip
cpython-ab427b8ccedacf94acdc0149fc8fb24f8c58c272.tar.gz
cpython-ab427b8ccedacf94acdc0149fc8fb24f8c58c272.tar.bz2
Generate correct reprs for Mul, Add, etc.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/compiler/astgen.py2
-rw-r--r--Tools/compiler/compiler/ast.py28
-rw-r--r--Tools/compiler/compiler/astgen.py2
3 files changed, 12 insertions, 20 deletions
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: