Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
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
Beispiel #4
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     data = Data.ApiData("test")
     data.scanTree(node)
     
     return data
Beispiel #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
Beispiel #6
0
Datei: api.py Projekt: zynga/jasy
    def process(self, code):
        node = Parser.parse(code)
        ScopeScanner.scan(node)
        data = Data.ApiData("test")
        data.scanTree(node)

        return data
Beispiel #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
Beispiel #8
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
Beispiel #9
0
 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
Beispiel #10
0
    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
Beispiel #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
Beispiel #12
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     LocalVariables.optimize(node)
     return Compressor.Compressor().compress(node)
Beispiel #13
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     CombineDeclarations.optimize(node)
     return Compressor.Compressor().compress(node)
Beispiel #14
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     CombineDeclarations.optimize(node)
     return Compressor.Compressor().compress(node)
Beispiel #15
0
 def process(self, code):
     node = Parser.parse(code)
     ScopeScanner.scan(node)
     LocalVariables.optimize(node)
     return Compressor.Compressor().compress(node)