updated grib_handle processing

This commit is contained in:
kevstone 2023-11-02 13:40:40 +00:00
parent b8c397e1bc
commit 8f284dee5f
7 changed files with 44 additions and 16 deletions

View File

@ -10,8 +10,3 @@ class ConstructorMethod(Method):
func_sig = funcsig.FuncSig.from_string(constructor_default_line)
super().__init__(func_sig)
# Return all arg names in a string, for example to use to call the base constructor
@property
def arg_name_string(self):
return ", ".join([f"{a.name}" for a in self.args if a])

View File

@ -358,9 +358,27 @@ class FunctionConverter:
# Default - do nothing!
return remainder
# Takes a cppstruct and updates any C structs within the [] of the index...
# Required because C to C++ struct transforms ignore the index contents and so miss any other structs...
def update_cppstruct_indexes(self, cppstruct_arg):
debug.line("update_cppstruct_indexes", f"IN cppstruct_arg=[{cppstruct_arg.as_string()}]")
struct_arg = cppstruct_arg
while struct_arg:
if struct_arg.index:
struct_arg.index = self.update_cstruct_access(struct_arg.index, 0)
struct_arg = struct_arg.member
debug.line("update_cppstruct_indexes", f"OUT cppstruct_arg=[{cppstruct_arg.as_string()}]")
return cppstruct_arg
def update_cstruct_access(self, line, depth):
assert depth<10, f"Unexpected recursion depth [{depth}]"
debug.line("update_cstruct_access", f"IN [{depth}] line=[{line}]")
cstruct_arg, match_start, match_end = struct_arg.cstruct_arg_from_string(line)
if cstruct_arg:
if depth == 0: debug.line("update_cstruct_access", f"IN cstruct_arg=[{cstruct_arg.as_string()}] : {line}")
@ -371,6 +389,8 @@ class FunctionConverter:
cppstruct_arg = self.transform_cstruct_arg(cstruct_arg)
assert cppstruct_arg, f"Could not transform struct {cstruct_arg.name} to C++"
cppstruct_arg = self.update_cppstruct_indexes(cppstruct_arg)
if not cppstruct_arg.name:
# TODO: Only delete line if assignment, else just remove struct...
line = f"// [Deleted struct {cstruct_arg.name}] " + line
@ -378,7 +398,7 @@ class FunctionConverter:
return line
# Check if this is a "set" operation (it's match group 3 to avoid false match with ==)
m = re.search(r"([=!\+\-\*/]=)|([,;\)])|(=)", line[match_end:])
m = re.search(r"([=!\<\>\+\-\*/]=)|([,;\)])|(=)", line[match_end:])
if m and m.group(3):
match_end += m.end()
remainder = " = " + self.update_cppstruct_arg_assignment(cppstruct_arg, line[match_end:])

View File

@ -22,7 +22,7 @@ class InheritedMethodConverter(MethodConverter):
cpp_lines.append("// " + line)
cpp_lines.append("")
cpp_lines.append(f"return {self._transforms.types['super']}::{self._cppfunction.name}({self._cppfunction.arg_string});")
cpp_lines.append(f"return {self._transforms.types['super']}::{self._cppfunction.name}({self._cppfunction.parent_call_arg_string});")
debug.line("create_commented_cpp_body", f"\n============================== {self._cfunction.name} [OUT] ==============================\n")
@ -31,7 +31,7 @@ class InheritedMethodConverter(MethodConverter):
# Overridden to handle specific cases
def create_cpp_body(self):
if self._cppfunction.name == "dump":
if self._cppfunction.name in ["dump", "compare"]:
return self.create_commented_cpp_body()
return super().create_cpp_body()

View File

@ -24,7 +24,7 @@ static {{ m.return_type }} {{ m.name }}({{ m.arg_string }}) {
}
{% endfor %}
{{ c.name }}::{{ c.name }}({{c.constructor.arg_string}}) : {{ c.super }}({{ c.constructor.arg_name_string }}){
{{ c.name }}::{{ c.name }}({{c.constructor.arg_string}}) : {{ c.super }}({{ c.constructor.parent_call_arg_string }}){
{{ c.constructor.body }}
}

View File

@ -7,8 +7,6 @@ class Method(Function):
super().__init__(func_sig)
self._const = False
#self._owner_arg_type = self._owner_class.name
#self._owner_arg_name = arg.transform_variable_name(self._owner_arg_type)
@property
def const(self):
@ -17,3 +15,8 @@ class Method(Function):
@const.setter
def const(self, value):
self._const = value
# Return all arg names in a string, for example to use to call the parent virtual function
@property
def parent_call_arg_string(self):
return ", ".join([f"{a.name}" for a in self.args if a])

View File

@ -70,11 +70,14 @@ class MethodConverter(FunctionConverter):
assert cppstruct_arg, f"Could not transform cstruct_arg: [{cstruct_arg.as_string()}]"
# Extra processing required for grib_handle members that are referenced
elif cstruct_arg.name == "grib_handle_of_accessor(a)":
if self._transforms.ctype_of(cstruct_arg.name) == "grib_handle*" or cstruct_arg.name == "grib_handle_of_accessor(a)":
if cstruct_member.name == "buffer":
cppstruct_arg = struct_arg.StructArg("", transform_function_name(cstruct_member.name), "" )
debug.line("DEBUG", f"buffer: cstruct_arg=[{cstruct_arg.as_string()}]")
cppstruct_arg = struct_arg.StructArg("", "buffer_", "" )
if cstruct_member.member and cstruct_member.member.name == "data":
cppstruct_arg.member = struct_arg.StructArg(".", "data()", "")
cppstruct_arg.member = struct_arg.StructArg(".", "data()", cstruct_member.member.index)
if cppstruct_arg:
return cppstruct_arg

View File

@ -44,6 +44,11 @@ class StructArg:
@property
def index(self):
return self._index
@index.setter
def index(self, value):
assert value[0] == "[" and value[-1] == "]", f"Invalid index [{value}]"
self._index = value
@property
def member(self):
@ -88,7 +93,8 @@ def cstruct_arg_from_string(input):
# Note: (?:\(.+\))? is a non-capturing group that optionally matches (TEXT)
# and therefore allows us to capture function calls that result in
# struct access, for example: grib_handle_of_accessor(a)->buffer->data;
m = re.search(rf"(/\*)|([\*&])?({name_match}(?:\(.+\))?)({access_match})(\w+)(\[[\w\d]*\])?", input)
#m = re.search(rf"(/\*)|([\*&])?({name_match}(?:\(.+\))?)({access_match})(\w+)(\[[\w\d]*\])?", input)
m = re.search(rf"(/\*)|([\*&])?({name_match}(?:\(.+\))?)({access_match})(\w+)(\[[^\]]*\])?", input)
if m and m.group(1) != "/*":
access = m.group(2)
@ -104,7 +110,8 @@ def cstruct_arg_from_string(input):
# Loop, adding any extra member sections (->foo[4]) that exist...
next_member = cstruct_arg.member
while m and m.end() < len(input):
m = re.match(rf"({access_match})({name_match})(\[[\w\d]*\])?", input[match_end:])
#m = re.match(rf"({access_match})({name_match})(\[[\w\d]*\])?", input[match_end:])
m = re.match(rf"({access_match})({name_match})(\[[^\]]*\])?", input[match_end:])
if not m:
break