paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | """ |
paul@0 | 4 | Inspect source files, obtaining details of classes and attributes. |
paul@0 | 5 | |
paul@299 | 6 | Copyright (C) 2007, 2008, 2009, 2010 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 7 | |
paul@0 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@0 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@0 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@0 | 11 | version. |
paul@0 | 12 | |
paul@0 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@0 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@0 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@0 | 16 | details. |
paul@0 | 17 | |
paul@0 | 18 | You should have received a copy of the GNU General Public License along with |
paul@0 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@91 | 20 | |
paul@91 | 21 | -------- |
paul@91 | 22 | |
paul@91 | 23 | The results of inspecting a module are as follows: |
paul@91 | 24 | |
paul@91 | 25 | Constants |
paul@91 | 26 | --------- |
paul@91 | 27 | |
paul@91 | 28 | All constants identified within the code shall be registered. |
paul@91 | 29 | |
paul@91 | 30 | Classes |
paul@91 | 31 | ------- |
paul@91 | 32 | |
paul@91 | 33 | All global classes shall be registered; local classes (within functions) or |
paul@91 | 34 | nested classes (within classes) are not currently registered. |
paul@91 | 35 | |
paul@91 | 36 | Base classes must be detected and constant. |
paul@91 | 37 | |
paul@91 | 38 | All classes without bases are made to inherit from __builtins__.object in order |
paul@91 | 39 | to support some standard methods. |
paul@91 | 40 | |
paul@91 | 41 | Functions |
paul@91 | 42 | --------- |
paul@91 | 43 | |
paul@91 | 44 | All functions and lambda definitions shall be registered. |
paul@91 | 45 | |
paul@91 | 46 | Namespaces |
paul@91 | 47 | ---------- |
paul@91 | 48 | |
paul@91 | 49 | Modules define their own "global" namespace, within which classes, functions |
paul@91 | 50 | and lambda definitions establish a hierarchy of namespaces. |
paul@91 | 51 | |
paul@91 | 52 | Only local, global and built-in namespaces are recognised; closures are not |
paul@91 | 53 | supported. |
paul@91 | 54 | |
paul@91 | 55 | Assignments |
paul@91 | 56 | ----------- |
paul@91 | 57 | |
paul@91 | 58 | Name assignment and attribute assignment involving modules and classes cause |
paul@91 | 59 | names to be associated with values within namespaces. |
paul@91 | 60 | |
paul@91 | 61 | Any assignments within loops are considered to cause the targets of such |
paul@91 | 62 | assignments to provide non-constant values. |
paul@91 | 63 | |
paul@91 | 64 | Assignments to names are only really considered to cause the targets of such |
paul@91 | 65 | assignments to provide constant values if the targets reside in the module |
paul@91 | 66 | namespace or in class namespaces, subject to the above conditions. |
paul@91 | 67 | |
paul@91 | 68 | Assignments to names within functions are not generally considered to cause the |
paul@91 | 69 | targets of such assignments to provide constant values since functions can be |
paul@331 | 70 | invoked many times with different inputs. This affects particularly the |
paul@331 | 71 | definition of functions or lambdas within functions. However, there may be |
paul@331 | 72 | benefits in considering a local to be constant within a single invocation. |
paul@0 | 73 | """ |
paul@0 | 74 | |
paul@39 | 75 | from micropython.common import * |
paul@83 | 76 | from micropython.data import * |
paul@0 | 77 | import compiler.ast |
paul@15 | 78 | |
paul@21 | 79 | # Program visitors. |
paul@21 | 80 | |
paul@15 | 81 | class InspectedModule(ASTVisitor, Module): |
paul@15 | 82 | |
paul@20 | 83 | """ |
paul@20 | 84 | An inspected module, providing core details via the Module superclass, but |
paul@20 | 85 | capable of being used as an AST visitor. |
paul@20 | 86 | """ |
paul@15 | 87 | |
paul@71 | 88 | def __init__(self, name, importer): |
paul@71 | 89 | |
paul@71 | 90 | """ |
paul@71 | 91 | Initialise this visitor with a module 'name' and an 'importer' which is |
paul@71 | 92 | used to provide access to other modules when required. |
paul@71 | 93 | """ |
paul@71 | 94 | |
paul@15 | 95 | ASTVisitor.__init__(self) |
paul@343 | 96 | Module.__init__(self, name, importer) |
paul@15 | 97 | self.visitor = self |
paul@15 | 98 | |
paul@91 | 99 | # Import machinery links. |
paul@91 | 100 | |
paul@343 | 101 | self.optimisations = self.importer.optimisations |
paul@61 | 102 | self.builtins = self.importer.modules.get("__builtins__") |
paul@15 | 103 | self.loaded = 0 |
paul@15 | 104 | |
paul@1 | 105 | # Current expression state. |
paul@1 | 106 | |
paul@1 | 107 | self.expr = None |
paul@1 | 108 | |
paul@1 | 109 | # Namespace state. |
paul@1 | 110 | |
paul@34 | 111 | self.in_init = 0 # Find instance attributes in __init__ methods. |
paul@91 | 112 | self.in_method = 0 # Find instance attributes in all methods. |
paul@331 | 113 | self.in_function = 0 # Note function presence, affecting definitions. |
paul@34 | 114 | self.in_loop = 0 # Note loop "membership", affecting assignments. |
paul@12 | 115 | self.namespaces = [] |
paul@235 | 116 | self.functions = [] |
paul@0 | 117 | |
paul@0 | 118 | def parse(self, filename): |
paul@9 | 119 | |
paul@9 | 120 | "Parse the file having the given 'filename'." |
paul@9 | 121 | |
paul@0 | 122 | module = compiler.parseFile(filename) |
paul@0 | 123 | self.process(module) |
paul@0 | 124 | |
paul@0 | 125 | def process(self, module): |
paul@9 | 126 | |
paul@9 | 127 | "Process the given 'module'." |
paul@9 | 128 | |
paul@343 | 129 | self.astnode = module |
paul@236 | 130 | |
paul@260 | 131 | # Add __name__ to the namespace by adding an explicit assignment to the |
paul@260 | 132 | # module. |
paul@260 | 133 | |
paul@260 | 134 | module.node.nodes.insert(0, compiler.ast.Assign( |
paul@260 | 135 | [compiler.ast.AssName("__name__", 0)], |
paul@260 | 136 | compiler.ast.Const(self.full_name()) |
paul@260 | 137 | )) |
paul@260 | 138 | |
paul@236 | 139 | # First, visit module-level code, recording global names. |
paul@236 | 140 | |
paul@1 | 141 | processed = self.dispatch(module) |
paul@235 | 142 | |
paul@236 | 143 | # Then, for each function, detect and record globals declared in those |
paul@236 | 144 | # functions. |
paul@236 | 145 | |
paul@236 | 146 | for node, namespaces in self.functions: |
paul@236 | 147 | self.process_globals(node) |
paul@236 | 148 | |
paul@344 | 149 | self.finalise_attribute_usage() |
paul@284 | 150 | |
paul@236 | 151 | # Then, visit each function, recording other names. |
paul@236 | 152 | |
paul@235 | 153 | for node, namespaces in self.functions: |
paul@235 | 154 | self._visitFunctionBody(node, namespaces) |
paul@344 | 155 | namespaces[-1].finalise_attribute_usage() |
paul@280 | 156 | |
paul@236 | 157 | # Add references to other modules declared using the __all__ global. |
paul@236 | 158 | |
paul@13 | 159 | if self.has_key("__all__"): |
paul@12 | 160 | all = self["__all__"] |
paul@1 | 161 | if isinstance(all, compiler.ast.List): |
paul@1 | 162 | for n in all.nodes: |
paul@167 | 163 | self.store(n.value, self.importer.add_module(self.name + "." + n.value)) |
paul@235 | 164 | |
paul@1 | 165 | return processed |
paul@0 | 166 | |
paul@236 | 167 | def process_globals(self, node): |
paul@236 | 168 | |
paul@236 | 169 | """ |
paul@236 | 170 | Within the given 'node', process global declarations, adjusting the |
paul@236 | 171 | module namespace. |
paul@236 | 172 | """ |
paul@236 | 173 | |
paul@236 | 174 | for n in node.getChildNodes(): |
paul@236 | 175 | if isinstance(n, compiler.ast.Global): |
paul@236 | 176 | for name in n.names: |
paul@236 | 177 | if not self.has_key(name): |
paul@236 | 178 | self[name] = None |
paul@236 | 179 | else: |
paul@236 | 180 | self.process_globals(n) |
paul@236 | 181 | |
paul@3 | 182 | def vacuum(self): |
paul@9 | 183 | |
paul@171 | 184 | """ |
paul@171 | 185 | Vacuum the module namespace, removing unreferenced objects and unused |
paul@171 | 186 | names. |
paul@171 | 187 | """ |
paul@9 | 188 | |
paul@241 | 189 | if self.should_optimise_unused_objects(): |
paul@252 | 190 | self.vacuum_object(self) |
paul@0 | 191 | |
paul@167 | 192 | all_objects = list(self.all_objects) |
paul@167 | 193 | |
paul@167 | 194 | for obj in all_objects: |
paul@252 | 195 | if isinstance(obj, Class): |
paul@252 | 196 | self.vacuum_object(obj) |
paul@171 | 197 | |
paul@252 | 198 | def vacuum_object(self, obj, delete_all=0): |
paul@241 | 199 | |
paul@252 | 200 | "Vacuum the given object 'obj'." |
paul@171 | 201 | |
paul@252 | 202 | for name, attr in obj.items(): |
paul@270 | 203 | |
paul@270 | 204 | # Only consider deleting entire unused objects or things accessible |
paul@270 | 205 | # via names which are never used. |
paul@270 | 206 | |
paul@344 | 207 | if delete_all or not self.importer.uses_attribute(obj.full_name(), name): |
paul@252 | 208 | del obj[name] |
paul@270 | 209 | |
paul@270 | 210 | # Delete any unambiguous attribute value. Such values can only |
paul@270 | 211 | # have been defined within the object and therefore are not |
paul@270 | 212 | # redefined by other code regions. |
paul@270 | 213 | |
paul@252 | 214 | if attr.assignments == 1: |
paul@252 | 215 | value = attr.get_value() |
paul@171 | 216 | |
paul@252 | 217 | if value is not obj and value in self.all_objects: |
paul@252 | 218 | self.all_objects.remove(value) |
paul@171 | 219 | |
paul@252 | 220 | # Delete class contents. |
paul@241 | 221 | |
paul@252 | 222 | if isinstance(value, Class): |
paul@252 | 223 | self.vacuum_object(value, 1) |
paul@171 | 224 | |
paul@287 | 225 | def unfinalise(self): |
paul@287 | 226 | |
paul@287 | 227 | "Reset finalised information for the module." |
paul@287 | 228 | |
paul@287 | 229 | for obj in self.all_objects: |
paul@287 | 230 | obj.unfinalise_attributes() |
paul@287 | 231 | |
paul@171 | 232 | def finalise(self): |
paul@171 | 233 | |
paul@171 | 234 | "Finalise the module." |
paul@171 | 235 | |
paul@171 | 236 | for obj in self.all_objects: |
paul@287 | 237 | obj.finalise_attributes() |
paul@171 | 238 | |
paul@167 | 239 | def add_object(self, obj, any_scope=0): |
paul@167 | 240 | |
paul@167 | 241 | """ |
paul@167 | 242 | Record 'obj' if non-local or if the optional 'any_scope' is set to a |
paul@167 | 243 | true value. |
paul@167 | 244 | """ |
paul@167 | 245 | |
paul@167 | 246 | if any_scope or not (self.namespaces and isinstance(self.namespaces[-1], Function)): |
paul@167 | 247 | self.all_objects.add(obj) |
paul@167 | 248 | |
paul@167 | 249 | # Optimisation tests. |
paul@167 | 250 | |
paul@167 | 251 | def should_optimise_unused_objects(self): |
paul@167 | 252 | return "unused_objects" in self.optimisations |
paul@167 | 253 | |
paul@3 | 254 | # Namespace methods. |
paul@0 | 255 | |
paul@330 | 256 | def in_class(self, namespaces=None): |
paul@330 | 257 | namespaces = namespaces or self.namespaces |
paul@330 | 258 | return len(namespaces) > 1 and isinstance(namespaces[-2], Class) |
paul@330 | 259 | |
paul@0 | 260 | def store(self, name, obj): |
paul@12 | 261 | |
paul@12 | 262 | "Record attribute or local 'name', storing 'obj'." |
paul@12 | 263 | |
paul@339 | 264 | # Store in the module. |
paul@339 | 265 | |
paul@12 | 266 | if not self.namespaces: |
paul@342 | 267 | if self.in_loop and self.used_in_scope(name, "builtins"): |
paul@339 | 268 | raise InspectError("Name %r already used as a built-in." % name) |
paul@339 | 269 | else: |
paul@339 | 270 | self.set(name, obj, not self.in_loop) |
paul@339 | 271 | |
paul@339 | 272 | # Or store locally. |
paul@339 | 273 | |
paul@12 | 274 | else: |
paul@341 | 275 | locals = self.namespaces[-1] |
paul@341 | 276 | |
paul@342 | 277 | if self.in_loop and locals.used_in_scope(name, "global") and not name in locals.globals: |
paul@341 | 278 | raise InspectError("Name %r already used as global." % name) |
paul@342 | 279 | elif self.in_loop and locals.used_in_scope(name, "builtins"): |
paul@341 | 280 | raise InspectError("Name %r already used as a built-in." % name) |
paul@341 | 281 | else: |
paul@341 | 282 | locals.set(name, obj, not self.in_loop) |
paul@12 | 283 | |
paul@85 | 284 | def store_lambda(self, obj): |
paul@91 | 285 | |
paul@91 | 286 | "Store a lambda function 'obj'." |
paul@91 | 287 | |
paul@167 | 288 | self.add_object(obj) |
paul@85 | 289 | |
paul@94 | 290 | def store_module_attr(self, name, module): |
paul@94 | 291 | |
paul@94 | 292 | """ |
paul@94 | 293 | Record module attribute 'name' in the given 'module' using the current |
paul@94 | 294 | expression. |
paul@94 | 295 | """ |
paul@94 | 296 | |
paul@192 | 297 | module.set(name, self.expr, 0) |
paul@94 | 298 | |
paul@91 | 299 | def store_class_attr(self, name): |
paul@91 | 300 | |
paul@94 | 301 | """ |
paul@94 | 302 | Record class attribute 'name' in the current class using the current |
paul@94 | 303 | expression. |
paul@94 | 304 | """ |
paul@91 | 305 | |
paul@91 | 306 | if self.in_method and self.namespaces[-2].has_key(name): |
paul@192 | 307 | self.namespaces[-2].set(name, self.expr, 0) |
paul@91 | 308 | return 1 |
paul@91 | 309 | |
paul@91 | 310 | return 0 |
paul@91 | 311 | |
paul@34 | 312 | def store_instance_attr(self, name): |
paul@12 | 313 | |
paul@12 | 314 | "Record instance attribute 'name' in the current class." |
paul@12 | 315 | |
paul@91 | 316 | if self.in_method: |
paul@15 | 317 | |
paul@12 | 318 | # Current namespace is the function. |
paul@12 | 319 | # Previous namespace is the class. |
paul@15 | 320 | |
paul@12 | 321 | self.namespaces[-2].add_instance_attribute(name) |
paul@0 | 322 | |
paul@272 | 323 | def get_namespace(self): |
paul@71 | 324 | |
paul@71 | 325 | "Return the parent (or most recent) namespace currently exposed." |
paul@71 | 326 | |
paul@12 | 327 | return (self.namespaces[-1:] or [self])[0] |
paul@7 | 328 | |
paul@323 | 329 | def use_name(self, name, node=None): |
paul@323 | 330 | |
paul@323 | 331 | """ |
paul@323 | 332 | Use the given 'name' within the current namespace/unit, either in |
paul@323 | 333 | conjunction with a particular object (if 'node' is specified and not |
paul@323 | 334 | None) or unconditionally. |
paul@323 | 335 | """ |
paul@250 | 336 | |
paul@323 | 337 | if node is not None and isinstance(node, compiler.ast.Name): |
paul@323 | 338 | self.use_attribute(node.name, name) |
paul@250 | 339 | |
paul@323 | 340 | # For general name usage, declare usage of the given name from this |
paul@323 | 341 | # particular unit. |
paul@323 | 342 | |
paul@323 | 343 | else: |
paul@323 | 344 | unit = self.get_namespace() |
paul@323 | 345 | self.importer.use_name(name, unit.full_name()) |
paul@250 | 346 | |
paul@279 | 347 | # Attribute usage methods. |
paul@279 | 348 | # These are convenience methods which refer to the specific namespace's |
paul@279 | 349 | # implementation of these operations. |
paul@279 | 350 | |
paul@272 | 351 | def new_branchpoint(self): |
paul@272 | 352 | self.get_namespace()._new_branchpoint() |
paul@272 | 353 | |
paul@311 | 354 | def new_branch(self, loop_node=None): |
paul@311 | 355 | self.get_namespace()._new_branch(loop_node) |
paul@272 | 356 | |
paul@299 | 357 | def abandon_branch(self): |
paul@299 | 358 | self.get_namespace()._abandon_branch() |
paul@299 | 359 | |
paul@272 | 360 | def shelve_branch(self): |
paul@272 | 361 | self.get_namespace()._shelve_branch() |
paul@272 | 362 | |
paul@272 | 363 | def merge_branches(self): |
paul@272 | 364 | self.get_namespace()._merge_branches() |
paul@272 | 365 | |
paul@278 | 366 | def define_attribute_user(self, node): |
paul@279 | 367 | |
paul@279 | 368 | """ |
paul@279 | 369 | Define 'node' as the user of attributes, indicating the point where the |
paul@279 | 370 | user is defined. |
paul@279 | 371 | """ |
paul@279 | 372 | |
paul@278 | 373 | self.get_namespace()._define_attribute_user(node) |
paul@272 | 374 | |
paul@280 | 375 | def use_attribute(self, name, attrname): |
paul@323 | 376 | |
paul@323 | 377 | "Note usage on the attribute user 'name' of the attribute 'attrname'." |
paul@323 | 378 | |
paul@280 | 379 | return self.get_namespace()._use_attribute(name, attrname) |
paul@272 | 380 | |
paul@347 | 381 | def use_specific_attribute(self, objname, attrname): |
paul@347 | 382 | |
paul@347 | 383 | """ |
paul@347 | 384 | Note usage on the object having the given 'objname' of the attribute |
paul@347 | 385 | 'attrname'. |
paul@347 | 386 | """ |
paul@347 | 387 | |
paul@347 | 388 | return self.get_namespace()._use_specific_attribute(objname, attrname) |
paul@347 | 389 | |
paul@3 | 390 | # Visitor methods. |
paul@3 | 391 | |
paul@3 | 392 | def default(self, node, *args): |
paul@339 | 393 | raise InspectError("Node class %r is not supported." % node.__class__) |
paul@3 | 394 | |
paul@0 | 395 | def NOP(self, node): |
paul@21 | 396 | for n in node.getChildNodes(): |
paul@21 | 397 | self.dispatch(n) |
paul@19 | 398 | return None |
paul@0 | 399 | |
paul@299 | 400 | def NOP_ABANDON(self, node): |
paul@302 | 401 | self.NOP(node) |
paul@299 | 402 | self.abandon_branch() |
paul@299 | 403 | |
paul@82 | 404 | def OP(self, node): |
paul@82 | 405 | for n in node.getChildNodes(): |
paul@82 | 406 | self.dispatch(n) |
paul@82 | 407 | return Instance() |
paul@1 | 408 | |
paul@314 | 409 | # Generic support for classes of operations. |
paul@314 | 410 | |
paul@172 | 411 | def _visitUnary(self, node): |
paul@172 | 412 | |
paul@172 | 413 | "Accounting method for the unary operator 'node'." |
paul@172 | 414 | |
paul@172 | 415 | method = unary_methods[node.__class__.__name__] |
paul@323 | 416 | self.use_name(method, node) |
paul@172 | 417 | return self.OP(node) |
paul@172 | 418 | |
paul@172 | 419 | def _visitBinary(self, node): |
paul@172 | 420 | |
paul@172 | 421 | "Accounting method for the binary operator 'node'." |
paul@172 | 422 | |
paul@172 | 423 | left_method, right_method = binary_methods[node.__class__.__name__] |
paul@323 | 424 | self.use_name(left_method, node) |
paul@323 | 425 | self.use_name(right_method, node) |
paul@172 | 426 | return self.OP(node) |
paul@172 | 427 | |
paul@85 | 428 | def _visitFunction(self, node, name): |
paul@85 | 429 | |
paul@85 | 430 | """ |
paul@85 | 431 | Return a function object for the function defined by 'node' with the |
paul@85 | 432 | given 'name'. If a lambda expression is being visited, 'name' should be |
paul@85 | 433 | None. |
paul@85 | 434 | """ |
paul@85 | 435 | |
paul@233 | 436 | # Define the function object. |
paul@233 | 437 | |
paul@85 | 438 | function = Function( |
paul@85 | 439 | name, |
paul@272 | 440 | self.get_namespace(), |
paul@85 | 441 | node.argnames, |
paul@85 | 442 | node.defaults, |
paul@85 | 443 | (node.flags & 4 != 0), |
paul@85 | 444 | (node.flags & 8 != 0), |
paul@331 | 445 | self.in_loop or self.in_function, |
paul@85 | 446 | self, |
paul@85 | 447 | node |
paul@85 | 448 | ) |
paul@85 | 449 | |
paul@233 | 450 | self.add_object(function, any_scope=1) |
paul@233 | 451 | |
paul@85 | 452 | # Make a back reference from the node for code generation. |
paul@85 | 453 | |
paul@85 | 454 | node.unit = function |
paul@85 | 455 | |
paul@85 | 456 | # Process the defaults. |
paul@85 | 457 | |
paul@85 | 458 | for n in node.defaults: |
paul@85 | 459 | self.expr = self.dispatch(n) |
paul@192 | 460 | function.store_default(self.expr) |
paul@85 | 461 | |
paul@235 | 462 | self.functions.append((node, self.namespaces + [function])) |
paul@85 | 463 | |
paul@330 | 464 | # Store the function. |
paul@330 | 465 | |
paul@85 | 466 | if name is not None: |
paul@85 | 467 | self.store(name, function) |
paul@85 | 468 | else: |
paul@85 | 469 | self.store_lambda(function) |
paul@167 | 470 | |
paul@330 | 471 | # Test the defaults and assess whether an dynamic object will result. |
paul@330 | 472 | |
paul@331 | 473 | function.make_dynamic() |
paul@331 | 474 | return function |
paul@85 | 475 | |
paul@235 | 476 | def _visitFunctionBody(self, node, namespaces): |
paul@235 | 477 | |
paul@235 | 478 | "Enter the function." |
paul@235 | 479 | |
paul@235 | 480 | # Current namespace is the function. |
paul@235 | 481 | # Previous namespace is the class. |
paul@235 | 482 | |
paul@330 | 483 | if self.in_class(namespaces): |
paul@235 | 484 | if namespaces[-1].name == "__init__": |
paul@235 | 485 | self.in_init = 1 |
paul@235 | 486 | self.in_method = 1 |
paul@235 | 487 | |
paul@331 | 488 | in_function = self.in_function |
paul@331 | 489 | in_loop = self.in_loop |
paul@331 | 490 | self.in_function = 1 |
paul@331 | 491 | self.in_loop = 0 |
paul@331 | 492 | |
paul@235 | 493 | self.namespaces = namespaces |
paul@235 | 494 | self.dispatch(node.code) |
paul@235 | 495 | |
paul@331 | 496 | self.in_loop = in_loop |
paul@331 | 497 | self.in_function = in_function |
paul@235 | 498 | self.in_init = 0 |
paul@235 | 499 | self.in_method = 0 |
paul@235 | 500 | |
paul@172 | 501 | # Specific handler methods. |
paul@172 | 502 | |
paul@172 | 503 | visitAdd = _visitBinary |
paul@82 | 504 | |
paul@82 | 505 | visitAnd = OP |
paul@0 | 506 | |
paul@4 | 507 | visitAssert = NOP |
paul@4 | 508 | |
paul@0 | 509 | def visitAssign(self, node): |
paul@0 | 510 | self.expr = self.dispatch(node.expr) |
paul@0 | 511 | for n in node.nodes: |
paul@0 | 512 | self.dispatch(n) |
paul@0 | 513 | return None |
paul@0 | 514 | |
paul@0 | 515 | def visitAssAttr(self, node): |
paul@0 | 516 | expr = self.dispatch(node.expr) |
paul@272 | 517 | |
paul@272 | 518 | # Record the attribute on the presumed target. |
paul@272 | 519 | |
paul@94 | 520 | if isinstance(expr, Attr): |
paul@94 | 521 | if expr.name == "self": |
paul@94 | 522 | if not self.store_class_attr(node.attrname): |
paul@94 | 523 | self.store_instance_attr(node.attrname) |
paul@192 | 524 | elif isinstance(expr.get_value(), Module): |
paul@192 | 525 | self.store_module_attr(node.attrname, expr.get_value()) |
paul@192 | 526 | print "Warning: attribute %r of module %r set outside the module." % (node.attrname, expr.get_value().name) |
paul@272 | 527 | |
paul@285 | 528 | # Note usage of the attribute where a local is involved. |
paul@272 | 529 | |
paul@272 | 530 | if expr.parent is self.get_namespace(): |
paul@309 | 531 | node._attrusers = self.use_attribute(expr.name, node.attrname) |
paul@309 | 532 | node._username = expr.name |
paul@272 | 533 | |
paul@0 | 534 | return None |
paul@0 | 535 | |
paul@0 | 536 | def visitAssList(self, node): |
paul@204 | 537 | |
paul@204 | 538 | # Declare names which will be used by generated code. |
paul@204 | 539 | |
paul@323 | 540 | self.use_name("__getitem__", node) |
paul@204 | 541 | |
paul@204 | 542 | # Process the assignment. |
paul@204 | 543 | |
paul@139 | 544 | for i, n in enumerate(node.nodes): |
paul@0 | 545 | self.dispatch(n) |
paul@168 | 546 | self.importer.make_constant(i) # for __getitem__(i) at run-time |
paul@0 | 547 | return None |
paul@0 | 548 | |
paul@0 | 549 | def visitAssName(self, node): |
paul@289 | 550 | if hasattr(node, "flags") and node.flags == "OP_DELETE": |
paul@298 | 551 | print "Warning: deletion of attribute %r in %r is not supported." % (node.name, self.full_name()) |
paul@339 | 552 | #raise InspectError("Deletion of attribute %r is not supported." % node.name) |
paul@274 | 553 | |
paul@120 | 554 | self.store(node.name, self.expr) |
paul@278 | 555 | self.define_attribute_user(node) |
paul@285 | 556 | |
paul@285 | 557 | # Ensure the presence of the given name in this namespace. |
paul@285 | 558 | |
paul@285 | 559 | self.use_specific_attribute(None, node.name) |
paul@0 | 560 | return None |
paul@0 | 561 | |
paul@0 | 562 | visitAssTuple = visitAssList |
paul@0 | 563 | |
paul@172 | 564 | def visitAugAssign(self, node): |
paul@172 | 565 | |
paul@172 | 566 | # Accounting. |
paul@172 | 567 | |
paul@172 | 568 | aug_method, (left_method, right_method) = augassign_methods[node.op] |
paul@323 | 569 | self.use_name(aug_method, node) |
paul@323 | 570 | self.use_name(left_method, node) |
paul@323 | 571 | self.use_name(right_method, node) |
paul@244 | 572 | |
paul@244 | 573 | # Process the assignment. |
paul@244 | 574 | |
paul@244 | 575 | self.expr = self.dispatch(node.expr) |
paul@244 | 576 | |
paul@244 | 577 | # NOTE: Similar to micropython.ast handler code. |
paul@244 | 578 | # NOTE: Slices and subscripts not supported. |
paul@244 | 579 | |
paul@244 | 580 | if isinstance(node.node, compiler.ast.Name): |
paul@244 | 581 | self.visitAssName(node.node) |
paul@244 | 582 | elif isinstance(node.node, compiler.ast.Getattr): |
paul@244 | 583 | self.visitAssAttr(node.node) |
paul@244 | 584 | else: |
paul@339 | 585 | raise InspectError("AugAssign(Slice or Subscript)") |
paul@244 | 586 | |
paul@244 | 587 | return None |
paul@2 | 588 | |
paul@82 | 589 | visitBackquote = OP |
paul@4 | 590 | |
paul@172 | 591 | visitBitand = _visitBinary |
paul@2 | 592 | |
paul@172 | 593 | visitBitor = _visitBinary |
paul@2 | 594 | |
paul@172 | 595 | visitBitxor = _visitBinary |
paul@4 | 596 | |
paul@299 | 597 | visitBreak = NOP_ABANDON |
paul@4 | 598 | |
paul@82 | 599 | visitCallFunc = OP |
paul@0 | 600 | |
paul@0 | 601 | def visitClass(self, node): |
paul@91 | 602 | |
paul@91 | 603 | """ |
paul@91 | 604 | Register the class at the given 'node' subject to the restrictions |
paul@91 | 605 | mentioned in the module docstring. |
paul@91 | 606 | """ |
paul@91 | 607 | |
paul@12 | 608 | if self.namespaces: |
paul@41 | 609 | print "Class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) |
paul@82 | 610 | return None |
paul@0 | 611 | else: |
paul@331 | 612 | if self.in_loop: |
paul@331 | 613 | print "Warning: class %r in %r defined in a loop." % (node.name, self.full_name()) |
paul@331 | 614 | |
paul@272 | 615 | cls = Class(node.name, self.get_namespace(), self, node) |
paul@37 | 616 | |
paul@37 | 617 | # Visit the base class expressions, attempting to find concrete |
paul@37 | 618 | # definitions of classes. |
paul@37 | 619 | |
paul@0 | 620 | for base in node.bases: |
paul@36 | 621 | expr = self.dispatch(base) |
paul@36 | 622 | if isinstance(expr, Attr): |
paul@36 | 623 | if expr.assignments != 1: |
paul@339 | 624 | raise InspectError("Base class %r for %r is not constant." % (base, cls.full_name())) |
paul@36 | 625 | else: |
paul@192 | 626 | cls.add_base(expr.get_value()) |
paul@36 | 627 | else: # if expr is None: |
paul@339 | 628 | raise InspectError("Base class %r for %r is not found: it may be hidden in some way." % (base, cls.full_name())) |
paul@0 | 629 | |
paul@59 | 630 | # NOTE: Potentially dubious measure to permit __init__ availability. |
paul@59 | 631 | # If no bases exist, adopt the 'object' class. |
paul@59 | 632 | |
paul@61 | 633 | if not node.bases and not (self.name == "__builtins__" and node.name == "object") : |
paul@59 | 634 | expr = self.dispatch(compiler.ast.Name("object")) |
paul@192 | 635 | cls.add_base(expr.get_value()) |
paul@59 | 636 | |
paul@21 | 637 | # Make a back reference from the node for code generation. |
paul@21 | 638 | |
paul@39 | 639 | node.unit = cls |
paul@21 | 640 | |
paul@0 | 641 | # Make an entry for the class. |
paul@0 | 642 | |
paul@0 | 643 | self.store(node.name, cls) |
paul@167 | 644 | self.add_object(cls) |
paul@0 | 645 | |
paul@59 | 646 | # Process the class body. |
paul@59 | 647 | |
paul@12 | 648 | self.namespaces.append(cls) |
paul@0 | 649 | self.dispatch(node.code) |
paul@344 | 650 | cls.finalise_attribute_usage() |
paul@12 | 651 | self.namespaces.pop() |
paul@0 | 652 | |
paul@82 | 653 | return cls |
paul@0 | 654 | |
paul@172 | 655 | def visitCompare(self, node): |
paul@172 | 656 | |
paul@172 | 657 | # Accounting. |
paul@172 | 658 | # NOTE: Replicates some code in micropython.ast.visitCompare. |
paul@172 | 659 | |
paul@323 | 660 | this_node = node |
paul@323 | 661 | |
paul@172 | 662 | for op in node.ops: |
paul@172 | 663 | op_name, next_node = op |
paul@323 | 664 | |
paul@323 | 665 | # Get the applicable methods. |
paul@323 | 666 | |
paul@172 | 667 | methods = comparison_methods[op_name] |
paul@323 | 668 | |
paul@323 | 669 | # Define name/attribute usage. |
paul@323 | 670 | |
paul@172 | 671 | if methods is not None: |
paul@323 | 672 | self.use_name(methods[0], this_node) |
paul@323 | 673 | self.use_name(methods[1], next_node) |
paul@172 | 674 | elif op_name.endswith("in"): |
paul@323 | 675 | self.use_name("__contains__", next_node) |
paul@323 | 676 | |
paul@323 | 677 | this_node = next_node |
paul@172 | 678 | |
paul@172 | 679 | return self.OP(node) |
paul@4 | 680 | |
paul@21 | 681 | def visitConst(self, node): |
paul@177 | 682 | |
paul@177 | 683 | # Register the constant, if necessary, returning the resulting object. |
paul@177 | 684 | |
paul@323 | 685 | self.use_name(self.importer.get_constant_type_name(node.value), node) |
paul@168 | 686 | return self.importer.make_constant(node.value) |
paul@0 | 687 | |
paul@299 | 688 | visitContinue = NOP_ABANDON |
paul@4 | 689 | |
paul@4 | 690 | visitDecorators = NOP |
paul@4 | 691 | |
paul@82 | 692 | visitDict = OP |
paul@0 | 693 | |
paul@0 | 694 | visitDiscard = NOP |
paul@0 | 695 | |
paul@172 | 696 | visitDiv = _visitBinary |
paul@4 | 697 | |
paul@4 | 698 | visitEllipsis = NOP |
paul@4 | 699 | |
paul@4 | 700 | visitExec = NOP |
paul@4 | 701 | |
paul@82 | 702 | visitExpression = OP |
paul@4 | 703 | |
paul@172 | 704 | visitFloorDiv = _visitBinary |
paul@4 | 705 | |
paul@34 | 706 | def visitFor(self, node): |
paul@272 | 707 | self.new_branchpoint() |
paul@204 | 708 | |
paul@204 | 709 | # Declare names which will be used by generated code. |
paul@204 | 710 | |
paul@323 | 711 | self.use_name("__iter__", node.list) |
paul@250 | 712 | self.use_name("next") |
paul@345 | 713 | self.use_name("StopIteration") |
paul@204 | 714 | |
paul@331 | 715 | in_loop = self.in_loop |
paul@289 | 716 | self.in_loop = 1 |
paul@341 | 717 | self.dispatch(node.list) |
paul@272 | 718 | self.dispatch(node.assign) |
paul@272 | 719 | |
paul@204 | 720 | # Enter the loop. |
paul@275 | 721 | # Propagate attribute usage to branches. |
paul@204 | 722 | |
paul@272 | 723 | self.new_branch() |
paul@272 | 724 | self.dispatch(node.body) |
paul@272 | 725 | self.shelve_branch() |
paul@331 | 726 | self.in_loop = in_loop |
paul@272 | 727 | |
paul@275 | 728 | # Maintain a branch for the else clause or the current retained usage |
paul@275 | 729 | # where execution avoids the conditional clauses. |
paul@275 | 730 | |
paul@275 | 731 | self.new_branch() |
paul@272 | 732 | if node.else_ is not None: |
paul@272 | 733 | self.dispatch(node.else_) |
paul@275 | 734 | self.shelve_branch() |
paul@272 | 735 | |
paul@272 | 736 | self.merge_branches() |
paul@82 | 737 | return None |
paul@0 | 738 | |
paul@0 | 739 | def visitFrom(self, node): |
paul@0 | 740 | module = self.importer.load(node.modname, 1) |
paul@0 | 741 | |
paul@35 | 742 | #if module is None: |
paul@35 | 743 | # print "Warning:", node.modname, "not imported." |
paul@0 | 744 | |
paul@0 | 745 | for name, alias in node.names: |
paul@0 | 746 | if name != "*": |
paul@285 | 747 | if module is not None and module.has_key(name): |
paul@24 | 748 | attr = module[name] |
paul@192 | 749 | self.store(alias or name, attr) |
paul@192 | 750 | if isinstance(attr.get_value(), Module) and not attr.get_value().loaded: |
paul@192 | 751 | self.importer.load(attr.get_value().name) |
paul@24 | 752 | |
paul@24 | 753 | # Support the import of names from missing modules. |
paul@24 | 754 | |
paul@3 | 755 | else: |
paul@24 | 756 | self.store(alias or name, UnresolvedName(name, node.modname, self)) |
paul@3 | 757 | else: |
paul@3 | 758 | if module is not None: |
paul@285 | 759 | for n in module.keys(): |
paul@24 | 760 | attr = module[n] |
paul@192 | 761 | self.store(n, attr) |
paul@192 | 762 | if isinstance(attr.get_value(), Module) and not attr.get_value().loaded: |
paul@192 | 763 | self.importer.load(attr.get_value().name) |
paul@0 | 764 | |
paul@0 | 765 | return None |
paul@0 | 766 | |
paul@0 | 767 | def visitFunction(self, node): |
paul@85 | 768 | return self._visitFunction(node, node.name) |
paul@0 | 769 | |
paul@82 | 770 | visitGenExpr = OP |
paul@4 | 771 | |
paul@4 | 772 | visitGenExprFor = NOP |
paul@4 | 773 | |
paul@4 | 774 | visitGenExprIf = NOP |
paul@4 | 775 | |
paul@4 | 776 | visitGenExprInner = NOP |
paul@4 | 777 | |
paul@0 | 778 | def visitGetattr(self, node): |
paul@0 | 779 | expr = self.dispatch(node.expr) |
paul@169 | 780 | attrname = node.attrname |
paul@169 | 781 | |
paul@272 | 782 | # Attempt to identify the nature of the attribute. |
paul@272 | 783 | |
paul@36 | 784 | if isinstance(expr, Attr): |
paul@192 | 785 | value = expr.get_value() |
paul@285 | 786 | |
paul@285 | 787 | # Get the attribute and record its usage. |
paul@285 | 788 | |
paul@87 | 789 | if isinstance(value, (Class, Module)): |
paul@285 | 790 | attr = value.get(attrname) |
paul@285 | 791 | self.use_specific_attribute(value.full_name(), attrname) |
paul@285 | 792 | |
paul@36 | 793 | elif isinstance(value, UnresolvedName): |
paul@169 | 794 | attr = UnresolvedName(attrname, value.full_name(), self) |
paul@285 | 795 | |
paul@87 | 796 | else: |
paul@167 | 797 | attr = None |
paul@272 | 798 | |
paul@285 | 799 | # Note usage of the attribute where a local is involved. |
paul@272 | 800 | |
paul@285 | 801 | if expr.parent is self.get_namespace(): |
paul@309 | 802 | node._attrusers = self.use_attribute(expr.name, attrname) |
paul@309 | 803 | node._username = expr.name |
paul@285 | 804 | else: |
paul@323 | 805 | self.use_name(attrname, node.expr) |
paul@272 | 806 | |
paul@167 | 807 | elif self.builtins is not None: |
paul@169 | 808 | attr = self.builtins.get(attrname) |
paul@285 | 809 | self.use_specific_attribute(self.builtins.full_name(), attrname) |
paul@280 | 810 | |
paul@61 | 811 | else: |
paul@169 | 812 | attr = UnresolvedName(attrname, value.full_name(), self) |
paul@169 | 813 | |
paul@167 | 814 | return attr |
paul@4 | 815 | |
paul@12 | 816 | def visitGlobal(self, node): |
paul@12 | 817 | if self.namespaces: |
paul@12 | 818 | for name in node.names: |
paul@178 | 819 | ns = self.namespaces[-1] |
paul@178 | 820 | if not ns.make_global(name): |
paul@339 | 821 | raise InspectError("Name %r is global and local in %r" % (name, ns.full_name())) |
paul@37 | 822 | |
paul@236 | 823 | # The name is recorded in an earlier process. |
paul@0 | 824 | |
paul@0 | 825 | def visitIf(self, node): |
paul@272 | 826 | self.new_branchpoint() |
paul@272 | 827 | |
paul@275 | 828 | # Propagate attribute usage to branches. |
paul@275 | 829 | |
paul@0 | 830 | for test, body in node.tests: |
paul@202 | 831 | self.dispatch(test) |
paul@272 | 832 | |
paul@272 | 833 | self.new_branch() |
paul@0 | 834 | self.dispatch(body) |
paul@272 | 835 | self.shelve_branch() |
paul@272 | 836 | |
paul@275 | 837 | # Maintain a branch for the else clause or the current retained usage |
paul@275 | 838 | # where execution avoids the conditional clauses. |
paul@275 | 839 | |
paul@275 | 840 | self.new_branch() |
paul@0 | 841 | if node.else_ is not None: |
paul@0 | 842 | self.dispatch(node.else_) |
paul@275 | 843 | self.shelve_branch() |
paul@272 | 844 | |
paul@272 | 845 | self.merge_branches() |
paul@0 | 846 | return None |
paul@0 | 847 | |
paul@12 | 848 | visitIfExp = NOP |
paul@12 | 849 | |
paul@0 | 850 | def visitImport(self, node): |
paul@0 | 851 | for name, alias in node.names: |
paul@2 | 852 | if alias is not None: |
paul@167 | 853 | module = self.importer.load(name, 1) or UnresolvedName(None, name, self) |
paul@167 | 854 | self.store(alias, module) |
paul@2 | 855 | else: |
paul@167 | 856 | module = self.importer.load(name) or UnresolvedName(None, name.split(".")[0], self) |
paul@167 | 857 | self.store(name.split(".")[0], module) |
paul@0 | 858 | |
paul@0 | 859 | return None |
paul@0 | 860 | |
paul@172 | 861 | visitInvert = _visitUnary |
paul@4 | 862 | |
paul@59 | 863 | def visitKeyword(self, node): |
paul@59 | 864 | self.dispatch(node.expr) |
paul@168 | 865 | self.importer.make_constant(node.name) |
paul@71 | 866 | self.keyword_names.add(node.name) |
paul@59 | 867 | return None |
paul@4 | 868 | |
paul@85 | 869 | def visitLambda(self, node): |
paul@252 | 870 | self.use_name(None) # lambda functions have no names but are assumed to be invoked |
paul@85 | 871 | return self._visitFunction(node, None) |
paul@4 | 872 | |
paul@172 | 873 | visitLeftShift = _visitBinary |
paul@1 | 874 | |
paul@346 | 875 | def visitList(self, node): |
paul@347 | 876 | self.use_specific_attribute("__builtins__", "list") |
paul@346 | 877 | self.OP(node) |
paul@0 | 878 | |
paul@341 | 879 | def visitListComp(self, node): |
paul@341 | 880 | for qual in node.quals: |
paul@341 | 881 | self.dispatch(qual) |
paul@341 | 882 | self.dispatch(node.expr) |
paul@341 | 883 | |
paul@341 | 884 | def visitListCompFor(self, node): |
paul@341 | 885 | self.new_branchpoint() |
paul@341 | 886 | |
paul@341 | 887 | # Declare names which will be used by generated code. |
paul@341 | 888 | |
paul@341 | 889 | self.use_name("__iter__", node.list) |
paul@341 | 890 | self.use_name("next") |
paul@4 | 891 | |
paul@341 | 892 | in_loop = self.in_loop |
paul@341 | 893 | self.in_loop = 1 |
paul@341 | 894 | self.dispatch(node.list) |
paul@341 | 895 | self.dispatch(node.assign) |
paul@341 | 896 | |
paul@341 | 897 | # Enter the loop. |
paul@341 | 898 | # Propagate attribute usage to branches. |
paul@341 | 899 | |
paul@341 | 900 | self.new_branch() |
paul@341 | 901 | |
paul@341 | 902 | for if_ in node.ifs: |
paul@341 | 903 | self.dispatch(if_) |
paul@341 | 904 | |
paul@341 | 905 | self.shelve_branch() |
paul@341 | 906 | self.in_loop = in_loop |
paul@341 | 907 | |
paul@341 | 908 | self.merge_branches() |
paul@341 | 909 | return None |
paul@4 | 910 | |
paul@4 | 911 | visitListCompIf = NOP |
paul@4 | 912 | |
paul@172 | 913 | visitMod = _visitBinary |
paul@4 | 914 | |
paul@0 | 915 | def visitModule(self, node): |
paul@143 | 916 | |
paul@143 | 917 | # Make a back reference from the node for code generation. |
paul@143 | 918 | |
paul@143 | 919 | node.unit = self |
paul@0 | 920 | return self.dispatch(node.node) |
paul@0 | 921 | |
paul@172 | 922 | visitMul = _visitBinary |
paul@2 | 923 | |
paul@0 | 924 | def visitName(self, node): |
paul@343 | 925 | return self.get_namespace().get_using_node(node.name, node) |
paul@0 | 926 | |
paul@82 | 927 | visitNot = OP |
paul@0 | 928 | |
paul@82 | 929 | visitOr = OP |
paul@0 | 930 | |
paul@0 | 931 | visitPass = NOP |
paul@0 | 932 | |
paul@172 | 933 | visitPower = _visitBinary |
paul@4 | 934 | |
paul@4 | 935 | visitPrint = NOP |
paul@4 | 936 | |
paul@4 | 937 | visitPrintnl = NOP |
paul@4 | 938 | |
paul@299 | 939 | visitRaise = NOP_ABANDON |
paul@0 | 940 | |
paul@299 | 941 | visitReturn = NOP_ABANDON |
paul@4 | 942 | |
paul@172 | 943 | visitRightShift = _visitBinary |
paul@1 | 944 | |
paul@342 | 945 | def visitSlice(self, node): |
paul@347 | 946 | self.use_specific_attribute("__builtins__", "slice") |
paul@342 | 947 | self.use_name("__getitem__", node) |
paul@342 | 948 | self.OP(node) |
paul@4 | 949 | |
paul@82 | 950 | visitSliceobj = OP |
paul@23 | 951 | |
paul@0 | 952 | def visitStmt(self, node): |
paul@0 | 953 | for n in node.nodes: |
paul@0 | 954 | self.dispatch(n) |
paul@0 | 955 | return None |
paul@0 | 956 | |
paul@172 | 957 | visitSub = _visitBinary |
paul@4 | 958 | |
paul@216 | 959 | def visitSubscript(self, node): |
paul@323 | 960 | self.use_name("__getitem__", node) |
paul@216 | 961 | self.OP(node) |
paul@0 | 962 | |
paul@0 | 963 | def visitTryExcept(self, node): |
paul@0 | 964 | self.dispatch(node.body) |
paul@272 | 965 | |
paul@272 | 966 | self.new_branchpoint() |
paul@272 | 967 | |
paul@0 | 968 | for name, var, n in node.handlers: |
paul@272 | 969 | self.new_branch() |
paul@97 | 970 | |
paul@97 | 971 | # Establish the local for the handler. |
paul@97 | 972 | |
paul@99 | 973 | if var is not None: |
paul@99 | 974 | self.dispatch(var) |
paul@99 | 975 | if n is not None: |
paul@99 | 976 | self.dispatch(n) |
paul@272 | 977 | |
paul@272 | 978 | self.shelve_branch() |
paul@272 | 979 | |
paul@0 | 980 | if node.else_ is not None: |
paul@272 | 981 | self.new_branch() |
paul@0 | 982 | self.dispatch(node.else_) |
paul@272 | 983 | self.shelve_branch() |
paul@272 | 984 | |
paul@272 | 985 | self.merge_branches() |
paul@0 | 986 | return None |
paul@0 | 987 | |
paul@4 | 988 | visitTryFinally = NOP |
paul@4 | 989 | |
paul@82 | 990 | visitTuple = OP |
paul@1 | 991 | |
paul@172 | 992 | visitUnaryAdd = _visitUnary |
paul@4 | 993 | |
paul@172 | 994 | visitUnarySub = _visitUnary |
paul@4 | 995 | |
paul@34 | 996 | def visitWhile(self, node): |
paul@272 | 997 | self.new_branchpoint() |
paul@272 | 998 | |
paul@275 | 999 | # Propagate attribute usage to branches. |
paul@275 | 1000 | |
paul@331 | 1001 | in_loop = self.in_loop |
paul@34 | 1002 | self.in_loop = 1 |
paul@272 | 1003 | self.dispatch(node.test) |
paul@311 | 1004 | self.new_branch(node) |
paul@272 | 1005 | self.dispatch(node.body) |
paul@272 | 1006 | self.shelve_branch() |
paul@331 | 1007 | self.in_loop = in_loop |
paul@272 | 1008 | |
paul@275 | 1009 | # Maintain a branch for the else clause or the current retained usage |
paul@275 | 1010 | # where execution avoids the conditional clauses. |
paul@311 | 1011 | # NOTE: Consider merging here before the else clause. |
paul@275 | 1012 | |
paul@275 | 1013 | self.new_branch() |
paul@272 | 1014 | if node.else_ is not None: |
paul@272 | 1015 | self.dispatch(node.else_) |
paul@275 | 1016 | self.shelve_branch() |
paul@272 | 1017 | |
paul@272 | 1018 | self.merge_branches() |
paul@82 | 1019 | return None |
paul@4 | 1020 | |
paul@4 | 1021 | visitWith = NOP |
paul@4 | 1022 | |
paul@4 | 1023 | visitYield = NOP |
paul@4 | 1024 | |
paul@0 | 1025 | # vim: tabstop=4 expandtab shiftwidth=4 |