__init__.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
def movedLineAfterSpecialFunction(cv, startingTree, startingPath, orig):
    """Sometimes, with Move Vectors, items that got combined are no longer combined. Fix this by moving up the tree."""
    if isinstance(cv, MoveVector):
        cvCopy = cv.deepcopy()
        origSpot = deepcopy(cvCopy.traverseTree(cv.start))
        if len(origSpot) <= cv.oldSubtree or len(origSpot) <= cv.newSubtree:
            cvCopy.path = startingPath[1:]
            parentSpot = deepcopy(cvCopy.traverseTree(startingTree))
            if type(parentSpot) == ast.BoolOp:
                # Change this to a ChangeVector at the parent's level
                newSpot = deepcopy(parentSpot)
                newSpot.values.insert(cv.newSubtree, newSpot.values[cv.oldSubtree])
                newSpot.values.pop(cv.oldSubtree + (0 if cv.oldSubtree < cv.newSubtree else 1)) # adjust for length change
                cv = ChangeVector(cv.path[2:], parentSpot, newSpot, cv.start)
                cv.wasMoveVector = True
                return cv
            elif cv.path[1][0] == 'body': # If we're in a set of statements
                lineToMove = parentSpot.body[cv.oldSubtree]
                # First, just delete this line
                if hasattr(lineToMove, "global_id"):
                    path = generatePathToId(orig, lineToMove.global_id)
                else:
                    log("Individualize\tmovedLineAfterSpecialFunction\tWhere is the global id? " + printFunction(lineToMove), "bug")
                firstEdit = DeleteVector(path, lineToMove, None, start=orig)
                # Then, add the line back in, but in the correct position
                newPath = [cv.newSubtree] + cv.path[1:]
                secondEdit = AddVector(newPath, None, lineToMove, start=cv.start)
                return [firstEdit, secondEdit]
            else:
                log("Individualize\tmapEdit\tMissing option in Move Vector special case: " + str(type(parentSpot)), "bug")
    return cv
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号