Converting grib(Un)PackXXX to member function calls

This commit is contained in:
kevstone 2024-02-05 22:03:49 +00:00
parent 620d90b5ea
commit dbe4544c1f
2 changed files with 16 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import code_object.value_declaration_reference as value_declaration_reference
import code_object.if_statement as if_statement
import code_object.virtual_member_function as virtual_member_function
import code_object.constructor_function as constructor_function
import code_object.function_call as function_call
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
@ -72,7 +73,8 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
return super().validate_function_call_arg(calling_arg_value, target_arg)
def validate_variable_declaration(self, cvariable_declaration, cppvariable_declaration):
if "GribStatus" in cppvariable_declaration.variable.as_string():
if "GribStatus" in cppvariable_declaration.variable.as_string() and \
not isinstance(cppvariable_declaration.value, function_call.FunctionCall):
updated_cpp_variable_declaration = variable_declaration.VariableDeclaration(
cppvariable_declaration.variable,
literal.Literal(f"GribStatus{{{cppvariable_declaration.value.as_string()}}}"))

View File

@ -3,6 +3,7 @@ import utils.debug as debug
import code_object.literal as literal
import code_object.function_call as function_call
from code_object_converter.conversion_funcs import as_commented_out_code
from utils.standard_transforms import transform_variable_name
special_function_name_mapping = {
"snprintf" : "fmtString",
@ -30,6 +31,18 @@ def apply_special_function_call_conversions(cfunction_call, cppfunction_call):
arg_entry = literal.Literal(f"initData.args[{cfunction_call.args[2].as_string()}].second")
return function_call.FunctionCall(f"std::get<long>", [arg_entry])
# If we're calling gribPackXXX or gribUnpackXXX and the first argument is "a", then we're actually calling ourself!
cppfuncname = ""
if cppfunction_call.name.startswith("gribPack"):
cppfuncname = "pack"
elif cppfunction_call.name.startswith("gribUnpack"):
cppfuncname = "unpack"
if cppfuncname and len(cppfunction_call.args) > 0 and cppfunction_call.args[0].as_string() == "a":
debug.line("apply_special_function_call_conversions", f"Updated function call=[{cppfunction_call.name}] to [{cppfuncname}]")
return function_call.FunctionCall(cppfuncname, cppfunction_call.args[1:])
for cfuncname, cppfuncname in special_function_name_mapping.items():
if cfunction_call.name == cfuncname:
if cppfuncname: