Пример #1
0
def patch(node):
    patchCount = 0

    this_base_vars = treeutil.findVariable(node, "this.base")
    for var in this_base_vars:
        if var.parent.type == "operand" and var.parent.parent.type == "call":
            call = var.parent.parent
            try:
                firstArgName = treeutil.selectNode(
                    call, "params/1/identifier/@name")
            except tree.NodeAccessException:
                continue

            if firstArgName != "arguments":
                continue

            newCall = treeutil.compileString(
                "arguments.callee.base.call(this)")
            newCall.replaceChild(newCall.getChild("params"),
                                 call.getChild("params"))
            treeutil.selectNode(newCall,
                                "params/1/identifier").set("name", "this")
            call.parent.replaceChild(call, newCall)
            patchCount += 1

    this_self_vars = treeutil.findVariable(node, "this.self")
    for var in this_self_vars:
        if var.parent.type == "operand" and var.parent.parent.type == "call":
            call = var.parent.parent
            try:
                firstArgName = treeutil.selectNode(
                    call, "params/1/identifier/@name")
            except tree.NodeAccessException:
                continue

            if firstArgName != "arguments":
                continue

            newCall = treeutil.compileString("arguments.callee.self")
            call.parent.replaceChild(call, newCall)
            patchCount += 1

    return patchCount
def patch(node):
    patchCount = 0

    this_base_vars = treeutil.findVariable(node, "this.base")
    for var in this_base_vars:
        if var.parent.type == "operand" and var.parent.parent.type == "call":
            call = var.parent.parent
            try:
                firstArgName = treeutil.selectNode(call, "params/1/identifier/@name")
            except tree.NodeAccessException:
                continue
            
            if firstArgName != "arguments":
                continue
            
            newCall = treeutil.compileString("arguments.callee.base.call(this)")
            newCall.replaceChild(newCall.getChild("params"), call.getChild("params"))
            treeutil.selectNode(newCall, "params/1/identifier").set("name", "this")
            call.parent.replaceChild(call, newCall)
            patchCount += 1
            
    this_self_vars = treeutil.findVariable(node, "this.self")
    for var in this_self_vars:
        if var.parent.type == "operand" and var.parent.parent.type == "call":
            call = var.parent.parent
            try:
                firstArgName = treeutil.selectNode(call, "params/1/identifier/@name")
            except tree.NodeAccessException:
                continue
            
            if firstArgName != "arguments":
                continue
            
            newCall = treeutil.compileString("arguments.callee.self")
            call.parent.replaceChild(call, newCall)
            patchCount += 1
            
            
            
    return patchCount
Пример #3
0
def detectDeps(node, optionalDeps, loadtimeDeps, runtimeDeps, fileId, fileDb, inFunction):
    if node.type == "variable":
        if node.hasChildren:
            assembled = ""
            first = True

            for child in node.children:
                if child.type == "identifier":
                    if not first:
                        assembled += "."

                    assembled += child.get("name")
                    first = False

                    if assembled != fileId and fileDb.has_key(assembled) and not assembled in optionalDeps:
                        if inFunction:
                            targetDeps = runtimeDeps
                        else:
                            targetDeps = loadtimeDeps

                        if assembled in targetDeps:
                            return

                        targetDeps.append(assembled)

                else:
                    assembled = ""
                    break

                # treat dependencies in defer as requires
                if assembled == "qx.Class.define" or assembled == "qx.Bootstrap.define":
                    if node.parent.type == "operand" and node.parent.parent.type == "call":
                        deferNode = treeutil.selectNode(
                            node, "../../params/2/keyvalue[@key='defer']/value/function/body/block"
                        )
                        if deferNode != None:
                            detectDeps(deferNode, optionalDeps, loadtimeDeps, runtimeDeps, fileId, fileDb, False)

    elif node.type == "body" and node.parent.type == "function":
        inFunction = True

    if node.hasChildren():
        for child in node.children:
            detectDeps(child, optionalDeps, loadtimeDeps, runtimeDeps, fileId, fileDb, inFunction)
Пример #4
0
def detectDeps(node, optionalDeps, loadtimeDeps, runtimeDeps, fileId, fileDb, inFunction):
    if node.type == "variable":
        if node.hasChildren:
            assembled = ""
            first = True

            for child in node.children:
                if child.type == "identifier":
                    if not first:
                        assembled += "."

                    assembled += child.get("name")
                    first = False

                    if assembled != fileId and fileDb.has_key(assembled) and not assembled in optionalDeps:
                        if inFunction:
                            targetDeps = runtimeDeps
                        else:
                            targetDeps = loadtimeDeps

                        if assembled in targetDeps:
                            return

                        targetDeps.append(assembled)

                else:
                    assembled = ""
                    break

                # treat dependencies in defer as requires
                if assembled == "qx.Class.define" or assembled == "qx.Bootstrap.define":
                    if node.parent.type == "operand" and node.parent.parent.type == "call":
                        deferNode = treeutil.selectNode(node, "../../params/2/keyvalue[@key='defer']/value/function/body/block")
                        if deferNode != None:
                            detectDeps(deferNode, optionalDeps, loadtimeDeps, runtimeDeps, fileId, fileDb, False)


    elif node.type == "body" and node.parent.type == "function":
        inFunction = True

    if node.hasChildren():
        for child in node.children:
            detectDeps(child, optionalDeps, loadtimeDeps, runtimeDeps, fileId, fileDb, inFunction)