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@31 | 6 | Copyright (C) 2007, 2008 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@0 | 20 | """ |
paul@0 | 21 | |
paul@39 | 22 | from micropython.common import * |
paul@83 | 23 | from micropython.data import * |
paul@0 | 24 | import compiler.ast |
paul@0 | 25 | from compiler.visitor import ASTVisitor |
paul@15 | 26 | |
paul@21 | 27 | # Program visitors. |
paul@21 | 28 | |
paul@15 | 29 | class InspectedModule(ASTVisitor, Module): |
paul@15 | 30 | |
paul@20 | 31 | """ |
paul@20 | 32 | An inspected module, providing core details via the Module superclass, but |
paul@20 | 33 | capable of being used as an AST visitor. |
paul@20 | 34 | """ |
paul@15 | 35 | |
paul@71 | 36 | def __init__(self, name, importer): |
paul@71 | 37 | |
paul@71 | 38 | """ |
paul@71 | 39 | Initialise this visitor with a module 'name' and an 'importer' which is |
paul@71 | 40 | used to provide access to other modules when required. |
paul@71 | 41 | """ |
paul@71 | 42 | |
paul@15 | 43 | ASTVisitor.__init__(self) |
paul@15 | 44 | Module.__init__(self, name) |
paul@15 | 45 | self.visitor = self |
paul@15 | 46 | |
paul@15 | 47 | self.importer = importer |
paul@61 | 48 | self.builtins = self.importer.modules.get("__builtins__") |
paul@15 | 49 | self.loaded = 0 |
paul@15 | 50 | |
paul@82 | 51 | # Constant records. |
paul@82 | 52 | |
paul@82 | 53 | self.constant_values = importer.constant_values |
paul@82 | 54 | |
paul@1 | 55 | # Current expression state. |
paul@1 | 56 | |
paul@1 | 57 | self.expr = None |
paul@1 | 58 | |
paul@1 | 59 | # Namespace state. |
paul@1 | 60 | |
paul@34 | 61 | self.in_init = 0 # Find instance attributes in __init__ methods. |
paul@34 | 62 | self.in_loop = 0 # Note loop "membership", affecting assignments. |
paul@12 | 63 | self.namespaces = [] |
paul@0 | 64 | self.module = None |
paul@0 | 65 | |
paul@0 | 66 | def parse(self, filename): |
paul@9 | 67 | |
paul@9 | 68 | "Parse the file having the given 'filename'." |
paul@9 | 69 | |
paul@0 | 70 | module = compiler.parseFile(filename) |
paul@0 | 71 | self.process(module) |
paul@0 | 72 | |
paul@0 | 73 | def process(self, module): |
paul@9 | 74 | |
paul@9 | 75 | "Process the given 'module'." |
paul@9 | 76 | |
paul@20 | 77 | self.node = self.module = module |
paul@1 | 78 | processed = self.dispatch(module) |
paul@13 | 79 | if self.has_key("__all__"): |
paul@12 | 80 | all = self["__all__"] |
paul@1 | 81 | if isinstance(all, compiler.ast.List): |
paul@1 | 82 | for n in all.nodes: |
paul@12 | 83 | self[n.value] = self.importer.add_module(self.name + "." + n.value) |
paul@1 | 84 | return processed |
paul@0 | 85 | |
paul@3 | 86 | def vacuum(self): |
paul@9 | 87 | |
paul@9 | 88 | "Vacuum the module namespace, removing unloaded module references." |
paul@9 | 89 | |
paul@13 | 90 | for name, value in self.items(): |
paul@3 | 91 | if isinstance(value, Module) and not value.loaded: |
paul@12 | 92 | del self[name] |
paul@0 | 93 | |
paul@16 | 94 | # Complain about globals not initialised at the module level. |
paul@16 | 95 | |
paul@16 | 96 | if isinstance(value, Global): |
paul@16 | 97 | print "Warning: global %r in module %r not initialised at the module level." % (name, self.name) |
paul@16 | 98 | |
paul@3 | 99 | # Namespace methods. |
paul@0 | 100 | |
paul@0 | 101 | def store(self, name, obj): |
paul@12 | 102 | |
paul@12 | 103 | "Record attribute or local 'name', storing 'obj'." |
paul@12 | 104 | |
paul@12 | 105 | if not self.namespaces: |
paul@34 | 106 | self.set(name, obj, not self.in_loop) |
paul@12 | 107 | else: |
paul@34 | 108 | self.namespaces[-1].set(name, obj, not self.in_loop) |
paul@12 | 109 | |
paul@12 | 110 | # Record all non-local objects. |
paul@12 | 111 | |
paul@12 | 112 | if not (self.namespaces and isinstance(self.namespaces[-1], Function)): |
paul@33 | 113 | self.all_objects.add(obj) |
paul@0 | 114 | |
paul@85 | 115 | def store_lambda(self, obj): |
paul@85 | 116 | self.all_objects.add(obj) |
paul@85 | 117 | |
paul@34 | 118 | def store_instance_attr(self, name): |
paul@12 | 119 | |
paul@12 | 120 | "Record instance attribute 'name' in the current class." |
paul@12 | 121 | |
paul@0 | 122 | if self.in_init: |
paul@15 | 123 | |
paul@12 | 124 | # Current namespace is the function. |
paul@12 | 125 | # Previous namespace is the class. |
paul@15 | 126 | |
paul@12 | 127 | self.namespaces[-2].add_instance_attribute(name) |
paul@0 | 128 | |
paul@7 | 129 | def get_parent(self): |
paul@71 | 130 | |
paul@71 | 131 | "Return the parent (or most recent) namespace currently exposed." |
paul@71 | 132 | |
paul@12 | 133 | return (self.namespaces[-1:] or [self])[0] |
paul@7 | 134 | |
paul@3 | 135 | # Visitor methods. |
paul@3 | 136 | |
paul@3 | 137 | def default(self, node, *args): |
paul@39 | 138 | raise InspectError(self.full_name(), node, "Node class %r is not supported." % node.__class__) |
paul@3 | 139 | |
paul@3 | 140 | def dispatch(self, node, *args): |
paul@3 | 141 | return ASTVisitor.dispatch(self, node, *args) |
paul@3 | 142 | |
paul@0 | 143 | def NOP(self, node): |
paul@21 | 144 | for n in node.getChildNodes(): |
paul@21 | 145 | self.dispatch(n) |
paul@19 | 146 | return None |
paul@0 | 147 | |
paul@82 | 148 | def OP(self, node): |
paul@82 | 149 | for n in node.getChildNodes(): |
paul@82 | 150 | self.dispatch(n) |
paul@82 | 151 | return Instance() |
paul@1 | 152 | |
paul@85 | 153 | def _visitFunction(self, node, name): |
paul@85 | 154 | |
paul@85 | 155 | """ |
paul@85 | 156 | Return a function object for the function defined by 'node' with the |
paul@85 | 157 | given 'name'. If a lambda expression is being visited, 'name' should be |
paul@85 | 158 | None. |
paul@85 | 159 | """ |
paul@85 | 160 | |
paul@85 | 161 | function = Function( |
paul@85 | 162 | name, |
paul@85 | 163 | self.get_parent(), |
paul@85 | 164 | node.argnames, |
paul@85 | 165 | node.defaults, |
paul@85 | 166 | (node.flags & 4 != 0), |
paul@85 | 167 | (node.flags & 8 != 0), |
paul@85 | 168 | self, |
paul@85 | 169 | node |
paul@85 | 170 | ) |
paul@85 | 171 | |
paul@85 | 172 | # Make a back reference from the node for code generation. |
paul@85 | 173 | |
paul@85 | 174 | node.unit = function |
paul@85 | 175 | |
paul@85 | 176 | # Process the defaults. |
paul@85 | 177 | |
paul@85 | 178 | for n in node.defaults: |
paul@85 | 179 | self.expr = self.dispatch(n) |
paul@85 | 180 | if isinstance(self.expr, Attr): |
paul@85 | 181 | function.store_default(self.expr.value) |
paul@85 | 182 | else: |
paul@85 | 183 | function.store_default(self.expr) |
paul@85 | 184 | |
paul@85 | 185 | # Enter the function. |
paul@85 | 186 | |
paul@85 | 187 | self.namespaces.append(function) |
paul@85 | 188 | |
paul@85 | 189 | # Current namespace is the function. |
paul@85 | 190 | # Previous namespace is the class. |
paul@85 | 191 | |
paul@85 | 192 | if name == "__init__" and isinstance(self.namespaces[-2], Class): |
paul@85 | 193 | self.in_init = 1 |
paul@85 | 194 | |
paul@85 | 195 | self.dispatch(node.code) |
paul@85 | 196 | self.in_init = 0 |
paul@85 | 197 | self.namespaces.pop() |
paul@85 | 198 | |
paul@85 | 199 | if name is not None: |
paul@85 | 200 | self.store(name, function) |
paul@85 | 201 | else: |
paul@85 | 202 | self.store_lambda(function) |
paul@85 | 203 | |
paul@85 | 204 | return function |
paul@85 | 205 | |
paul@82 | 206 | visitAdd = OP |
paul@82 | 207 | |
paul@82 | 208 | visitAnd = OP |
paul@0 | 209 | |
paul@4 | 210 | visitAssert = NOP |
paul@4 | 211 | |
paul@0 | 212 | def visitAssign(self, node): |
paul@0 | 213 | self.expr = self.dispatch(node.expr) |
paul@0 | 214 | for n in node.nodes: |
paul@0 | 215 | self.dispatch(n) |
paul@0 | 216 | return None |
paul@0 | 217 | |
paul@0 | 218 | def visitAssAttr(self, node): |
paul@0 | 219 | expr = self.dispatch(node.expr) |
paul@36 | 220 | if isinstance(expr, Attr) and expr.name == "self": |
paul@34 | 221 | self.store_instance_attr(node.attrname) |
paul@0 | 222 | return None |
paul@0 | 223 | |
paul@0 | 224 | def visitAssList(self, node): |
paul@0 | 225 | for n in node.nodes: |
paul@0 | 226 | self.dispatch(n) |
paul@0 | 227 | return None |
paul@0 | 228 | |
paul@0 | 229 | def visitAssName(self, node): |
paul@36 | 230 | if isinstance(self.expr, Attr): |
paul@36 | 231 | self.store(node.name, self.expr.value) |
paul@36 | 232 | else: |
paul@36 | 233 | self.store(node.name, self.expr) |
paul@0 | 234 | return None |
paul@0 | 235 | |
paul@0 | 236 | visitAssTuple = visitAssList |
paul@0 | 237 | |
paul@82 | 238 | visitAugAssign = OP |
paul@2 | 239 | |
paul@82 | 240 | visitBackquote = OP |
paul@4 | 241 | |
paul@82 | 242 | visitBitand = OP |
paul@2 | 243 | |
paul@82 | 244 | visitBitor = OP |
paul@2 | 245 | |
paul@82 | 246 | visitBitxor = OP |
paul@4 | 247 | |
paul@4 | 248 | visitBreak = NOP |
paul@4 | 249 | |
paul@82 | 250 | visitCallFunc = OP |
paul@0 | 251 | |
paul@0 | 252 | def visitClass(self, node): |
paul@12 | 253 | if self.namespaces: |
paul@41 | 254 | print "Class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) |
paul@82 | 255 | return None |
paul@0 | 256 | else: |
paul@53 | 257 | cls = Class(node.name, self.get_parent(), self, node) |
paul@37 | 258 | |
paul@37 | 259 | # Visit the base class expressions, attempting to find concrete |
paul@37 | 260 | # definitions of classes. |
paul@37 | 261 | |
paul@0 | 262 | for base in node.bases: |
paul@36 | 263 | expr = self.dispatch(base) |
paul@36 | 264 | if isinstance(expr, Attr): |
paul@36 | 265 | if expr.assignments != 1: |
paul@39 | 266 | raise InspectError(self.full_name(), node, |
paul@40 | 267 | "Base class %r for %r is not constant." % (base, cls.full_name())) |
paul@36 | 268 | else: |
paul@36 | 269 | cls.add_base(expr.value) |
paul@36 | 270 | else: # if expr is None: |
paul@39 | 271 | raise InspectError(self.full_name(), node, |
paul@40 | 272 | "Base class %r for %r is not found: it may be hidden in some way." % (base, cls.full_name())) |
paul@0 | 273 | |
paul@59 | 274 | # NOTE: Potentially dubious measure to permit __init__ availability. |
paul@59 | 275 | # If no bases exist, adopt the 'object' class. |
paul@59 | 276 | |
paul@61 | 277 | if not node.bases and not (self.name == "__builtins__" and node.name == "object") : |
paul@59 | 278 | expr = self.dispatch(compiler.ast.Name("object")) |
paul@59 | 279 | cls.add_base(expr.value) |
paul@59 | 280 | |
paul@21 | 281 | # Make a back reference from the node for code generation. |
paul@21 | 282 | |
paul@39 | 283 | node.unit = cls |
paul@21 | 284 | |
paul@0 | 285 | # Make an entry for the class. |
paul@0 | 286 | |
paul@0 | 287 | self.store(node.name, cls) |
paul@0 | 288 | |
paul@59 | 289 | # Process the class body. |
paul@59 | 290 | |
paul@12 | 291 | self.namespaces.append(cls) |
paul@0 | 292 | self.dispatch(node.code) |
paul@12 | 293 | self.namespaces.pop() |
paul@0 | 294 | |
paul@82 | 295 | return cls |
paul@0 | 296 | |
paul@82 | 297 | visitCompare = OP |
paul@4 | 298 | |
paul@21 | 299 | def visitConst(self, node): |
paul@21 | 300 | const = Const(node.value) |
paul@22 | 301 | self.constant_values[node.value] = const |
paul@24 | 302 | return const |
paul@0 | 303 | |
paul@4 | 304 | visitContinue = NOP |
paul@4 | 305 | |
paul@4 | 306 | visitDecorators = NOP |
paul@4 | 307 | |
paul@82 | 308 | visitDict = OP |
paul@0 | 309 | |
paul@0 | 310 | visitDiscard = NOP |
paul@0 | 311 | |
paul@82 | 312 | visitDiv = OP |
paul@4 | 313 | |
paul@4 | 314 | visitEllipsis = NOP |
paul@4 | 315 | |
paul@4 | 316 | visitExec = NOP |
paul@4 | 317 | |
paul@82 | 318 | visitExpression = OP |
paul@4 | 319 | |
paul@82 | 320 | visitFloorDiv = OP |
paul@4 | 321 | |
paul@34 | 322 | def visitFor(self, node): |
paul@34 | 323 | self.in_loop = 1 |
paul@34 | 324 | self.NOP(node) |
paul@34 | 325 | self.in_loop = 0 |
paul@82 | 326 | return None |
paul@0 | 327 | |
paul@0 | 328 | def visitFrom(self, node): |
paul@0 | 329 | module = self.importer.load(node.modname, 1) |
paul@0 | 330 | |
paul@35 | 331 | #if module is None: |
paul@35 | 332 | # print "Warning:", node.modname, "not imported." |
paul@0 | 333 | |
paul@0 | 334 | for name, alias in node.names: |
paul@0 | 335 | if name != "*": |
paul@4 | 336 | if module is not None and module.namespace.has_key(name): |
paul@24 | 337 | attr = module[name] |
paul@36 | 338 | self.store(alias or name, attr.value) |
paul@2 | 339 | if isinstance(attr, Module) and not attr.loaded: |
paul@2 | 340 | self.importer.load(attr.name) |
paul@24 | 341 | |
paul@24 | 342 | # Support the import of names from missing modules. |
paul@24 | 343 | |
paul@3 | 344 | else: |
paul@24 | 345 | self.store(alias or name, UnresolvedName(name, node.modname, self)) |
paul@3 | 346 | else: |
paul@3 | 347 | if module is not None: |
paul@3 | 348 | for n in module.namespace.keys(): |
paul@24 | 349 | attr = module[n] |
paul@36 | 350 | self.store(n, attr.value) |
paul@3 | 351 | if isinstance(attr, Module) and not attr.loaded: |
paul@3 | 352 | self.importer.load(attr.name) |
paul@0 | 353 | |
paul@0 | 354 | return None |
paul@0 | 355 | |
paul@0 | 356 | def visitFunction(self, node): |
paul@85 | 357 | return self._visitFunction(node, node.name) |
paul@0 | 358 | |
paul@82 | 359 | visitGenExpr = OP |
paul@4 | 360 | |
paul@4 | 361 | visitGenExprFor = NOP |
paul@4 | 362 | |
paul@4 | 363 | visitGenExprIf = NOP |
paul@4 | 364 | |
paul@4 | 365 | visitGenExprInner = NOP |
paul@4 | 366 | |
paul@0 | 367 | def visitGetattr(self, node): |
paul@0 | 368 | expr = self.dispatch(node.expr) |
paul@36 | 369 | if isinstance(expr, Attr): |
paul@36 | 370 | value = expr.value |
paul@87 | 371 | if isinstance(value, (Class, Module)): |
paul@36 | 372 | return value.namespace.get(node.attrname) |
paul@36 | 373 | elif isinstance(value, UnresolvedName): |
paul@36 | 374 | return UnresolvedName(node.attrname, value.full_name(), self) |
paul@87 | 375 | else: |
paul@87 | 376 | return None |
paul@61 | 377 | if self.builtins is not None: |
paul@61 | 378 | return self.builtins.get(node.attrname) |
paul@61 | 379 | else: |
paul@61 | 380 | return UnresolvedName(node.attrname, value.full_name(), self) |
paul@4 | 381 | |
paul@12 | 382 | def visitGlobal(self, node): |
paul@12 | 383 | if self.namespaces: |
paul@12 | 384 | for name in node.names: |
paul@12 | 385 | self.namespaces[-1].make_global(name) |
paul@37 | 386 | |
paul@37 | 387 | # Record a global entry for the name in the module. |
paul@37 | 388 | |
paul@15 | 389 | if not self.has_key(name): |
paul@16 | 390 | self[name] = Global() |
paul@0 | 391 | |
paul@0 | 392 | def visitIf(self, node): |
paul@0 | 393 | for test, body in node.tests: |
paul@0 | 394 | self.dispatch(body) |
paul@0 | 395 | if node.else_ is not None: |
paul@0 | 396 | self.dispatch(node.else_) |
paul@0 | 397 | return None |
paul@0 | 398 | |
paul@12 | 399 | visitIfExp = NOP |
paul@12 | 400 | |
paul@0 | 401 | def visitImport(self, node): |
paul@0 | 402 | for name, alias in node.names: |
paul@2 | 403 | if alias is not None: |
paul@24 | 404 | self.store(alias, self.importer.load(name, 1) or UnresolvedName(None, name, self)) |
paul@2 | 405 | else: |
paul@24 | 406 | self.store(name.split(".")[0], self.importer.load(name) or UnresolvedName(None, name.split(".")[0], self)) |
paul@0 | 407 | |
paul@0 | 408 | return None |
paul@0 | 409 | |
paul@82 | 410 | visitInvert = OP |
paul@4 | 411 | |
paul@59 | 412 | def visitKeyword(self, node): |
paul@59 | 413 | self.dispatch(node.expr) |
paul@59 | 414 | const = Const(node.name) |
paul@59 | 415 | self.constant_values[node.name] = const |
paul@71 | 416 | self.keyword_names.add(node.name) |
paul@59 | 417 | return None |
paul@4 | 418 | |
paul@85 | 419 | def visitLambda(self, node): |
paul@85 | 420 | return self._visitFunction(node, None) |
paul@4 | 421 | |
paul@82 | 422 | visitLeftShift = OP |
paul@1 | 423 | |
paul@82 | 424 | visitList = OP |
paul@0 | 425 | |
paul@82 | 426 | visitListComp = OP |
paul@4 | 427 | |
paul@4 | 428 | visitListCompFor = NOP |
paul@4 | 429 | |
paul@4 | 430 | visitListCompIf = NOP |
paul@4 | 431 | |
paul@82 | 432 | visitMod = OP |
paul@4 | 433 | |
paul@0 | 434 | def visitModule(self, node): |
paul@0 | 435 | return self.dispatch(node.node) |
paul@0 | 436 | |
paul@82 | 437 | visitMul = OP |
paul@2 | 438 | |
paul@0 | 439 | def visitName(self, node): |
paul@0 | 440 | name = node.name |
paul@82 | 441 | if name == "None": |
paul@82 | 442 | const = Const(None) |
paul@82 | 443 | self.constant_values[None] = const |
paul@82 | 444 | return const |
paul@82 | 445 | elif self.namespaces and self.namespaces[-1].has_key(name): |
paul@35 | 446 | return self.namespaces[-1][name] |
paul@13 | 447 | elif self.has_key(name): |
paul@12 | 448 | return self[name] |
paul@61 | 449 | elif self.builtins is not None and self.builtins.has_key(name): |
paul@61 | 450 | return self.builtins[name] |
paul@0 | 451 | else: |
paul@0 | 452 | return None |
paul@0 | 453 | |
paul@82 | 454 | visitNot = OP |
paul@0 | 455 | |
paul@82 | 456 | visitOr = OP |
paul@0 | 457 | |
paul@0 | 458 | visitPass = NOP |
paul@0 | 459 | |
paul@82 | 460 | visitPower = OP |
paul@4 | 461 | |
paul@4 | 462 | visitPrint = NOP |
paul@4 | 463 | |
paul@4 | 464 | visitPrintnl = NOP |
paul@4 | 465 | |
paul@0 | 466 | visitRaise = NOP |
paul@0 | 467 | |
paul@4 | 468 | visitReturn = NOP |
paul@4 | 469 | |
paul@82 | 470 | visitRightShift = OP |
paul@1 | 471 | |
paul@82 | 472 | visitSlice = OP |
paul@4 | 473 | |
paul@82 | 474 | visitSliceobj = OP |
paul@23 | 475 | |
paul@0 | 476 | def visitStmt(self, node): |
paul@0 | 477 | for n in node.nodes: |
paul@0 | 478 | self.dispatch(n) |
paul@0 | 479 | return None |
paul@0 | 480 | |
paul@82 | 481 | visitSub = OP |
paul@4 | 482 | |
paul@82 | 483 | visitSubscript = OP |
paul@0 | 484 | |
paul@0 | 485 | def visitTryExcept(self, node): |
paul@0 | 486 | self.dispatch(node.body) |
paul@0 | 487 | for name, var, n in node.handlers: |
paul@0 | 488 | self.dispatch(n) |
paul@0 | 489 | if node.else_ is not None: |
paul@0 | 490 | self.dispatch(node.else_) |
paul@0 | 491 | return None |
paul@0 | 492 | |
paul@4 | 493 | visitTryFinally = NOP |
paul@4 | 494 | |
paul@82 | 495 | visitTuple = OP |
paul@1 | 496 | |
paul@82 | 497 | visitUnaryAdd = OP |
paul@4 | 498 | |
paul@82 | 499 | visitUnarySub = OP |
paul@4 | 500 | |
paul@34 | 501 | def visitWhile(self, node): |
paul@34 | 502 | self.in_loop = 1 |
paul@34 | 503 | self.NOP(node) |
paul@34 | 504 | self.in_loop = 0 |
paul@82 | 505 | return None |
paul@4 | 506 | |
paul@4 | 507 | visitWith = NOP |
paul@4 | 508 | |
paul@4 | 509 | visitYield = NOP |
paul@4 | 510 | |
paul@16 | 511 | class Global: |
paul@16 | 512 | |
paul@16 | 513 | """ |
paul@16 | 514 | A reference to an object assigned to a global from outside the module |
paul@16 | 515 | top-level. |
paul@16 | 516 | """ |
paul@16 | 517 | |
paul@16 | 518 | pass |
paul@16 | 519 | |
paul@0 | 520 | # vim: tabstop=4 expandtab shiftwidth=4 |