paulb@31 | 1 | #!/usr/bin/env python |
paulb@31 | 2 | |
paulb@31 | 3 | """ |
paulb@47 | 4 | Fix name-related operations. The code in this module operates upon simplified |
paulb@47 | 5 | program node trees. |
paulb@31 | 6 | |
paulb@254 | 7 | Copyright (C) 2006, 2007 Paul Boddie <paul@boddie.org.uk> |
paulb@31 | 8 | |
paulb@260 | 9 | This program is free software; you can redistribute it and/or modify it under |
paulb@260 | 10 | the terms of the GNU General Public License as published by the Free Software |
paulb@260 | 11 | Foundation; either version 3 of the License, or (at your option) any later |
paulb@260 | 12 | version. |
paulb@31 | 13 | |
paulb@260 | 14 | This program is distributed in the hope that it will be useful, but WITHOUT |
paulb@260 | 15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paulb@260 | 16 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paulb@260 | 17 | details. |
paulb@31 | 18 | |
paulb@260 | 19 | You should have received a copy of the GNU General Public License along with |
paulb@260 | 20 | this program. If not, see <http://www.gnu.org/licenses/>. |
paulb@46 | 21 | |
paulb@46 | 22 | -------- |
paulb@46 | 23 | |
paulb@57 | 24 | To use this module, the easiest approach is to use the fix function: |
paulb@57 | 25 | |
paulb@57 | 26 | fix(module) |
paulb@57 | 27 | |
paulb@57 | 28 | The more complicated approach involves instantiating a Fixer object: |
paulb@46 | 29 | |
paulb@46 | 30 | fixer = Fixer() |
paulb@46 | 31 | |
paulb@57 | 32 | Then, applying the fixer to an existing module: |
paulb@46 | 33 | |
paulb@57 | 34 | fixer.process(module) |
paulb@46 | 35 | |
paulb@57 | 36 | If a module containing built-in classes and functions exists, apply the fixer as |
paulb@57 | 37 | follows: |
paulb@46 | 38 | |
paulb@57 | 39 | fixer.process(module, builtins) |
paulb@31 | 40 | """ |
paulb@31 | 41 | |
paulb@220 | 42 | from simplify.simplified import * |
paulb@31 | 43 | |
paulb@31 | 44 | # Fixing of name-related operations. |
paulb@31 | 45 | |
paulb@31 | 46 | class Fixer(Visitor): |
paulb@31 | 47 | |
paulb@31 | 48 | """ |
paulb@47 | 49 | The name fixer which traverses the program nodes in a module, typically |
paulb@47 | 50 | depth-first, and maintains a record of name usage in the different |
paulb@47 | 51 | namespaces. As a consequence of various observations, some parts of the |
paulb@47 | 52 | program node tree are modified with different operations employed to those |
paulb@47 | 53 | originally defined. |
paulb@47 | 54 | |
paulb@47 | 55 | There are two kinds of subprograms in modules: functions/methods and |
paulb@47 | 56 | internal subprograms which support things like loops. The latter kind of |
paulb@47 | 57 | subprogram may acquire the locals from their callers and must therefore be |
paulb@47 | 58 | traversed with information from such callers. Thus, we choose the top-level |
paulb@47 | 59 | code and all functions/methods as roots for processing, following |
paulb@47 | 60 | invocations of internal subprograms in order to reach all subprograms that |
paulb@47 | 61 | are defined in each module. |
paulb@47 | 62 | |
paulb@47 | 63 | top-level |
paulb@47 | 64 | ... |
paulb@47 | 65 | invoke function |
paulb@47 | 66 | ... |
paulb@47 | 67 | invoke loop -> subprogram (internal) |
paulb@47 | 68 | ... |
paulb@47 | 69 | |
paulb@47 | 70 | subprogram (function) |
paulb@47 | 71 | ... |
paulb@47 | 72 | invoke loop -> subprogram (internal) |
paulb@47 | 73 | ... |
paulb@47 | 74 | |
paulb@47 | 75 | ... |
paulb@47 | 76 | |
paulb@47 | 77 | The above approach should guarantee that all subprograms are traversed and |
paulb@47 | 78 | that all name lookups are correctly categorised. |
paulb@31 | 79 | """ |
paulb@31 | 80 | |
paulb@31 | 81 | def __init__(self): |
paulb@45 | 82 | |
paulb@45 | 83 | "Initialise the name fixer." |
paulb@45 | 84 | |
paulb@31 | 85 | Visitor.__init__(self) |
paulb@31 | 86 | |
paulb@31 | 87 | # Satisfy visitor issues. |
paulb@31 | 88 | |
paulb@31 | 89 | self.visitor = self |
paulb@31 | 90 | |
paulb@57 | 91 | def process(self, module, builtins=None): |
paulb@45 | 92 | |
paulb@46 | 93 | """ |
paulb@57 | 94 | Process the given 'module' optionally using some 'builtins' to reference |
paulb@57 | 95 | built-in objects. |
paulb@46 | 96 | """ |
paulb@45 | 97 | |
paulb@47 | 98 | # The fixer maintains a list of transformed subprograms (added for each |
paulb@47 | 99 | # of the processing "roots" and also for each invoked internal |
paulb@47 | 100 | # subprogram), along with a list of current subprograms (used to avoid |
paulb@47 | 101 | # recursion issues) and a list of current namespaces (used to recall |
paulb@47 | 102 | # namespaces upon invoking internal subprograms). |
paulb@47 | 103 | |
paulb@263 | 104 | self.subprograms = set() |
paulb@45 | 105 | self.current_subprograms = [] |
paulb@45 | 106 | self.current_namespaces = [] |
paulb@45 | 107 | |
paulb@45 | 108 | # First, process the top-level code, finding out which names are |
paulb@45 | 109 | # defined at that level. |
paulb@45 | 110 | |
paulb@45 | 111 | self.global_namespace = None |
paulb@57 | 112 | self.module = module |
paulb@165 | 113 | self.builtins = builtins or module |
paulb@47 | 114 | |
paulb@57 | 115 | self.process_node(self.module) |
paulb@45 | 116 | |
paulb@45 | 117 | # Then, process all functions and methods, providing a global namespace. |
paulb@47 | 118 | # By setting a global namespace, we influence the resolution of names: |
paulb@47 | 119 | # those which are global to the top-level module (processed above) are |
paulb@47 | 120 | # considered as built-in names, whereas those which are global to a |
paulb@47 | 121 | # function or method are searched for in the global namespace. |
paulb@45 | 122 | |
paulb@45 | 123 | self.global_namespace = self.namespace |
paulb@45 | 124 | |
paulb@57 | 125 | for subprogram in self.module.simplifier.subprograms: |
paulb@45 | 126 | |
paulb@45 | 127 | # Internal subprograms are skipped here and processed specially via |
paulb@45 | 128 | # Invoke nodes. |
paulb@45 | 129 | |
paulb@269 | 130 | if not subprogram.internal: |
paulb@263 | 131 | self.subprograms.add(self.process_node(subprogram)) |
paulb@45 | 132 | |
paulb@47 | 133 | # Ultimately, we redefine the list of subprograms on the visitor. |
paulb@47 | 134 | |
paulb@57 | 135 | self.module.simplifier.subprograms = self.subprograms |
paulb@57 | 136 | return self.module |
paulb@31 | 137 | |
paulb@45 | 138 | def process_node(self, node, namespace=None): |
paulb@31 | 139 | |
paulb@31 | 140 | """ |
paulb@43 | 141 | Process a subprogram or module 'node', discovering from attributes on |
paulb@43 | 142 | 'node' any initial locals. Return a modified subprogram or module. |
paulb@31 | 143 | """ |
paulb@31 | 144 | |
paulb@45 | 145 | # Do not process subprograms already being processed. |
paulb@45 | 146 | |
paulb@45 | 147 | if node in self.current_subprograms: |
paulb@45 | 148 | return None |
paulb@45 | 149 | |
paulb@31 | 150 | # Obtain a namespace either based on locals or on a structure. |
paulb@31 | 151 | |
paulb@269 | 152 | structure = node.structure |
paulb@210 | 153 | |
paulb@210 | 154 | # If passed some namespace, use that as the current namespace. |
paulb@210 | 155 | |
paulb@210 | 156 | if namespace is not None: |
paulb@210 | 157 | self.namespace.merge_namespace(namespace) |
paulb@210 | 158 | else: |
paulb@210 | 159 | self.namespace = NameOrganiser(structure) |
paulb@45 | 160 | |
paulb@45 | 161 | # Record the current subprogram and namespace. |
paulb@45 | 162 | |
paulb@45 | 163 | self.current_subprograms.append(node) |
paulb@45 | 164 | self.current_namespaces.append(self.namespace) |
paulb@45 | 165 | |
paulb@169 | 166 | # NOTE: Avoid PEP 227 (nested scopes) whilst permitting references to a |
paulb@172 | 167 | # NOTE: subprogram within itself. Do not define the name of the function |
paulb@172 | 168 | # NOTE: within a method definition. |
paulb@169 | 169 | |
paulb@269 | 170 | if isinstance(node, Subprogram) and node.name is not None and not node.is_method: |
paulb@169 | 171 | self.namespace.store(node.name) |
paulb@169 | 172 | |
paulb@47 | 173 | # Register the names of parameters in the namespace. |
paulb@43 | 174 | |
paulb@269 | 175 | if node.params: |
paulb@52 | 176 | new_params = [] |
paulb@43 | 177 | for param, default in node.params: |
paulb@52 | 178 | new_params.append((param, self.dispatch(default))) |
paulb@43 | 179 | self.namespace.store(param) |
paulb@52 | 180 | node.params = new_params |
paulb@269 | 181 | if node.star: |
paulb@45 | 182 | param, default = node.star |
paulb@43 | 183 | self.namespace.store(param) |
paulb@52 | 184 | node.star = param, self.dispatch(default) |
paulb@269 | 185 | if node.dstar: |
paulb@45 | 186 | param, default = node.dstar |
paulb@43 | 187 | self.namespace.store(param) |
paulb@52 | 188 | node.dstar = param, self.dispatch(default) |
paulb@43 | 189 | |
paulb@31 | 190 | # Add namespace details to any structure involved. |
paulb@31 | 191 | |
paulb@269 | 192 | if node.structure is not None: |
paulb@31 | 193 | |
paulb@31 | 194 | # Initialise bases where appropriate. |
paulb@31 | 195 | |
paulb@31 | 196 | if hasattr(node.structure, "bases"): |
paulb@31 | 197 | bases = [] |
paulb@31 | 198 | for base in node.structure.bases: |
paulb@31 | 199 | bases.append(self.dispatch(base)) |
paulb@31 | 200 | node.structure.bases = bases |
paulb@31 | 201 | |
paulb@31 | 202 | # Dispatch to the code itself. |
paulb@31 | 203 | |
paulb@31 | 204 | result = self.dispatch(node) |
paulb@47 | 205 | result.organiser = self.namespace |
paulb@45 | 206 | |
paulb@45 | 207 | # Restore the previous subprogram and namespace. |
paulb@45 | 208 | |
paulb@45 | 209 | self.current_namespaces.pop() |
paulb@45 | 210 | if self.current_namespaces: |
paulb@45 | 211 | self.namespace = self.current_namespaces[-1] |
paulb@45 | 212 | self.current_subprograms.pop() |
paulb@45 | 213 | |
paulb@31 | 214 | return result |
paulb@31 | 215 | |
paulb@31 | 216 | # Visitor methods. |
paulb@31 | 217 | |
paulb@31 | 218 | def default(self, node): |
paulb@31 | 219 | |
paulb@31 | 220 | """ |
paulb@31 | 221 | Process the given 'node', given that it does not have a specific |
paulb@31 | 222 | handler. |
paulb@31 | 223 | """ |
paulb@31 | 224 | |
paulb@98 | 225 | for attr in ("pos_args",): |
paulb@31 | 226 | value = getattr(node, attr, None) |
paulb@31 | 227 | if value is not None: |
paulb@31 | 228 | setattr(node, attr, self.dispatches(value)) |
paulb@98 | 229 | for attr in ("kw_args",): |
paulb@98 | 230 | value = getattr(node, attr, None) |
paulb@98 | 231 | if value is not None: |
paulb@98 | 232 | setattr(node, attr, self.dispatch_dict(value)) |
paulb@36 | 233 | for attr in ("expr", "lvalue", "test", "star", "dstar"): |
paulb@31 | 234 | value = getattr(node, attr, None) |
paulb@31 | 235 | if value is not None: |
paulb@31 | 236 | setattr(node, attr, self.dispatch(value)) |
paulb@219 | 237 | for attr in ("body", "else_", "handler", "finally_", "code", "choices", "nodes"): |
paulb@31 | 238 | value = getattr(node, attr, None) |
paulb@31 | 239 | if value is not None: |
paulb@31 | 240 | setattr(node, attr, self.dispatches(value)) |
paulb@31 | 241 | return node |
paulb@31 | 242 | |
paulb@31 | 243 | def visitGlobal(self, global_): |
paulb@31 | 244 | for name in global_.names: |
paulb@31 | 245 | self.namespace.make_global(name) |
paulb@31 | 246 | return global_ |
paulb@31 | 247 | |
paulb@31 | 248 | def visitLoadName(self, loadname): |
paulb@45 | 249 | |
paulb@45 | 250 | "Transform the 'loadname' node to a specific, scope-sensitive node." |
paulb@45 | 251 | |
paulb@47 | 252 | scope = self.namespace.find_for_load(loadname.name) |
paulb@45 | 253 | |
paulb@45 | 254 | # For structure namespaces, load an attribute. |
paulb@45 | 255 | |
paulb@31 | 256 | if scope == "structure": |
paulb@63 | 257 | result = self.dispatch( |
paulb@79 | 258 | LoadAttr(loadname.original, loadname.defining, |
paulb@63 | 259 | expr=LoadRef(loadname.original, |
paulb@63 | 260 | ref=self.namespace.structure), |
paulb@63 | 261 | name=loadname.name, |
paulb@63 | 262 | nstype="structure") |
paulb@63 | 263 | ) |
paulb@45 | 264 | |
paulb@45 | 265 | # For global accesses (ie. those outside the local namespace)... |
paulb@45 | 266 | |
paulb@31 | 267 | elif scope == "global": |
paulb@45 | 268 | |
paulb@45 | 269 | # Where a distinct global namespace exists, examine it. |
paulb@45 | 270 | |
paulb@45 | 271 | if self.global_namespace is not None: |
paulb@47 | 272 | scope = self.global_namespace.find_for_load(loadname.name) |
paulb@45 | 273 | |
paulb@45 | 274 | # Where the name is outside the global namespace, it must be a |
paulb@45 | 275 | # built-in. |
paulb@45 | 276 | |
paulb@45 | 277 | if scope == "global": |
paulb@63 | 278 | result = self.dispatch( |
paulb@79 | 279 | LoadAttr(loadname.original, loadname.defining, |
paulb@63 | 280 | expr=LoadRef(loadname.original, |
paulb@63 | 281 | ref=self.builtins), |
paulb@63 | 282 | name=loadname.name, |
paulb@63 | 283 | nstype="module") |
paulb@63 | 284 | ) |
paulb@45 | 285 | |
paulb@45 | 286 | # Otherwise, it is within the global namespace and must be a |
paulb@45 | 287 | # global. |
paulb@45 | 288 | |
paulb@45 | 289 | else: |
paulb@63 | 290 | result = self.dispatch( |
paulb@79 | 291 | LoadAttr(loadname.original, loadname.defining, |
paulb@63 | 292 | expr=LoadRef(loadname.original, |
paulb@63 | 293 | ref=self.module), |
paulb@63 | 294 | name=loadname.name, |
paulb@63 | 295 | nstype="module") |
paulb@63 | 296 | ) |
paulb@45 | 297 | |
paulb@45 | 298 | # Where no global namespace exists, we are at the module level and |
paulb@45 | 299 | # must be accessing a built-in. |
paulb@45 | 300 | |
paulb@45 | 301 | else: |
paulb@63 | 302 | result = self.dispatch( |
paulb@79 | 303 | LoadAttr(loadname.original, loadname.defining, |
paulb@63 | 304 | expr=LoadRef(loadname.original, |
paulb@63 | 305 | ref=self.builtins), |
paulb@63 | 306 | name=loadname.name, |
paulb@63 | 307 | nstype="module") |
paulb@63 | 308 | ) |
paulb@45 | 309 | |
paulb@45 | 310 | # For local accesses... |
paulb@45 | 311 | |
paulb@31 | 312 | else: |
paulb@45 | 313 | |
paulb@45 | 314 | # Where a distinct global namespace exists, it must be a local. |
paulb@45 | 315 | |
paulb@45 | 316 | if self.global_namespace is not None: |
paulb@45 | 317 | result = loadname |
paulb@45 | 318 | |
paulb@45 | 319 | # Otherwise, we must be accessing a global (which is local at the |
paulb@45 | 320 | # module level). |
paulb@45 | 321 | |
paulb@45 | 322 | else: |
paulb@63 | 323 | result = self.dispatch( |
paulb@79 | 324 | LoadAttr(loadname.original, loadname.defining, |
paulb@63 | 325 | expr=LoadRef(loadname.original, |
paulb@63 | 326 | ref=self.module), |
paulb@63 | 327 | name=loadname.name, |
paulb@63 | 328 | nstype="module") |
paulb@63 | 329 | ) |
paulb@45 | 330 | |
paulb@31 | 331 | return result |
paulb@31 | 332 | |
paulb@31 | 333 | def visitStoreName(self, storename): |
paulb@45 | 334 | |
paulb@45 | 335 | "Transform the 'storename' node to a specific, scope-sensitive node." |
paulb@45 | 336 | |
paulb@47 | 337 | scope = self.namespace.find_for_store(storename.name) |
paulb@45 | 338 | |
paulb@45 | 339 | # For structure namespaces, store an attribute. |
paulb@45 | 340 | |
paulb@31 | 341 | if scope == "structure": |
paulb@164 | 342 | self.namespace.store(storename.name) |
paulb@164 | 343 | |
paulb@63 | 344 | return self.dispatch( |
paulb@79 | 345 | StoreAttr(storename.original, storename.defining, |
paulb@63 | 346 | lvalue=LoadRef(storename.original, |
paulb@63 | 347 | ref=self.namespace.structure), |
paulb@63 | 348 | name=storename.name, |
paulb@63 | 349 | expr=storename.expr, |
paulb@63 | 350 | nstype="structure") |
paulb@63 | 351 | ) |
paulb@45 | 352 | |
paulb@45 | 353 | # Where the name is outside the local namespace, disallow any built-in |
paulb@45 | 354 | # assignment and store the name globally. |
paulb@45 | 355 | |
paulb@31 | 356 | elif scope == "global": |
paulb@63 | 357 | return self.dispatch( |
paulb@79 | 358 | StoreAttr(storename.original, storename.defining, |
paulb@63 | 359 | lvalue=LoadRef(storename.original, |
paulb@63 | 360 | ref=self.module), |
paulb@63 | 361 | name=storename.name, |
paulb@63 | 362 | expr=storename.expr, |
paulb@63 | 363 | nstype="module") |
paulb@63 | 364 | ) |
paulb@45 | 365 | |
paulb@45 | 366 | # For local namespace accesses... |
paulb@45 | 367 | |
paulb@31 | 368 | else: |
paulb@31 | 369 | self.namespace.store(storename.name) |
paulb@45 | 370 | |
paulb@45 | 371 | # If a distinct global namespace exists, it must be a local access. |
paulb@45 | 372 | |
paulb@45 | 373 | if self.global_namespace is not None: |
paulb@45 | 374 | return storename |
paulb@45 | 375 | |
paulb@45 | 376 | # Otherwise, the name is being set at the module level and is |
paulb@45 | 377 | # considered global. |
paulb@45 | 378 | |
paulb@45 | 379 | else: |
paulb@63 | 380 | return self.dispatch( |
paulb@79 | 381 | StoreAttr(storename.original, storename.defining, |
paulb@63 | 382 | lvalue=LoadRef(storename.original, |
paulb@63 | 383 | ref=self.module), |
paulb@63 | 384 | name=storename.name, |
paulb@63 | 385 | expr=storename.expr, |
paulb@63 | 386 | nstype="module") |
paulb@63 | 387 | ) |
paulb@45 | 388 | |
paulb@57 | 389 | def visitInvokeFunction(self, invoke): |
paulb@57 | 390 | |
paulb@57 | 391 | "Transform the 'invoke' node, performing processing on subprograms." |
paulb@57 | 392 | |
paulb@57 | 393 | return self.default(invoke) |
paulb@57 | 394 | |
paulb@204 | 395 | def visitInvokeRef(self, invoke): |
paulb@45 | 396 | |
paulb@45 | 397 | "Transform the 'invoke' node, performing processing on subprograms." |
paulb@45 | 398 | |
paulb@45 | 399 | # The special case of internal subprogram invocation is addressed by |
paulb@45 | 400 | # propagating namespace information to the subprogram and processing it. |
paulb@45 | 401 | |
paulb@210 | 402 | if invoke.share_locals: |
paulb@210 | 403 | subprogram = self.process_node(invoke.ref, self.namespace) |
paulb@210 | 404 | else: |
paulb@210 | 405 | subprogram = self.process_node(invoke.ref) |
paulb@210 | 406 | |
paulb@57 | 407 | if subprogram is not None: |
paulb@263 | 408 | self.subprograms.add(subprogram) |
paulb@57 | 409 | return invoke |
paulb@31 | 410 | |
paulb@46 | 411 | class ScopeMismatch(Exception): |
paulb@46 | 412 | pass |
paulb@46 | 413 | |
paulb@34 | 414 | class NameOrganiser: |
paulb@32 | 415 | |
paulb@32 | 416 | """ |
paulb@32 | 417 | A local namespace which may either relate to a genuine set of function |
paulb@32 | 418 | locals or the initialisation of a structure. |
paulb@32 | 419 | """ |
paulb@32 | 420 | |
paulb@32 | 421 | def __init__(self, structure=None): |
paulb@46 | 422 | |
paulb@46 | 423 | "Initialise the namespace with an optional 'structure'." |
paulb@46 | 424 | |
paulb@32 | 425 | self.structure = structure |
paulb@32 | 426 | if structure is not None: |
paulb@32 | 427 | self.local = "structure" |
paulb@32 | 428 | else: |
paulb@32 | 429 | self.local = "local" |
paulb@46 | 430 | |
paulb@46 | 431 | # Names may be self.local or "global". |
paulb@46 | 432 | |
paulb@32 | 433 | self.names = {} |
paulb@32 | 434 | |
paulb@32 | 435 | def make_global(self, name): |
paulb@46 | 436 | if not self.names.has_key(name): |
paulb@46 | 437 | self.names[name] = "global" |
paulb@46 | 438 | elif self.names[name] == self.local: |
paulb@46 | 439 | raise ScopeMismatch, "Name '%s' already considered as %s." % (name, self.local) |
paulb@32 | 440 | |
paulb@47 | 441 | def find_for_load(self, name): |
paulb@46 | 442 | return self.names.get(name, "global") |
paulb@32 | 443 | |
paulb@47 | 444 | def find_for_store(self, name): |
paulb@47 | 445 | return self.names.get(name, self.local) |
paulb@47 | 446 | |
paulb@45 | 447 | def store(self, name): |
paulb@46 | 448 | if self.names.get(name) != "global": |
paulb@46 | 449 | self.names[name] = self.local |
paulb@32 | 450 | else: |
paulb@46 | 451 | raise ScopeMismatch, "Name '%s' already considered as global." % name |
paulb@32 | 452 | |
paulb@46 | 453 | def merge(self, name, scope): |
paulb@46 | 454 | if self.names.get(name) in (None, scope): |
paulb@46 | 455 | self.names[name] = scope |
paulb@32 | 456 | else: |
paulb@46 | 457 | raise ScopeMismatch, "Name '%s' already considered as %s." % (name, self.names[name]) |
paulb@45 | 458 | |
paulb@45 | 459 | def merge_namespace(self, namespace): |
paulb@46 | 460 | self.merge_items(namespace.names.items()) |
paulb@45 | 461 | |
paulb@46 | 462 | def merge_items(self, items): |
paulb@46 | 463 | for name, scope in items: |
paulb@46 | 464 | self.merge(name, scope) |
paulb@45 | 465 | |
paulb@43 | 466 | def __repr__(self): |
paulb@43 | 467 | return repr(self.names) |
paulb@43 | 468 | |
paulb@57 | 469 | # Convenience functions. |
paulb@57 | 470 | |
paulb@57 | 471 | def fix(module, builtins=None): |
paulb@57 | 472 | |
paulb@57 | 473 | """ |
paulb@57 | 474 | Fix the names in the given 'module', also employing the optional 'builtins' |
paulb@57 | 475 | module, if specified. |
paulb@57 | 476 | """ |
paulb@57 | 477 | |
paulb@57 | 478 | fixer = Fixer() |
paulb@57 | 479 | if builtins is not None: |
paulb@57 | 480 | fixer.process(module, builtins) |
paulb@57 | 481 | else: |
paulb@57 | 482 | fixer.process(module) |
paulb@57 | 483 | |
paulb@31 | 484 | # vim: tabstop=4 expandtab shiftwidth=4 |