Skip to content

Commit 24de13c

Browse files
committed
Add force_instance_methods; rename shortcut funcs
Refactor macOS shortcut parsing helpers to use more specific names (e.g. ToLower -> ShortcutToLower, SplitAccelerator -> SplitShortcutAccelerator, ParseAcceleratorTokens -> ParseShortcutAcceleratorTokens, ParseAcceleratorMac -> ParseMacShortcutAccelerator) and update their call sites. Also add a new TypeMapper option force_instance_methods (loaded from config) and honor it when mapping methods by computing a method key and forcing instance dispatch (adjusting static and needs_instance_handle) for listed methods.
1 parent b4dd766 commit 24de13c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/platform/macos/shortcut_manager_macos.mm

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
namespace nativeapi {
1515
namespace {
1616

17-
std::string ToLower(std::string value) {
17+
std::string ShortcutToLower(std::string value) {
1818
std::transform(value.begin(), value.end(), value.begin(),
1919
[](unsigned char ch) { return static_cast<char>(std::tolower(ch)); });
2020
return value;
2121
}
2222

23-
std::vector<std::string> SplitAccelerator(const std::string& accelerator) {
23+
std::vector<std::string> SplitShortcutAccelerator(const std::string& accelerator) {
2424
std::vector<std::string> parts;
2525
std::string current;
2626
for (char ch : accelerator) {
@@ -39,19 +39,19 @@
3939
return parts;
4040
}
4141

42-
bool ParseAcceleratorTokens(const std::string& accelerator,
43-
std::vector<std::string>& modifiers,
44-
std::string& key_token) {
42+
bool ParseShortcutAcceleratorTokens(const std::string& accelerator,
43+
std::vector<std::string>& modifiers,
44+
std::string& key_token) {
4545
modifiers.clear();
4646
key_token.clear();
4747

48-
auto parts = SplitAccelerator(accelerator);
48+
auto parts = SplitShortcutAccelerator(accelerator);
4949
if (parts.empty()) {
5050
return false;
5151
}
5252

5353
for (auto& part : parts) {
54-
std::string token = ToLower(part);
54+
std::string token = ShortcutToLower(part);
5555
if (token == "ctrl" || token == "control" || token == "alt" || token == "shift" ||
5656
token == "cmd" || token == "command" || token == "super" || token == "meta" ||
5757
token == "cmdorctrl") {
@@ -67,13 +67,15 @@ bool ParseAcceleratorTokens(const std::string& accelerator,
6767
return !key_token.empty();
6868
}
6969

70-
bool ParseAcceleratorMac(const std::string& accelerator, UInt32& modifiers, UInt32& keycode) {
70+
bool ParseMacShortcutAccelerator(const std::string& accelerator,
71+
UInt32& modifiers,
72+
UInt32& keycode) {
7173
modifiers = 0;
7274
keycode = 0;
7375

7476
std::vector<std::string> modifier_tokens;
7577
std::string key_token;
76-
if (!ParseAcceleratorTokens(accelerator, modifier_tokens, key_token)) {
78+
if (!ParseShortcutAcceleratorTokens(accelerator, modifier_tokens, key_token)) {
7779
return false;
7880
}
7981

@@ -235,7 +237,7 @@ bool RegisterShortcut(const std::shared_ptr<Shortcut>& shortcut) override {
235237

236238
UInt32 modifiers = 0;
237239
UInt32 keycode = 0;
238-
if (!ParseAcceleratorMac(shortcut->GetAccelerator(), modifiers, keycode)) {
240+
if (!ParseMacShortcutAccelerator(shortcut->GetAccelerator(), modifiers, keycode)) {
239241
return false;
240242
}
241243

tools/bindgen/codegen/context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def __init__(self, config: MappingConfig):
225225
options = config.options or {}
226226
self.symbol_overrides: Dict[str, str] = dict(options.get("symbol_overrides", {}) or {})
227227
self.singleton_classes = set(options.get("singleton_classes", []) or [])
228+
self.force_instance_methods = set(options.get("force_instance_methods", []) or [])
228229
self.cstring_free_symbols: Dict[str, str] = dict(options.get("cstring_free_symbols", {}) or {})
229230
self.bridge_types: Dict[str, str] = dict(options.get("bridge_types", {}) or {})
230231
self.api_type_exact: Dict[str, str] = dict(
@@ -558,6 +559,9 @@ def map_method(self, ir_method: IRMethod, ir_class: IRClass) -> MappedMethod:
558559
api_return_type = self._api_type(return_type)
559560
call_symbol = self._symbol_for_method(ir_class, ir_method)
560561
params = [self.map_param(p) for p in ir_method.params]
562+
class_key = ir_class.qualified_name or ir_class.name
563+
method_key = f"{class_key}::{ir_method.name}"
564+
force_instance = method_key in self.force_instance_methods
561565

562566
call_args: List[str] = []
563567
for param in params:
@@ -600,8 +604,8 @@ def map_method(self, ir_method: IRMethod, ir_class: IRClass) -> MappedMethod:
600604
is_property=is_property,
601605
property_name=property_name,
602606
method_kind=ir_method.kind,
603-
static=ir_method.static,
604-
needs_instance_handle=not ir_method.static,
607+
static=ir_method.static and not force_instance,
608+
needs_instance_handle=(not ir_method.static) or force_instance,
605609
const=ir_method.const,
606610
access=ir_method.access,
607611
variadic=ir_method.variadic,

0 commit comments

Comments
 (0)