Eolian: Small refactoring

This commit is contained in:
Kai Huuhko 2014-06-26 23:11:43 +03:00
parent 7222158dfd
commit 7810bcb216
1 changed files with 20 additions and 26 deletions

View File

@ -212,6 +212,20 @@ class PyxGenerator(Generator):
self.write("%s %s" % (t, ", ".join(names)))
self.dedent()
def c_call_write(self, name, params, ret_type, ret_param, legacy=False):
if legacy:
c_call = "%s(%s)" % (name, ", ".join(("self.obj", params)))
else:
c_call = "eo_do(self.obj, %s(%s))" % (name, params)
if ret_type:
r_type = ret_type
if r_type in return_type_mapping:
conv = return_type_mapping[r_type][1]
if conv:
c_call = conv.format(c_call)
c_call = ret_param + " = " + c_call
self.write(c_call)
class Method(object):
@ -305,29 +319,6 @@ class Method(object):
return self
def eo_call_generate(self, params, ret_param):
c_call = "eo_do(self.obj, %s(%s))" % (self.c_name, params)
if self.ret_type:
r_type = self.ret_type
if r_type in return_type_mapping:
conv = return_type_mapping[r_type][1]
if conv:
c_call = conv.format(c_call)
c_call = ret_param + " = " + c_call
return c_call
def legacy_call_generate(self, params, ret_param):
c_call = "%s(%s)" % (
self.c_name, ", ".join(("self.obj", params)))
if self.ret_type:
r_type = self.ret_type
if r_type in return_type_mapping:
conv = return_type_mapping[r_type][1]
if conv:
c_call = conv.format(c_call)
c_call = ret_param + " = " + c_call
return c_call
def pyx_generate(self, gen, param_conv=None):
gen.method_header_write(self.py_name, self.py_params)
gen.indent()
@ -369,12 +360,15 @@ class Method(object):
c_params = ", ".join([c[1] for c in self.c_params])
if self.eo_prefix:
c_call = self.eo_call_generate(c_params, RET_PARAM)
gen.c_call_write(
self.c_name, c_params, self.ret_type, RET_PARAM, legacy=False
)
elif self.legacy_prefix:
c_call = self.legacy_call_generate(c_params, RET_PARAM)
gen.c_call_write(
self.c_name, c_params, self.ret_type, RET_PARAM, legacy=True
)
else:
raise ValueError("no prefix found for %r" % (self.name))
gen.write(c_call)
if self.returns:
ret = self.returns[:]