Fixed GribStatus return type bug

This commit is contained in:
kevstone 2024-02-04 18:47:03 +00:00
parent c7fd597563
commit 30e7ee9b6d
2 changed files with 16 additions and 6 deletions

View File

@ -37,10 +37,6 @@ class ConversionData:
@property
def info(self):
return self._info
@property
def current_cfuncname(self):
return self._info.current_cfuncname
# ============================== Functions to update the mappings: start ==============================
@ -51,8 +47,6 @@ 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}]"
@ -335,6 +329,9 @@ class ConversionData:
if entry.cfuncsig.name == cfuncname:
return entry
return None
def funcsig_mapping_for_current_cfuncname(self):
return self.funcsig_mapping_for_cfuncname(self._info.current_cfuncname)
def funcsig_buffer_mapping_for_cname(self, cname):
for mapping in self.all_mappings():

View File

@ -5,6 +5,7 @@ import code_object.literal as literal
import code_object.variable_declaration as variable_declaration
import code_object.value_declaration_reference as value_declaration_reference
import code_object.binary_operation as binary_operation
import code_object.return_statement as return_statement
from grib_accessor.grib_accessor_conversion_pack.grib_accessor_special_function_call_conversion import apply_special_function_call_conversions
from code_object.code_interface import NONE_VALUE
import code_object.if_statement as if_statement
@ -67,4 +68,16 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
return super().validate_if_statement(cif_statement, cppif_statement)
def validate_return_statement(self, creturn_statement, cppreturn_statement):
mapping = self._conversion_data.funcsig_mapping_for_current_cfuncname()
if mapping:
if mapping.cppfuncsig.return_type.type == "GribStatus":
cpp_expression = cppreturn_statement.expression.as_string()
if cpp_expression == "0":
updated_cpp_expression = literal.Literal("GribStatus::SUCCESS")
else:
updated_cpp_expression = literal.Literal(f"static_cast<GribStatus>({cpp_expression})")
return return_statement.ReturnStatement(updated_cpp_expression)
return super().validate_return_statement(creturn_statement, cppreturn_statement)