def cleanup(node): """""" if not hasattr(node, "variables"): ScopeScanner.scan(node) # Re cleanup until nothing to remove is found x = 0 cleaned = False Console.debug("Removing unused variables...") while True: x = x + 1 #debug("Removing unused variables [Iteration: %s]...", x) Console.indent() if __cleanup(node): ScopeScanner.scan(node) cleaned = True Console.outdent() else: Console.outdent() break return cleaned
def __getOptimizedTree(self, permutation=None): """Returns an optimized tree with permutations applied.""" field = "script:opt-tree[%s]-%s" % (self.id, permutation) tree = self.project.getCache().read(field, self.mtime) if not tree: tree = copy.deepcopy(self.__getTree()) # Logging msg = "Optimizing class %s" % Console.colorize(self.id, "bold") if permutation: msg += Console.colorize(" (%s)" % permutation, "grey") Console.info("%s..." % msg) Console.indent() # Apply permutation if permutation: Console.debug("Patching tree with permutation: %s", permutation) Console.indent() jasy.script.clean.Permutate.patch(tree, permutation) Console.outdent() # Cleanups jasy.script.clean.DeadCode.cleanup(tree) ScopeScanner.scan(tree) jasy.script.clean.Unused.cleanup(tree) self.project.getCache().store(field, tree, self.mtime, True) Console.outdent() return tree
def process(self, code): node = Parser.parse(code) ScopeScanner.scan(node) data = Data.ApiData("test") data.scanTree(node) return data
def __getTree(self): """Returns the abstract syntax tree.""" field = "script:tree[%s]" % self.id tree = self.project.getCache().read(field, self.mtime) if not tree: Console.info("Processing class %s...", Console.colorize(self.id, "bold")) Console.indent() tree = Parser.parse(self.getText(), self.id) ScopeScanner.scan(tree) Console.outdent() self.project.getCache().store(field, tree, self.mtime, True) return tree
def process(self, code): node = Parser.parse(code) ScopeScanner.scan(node) LocalVariables.optimize(node) return Compressor.Compressor().compress(node)
def process(self, code): node = Parser.parse(code) ScopeScanner.scan(node) CombineDeclarations.optimize(node) return Compressor.Compressor().compress(node)