0
0
mirror of https://github.com/python/cpython.git synced 2024-12-01 11:15:56 +01:00

Generate correct reprs for Mul, Add, etc.

This commit is contained in:
Jeremy Hylton 2001-08-18 00:14:37 +00:00
parent ec5bfd13ca
commit ab427b8cce
4 changed files with 20 additions and 40 deletions

View File

@ -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"

View File

@ -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:

View File

@ -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"

View File

@ -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: