Final conversion fixes for ASCII accessor

This commit is contained in:
kevstone 2024-02-06 15:41:30 +00:00
parent 97b01e1374
commit 508d386311
2 changed files with 17 additions and 8 deletions

View File

@ -112,11 +112,11 @@ class DefaultConversionValidation(conversion_validation.ConversionValidation):
# If we've got a StructMemberAccess object, we're probably dealing with a container...
cppleft = cppbinary_operation.left_operand
if isinstance(cppleft, struct_member_access.StructMemberAccess):
cppbinary_op = cppbinary_operation.binary_op
cppright = cppbinary_operation.right_operand
cppbinary_op = cppbinary_operation.binary_op
cppright = cppbinary_operation.right_operand
if cppbinary_op.is_assignment():
if cppbinary_op.is_assignment():
if isinstance(cppleft, struct_member_access.StructMemberAccess):
cpparg = self._conversion_data.cpparg_for_cppname(cppleft.name)
if cppleft.member:
if cppleft.member.name == "size()":
@ -140,6 +140,12 @@ 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)
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):
cppleft = literal.Literal(f"{cpparg.name}.size()")
return binary_operation.BinaryOperation(cppleft, cppbinary_op, cppright)
return cppbinary_operation

View File

@ -43,10 +43,13 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
cpp_body = compound_statement.CompoundStatement()
cpp_body.add_code_object(as_commented_out_code("C++ implementation not yet available."))
cpp_body.add_code_object(as_commented_out_code("Commented C body provided below for reference:\n"))
cpp_body.add_code_object(as_commented_out_code("Current C++ conversion provided below (disabled, for reference only):\n"))
cpp_body.add_code_object(literal.Literal(f"#if 0"))
for entry in cvirtual_member_function.body.code_objects:
cpp_body.add_code_object(as_commented_out_code(entry))
for entry in cppvirtual_member_function.body.code_objects:
cpp_body.add_code_object(entry)
cpp_body.add_code_object(literal.Literal(f"#endif // 0"))
cpp_body.add_code_object(literal.Literal(f"\nreturn {self._conversion_data.info.super_class_name}::{cppvirtual_member_function.funcsig_as_call};"))
return virtual_member_function.VirtualMemberFunction(cppvirtual_member_function.funcsig, cpp_body, cppvirtual_member_function.class_name)
@ -124,7 +127,7 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
cpp_expression = cppreturn_statement.expression.as_string()
if cpp_expression == "0":
updated_cpp_expression = literal.Literal("GribStatus::SUCCESS")
else:
elif not cpp_expression.startswith("GribStatus"):
updated_cpp_expression = literal.Literal(f"static_cast<GribStatus>({cpp_expression})")
if updated_cpp_expression: