mirror of https://github.com/ecmwf/eccodes.git
Added parsing for base member functions
This commit is contained in:
parent
e20f9e5d99
commit
2523b617dd
|
@ -6,6 +6,7 @@ import code_object_converter.conversion_funcs as conversion_funcs
|
|||
import code_object.arg as arg
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
import code_object_converter.conversion_pack.arg_utils as arg_utils
|
||||
import re
|
||||
|
||||
class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
||||
def __init__(self, ccode_object) -> None:
|
||||
|
@ -18,6 +19,16 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
debug.line("create_cpp_code_object", f"FunctionCallConverter [IN] cfunction_call=[{debug.as_debug_string(cfunction_call)}]")
|
||||
|
||||
m = re.match(r".*->", cfunction_call.name)
|
||||
if m:
|
||||
# The function call is through a pointer. We'll remove the pointer part and convert the function
|
||||
# The pointer will be converted elsewhere...
|
||||
function_name_pointer = m.group(0)
|
||||
cfunction_call = function_call.FunctionCall(cfunction_call.name[m.end():], cfunction_call.args)
|
||||
debug.line("create_cpp_code_object", f"Converting [{debug.as_debug_string(self._ccode_object)}] without function name pointer [{function_name_pointer}] => [{debug.as_debug_string(cfunction_call)}]")
|
||||
else:
|
||||
function_name_pointer = ""
|
||||
|
||||
# 1. Check if there is a function mapping defined
|
||||
mapping = conversion_pack.conversion_data.funcsig_mapping_for_cfuncname(cfunction_call.name)
|
||||
|
||||
|
@ -64,12 +75,19 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
cppfunction_call = function_call.FunctionCall(cpp_name, cpp_args)
|
||||
|
||||
# 3. Apply validation (and special handling)
|
||||
# 3. Restore function name pointer before performing validation...
|
||||
if function_name_pointer:
|
||||
cppfunction_call = function_call.FunctionCall(function_name_pointer+cppfunction_call.name, cppfunction_call.args)
|
||||
debug.line("create_cpp_code_object", f"Restoring function_name_pointer=[{function_name_pointer}] --> [{debug.as_debug_string(cppfunction_call)}]")
|
||||
|
||||
# 4. Apply validation (and special handling)
|
||||
updated_cppfunction_call = conversion_pack.conversion_validation.validate_function_call(cfunction_call, cppfunction_call)
|
||||
|
||||
# 4. Add the function call to the conversion data in case we need to process it later (e.g. for using C::x declarations)
|
||||
# 5. Add the function call to the conversion data in case we need to process it later (e.g. for using C::x declarations)
|
||||
# Only if function_call type!
|
||||
if isinstance(updated_cppfunction_call, function_call.FunctionCall):
|
||||
conversion_pack.conversion_data.add_cppfunction_call(updated_cppfunction_call)
|
||||
|
||||
|
||||
|
||||
return updated_cppfunction_call
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
import utils.debug as debug
|
||||
import grib_accessor.grib_accessor_conversion_pack.conversion_pack_updates.base_conversion_pack_updates as base_conversion_pack_updates
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
class TemplateConversionPackUpdates(base_conversion_pack_updates.BaseConversionPackUpdates):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
self._update_funcs.update({
|
||||
"pack_long": self.apply_updates_for_pack_long
|
||||
})
|
||||
|
||||
self._funcsig_mappings.extend([
|
||||
# template<typename T> static int unpack_helper(grib_accessor* a, T* val, size_t* len)
|
||||
FuncSigMapping(FuncSig("int", "unpack_helper", [Arg("grib_accessor*", "a"), Arg("T*", "val"), Arg("size_t*", "len")]),
|
||||
FuncSig("GribStatus", "unpackHelper", [NONE_VALUE, Arg("std::vector<T>&", "vecTValues"), NONE_VALUE]),
|
||||
ArgIndexes(cbuffer=1, clength=2, cpp_container=1)),
|
||||
])
|
||||
|
||||
self._all_function_arg_mappings.update({
|
||||
Arg("unsigned char*","p") : Arg("AccessorDataPointer","p"),
|
||||
})
|
||||
|
||||
def apply_updates_for_pack_long(self, conversion_pack):
|
||||
conversion_pack.conversion_data.add_funcbody_arg_mapping(Arg("unsigned char*","mdata"), Arg("AccessorDataPointer","mdata"))
|
|
@ -8,6 +8,7 @@ class BaseConversionPackUpdates:
|
|||
def __init__(self) -> None:
|
||||
self._update_funcs = {}
|
||||
self._funcsig_mappings = []
|
||||
self._all_function_arg_mappings = {}
|
||||
|
||||
def add_funcsig_mappings_to_conversion_data(self, conversion_data):
|
||||
for mapping in self._funcsig_mappings:
|
||||
|
@ -32,3 +33,7 @@ class BaseConversionPackUpdates:
|
|||
DataMember("grib_accessor_class**", "cclass->super"): DataMember("AccessorData", conversion_pack.conversion_data.info.super_class_name),
|
||||
}.items():
|
||||
conversion_pack.conversion_data.add_data_member_mapping(cmember, cppmember)
|
||||
|
||||
# All function arg mappings
|
||||
for carg, cpparg in self._all_function_arg_mappings.items():
|
||||
conversion_pack.conversion_data.add_funcbody_arg_mapping(carg, cpparg)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
import utils.debug as debug
|
||||
import grib_accessor.grib_accessor_conversion_pack.conversion_pack_updates.base_conversion_pack_updates as base_conversion_pack_updates
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
class BytesConversionPackUpdates(base_conversion_pack_updates.BaseConversionPackUpdates):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
self._all_function_arg_mappings.update({
|
||||
Arg("unsigned char*","p") : Arg("AccessorDataPointer","p"),
|
||||
})
|
||||
|
|
@ -69,6 +69,13 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
|
|||
if special_function_call:
|
||||
return special_function_call
|
||||
|
||||
if cppfunction_call.name.startswith("super->"):
|
||||
updated_func_name = cppfunction_call.name.replace("super->", f"{self._conversion_data.info.super_class_name}::")
|
||||
updated_cppfunction_call = function_call.FunctionCall(updated_func_name, cppfunction_call.args)
|
||||
|
||||
debug.line("validate_function_call", f"updated func name: [{debug.as_debug_string(cppfunction_call)}]->[{debug.as_debug_string(updated_cppfunction_call)}]")
|
||||
return updated_cppfunction_call
|
||||
|
||||
if cfunction_call.name == "sscanf":
|
||||
# Need to convert to using conversion helper function:
|
||||
# template <typename... Args>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from code_object.arg import Arg
|
||||
from code_object.declaration_specifier import DeclSpec
|
||||
import code_object_converter.conversion_pack.conversion_data as conversion_data
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
# ==================== FUNCSIG TYPE MAPPINGS: Begin ====================
|
||||
|
||||
|
@ -22,11 +23,12 @@ def add_funcsig_type_mappings_to_conversion_data(conversion_data):
|
|||
# ==================== FUNCBODY TYPE MAPPINGS: Begin ====================
|
||||
|
||||
common_grib_funcbody_type_mappings = {
|
||||
"grib_accessor*" : "AccessorPtr",
|
||||
"grib_handle*" : DeclSpec.NONE,
|
||||
"grib_context*" : DeclSpec.NONE,
|
||||
"grib_expression*" : "GribExpressionPtr",
|
||||
"grib_codetable*" : "GribCodeTablePtr",
|
||||
"grib_accessor*" : "AccessorPtr",
|
||||
"grib_accessor_class*" : NONE_VALUE,
|
||||
"grib_handle*" : NONE_VALUE,
|
||||
"grib_context*" : NONE_VALUE,
|
||||
"grib_expression*" : "GribExpressionPtr",
|
||||
"grib_codetable*" : "GribCodeTablePtr",
|
||||
}
|
||||
|
||||
grib_array_funcbody_type_mappings = {
|
||||
|
|
Loading…
Reference in New Issue