예제 #1
0
        def optimizeTree(tree):

            if "comments" in optimize:
                commentoptimizer.patch(tree)

            # "variants" prunes parts of the tree, so all subsequent optimizations benefit
            if "variants" in optimize:
                variantoptimizer.search(tree, variantSet, self.id)

            # 'statics' has to come before 'privates', as it needs the original key names in tree
            # if features should be removed recursively, this has to be controlled on the calling
            # level.
            if "statics" in optimize:
                if not featureMap:
                    console.warn(
                        "Empty feature map passed to static methods optimization; skipping"
                    )
                elif self.type == 'static' and self.id in featureMap:
                    optimzed_features = featureoptimizer.patch(
                        tree, self, featureMap)
                    if optimzed_features:
                        optimized_statics_overall = load_features()
                        copy = optimized_statics_overall.copy()
                        copy.update(optimzed_features)
                        write_features(copy)

            if "basecalls" in optimize:
                basecalloptimizer.patch(tree)

            if "privates" in optimize:
                privatesMap = load_privates()
                privateoptimizer.patch(tree, id, privatesMap)
                write_privates(privatesMap)

            if "globals" in optimize:
                tree = globalsoptimizer.process(
                    tree
                )  # need to re-assign as this optimizer might change the root node

            if "strings" in optimize:
                tree = stringoptimizer.process(tree, self.id)

            if "variables" in optimize:
                variableoptimizer.search(tree)

            return tree
예제 #2
0
파일: MClassCode.py 프로젝트: 1and1/qooxdoo
        def optimizeTree(tree):

            if "comments" in optimize:
                commentoptimizer.patch(tree)

            # "variants" prunes parts of the tree, so all subsequent optimizations benefit
            if "variants" in optimize:
                variantoptimizer.search(tree, variantSet, self.id)

            # 'statics' has to come before 'privates', as it needs the original key names in tree
            # if features should be removed recursively, this has to be controlled on the calling
            # level.
            if "statics" in optimize:
                if not featureMap:
                    console.warn("Empty feature map passed to static methods optimization; skipping")
                elif self.type == 'static' and self.id in featureMap:
                    optimzed_features = featureoptimizer.patch(tree, self, featureMap)
                    if optimzed_features:
                        optimized_statics_overall = load_features()
                        copy = optimized_statics_overall.copy()
                        copy.update(optimzed_features)
                        write_features(copy)

            if "basecalls" in optimize:
                basecalloptimizer.patch(tree)

            if "privates" in optimize:
                privatesMap = load_privates()
                privateoptimizer.patch(tree, id, privatesMap)
                write_privates(privatesMap)

            if "globals" in optimize:
                tree = globalsoptimizer.process(tree) # need to re-assign as this optimizer might change the root node

            if "strings" in optimize:
                tree = stringoptimizer.process(tree, self.id)

            if "variables" in optimize:
                variableoptimizer.search(tree)

            return tree
예제 #3
0
def run_compile(fileName, fileContent, options, args):
    fileId = fileName
    tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName)
    if not options.quiet:
        print(">>> Creating tree...")
    tree = treegenerator.createFileTree(tokens)
    tree = scopes.create_scopes(tree)

    # optimizing tree
    if len(options.variants) > 0:
        if not options.quiet:
            print(">>> Selecting variants...")
        varmap = {}
        for entry in options.variants:
            pos = entry.index(":")
            varmap[entry[0:pos]] = entry[pos + 1:]

        variantoptimizer.search(tree, varmap, fileId)

    if options.all or options.basecalls:
        if not options.quiet:
            print(">>> Optimizing basecalls...")
        basecalloptimizer.patch(tree)

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

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

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

    if options.all or options.globals:
        if not options.quiet:
            print(">>> Optimizing globals...")
        tree = globalsoptimizer.process(tree)

    if options.all or options.privates:
        if not options.quiet:
            print(">>> Optimizing privates...")
        privates = {}
        if options.cache:
            cache = Cache(options.cache, interruptRegistry=interruptRegistry)
            privates, _ = cache.read(options.privateskey)
            if privates == None:
                privates = {}
        privateoptimizer.patch(tree, fileId, privates)
        if options.cache:
            cache.write(options.privateskey, privates)

    if not options.quiet:
        print(">>> Compiling...")
    result = [u'']
    result = Packer().serializeNode(tree, None, result, True)
    result = u''.join(result)
    print(result.encode('utf-8'))

    return
예제 #4
0
def run_compile(fileName, fileContent, options, args):
    fileId = fileName
    tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName)
    if not options.quiet:
        print(">>> Creating tree...")
    tree = treegenerator.createFileTree(tokens)
    tree = scopes.create_scopes(tree)

    # optimizing tree
    if len(options.variants) > 0:
        if not options.quiet:
            print(">>> Selecting variants...")
        varmap = {}
        for entry in options.variants:
            pos = entry.index(":")
            varmap[entry[0:pos]] = entry[pos+1:]

        variantoptimizer.search(tree, varmap, fileId)

    if options.all or options.basecalls:
        if not options.quiet:
            print(">>> Optimizing basecalls...")
        basecalloptimizer.patch(tree)

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

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

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

    if options.all or options.globals:
        if not options.quiet:
            print(">>> Optimizing globals...")
        tree = globalsoptimizer.process(tree)

    if options.all or options.privates:
        if not options.quiet:
            print(">>> Optimizing privates...")
        privates = {}
        if options.cache:
            cache = Cache(options.cache,
                interruptRegistry=interruptRegistry
            )
            privates, _ = cache.read(options.privateskey)
            if privates == None:
                privates = {}
        privateoptimizer.patch(tree, fileId, privates)
        if options.cache:
            cache.write(options.privateskey, privates)

    if not options.quiet:
        print(">>> Compiling...")
    result = [u'']
    result = Packer().serializeNode(tree, None, result, True)
    result = u''.join(result)
    print(result.encode('utf-8'))

    return