mirror of https://github.com/ecmwf/eccodes.git
Updates to assist with return code processing...
This commit is contained in:
parent
2123683e85
commit
c7fd597563
|
@ -25,17 +25,22 @@ class ConversionData:
|
|||
# Call this to ensure local state is set ready for function conversions
|
||||
def set_local_state(self):
|
||||
self._state = ConversionDataState.LOCAL
|
||||
self.reset_local_state()
|
||||
self.reset_local_state("")
|
||||
|
||||
# Clear out / reset local state data ready to convert a new function
|
||||
def reset_local_state(self):
|
||||
# Clear out / reset local state data ready to convert a new function (cfuncname)
|
||||
def reset_local_state(self, cfuncname):
|
||||
self._local_mappings = code_mappings.CodeMappings()
|
||||
|
||||
self.info.current_cfuncname = cfuncname
|
||||
debug.line("reset_local_state", f"cfuncname=[{cfuncname}]")
|
||||
|
||||
# The info object can be manipulated directly
|
||||
@property
|
||||
def info(self):
|
||||
return self._info
|
||||
|
||||
@property
|
||||
def current_cfuncname(self):
|
||||
return self._info.current_cfuncname
|
||||
|
||||
# ============================== Functions to update the mappings: start ==============================
|
||||
|
||||
|
@ -46,6 +51,8 @@ class ConversionData:
|
|||
else:
|
||||
return self._global_mappings
|
||||
|
||||
|
||||
|
||||
def add_funcbody_type_mapping(self, cdecl_spec, cppdecl_spec):
|
||||
assert isinstance(cdecl_spec, DeclSpec), f"Expected DeclSpec, got [{cdecl_spec}]"
|
||||
assert isinstance(cppdecl_spec, DeclSpec) or cppdecl_spec==DeclSpec.NONE, f"Expected DeclSpec, got [{cppdecl_spec}]"
|
||||
|
|
|
@ -9,6 +9,8 @@ class ConversionPack:
|
|||
self._conversion_validation = conversion_validation
|
||||
self._container_utils = container_utils
|
||||
|
||||
self._conversion_validation.set_conversion_pack(self)
|
||||
|
||||
@property
|
||||
def conversion_data(self):
|
||||
return self._conversion_data
|
||||
|
|
|
@ -6,8 +6,14 @@ import utils.debug as debug
|
|||
# Holds a reference to the conversion_data (part of the containing conversion_pack class)
|
||||
# This is the interface, override as required...
|
||||
class ConversionValidation:
|
||||
def __init__(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# NOTE: This is a reference back to the containing conversion_pack!
|
||||
def set_conversion_pack(self, conversion_pack):
|
||||
self._conversion_pack = conversion_pack
|
||||
self._conversion_data = self._conversion_pack.conversion_data
|
||||
self._container_utils = self._conversion_pack.container_utils
|
||||
|
||||
# ---------- CodeObject Validation : Begin -----------------------------------------------------
|
||||
# Perform full validation of converted C++ function call
|
||||
|
|
|
@ -41,4 +41,4 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
cppfunction_call = function_call.FunctionCall(cpp_name, cpp_args)
|
||||
|
||||
# 3. Apply validation (and special handling)
|
||||
return conversion_pack.conversion_validation.validate_function_call(cfunction_call, cppfunction_call, mapping)
|
||||
return conversion_pack.conversion_validation.validate_function_call(cfunction_call, cppfunction_call)
|
||||
|
|
|
@ -11,6 +11,9 @@ class CodeInfo:
|
|||
self._forward_declarations = []
|
||||
self._header_includes = []
|
||||
self._source_includes = []
|
||||
|
||||
# Access directly to set/get the name of the c function currently being processed
|
||||
self.current_cfuncname = ""
|
||||
|
||||
@property
|
||||
def file_name(self):
|
||||
|
|
|
@ -43,7 +43,7 @@ class DefaultCCodeConverter:
|
|||
self._code_info = self.create_code_info()
|
||||
self._code_elements = code_elements.CodeElements()
|
||||
conv_data = self.create_conversion_data()
|
||||
conv_validation = self.create_conversion_validation(conv_data)
|
||||
conv_validation = self.create_conversion_validation()
|
||||
container_utils = self.create_container_utils()
|
||||
self._conversion_pack = conversion_pack.ConversionPack(conv_data, conv_validation, container_utils)
|
||||
|
||||
|
@ -69,8 +69,8 @@ class DefaultCCodeConverter:
|
|||
def set_custom_conversion_data(self, conv_data):
|
||||
pass
|
||||
|
||||
def create_conversion_validation(self, conv_data):
|
||||
return DefaultConversionValidation(conv_data)
|
||||
def create_conversion_validation(self):
|
||||
return DefaultConversionValidation()
|
||||
|
||||
def create_container_utils(self):
|
||||
return default_container_utils.DefaultContainerUtils()
|
||||
|
@ -105,7 +105,7 @@ class DefaultCCodeConverter:
|
|||
|
||||
# Helper to ensure the function is converted correctly, including resetting the local conversion data!
|
||||
def to_cpp_function(self, func):
|
||||
self._conversion_pack.conversion_data.reset_local_state()
|
||||
self._conversion_pack.conversion_data.reset_local_state(func.funcsig.name)
|
||||
self.function_specific_conversion_pack_updates(func.funcsig.name)
|
||||
cpp_func = conversion_funcs.convert_ccode_object(func, self._conversion_pack)
|
||||
if isinstance(cpp_func, member_function.MemberFunction):
|
||||
|
|
|
@ -9,15 +9,21 @@ import re
|
|||
import code_object.binary_operation as binary_operation
|
||||
import code_object.struct_member_access as struct_member_access
|
||||
import code_object_converter.conversion_pack.arg_utils as arg_utils
|
||||
import code_object_converter.conversion_pack.container_utils as container_utils
|
||||
|
||||
# Pass this to the conversion_data object to be accessed by the conversion routines
|
||||
class DefaultConversionValidation(conversion_validation.ConversionValidation):
|
||||
|
||||
def validate_function_call(self, cfunction_call, cppfunction_call, callee_funcsig_mapping):
|
||||
if callee_funcsig_mapping:
|
||||
def validate_function_call(self, cfunction_call, cppfunction_call):
|
||||
|
||||
# See if there is an existing mapping defined
|
||||
mapping = self._conversion_data.funcsig_mapping_for_cfuncname(cfunction_call.name)
|
||||
|
||||
debug.line("validate_function_call", f"cfunction_call=[{debug.as_debug_string(cfunction_call)}] cppfunction_call=[{debug.as_debug_string(cppfunction_call)}] mapping=[{mapping}]")
|
||||
|
||||
if mapping:
|
||||
debug.line("validate_function_call", f"mapping.cfuncsig=[{debug.as_debug_string(mapping.cfuncsig)}] mapping.cppfuncsig=[{debug.as_debug_string(mapping.cppfuncsig)}]")
|
||||
cpp_args = []
|
||||
for arg_entry in callee_funcsig_mapping.cppfuncsig.args:
|
||||
for arg_entry in mapping.cppfuncsig.args:
|
||||
if arg_entry != NONE_VALUE:
|
||||
# The size of cpp_args should be the same as the next valid index :-)
|
||||
cpp_arg_entry = self.validate_function_call_arg(cppfunction_call.args[len(cpp_args)], arg_entry)
|
||||
|
@ -29,7 +35,7 @@ class DefaultConversionValidation(conversion_validation.ConversionValidation):
|
|||
|
||||
if cfunction_call.name == "strlen":
|
||||
# Replace the function call with a StructMemberAccess representing the container.size() call...
|
||||
return container_utils.create_cpp_container_length_arg(cppfunction_call.args[0].name)
|
||||
return self._container_utils.create_cpp_container_length_arg(cppfunction_call.args[0].name)
|
||||
|
||||
return cppfunction_call
|
||||
|
||||
|
@ -69,7 +75,7 @@ class DefaultConversionValidation(conversion_validation.ConversionValidation):
|
|||
m = re.search(rf"sizeof\(([^\)]+)\)\s*/\s*sizeof\((\*\1\)|(\1\[0\]\)))", cvalue)
|
||||
if m:
|
||||
cname = m.group(1)
|
||||
cpp_container_arg = container_utils.cname_to_cpp_container_length(cname, self._conversion_data)
|
||||
cpp_container_arg = self._container_utils.cname_to_cpp_container_length(cname, self._conversion_data)
|
||||
debug.line("validate_binary_operation", f"sizeof(x)/sizeof(*x) x=[{cname}] cpp_container_arg=[{debug.as_debug_string(cpp_container_arg)}]")
|
||||
if cpp_container_arg:
|
||||
return cpp_container_arg
|
||||
|
|
|
@ -64,7 +64,7 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter):
|
|||
|
||||
# See if we have an Accessor-specific validator (e.g. ProjStringValidation),
|
||||
# Otherwise use the default
|
||||
def create_conversion_validation(self, conv_data):
|
||||
def create_conversion_validation(self,):
|
||||
validators_path="grib_accessor.grib_accessor_conversion_pack.validators"
|
||||
cclass_short_name = self._ccode.class_name.replace(prefix, "")
|
||||
accessor_validator_mod_name = f"{cclass_short_name}_validation"
|
||||
|
@ -76,11 +76,11 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter):
|
|||
accessor_validator_class_name = standard_transforms.transform_type_name(accessor_validator_mod_name)
|
||||
accessor_validation_class = getattr(accessor_validator_lib, accessor_validator_class_name)
|
||||
debug.line("create_conversion_validation", f"Loaded accessor_validator class name=[{accessor_validator_class_name}]")
|
||||
return accessor_validation_class(conv_data)
|
||||
return accessor_validation_class()
|
||||
except ModuleNotFoundError:
|
||||
debug.line("create_conversion_validation", f"Could not find accessor_validator lib name=[{accessor_validator_lib_name}] - using default")
|
||||
|
||||
return GribAccessorConversionValidation(conv_data)
|
||||
return GribAccessorConversionValidation()
|
||||
|
||||
def create_container_utils(self):
|
||||
return grib_accessor_container_utils.GribAccessorContainerUtils()
|
||||
|
|
|
@ -16,12 +16,12 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
|
|||
def type_info(self):
|
||||
return grib_accessor_type_info.GribAccessorTypeInfo()
|
||||
|
||||
def validate_function_call(self, cfunction_call, cppfunction_call, callee_funcsig_mapping):
|
||||
def validate_function_call(self, cfunction_call, cppfunction_call):
|
||||
special_function_call = apply_special_function_call_conversions(cfunction_call, cppfunction_call)
|
||||
if special_function_call:
|
||||
return special_function_call
|
||||
|
||||
return super().validate_function_call(cfunction_call, cppfunction_call, callee_funcsig_mapping)
|
||||
return super().validate_function_call(cfunction_call, cppfunction_call)
|
||||
|
||||
def validate_function_call_arg(self, calling_arg_value, target_arg):
|
||||
|
||||
|
|
9125
src/debug.txt
9125
src/debug.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue