mirror of https://github.com/ecmwf/eccodes.git
Fixed issue with member variable conversion
This commit is contained in:
parent
5b4e8a9b33
commit
61ad744fcf
|
@ -90,6 +90,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
debug.line("create_funcsig_cpparg", f"Arg conversion arg mapping: [{debug.as_debug_string(carg)}] -> [{debug.as_debug_string(cpp_arg)}]")
|
||||
|
||||
return cpp_arg
|
||||
|
||||
def convert_funcbody_arg(self):
|
||||
carg = self._ccode_object
|
||||
|
||||
|
|
|
@ -202,6 +202,7 @@ class ConversionData:
|
|||
def funcbody_cpparg_for_carg(self, carg):
|
||||
for mapping in self.all_mappings():
|
||||
for key, value in mapping.funcbody_arg_mappings.items():
|
||||
debug.line("funcbody_cpparg_for_carg", f"key=[{debug.as_debug_string(key)}] value=[{debug.as_debug_string(value)}]")
|
||||
if key.name == carg.name:
|
||||
return value
|
||||
return None
|
||||
|
@ -230,6 +231,7 @@ class ConversionData:
|
|||
def cppdata_member_for_cdata_member(self, cmember):
|
||||
for mapping in self.all_mappings():
|
||||
for key, value in mapping.data_member_mappings.items():
|
||||
debug.line("cppdata_member_for_cdata_member", f"key=[{debug.as_debug_string(key)}] value=[{debug.as_debug_string(value)}]")
|
||||
if key.name == cmember.name:
|
||||
return value
|
||||
return None
|
||||
|
|
|
@ -15,6 +15,29 @@ class DataMemberConverter(arg_converter.ArgConverter):
|
|||
assert isinstance(ccode_object, data_member.DataMember), f"Expected DataMember, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpparg = super().create_cpp_code_object(conversion_pack)
|
||||
self._conversion_pack = conversion_pack
|
||||
cmember = self._ccode_object
|
||||
debug.line("create_cpp_code_object", f"DataMemberConverter [IN] cmember=[{debug.as_debug_string(cmember)}]")
|
||||
|
||||
return data_member.DataMember(cpparg.decl_spec, cpparg.name, self._ccode_object.mutable)
|
||||
cppmember = self._conversion_pack.conversion_data.cppdata_member_for_cdata_member(self._ccode_object)
|
||||
assert cppmember != NONE_VALUE
|
||||
|
||||
if cppmember:
|
||||
return cppmember
|
||||
else:
|
||||
# Convert using the same rules as ArgConverter...
|
||||
cpp_decl_spec, _ = super().convert_funcbody_decl_spec(cmember.decl_spec)
|
||||
cpp_name = standard_transforms.transform_variable_name(cmember.name) + "_"
|
||||
|
||||
cppmember = data_member.DataMember(cpp_decl_spec, cpp_name, cmember.mutable)
|
||||
|
||||
# FOR NOW - MAKE ALL MEMBERS NON-CONST
|
||||
if cppmember.decl_spec.const_qualifier:
|
||||
cppmember.decl_spec.const_qualifier = ""
|
||||
debug.line("create_cpp_code_object", f"DataMemberConverter *** SETTING DATA MEMBER TO NON-CONST ***")
|
||||
|
||||
self._conversion_pack.conversion_data.add_data_member_mapping(cmember, cppmember)
|
||||
debug.line("create_cpp_code_object", f"Adding data member mapping cmember=[{debug.as_debug_string(cmember)}] cppmember=[{debug.as_debug_string(cppmember)}]")
|
||||
|
||||
debug.line("create_cpp_code_object", f"DataMemberConverter [OUT] cppmember=[{debug.as_debug_string(cppmember)}]")
|
||||
return cppmember
|
||||
|
|
|
@ -10,5 +10,9 @@ class MacroInstantiationConverter(code_interface_converter.CodeInterfaceConverte
|
|||
assert isinstance(ccode_object, macro_instantation.MacroInstantation), f"Expected MacroInstantation, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
# For now, just return a copy...
|
||||
# For now, just return a copy or comment out if not wanted...
|
||||
|
||||
if self._ccode_object.as_string().startswith("Assert"):
|
||||
return conversion_funcs.as_commented_out_code(self._ccode_object, f"Ignoring Assert (for now!)")
|
||||
|
||||
return macro_instantation.MacroInstantation(self._ccode_object.as_lines())
|
||||
|
|
|
@ -75,17 +75,7 @@ class DefaultCCodeConverter:
|
|||
def convert_data_members(self):
|
||||
for cmember in self._ccode.data_members:
|
||||
cppmember = conversion_funcs.convert_ccode_object(cmember, self._conversion_pack)
|
||||
cppmember = data_member.DataMember(cppmember.decl_spec, cppmember.name + "_")
|
||||
|
||||
# FOR NOW - MAKE ALL MEMBERS NON-CONST
|
||||
if cppmember.decl_spec.const_qualifier:
|
||||
cppmember.decl_spec.const_qualifier = ""
|
||||
debug.line("convert_data_members", f"*** SETTING DATA MEMBER TO NON-CONST *** cppmember=[{debug.as_debug_string(cppmember)}]")
|
||||
|
||||
self._code_elements.add_data_member(cppmember)
|
||||
self._conversion_pack.conversion_data.add_data_member_mapping(cmember, cppmember)
|
||||
debug.line("convert_data_members", f"cmember=[{debug.as_debug_string(cmember)}] cppmember=[{debug.as_debug_string(cppmember)}]")
|
||||
|
||||
|
||||
# Override to return True if the member function should be marked const
|
||||
def is_const_member_function(self, function_name):
|
||||
|
|
Loading…
Reference in New Issue