Added default constructor if no C version exists

This commit is contained in:
kevstone 2024-02-08 16:27:05 +00:00
parent 963c28a1de
commit 542ed863a2
2 changed files with 22 additions and 1 deletions

View File

@ -38,6 +38,8 @@ class DefaultCCodeConverter:
# Post-processing
self.run_post_processing()
self.validate_code_elements()
return cppcode.CppCode(self._code_info, self._code_elements)
# ============================== Setup functions: start ==============================
@ -160,6 +162,9 @@ class DefaultCCodeConverter:
# ============================== Post-processing: end ==============================
# Override for any final validation of the new cppcode object
def validate_code_elements(self):
pass
# Helper for consistent debug output!
def dump_function(self, def_name, cppfunc):

View File

@ -22,7 +22,8 @@ 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
import code_object_converter.conversion_pack.arg_utils as arg_utils
import code_object.compound_statement as compound_statement
import code_object.constructor_function as constructor_function
prefix = "grib_accessor_class_"
rename = {
@ -165,3 +166,18 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter):
if mismatch_found:
break
def validate_code_elements(self):
if not self._code_elements.constructor:
# We need to create a default constructor to ensure the InitData is passed up the construction hierarchy correctly!
cppconstructor_funcsig = self._conversion_pack.conversion_data.cppfuncsig_for_cfuncname("init")
assert cppconstructor_funcsig
cppconstructor_body = compound_statement.CompoundStatement()
cppconstructor = constructor_function.ConstructorFunction(cppconstructor_funcsig,
cppconstructor_body,
self._conversion_pack.conversion_data.info.class_name,
self._conversion_pack.conversion_data.info.super_class_name)
debug.line("validate_cppcode", f"No constructor found, adding a default=[{debug.as_debug_string(cppconstructor)}]")
self._code_elements.add_constructor(cppconstructor)
super().validate_code_elements()