mrdocs icon indicating copy to clipboard operation
mrdocs copied to clipboard

Correctly determine if a member function should be extracted

Open vinniefalco opened this issue 2 years ago • 1 comments

We need to dial-in the logic in Interface::Build which determines if a member function should be extracted, given the various cases of final, virtual, and access.

vinniefalco avatar May 13 '23 23:05 vinniefalco

Here is something that will almost always work. This does not account for:

  • friend declarations, or
  • using-declarations (e.g. using B::f; appearing as a public member of a class D derived from B where B::f is a protected member of B), or
  • public/protected data members whose type depends on a private member, or
  • public/protected member function whose parameters or return type depends on a private member

Given a member M that has access A declared in class C:

  • if M is not a virtual function:
    • if A is public, emit M.
    • if A is private, do not emit M.
    • if A is protected, emit M if C is not declared final.
  • otherwise, if M is a virtual function:
    • if A is public, emit M.
    • if A is private, emit M if:
      • M overrides a member of a base class of C, or
      • C is not declared final (note: a private virtual function declared final will prevent derived classes from overriding the function; since final is only meaningful for member functions of a non-final class, it does not require special treatment here).
    • if A is protected, emit M if:
      • C is not declared final, or
      • C is declared final and M overrides a member of a base class of C.

The same rules apply for class templates except when C has a dependent base class B. In such cases, we must assume that every non-template non-static member function F overrides a member of B (for the purposes of determining whether to emit the function). Since mrdox only supports valid C++, we can assume that F does not override a function in B if it has a trailing requires-clause, or if the return type of F is a placeholder type (i.e. auto/decltype(auto)) without a trailing-return-type.

sdkrystian avatar May 25 '23 10:05 sdkrystian