From a151674c11014ce564eaf7584995ccf420ab8c45 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 13 Mar 2026 00:07:52 -0700 Subject: [PATCH 1/2] Handle template variables in the API snapshot Summary: Changelog: [Internal] Adds support for templates in variable declaration to the c++ API snapshot generator Differential Revision: D96279463 --- scripts/cxx-api/parser/builders.py | 6 +++++- scripts/cxx-api/parser/member.py | 3 +++ .../snapshot.api | 7 +++++++ .../should_handle_template_variable/test.h | 20 +++++++++++++++++++ .../snapshot.api | 4 +++- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 9beb9a93880d..1122433b9c14 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -249,7 +249,7 @@ def get_variable_member( if initializer_type == InitializerType.BRACE: is_brace_initializer = True - return VariableMember( + member = VariableMember( variable_name, variable_type, visibility, @@ -263,6 +263,10 @@ def get_variable_member( is_brace_initializer, ) + member.add_template(get_template_params(member_def)) + + return member + def get_doxygen_params( function_def: compound.MemberdefType, diff --git a/scripts/cxx-api/parser/member.py b/scripts/cxx-api/parser/member.py index 7681b42dc1df..7c8290dad50e 100644 --- a/scripts/cxx-api/parser/member.py +++ b/scripts/cxx-api/parser/member.py @@ -162,6 +162,9 @@ def to_string( result = " " * indent + if self.template_list is not None: + result += self.template_list.to_string() + "\n" + " " * indent + if not hide_visibility: result += self.visibility + " " diff --git a/scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api new file mode 100644 index 000000000000..52711af8da35 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/snapshot.api @@ -0,0 +1,7 @@ +template +const test::Strct test::Strct::VALUE; + +template +struct test::Strct { + public static const test::Strct VALUE; +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h new file mode 100644 index 000000000000..c1caf34d39df --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_template_variable/test.h @@ -0,0 +1,20 @@ +/* + * 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 { + +template +struct Strct { + static const Strct VALUE; +}; + +template +const Strct Strct::VALUE = {}; + +} // namespace test diff --git a/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api b/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api index 2d598603d29e..6248acdb5c77 100644 --- a/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_qualify_variable_template_specialization/snapshot.api @@ -1,5 +1,7 @@ -constexpr T test::default_value; constexpr test::MyType test::default_value; +template +constexpr T test::default_value; +template T* test::null_ptr; test::MyType* test::null_ptr; From 7270dc6bb35dc686b92002387b49e2aea6c5228b Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 13 Mar 2026 03:10:53 -0700 Subject: [PATCH 2/2] Fix handling of member function pointers in the API snapshot (#56069) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56069 Changelog: [Internal] Fixes handling of member function pointers in the C++ Api snapshot. Differential Revision: D96279461 --- scripts/cxx-api/parser/builders.py | 15 +++++++++++++ .../snapshot.api | 6 ++++++ .../test.h | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 1122433b9c14..f72c62f45e2b 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -317,6 +317,21 @@ def get_doxygen_params( else: param_type += param_array + # Handle pointer-to-member-function types where the name must be + # embedded inside the declarator group. Doxygen gives: + # type = "void(ns::*)() const", name = "asFoo" + # We need to produce: + # "void(ns::*asFoo)() const" + if param_name: + m = re.search(r"\([^)]*::\*\)", param_type) + if m: + # Insert name before the closing ')' of the ptr-to-member group + insert_pos = m.end() - 1 + param_type = ( + param_type[:insert_pos] + param_name + param_type[insert_pos:] + ) + param_name = None + 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_pointer_to_member_function_param/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api new file mode 100644 index 000000000000..3df3cf570cee --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api @@ -0,0 +1,6 @@ +struct folly::dynamic { +} + + +template +R test::jsArg(const folly::dynamic& arg, R(folly::dynamic::*asFoo)() const, const T &... desc); diff --git a/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h new file mode 100644 index 000000000000..8aaea82b5a17 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_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 folly { + +struct dynamic {}; + +} // namespace folly + +namespace test { + +template +R jsArg(const folly::dynamic &arg, R (folly::dynamic::*asFoo)() const, const T &...desc); + +} // namespace test