Fixed bug with function_call conversion

This commit is contained in:
kevstone 2024-02-11 11:21:40 +00:00
parent 0824ea8865
commit 6813425c64
3 changed files with 28 additions and 20 deletions

View File

@ -5,6 +5,7 @@ from code_object.struct_member_access import StructMemberAccess
from code_object.literal import Literal
import code_object_converter.conversion_pack.buffer_mapping as buffer_mapping
import code_object_converter.conversion_pack.arg_utils as arg_utils
from code_object.code_interface import NONE_VALUE
class ContainerUtils:
def create_cpp_container_buffer_arg(self, name):
@ -45,7 +46,7 @@ class ContainerUtils:
# 2. Try standard arg conversions
cpparg = conversion_data.funcbody_cpparg_for_carg_name(cname)
if cpparg and conversion_data.is_container_type(cpparg.decl_spec.type):
if cpparg and cpparg != NONE_VALUE and conversion_data.is_container_type(cpparg.decl_spec.type):
return self.create_cpp_container_buffer_arg(cpparg.name)
return None

View File

@ -27,17 +27,23 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
debug.line("create_cpp_code_object", f"FunctionCallConverter [1] mapping.cfuncsig=[{debug.as_debug_string(mapping.cfuncsig)}] -> mapping.cppfuncsig=[{debug.as_debug_string(mapping.cppfuncsig)}]")
cpp_args = []
for i, arg_entry in enumerate(mapping.cppfuncsig.args):
debug.line("create_cpp_code_object", f"FunctionCallConverter [1] --> i=[{i}] arg_entry=[{debug.as_debug_string(arg_entry)}]")
debug.line("create_cpp_code_object", f"FunctionCallConverter [2] --> i=[{i}] arg_entry=[{debug.as_debug_string(arg_entry)}]")
if arg_entry != NONE_VALUE:
# We expect this argument to be converted to the C++ version, however, some calls don't always convert as expected.
# For example: [int grib_value_count(grib_accessor* a, long* count)] -> [GribStatus gribValueCount(AccessorPtr ptr, long& count)]
# This can be called with an accessor pointer if we're calling a different class instance, however if we're calling ourself it will be NONE_VALUE
# Therefore, if a value doesn't convert, we'll just use the C value (which we handle later)
cpp_arg_entry = conversion_funcs.convert_ccode_object(cfunction_call.args[i], conversion_pack)
assert cpp_arg_entry != NONE_VALUE, f"Expected cpp_arg_entry for carg=[{debug.as_debug_string(cfunction_call.args[i])}], got NoneValue!"
# Check if we have a container arg
cpp_arg_name = arg_utils.extract_name(cpp_arg_entry)
if cpp_arg_name:
cpp_container_arg = conversion_pack.container_utils.cname_to_cpp_container(cpp_arg_name, conversion_pack.conversion_data)
if cpp_container_arg:
cpp_arg_entry = cpp_container_arg
if cpp_arg_entry == NONE_VALUE:
cpp_arg_entry = arg_entry
debug.line("create_cpp_code_object", f"FunctionCallConverter [3] carg=[{debug.as_debug_string(cfunction_call.args[i])}] has no C++ conversion (may be a <self> arg), setting cpp_arg_entry=[{debug.as_debug_string(cpp_arg_entry)}]")
else:
# Check if we have a container arg
cpp_arg_name = arg_utils.extract_name(cpp_arg_entry)
if cpp_arg_name:
cpp_container_arg = conversion_pack.container_utils.cname_to_cpp_container(cpp_arg_name, conversion_pack.conversion_data)
if cpp_container_arg:
cpp_arg_entry = cpp_container_arg
cpp_args.append(cpp_arg_entry)
@ -46,7 +52,7 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
debug.line("create_cpp_code_object", f"cppfunction_call NOW EQUALS [{debug.as_debug_string(cppfunction_call)}]")
else:
debug.line("create_cpp_code_object", f"FunctionCallConverter [2]")
debug.line("create_cpp_code_object", f"FunctionCallConverter [4]")
# 2. Perform a manual conversion
cpp_name = conversion_funcs.convert_ccode_object(cfunction_call.name, conversion_pack)
cpp_args = []

View File

@ -21,19 +21,20 @@ class ValueDeclarationReferenceConverter(code_interface_converter.CodeInterfaceC
if cppfuncsig:
return value_declaration_reference.ValueDeclarationReference(cppfuncsig.name)
# 2. Check if it is an arg
cpparg = conversion_pack.conversion_data.funcbody_cpparg_for_carg_name(cdecl_ref_expr_value)
debug.line("create_cpp_code_object", f"ValueDeclarationReferenceConverter [2] cdecl_ref_expr_value=[{debug.as_debug_string(cdecl_ref_expr_value)}] cpparg=[{debug.as_debug_string(cpparg)}]")
# 2. Check if it is a mapped buffer (e.g. char *c, int* len => std::string& str)
cpp_container_arg = conversion_pack.container_utils.cname_to_cpp_container(cdecl_ref_expr_value, conversion_pack.conversion_data)
debug.line("create_cpp_code_object", f"ValueDeclarationReferenceConverter [2] cdecl_ref_expr_value=[{debug.as_debug_string(cdecl_ref_expr_value)}] cpp_container_arg=[{debug.as_debug_string(cpp_container_arg)}]")
if cpp_container_arg:
return cpp_container_arg #value_declaration_reference.ValueDeclarationReference(cpp_container_arg.as_string())
# 3. Check if it is an arg
#cpparg = conversion_pack.conversion_data.funcbody_cpparg_for_carg_name(cdecl_ref_expr_value)
cpparg = conversion_pack.conversion_data.cpparg_for_cname(cdecl_ref_expr_value)
debug.line("create_cpp_code_object", f"ValueDeclarationReferenceConverter [3] cdecl_ref_expr_value=[{debug.as_debug_string(cdecl_ref_expr_value)}] cpparg=[{debug.as_debug_string(cpparg)}]")
if cpparg == NONE_VALUE:
return NONE_VALUE
elif cpparg:
return value_declaration_reference.ValueDeclarationReference(cpparg.name)
# 3. Check if it is a mapped buffer (e.g. char *c, int* len => std::string& str)
cpp_container_arg = conversion_pack.container_utils.cname_to_cpp_container(cdecl_ref_expr_value, conversion_pack.conversion_data)
debug.line("create_cpp_code_object", f"ValueDeclarationReferenceConverter [3] cdecl_ref_expr_value=[{debug.as_debug_string(cdecl_ref_expr_value)}] cpp_container_arg=[{debug.as_debug_string(cpp_container_arg)}]")
if cpp_container_arg:
return cpp_container_arg #value_declaration_reference.ValueDeclarationReference(cpp_container_arg.as_string())
# 4. Perform a default conversion
cppdecl_ref_expr_value = conversion_funcs.convert_ccode_object(cdecl_ref_expr_value, conversion_pack)