Example #1
0
def src_lineno(node):
	n = node
	lineage = [n]
	while(hasattr(n, 'parent')):
		n = n.parent
		lineage.append(n)

	if not hasattr(n, 'lineno') or n.lineno is None:
		raise Exception("could not find origin for node: %s" % (
			"\n".join(["%s:%s" % (getattr(x, 'cpass', 'None'), pyc_parser.dump(x)) for x in lineage])
		))
		#return 0
	
	return n.lineno
Example #2
0
File: pyc_sir.py Project: 0xcc/pyc
def _sir_list_to_str(sir_list, depth=0):
	lines = []
	for sir in sir_list:
		if isinstance(sir, ast.If):
			lines.append("%sIf(%s)" % (" "*depth, ast.dump(sir.test)) )
			lines.extend(_sir_list_to_str(sir.body, depth+1) )
			lines.append("%selse(%s)" % (" "*depth, ast.dump(sir.test)) )
			lines.extend(_sir_list_to_str(sir.orelse, depth+1) )
			lines.append("%send(%s)" % (" "*depth, ast.dump(sir.test)) )
		elif isinstance(sir, BlocDef):
			#print repr(ast.dump(sir))
			lines.append("%sBlocDef(%s)(%s)" % (
				" "*depth, 
				sir.name, 
				", ".join([n.id for n in sir.params])
			))
			lines.extend(_sir_list_to_str(sir.body, depth+1) )
			lines.append("%send(%s)" % (" "*depth, sir.name) )
		else:
			lines.append("%s%s" % (" "*depth, pyc_parser.dump(sir) ) )
			

	return lines