tools: translator: Add void* return value support (fixes #3591)
This commit is contained in:
parent
467a0d6a85
commit
330534a2e7
|
@ -1514,6 +1514,7 @@ class obj_argument:
|
||||||
if self.type.is_result_vector():
|
if self.type.is_result_vector():
|
||||||
# all vector types must be passed by reference
|
# all vector types must be passed by reference
|
||||||
if not self.type.is_byref():
|
if not self.type.is_byref():
|
||||||
|
print('ERROR: Invalid (vector not byref) type')
|
||||||
return 'invalid'
|
return 'invalid'
|
||||||
|
|
||||||
if self.type.is_result_vector_string():
|
if self.type.is_result_vector_string():
|
||||||
|
@ -1549,6 +1550,8 @@ class obj_argument:
|
||||||
# string single map type
|
# string single map type
|
||||||
if self.type.is_result_map_single():
|
if self.type.is_result_map_single():
|
||||||
if not self.type.is_byref():
|
if not self.type.is_byref():
|
||||||
|
print('ERROR: Invalid (single map not byref) type for %s' %
|
||||||
|
self.type.get_name())
|
||||||
return 'invalid'
|
return 'invalid'
|
||||||
if self.type.is_const():
|
if self.type.is_const():
|
||||||
return 'string_map_single_byref_const'
|
return 'string_map_single_byref_const'
|
||||||
|
@ -1557,11 +1560,14 @@ class obj_argument:
|
||||||
# string multi map type
|
# string multi map type
|
||||||
if self.type.is_result_map_multi():
|
if self.type.is_result_map_multi():
|
||||||
if not self.type.is_byref():
|
if not self.type.is_byref():
|
||||||
|
print('ERROR: Invalid (multi map not byref) type for %s' %
|
||||||
|
self.type.get_name())
|
||||||
return 'invalid'
|
return 'invalid'
|
||||||
if self.type.is_const():
|
if self.type.is_const():
|
||||||
return 'string_map_multi_byref_const'
|
return 'string_map_multi_byref_const'
|
||||||
return 'string_map_multi_byref'
|
return 'string_map_multi_byref'
|
||||||
|
|
||||||
|
print('ERROR: Invalid (unknown) type for %s' % self.type.get_name())
|
||||||
return 'invalid'
|
return 'invalid'
|
||||||
|
|
||||||
def get_retval_type(self):
|
def get_retval_type(self):
|
||||||
|
@ -1569,9 +1575,19 @@ class obj_argument:
|
||||||
if self.type.has_name():
|
if self.type.has_name():
|
||||||
raise Exception('Cannot be called for argument types')
|
raise Exception('Cannot be called for argument types')
|
||||||
|
|
||||||
|
# special case for void* return value (may also be const)
|
||||||
|
if self.type.get_type() == 'void' and self.type.is_byaddr():
|
||||||
|
return 'simple_byaddr'
|
||||||
|
|
||||||
# unsupported modifiers
|
# unsupported modifiers
|
||||||
if self.type.is_const() or self.type.is_byref() or \
|
if self.type.is_const():
|
||||||
self.type.is_byaddr():
|
print('ERROR: Invalid (const) type for retval')
|
||||||
|
return 'invalid'
|
||||||
|
if self.type.is_byref():
|
||||||
|
print('ERROR: Invalid (byref) type for retval')
|
||||||
|
return 'invalid'
|
||||||
|
if self.type.is_byaddr():
|
||||||
|
print('ERROR: Invalid (byaddr) type for retval')
|
||||||
return 'invalid'
|
return 'invalid'
|
||||||
|
|
||||||
# void types don't have a return value
|
# void types don't have a return value
|
||||||
|
@ -1596,6 +1612,7 @@ class obj_argument:
|
||||||
else:
|
else:
|
||||||
return prefix + 'ptr_diff'
|
return prefix + 'ptr_diff'
|
||||||
|
|
||||||
|
print('ERROR: Invalid (unknown) type for retval')
|
||||||
return 'invalid'
|
return 'invalid'
|
||||||
|
|
||||||
def get_retval_default(self, for_capi):
|
def get_retval_default(self, for_capi):
|
||||||
|
@ -1615,6 +1632,10 @@ class obj_argument:
|
||||||
type = self.get_retval_type()
|
type = self.get_retval_type()
|
||||||
if type == 'simple':
|
if type == 'simple':
|
||||||
return self.get_type().get_result_simple_default()
|
return self.get_type().get_result_simple_default()
|
||||||
|
elif type == 'simple_byaddr':
|
||||||
|
if for_capi:
|
||||||
|
return 'NULL'
|
||||||
|
return 'nullptr'
|
||||||
elif type == 'bool':
|
elif type == 'bool':
|
||||||
if for_capi:
|
if for_capi:
|
||||||
return '0'
|
return '0'
|
||||||
|
|
|
@ -325,7 +325,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names, base_scoped):
|
||||||
|
|
||||||
if retval_type != 'none':
|
if retval_type != 'none':
|
||||||
# has a return value
|
# has a return value
|
||||||
if retval_type == 'simple':
|
if retval_type == 'simple' or retval_type == 'simple_byaddr':
|
||||||
result += retval.get_type().get_result_simple_type()
|
result += retval.get_type().get_result_simple_type()
|
||||||
else:
|
else:
|
||||||
result += retval.get_type().get_type()
|
result += retval.get_type().get_type()
|
||||||
|
@ -446,7 +446,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names, base_scoped):
|
||||||
if retval_type != 'none':
|
if retval_type != 'none':
|
||||||
# has a return value
|
# has a return value
|
||||||
result += '\n // Return type: ' + retval_type
|
result += '\n // Return type: ' + retval_type
|
||||||
if retval_type == 'simple' or retval_type == 'bool':
|
if retval_type == 'simple' or retval_type == 'simple_byaddr' or retval_type == 'bool':
|
||||||
result += '\n return _retval;'
|
result += '\n return _retval;'
|
||||||
elif retval_type == 'string':
|
elif retval_type == 'string':
|
||||||
result += '\n return _retval.DetachToUserFree();'
|
result += '\n return _retval.DetachToUserFree();'
|
||||||
|
|
|
@ -342,6 +342,8 @@ def make_ctocpp_function_impl_new(clsname, name, func, base_scoped):
|
||||||
# has a return value
|
# has a return value
|
||||||
if retval_type == 'simple' or retval_type == 'bool':
|
if retval_type == 'simple' or retval_type == 'bool':
|
||||||
result += retval.get_type().get_result_simple_type_root()
|
result += retval.get_type().get_result_simple_type_root()
|
||||||
|
elif retval_type == 'simple_byaddr':
|
||||||
|
result += retval.get_type().get_result_simple_type()
|
||||||
elif retval_type == 'string':
|
elif retval_type == 'string':
|
||||||
result += 'cef_string_userfree_t'
|
result += 'cef_string_userfree_t'
|
||||||
elif retval_type == 'refptr_same' or retval_type == 'refptr_diff' or \
|
elif retval_type == 'refptr_same' or retval_type == 'refptr_diff' or \
|
||||||
|
@ -485,7 +487,7 @@ def make_ctocpp_function_impl_new(clsname, name, func, base_scoped):
|
||||||
if retval_type != 'none':
|
if retval_type != 'none':
|
||||||
# has a return value
|
# has a return value
|
||||||
result += '\n // Return type: ' + retval_type
|
result += '\n // Return type: ' + retval_type
|
||||||
if retval_type == 'simple':
|
if retval_type == 'simple' or retval_type == 'simple_byaddr':
|
||||||
result += '\n return _retval;'
|
result += '\n return _retval;'
|
||||||
elif retval_type == 'bool':
|
elif retval_type == 'bool':
|
||||||
result += '\n return _retval?true:false;'
|
result += '\n return _retval?true:false;'
|
||||||
|
|
Loading…
Reference in New Issue