Ejemplo n.º 1
0
    def getApi(self, fileId, variantSet):
        filePath = self._classesObj[fileId].path

        cacheId = "api-%s" % filePath
        tdata, _ = self._cache.read(cacheId, filePath)
        if tdata != None:
            return tdata

        self._console.debug("Extracting API data: %s..." % fileId)

        self._console.indent()
        tree_ = self._classesObj[fileId].tree(treegenerator)
        optimize = self._job.get("compile-options/code/optimize", [])
        if "variants" in optimize:
            tree_ = self._classesObj[fileId].optimize(tree_, ["variants"], variantSet)
        (data, hasError, attachMap) = api.createDoc(tree_)
        # debug on
        #if fileId=="qx.module.Animation":
        #    import pydb; pydb.debugger()
        # debug off
        self._console.outdent()
        
        if hasError:
            self._console.error("Error in API data of class: %s" % fileId)
            data = None
        
        self._cache.write(cacheId, (data, attachMap))
        return data, attachMap
Ejemplo n.º 2
0
    def getApi(self, fileId, variantSet):
        filePath = self._classesObj[fileId].path

        cacheId = "api-%s" % filePath
        tdata, _ = self._cache.read(cacheId, filePath)
        if tdata != None:
            return tdata

        self._console.debug("Extracting API data: %s..." % fileId)

        self._console.indent()
        tree_ = self._classesObj[fileId].tree(treegenerator)
        optimize = self._job.get("compile-options/code/optimize", [])
        if "variants" in optimize:
            tree_ = self._classesObj[fileId].optimize(tree_, ["variants"],
                                                      variantSet)
        (data, hasError, attachMap) = api.createDoc(tree_)
        self._console.outdent()

        if hasError:
            self._console.error("Error in API data of class: %s" % fileId)
            data = None

        self._cache.write(cacheId, (data, attachMap))
        return data, attachMap
Ejemplo n.º 3
0
    def getApi(self, fileId, variantSet):
        filePath = self._classesObj[fileId].path

        cacheId = "api-%s" % filePath
        data, _ = self._cache.read(cacheId, filePath)
        if data != None:
            return data

        self._console.debug("Extracting API data: %s..." % fileId)

        self._console.indent()
        tree = self._classesObj[fileId].tree(treegenerator_2)
        (data, hasError) = api.createDoc(tree)
        self._console.outdent()
        
        if hasError:
            self._console.error("Error in API data of class: %s" % fileId)
            data = None
        
        self._cache.write(cacheId, data)
        return data
Ejemplo n.º 4
0
    def getApi(self, fileId):
        filePath = self._classesObj[fileId].path

        cacheId = "api-%s" % filePath
        data, _ = self._cache.read(cacheId, filePath)
        if data != None:
            return data

        self._console.debug("Extracting API data: %s..." % fileId)

        self._console.indent()
        #tree = self._treeLoader.getTree(fileId)
        tree = self._classesObj[fileId].tree()
        (data, hasError) = api.createDoc(tree)
        self._console.outdent()

        if hasError:
            self._console.error("Error in API data of class: %s" % fileId)
            data = None

        self._cache.write(cacheId, data)
        return data
Ejemplo n.º 5
0
    def getApi(self, fileId):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        cacheId = "api-%s" % fileId
        data = self._cache.read(cacheId, filePath)
        if data != None:
            return data

        self._console.debug("Extracting API data: %s..." % fileId)

        self._console.indent()
        tree = self._treeLoader.getTree(fileId)
        (data, hasError) = api.createDoc(tree)
        self._console.outdent()

        if hasError:
            self._console.error("Error in API data of class: %s" % fileId)
            data = None

        self._cache.write(cacheId, data)
        return data
Ejemplo n.º 6
0
def main():
    parser = optparse.OptionParser(option_class=ExtendAction)

    usage_str = '''%prog [options] file.js,...'''
    parser.set_usage(usage_str)
    
    # General flags
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose output mode (extra verbose)")

    # Optimization flags
    parser.add_option("-n", "--variables", action="store_true", dest="variables", default=False, help="optimize variables")
    parser.add_option("-s", "--strings", action="store_true", dest="strings", default=False, help="optimize strings")
    parser.add_option("-p", "--privates", action="store_true", dest="privates", default=False, help="optimize privates")
    parser.add_option("-b", "--basecalls", action="store_true", dest="basecalls", default=False, help="optimize basecalls")            
    parser.add_option("-i", "--inline", action="store_true", dest="inline", default=False, help="optimize inline")
    parser.add_option("--all", action="store_true", dest="all", default=False, help="optimize all")            

    # Variant support
    parser.add_option("--variant", action="extend", dest="variants", metavar="KEY:VALUE", type="string", default=[], help="Selected variants")
    
    # Action modifier
    parser.add_option("--pretty", action="store_true", dest="pretty", default=False, help="print out pretty printed")            
    parser.add_option("--tree", action="store_true", dest="tree", default=False, help="print out tree")
    parser.add_option("--apiXml", action="store_true", dest="apiXml", default=False, help="print out api data as XML")
    parser.add_option("--apiJson", action="store_true", dest="apiJson", default=False, help="print out api data as JSON")
    parser.add_option("--lint", action="store_true", dest="lint", default=False, help="ecmalint the file")
    
    
    #
    # Process arguments
    #
    (options, args) = parser.parse_args(sys.argv[1:])
    
    if len(args) == 0:
        print ">>> Missing filename!"
        return

    print ">>> Parsing file..."
    fileName = args[0]
    fileContent = filetool.read(fileName, "utf-8")
    fileId = "xxx"
    tokens = tokenizer.parseStream(fileContent, fileName)
    
    print ">>> Creating tree..."
    tree = treegenerator.createSyntaxTree(tokens)
    
    
    #
    # Optimizing tree
    #
    
    if len(options.variants) > 0:
        print ">>> Selecting variants..."
        variantoptimizer.search(tree, options.variants, fileId)
    
    if options.all or options.basecalls:
        print ">>> Optimizing basecalls..."
        basecalloptimizer.patch(tree)   

    if options.all or options.inline:
        print ">>> Optimizing inline..."
        inlineoptimizer.patch(tree)   

    if options.all or options.strings:
        print ">>> Optimizing strings..."
        _optimizeStrings(tree, fileId)

    if options.all or options.variables:
        print ">>> Optimizing variables..."
        variableoptimizer.search(tree)

    if options.all or options.privates:
        print ">>> Optimizing privates..."
        privateoptimizer.patch(tree, fileId)
         
         
    #
    # Output the result
    #
    
    if options.apiXml or options.apiJson:
        (data, hasError) = api.createDoc(tree)  
        if hasError:
            print "Error in API docs!"
        elif options.apiXml:
            print ">>> API data as XML..."
            print data.toXml()
        else:
            print ">>> API data as JSON..."
            print data.toJson()
            
    elif options.lint:
        print ">>> Executing ecmalint..."
        print "Needs implementation"
    
    elif options.tree:
        print ">>> Printing out tree..."
        print tree.toXml()
        
    else:
        print ">>> Compiling..."
        compiled = _compileTree(tree, options.pretty)
        print compiled