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:]
def addDeclDebug(parent, child): name = getTypeName(getType(child)) ASTModifier.addVar(child) index = [x[1] for x in parent.children()].index(child) parent.block_items = parent.block_items[:index + 1] + \ [ASTModifier.makeDeclLog(child.coord, name)] + \ [ASTModifier.makeAssignLog(child.coord, name)] + \ parent.block_items[index + 1:]
def addFuncParamDebug(func): debug = [ASTModifier.makeFuncCallLog(func)] for param in func['params']: debug.append(ASTModifier.makeDeclLog(param.coord, getTypeName(getType(param)))) debug.append(ASTModifier.makeAssignLog(param.coord, getTypeName(getType(param)))) if func['body'].block_items != None: func['body'].block_items = debug + \ func['body'].block_items + \ [ASTModifier.makeFuncReturnLog(func['file'] + ':' + str(func['endLine']), func)] else: func['body'].block_items = debug + \ [ASTModifier.makeFuncReturnLog(func['file'] + ':' + str(func['endLine']), func)]
def addUnopDebug(parent, child): name = child.expr.name index = [x[1] for x in parent.children()].index(child) parent.block_items = parent.block_items[:index + 1] + \ [ASTModifier.makeAssignLog(child.coord, name)] + \ parent.block_items[index + 1:]