Added custom arg transforms

This commit is contained in:
kevstone 2023-11-06 21:35:44 +00:00
parent 8dd9072c77
commit f9546a6835
5 changed files with 42 additions and 3 deletions

View File

@ -7,3 +7,5 @@ class AccessorSpecific:
def update_converters(self, converters):
return converters
def add_custom_transforms(self, transforms):
return transforms

View File

@ -1,6 +1,16 @@
from accessor_specific.default import AccessorSpecific
import arg
class BitDataAccessorSpecific(AccessorSpecific):
def __init__(self) -> None:
super().__init__()
custom_arg_transforms = {
arg.Arg("unsigned char*","mdata") : arg.Arg("DataPointer","mdata"),
}
def add_custom_transforms(self, transforms):
for carg, cpparg in self.custom_arg_transforms.items():
transforms.add_custom_args(carg, cpparg)
return transforms

View File

@ -13,6 +13,15 @@ class ArgConverter:
self._initial_carg = initial_carg
self._transforms = None
def transform_using_custom_types(self, carg):
# Do we have a custom arg transform to apply?
if carg in self._transforms.custom_args:
cpparg = self._transforms.custom_args[carg]
debug.line("transform_using_custom_types", f"Using custom arg transform: [{arg.arg_string(carg)}] -> [{arg.arg_string(cpparg)}]")
return cpparg
return CARG_NOT_FOUND
def transform_known_funcsig_types(self, carg):
if not carg.is_func_arg:
return CARG_NOT_FOUND
@ -125,6 +134,7 @@ class ArgConverter:
updated_carg._is_func_arg = self._initial_carg.is_func_arg
transform_funcs = [
self.transform_using_custom_types,
self.transform_known_funcsig_types,
self.transform_known_types,
self.transform_arrays,

View File

@ -52,7 +52,6 @@ common_funcsig_type_transforms = {
# These will be used if no other supplied...
common_type_transforms = {
# "unsigned char*" : "DataPointer",
"char**" : "std::string&",
"char*" : "std::string",
"char[]" : "std::string",
@ -179,6 +178,9 @@ class GribAccessorConverter:
self._transforms.add_to_types("supersuper", cpp_super_super_name)
# Add in any custom transforms
self._transforms = self._accessor_specific.add_custom_transforms(self._transforms)
def add_global_function(self):
global_func_funcsig_converter = self._converters[Converter.GLOBAL_FUNC_FUNCSIG](self._grib_accessor.global_function.func_sig)
mapping = global_func_funcsig_converter.create_funcsig_mapping(self._transforms)

View File

@ -22,6 +22,7 @@ class Transforms:
self._function_pointers = {}
self._all_args = {}
self._global_args = {}
self._custom_args = {}
self._members = {}
self._inherited_funcsig_mappings = []
self._private_funcsig_mappings = []
@ -98,14 +99,28 @@ class Transforms:
if carg in self._all_args:
assert self._all_args[carg] == cpparg, f"Updating an existing local arg transform: C Arg = {arg.arg_string(carg)} -> {arg.arg_string(cpparg)} Previous arg = {arg.arg_string(self._all_args[carg])}"
else:
debug.line("Transforms", f"Adding new local arg transform: {arg.arg_string(carg)} -> {arg.arg_string(cpparg)}")
assert carg, f"ADDING carg which is None!"
debug.line("Transforms", f"Adding new local arg transform: {arg.arg_string(carg)} -> {arg.arg_string(cpparg)}")
self._all_args[carg] = cpparg
def clear_local_args(self):
self._all_args.clear()
self._all_args = copy.copy(self._global_args)
# Custom args live in their own map which should not be used by external code
# It provides an override that is applied when add_local_args is called...
def add_custom_args(self, carg, cpparg):
if carg in self._custom_args:
assert self._custom_args[carg] == cpparg, f"Updating an existing custom arg transform: C Arg = {arg.arg_string(carg)} -> {arg.arg_string(cpparg)} Previous arg = {arg.arg_string(self._custom_args[carg])}"
else:
debug.line("Transforms", f"Adding new custom arg transform: {arg.arg_string(carg)} -> {arg.arg_string(cpparg)}")
assert carg, f"ADDING carg which is None!"
self._custom_args[carg] = cpparg
@property
def custom_args(self):
return self._custom_args
@property
def global_args(self):
return self._global_args