summaryrefslogtreecommitdiffstats
path: root/Tools/compiler
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-09-17 20:17:02 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-09-17 20:17:02 (GMT)
commitc8ed18a4e3756f0cccbcddd10323ef536ad003ec (patch)
tree99fd1e4b627ae18cf7c6890301f94ca24de5e884 /Tools/compiler
parenteab4328f1a4de03e527c746086f73c8a4d6f6b08 (diff)
downloadcpython-c8ed18a4e3756f0cccbcddd10323ef536ad003ec.zip
cpython-c8ed18a4e3756f0cccbcddd10323ef536ad003ec.tar.gz
cpython-c8ed18a4e3756f0cccbcddd10323ef536ad003ec.tar.bz2
Re-created after change to astgen to calculate hardest_arg correctly
Diffstat (limited to 'Tools/compiler')
-rw-r--r--Tools/compiler/compiler/ast.py1180
1 files changed, 603 insertions, 577 deletions
diff --git a/Tools/compiler/compiler/ast.py b/Tools/compiler/compiler/ast.py
index 53dc410..9a5d53c 100644
--- a/Tools/compiler/compiler/ast.py
+++ b/Tools/compiler/compiler/ast.py
@@ -48,415 +48,455 @@ class Node: # an abstract base class
class EmptyNode(Node):
pass
-class If(Node):
- nodes["if"] = "If"
- def __init__(self, tests, else_):
- self.tests = tests
- self.else_ = else_
+class Slice(Node):
+ nodes["slice"] = "Slice"
+ def __init__(self, expr, flags, lower, upper):
+ self.expr = expr
+ self.flags = flags
+ self.lower = lower
+ self.upper = upper
def getChildren(self):
children = []
- children.extend(flatten(self.tests))
- children.append(self.else_)
+ children.append(self.expr)
+ children.append(self.flags)
+ children.append(self.lower)
+ children.append(self.upper)
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.extend(flatten_nodes(self.tests))
- if self.else_ is not None: nodes.append(self.else_)
+ nodes.append(self.expr)
+ if self.lower is not None: nodes.append(self.lower)
+ if self.upper is not None: nodes.append(self.upper)
return tuple(nodes)
def __repr__(self):
- return "If(%s, %s)" % (repr(self.tests), repr(self.else_))
+ return "Slice(%s, %s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.lower), repr(self.upper))
-class ListComp(Node):
- nodes["listcomp"] = "ListComp"
- def __init__(self, expr, quals):
- self.expr = expr
- self.quals = quals
+class Const(Node):
+ nodes["const"] = "Const"
+ def __init__(self, value):
+ self.value = value
+
+ def getChildren(self):
+ return self.value,
+
+ def getChildNodes(self):
+ return ()
+
+ def __repr__(self):
+ return "Const(%s)" % (repr(self.value),)
+
+class Raise(Node):
+ nodes["raise"] = "Raise"
+ def __init__(self, expr1, expr2, expr3):
+ self.expr1 = expr1
+ self.expr2 = expr2
+ self.expr3 = expr3
def getChildren(self):
children = []
- children.append(self.expr)
- children.extend(flatten(self.quals))
+ children.append(self.expr1)
+ children.append(self.expr2)
+ children.append(self.expr3)
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.append(self.expr)
- nodes.extend(flatten_nodes(self.quals))
+ if self.expr1 is not None: nodes.append(self.expr1)
+ if self.expr2 is not None: nodes.append(self.expr2)
+ if self.expr3 is not None: nodes.append(self.expr3)
return tuple(nodes)
def __repr__(self):
- return "ListComp(%s, %s)" % (repr(self.expr), repr(self.quals))
+ return "Raise(%s, %s, %s)" % (repr(self.expr1), repr(self.expr2), repr(self.expr3))
-class Bitor(Node):
- nodes["bitor"] = "Bitor"
- def __init__(self, nodes):
- self.nodes = nodes
+class For(Node):
+ nodes["for"] = "For"
+ def __init__(self, assign, list, body, else_):
+ self.assign = assign
+ self.list = list
+ self.body = body
+ self.else_ = else_
def getChildren(self):
children = []
- children.extend(flatten(self.nodes))
+ children.append(self.assign)
+ children.append(self.list)
+ children.append(self.body)
+ children.append(self.else_)
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.extend(flatten_nodes(self.nodes))
+ nodes.append(self.assign)
+ nodes.append(self.list)
+ nodes.append(self.body)
+ if self.else_ is not None: nodes.append(self.else_)
return tuple(nodes)
def __repr__(self):
- return "Bitor(%s)" % (repr(self.nodes),)
+ return "For(%s, %s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.body), repr(self.else_))
-class Pass(Node):
- nodes["pass"] = "Pass"
- def __init__(self, ):
- pass
+class AssTuple(Node):
+ nodes["asstuple"] = "AssTuple"
+ def __init__(self, nodes):
+ self.nodes = nodes
def getChildren(self):
- return ()
+ children = []
+ children.extend(flatten(self.nodes))
+ return tuple(children)
def getChildNodes(self):
- return ()
+ nodes = []
+ nodes.extend(flatten_nodes(self.nodes))
+ return tuple(nodes)
def __repr__(self):
- return "Pass()"
+ return "AssTuple(%s)" % (repr(self.nodes),)
-class Module(Node):
- nodes["module"] = "Module"
- def __init__(self, doc, node):
- self.doc = doc
- self.node = node
+class Mul(Node):
+ nodes["mul"] = "Mul"
+ def __init__(self, (left, right)):
+ self.left = left
+ self.right = right
def getChildren(self):
- return self.doc, self.node
+ return self.left, self.right
def getChildNodes(self):
- return self.node,
+ return self.left, self.right
def __repr__(self):
- return "Module(%s, %s)" % (repr(self.doc), repr(self.node))
+ return "Mul((%s, %s))" % (repr(self.left), repr(self.right))
-class Global(Node):
- nodes["global"] = "Global"
- def __init__(self, names):
- self.names = names
+class Invert(Node):
+ nodes["invert"] = "Invert"
+ def __init__(self, expr):
+ self.expr = expr
def getChildren(self):
- return self.names,
+ return self.expr,
def getChildNodes(self):
- return ()
+ return self.expr,
def __repr__(self):
- return "Global(%s)" % (repr(self.names),)
+ return "Invert(%s)" % (repr(self.expr),)
-class CallFunc(Node):
- nodes["callfunc"] = "CallFunc"
- def __init__(self, node, args, star_args = None, dstar_args = None):
- self.node = node
- self.args = args
- self.star_args = star_args
- self.dstar_args = dstar_args
+class RightShift(Node):
+ nodes["rightshift"] = "RightShift"
+ def __init__(self, (left, right)):
+ self.left = left
+ self.right = right
def getChildren(self):
- children = []
- children.append(self.node)
- children.extend(flatten(self.args))
- children.append(self.star_args)
- children.append(self.dstar_args)
- return tuple(children)
+ return self.left, self.right
def getChildNodes(self):
- nodes = []
- nodes.append(self.node)
- nodes.extend(flatten_nodes(self.args))
- if self.star_args is not None: nodes.append(self.star_args)
- if self.dstar_args is not None: nodes.append(self.dstar_args)
- return tuple(nodes)
+ return self.left, self.right
def __repr__(self):
- return "CallFunc(%s, %s, %s, %s)" % (repr(self.node), repr(self.args), repr(self.star_args), repr(self.dstar_args))
+ return "RightShift((%s, %s))" % (repr(self.left), repr(self.right))
-class Printnl(Node):
- nodes["printnl"] = "Printnl"
- def __init__(self, nodes, dest):
+class AssList(Node):
+ nodes["asslist"] = "AssList"
+ def __init__(self, nodes):
self.nodes = nodes
- self.dest = dest
def getChildren(self):
children = []
children.extend(flatten(self.nodes))
- children.append(self.dest)
return tuple(children)
def getChildNodes(self):
nodes = []
nodes.extend(flatten_nodes(self.nodes))
- if self.dest is not None: nodes.append(self.dest)
return tuple(nodes)
def __repr__(self):
- return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest))
+ return "AssList(%s)" % (repr(self.nodes),)
-class Tuple(Node):
- nodes["tuple"] = "Tuple"
- def __init__(self, nodes):
- self.nodes = nodes
+class From(Node):
+ nodes["from"] = "From"
+ def __init__(self, modname, names):
+ self.modname = modname
+ self.names = names
def getChildren(self):
- children = []
- children.extend(flatten(self.nodes))
- return tuple(children)
+ return self.modname, self.names
def getChildNodes(self):
- nodes = []
- nodes.extend(flatten_nodes(self.nodes))
- return tuple(nodes)
+ return ()
def __repr__(self):
- return "Tuple(%s)" % (repr(self.nodes),)
+ return "From(%s, %s)" % (repr(self.modname), repr(self.names))
-class Compare(Node):
- nodes["compare"] = "Compare"
- def __init__(self, expr, ops):
+class Getattr(Node):
+ nodes["getattr"] = "Getattr"
+ def __init__(self, expr, attrname):
self.expr = expr
- self.ops = ops
+ self.attrname = attrname
def getChildren(self):
- children = []
- children.append(self.expr)
- children.extend(flatten(self.ops))
- return tuple(children)
+ return self.expr, self.attrname
def getChildNodes(self):
- nodes = []
- nodes.append(self.expr)
- nodes.extend(flatten_nodes(self.ops))
- return tuple(nodes)
+ return self.expr,
def __repr__(self):
- return "Compare(%s, %s)" % (repr(self.expr), repr(self.ops))
+ return "Getattr(%s, %s)" % (repr(self.expr), repr(self.attrname))
-class And(Node):
- nodes["and"] = "And"
- def __init__(self, nodes):
- self.nodes = nodes
+class Dict(Node):
+ nodes["dict"] = "Dict"
+ def __init__(self, items):
+ self.items = items
def getChildren(self):
children = []
- children.extend(flatten(self.nodes))
+ children.extend(flatten(self.items))
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.extend(flatten_nodes(self.nodes))
+ nodes.extend(flatten_nodes(self.items))
return tuple(nodes)
def __repr__(self):
- return "And(%s)" % (repr(self.nodes),)
-
-class Lambda(Node):
- nodes["lambda"] = "Lambda"
- def __init__(self, argnames, defaults, flags, code):
- self.argnames = argnames
- self.defaults = defaults
- self.flags = flags
- self.code = code
- self.varargs = self.kwargs = None
- if flags & CO_VARARGS:
- self.varargs = 1
- if flags & CO_VARKEYWORDS:
- self.kwargs = 1
+ return "Dict(%s)" % (repr(self.items),)
+class Module(Node):
+ nodes["module"] = "Module"
+ def __init__(self, doc, node):
+ self.doc = doc
+ self.node = node
def getChildren(self):
- return self.argnames, self.defaults, self.flags, self.code
+ return self.doc, self.node
def getChildNodes(self):
- return self.code,
+ return self.node,
def __repr__(self):
- return "Lambda(%s, %s, %s, %s)" % (repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.code))
+ return "Module(%s, %s)" % (repr(self.doc), repr(self.node))
-class Assign(Node):
- nodes["assign"] = "Assign"
- def __init__(self, nodes, expr):
- self.nodes = nodes
+class UnaryAdd(Node):
+ nodes["unaryadd"] = "UnaryAdd"
+ def __init__(self, expr):
self.expr = expr
def getChildren(self):
- children = []
- children.extend(flatten(self.nodes))
- children.append(self.expr)
- return tuple(children)
+ return self.expr,
def getChildNodes(self):
- nodes = []
- nodes.extend(flatten_nodes(self.nodes))
- nodes.append(self.expr)
- return tuple(nodes)
+ return self.expr,
def __repr__(self):
- return "Assign(%s, %s)" % (repr(self.nodes), repr(self.expr))
+ return "UnaryAdd(%s)" % (repr(self.expr),)
-class Sub(Node):
- nodes["sub"] = "Sub"
- def __init__(self, (left, right)):
- self.left = left
- self.right = right
+class Ellipsis(Node):
+ nodes["ellipsis"] = "Ellipsis"
+ def __init__(self, ):
+ pass
def getChildren(self):
- return self.left, self.right
+ return ()
def getChildNodes(self):
- return self.left, self.right
+ return ()
def __repr__(self):
- return "Sub((%s, %s))" % (repr(self.left), repr(self.right))
+ return "Ellipsis()"
-class ListCompIf(Node):
- nodes["listcompif"] = "ListCompIf"
- def __init__(self, test):
- self.test = test
+class Print(Node):
+ nodes["print"] = "Print"
+ def __init__(self, nodes, dest):
+ self.nodes = nodes
+ self.dest = dest
def getChildren(self):
- return self.test,
+ children = []
+ children.extend(flatten(self.nodes))
+ children.append(self.dest)
+ return tuple(children)
def getChildNodes(self):
- return self.test,
+ nodes = []
+ nodes.extend(flatten_nodes(self.nodes))
+ if self.dest is not None: nodes.append(self.dest)
+ return tuple(nodes)
def __repr__(self):
- return "ListCompIf(%s)" % (repr(self.test),)
+ return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest))
-class Div(Node):
- nodes["div"] = "Div"
- def __init__(self, (left, right)):
- self.left = left
- self.right = right
+class Import(Node):
+ nodes["import"] = "Import"
+ def __init__(self, names):
+ self.names = names
def getChildren(self):
- return self.left, self.right
+ return self.names,
def getChildNodes(self):
- return self.left, self.right
+ return ()
def __repr__(self):
- return "Div((%s, %s))" % (repr(self.left), repr(self.right))
+ return "Import(%s)" % (repr(self.names),)
-class Discard(Node):
- nodes["discard"] = "Discard"
- def __init__(self, expr):
+class Subscript(Node):
+ nodes["subscript"] = "Subscript"
+ def __init__(self, expr, flags, subs):
self.expr = expr
+ self.flags = flags
+ self.subs = subs
def getChildren(self):
- return self.expr,
+ children = []
+ children.append(self.expr)
+ children.append(self.flags)
+ children.extend(flatten(self.subs))
+ return tuple(children)
def getChildNodes(self):
- return self.expr,
+ nodes = []
+ nodes.append(self.expr)
+ nodes.extend(flatten_nodes(self.subs))
+ return tuple(nodes)
def __repr__(self):
- return "Discard(%s)" % (repr(self.expr),)
+ return "Subscript(%s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.subs))
-class Backquote(Node):
- nodes["backquote"] = "Backquote"
- def __init__(self, expr):
- self.expr = expr
+class TryExcept(Node):
+ nodes["tryexcept"] = "TryExcept"
+ def __init__(self, body, handlers, else_):
+ self.body = body
+ self.handlers = handlers
+ self.else_ = else_
def getChildren(self):
- return self.expr,
+ children = []
+ children.append(self.body)
+ children.extend(flatten(self.handlers))
+ children.append(self.else_)
+ return tuple(children)
def getChildNodes(self):
- return self.expr,
+ nodes = []
+ nodes.append(self.body)
+ nodes.extend(flatten_nodes(self.handlers))
+ if self.else_ is not None: nodes.append(self.else_)
+ return tuple(nodes)
def __repr__(self):
- return "Backquote(%s)" % (repr(self.expr),)
+ return "TryExcept(%s, %s, %s)" % (repr(self.body), repr(self.handlers), repr(self.else_))
-class RightShift(Node):
- nodes["rightshift"] = "RightShift"
- def __init__(self, (left, right)):
- self.left = left
- self.right = right
+class Or(Node):
+ nodes["or"] = "Or"
+ def __init__(self, nodes):
+ self.nodes = nodes
def getChildren(self):
- return self.left, self.right
+ children = []
+ children.extend(flatten(self.nodes))
+ return tuple(children)
def getChildNodes(self):
- return self.left, self.right
+ nodes = []
+ nodes.extend(flatten_nodes(self.nodes))
+ return tuple(nodes)
def __repr__(self):
- return "RightShift((%s, %s))" % (repr(self.left), repr(self.right))
+ return "Or(%s)" % (repr(self.nodes),)
-class Continue(Node):
- nodes["continue"] = "Continue"
- def __init__(self, ):
- pass
+class Name(Node):
+ nodes["name"] = "Name"
+ def __init__(self, name):
+ self.name = name
def getChildren(self):
- return ()
+ return self.name,
def getChildNodes(self):
return ()
def __repr__(self):
- return "Continue()"
+ return "Name(%s)" % (repr(self.name),)
+
+class Function(Node):
+ nodes["function"] = "Function"
+ def __init__(self, name, argnames, defaults, flags, doc, code):
+ self.name = name
+ self.argnames = argnames
+ self.defaults = defaults
+ self.flags = flags
+ self.doc = doc
+ self.code = code
+ self.varargs = self.kwargs = None
+ if flags & CO_VARARGS:
+ self.varargs = 1
+ if flags & CO_VARKEYWORDS:
+ self.kwargs = 1
+
-class While(Node):
- nodes["while"] = "While"
- def __init__(self, test, body, else_):
- self.test = test
- self.body = body
- self.else_ = else_
def getChildren(self):
children = []
- children.append(self.test)
- children.append(self.body)
- children.append(self.else_)
+ children.append(self.name)
+ children.append(self.argnames)
+ children.extend(flatten(self.defaults))
+ children.append(self.flags)
+ children.append(self.doc)
+ children.append(self.code)
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.append(self.test)
- nodes.append(self.body)
- if self.else_ is not None: nodes.append(self.else_)
+ nodes.extend(flatten_nodes(self.defaults))
+ nodes.append(self.code)
return tuple(nodes)
def __repr__(self):
- return "While(%s, %s, %s)" % (repr(self.test), repr(self.body), repr(self.else_))
+ return "Function(%s, %s, %s, %s, %s, %s)" % (repr(self.name), repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.doc), repr(self.code))
-class AssName(Node):
- nodes["assname"] = "AssName"
- def __init__(self, name, flags):
- self.name = name
- self.flags = flags
+class Assert(Node):
+ nodes["assert"] = "Assert"
+ def __init__(self, test, fail):
+ self.test = test
+ self.fail = fail
def getChildren(self):
- return self.name, self.flags
+ children = []
+ children.append(self.test)
+ children.append(self.fail)
+ return tuple(children)
def getChildNodes(self):
- return ()
+ nodes = []
+ nodes.append(self.test)
+ if self.fail is not None: nodes.append(self.fail)
+ return tuple(nodes)
def __repr__(self):
- return "AssName(%s, %s)" % (repr(self.name), repr(self.flags))
+ return "Assert(%s, %s)" % (repr(self.test), repr(self.fail))
-class LeftShift(Node):
- nodes["leftshift"] = "LeftShift"
- def __init__(self, (left, right)):
- self.left = left
- self.right = right
+class Return(Node):
+ nodes["return"] = "Return"
+ def __init__(self, value):
+ self.value = value
def getChildren(self):
- return self.left, self.right
+ return self.value,
def getChildNodes(self):
- return self.left, self.right
+ return self.value,
def __repr__(self):
- return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right))
+ return "Return(%s)" % (repr(self.value),)
-class Mul(Node):
- nodes["mul"] = "Mul"
+class Power(Node):
+ nodes["power"] = "Power"
def __init__(self, (left, right)):
self.left = left
self.right = right
@@ -468,24 +508,34 @@ class Mul(Node):
return self.left, self.right
def __repr__(self):
- return "Mul((%s, %s))" % (repr(self.left), repr(self.right))
+ return "Power((%s, %s))" % (repr(self.left), repr(self.right))
-class Yield(Node):
- nodes["yield"] = "Yield"
- def __init__(self, value):
- self.value = value
+class Exec(Node):
+ nodes["exec"] = "Exec"
+ def __init__(self, expr, locals, globals):
+ self.expr = expr
+ self.locals = locals
+ self.globals = globals
def getChildren(self):
- return self.value,
+ children = []
+ children.append(self.expr)
+ children.append(self.locals)
+ children.append(self.globals)
+ return tuple(children)
def getChildNodes(self):
- return self.value,
+ nodes = []
+ nodes.append(self.expr)
+ if self.locals is not None: nodes.append(self.locals)
+ if self.globals is not None: nodes.append(self.globals)
+ return tuple(nodes)
def __repr__(self):
- return "Yield(%s)" % (repr(self.value),)
+ return "Exec(%s, %s, %s)" % (repr(self.expr), repr(self.locals), repr(self.globals))
-class List(Node):
- nodes["list"] = "List"
+class Stmt(Node):
+ nodes["stmt"] = "Stmt"
def __init__(self, nodes):
self.nodes = nodes
@@ -500,26 +550,10 @@ class List(Node):
return tuple(nodes)
def __repr__(self):
- return "List(%s)" % (repr(self.nodes),)
-
-class AugAssign(Node):
- nodes["augassign"] = "AugAssign"
- def __init__(self, node, op, expr):
- self.node = node
- self.op = op
- self.expr = expr
-
- def getChildren(self):
- return self.node, self.op, self.expr
-
- def getChildNodes(self):
- return self.node, self.expr
-
- def __repr__(self):
- return "AugAssign(%s, %s, %s)" % (repr(self.node), repr(self.op), repr(self.expr))
+ return "Stmt(%s)" % (repr(self.nodes),)
-class Or(Node):
- nodes["or"] = "Or"
+class Sliceobj(Node):
+ nodes["sliceobj"] = "Sliceobj"
def __init__(self, nodes):
self.nodes = nodes
@@ -534,55 +568,42 @@ class Or(Node):
return tuple(nodes)
def __repr__(self):
- return "Or(%s)" % (repr(self.nodes),)
-
-class Keyword(Node):
- nodes["keyword"] = "Keyword"
- def __init__(self, name, expr):
- self.name = name
- self.expr = expr
-
- def getChildren(self):
- return self.name, self.expr
-
- def getChildNodes(self):
- return self.expr,
-
- def __repr__(self):
- return "Keyword(%s, %s)" % (repr(self.name), repr(self.expr))
+ return "Sliceobj(%s)" % (repr(self.nodes),)
-class AssAttr(Node):
- nodes["assattr"] = "AssAttr"
- def __init__(self, expr, attrname, flags):
- self.expr = expr
- self.attrname = attrname
- self.flags = flags
+class Break(Node):
+ nodes["break"] = "Break"
+ def __init__(self, ):
+ pass
def getChildren(self):
- return self.expr, self.attrname, self.flags
+ return ()
def getChildNodes(self):
- return self.expr,
+ return ()
def __repr__(self):
- return "AssAttr(%s, %s, %s)" % (repr(self.expr), repr(self.attrname), repr(self.flags))
+ return "Break()"
-class Const(Node):
- nodes["const"] = "Const"
- def __init__(self, value):
- self.value = value
+class Bitand(Node):
+ nodes["bitand"] = "Bitand"
+ def __init__(self, nodes):
+ self.nodes = nodes
def getChildren(self):
- return self.value,
+ children = []
+ children.extend(flatten(self.nodes))
+ return tuple(children)
def getChildNodes(self):
- return ()
+ nodes = []
+ nodes.extend(flatten_nodes(self.nodes))
+ return tuple(nodes)
def __repr__(self):
- return "Const(%s)" % (repr(self.value),)
+ return "Bitand(%s)" % (repr(self.nodes),)
-class Mod(Node):
- nodes["mod"] = "Mod"
+class FloorDiv(Node):
+ nodes["floordiv"] = "FloorDiv"
def __init__(self, (left, right)):
self.left = left
self.right = right
@@ -594,24 +615,22 @@ class Mod(Node):
return self.left, self.right
def __repr__(self):
- return "Mod((%s, %s))" % (repr(self.left), repr(self.right))
+ return "FloorDiv((%s, %s))" % (repr(self.left), repr(self.right))
-class Class(Node):
- nodes["class"] = "Class"
- def __init__(self, name, bases, doc, code):
- self.name = name
- self.bases = bases
- self.doc = doc
- self.code = code
+class TryFinally(Node):
+ nodes["tryfinally"] = "TryFinally"
+ def __init__(self, body, final):
+ self.body = body
+ self.final = final
def getChildren(self):
- return self.name, self.bases, self.doc, self.code
+ return self.body, self.final
def getChildNodes(self):
- return self.code,
+ return self.body, self.final
def __repr__(self):
- return "Class(%s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code))
+ return "TryFinally(%s, %s)" % (repr(self.body), repr(self.final))
class Not(Node):
nodes["not"] = "Not"
@@ -627,41 +646,33 @@ class Not(Node):
def __repr__(self):
return "Not(%s)" % (repr(self.expr),)
-class Bitxor(Node):
- nodes["bitxor"] = "Bitxor"
- def __init__(self, nodes):
- self.nodes = nodes
+class Class(Node):
+ nodes["class"] = "Class"
+ def __init__(self, name, bases, doc, code):
+ self.name = name
+ self.bases = bases
+ self.doc = doc
+ self.code = code
def getChildren(self):
children = []
- children.extend(flatten(self.nodes))
+ children.append(self.name)
+ children.extend(flatten(self.bases))
+ children.append(self.doc)
+ children.append(self.code)
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.extend(flatten_nodes(self.nodes))
+ nodes.extend(flatten_nodes(self.bases))
+ nodes.append(self.code)
return tuple(nodes)
def __repr__(self):
- return "Bitxor(%s)" % (repr(self.nodes),)
-
-class TryFinally(Node):
- nodes["tryfinally"] = "TryFinally"
- def __init__(self, body, final):
- self.body = body
- self.final = final
-
- def getChildren(self):
- return self.body, self.final
-
- def getChildNodes(self):
- return self.body, self.final
-
- def __repr__(self):
- return "TryFinally(%s, %s)" % (repr(self.body), repr(self.final))
+ return "Class(%s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code))
-class FloorDiv(Node):
- nodes["floordiv"] = "FloorDiv"
+class Mod(Node):
+ nodes["mod"] = "Mod"
def __init__(self, (left, right)):
self.left = left
self.right = right
@@ -673,42 +684,31 @@ class FloorDiv(Node):
return self.left, self.right
def __repr__(self):
- return "FloorDiv((%s, %s))" % (repr(self.left), repr(self.right))
+ return "Mod((%s, %s))" % (repr(self.left), repr(self.right))
-class Bitand(Node):
- nodes["bitand"] = "Bitand"
- def __init__(self, nodes):
+class Printnl(Node):
+ nodes["printnl"] = "Printnl"
+ def __init__(self, nodes, dest):
self.nodes = nodes
+ self.dest = dest
def getChildren(self):
children = []
children.extend(flatten(self.nodes))
+ children.append(self.dest)
return tuple(children)
def getChildNodes(self):
nodes = []
nodes.extend(flatten_nodes(self.nodes))
+ if self.dest is not None: nodes.append(self.dest)
return tuple(nodes)
def __repr__(self):
- return "Bitand(%s)" % (repr(self.nodes),)
-
-class Break(Node):
- nodes["break"] = "Break"
- def __init__(self, ):
- pass
-
- def getChildren(self):
- return ()
-
- def getChildNodes(self):
- return ()
-
- def __repr__(self):
- return "Break()"
+ return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest))
-class Stmt(Node):
- nodes["stmt"] = "Stmt"
+class Tuple(Node):
+ nodes["tuple"] = "Tuple"
def __init__(self, nodes):
self.nodes = nodes
@@ -723,84 +723,75 @@ class Stmt(Node):
return tuple(nodes)
def __repr__(self):
- return "Stmt(%s)" % (repr(self.nodes),)
+ return "Tuple(%s)" % (repr(self.nodes),)
-class Assert(Node):
- nodes["assert"] = "Assert"
- def __init__(self, test, fail):
- self.test = test
- self.fail = fail
+class AssAttr(Node):
+ nodes["assattr"] = "AssAttr"
+ def __init__(self, expr, attrname, flags):
+ self.expr = expr
+ self.attrname = attrname
+ self.flags = flags
def getChildren(self):
- children = []
- children.append(self.test)
- children.append(self.fail)
- return tuple(children)
+ return self.expr, self.attrname, self.flags
def getChildNodes(self):
- nodes = []
- nodes.append(self.test)
- if self.fail is not None: nodes.append(self.fail)
- return tuple(nodes)
+ return self.expr,
def __repr__(self):
- return "Assert(%s, %s)" % (repr(self.test), repr(self.fail))
+ return "AssAttr(%s, %s, %s)" % (repr(self.expr), repr(self.attrname), repr(self.flags))
-class Exec(Node):
- nodes["exec"] = "Exec"
- def __init__(self, expr, locals, globals):
+class Keyword(Node):
+ nodes["keyword"] = "Keyword"
+ def __init__(self, name, expr):
+ self.name = name
self.expr = expr
- self.locals = locals
- self.globals = globals
def getChildren(self):
- children = []
- children.append(self.expr)
- children.append(self.locals)
- children.append(self.globals)
- return tuple(children)
+ return self.name, self.expr
def getChildNodes(self):
- nodes = []
- nodes.append(self.expr)
- if self.locals is not None: nodes.append(self.locals)
- if self.globals is not None: nodes.append(self.globals)
- return tuple(nodes)
+ return self.expr,
def __repr__(self):
- return "Exec(%s, %s, %s)" % (repr(self.expr), repr(self.locals), repr(self.globals))
+ return "Keyword(%s, %s)" % (repr(self.name), repr(self.expr))
-class Power(Node):
- nodes["power"] = "Power"
- def __init__(self, (left, right)):
- self.left = left
- self.right = right
+class AugAssign(Node):
+ nodes["augassign"] = "AugAssign"
+ def __init__(self, node, op, expr):
+ self.node = node
+ self.op = op
+ self.expr = expr
def getChildren(self):
- return self.left, self.right
+ return self.node, self.op, self.expr
def getChildNodes(self):
- return self.left, self.right
+ return self.node, self.expr
def __repr__(self):
- return "Power((%s, %s))" % (repr(self.left), repr(self.right))
+ return "AugAssign(%s, %s, %s)" % (repr(self.node), repr(self.op), repr(self.expr))
-class Ellipsis(Node):
- nodes["ellipsis"] = "Ellipsis"
- def __init__(self, ):
- pass
+class List(Node):
+ nodes["list"] = "List"
+ def __init__(self, nodes):
+ self.nodes = nodes
def getChildren(self):
- return ()
+ children = []
+ children.extend(flatten(self.nodes))
+ return tuple(children)
def getChildNodes(self):
- return ()
+ nodes = []
+ nodes.extend(flatten_nodes(self.nodes))
+ return tuple(nodes)
def __repr__(self):
- return "Ellipsis()"
+ return "List(%s)" % (repr(self.nodes),)
-class Return(Node):
- nodes["return"] = "Return"
+class Yield(Node):
+ nodes["yield"] = "Yield"
def __init__(self, value):
self.value = value
@@ -811,10 +802,10 @@ class Return(Node):
return self.value,
def __repr__(self):
- return "Return(%s)" % (repr(self.value),)
+ return "Yield(%s)" % (repr(self.value),)
-class Add(Node):
- nodes["add"] = "Add"
+class LeftShift(Node):
+ nodes["leftshift"] = "LeftShift"
def __init__(self, (left, right)):
self.left = left
self.right = right
@@ -826,189 +817,215 @@ class Add(Node):
return self.left, self.right
def __repr__(self):
- return "Add((%s, %s))" % (repr(self.left), repr(self.right))
+ return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right))
-class Function(Node):
- nodes["function"] = "Function"
- def __init__(self, name, argnames, defaults, flags, doc, code):
+class AssName(Node):
+ nodes["assname"] = "AssName"
+ def __init__(self, name, flags):
self.name = name
- self.argnames = argnames
- self.defaults = defaults
self.flags = flags
- self.doc = doc
- self.code = code
- self.varargs = self.kwargs = None
- if flags & CO_VARARGS:
- self.varargs = 1
- if flags & CO_VARKEYWORDS:
- self.kwargs = 1
-
-
def getChildren(self):
- return self.name, self.argnames, self.defaults, self.flags, self.doc, self.code
+ return self.name, self.flags
def getChildNodes(self):
- return self.code,
+ return ()
def __repr__(self):
- return "Function(%s, %s, %s, %s, %s, %s)" % (repr(self.name), repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.doc), repr(self.code))
+ return "AssName(%s, %s)" % (repr(self.name), repr(self.flags))
-class TryExcept(Node):
- nodes["tryexcept"] = "TryExcept"
- def __init__(self, body, handlers, else_):
+class While(Node):
+ nodes["while"] = "While"
+ def __init__(self, test, body, else_):
+ self.test = test
self.body = body
- self.handlers = handlers
self.else_ = else_
def getChildren(self):
children = []
+ children.append(self.test)
children.append(self.body)
- children.extend(flatten(self.handlers))
children.append(self.else_)
return tuple(children)
def getChildNodes(self):
nodes = []
+ nodes.append(self.test)
nodes.append(self.body)
- nodes.extend(flatten_nodes(self.handlers))
if self.else_ is not None: nodes.append(self.else_)
return tuple(nodes)
def __repr__(self):
- return "TryExcept(%s, %s, %s)" % (repr(self.body), repr(self.handlers), repr(self.else_))
+ return "While(%s, %s, %s)" % (repr(self.test), repr(self.body), repr(self.else_))
-class Subscript(Node):
- nodes["subscript"] = "Subscript"
- def __init__(self, expr, flags, subs):
+class Continue(Node):
+ nodes["continue"] = "Continue"
+ def __init__(self, ):
+ pass
+
+ def getChildren(self):
+ return ()
+
+ def getChildNodes(self):
+ return ()
+
+ def __repr__(self):
+ return "Continue()"
+
+class Backquote(Node):
+ nodes["backquote"] = "Backquote"
+ def __init__(self, expr):
self.expr = expr
- self.flags = flags
- self.subs = subs
def getChildren(self):
- children = []
- children.append(self.expr)
- children.append(self.flags)
- children.extend(flatten(self.subs))
- return tuple(children)
+ return self.expr,
def getChildNodes(self):
- nodes = []
- nodes.append(self.expr)
- nodes.extend(flatten_nodes(self.subs))
- return tuple(nodes)
+ return self.expr,
def __repr__(self):
- return "Subscript(%s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.subs))
+ return "Backquote(%s)" % (repr(self.expr),)
-class Import(Node):
- nodes["import"] = "Import"
- def __init__(self, names):
- self.names = names
+class Discard(Node):
+ nodes["discard"] = "Discard"
+ def __init__(self, expr):
+ self.expr = expr
def getChildren(self):
- return self.names,
+ return self.expr,
def getChildNodes(self):
- return ()
+ return self.expr,
def __repr__(self):
- return "Import(%s)" % (repr(self.names),)
+ return "Discard(%s)" % (repr(self.expr),)
-class Print(Node):
- nodes["print"] = "Print"
- def __init__(self, nodes, dest):
+class Div(Node):
+ nodes["div"] = "Div"
+ def __init__(self, (left, right)):
+ self.left = left
+ self.right = right
+
+ def getChildren(self):
+ return self.left, self.right
+
+ def getChildNodes(self):
+ return self.left, self.right
+
+ def __repr__(self):
+ return "Div((%s, %s))" % (repr(self.left), repr(self.right))
+
+class Assign(Node):
+ nodes["assign"] = "Assign"
+ def __init__(self, nodes, expr):
self.nodes = nodes
- self.dest = dest
+ self.expr = expr
def getChildren(self):
children = []
children.extend(flatten(self.nodes))
- children.append(self.dest)
+ children.append(self.expr)
return tuple(children)
def getChildNodes(self):
nodes = []
nodes.extend(flatten_nodes(self.nodes))
- if self.dest is not None: nodes.append(self.dest)
+ nodes.append(self.expr)
return tuple(nodes)
def __repr__(self):
- return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest))
+ return "Assign(%s, %s)" % (repr(self.nodes), repr(self.expr))
+
+class Lambda(Node):
+ nodes["lambda"] = "Lambda"
+ def __init__(self, argnames, defaults, flags, code):
+ self.argnames = argnames
+ self.defaults = defaults
+ self.flags = flags
+ self.code = code
+ self.varargs = self.kwargs = None
+ if flags & CO_VARARGS:
+ self.varargs = 1
+ if flags & CO_VARKEYWORDS:
+ self.kwargs = 1
-class UnaryAdd(Node):
- nodes["unaryadd"] = "UnaryAdd"
- def __init__(self, expr):
- self.expr = expr
def getChildren(self):
- return self.expr,
+ children = []
+ children.append(self.argnames)
+ children.extend(flatten(self.defaults))
+ children.append(self.flags)
+ children.append(self.code)
+ return tuple(children)
def getChildNodes(self):
- return self.expr,
+ nodes = []
+ nodes.extend(flatten_nodes(self.defaults))
+ nodes.append(self.code)
+ return tuple(nodes)
def __repr__(self):
- return "UnaryAdd(%s)" % (repr(self.expr),)
+ return "Lambda(%s, %s, %s, %s)" % (repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.code))
-class ListCompFor(Node):
- nodes["listcompfor"] = "ListCompFor"
- def __init__(self, assign, list, ifs):
- self.assign = assign
- self.list = list
- self.ifs = ifs
+class And(Node):
+ nodes["and"] = "And"
+ def __init__(self, nodes):
+ self.nodes = nodes
def getChildren(self):
children = []
- children.append(self.assign)
- children.append(self.list)
- children.extend(flatten(self.ifs))
+ children.extend(flatten(self.nodes))
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.append(self.assign)
- nodes.append(self.list)
- nodes.extend(flatten_nodes(self.ifs))
+ nodes.extend(flatten_nodes(self.nodes))
return tuple(nodes)
def __repr__(self):
- return "ListCompFor(%s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.ifs))
+ return "And(%s)" % (repr(self.nodes),)
-class Dict(Node):
- nodes["dict"] = "Dict"
- def __init__(self, items):
- self.items = items
+class Compare(Node):
+ nodes["compare"] = "Compare"
+ def __init__(self, expr, ops):
+ self.expr = expr
+ self.ops = ops
def getChildren(self):
children = []
- children.extend(flatten(self.items))
+ children.append(self.expr)
+ children.extend(flatten(self.ops))
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.extend(flatten_nodes(self.items))
+ nodes.append(self.expr)
+ nodes.extend(flatten_nodes(self.ops))
return tuple(nodes)
def __repr__(self):
- return "Dict(%s)" % (repr(self.items),)
+ return "Compare(%s, %s)" % (repr(self.expr), repr(self.ops))
-class Getattr(Node):
- nodes["getattr"] = "Getattr"
- def __init__(self, expr, attrname):
- self.expr = expr
- self.attrname = attrname
+class Bitor(Node):
+ nodes["bitor"] = "Bitor"
+ def __init__(self, nodes):
+ self.nodes = nodes
def getChildren(self):
- return self.expr, self.attrname
+ children = []
+ children.extend(flatten(self.nodes))
+ return tuple(children)
def getChildNodes(self):
- return self.expr,
+ nodes = []
+ nodes.extend(flatten_nodes(self.nodes))
+ return tuple(nodes)
def __repr__(self):
- return "Getattr(%s, %s)" % (repr(self.expr), repr(self.attrname))
+ return "Bitor(%s)" % (repr(self.nodes),)
-class AssList(Node):
- nodes["asslist"] = "AssList"
+class Bitxor(Node):
+ nodes["bitxor"] = "Bitxor"
def __init__(self, nodes):
self.nodes = nodes
@@ -1023,177 +1040,186 @@ class AssList(Node):
return tuple(nodes)
def __repr__(self):
- return "AssList(%s)" % (repr(self.nodes),)
+ return "Bitxor(%s)" % (repr(self.nodes),)
-class UnarySub(Node):
- nodes["unarysub"] = "UnarySub"
- def __init__(self, expr):
- self.expr = expr
+class CallFunc(Node):
+ nodes["callfunc"] = "CallFunc"
+ def __init__(self, node, args, star_args = None, dstar_args = None):
+ self.node = node
+ self.args = args
+ self.star_args = star_args
+ self.dstar_args = dstar_args
def getChildren(self):
- return self.expr,
+ children = []
+ children.append(self.node)
+ children.extend(flatten(self.args))
+ children.append(self.star_args)
+ children.append(self.dstar_args)
+ return tuple(children)
def getChildNodes(self):
- return self.expr,
+ nodes = []
+ nodes.append(self.node)
+ nodes.extend(flatten_nodes(self.args))
+ if self.star_args is not None: nodes.append(self.star_args)
+ if self.dstar_args is not None: nodes.append(self.dstar_args)
+ return tuple(nodes)
def __repr__(self):
- return "UnarySub(%s)" % (repr(self.expr),)
+ return "CallFunc(%s, %s, %s, %s)" % (repr(self.node), repr(self.args), repr(self.star_args), repr(self.dstar_args))
-class Sliceobj(Node):
- nodes["sliceobj"] = "Sliceobj"
- def __init__(self, nodes):
- self.nodes = nodes
+class Global(Node):
+ nodes["global"] = "Global"
+ def __init__(self, names):
+ self.names = names
def getChildren(self):
- children = []
- children.extend(flatten(self.nodes))
- return tuple(children)
+ return self.names,
def getChildNodes(self):
- nodes = []
- nodes.extend(flatten_nodes(self.nodes))
- return tuple(nodes)
+ return ()
def __repr__(self):
- return "Sliceobj(%s)" % (repr(self.nodes),)
+ return "Global(%s)" % (repr(self.names),)
-class Invert(Node):
- nodes["invert"] = "Invert"
- def __init__(self, expr):
- self.expr = expr
+class Add(Node):
+ nodes["add"] = "Add"
+ def __init__(self, (left, right)):
+ self.left = left
+ self.right = right
def getChildren(self):
- return self.expr,
+ return self.left, self.right
def getChildNodes(self):
- return self.expr,
+ return self.left, self.right
def __repr__(self):
- return "Invert(%s)" % (repr(self.expr),)
+ return "Add((%s, %s))" % (repr(self.left), repr(self.right))
-class Name(Node):
- nodes["name"] = "Name"
- def __init__(self, name):
- self.name = name
+class ListCompIf(Node):
+ nodes["listcompif"] = "ListCompIf"
+ def __init__(self, test):
+ self.test = test
def getChildren(self):
- return self.name,
+ return self.test,
+
+ def getChildNodes(self):
+ return self.test,
+
+ def __repr__(self):
+ return "ListCompIf(%s)" % (repr(self.test),)
+
+class Sub(Node):
+ nodes["sub"] = "Sub"
+ def __init__(self, (left, right)):
+ self.left = left
+ self.right = right
+
+ def getChildren(self):
+ return self.left, self.right
+
+ def getChildNodes(self):
+ return self.left, self.right
+
+ def __repr__(self):
+ return "Sub((%s, %s))" % (repr(self.left), repr(self.right))
+
+class Pass(Node):
+ nodes["pass"] = "Pass"
+ def __init__(self, ):
+ pass
+
+ def getChildren(self):
+ return ()
def getChildNodes(self):
return ()
def __repr__(self):
- return "Name(%s)" % (repr(self.name),)
+ return "Pass()"
-class AssTuple(Node):
- nodes["asstuple"] = "AssTuple"
- def __init__(self, nodes):
- self.nodes = nodes
+class UnarySub(Node):
+ nodes["unarysub"] = "UnarySub"
+ def __init__(self, expr):
+ self.expr = expr
def getChildren(self):
- children = []
- children.extend(flatten(self.nodes))
- return tuple(children)
+ return self.expr,
def getChildNodes(self):
- nodes = []
- nodes.extend(flatten_nodes(self.nodes))
- return tuple(nodes)
+ return self.expr,
def __repr__(self):
- return "AssTuple(%s)" % (repr(self.nodes),)
+ return "UnarySub(%s)" % (repr(self.expr),)
-class For(Node):
- nodes["for"] = "For"
- def __init__(self, assign, list, body, else_):
- self.assign = assign
- self.list = list
- self.body = body
+class If(Node):
+ nodes["if"] = "If"
+ def __init__(self, tests, else_):
+ self.tests = tests
self.else_ = else_
def getChildren(self):
children = []
- children.append(self.assign)
- children.append(self.list)
- children.append(self.body)
+ children.extend(flatten(self.tests))
children.append(self.else_)
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.append(self.assign)
- nodes.append(self.list)
- nodes.append(self.body)
+ nodes.extend(flatten_nodes(self.tests))
if self.else_ is not None: nodes.append(self.else_)
return tuple(nodes)
def __repr__(self):
- return "For(%s, %s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.body), repr(self.else_))
+ return "If(%s, %s)" % (repr(self.tests), repr(self.else_))
-class Raise(Node):
- nodes["raise"] = "Raise"
- def __init__(self, expr1, expr2, expr3):
- self.expr1 = expr1
- self.expr2 = expr2
- self.expr3 = expr3
+class ListComp(Node):
+ nodes["listcomp"] = "ListComp"
+ def __init__(self, expr, quals):
+ self.expr = expr
+ self.quals = quals
def getChildren(self):
children = []
- children.append(self.expr1)
- children.append(self.expr2)
- children.append(self.expr3)
+ children.append(self.expr)
+ children.extend(flatten(self.quals))
return tuple(children)
def getChildNodes(self):
nodes = []
- if self.expr1 is not None: nodes.append(self.expr1)
- if self.expr2 is not None: nodes.append(self.expr2)
- if self.expr3 is not None: nodes.append(self.expr3)
+ nodes.append(self.expr)
+ nodes.extend(flatten_nodes(self.quals))
return tuple(nodes)
def __repr__(self):
- return "Raise(%s, %s, %s)" % (repr(self.expr1), repr(self.expr2), repr(self.expr3))
-
-class From(Node):
- nodes["from"] = "From"
- def __init__(self, modname, names):
- self.modname = modname
- self.names = names
-
- def getChildren(self):
- return self.modname, self.names
-
- def getChildNodes(self):
- return ()
-
- def __repr__(self):
- return "From(%s, %s)" % (repr(self.modname), repr(self.names))
+ return "ListComp(%s, %s)" % (repr(self.expr), repr(self.quals))
-class Slice(Node):
- nodes["slice"] = "Slice"
- def __init__(self, expr, flags, lower, upper):
- self.expr = expr
- self.flags = flags
- self.lower = lower
- self.upper = upper
+class ListCompFor(Node):
+ nodes["listcompfor"] = "ListCompFor"
+ def __init__(self, assign, list, ifs):
+ self.assign = assign
+ self.list = list
+ self.ifs = ifs
def getChildren(self):
children = []
- children.append(self.expr)
- children.append(self.flags)
- children.append(self.lower)
- children.append(self.upper)
+ children.append(self.assign)
+ children.append(self.list)
+ children.extend(flatten(self.ifs))
return tuple(children)
def getChildNodes(self):
nodes = []
- nodes.append(self.expr)
- if self.lower is not None: nodes.append(self.lower)
- if self.upper is not None: nodes.append(self.upper)
+ nodes.append(self.assign)
+ nodes.append(self.list)
+ nodes.extend(flatten_nodes(self.ifs))
return tuple(nodes)
def __repr__(self):
- return "Slice(%s, %s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.lower), repr(self.upper))
+ return "ListCompFor(%s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.ifs))
klasses = globals()
for k in nodes.keys():