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. This file is automatically generated.
""" """
# XXX performance issues:
# 1. getChildren() could be more efficient for many cases
from types import TupleType, ListType from types import TupleType, ListType
from consts import CO_VARARGS, CO_VARKEYWORDS from consts import CO_VARARGS, CO_VARKEYWORDS
@ -193,7 +190,7 @@ class Sub(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class ListCompIf(Node):
nodes["listcompif"] = "ListCompIf" nodes["listcompif"] = "ListCompIf"
@ -212,7 +209,7 @@ class Div(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Discard(Node):
nodes["discard"] = "Discard" nodes["discard"] = "Discard"
@ -240,7 +237,7 @@ class RightShift(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Continue(Node):
nodes["continue"] = "Continue" nodes["continue"] = "Continue"
@ -280,7 +277,7 @@ class LeftShift(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Mul(Node):
nodes["mul"] = "Mul" nodes["mul"] = "Mul"
@ -290,7 +287,7 @@ class Mul(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Yield(Node):
nodes["yield"] = "Yield" nodes["yield"] = "Yield"
@ -368,7 +365,7 @@ class Mod(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Class(Node):
nodes["class"] = "Class" nodes["class"] = "Class"
@ -466,7 +463,7 @@ class Power(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Ellipsis(Node):
nodes["ellipsis"] = "Ellipsis" nodes["ellipsis"] = "Ellipsis"
@ -486,15 +483,6 @@ class Return(Node):
def __repr__(self): def __repr__(self):
return "Return(%s)" % (repr(self.value),) 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): class Add(Node):
nodes["add"] = "Add" nodes["add"] = "Add"
def __init__(self, (left, right)): def __init__(self, (left, right)):
@ -503,7 +491,7 @@ class Add(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Function(Node):
nodes["function"] = "Function" nodes["function"] = "Function"

View File

@ -81,6 +81,8 @@ class NodeInfo:
print >> buf, " def __repr__(self):" print >> buf, " def __repr__(self):"
if self.argnames: if self.argnames:
fmt = COMMA.join(["%s"] * self.nargs) fmt = COMMA.join(["%s"] * self.nargs)
if '(' in self.args:
fmt = '(%s)' % fmt
vals = ["repr(self.%s)" % name for name in self.argnames] vals = ["repr(self.%s)" % name for name in self.argnames]
vals = COMMA.join(vals) vals = COMMA.join(vals)
if self.nargs == 1: if self.nargs == 1:

View File

@ -2,9 +2,6 @@
This file is automatically generated. This file is automatically generated.
""" """
# XXX performance issues:
# 1. getChildren() could be more efficient for many cases
from types import TupleType, ListType from types import TupleType, ListType
from consts import CO_VARARGS, CO_VARKEYWORDS from consts import CO_VARARGS, CO_VARKEYWORDS
@ -193,7 +190,7 @@ class Sub(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class ListCompIf(Node):
nodes["listcompif"] = "ListCompIf" nodes["listcompif"] = "ListCompIf"
@ -212,7 +209,7 @@ class Div(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Discard(Node):
nodes["discard"] = "Discard" nodes["discard"] = "Discard"
@ -240,7 +237,7 @@ class RightShift(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Continue(Node):
nodes["continue"] = "Continue" nodes["continue"] = "Continue"
@ -280,7 +277,7 @@ class LeftShift(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Mul(Node):
nodes["mul"] = "Mul" nodes["mul"] = "Mul"
@ -290,7 +287,7 @@ class Mul(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Yield(Node):
nodes["yield"] = "Yield" nodes["yield"] = "Yield"
@ -368,7 +365,7 @@ class Mod(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Class(Node):
nodes["class"] = "Class" nodes["class"] = "Class"
@ -466,7 +463,7 @@ class Power(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Ellipsis(Node):
nodes["ellipsis"] = "Ellipsis" nodes["ellipsis"] = "Ellipsis"
@ -486,15 +483,6 @@ class Return(Node):
def __repr__(self): def __repr__(self):
return "Return(%s)" % (repr(self.value),) 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): class Add(Node):
nodes["add"] = "Add" nodes["add"] = "Add"
def __init__(self, (left, right)): def __init__(self, (left, right)):
@ -503,7 +491,7 @@ class Add(Node):
def _getChildren(self): def _getChildren(self):
return self.left, self.right return self.left, self.right
def __repr__(self): 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): class Function(Node):
nodes["function"] = "Function" nodes["function"] = "Function"

View File

@ -81,6 +81,8 @@ class NodeInfo:
print >> buf, " def __repr__(self):" print >> buf, " def __repr__(self):"
if self.argnames: if self.argnames:
fmt = COMMA.join(["%s"] * self.nargs) fmt = COMMA.join(["%s"] * self.nargs)
if '(' in self.args:
fmt = '(%s)' % fmt
vals = ["repr(self.%s)" % name for name in self.argnames] vals = ["repr(self.%s)" % name for name in self.argnames]
vals = COMMA.join(vals) vals = COMMA.join(vals)
if self.nargs == 1: if self.nargs == 1: