mirror of https://github.com/ecmwf/eccodes.git
Fixed funcsig arg mapping bug
This commit is contained in:
parent
74673d6220
commit
1ed85d67d6
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
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)
|
||||
|
|
|
@ -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"))
|
||||
conversion_pack.conversion_data.add_funcbody_arg_mapping(Arg("unsigned char*","mdata"), Arg("AccessorDataPointer","mdata"))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<double>",
|
||||
"grib_iarray*" : "std::vector<long>",
|
||||
"grib_sarray*" : "std::string",
|
||||
|
@ -20,37 +38,23 @@ grib_array_type_mappings = {
|
|||
"grib_vsarray*" : "std::vector<std::string>",
|
||||
}
|
||||
|
||||
grib_array_function_mappings = {
|
||||
"grib_darray" : "std::vector<double>",
|
||||
"grib_iarray" : "std::vector<long>",
|
||||
"grib_sarray" : "std::string",
|
||||
"grib_vdarray" : "std::vector<std::vector<double>>",
|
||||
"grib_viarray" : "std::vector<std::vector<long>>",
|
||||
"grib_vsarray" : "std::vector<std::string>",
|
||||
}
|
||||
|
||||
# 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)
|
||||
|
|
Loading…
Reference in New Issue