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@506 | 6 | Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 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@557 | 65 | assignments to provide constant values if the targets reside in class |
paul@557 | 66 | 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@601 | 75 | from micropython.common import ASTVisitor, operator_functions |
paul@83 | 76 | from micropython.data import * |
paul@555 | 77 | from micropython.errors import * |
paul@0 | 78 | import compiler.ast |
paul@507 | 79 | import sys |
paul@15 | 80 | |
paul@622 | 81 | class NullBranch(compiler.ast.AttributeUser): |
paul@622 | 82 | |
paul@622 | 83 | "A class representing an attribute user for a non-existent branch." |
paul@622 | 84 | |
paul@622 | 85 | pass |
paul@622 | 86 | |
paul@21 | 87 | # Program visitors. |
paul@21 | 88 | |
paul@15 | 89 | class InspectedModule(ASTVisitor, Module): |
paul@15 | 90 | |
paul@20 | 91 | """ |
paul@20 | 92 | An inspected module, providing core details via the Module superclass, but |
paul@20 | 93 | capable of being used as an AST visitor. |
paul@575 | 94 | |
paul@575 | 95 | A module can be inspected through the invocation of the following methods in |
paul@575 | 96 | order: |
paul@575 | 97 | |
paul@575 | 98 | 1. parse |
paul@581 | 99 | 2. process |
paul@581 | 100 | 3. vacuum |
paul@581 | 101 | 4. finalise |
paul@575 | 102 | |
paul@575 | 103 | A module importer can be expected to perform these invocations. |
paul@20 | 104 | """ |
paul@15 | 105 | |
paul@71 | 106 | def __init__(self, name, importer): |
paul@71 | 107 | |
paul@71 | 108 | """ |
paul@71 | 109 | Initialise this visitor with a module 'name' and an 'importer' which is |
paul@71 | 110 | used to provide access to other modules when required. |
paul@71 | 111 | """ |
paul@71 | 112 | |
paul@343 | 113 | Module.__init__(self, name, importer) |
paul@15 | 114 | self.visitor = self |
paul@15 | 115 | |
paul@91 | 116 | # Import machinery links. |
paul@91 | 117 | |
paul@343 | 118 | self.optimisations = self.importer.optimisations |
paul@61 | 119 | self.builtins = self.importer.modules.get("__builtins__") |
paul@591 | 120 | self.loaded = False |
paul@591 | 121 | self.completed = False |
paul@15 | 122 | |
paul@1 | 123 | # Current expression state. |
paul@1 | 124 | |
paul@1 | 125 | self.expr = None |
paul@591 | 126 | self.in_assignment = False # For slice and subscript handling. |
paul@1 | 127 | |
paul@1 | 128 | # Namespace state. |
paul@1 | 129 | |
paul@591 | 130 | self.in_method = False # Find instance attributes in all methods. |
paul@591 | 131 | self.in_function = False # Note function presence, affecting definitions. |
paul@591 | 132 | self.in_loop = False # Note loop "membership", affecting assignments. |
paul@12 | 133 | self.namespaces = [] |
paul@235 | 134 | self.functions = [] |
paul@0 | 135 | |
paul@0 | 136 | def parse(self, filename): |
paul@9 | 137 | |
paul@9 | 138 | "Parse the file having the given 'filename'." |
paul@9 | 139 | |
paul@581 | 140 | self.astnode = module = compiler.parseFile(filename) |
paul@581 | 141 | |
paul@581 | 142 | # Detect and record imports and globals declared in the module. |
paul@581 | 143 | |
paul@581 | 144 | self.process_structure(module) |
paul@0 | 145 | |
paul@581 | 146 | def complete(self): |
paul@581 | 147 | if not self.completed: |
paul@591 | 148 | self.completed = True |
paul@581 | 149 | self.process() |
paul@581 | 150 | if self.importer.verbose: |
paul@581 | 151 | print >>sys.stderr, "Completed import of", self.full_name() |
paul@581 | 152 | |
paul@581 | 153 | def process(self): |
paul@581 | 154 | return self.process_module(self.astnode) |
paul@581 | 155 | |
paul@581 | 156 | def process_module(self, module): |
paul@9 | 157 | |
paul@546 | 158 | """ |
paul@581 | 159 | Process the given 'module', visiting module-level code and function |
paul@581 | 160 | code. |
paul@546 | 161 | """ |
paul@9 | 162 | |
paul@439 | 163 | # Add __name__ to the namespace. |
paul@260 | 164 | |
paul@439 | 165 | self.store("__name__", self._visitConst(self.full_name())) |
paul@260 | 166 | |
paul@575 | 167 | # Visit module-level code, also recording global names. |
paul@236 | 168 | |
paul@1 | 169 | processed = self.dispatch(module) |
paul@235 | 170 | |
paul@344 | 171 | self.finalise_attribute_usage() |
paul@284 | 172 | |
paul@578 | 173 | # Visit functions. |
paul@578 | 174 | |
paul@578 | 175 | self.process_functions() |
paul@578 | 176 | |
paul@236 | 177 | # Add references to other modules declared using the __all__ global. |
paul@236 | 178 | |
paul@13 | 179 | if self.has_key("__all__"): |
paul@12 | 180 | all = self["__all__"] |
paul@1 | 181 | if isinstance(all, compiler.ast.List): |
paul@1 | 182 | for n in all.nodes: |
paul@167 | 183 | self.store(n.value, self.importer.add_module(self.name + "." + n.value)) |
paul@235 | 184 | |
paul@1 | 185 | return processed |
paul@0 | 186 | |
paul@546 | 187 | def process_functions(self): |
paul@546 | 188 | |
paul@546 | 189 | """ |
paul@546 | 190 | Process all function bodies. Deferred imports may occur during this |
paul@546 | 191 | process. |
paul@546 | 192 | """ |
paul@546 | 193 | |
paul@547 | 194 | # Then, visit each function, recording other names. This happens to |
paul@547 | 195 | # work for lambda definitions inside functions since they are added to |
paul@547 | 196 | # the end of self.functions and are thus visited as the iteration |
paul@547 | 197 | # reaches the end of the original list. |
paul@546 | 198 | |
paul@546 | 199 | for node, namespaces in self.functions: |
paul@546 | 200 | self._visitFunctionBody(node, namespaces) |
paul@546 | 201 | namespaces[-1].finalise_attribute_usage() |
paul@546 | 202 | |
paul@581 | 203 | def process_structure(self, node): |
paul@236 | 204 | |
paul@236 | 205 | """ |
paul@236 | 206 | Within the given 'node', process global declarations, adjusting the |
paul@581 | 207 | module namespace, and import statements, building a module dependency |
paul@581 | 208 | hierarchy. |
paul@236 | 209 | """ |
paul@236 | 210 | |
paul@236 | 211 | for n in node.getChildNodes(): |
paul@581 | 212 | |
paul@581 | 213 | # Module global detection. |
paul@581 | 214 | |
paul@236 | 215 | if isinstance(n, compiler.ast.Global): |
paul@236 | 216 | for name in n.names: |
paul@575 | 217 | |
paul@575 | 218 | # Each name may potentially be assigned many times. |
paul@578 | 219 | # We don't try and find out the specifics at this point and |
paul@578 | 220 | # just indicate that the name cannot be relied upon for |
paul@578 | 221 | # various observations. |
paul@575 | 222 | |
paul@581 | 223 | self.modify_name(name) |
paul@581 | 224 | |
paul@581 | 225 | # Module import declarations. |
paul@581 | 226 | |
paul@581 | 227 | elif isinstance(n, compiler.ast.From): |
paul@581 | 228 | |
paul@581 | 229 | # Load the mentioned module. |
paul@581 | 230 | |
paul@581 | 231 | self.record_import(n.modname, n) |
paul@581 | 232 | |
paul@581 | 233 | # Speculatively load modules for names beneath the module. |
paul@581 | 234 | |
paul@581 | 235 | for name, alias in n.names: |
paul@581 | 236 | modname = n.modname + "." + name |
paul@581 | 237 | self.record_import(modname, n) |
paul@581 | 238 | |
paul@581 | 239 | elif isinstance(n, compiler.ast.Import): |
paul@581 | 240 | |
paul@581 | 241 | # Load the mentioned module. |
paul@581 | 242 | |
paul@581 | 243 | for name, alias in n.names: |
paul@581 | 244 | self.record_import(name, n) |
paul@581 | 245 | |
paul@581 | 246 | # Nodes using operator module functions. |
paul@581 | 247 | |
paul@581 | 248 | elif operator_functions.has_key(n.__class__.__name__) or \ |
paul@581 | 249 | isinstance(n, (compiler.ast.AugAssign, compiler.ast.Compare)): |
paul@581 | 250 | |
paul@581 | 251 | n._module = self.importer.load("operator") |
paul@576 | 252 | |
paul@236 | 253 | else: |
paul@581 | 254 | self.process_structure(n) |
paul@581 | 255 | |
paul@581 | 256 | def get_module_paths(self, name): |
paul@581 | 257 | |
paul@581 | 258 | """ |
paul@581 | 259 | Return the paths of modules leading to the module having the given |
paul@581 | 260 | 'name'. |
paul@581 | 261 | """ |
paul@581 | 262 | |
paul@581 | 263 | names = [] |
paul@581 | 264 | parts = [] |
paul@581 | 265 | for part in name.split("."): |
paul@581 | 266 | parts.append(part) |
paul@581 | 267 | names.append(".".join(parts)) |
paul@581 | 268 | return names |
paul@581 | 269 | |
paul@581 | 270 | def record_import(self, name, node): |
paul@581 | 271 | |
paul@581 | 272 | """ |
paul@581 | 273 | Record an import of a module with the given 'name' occurring at the |
paul@581 | 274 | given 'node'. |
paul@581 | 275 | """ |
paul@581 | 276 | |
paul@581 | 277 | module = self.importer.load(name, 1, importer=node) |
paul@581 | 278 | if module and not module.loaded: |
paul@581 | 279 | self.importer.circular_imports.add(module) |
paul@581 | 280 | |
paul@581 | 281 | def complete_import(self, name, return_leaf): |
paul@581 | 282 | |
paul@581 | 283 | """ |
paul@581 | 284 | Complete the import of the module with the given 'name', returning the |
paul@581 | 285 | module itself if 'return_leaf' is a true value, or returning the root of |
paul@581 | 286 | the module hierarchy if 'return_leaf' is a false value. |
paul@581 | 287 | """ |
paul@581 | 288 | |
paul@581 | 289 | top = module = None |
paul@581 | 290 | |
paul@581 | 291 | for modname in self.get_module_paths(name): |
paul@581 | 292 | |
paul@581 | 293 | # Attempt to get the module, returning None for non-existent |
paul@581 | 294 | # modules. |
paul@581 | 295 | |
paul@581 | 296 | try: |
paul@581 | 297 | module = self.importer.get_module(modname) |
paul@581 | 298 | except KeyError: |
paul@581 | 299 | return None |
paul@581 | 300 | |
paul@581 | 301 | if module: |
paul@581 | 302 | module.complete() |
paul@581 | 303 | |
paul@581 | 304 | if top is None: |
paul@581 | 305 | top = module |
paul@581 | 306 | |
paul@581 | 307 | if return_leaf: |
paul@581 | 308 | return module |
paul@581 | 309 | else: |
paul@581 | 310 | return top |
paul@236 | 311 | |
paul@3 | 312 | def vacuum(self): |
paul@9 | 313 | |
paul@171 | 314 | """ |
paul@171 | 315 | Vacuum the module namespace, removing unreferenced objects and unused |
paul@171 | 316 | names. |
paul@171 | 317 | """ |
paul@9 | 318 | |
paul@241 | 319 | if self.should_optimise_unused_objects(): |
paul@252 | 320 | self.vacuum_object(self) |
paul@0 | 321 | |
paul@167 | 322 | all_objects = list(self.all_objects) |
paul@167 | 323 | |
paul@167 | 324 | for obj in all_objects: |
paul@351 | 325 | self.vacuum_object(obj) |
paul@171 | 326 | |
paul@252 | 327 | def vacuum_object(self, obj, delete_all=0): |
paul@241 | 328 | |
paul@252 | 329 | "Vacuum the given object 'obj'." |
paul@171 | 330 | |
paul@468 | 331 | # Get all constant objects in apparent use. |
paul@468 | 332 | |
paul@468 | 333 | if delete_all: |
paul@468 | 334 | obj_objects = set() |
paul@468 | 335 | else: |
paul@468 | 336 | obj_objects = [] |
paul@468 | 337 | for name, attr in obj.items_for_vacuum(): |
paul@468 | 338 | |
paul@468 | 339 | # Get constant objects for attributes in use. |
paul@468 | 340 | |
paul@468 | 341 | if self.importer.uses_attribute(obj.full_name(), name) and \ |
paul@468 | 342 | attr is not None and attr.is_constant(): |
paul@468 | 343 | |
paul@468 | 344 | value = attr.get_value() |
paul@468 | 345 | obj_objects.append(value) |
paul@468 | 346 | |
paul@468 | 347 | # Now vacuum unused attributes and objects not in use. |
paul@468 | 348 | |
paul@351 | 349 | for name, attr in obj.items_for_vacuum(): |
paul@270 | 350 | |
paul@270 | 351 | # Only consider deleting entire unused objects or things accessible |
paul@270 | 352 | # via names which are never used. |
paul@270 | 353 | |
paul@344 | 354 | if delete_all or not self.importer.uses_attribute(obj.full_name(), name): |
paul@351 | 355 | obj.vacuum_item(name) |
paul@270 | 356 | |
paul@270 | 357 | # Delete any unambiguous attribute value. Such values can only |
paul@270 | 358 | # have been defined within the object and therefore are not |
paul@270 | 359 | # redefined by other code regions. |
paul@270 | 360 | |
paul@468 | 361 | if attr is not None and attr.is_constant(): |
paul@252 | 362 | value = attr.get_value() |
paul@171 | 363 | |
paul@394 | 364 | # The value must have this object as a parent. |
paul@468 | 365 | # However, it must not be shared by several names. |
paul@394 | 366 | |
paul@468 | 367 | if value is not obj and value.parent is obj and \ |
paul@468 | 368 | value in self.all_objects and value not in obj_objects: |
paul@468 | 369 | |
paul@252 | 370 | self.all_objects.remove(value) |
paul@171 | 371 | |
paul@351 | 372 | # Delete class contents and lambdas from functions. |
paul@241 | 373 | |
paul@351 | 374 | self.vacuum_object(value, 1) |
paul@171 | 375 | |
paul@287 | 376 | def unfinalise(self): |
paul@287 | 377 | |
paul@287 | 378 | "Reset finalised information for the module." |
paul@287 | 379 | |
paul@287 | 380 | for obj in self.all_objects: |
paul@287 | 381 | obj.unfinalise_attributes() |
paul@287 | 382 | |
paul@437 | 383 | def finalise(self, objtable): |
paul@171 | 384 | |
paul@171 | 385 | "Finalise the module." |
paul@171 | 386 | |
paul@171 | 387 | for obj in self.all_objects: |
paul@437 | 388 | obj.finalise(objtable) |
paul@171 | 389 | |
paul@478 | 390 | self.finalise_users(objtable) |
paul@478 | 391 | |
paul@167 | 392 | def add_object(self, obj, any_scope=0): |
paul@167 | 393 | |
paul@167 | 394 | """ |
paul@167 | 395 | Record 'obj' if non-local or if the optional 'any_scope' is set to a |
paul@167 | 396 | true value. |
paul@167 | 397 | """ |
paul@167 | 398 | |
paul@167 | 399 | if any_scope or not (self.namespaces and isinstance(self.namespaces[-1], Function)): |
paul@167 | 400 | self.all_objects.add(obj) |
paul@167 | 401 | |
paul@167 | 402 | # Optimisation tests. |
paul@167 | 403 | |
paul@167 | 404 | def should_optimise_unused_objects(self): |
paul@167 | 405 | return "unused_objects" in self.optimisations |
paul@167 | 406 | |
paul@3 | 407 | # Namespace methods. |
paul@0 | 408 | |
paul@330 | 409 | def in_class(self, namespaces=None): |
paul@330 | 410 | namespaces = namespaces or self.namespaces |
paul@330 | 411 | return len(namespaces) > 1 and isinstance(namespaces[-2], Class) |
paul@330 | 412 | |
paul@0 | 413 | def store(self, name, obj): |
paul@12 | 414 | |
paul@12 | 415 | "Record attribute or local 'name', storing 'obj'." |
paul@12 | 416 | |
paul@339 | 417 | # Store in the module. |
paul@339 | 418 | |
paul@12 | 419 | if not self.namespaces: |
paul@342 | 420 | if self.in_loop and self.used_in_scope(name, "builtins"): |
paul@339 | 421 | raise InspectError("Name %r already used as a built-in." % name) |
paul@339 | 422 | else: |
paul@339 | 423 | self.set(name, obj, not self.in_loop) |
paul@339 | 424 | |
paul@339 | 425 | # Or store locally. |
paul@339 | 426 | |
paul@12 | 427 | else: |
paul@341 | 428 | locals = self.namespaces[-1] |
paul@341 | 429 | |
paul@342 | 430 | if self.in_loop and locals.used_in_scope(name, "global") and not name in locals.globals: |
paul@341 | 431 | raise InspectError("Name %r already used as global." % name) |
paul@342 | 432 | elif self.in_loop and locals.used_in_scope(name, "builtins"): |
paul@341 | 433 | raise InspectError("Name %r already used as a built-in." % name) |
paul@341 | 434 | else: |
paul@341 | 435 | locals.set(name, obj, not self.in_loop) |
paul@12 | 436 | |
paul@85 | 437 | def store_lambda(self, obj): |
paul@91 | 438 | |
paul@91 | 439 | "Store a lambda function 'obj'." |
paul@91 | 440 | |
paul@167 | 441 | self.add_object(obj) |
paul@351 | 442 | self.get_namespace().add_lambda(obj) |
paul@85 | 443 | |
paul@94 | 444 | def store_module_attr(self, name, module): |
paul@94 | 445 | |
paul@94 | 446 | """ |
paul@94 | 447 | Record module attribute 'name' in the given 'module' using the current |
paul@94 | 448 | expression. |
paul@94 | 449 | """ |
paul@94 | 450 | |
paul@192 | 451 | module.set(name, self.expr, 0) |
paul@405 | 452 | self.use_specific_attribute(module.full_name(), name) |
paul@94 | 453 | |
paul@404 | 454 | def store_class_attr(self, name, cls): |
paul@91 | 455 | |
paul@94 | 456 | """ |
paul@404 | 457 | Record class attribute 'name' in the given class 'cls' using the current |
paul@94 | 458 | expression. |
paul@94 | 459 | """ |
paul@91 | 460 | |
paul@404 | 461 | cls.set(name, self.expr, 0) |
paul@405 | 462 | self.use_specific_attribute(cls.full_name(), name) |
paul@91 | 463 | |
paul@527 | 464 | def store_instance_attr(self, name, tentative=False): |
paul@12 | 465 | |
paul@527 | 466 | """ |
paul@527 | 467 | Record instance attribute 'name' in the current class. If 'tentative' is |
paul@527 | 468 | set to a true value, the instance attribute will be discarded if a class |
paul@527 | 469 | attribute is observed. |
paul@527 | 470 | """ |
paul@12 | 471 | |
paul@91 | 472 | if self.in_method: |
paul@15 | 473 | |
paul@12 | 474 | # Current namespace is the function. |
paul@12 | 475 | # Previous namespace is the class. |
paul@15 | 476 | |
paul@405 | 477 | cls = self.namespaces[-2] |
paul@527 | 478 | cls.add_instance_attribute(name, tentative) |
paul@406 | 479 | |
paul@406 | 480 | # NOTE: The instance attribute, although defined in a specific |
paul@406 | 481 | # NOTE: class, obviously appears in all descendant classes. |
paul@406 | 482 | |
paul@405 | 483 | self.use_specific_attribute(cls.full_name(), name) |
paul@0 | 484 | |
paul@272 | 485 | def get_namespace(self): |
paul@71 | 486 | |
paul@71 | 487 | "Return the parent (or most recent) namespace currently exposed." |
paul@71 | 488 | |
paul@12 | 489 | return (self.namespaces[-1:] or [self])[0] |
paul@7 | 490 | |
paul@623 | 491 | get_unit = get_namespace # compatibility method for error handling |
paul@623 | 492 | |
paul@557 | 493 | def use_name(self, name, node=None, value=None, ns=None): |
paul@323 | 494 | |
paul@323 | 495 | """ |
paul@323 | 496 | Use the given 'name' within the current namespace/unit, either in |
paul@323 | 497 | conjunction with a particular object (if 'node' is specified and not |
paul@323 | 498 | None) or unconditionally. |
paul@323 | 499 | """ |
paul@250 | 500 | |
paul@557 | 501 | unit = self.get_namespace() |
paul@557 | 502 | |
paul@557 | 503 | # Handle attribute usage situations within the current unit. |
paul@557 | 504 | |
paul@557 | 505 | if node is not None and isinstance(node, compiler.ast.Name) and ns is unit: |
paul@404 | 506 | self.use_attribute(node.name, name, value) |
paul@250 | 507 | |
paul@323 | 508 | # For general name usage, declare usage of the given name from this |
paul@323 | 509 | # particular unit. |
paul@323 | 510 | |
paul@323 | 511 | else: |
paul@404 | 512 | self.importer.use_name(name, unit.full_name(), value) |
paul@250 | 513 | |
paul@440 | 514 | def use_constant(self, const): |
paul@440 | 515 | |
paul@440 | 516 | "Use the given 'const' within the current namespace/unit." |
paul@440 | 517 | |
paul@440 | 518 | unit = self.get_namespace() |
paul@440 | 519 | self.importer.use_constant(const, unit.full_name()) |
paul@440 | 520 | |
paul@279 | 521 | # Attribute usage methods. |
paul@279 | 522 | # These are convenience methods which refer to the specific namespace's |
paul@279 | 523 | # implementation of these operations. |
paul@279 | 524 | |
paul@388 | 525 | def new_branchpoint(self, loop_node=None): |
paul@388 | 526 | self.get_namespace()._new_branchpoint(loop_node) |
paul@272 | 527 | |
paul@379 | 528 | def new_branch(self, node): |
paul@379 | 529 | self.get_namespace()._new_branch(node) |
paul@272 | 530 | |
paul@299 | 531 | def abandon_branch(self): |
paul@299 | 532 | self.get_namespace()._abandon_branch() |
paul@299 | 533 | |
paul@388 | 534 | def suspend_broken_branch(self): |
paul@388 | 535 | self.get_namespace()._suspend_broken_branch() |
paul@388 | 536 | |
paul@388 | 537 | def suspend_continuing_branch(self): |
paul@388 | 538 | self.get_namespace()._suspend_continuing_branch() |
paul@387 | 539 | |
paul@272 | 540 | def shelve_branch(self): |
paul@272 | 541 | self.get_namespace()._shelve_branch() |
paul@272 | 542 | |
paul@379 | 543 | def merge_branches(self): |
paul@379 | 544 | self.get_namespace()._merge_branches() |
paul@272 | 545 | |
paul@388 | 546 | def resume_broken_branches(self): |
paul@388 | 547 | self.get_namespace()._resume_broken_branches() |
paul@388 | 548 | |
paul@388 | 549 | def resume_continuing_branches(self): |
paul@388 | 550 | self.get_namespace()._resume_continuing_branches() |
paul@387 | 551 | |
paul@540 | 552 | def resume_abandoned_branches(self): |
paul@540 | 553 | self.get_namespace()._resume_abandoned_branches() |
paul@540 | 554 | |
paul@278 | 555 | def define_attribute_user(self, node): |
paul@279 | 556 | |
paul@279 | 557 | """ |
paul@279 | 558 | Define 'node' as the user of attributes, indicating the point where the |
paul@279 | 559 | user is defined. |
paul@279 | 560 | """ |
paul@279 | 561 | |
paul@278 | 562 | self.get_namespace()._define_attribute_user(node) |
paul@272 | 563 | |
paul@404 | 564 | def use_attribute(self, name, attrname, value=None): |
paul@323 | 565 | |
paul@404 | 566 | """ |
paul@404 | 567 | Note usage on the attribute user 'name' of the attribute 'attrname', |
paul@404 | 568 | noting an assignment if 'value' is specified. |
paul@404 | 569 | """ |
paul@323 | 570 | |
paul@404 | 571 | return self.get_namespace()._use_attribute(name, attrname, value) |
paul@272 | 572 | |
paul@434 | 573 | def use_specific_attribute(self, objname, attrname, from_name=None): |
paul@347 | 574 | |
paul@347 | 575 | """ |
paul@347 | 576 | Note usage on the object having the given 'objname' of the attribute |
paul@351 | 577 | 'attrname'. If 'objname' is None, the current namespace is chosen as the |
paul@351 | 578 | object providing the attribute. |
paul@347 | 579 | """ |
paul@347 | 580 | |
paul@434 | 581 | return self.get_namespace()._use_specific_attribute(objname, attrname, from_name) |
paul@347 | 582 | |
paul@556 | 583 | def define_attribute_accessor(self, name, attrname, node, value=None): |
paul@556 | 584 | |
paul@556 | 585 | """ |
paul@556 | 586 | Note applicable attribute users providing the given 'name' when |
paul@556 | 587 | accessing the given 'attrname' on the specified 'node', with the |
paul@556 | 588 | optional 'value' indicating an assignment. |
paul@556 | 589 | """ |
paul@556 | 590 | |
paul@556 | 591 | self.get_namespace()._define_attribute_accessor(name, attrname, node, value) |
paul@556 | 592 | |
paul@3 | 593 | # Visitor methods. |
paul@3 | 594 | |
paul@3 | 595 | def default(self, node, *args): |
paul@339 | 596 | raise InspectError("Node class %r is not supported." % node.__class__) |
paul@3 | 597 | |
paul@0 | 598 | def NOP(self, node): |
paul@21 | 599 | for n in node.getChildNodes(): |
paul@21 | 600 | self.dispatch(n) |
paul@0 | 601 | |
paul@299 | 602 | def NOP_ABANDON(self, node): |
paul@302 | 603 | self.NOP(node) |
paul@299 | 604 | self.abandon_branch() |
paul@299 | 605 | |
paul@462 | 606 | def TEST_NOP(self, node): |
paul@462 | 607 | self.use_name("__bool__", node) |
paul@462 | 608 | self.NOP(node) |
paul@462 | 609 | |
paul@82 | 610 | def OP(self, node): |
paul@82 | 611 | for n in node.getChildNodes(): |
paul@82 | 612 | self.dispatch(n) |
paul@448 | 613 | return make_instance() |
paul@1 | 614 | |
paul@462 | 615 | def TEST_OP(self, node): |
paul@462 | 616 | self.use_name("__bool__", node) |
paul@531 | 617 | self.new_branchpoint() |
paul@531 | 618 | |
paul@531 | 619 | # Propagate attribute usage to branches. |
paul@531 | 620 | # Each node starts a new conditional region, effectively making a deeply |
paul@531 | 621 | # nested collection of if-like statements. |
paul@531 | 622 | |
paul@531 | 623 | for n in node.nodes: |
paul@531 | 624 | self.new_branch(n) |
paul@531 | 625 | self.dispatch(n) |
paul@531 | 626 | |
paul@531 | 627 | # The nested regions must be terminated. |
paul@531 | 628 | |
paul@531 | 629 | for n in node.nodes: |
paul@531 | 630 | self.shelve_branch() |
paul@531 | 631 | |
paul@531 | 632 | self.merge_branches() |
paul@531 | 633 | return make_instance() |
paul@462 | 634 | |
paul@314 | 635 | # Generic support for classes of operations. |
paul@314 | 636 | |
paul@581 | 637 | def _ensureOperators(self, node): |
paul@358 | 638 | attr, scope, namespace = self._get_with_scope("$operator") |
paul@358 | 639 | if attr is None: |
paul@581 | 640 | module = node._module |
paul@581 | 641 | module.complete() |
paul@354 | 642 | self["$operator"] = module |
paul@358 | 643 | else: |
paul@358 | 644 | module = attr.get_value() |
paul@358 | 645 | return module |
paul@354 | 646 | |
paul@374 | 647 | def _visitOperator(self, node, operator_name=None): |
paul@172 | 648 | |
paul@358 | 649 | "Accounting method for the operator 'node'." |
paul@172 | 650 | |
paul@581 | 651 | operator_module = self._ensureOperators(node) |
paul@374 | 652 | operator_fn = operator_functions[operator_name or node.__class__.__name__] |
paul@354 | 653 | self.use_specific_attribute(operator_module.full_name(), operator_fn) |
paul@172 | 654 | return self.OP(node) |
paul@172 | 655 | |
paul@372 | 656 | def _visitAttr(self, expr, attrname, node): |
paul@372 | 657 | |
paul@468 | 658 | """ |
paul@468 | 659 | Process the attribute provided by the given 'expr' with the given |
paul@468 | 660 | 'attrname' and involving the given 'node'. |
paul@468 | 661 | """ |
paul@468 | 662 | |
paul@372 | 663 | # Attempt to identify the nature of the attribute. |
paul@372 | 664 | |
paul@372 | 665 | if isinstance(expr, Attr): |
paul@372 | 666 | value = expr.get_value() |
paul@372 | 667 | |
paul@372 | 668 | # Get the attribute and record its usage. |
paul@559 | 669 | # NOTE: Need to provide concrete values for things like base classes |
paul@559 | 670 | # NOTE: while also handling module attribute modification. |
paul@372 | 671 | |
paul@599 | 672 | # Only specific class attributes are detected here since class |
paul@599 | 673 | # attribute finalisation has not yet occurred. |
paul@599 | 674 | |
paul@559 | 675 | if isinstance(value, (Class, Module)): |
paul@401 | 676 | |
paul@401 | 677 | # Check for class.__class__. |
paul@401 | 678 | |
paul@401 | 679 | if attrname == "__class__" and isinstance(value, Class): |
paul@618 | 680 | attr = get_constant_class("type") |
paul@401 | 681 | else: |
paul@448 | 682 | attr = value.get(attrname) or make_instance() |
paul@372 | 683 | self.use_specific_attribute(value.full_name(), attrname) |
paul@372 | 684 | |
paul@372 | 685 | elif isinstance(value, UnresolvedName): |
paul@372 | 686 | attr = UnresolvedName(attrname, value.full_name(), self) |
paul@372 | 687 | |
paul@467 | 688 | # The actual attribute is not readily identifiable and is assumed |
paul@467 | 689 | # to be an instance. |
paul@467 | 690 | |
paul@372 | 691 | else: |
paul@527 | 692 | |
paul@527 | 693 | # Record any instance attributes. |
paul@527 | 694 | |
paul@527 | 695 | if expr.name == "self": |
paul@527 | 696 | self.store_instance_attr(attrname, tentative=True) |
paul@527 | 697 | |
paul@448 | 698 | attr = make_instance() |
paul@372 | 699 | |
paul@372 | 700 | # Note usage of the attribute where a local is involved. |
paul@372 | 701 | |
paul@404 | 702 | self._visitAttrUser(expr, attrname, node) |
paul@372 | 703 | |
paul@619 | 704 | # Constants provide specific kinds of expressions. |
paul@619 | 705 | # NOTE: If attributes are accessed on a pre-made, but not yet defined |
paul@619 | 706 | # NOTE: class, no useful attribute will be available. |
paul@619 | 707 | |
paul@619 | 708 | elif isinstance(expr, Const): |
paul@619 | 709 | attr = get_constant_class(expr.get_class_name()).all_attributes().get(attrname) or make_instance() |
paul@619 | 710 | |
paul@467 | 711 | # No particular attribute has been identified, thus a general instance |
paul@467 | 712 | # is assumed. |
paul@467 | 713 | |
paul@372 | 714 | else: |
paul@448 | 715 | attr = make_instance() |
paul@372 | 716 | self.use_name(attrname, node) |
paul@372 | 717 | |
paul@372 | 718 | return attr |
paul@358 | 719 | |
paul@404 | 720 | def _visitAttrUser(self, expr, attrname, node, value=None): |
paul@404 | 721 | |
paul@404 | 722 | """ |
paul@404 | 723 | Note usage of the attribute provided by 'expr' with the given 'attrname' |
paul@404 | 724 | where a local is involved, annotating the given 'node'. If the optional |
paul@404 | 725 | 'value' is given, note an assignment for future effects on attributes |
paul@404 | 726 | where such attributes are inferred from the usage. |
paul@404 | 727 | """ |
paul@404 | 728 | |
paul@571 | 729 | # Access to attributes via a local in functions, classes or modules. |
paul@571 | 730 | # Since module-level locals are globals that can be modified |
paul@571 | 731 | # independently of the namespace, any attribute usage observations made |
paul@571 | 732 | # here may be revoked later if such modification is thought to occur. |
paul@467 | 733 | |
paul@571 | 734 | if expr.parent is self.get_namespace(): |
paul@556 | 735 | self.define_attribute_accessor(expr.name, attrname, node, value) |
paul@404 | 736 | else: |
paul@557 | 737 | self.use_name(attrname, node.expr, value, ns=expr.parent) |
paul@404 | 738 | |
paul@439 | 739 | def _visitConst(self, value): |
paul@439 | 740 | |
paul@439 | 741 | """ |
paul@439 | 742 | Register the constant given by 'value', if necessary, returning the |
paul@439 | 743 | resulting object. The type name is noted as being used, thus preserving |
paul@439 | 744 | the class in any generated program. |
paul@439 | 745 | """ |
paul@439 | 746 | |
paul@439 | 747 | self.use_specific_attribute("__builtins__", self.importer.get_constant_type_name(value)) |
paul@440 | 748 | const = self.importer.make_constant(value) |
paul@440 | 749 | self.use_constant(const) |
paul@440 | 750 | return const |
paul@439 | 751 | |
paul@85 | 752 | def _visitFunction(self, node, name): |
paul@85 | 753 | |
paul@85 | 754 | """ |
paul@85 | 755 | Return a function object for the function defined by 'node' with the |
paul@85 | 756 | given 'name'. If a lambda expression is being visited, 'name' should be |
paul@85 | 757 | None. |
paul@85 | 758 | """ |
paul@85 | 759 | |
paul@233 | 760 | # Define the function object. |
paul@233 | 761 | |
paul@85 | 762 | function = Function( |
paul@85 | 763 | name, |
paul@272 | 764 | self.get_namespace(), |
paul@85 | 765 | node.argnames, |
paul@85 | 766 | node.defaults, |
paul@85 | 767 | (node.flags & 4 != 0), |
paul@85 | 768 | (node.flags & 8 != 0), |
paul@331 | 769 | self.in_loop or self.in_function, |
paul@85 | 770 | self, |
paul@85 | 771 | node |
paul@85 | 772 | ) |
paul@85 | 773 | |
paul@233 | 774 | self.add_object(function, any_scope=1) |
paul@233 | 775 | |
paul@85 | 776 | # Make a back reference from the node for code generation. |
paul@85 | 777 | |
paul@85 | 778 | node.unit = function |
paul@85 | 779 | |
paul@85 | 780 | # Process the defaults. |
paul@85 | 781 | |
paul@85 | 782 | for n in node.defaults: |
paul@85 | 783 | self.expr = self.dispatch(n) |
paul@192 | 784 | function.store_default(self.expr) |
paul@85 | 785 | |
paul@368 | 786 | # Note attribute usage where tuple parameters are involved. |
paul@368 | 787 | |
paul@368 | 788 | if function.tuple_parameters(): |
paul@368 | 789 | self.use_name("__getitem__", node) |
paul@368 | 790 | |
paul@368 | 791 | # Record the namespace context of the function for later processing. |
paul@368 | 792 | |
paul@235 | 793 | self.functions.append((node, self.namespaces + [function])) |
paul@85 | 794 | |
paul@330 | 795 | # Store the function. |
paul@330 | 796 | |
paul@85 | 797 | if name is not None: |
paul@85 | 798 | self.store(name, function) |
paul@85 | 799 | else: |
paul@85 | 800 | self.store_lambda(function) |
paul@167 | 801 | |
paul@330 | 802 | # Test the defaults and assess whether an dynamic object will result. |
paul@330 | 803 | |
paul@331 | 804 | function.make_dynamic() |
paul@331 | 805 | return function |
paul@85 | 806 | |
paul@235 | 807 | def _visitFunctionBody(self, node, namespaces): |
paul@235 | 808 | |
paul@235 | 809 | "Enter the function." |
paul@235 | 810 | |
paul@235 | 811 | # Current namespace is the function. |
paul@235 | 812 | # Previous namespace is the class. |
paul@235 | 813 | |
paul@330 | 814 | if self.in_class(namespaces): |
paul@591 | 815 | self.in_method = True |
paul@235 | 816 | |
paul@331 | 817 | in_function = self.in_function |
paul@331 | 818 | in_loop = self.in_loop |
paul@591 | 819 | self.in_function = True |
paul@591 | 820 | self.in_loop = False |
paul@331 | 821 | |
paul@235 | 822 | self.namespaces = namespaces |
paul@235 | 823 | self.dispatch(node.code) |
paul@235 | 824 | |
paul@331 | 825 | self.in_loop = in_loop |
paul@331 | 826 | self.in_function = in_function |
paul@591 | 827 | self.in_method = False |
paul@235 | 828 | |
paul@172 | 829 | # Specific handler methods. |
paul@172 | 830 | |
paul@580 | 831 | visitAdd = _visitOperator |
paul@82 | 832 | |
paul@462 | 833 | visitAnd = TEST_OP |
paul@0 | 834 | |
paul@4 | 835 | visitAssert = NOP |
paul@4 | 836 | |
paul@0 | 837 | def visitAssign(self, node): |
paul@0 | 838 | self.expr = self.dispatch(node.expr) |
paul@591 | 839 | self.in_assignment = True |
paul@0 | 840 | for n in node.nodes: |
paul@0 | 841 | self.dispatch(n) |
paul@591 | 842 | self.in_assignment = False |
paul@0 | 843 | |
paul@0 | 844 | def visitAssAttr(self, node): |
paul@0 | 845 | expr = self.dispatch(node.expr) |
paul@404 | 846 | attrname = node.attrname |
paul@272 | 847 | |
paul@272 | 848 | # Record the attribute on the presumed target. |
paul@272 | 849 | |
paul@94 | 850 | if isinstance(expr, Attr): |
paul@404 | 851 | value = expr.get_value() |
paul@404 | 852 | |
paul@94 | 853 | if expr.name == "self": |
paul@404 | 854 | self.store_instance_attr(attrname) |
paul@556 | 855 | self.use_attribute(expr.name, attrname, value) |
paul@488 | 856 | self._visitAttrUser(expr, attrname, node, self.expr) |
paul@404 | 857 | |
paul@602 | 858 | # No definite attribute can be identified, since the instance |
paul@602 | 859 | # being accessed may be a subclass of the method's class. |
paul@602 | 860 | |
paul@602 | 861 | attr = make_instance() |
paul@602 | 862 | |
paul@404 | 863 | elif isinstance(value, Module): |
paul@404 | 864 | self.store_module_attr(attrname, value) |
paul@602 | 865 | attr = value.get(attrname) |
paul@272 | 866 | |
paul@404 | 867 | elif isinstance(value, Class): |
paul@404 | 868 | self.store_class_attr(attrname, value) |
paul@602 | 869 | attr = value.get(attrname) |
paul@404 | 870 | |
paul@285 | 871 | # Note usage of the attribute where a local is involved. |
paul@272 | 872 | |
paul@404 | 873 | else: |
paul@404 | 874 | self._visitAttrUser(expr, attrname, node, self.expr) |
paul@602 | 875 | attr = make_instance() |
paul@381 | 876 | |
paul@404 | 877 | else: |
paul@404 | 878 | self.use_name(attrname, node) |
paul@602 | 879 | attr = make_instance() |
paul@602 | 880 | |
paul@602 | 881 | node._attr = attr |
paul@272 | 882 | |
paul@0 | 883 | def visitAssList(self, node): |
paul@204 | 884 | |
paul@204 | 885 | # Declare names which will be used by generated code. |
paul@204 | 886 | |
paul@323 | 887 | self.use_name("__getitem__", node) |
paul@204 | 888 | |
paul@204 | 889 | # Process the assignment. |
paul@204 | 890 | |
paul@139 | 891 | for i, n in enumerate(node.nodes): |
paul@0 | 892 | self.dispatch(n) |
paul@439 | 893 | self._visitConst(i) # for __getitem__(i) at run-time |
paul@0 | 894 | |
paul@0 | 895 | def visitAssName(self, node): |
paul@599 | 896 | if node.flags == "OP_DELETE": |
paul@507 | 897 | print >>sys.stderr, "Warning: deletion of attribute %r in %r is not supported." % (node.name, self.full_name()) |
paul@339 | 898 | #raise InspectError("Deletion of attribute %r is not supported." % node.name) |
paul@599 | 899 | self._visitAssName(node) |
paul@274 | 900 | |
paul@599 | 901 | def _visitAssName(self, node): |
paul@120 | 902 | self.store(node.name, self.expr) |
paul@278 | 903 | self.define_attribute_user(node) |
paul@285 | 904 | |
paul@285 | 905 | # Ensure the presence of the given name in this namespace. |
paul@431 | 906 | # NOTE: Consider not registering assignments involving methods, since |
paul@431 | 907 | # NOTE: this is merely creating aliases for such methods. |
paul@285 | 908 | |
paul@434 | 909 | if isinstance(self.get_namespace(), (Class, Module)): |
paul@434 | 910 | if not isinstance(self.expr, Attr) or not isinstance(self.expr.get_value(), Function): |
paul@434 | 911 | self.use_specific_attribute(None, node.name) |
paul@434 | 912 | else: |
paul@434 | 913 | fn = self.expr.get_value() |
paul@434 | 914 | ns = self.get_namespace().full_name() |
paul@434 | 915 | self.use_specific_attribute(fn.parent.full_name(), fn.name, "%s.%s" % (ns, node.name)) |
paul@434 | 916 | |
paul@0 | 917 | visitAssTuple = visitAssList |
paul@0 | 918 | |
paul@172 | 919 | def visitAugAssign(self, node): |
paul@172 | 920 | |
paul@172 | 921 | # Accounting. |
paul@172 | 922 | |
paul@354 | 923 | operator_fn = operator_functions.get(node.op) |
paul@581 | 924 | operator_module = self._ensureOperators(node) |
paul@354 | 925 | self.use_specific_attribute(operator_module.full_name(), operator_fn) |
paul@244 | 926 | |
paul@244 | 927 | # Process the assignment. |
paul@244 | 928 | |
paul@244 | 929 | self.expr = self.dispatch(node.expr) |
paul@244 | 930 | |
paul@244 | 931 | # NOTE: Similar to micropython.ast handler code. |
paul@363 | 932 | # NOTE: Slices and subscripts are supported by __setitem__(slice) and |
paul@363 | 933 | # NOTE: not __setslice__. |
paul@244 | 934 | |
paul@244 | 935 | if isinstance(node.node, compiler.ast.Name): |
paul@599 | 936 | self._visitAssName(node.node) |
paul@244 | 937 | elif isinstance(node.node, compiler.ast.Getattr): |
paul@244 | 938 | self.visitAssAttr(node.node) |
paul@244 | 939 | else: |
paul@594 | 940 | self.dispatch(node.node) |
paul@363 | 941 | self.use_specific_attribute("__builtins__", "slice") |
paul@363 | 942 | self.use_name("__setitem__", node) |
paul@244 | 943 | |
paul@82 | 944 | visitBackquote = OP |
paul@4 | 945 | |
paul@580 | 946 | visitBitand = _visitOperator |
paul@2 | 947 | |
paul@580 | 948 | visitBitor = _visitOperator |
paul@2 | 949 | |
paul@580 | 950 | visitBitxor = _visitOperator |
paul@4 | 951 | |
paul@388 | 952 | def visitBreak(self, node): |
paul@388 | 953 | self.NOP(node) |
paul@388 | 954 | self.suspend_broken_branch() |
paul@4 | 955 | |
paul@82 | 956 | visitCallFunc = OP |
paul@0 | 957 | |
paul@0 | 958 | def visitClass(self, node): |
paul@91 | 959 | |
paul@91 | 960 | """ |
paul@91 | 961 | Register the class at the given 'node' subject to the restrictions |
paul@91 | 962 | mentioned in the module docstring. |
paul@91 | 963 | """ |
paul@91 | 964 | |
paul@12 | 965 | if self.namespaces: |
paul@507 | 966 | print >>sys.stderr, "Warning: class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) |
paul@442 | 967 | return |
paul@0 | 968 | else: |
paul@331 | 969 | if self.in_loop: |
paul@507 | 970 | print >>sys.stderr, "Warning: class %r in %r defined in a loop." % (node.name, self.full_name()) |
paul@331 | 971 | |
paul@394 | 972 | cls = get_class(node.name, self.get_namespace(), self, node) |
paul@37 | 973 | |
paul@349 | 974 | # Make a back reference from the node for code generation. |
paul@349 | 975 | |
paul@349 | 976 | node.unit = cls |
paul@349 | 977 | |
paul@349 | 978 | # Process base classes in the context of the class's namespace. |
paul@349 | 979 | # This confines references to such classes to the class instead of |
paul@349 | 980 | # the namespace in which it is defined. |
paul@349 | 981 | |
paul@349 | 982 | self.namespaces.append(cls) |
paul@349 | 983 | |
paul@37 | 984 | # Visit the base class expressions, attempting to find concrete |
paul@37 | 985 | # definitions of classes. |
paul@37 | 986 | |
paul@0 | 987 | for base in node.bases: |
paul@36 | 988 | expr = self.dispatch(base) |
paul@349 | 989 | |
paul@349 | 990 | # Each base class must be constant and known at compile-time. |
paul@349 | 991 | |
paul@36 | 992 | if isinstance(expr, Attr): |
paul@36 | 993 | if expr.assignments != 1: |
paul@442 | 994 | raise InspectError("Base class %r for %r is not constant: %r" % (base, cls.full_name(), expr)) |
paul@541 | 995 | elif not isinstance(expr.get_value(), Class): |
paul@541 | 996 | raise InspectError("Base class %r for %r is not a class: %r" % (base, cls.full_name(), expr.get_value())) |
paul@36 | 997 | else: |
paul@192 | 998 | cls.add_base(expr.get_value()) |
paul@349 | 999 | |
paul@349 | 1000 | # Where no expression value is available, the base class is |
paul@349 | 1001 | # not identifiable. |
paul@349 | 1002 | |
paul@349 | 1003 | else: |
paul@339 | 1004 | raise InspectError("Base class %r for %r is not found: it may be hidden in some way." % (base, cls.full_name())) |
paul@0 | 1005 | |
paul@59 | 1006 | # NOTE: Potentially dubious measure to permit __init__ availability. |
paul@59 | 1007 | # If no bases exist, adopt the 'object' class. |
paul@59 | 1008 | |
paul@580 | 1009 | if not node.bases and not (self.name == "__builtins__" and node.name == "object"): |
paul@59 | 1010 | expr = self.dispatch(compiler.ast.Name("object")) |
paul@192 | 1011 | cls.add_base(expr.get_value()) |
paul@59 | 1012 | |
paul@349 | 1013 | # Make an entry for the class in the parent namespace. |
paul@21 | 1014 | |
paul@349 | 1015 | self.namespaces.pop() |
paul@0 | 1016 | self.store(node.name, cls) |
paul@635 | 1017 | self.define_attribute_user(node) |
paul@167 | 1018 | self.add_object(cls) |
paul@0 | 1019 | |
paul@349 | 1020 | # Process the class body in its own namespace. |
paul@439 | 1021 | # Add __name__ to the namespace. |
paul@59 | 1022 | |
paul@12 | 1023 | self.namespaces.append(cls) |
paul@439 | 1024 | self.store("__name__", self._visitConst(node.name)) |
paul@0 | 1025 | self.dispatch(node.code) |
paul@12 | 1026 | self.namespaces.pop() |
paul@0 | 1027 | |
paul@349 | 1028 | cls.finalise_attribute_usage() |
paul@82 | 1029 | return cls |
paul@0 | 1030 | |
paul@172 | 1031 | def visitCompare(self, node): |
paul@172 | 1032 | |
paul@172 | 1033 | # Accounting. |
paul@172 | 1034 | # NOTE: Replicates some code in micropython.ast.visitCompare. |
paul@172 | 1035 | |
paul@462 | 1036 | self.use_name("__bool__", node) |
paul@462 | 1037 | |
paul@323 | 1038 | this_node = node |
paul@323 | 1039 | |
paul@172 | 1040 | for op in node.ops: |
paul@172 | 1041 | op_name, next_node = op |
paul@323 | 1042 | |
paul@354 | 1043 | # Define name/attribute usage. |
paul@354 | 1044 | # Get the applicable operation. |
paul@323 | 1045 | |
paul@354 | 1046 | operator_fn = operator_functions.get(op_name) |
paul@354 | 1047 | |
paul@354 | 1048 | # For operators, reference the specific function involved. |
paul@323 | 1049 | |
paul@354 | 1050 | if operator_fn is not None: |
paul@581 | 1051 | operator_module = self._ensureOperators(node) |
paul@354 | 1052 | self.use_specific_attribute(operator_module.full_name(), operator_fn) |
paul@323 | 1053 | |
paul@354 | 1054 | # Define __contains__ usage on the next node. |
paul@354 | 1055 | |
paul@172 | 1056 | elif op_name.endswith("in"): |
paul@323 | 1057 | self.use_name("__contains__", next_node) |
paul@323 | 1058 | |
paul@323 | 1059 | this_node = next_node |
paul@172 | 1060 | |
paul@172 | 1061 | return self.OP(node) |
paul@4 | 1062 | |
paul@21 | 1063 | def visitConst(self, node): |
paul@439 | 1064 | return self._visitConst(node.value) |
paul@0 | 1065 | |
paul@388 | 1066 | def visitContinue(self, node): |
paul@388 | 1067 | self.NOP(node) |
paul@388 | 1068 | self.suspend_continuing_branch() |
paul@4 | 1069 | |
paul@4 | 1070 | visitDecorators = NOP |
paul@4 | 1071 | |
paul@82 | 1072 | visitDict = OP |
paul@0 | 1073 | |
paul@0 | 1074 | visitDiscard = NOP |
paul@0 | 1075 | |
paul@580 | 1076 | visitDiv = _visitOperator |
paul@4 | 1077 | |
paul@4 | 1078 | visitEllipsis = NOP |
paul@4 | 1079 | |
paul@4 | 1080 | visitExec = NOP |
paul@4 | 1081 | |
paul@82 | 1082 | visitExpression = OP |
paul@4 | 1083 | |
paul@580 | 1084 | visitFloorDiv = _visitOperator |
paul@4 | 1085 | |
paul@34 | 1086 | def visitFor(self, node): |
paul@388 | 1087 | self.new_branchpoint(node) |
paul@204 | 1088 | |
paul@204 | 1089 | # Declare names which will be used by generated code. |
paul@204 | 1090 | |
paul@323 | 1091 | self.use_name("__iter__", node.list) |
paul@250 | 1092 | self.use_name("next") |
paul@345 | 1093 | self.use_name("StopIteration") |
paul@204 | 1094 | |
paul@331 | 1095 | in_loop = self.in_loop |
paul@591 | 1096 | self.in_loop = True |
paul@341 | 1097 | self.dispatch(node.list) |
paul@442 | 1098 | |
paul@442 | 1099 | # NOTE: Could generate AST nodes for the actual operations instead of |
paul@442 | 1100 | # NOTE: manually generating code in micropython.ast. |
paul@442 | 1101 | |
paul@448 | 1102 | self.expr = make_instance() # each element is a result of a function call |
paul@272 | 1103 | self.dispatch(node.assign) |
paul@272 | 1104 | |
paul@204 | 1105 | # Enter the loop. |
paul@275 | 1106 | # Propagate attribute usage to branches. |
paul@204 | 1107 | |
paul@379 | 1108 | self.new_branch(node) |
paul@272 | 1109 | self.dispatch(node.body) |
paul@385 | 1110 | |
paul@388 | 1111 | self.resume_continuing_branches() |
paul@385 | 1112 | |
paul@272 | 1113 | self.shelve_branch() |
paul@362 | 1114 | |
paul@331 | 1115 | self.in_loop = in_loop |
paul@272 | 1116 | |
paul@386 | 1117 | # A null branch is used to record a path around the loop. |
paul@275 | 1118 | |
paul@379 | 1119 | self.new_branch(node.else_ or NullBranch()) |
paul@379 | 1120 | self.shelve_branch() |
paul@272 | 1121 | |
paul@379 | 1122 | self.merge_branches() |
paul@386 | 1123 | |
paul@386 | 1124 | # The else clause is evaluated outside any branch. |
paul@386 | 1125 | |
paul@386 | 1126 | if node.else_ is not None: |
paul@386 | 1127 | self.dispatch(node.else_) |
paul@386 | 1128 | |
paul@387 | 1129 | # Any suspended branches from the loop can now be resumed. |
paul@387 | 1130 | |
paul@388 | 1131 | self.resume_broken_branches() |
paul@387 | 1132 | |
paul@0 | 1133 | def visitFrom(self, node): |
paul@581 | 1134 | module = self.complete_import(node.modname, True) |
paul@0 | 1135 | |
paul@0 | 1136 | for name, alias in node.names: |
paul@563 | 1137 | |
paul@563 | 1138 | # For specific names, obtain and store referenced objects using |
paul@563 | 1139 | # the name or any alias provided in the current namespace. |
paul@563 | 1140 | |
paul@0 | 1141 | if name != "*": |
paul@545 | 1142 | if module: |
paul@501 | 1143 | |
paul@501 | 1144 | # Missing names may refer to submodules. |
paul@501 | 1145 | |
paul@581 | 1146 | submodule = self.complete_import(node.modname + "." + name, True) |
paul@581 | 1147 | if submodule: |
paul@581 | 1148 | if not module.has_key(name): |
paul@501 | 1149 | module.store(name, submodule) |
paul@501 | 1150 | |
paul@501 | 1151 | # Complete the import if the name was found. |
paul@501 | 1152 | |
paul@501 | 1153 | if module.has_key(name): |
paul@501 | 1154 | attr = module[name] |
paul@501 | 1155 | self.store(alias or name, attr) |
paul@501 | 1156 | self.use_specific_attribute(module.full_name(), name) |
paul@501 | 1157 | continue |
paul@24 | 1158 | |
paul@24 | 1159 | # Support the import of names from missing modules. |
paul@24 | 1160 | |
paul@501 | 1161 | self.store(alias or name, UnresolvedName(name, node.modname, self)) |
paul@501 | 1162 | |
paul@563 | 1163 | # For wildcards, obtain and store all objects from a module in the |
paul@563 | 1164 | # current namespace. |
paul@563 | 1165 | |
paul@3 | 1166 | else: |
paul@545 | 1167 | if module: |
paul@285 | 1168 | for n in module.keys(): |
paul@24 | 1169 | attr = module[n] |
paul@192 | 1170 | self.store(n, attr) |
paul@364 | 1171 | self.use_specific_attribute(module.full_name(), n) |
paul@0 | 1172 | |
paul@0 | 1173 | def visitFunction(self, node): |
paul@85 | 1174 | return self._visitFunction(node, node.name) |
paul@0 | 1175 | |
paul@82 | 1176 | visitGenExpr = OP |
paul@4 | 1177 | |
paul@4 | 1178 | visitGenExprFor = NOP |
paul@4 | 1179 | |
paul@4 | 1180 | visitGenExprIf = NOP |
paul@4 | 1181 | |
paul@4 | 1182 | visitGenExprInner = NOP |
paul@4 | 1183 | |
paul@0 | 1184 | def visitGetattr(self, node): |
paul@602 | 1185 | node._expr = self.dispatch(node.expr) |
paul@602 | 1186 | node._attr = self._visitAttr(node._expr, node.attrname, node) |
paul@556 | 1187 | return node._attr |
paul@4 | 1188 | |
paul@12 | 1189 | def visitGlobal(self, node): |
paul@12 | 1190 | if self.namespaces: |
paul@12 | 1191 | for name in node.names: |
paul@178 | 1192 | ns = self.namespaces[-1] |
paul@178 | 1193 | if not ns.make_global(name): |
paul@339 | 1194 | raise InspectError("Name %r is global and local in %r" % (name, ns.full_name())) |
paul@37 | 1195 | |
paul@236 | 1196 | # The name is recorded in an earlier process. |
paul@0 | 1197 | |
paul@0 | 1198 | def visitIf(self, node): |
paul@462 | 1199 | self.use_name("__bool__", node) |
paul@272 | 1200 | self.new_branchpoint() |
paul@272 | 1201 | |
paul@275 | 1202 | # Propagate attribute usage to branches. |
paul@275 | 1203 | |
paul@0 | 1204 | for test, body in node.tests: |
paul@202 | 1205 | self.dispatch(test) |
paul@272 | 1206 | |
paul@377 | 1207 | self.new_branch(body) |
paul@0 | 1208 | self.dispatch(body) |
paul@272 | 1209 | self.shelve_branch() |
paul@272 | 1210 | |
paul@377 | 1211 | # Maintain a branch for the else clause. |
paul@275 | 1212 | |
paul@379 | 1213 | self.new_branch(node.else_ or NullBranch()) |
paul@0 | 1214 | if node.else_ is not None: |
paul@0 | 1215 | self.dispatch(node.else_) |
paul@379 | 1216 | self.shelve_branch() |
paul@272 | 1217 | |
paul@272 | 1218 | self.merge_branches() |
paul@442 | 1219 | |
paul@442 | 1220 | def visitIfExp(self, node): |
paul@462 | 1221 | self.use_name("__bool__", node) |
paul@442 | 1222 | self.new_branchpoint() |
paul@442 | 1223 | |
paul@442 | 1224 | # Propagate attribute usage to branches. |
paul@442 | 1225 | |
paul@442 | 1226 | self.dispatch(node.test) |
paul@0 | 1227 | |
paul@442 | 1228 | self.new_branch(node.then) |
paul@442 | 1229 | self.dispatch(node.then) |
paul@442 | 1230 | self.shelve_branch() |
paul@442 | 1231 | |
paul@442 | 1232 | self.new_branch(node.else_) |
paul@442 | 1233 | self.dispatch(node.else_) |
paul@442 | 1234 | self.shelve_branch() |
paul@442 | 1235 | |
paul@442 | 1236 | self.merge_branches() |
paul@448 | 1237 | return make_instance() # either outcome is possible |
paul@12 | 1238 | |
paul@0 | 1239 | def visitImport(self, node): |
paul@0 | 1240 | for name, alias in node.names: |
paul@581 | 1241 | module = self.complete_import(name, alias) |
paul@2 | 1242 | if alias is not None: |
paul@581 | 1243 | self.store(alias, module or UnresolvedName(None, name, self)) |
paul@2 | 1244 | else: |
paul@581 | 1245 | name_used = name.split(".")[0] |
paul@581 | 1246 | self.store(name_used, module or UnresolvedName(None, name_used, self)) |
paul@578 | 1247 | |
paul@580 | 1248 | visitInvert = _visitOperator |
paul@4 | 1249 | |
paul@59 | 1250 | def visitKeyword(self, node): |
paul@59 | 1251 | self.dispatch(node.expr) |
paul@439 | 1252 | self._visitConst(node.name) |
paul@71 | 1253 | self.keyword_names.add(node.name) |
paul@4 | 1254 | |
paul@85 | 1255 | def visitLambda(self, node): |
paul@351 | 1256 | fn = self._visitFunction(node, None) |
paul@351 | 1257 | self.use_specific_attribute(None, fn.name) |
paul@351 | 1258 | return fn |
paul@4 | 1259 | |
paul@580 | 1260 | visitLeftShift = _visitOperator |
paul@1 | 1261 | |
paul@346 | 1262 | def visitList(self, node): |
paul@347 | 1263 | self.use_specific_attribute("__builtins__", "list") |
paul@442 | 1264 | return self.OP(node) |
paul@0 | 1265 | |
paul@341 | 1266 | def visitListComp(self, node): |
paul@506 | 1267 | |
paul@506 | 1268 | # Note that explicit dispatch is performed. |
paul@506 | 1269 | |
paul@506 | 1270 | if node.quals: |
paul@506 | 1271 | self.visitListCompFor(node.quals[0], node.quals[1:], node.expr) |
paul@448 | 1272 | return make_instance() |
paul@341 | 1273 | |
paul@506 | 1274 | def visitListCompFor(self, node, following_quals, expr): |
paul@341 | 1275 | self.new_branchpoint() |
paul@341 | 1276 | |
paul@341 | 1277 | # Declare names which will be used by generated code. |
paul@341 | 1278 | |
paul@341 | 1279 | self.use_name("__iter__", node.list) |
paul@341 | 1280 | self.use_name("next") |
paul@4 | 1281 | |
paul@341 | 1282 | in_loop = self.in_loop |
paul@591 | 1283 | self.in_loop = True |
paul@341 | 1284 | self.dispatch(node.list) |
paul@442 | 1285 | |
paul@442 | 1286 | # NOTE: Could generate AST nodes for the actual operations instead of |
paul@442 | 1287 | # NOTE: manually generating code in micropython.ast. |
paul@442 | 1288 | |
paul@448 | 1289 | self.expr = make_instance() # each element is a result of a function call |
paul@341 | 1290 | self.dispatch(node.assign) |
paul@341 | 1291 | |
paul@341 | 1292 | # Enter the loop. |
paul@341 | 1293 | # Propagate attribute usage to branches. |
paul@341 | 1294 | |
paul@379 | 1295 | self.new_branch(node) |
paul@341 | 1296 | |
paul@506 | 1297 | # Note that explicit dispatch is performed. |
paul@506 | 1298 | |
paul@506 | 1299 | if node.ifs: |
paul@506 | 1300 | self.visitListCompIf(node.ifs[0], node.ifs[1:], following_quals, expr) |
paul@506 | 1301 | elif following_quals: |
paul@506 | 1302 | self.visitListCompFor(following_quals[0], following_quals[1:], expr) |
paul@506 | 1303 | else: |
paul@506 | 1304 | self.dispatch(expr) |
paul@341 | 1305 | |
paul@341 | 1306 | self.shelve_branch() |
paul@341 | 1307 | self.in_loop = in_loop |
paul@341 | 1308 | |
paul@379 | 1309 | self.merge_branches() |
paul@4 | 1310 | |
paul@506 | 1311 | def visitListCompIf(self, node, following_ifs, following_quals, expr): |
paul@506 | 1312 | self.use_name("__bool__", node) |
paul@506 | 1313 | self.new_branchpoint() |
paul@506 | 1314 | |
paul@506 | 1315 | # Propagate attribute usage to branches. |
paul@506 | 1316 | |
paul@506 | 1317 | self.dispatch(node.test) |
paul@506 | 1318 | |
paul@506 | 1319 | # Note that explicit dispatch is performed. |
paul@506 | 1320 | |
paul@506 | 1321 | if following_ifs: |
paul@506 | 1322 | self.visitListCompIf(following_ifs[0], following_ifs[1:], following_quals, expr) |
paul@506 | 1323 | elif following_quals: |
paul@506 | 1324 | self.visitListCompFor(following_quals[0], following_quals[1:], expr) |
paul@506 | 1325 | else: |
paul@506 | 1326 | self.new_branch(expr) |
paul@506 | 1327 | self.dispatch(expr) |
paul@506 | 1328 | self.shelve_branch() |
paul@506 | 1329 | |
paul@506 | 1330 | # Maintain a branch for the else clause. |
paul@506 | 1331 | |
paul@506 | 1332 | self.new_branch(NullBranch()) |
paul@506 | 1333 | self.shelve_branch() |
paul@506 | 1334 | |
paul@506 | 1335 | self.merge_branches() |
paul@4 | 1336 | |
paul@580 | 1337 | visitMod = _visitOperator |
paul@4 | 1338 | |
paul@0 | 1339 | def visitModule(self, node): |
paul@143 | 1340 | |
paul@143 | 1341 | # Make a back reference from the node for code generation. |
paul@143 | 1342 | |
paul@143 | 1343 | node.unit = self |
paul@0 | 1344 | return self.dispatch(node.node) |
paul@0 | 1345 | |
paul@580 | 1346 | visitMul = _visitOperator |
paul@2 | 1347 | |
paul@0 | 1348 | def visitName(self, node): |
paul@583 | 1349 | attr = self.get_namespace().get_using_node(node.name, node) or make_instance() |
paul@583 | 1350 | node._attr = attr |
paul@583 | 1351 | return attr |
paul@0 | 1352 | |
paul@531 | 1353 | def visitNot(self, node): |
paul@531 | 1354 | self.use_name("__bool__", node) |
paul@531 | 1355 | self.dispatch(node.expr) |
paul@531 | 1356 | return make_instance() |
paul@0 | 1357 | |
paul@462 | 1358 | visitOr = TEST_OP |
paul@0 | 1359 | |
paul@0 | 1360 | visitPass = NOP |
paul@0 | 1361 | |
paul@580 | 1362 | visitPower = _visitOperator |
paul@4 | 1363 | |
paul@393 | 1364 | def _visitPrint(self, node, function_name): |
paul@393 | 1365 | self.NOP(node) |
paul@393 | 1366 | self.use_specific_attribute("__builtins__", function_name) |
paul@4 | 1367 | |
paul@393 | 1368 | def visitPrint(self, node): |
paul@393 | 1369 | self._visitPrint(node, "_print") |
paul@393 | 1370 | |
paul@393 | 1371 | def visitPrintnl(self, node): |
paul@393 | 1372 | self._visitPrint(node, "_printnl") |
paul@4 | 1373 | |
paul@299 | 1374 | visitRaise = NOP_ABANDON |
paul@0 | 1375 | |
paul@299 | 1376 | visitReturn = NOP_ABANDON |
paul@4 | 1377 | |
paul@580 | 1378 | visitRightShift = _visitOperator |
paul@1 | 1379 | |
paul@342 | 1380 | def visitSlice(self, node): |
paul@442 | 1381 | return self._visitOperator(node, self.in_assignment and "AssSlice" or "Slice") |
paul@4 | 1382 | |
paul@82 | 1383 | visitSliceobj = OP |
paul@23 | 1384 | |
paul@0 | 1385 | def visitStmt(self, node): |
paul@0 | 1386 | for n in node.nodes: |
paul@0 | 1387 | self.dispatch(n) |
paul@0 | 1388 | |
paul@580 | 1389 | visitSub = _visitOperator |
paul@4 | 1390 | |
paul@216 | 1391 | def visitSubscript(self, node): |
paul@442 | 1392 | return self._visitOperator(node, self.in_assignment and "AssSubscript" or "Subscript") |
paul@0 | 1393 | |
paul@0 | 1394 | def visitTryExcept(self, node): |
paul@540 | 1395 | self.new_branchpoint() |
paul@0 | 1396 | self.dispatch(node.body) |
paul@272 | 1397 | |
paul@0 | 1398 | for name, var, n in node.handlers: |
paul@572 | 1399 | if name is not None: |
paul@572 | 1400 | self.dispatch(name) |
paul@572 | 1401 | |
paul@537 | 1402 | self.new_branch(n) |
paul@97 | 1403 | |
paul@540 | 1404 | # Any abandoned branches from the body can now be resumed. |
paul@540 | 1405 | |
paul@540 | 1406 | self.resume_abandoned_branches() |
paul@540 | 1407 | |
paul@97 | 1408 | # Establish the local for the handler. |
paul@97 | 1409 | |
paul@99 | 1410 | if var is not None: |
paul@99 | 1411 | self.dispatch(var) |
paul@99 | 1412 | if n is not None: |
paul@99 | 1413 | self.dispatch(n) |
paul@272 | 1414 | |
paul@272 | 1415 | self.shelve_branch() |
paul@272 | 1416 | |
paul@540 | 1417 | # The else clause maintains the usage from the body but without the |
paul@540 | 1418 | # abandoned branches since they would never lead to the else clause |
paul@540 | 1419 | # being executed. |
paul@540 | 1420 | |
paul@379 | 1421 | self.new_branch(node.else_ or NullBranch()) |
paul@0 | 1422 | if node.else_ is not None: |
paul@0 | 1423 | self.dispatch(node.else_) |
paul@379 | 1424 | self.shelve_branch() |
paul@272 | 1425 | |
paul@272 | 1426 | self.merge_branches() |
paul@0 | 1427 | |
paul@4 | 1428 | visitTryFinally = NOP |
paul@4 | 1429 | |
paul@82 | 1430 | visitTuple = OP |
paul@1 | 1431 | |
paul@580 | 1432 | visitUnaryAdd = _visitOperator |
paul@4 | 1433 | |
paul@580 | 1434 | visitUnarySub = _visitOperator |
paul@4 | 1435 | |
paul@34 | 1436 | def visitWhile(self, node): |
paul@462 | 1437 | self.use_name("__bool__", node) |
paul@388 | 1438 | self.new_branchpoint(node) |
paul@272 | 1439 | |
paul@275 | 1440 | # Propagate attribute usage to branches. |
paul@275 | 1441 | |
paul@331 | 1442 | in_loop = self.in_loop |
paul@591 | 1443 | self.in_loop = True |
paul@381 | 1444 | |
paul@386 | 1445 | # The test is evaluated initially and again in the loop. |
paul@381 | 1446 | |
paul@272 | 1447 | self.dispatch(node.test) |
paul@381 | 1448 | |
paul@379 | 1449 | self.new_branch(node) |
paul@272 | 1450 | self.dispatch(node.body) |
paul@388 | 1451 | |
paul@388 | 1452 | self.resume_continuing_branches() |
paul@388 | 1453 | |
paul@386 | 1454 | self.dispatch(node.test) |
paul@386 | 1455 | self.shelve_branch() |
paul@381 | 1456 | |
paul@386 | 1457 | self.in_loop = in_loop |
paul@386 | 1458 | |
paul@386 | 1459 | # A null branch is used to record a path around the loop. |
paul@381 | 1460 | |
paul@386 | 1461 | self.new_branch(node.else_ or NullBranch()) |
paul@386 | 1462 | self.shelve_branch() |
paul@385 | 1463 | |
paul@386 | 1464 | self.merge_branches() |
paul@386 | 1465 | |
paul@386 | 1466 | # The else clause is evaluated outside any branch. |
paul@385 | 1467 | |
paul@385 | 1468 | if node.else_ is not None: |
paul@385 | 1469 | self.dispatch(node.else_) |
paul@385 | 1470 | |
paul@387 | 1471 | # Any suspended branches from the loop can now be resumed. |
paul@387 | 1472 | |
paul@388 | 1473 | self.resume_broken_branches() |
paul@387 | 1474 | |
paul@4 | 1475 | visitWith = NOP |
paul@4 | 1476 | |
paul@4 | 1477 | visitYield = NOP |
paul@4 | 1478 | |
paul@0 | 1479 | # vim: tabstop=4 expandtab shiftwidth=4 |