1 #!/usr/bin/env python 2 3 """ 4 Annotate program node structures. The code in this module operates upon nodes 5 which are produced when simplifying AST node trees originating from the compiler 6 module. 7 8 Copyright (C) 2006 Paul Boddie <paul@boddie.org.uk> 9 10 This software is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public License as 12 published by the Free Software Foundation; either version 2 of 13 the License, or (at your option) any later version. 14 15 This software is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public 21 License along with this library; see the file LICENCE.txt 22 If not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 24 25 -------- 26 27 To use this module, the easiest approach is to use the annotate function: 28 29 annotate(module, builtins) 30 31 The more complicated approach involves obtaining an Annotator: 32 33 annotator = Annotator() 34 35 Then, processing an existing module with it: 36 37 annotator.process(module) 38 39 If a module containing built-in classes and functions has already been 40 annotated, such a module should be passed in as an additional argument: 41 42 annotator.process(module, builtins) 43 """ 44 45 from simplified import * 46 import compiler 47 48 class System: 49 50 """ 51 A class maintaining the state of the annotation system. When the system 52 counter can no longer be incremented by any annotation operation, the 53 system may be considered stable and fully annotated. 54 """ 55 56 def __init__(self): 57 self.count = 0 58 def init(self, node): 59 if not hasattr(node, "types"): 60 node.types = [] 61 def annotate(self, node, types): 62 self.init(node) 63 for type in types: 64 if type not in node.types: 65 node.types.append(type) 66 self.count += 1 67 68 system = System() 69 70 # Exceptions. 71 72 class AnnotationError(SimplifiedError): 73 74 "An error in the annotation process." 75 76 pass 77 78 class AnnotationMessage(Exception): 79 80 "A lesser annotation error." 81 82 pass 83 84 # Annotation. 85 86 class Annotator(Visitor): 87 88 """ 89 The type annotator which traverses the program nodes, typically depth-first, 90 and maintains a record of the current set of types applying to the currently 91 considered operation. Such types are also recorded on the nodes, and a 92 special "system" record is maintained to monitor the level of annotation 93 activity with a view to recognising when no more annotations are possible. 94 95 Throughout the annotation activity, type information consists of lists of 96 Attribute objects where such objects retain information about the context of 97 the type (since a value in the program may be associated with an object or 98 class) and the actual type of the value being manipulated. Upon accessing 99 attribute information on namespaces, additional accessor information is also 100 exchanged - this provides a means of distinguishing between the different 101 types possible when the means of constructing the namespace may depend on 102 run-time behaviour. 103 """ 104 105 def __init__(self): 106 107 "Initialise the visitor." 108 109 Visitor.__init__(self) 110 self.system = system 111 112 # Satisfy visitor issues. 113 114 self.visitor = self 115 116 def process(self, module, builtins=None): 117 118 """ 119 Process the given 'module', using the optional 'builtins' to access 120 built-in classes and functions. 121 """ 122 123 self.subprograms = [] 124 self.current_subprograms = [] 125 self.current_namespaces = [] 126 127 # Give constants their own namespace. 128 129 for value, constant in module.simplifier.constants.items(): 130 constant.namespace = Namespace() 131 132 # Process the module, supplying builtins if possible. 133 134 self.builtins = builtins 135 self.global_namespace = Namespace() 136 137 if builtins is not None: 138 self.builtins_namespace = builtins.namespace 139 else: 140 self.builtins_namespace = self.global_namespace 141 142 return self.process_node(module) 143 144 def process_node(self, node, locals=None): 145 146 """ 147 Process a subprogram or module 'node', indicating any initial 'locals'. 148 Return an annotated subprogram or module. Note that this method may 149 mutate nodes in the original program. 150 """ 151 152 # Determine the namespace. 153 154 if locals is not None: 155 self.namespace = locals 156 else: 157 self.namespace = self.global_namespace 158 159 # Record the current subprogram and namespace. 160 161 self.current_subprograms.append(node) 162 self.current_namespaces.append(self.namespace) 163 164 # Add namespace details to any structure involved. 165 166 if getattr(node, "structure", None) is not None: 167 node.structure.namespace = Namespace() 168 169 # Initialise bases where appropriate. 170 171 if hasattr(node.structure, "bases"): 172 base_refs = [] 173 for base in node.structure.bases: 174 self.dispatch(base) 175 base_refs.append(self.namespace.types) 176 node.structure.base_refs = base_refs 177 178 # Dispatch to the code itself. 179 180 node.namespace = self.namespace 181 result = self.dispatch(node) 182 result.namespace = self.namespace 183 184 # Obtain the return values. 185 186 self.last_returns = self.namespace.returns 187 self.returned_locals = self.namespace.return_locals 188 189 # Restore the previous subprogram and namespace. 190 191 self.current_namespaces.pop() 192 if self.current_namespaces: 193 self.namespace = self.current_namespaces[-1] 194 195 self.current_subprograms.pop() 196 197 return result 198 199 def annotate(self, node, types=None): 200 201 """ 202 Annotate the given 'node' in the system, using either the optional 203 'types' or the namespace's current type information. 204 """ 205 206 self.system.annotate(node, types or self.namespace.types) 207 208 # Visitor methods. 209 210 def default(self, node): 211 212 """ 213 Process the given 'node', given that it does not have a specific 214 handler. 215 """ 216 217 for attr in ("expr", "lvalue", "test", "handler"): 218 value = getattr(node, attr, None) 219 if value is not None: 220 setattr(node, attr, self.dispatch(value)) 221 for attr in ("body", "else_", "finally_", "code"): 222 value = getattr(node, attr, None) 223 if value is not None: 224 setattr(node, attr, self.dispatches(value)) 225 return node 226 227 def dispatch(self, node, *args): 228 try: 229 return Visitor.dispatch(self, node, *args) 230 except AnnotationError, exc: 231 exc.add(node) 232 raise 233 except AnnotationMessage, exc: 234 raise AnnotationError(exc, node) 235 236 def visitLoadRef(self, loadref): 237 self.namespace.set_types([Attribute(None, loadref.ref)]) 238 self.annotate(loadref) 239 return loadref 240 241 def visitLoadName(self, loadname): 242 self.namespace.set_types(self.namespace.load(loadname.name)) 243 result = loadname 244 self.annotate(result) 245 return result 246 247 def visitStoreName(self, storename): 248 storename.expr = self.dispatch(storename.expr) 249 self.namespace.store(storename.name, self.namespace.types) 250 return storename 251 252 def visitLoadTemp(self, loadtemp): 253 index = getattr(loadtemp, "index", None) 254 try: 255 if getattr(loadtemp, "release", 0): 256 self.namespace.set_types(self.namespace.temp[index].pop()) 257 else: 258 self.namespace.set_types(self.namespace.temp[index][-1]) 259 except KeyError: 260 raise AnnotationMessage, "Temporary store index '%s' not defined." % index 261 self.annotate(loadtemp) 262 return loadtemp 263 264 def visitStoreTemp(self, storetemp): 265 storetemp.expr = self.dispatch(storetemp.expr) 266 index = getattr(storetemp, "index", None) 267 if not self.namespace.temp.has_key(index): 268 self.namespace.temp[index] = [] 269 self.namespace.temp[index].append(self.namespace.types) 270 return storetemp 271 272 def visitReleaseTemp(self, releasetemp): 273 index = getattr(releasetemp, "index", None) 274 try: 275 self.namespace.temp[index].pop() 276 except KeyError: 277 raise AnnotationMessage, "Temporary store index '%s' not defined." % index 278 except IndexError: 279 pass #raise AnnotationMessage, "Temporary store index '%s' is empty." % index 280 return releasetemp 281 282 def visitLoadAttr(self, loadattr): 283 loadattr.expr = self.dispatch(loadattr.expr) 284 types = [] 285 accesses = {} 286 non_accesses = {} 287 for attr in self.namespace.types: 288 for attribute, accessor in get_attributes(attr.type, loadattr.name): 289 if attribute is not None: 290 types.append(attribute) 291 if not accesses.has_key(attr.type): 292 accesses[attr.type] = [] 293 if not (attribute, accessor) in accesses[attr.type]: 294 accesses[attr.type].append((attribute, accessor)) 295 else: 296 print "Empty attribute", loadattr.name, "via accessor", accessor 297 if not non_accesses.has_key(attr.type): 298 non_accesses[attr.type] = [] 299 if not (attribute, accessor) in non_accesses[attr.type]: 300 non_accesses[attr.type].append((attribute, accessor)) 301 self.namespace.set_types(types) 302 loadattr.accesses = accesses 303 loadattr.non_accesses = non_accesses 304 self.annotate(loadattr) 305 return loadattr 306 307 def visitStoreAttr(self, storeattr): 308 storeattr.expr = self.dispatch(storeattr.expr) 309 expr = self.namespace.types 310 storeattr.lvalue = self.dispatch(storeattr.lvalue) 311 writes = {} 312 for attr in self.namespace.types: 313 if attr is None: 314 print "Empty attribute storage attempt" 315 continue 316 attr.type.namespace.store(storeattr.name, expr) 317 writes[attr.type] = attr.type.namespace.load(storeattr.name) 318 storeattr.writes = writes 319 return storeattr 320 321 def visitConditional(self, conditional): 322 323 # Conditionals keep local namespace changes isolated. 324 # With Return nodes inside the body/else sections, the changes are 325 # communicated to the caller. 326 327 conditional.test = self.dispatch(conditional.test) 328 saved_namespace = self.namespace 329 330 self.namespace = Namespace() 331 self.namespace.merge_namespace(saved_namespace) 332 conditional.body = self.dispatches(conditional.body) 333 body_namespace = self.namespace 334 335 self.namespace = Namespace() 336 self.namespace.merge_namespace(saved_namespace) 337 conditional.else_ = self.dispatches(conditional.else_) 338 else_namespace = self.namespace 339 340 self.namespace = Namespace() 341 self.namespace.merge_namespace(body_namespace) 342 self.namespace.merge_namespace(else_namespace) 343 344 return conditional 345 346 def visitReturn(self, return_): 347 if hasattr(return_, "expr"): 348 return_.expr = self.dispatch(return_.expr) 349 combine(self.namespace.returns, self.namespace.types) 350 self.annotate(return_) 351 self.namespace.snapshot() 352 return return_ 353 354 def visitInvoke(self, invoke): 355 356 # First find the callables. 357 358 invoke.expr = self.dispatch(invoke.expr) 359 invocation_types = self.namespace.types 360 361 # Invocation processing starts with making sure that the arguments have 362 # been processed. 363 364 if isinstance(invoke, InvokeFunction): 365 self.process_args(invoke) 366 367 # Now locate and invoke the subprogram. This can be complicated because 368 # the target may be a class or object, and there may be many different 369 # related subprograms. 370 371 invocations = [] 372 373 # Visit each callable in turn, finding subprograms. 374 375 for attr in invocation_types: 376 377 # Deal with class invocations by providing instance objects. 378 # Here, each class is queried for the __init__ method, which may 379 # exist for some combinations of classes in a hierarchy but not for 380 # others. 381 382 if isinstance(attr.type, Class): 383 attributes = get_attributes(attr.type, "__init__") 384 385 # Deal with object invocations by using __call__ methods. 386 387 elif isinstance(attr.type, Instance): 388 attributes = get_attributes(attr.type, "__call__") 389 390 # Normal functions or methods are more straightforward. 391 # Here, we model them using an attribute with no context and with 392 # no associated accessor. 393 394 else: 395 attributes = [(attr, None)] 396 397 # Inspect each attribute and extract the subprogram. 398 399 for attribute, accessor in attributes: 400 401 # If a class is involved, presume that it must create a new 402 # object. 403 404 if isinstance(attr.type, Class): 405 406 # Instantiate the class. 407 # NOTE: Should probably only allocate a single instance. 408 409 instance = self.new_instance(invoke, "new", attr.type.full_name(), attr.type) 410 411 # For instantiations, switch the context. 412 413 if attribute is not None: 414 attribute = Attribute(instance, attribute.type) 415 416 # Skip cases where no callable is found. 417 418 if attribute is not None: 419 420 # If a subprogram is defined, invoke it. 421 422 self.invoke_subprogram(invoke, attribute) 423 if attribute.type not in invocations: 424 invocations.append(attribute.type) 425 426 elif not isinstance(attr.type, Class): 427 print "Invocation type is None for", accessor 428 429 # Special case: initialisation. 430 431 if isinstance(attr.type, Class): 432 433 # Associate the instance with the result of this invocation. 434 435 self.namespace.set_types([Attribute(None, instance)]) 436 self.annotate(invoke) 437 438 # Remember the invocations that were found, along with the return type 439 # information. 440 441 invoke.invocations = invocations 442 self.namespace.set_types(getattr(invoke, "types", [])) 443 return invoke 444 445 visitInvokeFunction = visitInvoke 446 visitInvokeBlock = visitInvoke 447 448 # Utility methods. 449 450 def new_instance(self, node, reason, target, type): 451 452 "Create, on the given 'node', a new instance with the given 'type'." 453 454 if not hasattr(node, "instances"): 455 node.instances = {} 456 457 if not node.instances.has_key((reason, target, type)): 458 459 # Insist on a single instance per type. 460 # NOTE: Strategy-dependent instantiation. 461 462 if len(type.instances) == 0: 463 instance = Instance() 464 instance.namespace = Namespace() 465 instance.namespace.store("__class__", [Attribute(None, type)]) 466 type.instances.append(instance) 467 else: 468 instance = type.instances[0] 469 470 node.instances[(reason, target, type)] = instance 471 472 return node.instances[(reason, target, type)] 473 474 def invoke_subprogram(self, invoke, subprogram): 475 476 "Invoke using the given 'invoke' node the given 'subprogram'." 477 478 # Test to see if anything has changed. 479 480 if hasattr(invoke, "syscount") and invoke.syscount == self.system.count: 481 return 482 483 # Remember the state of the system. 484 485 else: 486 invoke.syscount = self.system.count 487 488 # Test for context information, making it into a real attribute. 489 490 if subprogram.context is not None: 491 context = Attribute(None, subprogram.context) 492 target = subprogram.type 493 else: 494 context = None 495 target = subprogram.type 496 497 # Provide the correct namespace for the invocation. 498 499 if isinstance(invoke, InvokeBlock): 500 namespace = Namespace() 501 namespace.merge_namespace(self.namespace) 502 else: 503 items = self.make_items(invoke, target, context) 504 namespace = self.make_namespace(items) 505 506 # Process the subprogram. 507 508 self.process_node(target, namespace) 509 510 # NOTE: Improve and verify this. 511 # If the invocation returns a value, acquire the return types. 512 513 if getattr(target, "returns_value", 0): 514 self.namespace.set_types(self.last_returns) 515 self.annotate(invoke) 516 517 # Otherwise, if it is a normal block, merge the locals. 518 519 elif isinstance(invoke, InvokeBlock): 520 for locals in self.returned_locals: 521 self.namespace.merge_namespace(locals) 522 523 def process_args(self, invocation): 524 525 "Process the arguments associated with an 'invocation'." 526 527 invocation.pos_args = self.dispatches(invocation.pos_args) 528 invocation.kw_args = self.dispatch_dict(invocation.kw_args) 529 530 # Get type information for star and dstar arguments. 531 532 if invocation.star is not None: 533 param, default = invocation.star 534 default = self.dispatch(default) 535 invocation.star = param, default 536 537 if invocation.dstar is not None: 538 param, default = invocation.dstar 539 default = self.dispatch(default) 540 invocation.dstar = param, default 541 542 def make_items(self, invocation, subprogram, context): 543 544 """ 545 Make an items mapping for the 'invocation' of the 'subprogram' using the 546 given 'context' (which may be None). 547 """ 548 549 if context is not None: 550 pos_args = [Self(context)] + invocation.pos_args 551 else: 552 pos_args = invocation.pos_args 553 kw_args = invocation.kw_args 554 555 # Sort the arguments into positional and keyword arguments. 556 557 params = subprogram.params 558 items = [] 559 star_args = [] 560 561 # Match each positional argument, taking excess arguments as star args. 562 563 for arg in pos_args: 564 if params: 565 param, default = params[0] 566 if arg is None: 567 arg = default 568 items.append((param, arg.types)) 569 params = params[1:] 570 else: 571 star_args.append(arg) 572 573 # Collect the remaining defaults. 574 575 while params: 576 param, default = params[0] 577 if kw_args.has_key(param): 578 arg = kw_args[param] 579 del kw_args[param] 580 elif default is not None: 581 arg = self.dispatch(default) 582 else: 583 raise AnnotationMessage, "No argument supplied in '%s' for parameter '%s'." % (subprogram, param) 584 items.append((param, arg.types)) 585 params = params[1:] 586 587 dstar_args = kw_args.values() 588 589 # Construct temporary objects. 590 591 if star_args: 592 star_invocation = self.make_star_args(invocation, subprogram, star_args) 593 self.dispatch(star_invocation) 594 star_types = star_invocation.types 595 else: 596 star_types = None 597 598 if dstar_args: 599 dstar_invocation = self.make_dstar_args(invocation, subprogram, dstar_args) # NOTE: To be written! 600 self.dispatch(dstar_invocation) 601 dstar_types = dstar_invocation.types 602 else: 603 dstar_types = None 604 605 # NOTE: Merge the objects properly. 606 607 star_types = star_types or invocation.star and invocation.star.types 608 dstar_types = dstar_types or invocation.dstar and invocation.dstar.types 609 610 # Add star and dstar. 611 612 if star_types is not None: 613 if subprogram.star is not None: 614 param, default = subprogram.star 615 items.append((param, star_types)) 616 else: 617 raise AnnotationMessage, "Invocation provides unwanted *args." 618 elif subprogram.star is not None: 619 param, default = subprogram.star 620 arg = self.dispatch(default) # NOTE: Review reprocessing. 621 items.append((param, arg.types)) 622 623 if dstar_types is not None: 624 if subprogram.dstar is not None: 625 param, default = subprogram.dstar 626 items.append((param, dstar_types)) 627 else: 628 raise AnnotationMessage, "Invocation provides unwanted **args." 629 elif subprogram.dstar is not None: 630 param, default = subprogram.dstar 631 arg = self.dispatch(default) # NOTE: Review reprocessing. 632 items.append((param, arg.types)) 633 634 # Record the parameter types. 635 636 subprogram.paramtypes = {} 637 for param, types in items: 638 subprogram.paramtypes[param] = types 639 640 return items 641 642 def make_star_args(self, invocation, subprogram, star_args): 643 644 "Make a subprogram which initialises a list containing 'star_args'." 645 646 if not hasattr(invocation, "stars"): 647 invocation.stars = {} 648 649 if not invocation.stars.has_key(subprogram.full_name()): 650 code=[ 651 StoreTemp( 652 expr=InvokeFunction( 653 expr=LoadAttr( 654 expr=LoadRef( 655 ref=self.builtins 656 ), 657 name="list", 658 nstype="module", 659 ), 660 args=[], 661 star=None, 662 dstar=None 663 ) 664 ) 665 ] 666 667 for arg in star_args: 668 code.append( 669 InvokeFunction( 670 expr=LoadAttr( 671 expr=LoadTemp(), 672 name="append" 673 ), 674 args=[arg], 675 star=None, 676 dstar=None 677 ) 678 ) 679 680 code += [ 681 Return(expr=LoadTemp(release=1)) 682 ] 683 684 invocation.stars[subprogram.full_name()] = InvokeBlock( 685 produces_result=1, 686 expr=LoadRef( 687 ref=Subprogram( 688 name=None, 689 returns_value=1, 690 params=[], 691 star=None, 692 dstar=None, 693 code=code 694 ) 695 ) 696 ) 697 698 return invocation.stars[subprogram.full_name()] 699 700 def make_namespace(self, items): 701 namespace = Namespace() 702 namespace.merge_items(items) 703 return namespace 704 705 # Namespace-related abstractions. 706 707 class Namespace: 708 709 """ 710 A local namespace which may either relate to a genuine set of function 711 locals or the initialisation of a structure or module. 712 """ 713 714 def __init__(self): 715 716 """ 717 Initialise the namespace with a mapping of local names to possible 718 types, a list of return values and of possible returned local 719 namespaces. The namespace also tracks the "current" types and a mapping 720 of temporary value names to types. 721 """ 722 723 self.names = {} 724 self.returns = [] 725 self.return_locals = [] 726 self.temp = {} 727 self.types = [] 728 729 def set_types(self, types): 730 self.types = types 731 732 def store(self, name, types): 733 self.names[name] = types 734 735 __setitem__ = store 736 737 def load(self, name): 738 return self.names[name] 739 740 __getitem__ = load 741 742 def merge_namespace(self, namespace): 743 self.merge_items(namespace.names.items()) 744 combine(self.returns, namespace.returns) 745 self.temp = namespace.temp 746 747 def merge_items(self, items): 748 for name, types in items: 749 self.merge(name, types) 750 751 def merge(self, name, types): 752 if not self.names.has_key(name): 753 self.names[name] = types[:] 754 else: 755 existing = self.names[name] 756 combine(existing, types) 757 758 def snapshot(self): 759 760 "Make a snapshot of the locals and remember them." 761 762 namespace = Namespace() 763 namespace.merge_namespace(self) 764 self.return_locals.append(namespace) 765 766 def __repr__(self): 767 return repr(self.names) 768 769 class Attribute: 770 771 """ 772 An attribute abstraction, indicating the type of the attribute along with 773 its context or origin. 774 """ 775 776 def __init__(self, context, type): 777 self.context = context 778 self.type = type 779 780 def __eq__(self, other): 781 return hasattr(other, "type") and other.type == self.type or other == self.type 782 783 def __repr__(self): 784 return "Attribute(%s, %s)" % (repr(self.context), repr(self.type)) 785 786 class Self: 787 788 "A node encapsulating object/context information in an argument list." 789 790 def __init__(self, attribute): 791 self.types = [attribute] 792 793 def combine(target, additions): 794 795 """ 796 Merge into the 'target' sequence the given 'additions', preventing duplicate 797 items. 798 """ 799 800 for addition in additions: 801 if addition not in target: 802 target.append(addition) 803 804 def find_attributes(structure, name): 805 806 """ 807 Find for the given 'structure' all attributes for the given 'name', visiting 808 base classes where appropriate and returning the attributes in order of 809 descending precedence for all possible base classes. 810 811 The elements in the result list are 2-tuples which contain the attribute and 812 the structure involved in accessing the attribute. 813 """ 814 815 # First attempt to search the instance/class namespace. 816 817 try: 818 l = structure.namespace.load(name) 819 attributes = [] 820 for attribute in l: 821 attributes.append((attribute, structure)) 822 823 # If that does not work, attempt to investigate any class or base classes. 824 825 except KeyError: 826 attributes = [] 827 828 # Investigate any instance's implementing class. 829 830 if isinstance(structure, Instance): 831 for attr in structure.namespace.load("__class__"): 832 cls = attr.type 833 l = get_attributes(cls, name) 834 combine(attributes, l) 835 836 # Investigate any class's base classes. 837 838 elif isinstance(structure, Class): 839 840 # If no base classes exist, return an indicator that no attribute 841 # exists. 842 843 if not structure.base_refs: 844 return [(None, structure)] 845 846 # Otherwise, find all possible base classes. 847 848 for base_refs in structure.base_refs: 849 base_attributes = [] 850 851 # For each base class, find attributes either in the base 852 # class or its own base classes. 853 854 for base_ref in base_refs: 855 l = get_attributes(base_ref, name) 856 combine(base_attributes, l) 857 858 combine(attributes, base_attributes) 859 860 return attributes 861 862 def get_attributes(structure, name): 863 864 """ 865 Return all possible attributes for the given 'structure' having the given 866 'name', wrapping each attribute in an Attribute object which includes 867 context information for the attribute access. 868 869 The elements in the result list are 2-tuples which contain the attribute and 870 the structure involved in accessing the attribute. 871 """ 872 873 if isinstance(structure, Attribute): 874 structure = structure.type 875 results = [] 876 for attribute, accessor in find_attributes(structure, name): 877 if attribute is not None and isinstance(structure, Structure): 878 results.append((Attribute(structure, attribute.type), accessor)) 879 else: 880 results.append((attribute, accessor)) 881 return results 882 883 # Convenience functions. 884 885 def annotate(module, builtins=None): 886 887 """ 888 Annotate the given 'module', also employing the optional 'builtins' module, 889 if specified. 890 """ 891 892 annotator = Annotator() 893 if builtins is not None: 894 annotator.process(module, builtins) 895 else: 896 annotator.process(module) 897 898 def annotate_all(modules, builtins): 899 annotate(builtins) 900 for module in modules: 901 annotate(module, builtins) 902 903 # vim: tabstop=4 expandtab shiftwidth=4