diff --git a/src/clang_convert/code_object_converter/conversion_pack/conversion_data.py b/src/clang_convert/code_object_converter/conversion_pack/conversion_data.py index 483db9ccd..47c4eaafa 100755 --- a/src/clang_convert/code_object_converter/conversion_pack/conversion_data.py +++ b/src/clang_convert/code_object_converter/conversion_pack/conversion_data.py @@ -170,9 +170,12 @@ class ConversionData: cppargs = [] for entry in cppfunction_call.args: cppname = arg_utils.extract_name(entry) - cpparg = self.cpparg_for_cname(cppname) if cppname else None + if not cppname: + debug.line("add_cppfunction_call", f"Couldn't deduce name for entry=[{debug.as_debug_string(entry)}] cppfunction_call=[{debug.as_debug_string(cppfunction_call)}]") + return + + cpparg = self.cpparg_for_cname(cppname) debug.line("add_cppfunction_call", f"[{debug.as_debug_string(cppfunction_call)}]---> entry type=[{type(entry)}] value=[{debug.as_debug_string(entry)}] cppname=[{debug.as_debug_string(cppname)}] cpparg=[{debug.as_debug_string(cpparg)}]") - assert cppname if cpparg and cpparg != NONE_VALUE: cppargs.append(cpparg) diff --git a/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/grib_accessor_conversion_validation.py b/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/grib_accessor_conversion_validation.py index 7593bfd28..a40a38202 100755 --- a/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/grib_accessor_conversion_validation.py +++ b/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/grib_accessor_conversion_validation.py @@ -144,24 +144,29 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv debug.line("validate_return_statement", f"creturn_statement=[{debug.as_debug_string(creturn_statement)}] cppreturn_statement=[{debug.as_debug_string(cppreturn_statement)}]") - mapping = self._conversion_data.funcsig_mapping_for_current_cfuncname() - if mapping: - cppfunc_return_type = mapping.cppfuncsig.return_type.type - cpparg = arg_utils.to_cpparg(cppreturn_statement.expression, self._conversion_data) - updated_cpp_expression = None + if isinstance(cppreturn_statement.expression, function_call.FunctionCall): + debug.line("validate_return_statement", f"cppreturn_statement.expression is a function call, assuming the function returns the correct type") + else: + mapping = self._conversion_data.funcsig_mapping_for_current_cfuncname() + if mapping: + cppfunc_return_type = mapping.cppfuncsig.return_type.type + cpparg = arg_utils.to_cpparg(cppreturn_statement.expression, self._conversion_data) + updated_cpp_expression = None - if cpparg: - if cpparg.decl_spec.type != cppfunc_return_type: - updated_cpp_expression = literal.Literal(f"static_cast({cpparg.name})") - elif cppfunc_return_type == "GribStatus": - cpp_expression = cppreturn_statement.expression.as_string() - if cpp_expression == "0": - updated_cpp_expression = literal.Literal("GribStatus::SUCCESS") - elif not cpp_expression.startswith("GribStatus"): - updated_cpp_expression = literal.Literal(f"static_cast({cpp_expression})") + debug.line("validate_return_statement", f"RETURN DEBUG: cppreturn_statement.expression=[{type(cppreturn_statement.expression)}]") - if updated_cpp_expression: - return return_statement.ReturnStatement(updated_cpp_expression) + if cpparg: + if cpparg.decl_spec.type != cppfunc_return_type: + updated_cpp_expression = literal.Literal(f"static_cast({cpparg.name})") + elif cppfunc_return_type == "GribStatus": + cpp_expression = cppreturn_statement.expression.as_string() + if cpp_expression == "0": + updated_cpp_expression = literal.Literal("GribStatus::SUCCESS") + elif not cpp_expression.startswith("GribStatus"): + updated_cpp_expression = literal.Literal(f"static_cast({cpp_expression})") + + if updated_cpp_expression: + return return_statement.ReturnStatement(updated_cpp_expression) return super().validate_return_statement(creturn_statement, cppreturn_statement)