示例#1
0
文件: Class.py 项目: zynga/jasy
    def __getOptimizedTree(self, permutation=None, context=None):
        """Returns an optimized tree with permutations applied"""

        field = "opt-tree[%s]-%s" % (self.id, permutation)
        tree = self.project.getCache().read(field, self.mtime)
        if not tree:
            tree = copy.deepcopy(self.__getTree("%s:plain" % context))

            # Logging
            msg = "Processing class %s" % Console.colorize(self.id, "bold")
            if permutation:
                msg += Console.colorize(" (%s)" % permutation, "grey")
            if context:
                msg += Console.colorize(" [%s]" % context, "cyan")

            Console.info("%s..." % msg)
            Console.indent()

            # Apply permutation
            if permutation:
                Console.debug("Patching tree with permutation: %s",
                              permutation)
                Console.indent()
                jasy.js.clean.Permutate.patch(tree, permutation)
                Console.outdent()

            # Cleanups
            jasy.js.clean.DeadCode.cleanup(tree)
            ScopeScanner.scan(tree)
            jasy.js.clean.Unused.cleanup(tree)

            self.project.getCache().store(field, tree, self.mtime, True)
            Console.outdent()

        return tree
示例#2
0
文件: Class.py 项目: dadicool/jasy
    def __getOptimizedTree(self, permutation=None, context=None):
        """Returns an optimized tree with permutations applied"""

        field = "opt-tree[%s]-%s" % (self.id, permutation)
        tree = self.project.getCache().read(field, self.mtime)
        if not tree:
            tree = copy.deepcopy(self.__getTree("%s:plain" % context))

            # Logging
            msg = "Processing class %s" % colorize(self.id, "bold")
            if permutation:
                msg += colorize(" (%s)" % permutation, "grey")
            if context:
                msg += colorize(" [%s]" % context, "cyan")
                
            info("%s..." % msg)
            indent()

            # Apply permutation
            if permutation:
                jasy.js.clean.Permutate.patch(tree, permutation)

            # Cleanups
            jasy.js.clean.DeadCode.cleanup(tree)
            ScopeScanner.scan(tree)
            jasy.js.clean.Unused.cleanup(tree)
        
            self.project.getCache().store(field, tree, self.mtime, True)
            outdent()

        return tree
示例#3
0
文件: Class.py 项目: csakatoku/jasy
    def getTree(self, permutation=None, cleanup=True):
        """
        Returns the tree (of nodes from the parser) of the class. This parses the class,
        creates the tree, applies and optional permutation, scans for variables usage 
        and puts the tree into the cache before returning it. The cache works with the
        permutation, so every permutated tree is cached separately.
        """

        permutation = self.filterPermutation(permutation)

        field = "tree[%s]-%s-%s" % (self.__id, permutation, cleanup)
        tree = self.__cache.read(field, self.__mtime)
        if tree is not None:
            return tree

        # Parse tree
        tree = Parser.parse(self.getText(), self.__name)

        # Apply permutation
        if permutation:
            jasy.js.clean.Permutate.patch(tree, permutation)

        # Remove dead code
        if cleanup:
            jasy.js.clean.DeadCode.cleanup(tree)

        # Scan for variable usage
        ScopeScanner.scan(tree)

        # Remove unused variables/functions
        if cleanup:
            jasy.js.clean.Unused.cleanup(tree)

        self.__cache.store(field, tree, self.__mtime, True)
        return tree
示例#4
0
文件: api.py 项目: Andais/jasy
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     data = Data.ApiData("test")
     data.scanTree(node)
     
     return data
示例#5
0
    def getTree(self, permutation=None, cleanup=True):
        """
        Returns the tree (of nodes from the parser) of the class. This parses the class,
        creates the tree, applies and optional permutation, scans for variables usage 
        and puts the tree into the cache before returning it. The cache works with the
        permutation, so every permutated tree is cached separately.
        """
        
        permutation = self.filterPermutation(permutation)
        
        field = "tree[%s]-%s-%s" % (self.__id, permutation, cleanup)
        tree = self.__cache.read(field, self.__mtime)
        if tree is not None:
            return tree
            
        # Parse tree
        tree = Parser.parse(self.getText(), self.__name)

        # Apply permutation
        if permutation:
            jasy.js.clean.Permutate.patch(tree, permutation)

        # Remove dead code
        if cleanup:
            jasy.js.clean.DeadCode.cleanup(tree)

        # Scan for variable usage
        ScopeScanner.scan(tree)
        
        # Remove unused variables/functions
        if cleanup:
            jasy.js.clean.Unused.cleanup(tree)
        
        self.__cache.store(field, tree, self.__mtime, True)
        return tree
示例#6
0
文件: api.py 项目: zynga/jasy
    def process(self, code):
        node = Parser.parse(code)
        ScopeScanner.scan(node)
        data = Data.ApiData("test")
        data.scanTree(node)

        return data
示例#7
0
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
示例#8
0
文件: Unused.py 项目: Andais/jasy
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
示例#9
0
文件: Class.py 项目: dadicool/jasy
 def __getTree(self, context=None):
     
     field = "tree[%s]" % self.id
     tree = self.project.getCache().read(field, self.mtime)
     if not tree:
         info("Processing class %s %s...", colorize(self.id, "bold"), colorize("[%s]" % context, "cyan"))
         
         indent()
         tree = Parser.parse(self.getText(), self.id)
         ScopeScanner.scan(tree)
         outdent()
         
         self.project.getCache().store(field, tree, self.mtime, True)
     
     return tree
示例#10
0
文件: Class.py 项目: zynga/jasy
    def __getTree(self, context=None):

        field = "tree[%s]" % self.id
        tree = self.project.getCache().read(field, self.mtime)
        if not tree:
            Console.info("Processing class %s %s...",
                         Console.colorize(self.id, "bold"),
                         Console.colorize("[%s]" % context, "cyan"))

            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
示例#11
0
def cleanup(node):
    """
    """
    
    if not hasattr(node, "variables"):
        ScopeScanner.scan(node)

    # Re cleanup until nothing to remove is found
    x = 0
    cleaned = False
    
    while True:
        x = x + 1
        logging.debug("Removing unused variables [Iteration: %s]..." % x)
        if __cleanup(node):
            ScopeScanner.scan(node)
            cleaned = True
        else:
            break
        
    return cleaned
示例#12
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     LocalVariables.optimize(node)
     return Compressor.Compressor().compress(node)
示例#13
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     CombineDeclarations.optimize(node)
     return Compressor.Compressor().compress(node)
示例#14
0
文件: combinedecl.py 项目: Val9/jasy
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     CombineDeclarations.optimize(node)
     return Compressor.Compressor().compress(node)
示例#15
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     LocalVariables.optimize(node)
     return Compressor.Compressor().compress(node)