From 269a2ee0cbdad78befe59564fd5de94ed5daa2ad Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 25 Feb 2026 11:16:36 -0800 Subject: [PATCH] Fix indexed access in function arguments (#55645) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55645 Changelog: [Internal] Updates the C++ api snapshot generator to correctly handle arrays of fixed size. Reviewed By: cipolleschi Differential Revision: D93407605 fbshipit-source-id: b64d30db04696ea54109258d7d4c4fbf43a4cc69 --- scripts/cxx-api/parser/main.py | 24 +++++++++++++++++++ .../should_handle_array_param/snapshot.api | 8 +++++++ .../should_handle_array_param/test.h | 21 ++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_array_param/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_array_param/test.h diff --git a/scripts/cxx-api/parser/main.py b/scripts/cxx-api/parser/main.py index 1674484cd4b..511e1dec79c 100644 --- a/scripts/cxx-api/parser/main.py +++ b/scripts/cxx-api/parser/main.py @@ -230,6 +230,30 @@ def get_doxygen_params( resolve_ref_text_name(param.defval).strip() if param.defval else None ) + # Doxygen splits array dimensions into a separate element. + # For complex declarators like "PropNameID (&&propertyNames)[N]", + # doxygen gives type="PropNameID(&&)", name="propertyNames", + # array="[N]". We must reconstruct the full declarator with the + # name embedded inside the grouping parentheses: + # PropNameID(&&propertyNames)[N] + param_array = param.array + if param_array: + # Match type ending with a pointer/reference declarator group: + # e.g. "PropNameID(&&)", "int(&)", "void(*)" + m = re.search(r"\([*&]+\)\s*$", param_type) + if m and param_name: + # Insert name before the closing ')' and append array + insert_pos = m.end() - 1 # position of trailing ')' + param_type = ( + param_type[:insert_pos] + + param_name + + param_type[insert_pos:] + + param_array + ) + param_name = None + else: + param_type += param_array + qualifiers, core_type = extract_qualifiers(param_type) arguments.append((qualifiers, core_type, param_name, param_default)) diff --git a/scripts/cxx-api/tests/snapshots/should_handle_array_param/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_array_param/snapshot.api new file mode 100644 index 00000000000..e148ded621a --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_array_param/snapshot.api @@ -0,0 +1,8 @@ +struct test::Node { + public void setArray(int(&arr)[10]); + template + public static std::vector< test::PropNameID > names(PropNameID(&&propertyNames)[N]); +} + +struct test::PropNameID { +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_array_param/test.h b/scripts/cxx-api/tests/snapshots/should_handle_array_param/test.h new file mode 100644 index 00000000000..86a0a276120 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_array_param/test.h @@ -0,0 +1,21 @@ +/* + * 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 { + +struct PropNameID {}; + +struct Node { + template + static std::vector names(PropNameID (&&propertyNames)[N]); + + void setArray(int (&arr)[10]); +}; + +} // namespace test