From 1ed85d67d68c152f100a56e654ce6df2e7489bdc Mon Sep 17 00:00:00 2001 From: kevstone Date: Sat, 10 Feb 2024 10:25:14 +0000 Subject: [PATCH] Fixed funcsig arg mapping bug --- .../grib_accessor_ccode_converter.py | 12 ++-- .../base_conversion_pack_updates.py | 13 ++++- .../bit_conversion_pack_updates.py | 6 +- .../grib_accessor/supporting/arg_mappings.py | 29 ++++++++-- .../grib_accessor/supporting/type_mappings.py | 58 ++++++++++--------- 5 files changed, 73 insertions(+), 45 deletions(-) diff --git a/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py b/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py index d87b991a8..cc31b65a1 100755 --- a/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py +++ b/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py @@ -20,7 +20,7 @@ import grib_accessor.supporting.arg_mappings as arg_mappings import grib_accessor.supporting.data_member_mappings as data_member_mappings import grib_accessor.grib_accessor_conversion_pack.grib_accessor_type_info as grib_accessor_type_info import grib_accessor.grib_accessor_conversion_pack.grib_accessor_container_utils as grib_accessor_container_utils -from code_object.data_member import DataMember +import grib_accessor.grib_accessor_conversion_pack.conversion_pack_updates.base_conversion_pack_updates as base_conversion_pack_updates prefix = "grib_accessor_class_" rename = { @@ -71,17 +71,13 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter): accessor_conversion_pack_updates_class_name = standard_transforms.transform_type_name(accessor_conversion_pack_updates_mod_name) accessor_conversion_pack_updates_class = getattr(accessor_conversion_pack_updates_lib, accessor_conversion_pack_updates_class_name) debug.line("function_specific_conversion_pack_updates", f"Loaded accessor_conversion_pack_updates_class_name=[{accessor_conversion_pack_updates_class_name}]") - updates_class_inst = accessor_conversion_pack_updates_class() - updates_class_inst.apply_updates_for_cfunction(cfunction_name, self._conversion_pack) except ModuleNotFoundError: - debug.line("function_specific_conversion_pack_updates", f"Could not find accessor_conversion_pack_updates_lib_name=[{accessor_conversion_pack_updates_lib_name}]") + debug.line("function_specific_conversion_pack_updates", f"Could not find accessor_conversion_pack_updates_lib_name=[{accessor_conversion_pack_updates_lib_name}], using base version") + updates_class_inst = base_conversion_pack_updates.BaseConversionPackUpdates() - # Add cclass->super data member mapping - cmember = DataMember("grib_accessor_class**", "cclass->super") - cppmember = DataMember("AccessorData", self._conversion_pack.conversion_data.info.super_class_name) - self._conversion_pack.conversion_data.add_data_member_mapping(cmember, cppmember) + updates_class_inst.apply_updates_for_cfunction(cfunction_name, self._conversion_pack) super().function_specific_conversion_pack_updates(cfunction_name) diff --git a/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/base_conversion_pack_updates.py b/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/base_conversion_pack_updates.py index fcd6e5fa9..3eac8cc6f 100755 --- a/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/base_conversion_pack_updates.py +++ b/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/base_conversion_pack_updates.py @@ -1,5 +1,8 @@ import utils.debug as debug +from code_object.data_member import DataMember +from code_object.arg import Arg +from code_object.code_interface import NONE_VALUE class BaseConversionPackUpdates: def __init__(self) -> None: @@ -8,7 +11,7 @@ class BaseConversionPackUpdates: # Use this entry point to call the appropriate derived function def apply_updates_for_cfunction(self, cfuncname, conversion_pack): - self.apply_updates_for_all_functions() + self.apply_updates_for_all_functions(conversion_pack) for name, update_func in self._update_funcs.items(): if name == cfuncname: @@ -17,5 +20,9 @@ class BaseConversionPackUpdates: # Override to set the same update for all functions # NOTE: Doesn't apply to global definition - def apply_updates_for_all_functions(self): - pass \ No newline at end of file + def apply_updates_for_all_functions(self, conversion_pack): + # Default data member mappings + for cmember, cppmember in { + DataMember("grib_accessor_class**", "cclass->super"): DataMember("AccessorData", conversion_pack.conversion_data.info.super_class_name), + }.items(): + conversion_pack.conversion_data.add_data_member_mapping(cmember, cppmember) diff --git a/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/bit_conversion_pack_updates.py b/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/bit_conversion_pack_updates.py index ec4080bd5..1267e2b60 100755 --- a/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/bit_conversion_pack_updates.py +++ b/src/clang_convert/grib_accessor/grib_accessor_conversion_pack/conversion_pack_updates/bit_conversion_pack_updates.py @@ -7,9 +7,9 @@ class BitConversionPackUpdates(base_conversion_pack_updates.BaseConversionPackUp def __init__(self) -> None: super().__init__() - self._update_funcs = { + self._update_funcs.extend({ "pack_long": self.apply_updates_for_pack_long - } + }) def apply_updates_for_pack_long(self, conversion_pack): - conversion_pack.conversion_data.add_funcbody_arg_mapping(Arg("unsigned char*","mdata"), Arg("AccessorDataPointer","mdata")) \ No newline at end of file + conversion_pack.conversion_data.add_funcbody_arg_mapping(Arg("unsigned char*","mdata"), Arg("AccessorDataPointer","mdata")) diff --git a/src/clang_convert/grib_accessor/supporting/arg_mappings.py b/src/clang_convert/grib_accessor/supporting/arg_mappings.py index 466518338..923133773 100755 --- a/src/clang_convert/grib_accessor/supporting/arg_mappings.py +++ b/src/clang_convert/grib_accessor/supporting/arg_mappings.py @@ -2,14 +2,35 @@ from code_object.arg import Arg from code_object.declaration_specifier import DeclSpec import code_object_converter.conversion_pack.conversion_data as conversion_data +from code_object.code_interface import NONE_VALUE + +# ==================== FUNCSIG ARG MAPPINGS: Begin ==================== + +common_funcsig_arg_mappings = { + Arg("grib_accessor*", "a") : NONE_VALUE, +} + +def add_funcsig_arg_mappings_to_conversion_data(conversion_data): + for funcsig_arg_mappings in [common_funcsig_arg_mappings]: + for carg, cpparg in funcsig_arg_mappings.items(): + conversion_data.add_funcsig_arg_mapping(carg, cpparg) + +# ==================== FUNCSIG ARG MAPPINGS: End ==================== + +# ==================== FUNCBODY ARG MAPPINGS: Begin ==================== -# These will be used if no other supplied... common_funcbody_arg_mappings = { Arg("int", "err") : Arg("GribStatus", "err"), Arg("int", "ret") : Arg("GribStatus", "ret"), } -def add_arg_mappings_to_conversion_data(conversion_data): +def add_funcbody_arg_mappings_to_conversion_data(conversion_data): for funcbody_arg_mappings in [common_funcbody_arg_mappings]: - for key, value in funcbody_arg_mappings.items(): - conversion_data.add_funcbody_arg_mapping(key, value) + for carg, cpparg in funcbody_arg_mappings.items(): + conversion_data.add_funcbody_arg_mapping(carg, cpparg) + +# ==================== FUNCBODY ARG MAPPINGS: End ==================== + +def add_arg_mappings_to_conversion_data(conversion_data): + add_funcsig_arg_mappings_to_conversion_data(conversion_data) + add_funcbody_arg_mappings_to_conversion_data(conversion_data) diff --git a/src/clang_convert/grib_accessor/supporting/type_mappings.py b/src/clang_convert/grib_accessor/supporting/type_mappings.py index a75f07564..d8f2416b5 100755 --- a/src/clang_convert/grib_accessor/supporting/type_mappings.py +++ b/src/clang_convert/grib_accessor/supporting/type_mappings.py @@ -3,7 +3,25 @@ from code_object.arg import Arg from code_object.declaration_specifier import DeclSpec import code_object_converter.conversion_pack.conversion_data as conversion_data -common_grib_type_mappings = { +# ==================== FUNCSIG TYPE MAPPINGS: Begin ==================== + +common_funcsig_type_mappings = { + "char*" : "std::string&", + "char[]" : "std::string&", +} + +def add_funcsig_type_mappings_to_conversion_data(conversion_data): + for type_mappings in [common_funcsig_type_mappings]: + for ctype, cpptype in type_mappings.items(): + cdecl_spec = DeclSpec.from_decl_specifier_seq(ctype) + cppdecl_spec = DeclSpec.from_decl_specifier_seq(cpptype) + conversion_data.add_funcsig_type_mapping(cdecl_spec, cppdecl_spec) + +# ==================== FUNCSIG TYPE MAPPINGS: End ==================== + +# ==================== FUNCBODY TYPE MAPPINGS: Begin ==================== + +common_grib_funcbody_type_mappings = { "grib_accessor*" : "AccessorPtr", "grib_handle*" : DeclSpec.NONE, "grib_context*" : DeclSpec.NONE, @@ -11,7 +29,7 @@ common_grib_type_mappings = { "grib_codetable*" : "GribCodeTablePtr", } -grib_array_type_mappings = { +grib_array_funcbody_type_mappings = { "grib_darray*" : "std::vector", "grib_iarray*" : "std::vector", "grib_sarray*" : "std::string", @@ -20,37 +38,23 @@ grib_array_type_mappings = { "grib_vsarray*" : "std::vector", } -grib_array_function_mappings = { - "grib_darray" : "std::vector", - "grib_iarray" : "std::vector", - "grib_sarray" : "std::string", - "grib_vdarray" : "std::vector>", - "grib_viarray" : "std::vector>", - "grib_vsarray" : "std::vector", -} - # These will be used if no other supplied... -common_type_mappings = { +common_funcbody_type_mappings = { "char**" : "std::string&", "char*" : "std::string", "char[]" : "std::string", "FILE*" : "FILE*", } -common_function_arg_type_mappings = { - "char*" : "std::string&", - "char[]" : "std::string&", -} - -def add_type_mappings_to_conversion_data(conversion_data): - for type_mappings in [common_grib_type_mappings, grib_array_type_mappings, common_type_mappings]: - for key, value in type_mappings.items(): - cdecl_spec = DeclSpec.from_decl_specifier_seq(key) - cppdecl_spec = DeclSpec.from_decl_specifier_seq(value) +def add_funcbody_type_mappings_to_conversion_data(conversion_data): + for type_mappings in [common_grib_funcbody_type_mappings, grib_array_funcbody_type_mappings, common_funcbody_type_mappings]: + for ctype, cpptype in type_mappings.items(): + cdecl_spec = DeclSpec.from_decl_specifier_seq(ctype) + cppdecl_spec = DeclSpec.from_decl_specifier_seq(cpptype) conversion_data.add_funcbody_type_mapping(cdecl_spec, cppdecl_spec) - for type_mappings in [common_function_arg_type_mappings]: - for key, value in type_mappings.items(): - cdecl_spec = DeclSpec.from_decl_specifier_seq(key) - cppdecl_spec = DeclSpec.from_decl_specifier_seq(value) - conversion_data.add_funcsig_type_mapping(cdecl_spec, cppdecl_spec) +# ==================== FUNCBODY TYPE MAPPINGS: End ==================== + +def add_type_mappings_to_conversion_data(conversion_data): + add_funcsig_type_mappings_to_conversion_data(conversion_data) + add_funcbody_type_mappings_to_conversion_data(conversion_data)