mirror of https://github.com/ecmwf/eccodes.git
Automatically detect if member function is non-const
This commit is contained in:
parent
ea6fa100c6
commit
e23dcdd798
|
@ -392,6 +392,11 @@ class ConversionData:
|
|||
self._info.add_function_call_entry(cppfuncsig)
|
||||
debug.line("add_cppfunction_call", f"Added function call cppfunction_call=[{debug.as_debug_string(cppfunction_call)}] -> cppfuncsig=[{debug.as_debug_string(cppfuncsig)}]")
|
||||
|
||||
def set_current_cfuncname_non_const(self):
|
||||
self._info.add_non_const_member_function_name(self._current_cfuncname)
|
||||
debug.line("set_current_cfuncname_non_const", f"Set function name=[{self._current_cfuncname}] to non-const")
|
||||
|
||||
|
||||
# ------------------------------ QUERY ------------------------------
|
||||
|
||||
# Given the cppname, search all stores to see if an arg exists
|
||||
|
@ -426,6 +431,13 @@ class ConversionData:
|
|||
|
||||
return None
|
||||
|
||||
def is_cppdata_member(self, cppdata_member_name):
|
||||
for mapping in self.all_mappings():
|
||||
for key, value in mapping.data_member_mappings.items():
|
||||
if value and value.name == cppdata_member_name:
|
||||
return True
|
||||
return False
|
||||
|
||||
def cppdata_member_for_cdata_member(self, cmember):
|
||||
for mapping in self.all_mappings():
|
||||
for key, value in mapping.data_member_mappings.items():
|
||||
|
@ -480,7 +492,6 @@ class ConversionData:
|
|||
|
||||
return False
|
||||
|
||||
|
||||
def is_self_class_pointer_name(self, name):
|
||||
debug.line("is_self_class_pointer_name", f"Testing name=[{debug.as_debug_string(name)}]")
|
||||
for mapping in self.all_mappings():
|
||||
|
|
|
@ -16,6 +16,7 @@ class CodeInfo:
|
|||
self._header_includes = []
|
||||
self._source_includes = []
|
||||
self._function_calls = [] # List all function calls made whilst converting (for post-processing)
|
||||
self._non_const_member_function_names = [] # default to const unless told otherwise!
|
||||
|
||||
@property
|
||||
def file_name(self):
|
||||
|
@ -53,6 +54,10 @@ class CodeInfo:
|
|||
def function_calls(self):
|
||||
return self._function_calls
|
||||
|
||||
@property
|
||||
def non_const_member_function_names(self):
|
||||
return self._non_const_member_function_names
|
||||
|
||||
def add_namespace(self, entry):
|
||||
self._namespaces.append(entry)
|
||||
|
||||
|
@ -77,3 +82,7 @@ class CodeInfo:
|
|||
return # Duplicate
|
||||
|
||||
self._function_calls.append(entry)
|
||||
|
||||
def add_non_const_member_function_name(self, name):
|
||||
if name not in self._non_const_member_function_names:
|
||||
self._non_const_member_function_names.append(name)
|
||||
|
|
|
@ -157,7 +157,14 @@ class DefaultConversionValidation(conversion_validation.ConversionValidation):
|
|||
cppleft.index = "[0]"
|
||||
debug.line("validate_binary_operation", f"Assigning number to container, so updating it to access first element: cppleft=[{debug.as_debug_string(cppleft)}] cppright_value=[{cppright_value}]")
|
||||
return binary_operation.BinaryOperation(cppleft, cppbinary_op, cppright)
|
||||
|
||||
# Check if we're assigning to a data member and need to ensure the function is non-const
|
||||
data_member_name = cppleft.name
|
||||
debug.line("validate_binary_operation", f"CHECK is_cppdata_member({data_member_name})")
|
||||
|
||||
if self._conversion_data.is_cppdata_member(data_member_name):
|
||||
self._conversion_data.set_current_cfuncname_non_const()
|
||||
|
||||
elif cppbinary_op.is_comparison():
|
||||
cpparg = arg_utils.to_cpparg(cppleft, self._conversion_data)
|
||||
if cpparg and self._conversion_data.is_container_type(cpparg.decl_spec.type):
|
||||
|
|
|
@ -171,6 +171,9 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter):
|
|||
if conv_pack.conversion_data.is_virtual_member_function(function_name):
|
||||
return function_name in virtual_member_functions.const_virtual_member_function_names
|
||||
|
||||
if function_name in self._code_info.non_const_member_function_names:
|
||||
return False
|
||||
|
||||
if conv_pack.conversion_data.is_member_function(function_name):
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in New Issue