def param_pass(ast, filename=""): """ Insert parameter declaration logging expressions """ rubric = param_rubric ast_ops.fix_typeofs(rubric) def dbg(f): # print f.__dict__ args = [d.name for d in f.decl.type.args.params] for arg in args[::-1]: r = copy.deepcopy(rubric) ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c) ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, f.coord, arg, type(f.decl.type.args)))) ast_ops.sar_string(r, "LVALUE", arg) ast_ops.sar_string(r, "RVALUE", arg) f.body.block_items.insert(0, r) return f ast_ops.sar(ast, FuncDef, dbg)
def var_pass(ast, filename=""): """ Insert assignment to variable logging expressions """ rubric = var_rubric ast_ops.fix_typeofs(rubric) def dbg(a): a.rvalue = ast_ops.sar(a.rvalue, Assignment, dbg) a.lvalue = ast_ops.sar(a.lvalue, Assignment, dbg) r = copy.deepcopy(rubric) ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c) ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, a.coord, a, type(a)))) ast_ops.sar_ID(r, "LVALUE", a.lvalue) ast_ops.sar_ID(r, "RVALUE", a.rvalue) # print "OPERATION: "+a.op r.block_items[-2].op = a.op # makes the operation (=, +=, -=) correct - TODO: magic number... return FuncCall(ID(""), ExprList([Compound(r.block_items, coord=a.coord)], coord=a.coord)) ast_ops.sar(ast, Assignment, dbg)
def unary_pass(ast, filename=""): rubric = unary_rubric ast_ops.fix_typeofs(rubric) def dbg(u): # print u.op if not ("++" in u.op or "--" in u.op): return u r = copy.deepcopy(rubric) def fix_op(ur): if "++" in ur.op or "--" in ur.op: ur.op = u.op return ur ast_ops.sar(r, UnaryOp, fix_op) ast_ops.sar(r, Constant, lambda c: Constant("int", str(ID_count + 1)) if c.value == "0" else c) ast_ops.sar_string(r, "__DEBUG_ID", new_sym((filename, u.coord, u, type(u)))) # print u.expr.__dict__ ast_ops.sar_ID(r, "LVALUE", u.expr) return FuncCall(ID(""), ExprList([Compound(r.block_items, coord=u.coord)], coord=u.coord)) ast_ops.sar(ast, UnaryOp, dbg)