paul@17 | 1 | #!/usr/bin/env python |
paul@17 | 2 | |
paul@17 | 3 | """ |
paul@17 | 4 | Translate the AST of a Python program into a more interpretable representation. |
paul@17 | 5 | |
paul@39 | 6 | Copyright (C) 2007, 2008 Paul Boddie <paul@boddie.org.uk> |
paul@17 | 7 | |
paul@17 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@17 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@17 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@17 | 11 | version. |
paul@17 | 12 | |
paul@17 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@17 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@17 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@17 | 16 | details. |
paul@17 | 17 | |
paul@17 | 18 | You should have received a copy of the GNU General Public License along with |
paul@17 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@17 | 20 | """ |
paul@17 | 21 | |
paul@17 | 22 | import micropython.inspect |
paul@17 | 23 | from micropython.rsvp import * |
paul@39 | 24 | from micropython.common import * |
paul@17 | 25 | import compiler.ast |
paul@17 | 26 | from compiler.visitor import ASTVisitor |
paul@17 | 27 | try: |
paul@17 | 28 | set |
paul@17 | 29 | except NameError: |
paul@17 | 30 | from sets import Set as set |
paul@17 | 31 | |
paul@39 | 32 | class TranslateError(ProcessingError): pass |
paul@17 | 33 | |
paul@19 | 34 | class Label: |
paul@19 | 35 | |
paul@19 | 36 | "A reference to a location." |
paul@19 | 37 | |
paul@19 | 38 | def __init__(self, number, location=None): |
paul@19 | 39 | self.number = number |
paul@19 | 40 | self.location = location |
paul@19 | 41 | |
paul@19 | 42 | def __repr__(self): |
paul@19 | 43 | return "Label(%r, location=%r)" % (self.number, self.location) |
paul@19 | 44 | |
paul@17 | 45 | # Program visitors. |
paul@17 | 46 | |
paul@17 | 47 | class Translation(ASTVisitor): |
paul@17 | 48 | |
paul@17 | 49 | "A translated module." |
paul@17 | 50 | |
paul@21 | 51 | def __init__(self, module, objtable, paramtable): |
paul@18 | 52 | |
paul@21 | 53 | """ |
paul@21 | 54 | Initialise the translation with an inspected 'module' and an attribute |
paul@21 | 55 | table 'objtable' and parameter table 'paramtable'. |
paul@21 | 56 | """ |
paul@18 | 57 | |
paul@17 | 58 | ASTVisitor.__init__(self) |
paul@17 | 59 | self.visitor = self |
paul@17 | 60 | self.module = module |
paul@21 | 61 | self.objtable = objtable |
paul@21 | 62 | self.paramtable = paramtable |
paul@17 | 63 | self.unit = None |
paul@17 | 64 | |
paul@19 | 65 | # Wiring within the code. |
paul@19 | 66 | |
paul@19 | 67 | self.labels = {} |
paul@19 | 68 | self.label_number = 0 |
paul@41 | 69 | self.loop_labels = [] |
paul@41 | 70 | |
paul@41 | 71 | # The code itself. |
paul@41 | 72 | |
paul@19 | 73 | self.code = None |
paul@19 | 74 | |
paul@17 | 75 | def get_module_code(self): |
paul@17 | 76 | |
paul@17 | 77 | "Return the top-level module code." |
paul@17 | 78 | |
paul@17 | 79 | self.unit = self.module |
paul@19 | 80 | self.code = [] |
paul@19 | 81 | self.dispatch(self.module.module) |
paul@19 | 82 | return self.code |
paul@17 | 83 | |
paul@17 | 84 | def get_code(self, unit): |
paul@17 | 85 | |
paul@17 | 86 | "Return the code for the given 'unit'." |
paul@17 | 87 | |
paul@17 | 88 | self.unit = unit |
paul@19 | 89 | self.code = [] |
paul@25 | 90 | if unit.node is not None: |
paul@25 | 91 | self.dispatch(unit.node) |
paul@19 | 92 | return self.code |
paul@17 | 93 | |
paul@17 | 94 | def __repr__(self): |
paul@17 | 95 | return "Translation(%r)" % self.module |
paul@17 | 96 | |
paul@17 | 97 | def get_scope(self, name): |
paul@17 | 98 | if self.unit.has_key(name): |
paul@17 | 99 | return "local" |
paul@17 | 100 | elif self.module.has_key(name): |
paul@17 | 101 | return "global" |
paul@17 | 102 | else: |
paul@17 | 103 | return "builtins" |
paul@17 | 104 | |
paul@19 | 105 | # Code writing methods. |
paul@19 | 106 | |
paul@19 | 107 | def new_label(self): |
paul@19 | 108 | number = self.label_number |
paul@19 | 109 | label = Label(number) |
paul@19 | 110 | self.labels[label] = label |
paul@19 | 111 | self.label_number += 1 |
paul@19 | 112 | return label |
paul@19 | 113 | |
paul@19 | 114 | def set_label(self, label): |
paul@19 | 115 | |
paul@19 | 116 | """ |
paul@19 | 117 | Set the location of 'label' to that within the entire image: the |
paul@19 | 118 | location within the code combined with location of the code unit. |
paul@19 | 119 | """ |
paul@19 | 120 | |
paul@19 | 121 | label.location = len(self.code) + self.unit.code_location |
paul@19 | 122 | |
paul@19 | 123 | def new_op(self, op): |
paul@19 | 124 | self.code.append(op) |
paul@19 | 125 | |
paul@43 | 126 | def replace_op(self, op): |
paul@43 | 127 | self.code[-1] = op |
paul@43 | 128 | |
paul@26 | 129 | def last_op(self): |
paul@26 | 130 | return self.code[-1] |
paul@26 | 131 | |
paul@17 | 132 | # Visitor methods. |
paul@17 | 133 | |
paul@17 | 134 | def default(self, node, *args): |
paul@39 | 135 | raise TranslateError(self.module.full_name(), node, "Node class %r is not supported." % node.__class__) |
paul@17 | 136 | |
paul@17 | 137 | def dispatch(self, node, *args): |
paul@17 | 138 | return ASTVisitor.dispatch(self, node, *args) |
paul@17 | 139 | |
paul@43 | 140 | def _visitAttr(self, node, classes): |
paul@43 | 141 | AttrInstruction, AttrIndexInstruction = classes |
paul@43 | 142 | self.dispatch(node.expr) |
paul@43 | 143 | |
paul@43 | 144 | # NOTE: Only simple cases are used for optimisations. |
paul@43 | 145 | |
paul@43 | 146 | last = self.last_op() |
paul@43 | 147 | if isinstance(last, (LoadName, LoadAttr)) and last.attr.assignments == 1: |
paul@43 | 148 | |
paul@43 | 149 | # Get the details of the access. |
paul@43 | 150 | |
paul@43 | 151 | target = last.attr.value |
paul@43 | 152 | target_name = target.full_name() |
paul@43 | 153 | table_entry = self.objtable.table[target_name] |
paul@43 | 154 | pos = table_entry[node.attrname] |
paul@43 | 155 | self.replace_op(AttrInstruction(pos)) |
paul@43 | 156 | |
paul@43 | 157 | else: |
paul@43 | 158 | index = self.objtable.get_index(node.attrname) |
paul@43 | 159 | self.new_op(AttrIndexInstruction(index)) |
paul@43 | 160 | |
paul@17 | 161 | def _visitName(self, node, classes): |
paul@17 | 162 | name = node.name |
paul@17 | 163 | scope = self.get_scope(name) |
paul@37 | 164 | #print self.module.name, node.lineno, name, scope |
paul@17 | 165 | NameInstruction, AttrInstruction = classes |
paul@17 | 166 | |
paul@17 | 167 | if scope == "local": |
paul@17 | 168 | unit = self.unit |
paul@17 | 169 | if isinstance(unit, micropython.inspect.Function): |
paul@38 | 170 | self.new_op(NameInstruction(unit.all_locals()[name])) |
paul@17 | 171 | elif isinstance(unit, micropython.inspect.Class): |
paul@19 | 172 | self.new_op(AttrInstruction(unit.all_class_attributes()[name])) |
paul@17 | 173 | elif isinstance(unit, micropython.inspect.Module): |
paul@19 | 174 | self.new_op(AttrInstruction(unit.module_attributes()[name])) |
paul@17 | 175 | else: |
paul@39 | 176 | raise TranslateError(self.module.full_name(), node, "Program unit %r has no local %r" % (unit, name)) |
paul@17 | 177 | |
paul@17 | 178 | elif scope == "global": |
paul@17 | 179 | globals = self.module.module_attributes() |
paul@17 | 180 | if globals.has_key(name): |
paul@19 | 181 | self.new_op(AttrInstruction(globals[name])) |
paul@17 | 182 | else: |
paul@39 | 183 | raise TranslateError(self.module.full_name(), node, "Module %r has no attribute %r" % (self.module, name)) |
paul@17 | 184 | |
paul@17 | 185 | else: |
paul@17 | 186 | builtins = micropython.inspect.builtins.module_attributes() |
paul@19 | 187 | self.new_op(AttrInstruction(builtins[name])) |
paul@17 | 188 | |
paul@21 | 189 | def visitAdd(self, node): |
paul@17 | 190 | |
paul@21 | 191 | """ |
paul@21 | 192 | _t1 = node.left |
paul@21 | 193 | _t2 = node.right |
paul@21 | 194 | try: |
paul@21 | 195 | _t1.__add__(_t2) |
paul@21 | 196 | except AttributeError: |
paul@21 | 197 | _t2.__radd__(_t1) |
paul@21 | 198 | """ |
paul@17 | 199 | |
paul@19 | 200 | def visitAnd(self, node): pass |
paul@17 | 201 | |
paul@19 | 202 | def visitAssert(self, node): pass |
paul@17 | 203 | |
paul@17 | 204 | def visitAssign(self, node): |
paul@19 | 205 | self.dispatch(node.expr) |
paul@17 | 206 | for n in node.nodes: |
paul@19 | 207 | self.dispatch(n) |
paul@17 | 208 | |
paul@43 | 209 | def visitAssAttr(self, node): |
paul@43 | 210 | self._visitAttr(node, (StoreAttr, StoreAttrIndex)) |
paul@17 | 211 | |
paul@19 | 212 | def visitAssList(self, node): pass |
paul@17 | 213 | |
paul@17 | 214 | def visitAssName(self, node): |
paul@19 | 215 | self._visitName(node, (StoreName, StoreAttr)) |
paul@17 | 216 | |
paul@17 | 217 | visitAssTuple = visitAssList |
paul@17 | 218 | |
paul@19 | 219 | def visitAugAssign(self, node): pass |
paul@17 | 220 | |
paul@19 | 221 | def visitBackquote(self, node): pass |
paul@17 | 222 | |
paul@19 | 223 | def visitBitand(self, node): pass |
paul@17 | 224 | |
paul@19 | 225 | def visitBitor(self, node): pass |
paul@17 | 226 | |
paul@19 | 227 | def visitBitxor(self, node): pass |
paul@17 | 228 | |
paul@41 | 229 | def visitBreak(self, node): |
paul@41 | 230 | next_label, exit_label = self.loop_labels[-1] |
paul@41 | 231 | self.new_op(Jump(exit_label)) |
paul@17 | 232 | |
paul@21 | 233 | def visitCallFunc(self, node): |
paul@21 | 234 | |
paul@21 | 235 | """ |
paul@21 | 236 | Evaluate positional arguments, evaluate and store keyword arguments in |
paul@21 | 237 | the correct location, then invoke the function. |
paul@21 | 238 | """ |
paul@21 | 239 | |
paul@21 | 240 | # Record the location of the invocation. |
paul@21 | 241 | |
paul@21 | 242 | self.new_op(MakeFrame()) # records the start of the frame |
paul@21 | 243 | |
paul@21 | 244 | # Evaluate the target. |
paul@21 | 245 | |
paul@21 | 246 | self.dispatch(node.node) |
paul@21 | 247 | |
paul@26 | 248 | # NOTE: Only simple cases are used for optimisations. |
paul@26 | 249 | |
paul@26 | 250 | last = self.last_op() |
paul@26 | 251 | if isinstance(last, (LoadName, LoadAttr)) and last.attr.assignments == 1: |
paul@26 | 252 | target = last.attr.value |
paul@26 | 253 | else: |
paul@26 | 254 | target = None |
paul@26 | 255 | |
paul@21 | 256 | # Evaluate the arguments. |
paul@21 | 257 | |
paul@22 | 258 | positional = 1 |
paul@22 | 259 | |
paul@21 | 260 | for i, arg in enumerate(node.args): |
paul@21 | 261 | if isinstance(arg, compiler.ast.Keyword): |
paul@22 | 262 | if positional: |
paul@22 | 263 | self.new_op(ReserveFrame(len(node.args) - i)) |
paul@22 | 264 | positional = 0 |
paul@22 | 265 | |
paul@21 | 266 | self.dispatch(arg.expr) |
paul@21 | 267 | |
paul@26 | 268 | # Optimise where the target is known now. |
paul@26 | 269 | |
paul@26 | 270 | if target is not None: |
paul@39 | 271 | |
paul@39 | 272 | # Find the parameter table entry for the target. |
paul@39 | 273 | |
paul@39 | 274 | target_name = target.full_name() |
paul@39 | 275 | |
paul@39 | 276 | # Look for a callable with the precise target name. |
paul@39 | 277 | |
paul@39 | 278 | try: |
paul@39 | 279 | table_entry = self.paramtable.table[target_name] |
paul@39 | 280 | |
paul@39 | 281 | # Where no callable is present, check to see if it is a |
paul@39 | 282 | # class name and find the initialiser instead. |
paul@39 | 283 | |
paul@39 | 284 | except KeyError: |
paul@39 | 285 | if self.objtable.table.has_key(target_name): |
paul@39 | 286 | table_entry = self.paramtable.table[target_name + ".__init__"] |
paul@39 | 287 | else: |
paul@39 | 288 | raise |
paul@39 | 289 | |
paul@39 | 290 | pos = table_entry[arg.name] |
paul@26 | 291 | self.new_op(StoreFrame(pos)) |
paul@26 | 292 | |
paul@26 | 293 | # Otherwise, generate the code needed to obtain the details of |
paul@26 | 294 | # the parameter location. |
paul@26 | 295 | |
paul@26 | 296 | else: |
paul@21 | 297 | |
paul@26 | 298 | # Combine the target details with the name to get the location. |
paul@26 | 299 | # See the access method on the List class. |
paul@26 | 300 | |
paul@39 | 301 | try: |
paul@39 | 302 | paramindex = self.paramtable.get_index(arg.name) |
paul@39 | 303 | except ValueError: |
paul@39 | 304 | raise TranslateError(self.module.full_name(), node, "No parameter definition exists for %r." % arg.name) |
paul@21 | 305 | |
paul@26 | 306 | self.new_op(StoreFrameIndex(paramindex)) |
paul@26 | 307 | |
paul@26 | 308 | # use (callable+0)+paramindex+table |
paul@26 | 309 | # checks embedded offset against (callable+0) |
paul@26 | 310 | # moves the top of stack to frame+position |
paul@21 | 311 | |
paul@21 | 312 | else: |
paul@21 | 313 | self.dispatch(arg) |
paul@21 | 314 | |
paul@21 | 315 | self.new_op(LoadCallable()) # uses the start of the frame to get the callable |
paul@21 | 316 | self.new_op(Jump()) |
paul@21 | 317 | |
paul@21 | 318 | # NOTE: Exception handling required. |
paul@21 | 319 | |
paul@21 | 320 | self.new_op(DropFrame()) |
paul@17 | 321 | |
paul@38 | 322 | def visitClass(self, node): |
paul@38 | 323 | unit = self.unit |
paul@39 | 324 | self.unit = node.unit |
paul@41 | 325 | self.unit.code_location = self.module.code_location + len(self.code) |
paul@38 | 326 | self.dispatch(node.code) |
paul@38 | 327 | self.unit = unit |
paul@17 | 328 | |
paul@21 | 329 | def visitCompare(self, node): |
paul@21 | 330 | |
paul@21 | 331 | """ |
paul@21 | 332 | self.dispatch(node.expr) |
paul@21 | 333 | for op_name, next_node in compare.ops: |
paul@21 | 334 | methods = self.comparison_methods[op_name] |
paul@21 | 335 | if methods is not None: |
paul@21 | 336 | # Generate method call using evaluated argument and next node. |
paul@21 | 337 | else: |
paul@21 | 338 | # Deal with the special operators. |
paul@21 | 339 | # Provide short-circuiting. |
paul@21 | 340 | """ |
paul@17 | 341 | |
paul@22 | 342 | def visitConst(self, node): |
paul@22 | 343 | const = self.module.constant_values[node.value] |
paul@22 | 344 | self.new_op(LoadConst(const)) |
paul@17 | 345 | |
paul@41 | 346 | def visitContinue(self, node): |
paul@41 | 347 | next_label, exit_label = self.loop_labels[-1] |
paul@41 | 348 | self.new_op(Jump(next_label)) |
paul@17 | 349 | |
paul@19 | 350 | def visitDecorators(self, node): pass |
paul@17 | 351 | |
paul@19 | 352 | def visitDict(self, node): pass |
paul@17 | 353 | |
paul@18 | 354 | def visitDiscard(self, node): |
paul@19 | 355 | self.dispatch(node.expr) |
paul@17 | 356 | |
paul@19 | 357 | def visitDiv(self, node): pass |
paul@17 | 358 | |
paul@19 | 359 | def visitEllipsis(self, node): pass |
paul@17 | 360 | |
paul@19 | 361 | def visitExec(self, node): pass |
paul@17 | 362 | |
paul@19 | 363 | def visitExpression(self, node): pass |
paul@17 | 364 | |
paul@19 | 365 | def visitFloorDiv(self, node): pass |
paul@17 | 366 | |
paul@19 | 367 | def visitFor(self, node): pass |
paul@17 | 368 | |
paul@19 | 369 | def visitFrom(self, node): pass |
paul@17 | 370 | |
paul@17 | 371 | def visitFunction(self, node): |
paul@17 | 372 | |
paul@17 | 373 | # Only store the name when visiting this node from outside. |
paul@17 | 374 | |
paul@39 | 375 | if self.unit is not node.unit: |
paul@39 | 376 | self.new_op(LoadConst(node.unit)) |
paul@19 | 377 | self._visitName(node, (StoreName, StoreAttr)) |
paul@22 | 378 | |
paul@22 | 379 | # Visiting of the code occurs when get_code is invoked on this node. |
paul@22 | 380 | |
paul@17 | 381 | else: |
paul@19 | 382 | self.dispatch(node.code) |
paul@21 | 383 | self.new_op(Return()) |
paul@17 | 384 | |
paul@19 | 385 | def visitGenExpr(self, node): pass |
paul@17 | 386 | |
paul@19 | 387 | def visitGenExprFor(self, node): pass |
paul@17 | 388 | |
paul@19 | 389 | def visitGenExprIf(self, node): pass |
paul@17 | 390 | |
paul@19 | 391 | def visitGenExprInner(self, node): pass |
paul@17 | 392 | |
paul@43 | 393 | def visitGetattr(self, node): |
paul@43 | 394 | self._visitAttr(node, (LoadAttr, LoadAttrIndex)) |
paul@17 | 395 | |
paul@19 | 396 | def visitGlobal(self, node): pass |
paul@17 | 397 | |
paul@17 | 398 | def visitIf(self, node): |
paul@19 | 399 | first = 1 |
paul@19 | 400 | exit_label = self.new_label() |
paul@17 | 401 | |
paul@19 | 402 | for test, body in node.tests + [(None, node.else_)]: |
paul@19 | 403 | if body is None: |
paul@19 | 404 | break |
paul@19 | 405 | if not first: |
paul@19 | 406 | self.set_label(next_label) |
paul@19 | 407 | if test is not None: |
paul@19 | 408 | self.dispatch(test) |
paul@19 | 409 | next_label = self.new_label() |
paul@41 | 410 | self.new_op(JumpIfFalse(next_label)) |
paul@19 | 411 | self.dispatch(body) |
paul@19 | 412 | self.new_op(Jump(exit_label)) |
paul@19 | 413 | first = 0 |
paul@17 | 414 | |
paul@19 | 415 | self.set_label(exit_label) |
paul@17 | 416 | |
paul@19 | 417 | def visitImport(self, node): pass |
paul@19 | 418 | |
paul@19 | 419 | def visitInvert(self, node): pass |
paul@17 | 420 | |
paul@19 | 421 | def visitKeyword(self, node): pass |
paul@17 | 422 | |
paul@19 | 423 | def visitLambda(self, node): pass |
paul@19 | 424 | |
paul@19 | 425 | def visitLeftShift(self, node): pass |
paul@17 | 426 | |
paul@19 | 427 | def visitList(self, node): pass |
paul@17 | 428 | |
paul@19 | 429 | def visitListComp(self, node): pass |
paul@17 | 430 | |
paul@19 | 431 | def visitListCompFor(self, node): pass |
paul@17 | 432 | |
paul@19 | 433 | def visitListCompIf(self, node): pass |
paul@19 | 434 | |
paul@19 | 435 | def visitMod(self, node): pass |
paul@17 | 436 | |
paul@17 | 437 | def visitModule(self, node): |
paul@19 | 438 | self.dispatch(node.node) |
paul@17 | 439 | |
paul@19 | 440 | def visitMul(self, node): pass |
paul@17 | 441 | |
paul@17 | 442 | def visitName(self, node): |
paul@19 | 443 | self._visitName(node, (LoadName, LoadAttr)) |
paul@17 | 444 | |
paul@19 | 445 | def visitNot(self, node): pass |
paul@17 | 446 | |
paul@19 | 447 | def visitOr(self, node): pass |
paul@17 | 448 | |
paul@19 | 449 | def visitPass(self, node): pass |
paul@17 | 450 | |
paul@19 | 451 | def visitPower(self, node): pass |
paul@17 | 452 | |
paul@19 | 453 | def visitPrint(self, node): pass |
paul@17 | 454 | |
paul@19 | 455 | def visitPrintnl(self, node): pass |
paul@17 | 456 | |
paul@19 | 457 | def visitRaise(self, node): pass |
paul@17 | 458 | |
paul@21 | 459 | def visitReturn(self, node): |
paul@21 | 460 | if node.value is not None: |
paul@21 | 461 | self.dispatch(node.value) |
paul@21 | 462 | self.new_op(Return()) |
paul@17 | 463 | |
paul@19 | 464 | def visitRightShift(self, node): pass |
paul@17 | 465 | |
paul@19 | 466 | def visitSlice(self, node): pass |
paul@17 | 467 | |
paul@17 | 468 | def visitStmt(self, node): |
paul@17 | 469 | for n in node.nodes: |
paul@19 | 470 | self.dispatch(n) |
paul@19 | 471 | |
paul@19 | 472 | def visitSub(self, node): pass |
paul@17 | 473 | |
paul@19 | 474 | def visitSubscript(self, node): pass |
paul@17 | 475 | |
paul@19 | 476 | def visitTryExcept(self, node): pass |
paul@17 | 477 | |
paul@19 | 478 | def visitTryFinally(self, node): pass |
paul@17 | 479 | |
paul@19 | 480 | def visitTuple(self, node): pass |
paul@17 | 481 | |
paul@19 | 482 | def visitUnaryAdd(self, node): pass |
paul@17 | 483 | |
paul@19 | 484 | def visitUnarySub(self, node): pass |
paul@17 | 485 | |
paul@41 | 486 | def visitWhile(self, node): |
paul@41 | 487 | exit_label = self.new_label() |
paul@41 | 488 | self.dispatch(node.test) |
paul@41 | 489 | self.new_op(JumpIfFalse(exit_label)) |
paul@41 | 490 | |
paul@41 | 491 | next_label = self.new_label() |
paul@41 | 492 | self.set_label(next_label) |
paul@41 | 493 | self.loop_labels.append((next_label, exit_label)) |
paul@41 | 494 | |
paul@41 | 495 | self.dispatch(node.body) |
paul@41 | 496 | self.new_op(Jump(next_label)) |
paul@41 | 497 | |
paul@41 | 498 | if node.else_ is not None: |
paul@41 | 499 | self.dispatch(node.else_) |
paul@41 | 500 | |
paul@41 | 501 | self.set_label(exit_label) |
paul@41 | 502 | self.loop_labels.pop() |
paul@17 | 503 | |
paul@19 | 504 | def visitWith(self, node): pass |
paul@17 | 505 | |
paul@19 | 506 | def visitYield(self, node): pass |
paul@17 | 507 | |
paul@21 | 508 | # Useful data. |
paul@21 | 509 | |
paul@21 | 510 | comparison_methods = { |
paul@21 | 511 | "==" : ("__eq__", "__ne__"), |
paul@21 | 512 | "!=" : ("__ne__", "__eq__"), |
paul@21 | 513 | "<" : ("__lt__", "__gt__"), |
paul@21 | 514 | "<=" : ("__le__", "__ge__"), |
paul@21 | 515 | ">=" : ("__ge__", "__le__"), |
paul@21 | 516 | ">" : ("__gt__", "__lt__"), |
paul@21 | 517 | "is" : None, |
paul@21 | 518 | "is not" : None, |
paul@21 | 519 | "in" : None, |
paul@21 | 520 | "not in" : None |
paul@21 | 521 | } |
paul@21 | 522 | |
paul@17 | 523 | # vim: tabstop=4 expandtab shiftwidth=4 |