Repository navigation
Override inherited overloads a direct base implements only in part - #153
guitargeek wants to merge 1 commit into
Conversation
| PyStandalone = type( | ||
| "PyStandalone", | ||
| (ns.Standalone,), | ||
| { | ||
| "operator()": lambda self, *args: 100 + len(args), | ||
| "run": lambda self, *args: 200 + len(args), | ||
| }, | ||
| ) |
There was a problem hiding this comment.
I believe we should be matching the __call__ in Python to operator() in C++.
And not this weird thing.
There was a problem hiding this comment.
You're right. It's one indirection more though, but worth it because the test becomes more readable.
| // signatures of the methods already overridden, per method name | ||
| typedef std::map<std::string, std::set<std::string>> Overridden_t; | ||
|
|
||
| static inline std::string MethodKey(TCppMethod_t method) { |
There was a problem hiding this comment.
| static inline std::string MethodKey(TCppMethod_t method) { | |
| static inline std::string GetMethodSignature(TCppMethod_t method) { |
?
Or something like that...
There was a problem hiding this comment.
We already have interop::GetMethodSignature in interop_wrapper.cxx to get the signature of a method.
There was a problem hiding this comment.
Renamed to GetOverrideSignature. interop::GetMethodSignature can't be reused here because it prints the types as written (no canonicalization, top-level cv-qualifiers kept) and leaves out constness, so the same signature declared slightly differently in two classes would be injected twice.
The dispatcher matched the methods a Python class overrides against the methods its direct C++ base declares itself, and only looked further up the hierarchy for names the base does not declare at all. A base that implements some overloads of a method and inherits others as pure virtual thus had only its own overloads overridden, and the dispatcher class remained abstract. Walk the whole hierarchy for every overridden name and override each virtual overload not already covered by a more derived class, keyed by canonical argument types and constness. The same key also prevents a signature from being defined twice when two bases declare it. Operators are matched by their Python name, so that e.g. defining __call__ overrides a virtual operator(). Fixes compiler-research#146
358fcf8 to
817bfe5
Compare
The dispatcher matched the methods a Python class overrides against the methods its direct C++ base declares itself, and only looked further up the hierarchy for names the base does not declare at all. A base that implements some overloads of a method and inherits others as pure virtual thus had only its own overloads overridden, and the dispatcher class remained abstract.
Walk the whole hierarchy for every overridden name and override each virtual overload not already covered by a more derived class, keyed by canonical argument types and constness. The same key also prevents a signature from being defined twice when two bases declare it.
Operators are matched by their Python name, so that e.g. defining call overrides a virtual operator().
Fixes #146