예제 #1
0
파일: stubgen.py 프로젝트: zlqhem/stubgen
def mdoc_stubfunction(cv):
	return bind(mdoc_name(cv), lambda name:
		   bind(mdie_type(cv), lambda die_type:
		   bind(mdoc_typeref(die_type), lambda return_type:
		   bind(unit([mdoc_formalparameter(cu, child) for child in die.iter_children() if child.tag == 'DW_TAG_formal_parameter']),
				lambda params:
		   bind(unit(name + P.text("_Callback")), lambda var_functionpointer:
		   bind(unit(P.text("STUBGEN_") + name + P.text("_CALLBACK")), lambda var_type:
		   bind(unit(P.text("(" + var_type + P.text(") 0"))), lambda value:
		   bind(unit(), lambda paramNamesCallback:
		   bind(unit(doc_exp_function_call(var_type, sequence(paramNamesCallback))), lambda call_exp:
		   bind(unit(P.block(P.text("static int stubCallCount = 0;" + P.newline() + (P.text("return ") if die_type else P.empty()) + callExp + P.text(";")))), lambda then_block:
		   bind(unit(), lambda else_block:
		   bind(unit(), lambda if_stmt:
		   unit(doc_decl_function(return_type, name, params, P.block(if_stmt)))))))))))))))
예제 #2
0
파일: stubgen.py 프로젝트: zlqhem/stubgen
def mdoc_structure_type((cu, die)):
	cv = (cu, die)
	# struct <name> " {" [<member>] " };"
	return bind(mdoc_name(cv), lambda name:
		   bind(mdoc_decl_function_struct_type_getter(cv), lambda struct_getter:
		   bind(unit(die.iter_children()), lambda members:
		   bind(sequence([mdoc_member((cu, member)) for member in members]), lambda docMembers:
		   unit(P.text("struct ") + name + P.space() + P.block(intersperse(docMembers, P.newline())) + P.text(";") + P.newline() + struct_getter)))))
예제 #3
0
파일: stubgen.py 프로젝트: zlqhem/stubgen
def mdoc_decl_function_struct_type_getter(cv):
	returnType = mdoc_typeref(cv)
	# FIXME: use bind
	name = P.text('default_value_') + value(mdoc_name(cv))
	params = P.empty()
	decl_temp = doc_decl_var(value(returnType), P.text('temp'), P.text('{0, }'))
	stmt_return = doc_stmt_return(P.text('temp'))
	block = P.block(decl_temp + P.newline() + stmt_return)
	return unit(P.text("static ") + doc_decl_function(value(returnType), name, params, block))
예제 #4
0
파일: stubgen.py 프로젝트: zlqhem/stubgen
def mdoc_subprogram_legacy(cv):
	(cu, die) = cv
	# <return-type> <function-name> <params>	
	name = mdoc_name(cv)
	typeDie = mdie_type(cv) 
	# TODO: use Monad. if die has no DW_AT_type, return P.text("void "), otherwise typeref(die.type)
	returnType = mkDoc_typeref(cu, typeDie) if typeDie else P.text("void ")
	params = [mkDoc_formalparameter(cu, child) for child in die.iter_children()
									   if child.tag == 'DW_TAG_formal_parameter']
	paramsCallback = params + P.text("int stubCallCount")

	varType = P.text("STUBGEN_") + value(name) + P.text("_CALLBACK")
	decl_typedef_callback = mkDoc_decl_typedef_fp(returnType, paramsCallback, varType)
	
	
	varFp = value(name) + P.text("_Callback")
	value = P.text("(") + varType + P.text(") 0")
	decl_var_callback_fp = doc_decl_static_var(varType, varFp, value)

	# [M doc]
	paramNamesCallback = [mdoc_name(cu, child) for child in die.iter_children()
				if child.tag == 'DW_TAG_formal_parameter'] + P.text("stubCallCount++")
	callExp = mkDoc_exp_function_call(varFp, sequence(paramNamesCallback))
	thenBlock = P.block(P.text("static int stubCallCount = 0;") + P.newline() + (P.text("return ") if typeDie else P.empty()) + callExp + P.text(";"))
	# FIXME: use monad
	elseBlock = P.block(doc_stmt_return(value(mdoc_exp_call_default_type_value(cv))))
	if_stmt = doc_stmt_if(varFp, thenBlock, elseBlock)
	# return, name, params, block
	stub_function = doc_decl_function(returnType, name, params, P.block(if_stmt))

	# decl callback setter function
	# void XXX_StubWithCallback (STUBGEN_XXX_CALLBACK cb)
	setter = name + P.text('_StubWithCallback')
	setter_param = [varType + P.text(' cb')] 
	setter_body = P.block(varFp + P.text(' = cb;'))
	setter_function = doc_decl_function(P.text('void'), setter, setter_param, setter_body)
	return intersperse([decl_typedef_callback, decl_var_callback_fp, stub_function, setter_function], P.newline()) + P.newline()