paul@0 | 1 | """Python abstract syntax node definitions |
paul@0 | 2 | |
paul@0 | 3 | This file is automatically generated by Tools/compiler/astgen.py |
paul@0 | 4 | """ |
paul@0 | 5 | from compiler.consts import CO_VARARGS, CO_VARKEYWORDS |
paul@0 | 6 | |
paul@0 | 7 | def flatten(seq): |
paul@0 | 8 | l = [] |
paul@0 | 9 | for elt in seq: |
paul@0 | 10 | t = type(elt) |
paul@0 | 11 | if t is tuple or t is list: |
paul@0 | 12 | for elt2 in flatten(elt): |
paul@0 | 13 | l.append(elt2) |
paul@0 | 14 | else: |
paul@0 | 15 | l.append(elt) |
paul@0 | 16 | return l |
paul@0 | 17 | |
paul@0 | 18 | def flatten_nodes(seq): |
paul@0 | 19 | return [n for n in flatten(seq) if isinstance(n, Node)] |
paul@0 | 20 | |
paul@0 | 21 | nodes = {} |
paul@0 | 22 | |
paul@0 | 23 | class Node: |
paul@0 | 24 | """Abstract base class for ast nodes.""" |
paul@0 | 25 | def getChildren(self): |
paul@0 | 26 | pass # implemented by subclasses |
paul@0 | 27 | def __iter__(self): |
paul@0 | 28 | for n in self.getChildren(): |
paul@0 | 29 | yield n |
paul@0 | 30 | def asList(self): # for backwards compatibility |
paul@0 | 31 | return self.getChildren() |
paul@0 | 32 | def getChildNodes(self): |
paul@0 | 33 | pass # implemented by subclasses |
paul@0 | 34 | |
paul@0 | 35 | class EmptyNode(Node): |
paul@0 | 36 | pass |
paul@0 | 37 | |
paul@0 | 38 | class Expression(Node): |
paul@0 | 39 | # Expression is an artificial node class to support "eval" |
paul@0 | 40 | nodes["expression"] = "Expression" |
paul@0 | 41 | def __init__(self, node): |
paul@0 | 42 | self.node = node |
paul@0 | 43 | |
paul@0 | 44 | def getChildren(self): |
paul@0 | 45 | return self.node, |
paul@0 | 46 | |
paul@0 | 47 | def getChildNodes(self): |
paul@0 | 48 | return self.node, |
paul@0 | 49 | |
paul@0 | 50 | def __repr__(self): |
paul@0 | 51 | return "Expression(%s)" % (repr(self.node)) |
paul@0 | 52 | |
paul@0 | 53 | class Add(Node): |
paul@0 | 54 | def __init__(self, leftright, lineno=None): |
paul@0 | 55 | self.left = leftright[0] |
paul@0 | 56 | self.right = leftright[1] |
paul@0 | 57 | self.lineno = lineno |
paul@0 | 58 | |
paul@0 | 59 | def getChildren(self): |
paul@0 | 60 | return self.left, self.right |
paul@0 | 61 | |
paul@0 | 62 | def getChildNodes(self): |
paul@0 | 63 | return self.left, self.right |
paul@0 | 64 | |
paul@0 | 65 | def __repr__(self): |
paul@0 | 66 | return "Add((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 67 | |
paul@0 | 68 | class And(Node): |
paul@0 | 69 | def __init__(self, nodes, lineno=None): |
paul@0 | 70 | self.nodes = nodes |
paul@0 | 71 | self.lineno = lineno |
paul@0 | 72 | |
paul@0 | 73 | def getChildren(self): |
paul@0 | 74 | return tuple(flatten(self.nodes)) |
paul@0 | 75 | |
paul@0 | 76 | def getChildNodes(self): |
paul@0 | 77 | nodelist = [] |
paul@0 | 78 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 79 | return tuple(nodelist) |
paul@0 | 80 | |
paul@0 | 81 | def __repr__(self): |
paul@0 | 82 | return "And(%s)" % (repr(self.nodes),) |
paul@0 | 83 | |
paul@0 | 84 | class AssAttr(Node): |
paul@0 | 85 | def __init__(self, expr, attrname, flags, lineno=None): |
paul@0 | 86 | self.expr = expr |
paul@0 | 87 | self.attrname = attrname |
paul@0 | 88 | self.flags = flags |
paul@0 | 89 | self.lineno = lineno |
paul@0 | 90 | |
paul@0 | 91 | def getChildren(self): |
paul@0 | 92 | return self.expr, self.attrname, self.flags |
paul@0 | 93 | |
paul@0 | 94 | def getChildNodes(self): |
paul@0 | 95 | return self.expr, |
paul@0 | 96 | |
paul@0 | 97 | def __repr__(self): |
paul@0 | 98 | return "AssAttr(%s, %s, %s)" % (repr(self.expr), repr(self.attrname), repr(self.flags)) |
paul@0 | 99 | |
paul@0 | 100 | class AssList(Node): |
paul@0 | 101 | def __init__(self, nodes, lineno=None): |
paul@0 | 102 | self.nodes = nodes |
paul@0 | 103 | self.lineno = lineno |
paul@0 | 104 | |
paul@0 | 105 | def getChildren(self): |
paul@0 | 106 | return tuple(flatten(self.nodes)) |
paul@0 | 107 | |
paul@0 | 108 | def getChildNodes(self): |
paul@0 | 109 | nodelist = [] |
paul@0 | 110 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 111 | return tuple(nodelist) |
paul@0 | 112 | |
paul@0 | 113 | def __repr__(self): |
paul@0 | 114 | return "AssList(%s)" % (repr(self.nodes),) |
paul@0 | 115 | |
paul@0 | 116 | class AssName(Node): |
paul@0 | 117 | def __init__(self, name, flags, lineno=None): |
paul@0 | 118 | self.name = name |
paul@0 | 119 | self.flags = flags |
paul@0 | 120 | self.lineno = lineno |
paul@0 | 121 | |
paul@0 | 122 | def getChildren(self): |
paul@0 | 123 | return self.name, self.flags |
paul@0 | 124 | |
paul@0 | 125 | def getChildNodes(self): |
paul@0 | 126 | return () |
paul@0 | 127 | |
paul@0 | 128 | def __repr__(self): |
paul@0 | 129 | return "AssName(%s, %s)" % (repr(self.name), repr(self.flags)) |
paul@0 | 130 | |
paul@0 | 131 | class AssTuple(Node): |
paul@0 | 132 | def __init__(self, nodes, lineno=None): |
paul@0 | 133 | self.nodes = nodes |
paul@0 | 134 | self.lineno = lineno |
paul@0 | 135 | |
paul@0 | 136 | def getChildren(self): |
paul@0 | 137 | return tuple(flatten(self.nodes)) |
paul@0 | 138 | |
paul@0 | 139 | def getChildNodes(self): |
paul@0 | 140 | nodelist = [] |
paul@0 | 141 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 142 | return tuple(nodelist) |
paul@0 | 143 | |
paul@0 | 144 | def __repr__(self): |
paul@0 | 145 | return "AssTuple(%s)" % (repr(self.nodes),) |
paul@0 | 146 | |
paul@0 | 147 | class Assert(Node): |
paul@0 | 148 | def __init__(self, test, fail, lineno=None): |
paul@0 | 149 | self.test = test |
paul@0 | 150 | self.fail = fail |
paul@0 | 151 | self.lineno = lineno |
paul@0 | 152 | |
paul@0 | 153 | def getChildren(self): |
paul@0 | 154 | children = [] |
paul@0 | 155 | children.append(self.test) |
paul@0 | 156 | children.append(self.fail) |
paul@0 | 157 | return tuple(children) |
paul@0 | 158 | |
paul@0 | 159 | def getChildNodes(self): |
paul@0 | 160 | nodelist = [] |
paul@0 | 161 | nodelist.append(self.test) |
paul@0 | 162 | if self.fail is not None: |
paul@0 | 163 | nodelist.append(self.fail) |
paul@0 | 164 | return tuple(nodelist) |
paul@0 | 165 | |
paul@0 | 166 | def __repr__(self): |
paul@0 | 167 | return "Assert(%s, %s)" % (repr(self.test), repr(self.fail)) |
paul@0 | 168 | |
paul@0 | 169 | class Assign(Node): |
paul@0 | 170 | def __init__(self, nodes, expr, lineno=None): |
paul@0 | 171 | self.nodes = nodes |
paul@0 | 172 | self.expr = expr |
paul@0 | 173 | self.lineno = lineno |
paul@0 | 174 | |
paul@0 | 175 | def getChildren(self): |
paul@0 | 176 | children = [] |
paul@0 | 177 | children.extend(flatten(self.nodes)) |
paul@0 | 178 | children.append(self.expr) |
paul@0 | 179 | return tuple(children) |
paul@0 | 180 | |
paul@0 | 181 | def getChildNodes(self): |
paul@0 | 182 | nodelist = [] |
paul@0 | 183 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 184 | nodelist.append(self.expr) |
paul@0 | 185 | return tuple(nodelist) |
paul@0 | 186 | |
paul@0 | 187 | def __repr__(self): |
paul@0 | 188 | return "Assign(%s, %s)" % (repr(self.nodes), repr(self.expr)) |
paul@0 | 189 | |
paul@0 | 190 | class AugAssign(Node): |
paul@0 | 191 | def __init__(self, node, op, expr, lineno=None): |
paul@0 | 192 | self.node = node |
paul@0 | 193 | self.op = op |
paul@0 | 194 | self.expr = expr |
paul@0 | 195 | self.lineno = lineno |
paul@0 | 196 | |
paul@0 | 197 | def getChildren(self): |
paul@0 | 198 | return self.node, self.op, self.expr |
paul@0 | 199 | |
paul@0 | 200 | def getChildNodes(self): |
paul@0 | 201 | return self.node, self.expr |
paul@0 | 202 | |
paul@0 | 203 | def __repr__(self): |
paul@0 | 204 | return "AugAssign(%s, %s, %s)" % (repr(self.node), repr(self.op), repr(self.expr)) |
paul@0 | 205 | |
paul@0 | 206 | class Backquote(Node): |
paul@0 | 207 | def __init__(self, expr, lineno=None): |
paul@0 | 208 | self.expr = expr |
paul@0 | 209 | self.lineno = lineno |
paul@0 | 210 | |
paul@0 | 211 | def getChildren(self): |
paul@0 | 212 | return self.expr, |
paul@0 | 213 | |
paul@0 | 214 | def getChildNodes(self): |
paul@0 | 215 | return self.expr, |
paul@0 | 216 | |
paul@0 | 217 | def __repr__(self): |
paul@0 | 218 | return "Backquote(%s)" % (repr(self.expr),) |
paul@0 | 219 | |
paul@0 | 220 | class Bitand(Node): |
paul@0 | 221 | def __init__(self, nodes, lineno=None): |
paul@0 | 222 | self.nodes = nodes |
paul@0 | 223 | self.lineno = lineno |
paul@0 | 224 | |
paul@0 | 225 | def getChildren(self): |
paul@0 | 226 | return tuple(flatten(self.nodes)) |
paul@0 | 227 | |
paul@0 | 228 | def getChildNodes(self): |
paul@0 | 229 | nodelist = [] |
paul@0 | 230 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 231 | return tuple(nodelist) |
paul@0 | 232 | |
paul@0 | 233 | def __repr__(self): |
paul@0 | 234 | return "Bitand(%s)" % (repr(self.nodes),) |
paul@0 | 235 | |
paul@0 | 236 | class Bitor(Node): |
paul@0 | 237 | def __init__(self, nodes, lineno=None): |
paul@0 | 238 | self.nodes = nodes |
paul@0 | 239 | self.lineno = lineno |
paul@0 | 240 | |
paul@0 | 241 | def getChildren(self): |
paul@0 | 242 | return tuple(flatten(self.nodes)) |
paul@0 | 243 | |
paul@0 | 244 | def getChildNodes(self): |
paul@0 | 245 | nodelist = [] |
paul@0 | 246 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 247 | return tuple(nodelist) |
paul@0 | 248 | |
paul@0 | 249 | def __repr__(self): |
paul@0 | 250 | return "Bitor(%s)" % (repr(self.nodes),) |
paul@0 | 251 | |
paul@0 | 252 | class Bitxor(Node): |
paul@0 | 253 | def __init__(self, nodes, lineno=None): |
paul@0 | 254 | self.nodes = nodes |
paul@0 | 255 | self.lineno = lineno |
paul@0 | 256 | |
paul@0 | 257 | def getChildren(self): |
paul@0 | 258 | return tuple(flatten(self.nodes)) |
paul@0 | 259 | |
paul@0 | 260 | def getChildNodes(self): |
paul@0 | 261 | nodelist = [] |
paul@0 | 262 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 263 | return tuple(nodelist) |
paul@0 | 264 | |
paul@0 | 265 | def __repr__(self): |
paul@0 | 266 | return "Bitxor(%s)" % (repr(self.nodes),) |
paul@0 | 267 | |
paul@0 | 268 | class Break(Node): |
paul@0 | 269 | def __init__(self, lineno=None): |
paul@0 | 270 | self.lineno = lineno |
paul@0 | 271 | |
paul@0 | 272 | def getChildren(self): |
paul@0 | 273 | return () |
paul@0 | 274 | |
paul@0 | 275 | def getChildNodes(self): |
paul@0 | 276 | return () |
paul@0 | 277 | |
paul@0 | 278 | def __repr__(self): |
paul@0 | 279 | return "Break()" |
paul@0 | 280 | |
paul@0 | 281 | class CallFunc(Node): |
paul@0 | 282 | def __init__(self, node, args, star_args = None, dstar_args = None, lineno=None): |
paul@0 | 283 | self.node = node |
paul@0 | 284 | self.args = args |
paul@0 | 285 | self.star_args = star_args |
paul@0 | 286 | self.dstar_args = dstar_args |
paul@0 | 287 | self.lineno = lineno |
paul@0 | 288 | |
paul@0 | 289 | def getChildren(self): |
paul@0 | 290 | children = [] |
paul@0 | 291 | children.append(self.node) |
paul@0 | 292 | children.extend(flatten(self.args)) |
paul@0 | 293 | children.append(self.star_args) |
paul@0 | 294 | children.append(self.dstar_args) |
paul@0 | 295 | return tuple(children) |
paul@0 | 296 | |
paul@0 | 297 | def getChildNodes(self): |
paul@0 | 298 | nodelist = [] |
paul@0 | 299 | nodelist.append(self.node) |
paul@0 | 300 | nodelist.extend(flatten_nodes(self.args)) |
paul@0 | 301 | if self.star_args is not None: |
paul@0 | 302 | nodelist.append(self.star_args) |
paul@0 | 303 | if self.dstar_args is not None: |
paul@0 | 304 | nodelist.append(self.dstar_args) |
paul@0 | 305 | return tuple(nodelist) |
paul@0 | 306 | |
paul@0 | 307 | def __repr__(self): |
paul@0 | 308 | return "CallFunc(%s, %s, %s, %s)" % (repr(self.node), repr(self.args), repr(self.star_args), repr(self.dstar_args)) |
paul@0 | 309 | |
paul@0 | 310 | class Class(Node): |
paul@0 | 311 | def __init__(self, name, bases, doc, code, decorators = None, lineno=None): |
paul@0 | 312 | self.name = name |
paul@0 | 313 | self.bases = bases |
paul@0 | 314 | self.doc = doc |
paul@0 | 315 | self.code = code |
paul@0 | 316 | self.decorators = decorators |
paul@0 | 317 | self.lineno = lineno |
paul@0 | 318 | |
paul@0 | 319 | def getChildren(self): |
paul@0 | 320 | children = [] |
paul@0 | 321 | children.append(self.name) |
paul@0 | 322 | children.extend(flatten(self.bases)) |
paul@0 | 323 | children.append(self.doc) |
paul@0 | 324 | children.append(self.code) |
paul@0 | 325 | children.append(self.decorators) |
paul@0 | 326 | return tuple(children) |
paul@0 | 327 | |
paul@0 | 328 | def getChildNodes(self): |
paul@0 | 329 | nodelist = [] |
paul@0 | 330 | nodelist.extend(flatten_nodes(self.bases)) |
paul@0 | 331 | nodelist.append(self.code) |
paul@0 | 332 | if self.decorators is not None: |
paul@0 | 333 | nodelist.append(self.decorators) |
paul@0 | 334 | return tuple(nodelist) |
paul@0 | 335 | |
paul@0 | 336 | def __repr__(self): |
paul@0 | 337 | return "Class(%s, %s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code), repr(self.decorators)) |
paul@0 | 338 | |
paul@0 | 339 | class Compare(Node): |
paul@0 | 340 | def __init__(self, expr, ops, lineno=None): |
paul@0 | 341 | self.expr = expr |
paul@0 | 342 | self.ops = ops |
paul@0 | 343 | self.lineno = lineno |
paul@0 | 344 | |
paul@0 | 345 | def getChildren(self): |
paul@0 | 346 | children = [] |
paul@0 | 347 | children.append(self.expr) |
paul@0 | 348 | children.extend(flatten(self.ops)) |
paul@0 | 349 | return tuple(children) |
paul@0 | 350 | |
paul@0 | 351 | def getChildNodes(self): |
paul@0 | 352 | nodelist = [] |
paul@0 | 353 | nodelist.append(self.expr) |
paul@0 | 354 | nodelist.extend(flatten_nodes(self.ops)) |
paul@0 | 355 | return tuple(nodelist) |
paul@0 | 356 | |
paul@0 | 357 | def __repr__(self): |
paul@0 | 358 | return "Compare(%s, %s)" % (repr(self.expr), repr(self.ops)) |
paul@0 | 359 | |
paul@0 | 360 | class Const(Node): |
paul@0 | 361 | def __init__(self, value, lineno=None): |
paul@0 | 362 | self.value = value |
paul@0 | 363 | self.lineno = lineno |
paul@0 | 364 | |
paul@0 | 365 | def getChildren(self): |
paul@0 | 366 | return self.value, |
paul@0 | 367 | |
paul@0 | 368 | def getChildNodes(self): |
paul@0 | 369 | return () |
paul@0 | 370 | |
paul@0 | 371 | def __repr__(self): |
paul@0 | 372 | return "Const(%s)" % (repr(self.value),) |
paul@0 | 373 | |
paul@0 | 374 | class Continue(Node): |
paul@0 | 375 | def __init__(self, lineno=None): |
paul@0 | 376 | self.lineno = lineno |
paul@0 | 377 | |
paul@0 | 378 | def getChildren(self): |
paul@0 | 379 | return () |
paul@0 | 380 | |
paul@0 | 381 | def getChildNodes(self): |
paul@0 | 382 | return () |
paul@0 | 383 | |
paul@0 | 384 | def __repr__(self): |
paul@0 | 385 | return "Continue()" |
paul@0 | 386 | |
paul@0 | 387 | class Decorators(Node): |
paul@0 | 388 | def __init__(self, nodes, lineno=None): |
paul@0 | 389 | self.nodes = nodes |
paul@0 | 390 | self.lineno = lineno |
paul@0 | 391 | |
paul@0 | 392 | def getChildren(self): |
paul@0 | 393 | return tuple(flatten(self.nodes)) |
paul@0 | 394 | |
paul@0 | 395 | def getChildNodes(self): |
paul@0 | 396 | nodelist = [] |
paul@0 | 397 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 398 | return tuple(nodelist) |
paul@0 | 399 | |
paul@0 | 400 | def __repr__(self): |
paul@0 | 401 | return "Decorators(%s)" % (repr(self.nodes),) |
paul@0 | 402 | |
paul@0 | 403 | class Dict(Node): |
paul@0 | 404 | def __init__(self, items, lineno=None): |
paul@0 | 405 | self.items = items |
paul@0 | 406 | self.lineno = lineno |
paul@0 | 407 | |
paul@0 | 408 | def getChildren(self): |
paul@0 | 409 | return tuple(flatten(self.items)) |
paul@0 | 410 | |
paul@0 | 411 | def getChildNodes(self): |
paul@0 | 412 | nodelist = [] |
paul@0 | 413 | nodelist.extend(flatten_nodes(self.items)) |
paul@0 | 414 | return tuple(nodelist) |
paul@0 | 415 | |
paul@0 | 416 | def __repr__(self): |
paul@0 | 417 | return "Dict(%s)" % (repr(self.items),) |
paul@0 | 418 | |
paul@0 | 419 | class Discard(Node): |
paul@0 | 420 | def __init__(self, expr, lineno=None): |
paul@0 | 421 | self.expr = expr |
paul@0 | 422 | self.lineno = lineno |
paul@0 | 423 | |
paul@0 | 424 | def getChildren(self): |
paul@0 | 425 | return self.expr, |
paul@0 | 426 | |
paul@0 | 427 | def getChildNodes(self): |
paul@0 | 428 | return self.expr, |
paul@0 | 429 | |
paul@0 | 430 | def __repr__(self): |
paul@0 | 431 | return "Discard(%s)" % (repr(self.expr),) |
paul@0 | 432 | |
paul@0 | 433 | class Div(Node): |
paul@0 | 434 | def __init__(self, leftright, lineno=None): |
paul@0 | 435 | self.left = leftright[0] |
paul@0 | 436 | self.right = leftright[1] |
paul@0 | 437 | self.lineno = lineno |
paul@0 | 438 | |
paul@0 | 439 | def getChildren(self): |
paul@0 | 440 | return self.left, self.right |
paul@0 | 441 | |
paul@0 | 442 | def getChildNodes(self): |
paul@0 | 443 | return self.left, self.right |
paul@0 | 444 | |
paul@0 | 445 | def __repr__(self): |
paul@0 | 446 | return "Div((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 447 | |
paul@0 | 448 | class Ellipsis(Node): |
paul@0 | 449 | def __init__(self, lineno=None): |
paul@0 | 450 | self.lineno = lineno |
paul@0 | 451 | |
paul@0 | 452 | def getChildren(self): |
paul@0 | 453 | return () |
paul@0 | 454 | |
paul@0 | 455 | def getChildNodes(self): |
paul@0 | 456 | return () |
paul@0 | 457 | |
paul@0 | 458 | def __repr__(self): |
paul@0 | 459 | return "Ellipsis()" |
paul@0 | 460 | |
paul@0 | 461 | class Exec(Node): |
paul@0 | 462 | def __init__(self, expr, locals, globals, lineno=None): |
paul@0 | 463 | self.expr = expr |
paul@0 | 464 | self.locals = locals |
paul@0 | 465 | self.globals = globals |
paul@0 | 466 | self.lineno = lineno |
paul@0 | 467 | |
paul@0 | 468 | def getChildren(self): |
paul@0 | 469 | children = [] |
paul@0 | 470 | children.append(self.expr) |
paul@0 | 471 | children.append(self.locals) |
paul@0 | 472 | children.append(self.globals) |
paul@0 | 473 | return tuple(children) |
paul@0 | 474 | |
paul@0 | 475 | def getChildNodes(self): |
paul@0 | 476 | nodelist = [] |
paul@0 | 477 | nodelist.append(self.expr) |
paul@0 | 478 | if self.locals is not None: |
paul@0 | 479 | nodelist.append(self.locals) |
paul@0 | 480 | if self.globals is not None: |
paul@0 | 481 | nodelist.append(self.globals) |
paul@0 | 482 | return tuple(nodelist) |
paul@0 | 483 | |
paul@0 | 484 | def __repr__(self): |
paul@0 | 485 | return "Exec(%s, %s, %s)" % (repr(self.expr), repr(self.locals), repr(self.globals)) |
paul@0 | 486 | |
paul@0 | 487 | class FloorDiv(Node): |
paul@0 | 488 | def __init__(self, leftright, lineno=None): |
paul@0 | 489 | self.left = leftright[0] |
paul@0 | 490 | self.right = leftright[1] |
paul@0 | 491 | self.lineno = lineno |
paul@0 | 492 | |
paul@0 | 493 | def getChildren(self): |
paul@0 | 494 | return self.left, self.right |
paul@0 | 495 | |
paul@0 | 496 | def getChildNodes(self): |
paul@0 | 497 | return self.left, self.right |
paul@0 | 498 | |
paul@0 | 499 | def __repr__(self): |
paul@0 | 500 | return "FloorDiv((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 501 | |
paul@0 | 502 | class For(Node): |
paul@0 | 503 | def __init__(self, assign, list, body, else_, lineno=None): |
paul@0 | 504 | self.assign = assign |
paul@0 | 505 | self.list = list |
paul@0 | 506 | self.body = body |
paul@0 | 507 | self.else_ = else_ |
paul@0 | 508 | self.lineno = lineno |
paul@0 | 509 | |
paul@0 | 510 | def getChildren(self): |
paul@0 | 511 | children = [] |
paul@0 | 512 | children.append(self.assign) |
paul@0 | 513 | children.append(self.list) |
paul@0 | 514 | children.append(self.body) |
paul@0 | 515 | children.append(self.else_) |
paul@0 | 516 | return tuple(children) |
paul@0 | 517 | |
paul@0 | 518 | def getChildNodes(self): |
paul@0 | 519 | nodelist = [] |
paul@0 | 520 | nodelist.append(self.assign) |
paul@0 | 521 | nodelist.append(self.list) |
paul@0 | 522 | nodelist.append(self.body) |
paul@0 | 523 | if self.else_ is not None: |
paul@0 | 524 | nodelist.append(self.else_) |
paul@0 | 525 | return tuple(nodelist) |
paul@0 | 526 | |
paul@0 | 527 | def __repr__(self): |
paul@0 | 528 | return "For(%s, %s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.body), repr(self.else_)) |
paul@0 | 529 | |
paul@0 | 530 | class From(Node): |
paul@0 | 531 | def __init__(self, modname, names, level, lineno=None): |
paul@0 | 532 | self.modname = modname |
paul@0 | 533 | self.names = names |
paul@0 | 534 | self.level = level |
paul@0 | 535 | self.lineno = lineno |
paul@0 | 536 | |
paul@0 | 537 | def getChildren(self): |
paul@0 | 538 | return self.modname, self.names, self.level |
paul@0 | 539 | |
paul@0 | 540 | def getChildNodes(self): |
paul@0 | 541 | return () |
paul@0 | 542 | |
paul@0 | 543 | def __repr__(self): |
paul@0 | 544 | return "From(%s, %s, %s)" % (repr(self.modname), repr(self.names), repr(self.level)) |
paul@0 | 545 | |
paul@0 | 546 | class Function(Node): |
paul@0 | 547 | def __init__(self, decorators, name, argnames, defaults, flags, doc, code, lineno=None): |
paul@0 | 548 | self.decorators = decorators |
paul@0 | 549 | self.name = name |
paul@0 | 550 | self.argnames = argnames |
paul@0 | 551 | self.defaults = defaults |
paul@0 | 552 | self.flags = flags |
paul@0 | 553 | self.doc = doc |
paul@0 | 554 | self.code = code |
paul@0 | 555 | self.lineno = lineno |
paul@0 | 556 | self.varargs = self.kwargs = None |
paul@0 | 557 | if flags & CO_VARARGS: |
paul@0 | 558 | self.varargs = 1 |
paul@0 | 559 | if flags & CO_VARKEYWORDS: |
paul@0 | 560 | self.kwargs = 1 |
paul@0 | 561 | |
paul@0 | 562 | |
paul@0 | 563 | def getChildren(self): |
paul@0 | 564 | children = [] |
paul@0 | 565 | children.append(self.decorators) |
paul@0 | 566 | children.append(self.name) |
paul@0 | 567 | children.append(self.argnames) |
paul@0 | 568 | children.extend(flatten(self.defaults)) |
paul@0 | 569 | children.append(self.flags) |
paul@0 | 570 | children.append(self.doc) |
paul@0 | 571 | children.append(self.code) |
paul@0 | 572 | return tuple(children) |
paul@0 | 573 | |
paul@0 | 574 | def getChildNodes(self): |
paul@0 | 575 | nodelist = [] |
paul@0 | 576 | if self.decorators is not None: |
paul@0 | 577 | nodelist.append(self.decorators) |
paul@0 | 578 | nodelist.extend(flatten_nodes(self.defaults)) |
paul@0 | 579 | nodelist.append(self.code) |
paul@0 | 580 | return tuple(nodelist) |
paul@0 | 581 | |
paul@0 | 582 | def __repr__(self): |
paul@0 | 583 | return "Function(%s, %s, %s, %s, %s, %s, %s)" % (repr(self.decorators), repr(self.name), repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.doc), repr(self.code)) |
paul@0 | 584 | |
paul@0 | 585 | class GenExpr(Node): |
paul@0 | 586 | def __init__(self, code, lineno=None): |
paul@0 | 587 | self.code = code |
paul@0 | 588 | self.lineno = lineno |
paul@0 | 589 | self.argnames = ['.0'] |
paul@0 | 590 | self.varargs = self.kwargs = None |
paul@0 | 591 | |
paul@0 | 592 | |
paul@0 | 593 | def getChildren(self): |
paul@0 | 594 | return self.code, |
paul@0 | 595 | |
paul@0 | 596 | def getChildNodes(self): |
paul@0 | 597 | return self.code, |
paul@0 | 598 | |
paul@0 | 599 | def __repr__(self): |
paul@0 | 600 | return "GenExpr(%s)" % (repr(self.code),) |
paul@0 | 601 | |
paul@0 | 602 | class GenExprFor(Node): |
paul@0 | 603 | def __init__(self, assign, iter, ifs, lineno=None): |
paul@0 | 604 | self.assign = assign |
paul@0 | 605 | self.iter = iter |
paul@0 | 606 | self.ifs = ifs |
paul@0 | 607 | self.lineno = lineno |
paul@0 | 608 | self.is_outmost = False |
paul@0 | 609 | |
paul@0 | 610 | def getChildren(self): |
paul@0 | 611 | children = [] |
paul@0 | 612 | children.append(self.assign) |
paul@0 | 613 | children.append(self.iter) |
paul@0 | 614 | children.extend(flatten(self.ifs)) |
paul@0 | 615 | return tuple(children) |
paul@0 | 616 | |
paul@0 | 617 | def getChildNodes(self): |
paul@0 | 618 | nodelist = [] |
paul@0 | 619 | nodelist.append(self.assign) |
paul@0 | 620 | nodelist.append(self.iter) |
paul@0 | 621 | nodelist.extend(flatten_nodes(self.ifs)) |
paul@0 | 622 | return tuple(nodelist) |
paul@0 | 623 | |
paul@0 | 624 | def __repr__(self): |
paul@0 | 625 | return "GenExprFor(%s, %s, %s)" % (repr(self.assign), repr(self.iter), repr(self.ifs)) |
paul@0 | 626 | |
paul@0 | 627 | class GenExprIf(Node): |
paul@0 | 628 | def __init__(self, test, lineno=None): |
paul@0 | 629 | self.test = test |
paul@0 | 630 | self.lineno = lineno |
paul@0 | 631 | |
paul@0 | 632 | def getChildren(self): |
paul@0 | 633 | return self.test, |
paul@0 | 634 | |
paul@0 | 635 | def getChildNodes(self): |
paul@0 | 636 | return self.test, |
paul@0 | 637 | |
paul@0 | 638 | def __repr__(self): |
paul@0 | 639 | return "GenExprIf(%s)" % (repr(self.test),) |
paul@0 | 640 | |
paul@0 | 641 | class GenExprInner(Node): |
paul@0 | 642 | def __init__(self, expr, quals, lineno=None): |
paul@0 | 643 | self.expr = expr |
paul@0 | 644 | self.quals = quals |
paul@0 | 645 | self.lineno = lineno |
paul@0 | 646 | |
paul@0 | 647 | def getChildren(self): |
paul@0 | 648 | children = [] |
paul@0 | 649 | children.append(self.expr) |
paul@0 | 650 | children.extend(flatten(self.quals)) |
paul@0 | 651 | return tuple(children) |
paul@0 | 652 | |
paul@0 | 653 | def getChildNodes(self): |
paul@0 | 654 | nodelist = [] |
paul@0 | 655 | nodelist.append(self.expr) |
paul@0 | 656 | nodelist.extend(flatten_nodes(self.quals)) |
paul@0 | 657 | return tuple(nodelist) |
paul@0 | 658 | |
paul@0 | 659 | def __repr__(self): |
paul@0 | 660 | return "GenExprInner(%s, %s)" % (repr(self.expr), repr(self.quals)) |
paul@0 | 661 | |
paul@0 | 662 | class Getattr(Node): |
paul@0 | 663 | def __init__(self, expr, attrname, lineno=None): |
paul@0 | 664 | self.expr = expr |
paul@0 | 665 | self.attrname = attrname |
paul@0 | 666 | self.lineno = lineno |
paul@0 | 667 | |
paul@0 | 668 | def getChildren(self): |
paul@0 | 669 | return self.expr, self.attrname |
paul@0 | 670 | |
paul@0 | 671 | def getChildNodes(self): |
paul@0 | 672 | return self.expr, |
paul@0 | 673 | |
paul@0 | 674 | def __repr__(self): |
paul@0 | 675 | return "Getattr(%s, %s)" % (repr(self.expr), repr(self.attrname)) |
paul@0 | 676 | |
paul@0 | 677 | class Global(Node): |
paul@0 | 678 | def __init__(self, names, lineno=None): |
paul@0 | 679 | self.names = names |
paul@0 | 680 | self.lineno = lineno |
paul@0 | 681 | |
paul@0 | 682 | def getChildren(self): |
paul@0 | 683 | return self.names, |
paul@0 | 684 | |
paul@0 | 685 | def getChildNodes(self): |
paul@0 | 686 | return () |
paul@0 | 687 | |
paul@0 | 688 | def __repr__(self): |
paul@0 | 689 | return "Global(%s)" % (repr(self.names),) |
paul@0 | 690 | |
paul@0 | 691 | class If(Node): |
paul@0 | 692 | def __init__(self, tests, else_, lineno=None): |
paul@0 | 693 | self.tests = tests |
paul@0 | 694 | self.else_ = else_ |
paul@0 | 695 | self.lineno = lineno |
paul@0 | 696 | |
paul@0 | 697 | def getChildren(self): |
paul@0 | 698 | children = [] |
paul@0 | 699 | children.extend(flatten(self.tests)) |
paul@0 | 700 | children.append(self.else_) |
paul@0 | 701 | return tuple(children) |
paul@0 | 702 | |
paul@0 | 703 | def getChildNodes(self): |
paul@0 | 704 | nodelist = [] |
paul@0 | 705 | nodelist.extend(flatten_nodes(self.tests)) |
paul@0 | 706 | if self.else_ is not None: |
paul@0 | 707 | nodelist.append(self.else_) |
paul@0 | 708 | return tuple(nodelist) |
paul@0 | 709 | |
paul@0 | 710 | def __repr__(self): |
paul@0 | 711 | return "If(%s, %s)" % (repr(self.tests), repr(self.else_)) |
paul@0 | 712 | |
paul@0 | 713 | class IfExp(Node): |
paul@0 | 714 | def __init__(self, test, then, else_, lineno=None): |
paul@0 | 715 | self.test = test |
paul@0 | 716 | self.then = then |
paul@0 | 717 | self.else_ = else_ |
paul@0 | 718 | self.lineno = lineno |
paul@0 | 719 | |
paul@0 | 720 | def getChildren(self): |
paul@0 | 721 | return self.test, self.then, self.else_ |
paul@0 | 722 | |
paul@0 | 723 | def getChildNodes(self): |
paul@0 | 724 | return self.test, self.then, self.else_ |
paul@0 | 725 | |
paul@0 | 726 | def __repr__(self): |
paul@0 | 727 | return "IfExp(%s, %s, %s)" % (repr(self.test), repr(self.then), repr(self.else_)) |
paul@0 | 728 | |
paul@0 | 729 | class Import(Node): |
paul@0 | 730 | def __init__(self, names, lineno=None): |
paul@0 | 731 | self.names = names |
paul@0 | 732 | self.lineno = lineno |
paul@0 | 733 | |
paul@0 | 734 | def getChildren(self): |
paul@0 | 735 | return self.names, |
paul@0 | 736 | |
paul@0 | 737 | def getChildNodes(self): |
paul@0 | 738 | return () |
paul@0 | 739 | |
paul@0 | 740 | def __repr__(self): |
paul@0 | 741 | return "Import(%s)" % (repr(self.names),) |
paul@0 | 742 | |
paul@0 | 743 | class Invert(Node): |
paul@0 | 744 | def __init__(self, expr, lineno=None): |
paul@0 | 745 | self.expr = expr |
paul@0 | 746 | self.lineno = lineno |
paul@0 | 747 | |
paul@0 | 748 | def getChildren(self): |
paul@0 | 749 | return self.expr, |
paul@0 | 750 | |
paul@0 | 751 | def getChildNodes(self): |
paul@0 | 752 | return self.expr, |
paul@0 | 753 | |
paul@0 | 754 | def __repr__(self): |
paul@0 | 755 | return "Invert(%s)" % (repr(self.expr),) |
paul@0 | 756 | |
paul@0 | 757 | class Keyword(Node): |
paul@0 | 758 | def __init__(self, name, expr, lineno=None): |
paul@0 | 759 | self.name = name |
paul@0 | 760 | self.expr = expr |
paul@0 | 761 | self.lineno = lineno |
paul@0 | 762 | |
paul@0 | 763 | def getChildren(self): |
paul@0 | 764 | return self.name, self.expr |
paul@0 | 765 | |
paul@0 | 766 | def getChildNodes(self): |
paul@0 | 767 | return self.expr, |
paul@0 | 768 | |
paul@0 | 769 | def __repr__(self): |
paul@0 | 770 | return "Keyword(%s, %s)" % (repr(self.name), repr(self.expr)) |
paul@0 | 771 | |
paul@0 | 772 | class Lambda(Node): |
paul@0 | 773 | def __init__(self, argnames, defaults, flags, code, lineno=None): |
paul@0 | 774 | self.argnames = argnames |
paul@0 | 775 | self.defaults = defaults |
paul@0 | 776 | self.flags = flags |
paul@0 | 777 | self.code = code |
paul@0 | 778 | self.lineno = lineno |
paul@0 | 779 | self.varargs = self.kwargs = None |
paul@0 | 780 | if flags & CO_VARARGS: |
paul@0 | 781 | self.varargs = 1 |
paul@0 | 782 | if flags & CO_VARKEYWORDS: |
paul@0 | 783 | self.kwargs = 1 |
paul@0 | 784 | |
paul@0 | 785 | |
paul@0 | 786 | def getChildren(self): |
paul@0 | 787 | children = [] |
paul@0 | 788 | children.append(self.argnames) |
paul@0 | 789 | children.extend(flatten(self.defaults)) |
paul@0 | 790 | children.append(self.flags) |
paul@0 | 791 | children.append(self.code) |
paul@0 | 792 | return tuple(children) |
paul@0 | 793 | |
paul@0 | 794 | def getChildNodes(self): |
paul@0 | 795 | nodelist = [] |
paul@0 | 796 | nodelist.extend(flatten_nodes(self.defaults)) |
paul@0 | 797 | nodelist.append(self.code) |
paul@0 | 798 | return tuple(nodelist) |
paul@0 | 799 | |
paul@0 | 800 | def __repr__(self): |
paul@0 | 801 | return "Lambda(%s, %s, %s, %s)" % (repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.code)) |
paul@0 | 802 | |
paul@0 | 803 | class LeftShift(Node): |
paul@0 | 804 | def __init__(self, leftright, lineno=None): |
paul@0 | 805 | self.left = leftright[0] |
paul@0 | 806 | self.right = leftright[1] |
paul@0 | 807 | self.lineno = lineno |
paul@0 | 808 | |
paul@0 | 809 | def getChildren(self): |
paul@0 | 810 | return self.left, self.right |
paul@0 | 811 | |
paul@0 | 812 | def getChildNodes(self): |
paul@0 | 813 | return self.left, self.right |
paul@0 | 814 | |
paul@0 | 815 | def __repr__(self): |
paul@0 | 816 | return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 817 | |
paul@0 | 818 | class List(Node): |
paul@0 | 819 | def __init__(self, nodes, lineno=None): |
paul@0 | 820 | self.nodes = nodes |
paul@0 | 821 | self.lineno = lineno |
paul@0 | 822 | |
paul@0 | 823 | def getChildren(self): |
paul@0 | 824 | return tuple(flatten(self.nodes)) |
paul@0 | 825 | |
paul@0 | 826 | def getChildNodes(self): |
paul@0 | 827 | nodelist = [] |
paul@0 | 828 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 829 | return tuple(nodelist) |
paul@0 | 830 | |
paul@0 | 831 | def __repr__(self): |
paul@0 | 832 | return "List(%s)" % (repr(self.nodes),) |
paul@0 | 833 | |
paul@0 | 834 | class ListComp(Node): |
paul@0 | 835 | def __init__(self, expr, quals, lineno=None): |
paul@0 | 836 | self.expr = expr |
paul@0 | 837 | self.quals = quals |
paul@0 | 838 | self.lineno = lineno |
paul@0 | 839 | |
paul@0 | 840 | def getChildren(self): |
paul@0 | 841 | children = [] |
paul@0 | 842 | children.append(self.expr) |
paul@0 | 843 | children.extend(flatten(self.quals)) |
paul@0 | 844 | return tuple(children) |
paul@0 | 845 | |
paul@0 | 846 | def getChildNodes(self): |
paul@0 | 847 | nodelist = [] |
paul@0 | 848 | nodelist.append(self.expr) |
paul@0 | 849 | nodelist.extend(flatten_nodes(self.quals)) |
paul@0 | 850 | return tuple(nodelist) |
paul@0 | 851 | |
paul@0 | 852 | def __repr__(self): |
paul@0 | 853 | return "ListComp(%s, %s)" % (repr(self.expr), repr(self.quals)) |
paul@0 | 854 | |
paul@0 | 855 | class ListCompFor(Node): |
paul@0 | 856 | def __init__(self, assign, list, ifs, lineno=None): |
paul@0 | 857 | self.assign = assign |
paul@0 | 858 | self.list = list |
paul@0 | 859 | self.ifs = ifs |
paul@0 | 860 | self.lineno = lineno |
paul@0 | 861 | |
paul@0 | 862 | def getChildren(self): |
paul@0 | 863 | children = [] |
paul@0 | 864 | children.append(self.assign) |
paul@0 | 865 | children.append(self.list) |
paul@0 | 866 | children.extend(flatten(self.ifs)) |
paul@0 | 867 | return tuple(children) |
paul@0 | 868 | |
paul@0 | 869 | def getChildNodes(self): |
paul@0 | 870 | nodelist = [] |
paul@0 | 871 | nodelist.append(self.assign) |
paul@0 | 872 | nodelist.append(self.list) |
paul@0 | 873 | nodelist.extend(flatten_nodes(self.ifs)) |
paul@0 | 874 | return tuple(nodelist) |
paul@0 | 875 | |
paul@0 | 876 | def __repr__(self): |
paul@0 | 877 | return "ListCompFor(%s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.ifs)) |
paul@0 | 878 | |
paul@0 | 879 | class ListCompIf(Node): |
paul@0 | 880 | def __init__(self, test, lineno=None): |
paul@0 | 881 | self.test = test |
paul@0 | 882 | self.lineno = lineno |
paul@0 | 883 | |
paul@0 | 884 | def getChildren(self): |
paul@0 | 885 | return self.test, |
paul@0 | 886 | |
paul@0 | 887 | def getChildNodes(self): |
paul@0 | 888 | return self.test, |
paul@0 | 889 | |
paul@0 | 890 | def __repr__(self): |
paul@0 | 891 | return "ListCompIf(%s)" % (repr(self.test),) |
paul@0 | 892 | |
paul@0 | 893 | class Mod(Node): |
paul@0 | 894 | def __init__(self, leftright, lineno=None): |
paul@0 | 895 | self.left = leftright[0] |
paul@0 | 896 | self.right = leftright[1] |
paul@0 | 897 | self.lineno = lineno |
paul@0 | 898 | |
paul@0 | 899 | def getChildren(self): |
paul@0 | 900 | return self.left, self.right |
paul@0 | 901 | |
paul@0 | 902 | def getChildNodes(self): |
paul@0 | 903 | return self.left, self.right |
paul@0 | 904 | |
paul@0 | 905 | def __repr__(self): |
paul@0 | 906 | return "Mod((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 907 | |
paul@0 | 908 | class Module(Node): |
paul@0 | 909 | def __init__(self, doc, node, lineno=None): |
paul@0 | 910 | self.doc = doc |
paul@0 | 911 | self.node = node |
paul@0 | 912 | self.lineno = lineno |
paul@0 | 913 | |
paul@0 | 914 | def getChildren(self): |
paul@0 | 915 | return self.doc, self.node |
paul@0 | 916 | |
paul@0 | 917 | def getChildNodes(self): |
paul@0 | 918 | return self.node, |
paul@0 | 919 | |
paul@0 | 920 | def __repr__(self): |
paul@0 | 921 | return "Module(%s, %s)" % (repr(self.doc), repr(self.node)) |
paul@0 | 922 | |
paul@0 | 923 | class Mul(Node): |
paul@0 | 924 | def __init__(self, leftright, lineno=None): |
paul@0 | 925 | self.left = leftright[0] |
paul@0 | 926 | self.right = leftright[1] |
paul@0 | 927 | self.lineno = lineno |
paul@0 | 928 | |
paul@0 | 929 | def getChildren(self): |
paul@0 | 930 | return self.left, self.right |
paul@0 | 931 | |
paul@0 | 932 | def getChildNodes(self): |
paul@0 | 933 | return self.left, self.right |
paul@0 | 934 | |
paul@0 | 935 | def __repr__(self): |
paul@0 | 936 | return "Mul((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 937 | |
paul@0 | 938 | class Name(Node): |
paul@0 | 939 | def __init__(self, name, lineno=None): |
paul@0 | 940 | self.name = name |
paul@0 | 941 | self.lineno = lineno |
paul@0 | 942 | |
paul@0 | 943 | def getChildren(self): |
paul@0 | 944 | return self.name, |
paul@0 | 945 | |
paul@0 | 946 | def getChildNodes(self): |
paul@0 | 947 | return () |
paul@0 | 948 | |
paul@0 | 949 | def __repr__(self): |
paul@0 | 950 | return "Name(%s)" % (repr(self.name),) |
paul@0 | 951 | |
paul@0 | 952 | class Not(Node): |
paul@0 | 953 | def __init__(self, expr, lineno=None): |
paul@0 | 954 | self.expr = expr |
paul@0 | 955 | self.lineno = lineno |
paul@0 | 956 | |
paul@0 | 957 | def getChildren(self): |
paul@0 | 958 | return self.expr, |
paul@0 | 959 | |
paul@0 | 960 | def getChildNodes(self): |
paul@0 | 961 | return self.expr, |
paul@0 | 962 | |
paul@0 | 963 | def __repr__(self): |
paul@0 | 964 | return "Not(%s)" % (repr(self.expr),) |
paul@0 | 965 | |
paul@0 | 966 | class Or(Node): |
paul@0 | 967 | def __init__(self, nodes, lineno=None): |
paul@0 | 968 | self.nodes = nodes |
paul@0 | 969 | self.lineno = lineno |
paul@0 | 970 | |
paul@0 | 971 | def getChildren(self): |
paul@0 | 972 | return tuple(flatten(self.nodes)) |
paul@0 | 973 | |
paul@0 | 974 | def getChildNodes(self): |
paul@0 | 975 | nodelist = [] |
paul@0 | 976 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 977 | return tuple(nodelist) |
paul@0 | 978 | |
paul@0 | 979 | def __repr__(self): |
paul@0 | 980 | return "Or(%s)" % (repr(self.nodes),) |
paul@0 | 981 | |
paul@0 | 982 | class Pass(Node): |
paul@0 | 983 | def __init__(self, lineno=None): |
paul@0 | 984 | self.lineno = lineno |
paul@0 | 985 | |
paul@0 | 986 | def getChildren(self): |
paul@0 | 987 | return () |
paul@0 | 988 | |
paul@0 | 989 | def getChildNodes(self): |
paul@0 | 990 | return () |
paul@0 | 991 | |
paul@0 | 992 | def __repr__(self): |
paul@0 | 993 | return "Pass()" |
paul@0 | 994 | |
paul@0 | 995 | class Power(Node): |
paul@0 | 996 | def __init__(self, leftright, lineno=None): |
paul@0 | 997 | self.left = leftright[0] |
paul@0 | 998 | self.right = leftright[1] |
paul@0 | 999 | self.lineno = lineno |
paul@0 | 1000 | |
paul@0 | 1001 | def getChildren(self): |
paul@0 | 1002 | return self.left, self.right |
paul@0 | 1003 | |
paul@0 | 1004 | def getChildNodes(self): |
paul@0 | 1005 | return self.left, self.right |
paul@0 | 1006 | |
paul@0 | 1007 | def __repr__(self): |
paul@0 | 1008 | return "Power((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 1009 | |
paul@0 | 1010 | class Print(Node): |
paul@0 | 1011 | def __init__(self, nodes, dest, lineno=None): |
paul@0 | 1012 | self.nodes = nodes |
paul@0 | 1013 | self.dest = dest |
paul@0 | 1014 | self.lineno = lineno |
paul@0 | 1015 | |
paul@0 | 1016 | def getChildren(self): |
paul@0 | 1017 | children = [] |
paul@0 | 1018 | children.extend(flatten(self.nodes)) |
paul@0 | 1019 | children.append(self.dest) |
paul@0 | 1020 | return tuple(children) |
paul@0 | 1021 | |
paul@0 | 1022 | def getChildNodes(self): |
paul@0 | 1023 | nodelist = [] |
paul@0 | 1024 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 1025 | if self.dest is not None: |
paul@0 | 1026 | nodelist.append(self.dest) |
paul@0 | 1027 | return tuple(nodelist) |
paul@0 | 1028 | |
paul@0 | 1029 | def __repr__(self): |
paul@0 | 1030 | return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest)) |
paul@0 | 1031 | |
paul@0 | 1032 | class Printnl(Node): |
paul@0 | 1033 | def __init__(self, nodes, dest, lineno=None): |
paul@0 | 1034 | self.nodes = nodes |
paul@0 | 1035 | self.dest = dest |
paul@0 | 1036 | self.lineno = lineno |
paul@0 | 1037 | |
paul@0 | 1038 | def getChildren(self): |
paul@0 | 1039 | children = [] |
paul@0 | 1040 | children.extend(flatten(self.nodes)) |
paul@0 | 1041 | children.append(self.dest) |
paul@0 | 1042 | return tuple(children) |
paul@0 | 1043 | |
paul@0 | 1044 | def getChildNodes(self): |
paul@0 | 1045 | nodelist = [] |
paul@0 | 1046 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 1047 | if self.dest is not None: |
paul@0 | 1048 | nodelist.append(self.dest) |
paul@0 | 1049 | return tuple(nodelist) |
paul@0 | 1050 | |
paul@0 | 1051 | def __repr__(self): |
paul@0 | 1052 | return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest)) |
paul@0 | 1053 | |
paul@0 | 1054 | class Raise(Node): |
paul@0 | 1055 | def __init__(self, expr1, expr2, expr3, lineno=None): |
paul@0 | 1056 | self.expr1 = expr1 |
paul@0 | 1057 | self.expr2 = expr2 |
paul@0 | 1058 | self.expr3 = expr3 |
paul@0 | 1059 | self.lineno = lineno |
paul@0 | 1060 | |
paul@0 | 1061 | def getChildren(self): |
paul@0 | 1062 | children = [] |
paul@0 | 1063 | children.append(self.expr1) |
paul@0 | 1064 | children.append(self.expr2) |
paul@0 | 1065 | children.append(self.expr3) |
paul@0 | 1066 | return tuple(children) |
paul@0 | 1067 | |
paul@0 | 1068 | def getChildNodes(self): |
paul@0 | 1069 | nodelist = [] |
paul@0 | 1070 | if self.expr1 is not None: |
paul@0 | 1071 | nodelist.append(self.expr1) |
paul@0 | 1072 | if self.expr2 is not None: |
paul@0 | 1073 | nodelist.append(self.expr2) |
paul@0 | 1074 | if self.expr3 is not None: |
paul@0 | 1075 | nodelist.append(self.expr3) |
paul@0 | 1076 | return tuple(nodelist) |
paul@0 | 1077 | |
paul@0 | 1078 | def __repr__(self): |
paul@0 | 1079 | return "Raise(%s, %s, %s)" % (repr(self.expr1), repr(self.expr2), repr(self.expr3)) |
paul@0 | 1080 | |
paul@0 | 1081 | class Return(Node): |
paul@0 | 1082 | def __init__(self, value, lineno=None): |
paul@0 | 1083 | self.value = value |
paul@0 | 1084 | self.lineno = lineno |
paul@0 | 1085 | |
paul@0 | 1086 | def getChildren(self): |
paul@0 | 1087 | return self.value, |
paul@0 | 1088 | |
paul@0 | 1089 | def getChildNodes(self): |
paul@0 | 1090 | return self.value, |
paul@0 | 1091 | |
paul@0 | 1092 | def __repr__(self): |
paul@0 | 1093 | return "Return(%s)" % (repr(self.value),) |
paul@0 | 1094 | |
paul@0 | 1095 | class RightShift(Node): |
paul@0 | 1096 | def __init__(self, leftright, lineno=None): |
paul@0 | 1097 | self.left = leftright[0] |
paul@0 | 1098 | self.right = leftright[1] |
paul@0 | 1099 | self.lineno = lineno |
paul@0 | 1100 | |
paul@0 | 1101 | def getChildren(self): |
paul@0 | 1102 | return self.left, self.right |
paul@0 | 1103 | |
paul@0 | 1104 | def getChildNodes(self): |
paul@0 | 1105 | return self.left, self.right |
paul@0 | 1106 | |
paul@0 | 1107 | def __repr__(self): |
paul@0 | 1108 | return "RightShift((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 1109 | |
paul@0 | 1110 | class Slice(Node): |
paul@0 | 1111 | def __init__(self, expr, flags, lower, upper, lineno=None): |
paul@0 | 1112 | self.expr = expr |
paul@0 | 1113 | self.flags = flags |
paul@0 | 1114 | self.lower = lower |
paul@0 | 1115 | self.upper = upper |
paul@0 | 1116 | self.lineno = lineno |
paul@0 | 1117 | |
paul@0 | 1118 | def getChildren(self): |
paul@0 | 1119 | children = [] |
paul@0 | 1120 | children.append(self.expr) |
paul@0 | 1121 | children.append(self.flags) |
paul@0 | 1122 | children.append(self.lower) |
paul@0 | 1123 | children.append(self.upper) |
paul@0 | 1124 | return tuple(children) |
paul@0 | 1125 | |
paul@0 | 1126 | def getChildNodes(self): |
paul@0 | 1127 | nodelist = [] |
paul@0 | 1128 | nodelist.append(self.expr) |
paul@0 | 1129 | if self.lower is not None: |
paul@0 | 1130 | nodelist.append(self.lower) |
paul@0 | 1131 | if self.upper is not None: |
paul@0 | 1132 | nodelist.append(self.upper) |
paul@0 | 1133 | return tuple(nodelist) |
paul@0 | 1134 | |
paul@0 | 1135 | def __repr__(self): |
paul@0 | 1136 | return "Slice(%s, %s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.lower), repr(self.upper)) |
paul@0 | 1137 | |
paul@0 | 1138 | class Sliceobj(Node): |
paul@0 | 1139 | def __init__(self, nodes, lineno=None): |
paul@0 | 1140 | self.nodes = nodes |
paul@0 | 1141 | self.lineno = lineno |
paul@0 | 1142 | |
paul@0 | 1143 | def getChildren(self): |
paul@0 | 1144 | return tuple(flatten(self.nodes)) |
paul@0 | 1145 | |
paul@0 | 1146 | def getChildNodes(self): |
paul@0 | 1147 | nodelist = [] |
paul@0 | 1148 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 1149 | return tuple(nodelist) |
paul@0 | 1150 | |
paul@0 | 1151 | def __repr__(self): |
paul@0 | 1152 | return "Sliceobj(%s)" % (repr(self.nodes),) |
paul@0 | 1153 | |
paul@0 | 1154 | class Stmt(Node): |
paul@0 | 1155 | def __init__(self, nodes, lineno=None): |
paul@0 | 1156 | self.nodes = nodes |
paul@0 | 1157 | self.lineno = lineno |
paul@0 | 1158 | |
paul@0 | 1159 | def getChildren(self): |
paul@0 | 1160 | return tuple(flatten(self.nodes)) |
paul@0 | 1161 | |
paul@0 | 1162 | def getChildNodes(self): |
paul@0 | 1163 | nodelist = [] |
paul@0 | 1164 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 1165 | return tuple(nodelist) |
paul@0 | 1166 | |
paul@0 | 1167 | def __repr__(self): |
paul@0 | 1168 | return "Stmt(%s)" % (repr(self.nodes),) |
paul@0 | 1169 | |
paul@0 | 1170 | class Sub(Node): |
paul@0 | 1171 | def __init__(self, leftright, lineno=None): |
paul@0 | 1172 | self.left = leftright[0] |
paul@0 | 1173 | self.right = leftright[1] |
paul@0 | 1174 | self.lineno = lineno |
paul@0 | 1175 | |
paul@0 | 1176 | def getChildren(self): |
paul@0 | 1177 | return self.left, self.right |
paul@0 | 1178 | |
paul@0 | 1179 | def getChildNodes(self): |
paul@0 | 1180 | return self.left, self.right |
paul@0 | 1181 | |
paul@0 | 1182 | def __repr__(self): |
paul@0 | 1183 | return "Sub((%s, %s))" % (repr(self.left), repr(self.right)) |
paul@0 | 1184 | |
paul@0 | 1185 | class Subscript(Node): |
paul@0 | 1186 | def __init__(self, expr, flags, subs, lineno=None): |
paul@0 | 1187 | self.expr = expr |
paul@0 | 1188 | self.flags = flags |
paul@0 | 1189 | self.subs = subs |
paul@0 | 1190 | self.lineno = lineno |
paul@0 | 1191 | |
paul@0 | 1192 | def getChildren(self): |
paul@0 | 1193 | children = [] |
paul@0 | 1194 | children.append(self.expr) |
paul@0 | 1195 | children.append(self.flags) |
paul@0 | 1196 | children.extend(flatten(self.subs)) |
paul@0 | 1197 | return tuple(children) |
paul@0 | 1198 | |
paul@0 | 1199 | def getChildNodes(self): |
paul@0 | 1200 | nodelist = [] |
paul@0 | 1201 | nodelist.append(self.expr) |
paul@0 | 1202 | nodelist.extend(flatten_nodes(self.subs)) |
paul@0 | 1203 | return tuple(nodelist) |
paul@0 | 1204 | |
paul@0 | 1205 | def __repr__(self): |
paul@0 | 1206 | return "Subscript(%s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.subs)) |
paul@0 | 1207 | |
paul@0 | 1208 | class TryExcept(Node): |
paul@0 | 1209 | def __init__(self, body, handlers, else_, lineno=None): |
paul@0 | 1210 | self.body = body |
paul@0 | 1211 | self.handlers = handlers |
paul@0 | 1212 | self.else_ = else_ |
paul@0 | 1213 | self.lineno = lineno |
paul@0 | 1214 | |
paul@0 | 1215 | def getChildren(self): |
paul@0 | 1216 | children = [] |
paul@0 | 1217 | children.append(self.body) |
paul@0 | 1218 | children.extend(flatten(self.handlers)) |
paul@0 | 1219 | children.append(self.else_) |
paul@0 | 1220 | return tuple(children) |
paul@0 | 1221 | |
paul@0 | 1222 | def getChildNodes(self): |
paul@0 | 1223 | nodelist = [] |
paul@0 | 1224 | nodelist.append(self.body) |
paul@0 | 1225 | nodelist.extend(flatten_nodes(self.handlers)) |
paul@0 | 1226 | if self.else_ is not None: |
paul@0 | 1227 | nodelist.append(self.else_) |
paul@0 | 1228 | return tuple(nodelist) |
paul@0 | 1229 | |
paul@0 | 1230 | def __repr__(self): |
paul@0 | 1231 | return "TryExcept(%s, %s, %s)" % (repr(self.body), repr(self.handlers), repr(self.else_)) |
paul@0 | 1232 | |
paul@0 | 1233 | class TryFinally(Node): |
paul@0 | 1234 | def __init__(self, body, final, lineno=None): |
paul@0 | 1235 | self.body = body |
paul@0 | 1236 | self.final = final |
paul@0 | 1237 | self.lineno = lineno |
paul@0 | 1238 | |
paul@0 | 1239 | def getChildren(self): |
paul@0 | 1240 | return self.body, self.final |
paul@0 | 1241 | |
paul@0 | 1242 | def getChildNodes(self): |
paul@0 | 1243 | return self.body, self.final |
paul@0 | 1244 | |
paul@0 | 1245 | def __repr__(self): |
paul@0 | 1246 | return "TryFinally(%s, %s)" % (repr(self.body), repr(self.final)) |
paul@0 | 1247 | |
paul@0 | 1248 | class Tuple(Node): |
paul@0 | 1249 | def __init__(self, nodes, lineno=None): |
paul@0 | 1250 | self.nodes = nodes |
paul@0 | 1251 | self.lineno = lineno |
paul@0 | 1252 | |
paul@0 | 1253 | def getChildren(self): |
paul@0 | 1254 | return tuple(flatten(self.nodes)) |
paul@0 | 1255 | |
paul@0 | 1256 | def getChildNodes(self): |
paul@0 | 1257 | nodelist = [] |
paul@0 | 1258 | nodelist.extend(flatten_nodes(self.nodes)) |
paul@0 | 1259 | return tuple(nodelist) |
paul@0 | 1260 | |
paul@0 | 1261 | def __repr__(self): |
paul@0 | 1262 | return "Tuple(%s)" % (repr(self.nodes),) |
paul@0 | 1263 | |
paul@0 | 1264 | class UnaryAdd(Node): |
paul@0 | 1265 | def __init__(self, expr, lineno=None): |
paul@0 | 1266 | self.expr = expr |
paul@0 | 1267 | self.lineno = lineno |
paul@0 | 1268 | |
paul@0 | 1269 | def getChildren(self): |
paul@0 | 1270 | return self.expr, |
paul@0 | 1271 | |
paul@0 | 1272 | def getChildNodes(self): |
paul@0 | 1273 | return self.expr, |
paul@0 | 1274 | |
paul@0 | 1275 | def __repr__(self): |
paul@0 | 1276 | return "UnaryAdd(%s)" % (repr(self.expr),) |
paul@0 | 1277 | |
paul@0 | 1278 | class UnarySub(Node): |
paul@0 | 1279 | def __init__(self, expr, lineno=None): |
paul@0 | 1280 | self.expr = expr |
paul@0 | 1281 | self.lineno = lineno |
paul@0 | 1282 | |
paul@0 | 1283 | def getChildren(self): |
paul@0 | 1284 | return self.expr, |
paul@0 | 1285 | |
paul@0 | 1286 | def getChildNodes(self): |
paul@0 | 1287 | return self.expr, |
paul@0 | 1288 | |
paul@0 | 1289 | def __repr__(self): |
paul@0 | 1290 | return "UnarySub(%s)" % (repr(self.expr),) |
paul@0 | 1291 | |
paul@0 | 1292 | class While(Node): |
paul@0 | 1293 | def __init__(self, test, body, else_, lineno=None): |
paul@0 | 1294 | self.test = test |
paul@0 | 1295 | self.body = body |
paul@0 | 1296 | self.else_ = else_ |
paul@0 | 1297 | self.lineno = lineno |
paul@0 | 1298 | |
paul@0 | 1299 | def getChildren(self): |
paul@0 | 1300 | children = [] |
paul@0 | 1301 | children.append(self.test) |
paul@0 | 1302 | children.append(self.body) |
paul@0 | 1303 | children.append(self.else_) |
paul@0 | 1304 | return tuple(children) |
paul@0 | 1305 | |
paul@0 | 1306 | def getChildNodes(self): |
paul@0 | 1307 | nodelist = [] |
paul@0 | 1308 | nodelist.append(self.test) |
paul@0 | 1309 | nodelist.append(self.body) |
paul@0 | 1310 | if self.else_ is not None: |
paul@0 | 1311 | nodelist.append(self.else_) |
paul@0 | 1312 | return tuple(nodelist) |
paul@0 | 1313 | |
paul@0 | 1314 | def __repr__(self): |
paul@0 | 1315 | return "While(%s, %s, %s)" % (repr(self.test), repr(self.body), repr(self.else_)) |
paul@0 | 1316 | |
paul@0 | 1317 | class With(Node): |
paul@0 | 1318 | def __init__(self, expr, vars, body, lineno=None): |
paul@0 | 1319 | self.expr = expr |
paul@0 | 1320 | self.vars = vars |
paul@0 | 1321 | self.body = body |
paul@0 | 1322 | self.lineno = lineno |
paul@0 | 1323 | |
paul@0 | 1324 | def getChildren(self): |
paul@0 | 1325 | children = [] |
paul@0 | 1326 | children.append(self.expr) |
paul@0 | 1327 | children.append(self.vars) |
paul@0 | 1328 | children.append(self.body) |
paul@0 | 1329 | return tuple(children) |
paul@0 | 1330 | |
paul@0 | 1331 | def getChildNodes(self): |
paul@0 | 1332 | nodelist = [] |
paul@0 | 1333 | nodelist.append(self.expr) |
paul@0 | 1334 | if self.vars is not None: |
paul@0 | 1335 | nodelist.append(self.vars) |
paul@0 | 1336 | nodelist.append(self.body) |
paul@0 | 1337 | return tuple(nodelist) |
paul@0 | 1338 | |
paul@0 | 1339 | def __repr__(self): |
paul@0 | 1340 | return "With(%s, %s, %s)" % (repr(self.expr), repr(self.vars), repr(self.body)) |
paul@0 | 1341 | |
paul@0 | 1342 | class Yield(Node): |
paul@0 | 1343 | def __init__(self, value, lineno=None): |
paul@0 | 1344 | self.value = value |
paul@0 | 1345 | self.lineno = lineno |
paul@0 | 1346 | |
paul@0 | 1347 | def getChildren(self): |
paul@0 | 1348 | return self.value, |
paul@0 | 1349 | |
paul@0 | 1350 | def getChildNodes(self): |
paul@0 | 1351 | return self.value, |
paul@0 | 1352 | |
paul@0 | 1353 | def __repr__(self): |
paul@0 | 1354 | return "Yield(%s)" % (repr(self.value),) |
paul@0 | 1355 | |
paul@0 | 1356 | for name, obj in globals().items(): |
paul@0 | 1357 | if isinstance(obj, type) and issubclass(obj, Node): |
paul@0 | 1358 | nodes[name.lower()] = obj |