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))
def dbg(d): if not d.__dict__.has_key("init"): return None # not the kind of Decl we're looking for if d.name.startswith("__DEBUG_"): return None # skip VAR pass variables d.init = ast_ops.sar(d.init, Decl, 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, d.coord, d, type(d)))) ast_ops.sar_string(r, "LVALUE", d.name) if d.init: ast_ops.sar_ID(r, "RVALUE", d.init) # No initial value, so RVALUE = *LVALUE implicitly (garbage value, but useful for debugging): else: ast_ops.sar_string(r, "RVALUE", d.name) return FuncCall(ID(""), ExprList([Compound(r.block_items, coord=d.coord)], coord=d.coord))
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))