Exemplo n.º 1
0
def addForDebug(parent, child, index):
    if nodeType(parent) != 'Compound':
        return
    preFor = [ASTModifier.makeScopeInLog(child.coord)]
    postFor = [ASTModifier.makeScopeOutLog(child.coord)]
    if nodeType(child.init) == 'DeclList':
        for (name, decl) in child.init.children():
            newDecl = ASTModifier.makeVarDecl(decl, decl.init)
            ASTModifier.addVar(decl)
            ASTModifier.addVar(newDecl)
            preFor.append(newDecl)
            preFor.append(ASTModifier.makeDeclLog(child.coord,
                                                getTypeName(getType(decl))))
            preFor.append(ASTModifier.makeAssignLog(child.coord,
                                                    getTypeName(getType(decl)),
                                                    getTypeName(getType(newDecl))))
            decl.init = ASTModifier.makeID(newDecl)
    else:
        child.init = makeAssignExprLog(child.init)
    child.cond = makeAssignExprLog(child.cond)
    child.next = makeAssignExprLog(child.next)
        
    parent.block_items = parent.block_items[:index] + \
                         preFor + \
                         [parent.block_items[index]] + \
                         postFor + \
                         parent.block_items[index + 1:]
Exemplo n.º 2
0
def addFuncReturnDebug(func, node = None):
    if node == None:
        addFuncReturnDebug(func, func['body'])
    else:
        for (name, child) in node.children():
            if nodeType(child) == 'Return':                
                newDecl = ASTModifier.makeVarDecl(func['type'], child.expr)
                ASTModifier.addVar(newDecl)
                child.expr = ASTModifier.makeID(newDecl)
                
                index = [x[1] for x in node.children()].index(child)
                node.block_items = node.block_items[:index] + \
                    [newDecl] + \
                    [ASTModifier.makeFuncReturnLog(child.coord, func, getTypeName(getType(newDecl)))] + \
                    node.block_items[index:]
            elif child != None:
                addFuncReturnDebug(func, child)