Skip to content

Commit

Permalink
Merge pull request #221 from robotpy/track-private-overloads
Browse files Browse the repository at this point in the history
Do minimal processing of ignored functions
  • Loading branch information
virtuald authored Nov 11, 2023
2 parents 5237df4 + 416ec18 commit 5de9a33
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
37 changes: 35 additions & 2 deletions robotpy_build/autowrap/cxxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class ClassStateData(typing.NamedTuple):

# have to defer processing these
defer_protected_methods: typing.List[Method]
defer_private_nonvirtual_methods: typing.List[Method]
defer_private_virtual_methods: typing.List[Method]
defer_protected_fields: typing.List[Field]

Expand Down Expand Up @@ -750,6 +751,7 @@ def on_class_start(self, state: AWClassBlockState) -> typing.Optional[bool]:
typealias_names=typealias_names,
# Method data
defer_protected_methods=[],
defer_private_nonvirtual_methods=[],
defer_private_virtual_methods=[],
defer_protected_fields=[],
# Trampoline data
Expand Down Expand Up @@ -983,8 +985,11 @@ def on_class_method(self, state: AWClassBlockState, method: Method) -> None:
self._on_class_method(state, method, cctx.wrapped_public_methods)
elif access == "protected":
cdata.defer_protected_methods.append(method)
elif access == "private" and is_polymorphic:
cdata.defer_private_virtual_methods.append(method)
elif access == "private":
if is_polymorphic:
cdata.defer_private_virtual_methods.append(method)
else:
cdata.defer_private_nonvirtual_methods.append(method)

def _on_class_method(
self,
Expand Down Expand Up @@ -1152,6 +1157,23 @@ def _on_class_method(
f"{cdata.cls_key}::{method_name}: has && ref-qualifier which cannot be directly bound by pybind11, must specify cpp_code or ignore_py"
)

def _on_class_method_process_overload_only(
self, state: AWClassBlockState, method: Method
):
cdata = state.user_data

method_name = self._get_fn_name(method)
if not method_name:
return

self.gendata.get_function_data(
method_name,
method,
cdata.cls_key,
cdata.data,
True,
)

def _is_copy_move_constructor(
self, cctx: ClassContext, first_type_param: DecoratedType
) -> bool:
Expand Down Expand Up @@ -1242,6 +1264,17 @@ def on_class_end(self, state: AWClassBlockState) -> None:
f"{cdata.cls_key} has trampoline_inline_code specified, but there is no trampoline!"
)

else:
# still need to do minimal processing to add deferred functions
# to the overload tracker, otherwise we won't handle it correctly
for m in cdata.defer_protected_methods:
self._on_class_method_process_overload_only(state, m)
for m in cdata.defer_private_virtual_methods:
self._on_class_method_process_overload_only(state, m)

for m in cdata.defer_private_nonvirtual_methods:
self._on_class_method_process_overload_only(state, m)

#
# Function/method processing
#
Expand Down
6 changes: 6 additions & 0 deletions tests/cpp/rpytest/ft/include/overloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ struct OverloadedObject
return 0x4;
}

void overloaded_private(int a) {}

private:

// this causes errors if we don't account for it
void overloaded_private(int a, int b) {}

int o;
};

0 comments on commit 5de9a33

Please sign in to comment.