From 31f262ed2eead22a20eb640ebd1c63d7ad8ed579 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 26 Mar 2026 08:40:54 -0700 Subject: [PATCH] Fix function pointer param args being qualified to outer class (#56217) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56217 Changelog: [Internal] Doxygen may incorrectly cross-reference parameter names inside function pointer types to member variables of the enclosing class. For example, `void (*cb)(const void* data)` inside a class that has a `data` member would produce `const void* Class::data` instead of `const void* data` in the snapshot. This diff addresses two issues: 1. In `get_doxygen_params`, re-parse function pointer type strings through `parse_type_with_argstrings` which delegates to `_parse_single_argument` that already strips "::" from parameter names. 2. In `parse_type_with_argstrings`, recognize complex declarator groups starting with `*` or `&` (e.g. `*(*fp)(int)`) as non-argument-list parenthesized sections, preventing incorrect name extraction from nested function pointer declarators. Reviewed By: cipolleschi Differential Revision: D98118629 fbshipit-source-id: a8532e2adaec1dd2b50be8a20eae1068ac49d548 --- scripts/cxx-api/parser/builders.py | 17 ++++++++++++++++- .../cxx-api/parser/utils/argument_parsing.py | 8 ++++++++ .../snapshot.api | 4 ++++ .../test.h | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index beb9be1c51c..e479660ee84 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -41,7 +41,12 @@ from .utils import ( resolve_linked_text_name, split_specialization, ) -from .utils.argument_parsing import _find_matching_angle, _split_arguments +from .utils.argument_parsing import ( + _find_matching_angle, + _split_arguments, + format_parsed_type, + parse_type_with_argstrings, +) @dataclass @@ -307,6 +312,16 @@ def get_doxygen_params( if param.get_type() else "" ) + + # Doxygen may incorrectly cross-reference parameter names inside + # inline function pointer types to member variables of the enclosing + # class, producing qualified paths like "const void* + # ns::Class::data" instead of "const void* data". Re-parse the + # type through parse_type_with_argstrings which delegates to + # _parse_single_argument — that already strips "::" from names. + segments = parse_type_with_argstrings(param_type) + if len(segments) > 1: + param_type = format_parsed_type(segments) param_name = param.declname or param.defname or None param_default = ( resolve_linked_text_name(param.defval)[0].strip() if param.defval else None diff --git a/scripts/cxx-api/parser/utils/argument_parsing.py b/scripts/cxx-api/parser/utils/argument_parsing.py index e9bcfb010ee..1449f46bac3 100644 --- a/scripts/cxx-api/parser/utils/argument_parsing.py +++ b/scripts/cxx-api/parser/utils/argument_parsing.py @@ -530,6 +530,14 @@ def parse_type_with_argstrings( i = close + 1 continue + # Complex declarator starting with * or &, e.g. *(*fp)(int) + # in "int(*(*fp)(int))(double)". Argument lists never start + # with pointer/reference characters. + if stripped and stripped[0] in ("*", "&"): + current_text.append(type_str[i : close + 1]) + i = close + 1 + continue + # Try to parse as a function argument list args: list[Argument] = [] if stripped: diff --git a/scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/snapshot.api new file mode 100644 index 00000000000..85ed57b7954 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/snapshot.api @@ -0,0 +1,4 @@ +class test::Runtime { + public int data; + public virtual void getStringData(void* ctx, void(*)(void* ctx, bool ascii, const void* data, size_t num) cb); +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/test.h b/scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/test.h new file mode 100644 index 00000000000..5ffb6c927c0 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_qualify_function_pointer_param_args_to_outer_class/test.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace test { + +class Runtime { + public: + int data; + virtual void getStringData(void *ctx, void (*cb)(void *ctx, bool ascii, const void *data, size_t num)); +}; + +} // namespace test