From f2ea073857706c895bacc0ec684e573252d7f107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Thu, 5 Mar 2026 07:21:42 -0800 Subject: [PATCH] Normalize pointer and reference spacing in parser output (#55901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55901 Fixes inconsistent spacing around pointer (`*`) and reference (`&`, `&&`) symbols in the parser output. Doxygen outputs types with a space before `*` and `&` (e.g., `NSString *`), which is inconsistent. This diff adds `normalize_pointer_spacing()` to standardize the output: - `NSString *` → `NSString*` - `int &` → `int&` - `T &&` → `T&&` - For function arguments: `NSString *name` → `NSString* name` ## Changes 1. Added `normalize_pointer_spacing()` function in `text_resolution.py` 2. Applied normalization in `resolve_ref_text_name()` and `resolve_linked_text_name()` 3. Applied normalization to block property argsstrings in `builders.py` 4. Updated all affected snapshot files to use normalized spacing Changelog: [Internal] Reviewed By: cortinico Differential Revision: D95078214 fbshipit-source-id: 1a21361565fd7915a3a597ac729cecc2cfe99961 --- scripts/cxx-api/parser/builders.py | 5 ++- scripts/cxx-api/parser/utils/__init__.py | 1 + .../cxx-api/parser/utils/text_resolution.py | 40 ++++++++++++++++++- .../snapshot.api | 2 +- .../should_handle_concept/snapshot.api | 2 +- .../should_handle_concept_indent/snapshot.api | 8 ++-- .../should_handle_deprecated_msg/snapshot.api | 4 +- .../snapshot.api | 2 +- .../snapshot.api | 4 +- .../snapshot.api | 4 +- .../snapshot.api | 2 +- .../snapshot.api | 4 +- .../snapshot.api | 8 ++-- .../snapshot.api | 4 +- .../snapshot.api | 2 +- .../snapshot.api | 2 +- .../snapshot.api | 2 +- .../snapshot.api | 4 +- .../snapshot.api | 2 +- .../snapshot.api | 2 +- .../should_strip_objc_macros/snapshot.api | 6 +-- 21 files changed, 75 insertions(+), 35 deletions(-) diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 4dbd7466596..e3c0b772818 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -33,6 +33,7 @@ from .utils import ( Argument, extract_qualifiers, InitializerType, + normalize_pointer_spacing, parse_qualified_path, resolve_linked_text_name, ) @@ -344,7 +345,9 @@ def get_property_member( if property_type.endswith("(^"): argsstring = member_def.get_argsstring() if argsstring: - property_type = f"{property_type}{property_name}{argsstring}" + # Normalize pointer spacing in the argsstring + normalized_argsstring = normalize_pointer_spacing(argsstring) + property_type = f"{property_type}{property_name}{normalized_argsstring}" property_name = "" return PropertyMember( diff --git a/scripts/cxx-api/parser/utils/__init__.py b/scripts/cxx-api/parser/utils/__init__.py index 25fd05b4183..248136e621f 100644 --- a/scripts/cxx-api/parser/utils/__init__.py +++ b/scripts/cxx-api/parser/utils/__init__.py @@ -18,6 +18,7 @@ from .text_resolution import ( extract_namespace_from_refid, InitializerType, normalize_angle_brackets, + normalize_pointer_spacing, resolve_linked_text_name, ) from .type_qualification import qualify_arguments, qualify_parsed_type, qualify_type_str diff --git a/scripts/cxx-api/parser/utils/text_resolution.py b/scripts/cxx-api/parser/utils/text_resolution.py index 497e1267a5d..8d5e7c46ad2 100644 --- a/scripts/cxx-api/parser/utils/text_resolution.py +++ b/scripts/cxx-api/parser/utils/text_resolution.py @@ -83,13 +83,46 @@ def extract_namespace_from_refid(refid: str) -> str: def normalize_angle_brackets(text: str) -> str: """Doxygen adds spaces around < and > to avoid XML ambiguity. - e.g. "NSArray< id< RCTBridgeMethod > > *" -> "NSArray> *" + e.g. "NSArray< id< RCTBridgeMethod > > *" -> "NSArray>*" """ text = re.sub(r"<\s+", "<", text) text = re.sub(r"\s+>", ">", text) return text +def normalize_pointer_spacing(text: str) -> str: + """Normalize spacing around pointer (*) and reference (&, &&) symbols. + + Doxygen outputs types with a space before * and &, e.g.: + - "NSString *" -> "NSString*" + - "int &" -> "int&" + - "T &&" -> "T&&" + + But for function arguments like "NSString *name", we want "NSString* name" + (space moved from before * to after *). + + This normalizes to have no space before the pointer/reference symbol, + while preserving the space after if there's an identifier following. + """ + # For patterns like "Type *name" -> "Type* name" (move space from before to after) + # Match: word/type character or > followed by space(s), then *, then word char + text = re.sub(r"(\w|>)\s+\*(\w)", r"\1* \2", text) + # For patterns like "Type *" at end or before comma/paren/angle/open-paren -> "Type*" + text = re.sub(r"(\w|>)\s+\*(?=\s*[,)>(]|$)", r"\1*", text) + # For patterns like "Type *" followed by another * (pointer to pointer) + text = re.sub(r"(\w|>)\s+\*(?=\*)", r"\1*", text) + + # Same for && (rvalue reference) + text = re.sub(r"(\w|>)\s+&&(\w)", r"\1&& \2", text) + text = re.sub(r"(\w|>)\s+&&(?=\s*[,)>(]|$)", r"\1&&", text) + + # Same for & (lvalue reference) - but don't match && + text = re.sub(r"(\w|>)\s+&(?!&)(\w)", r"\1& \2", text) + text = re.sub(r"(\w|>)\s+&(?!&)(?=\s*[,)>(]|$)", r"\1&", text) + + return text + + class InitializerType(Enum): NONE = (0,) ASSIGNMENT = (1,) @@ -145,7 +178,10 @@ def resolve_linked_text_name( initialier_type = InitializerType.BRACE name = name[1:-1].strip() - return (normalize_angle_brackets(name.strip()), initialier_type) + return ( + normalize_pointer_spacing(normalize_angle_brackets(name.strip())), + initialier_type, + ) def _qualify_text_with_refid(text: str, refid: str) -> str: diff --git a/scripts/cxx-api/tests/snapshots/should_handle_class_public_method_arguments/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_class_public_method_arguments/snapshot.api index f0d525d1c1c..264305555fc 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_class_public_method_arguments/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_class_public_method_arguments/snapshot.api @@ -10,7 +10,7 @@ class test::Clss { public void fn7(std::vector>> v); public void fn8(std::map> m); public void fn9(int(*)(int, int) callback); - public void fn10(void(*)(const char *, size_t) handler); + public void fn10(void(*)(const char*, size_t) handler); public void fn11(int(*(*fp)(int))(double)); public void fn12(int x = 5, std::string s = "default"); public void fn13(std::function f = nullptr); diff --git a/scripts/cxx-api/tests/snapshots/should_handle_concept/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_concept/snapshot.api index 1b3a474c3a0..e3b332471d7 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_concept/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_concept/snapshot.api @@ -1,4 +1,4 @@ template -concept test::CSSParserSink = requires(CSSSyntaxParser &parser) { +concept test::CSSParserSink = requires(CSSSyntaxParser& parser) { { T::consume(parser) } -> std::convertible_to; }; diff --git a/scripts/cxx-api/tests/snapshots/should_handle_concept_indent/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_concept_indent/snapshot.api index 8ed0e695f88..28740457b61 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_concept_indent/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_concept_indent/snapshot.api @@ -1,9 +1,9 @@ template -concept test::CSSUniqueComponentValueVisitors = CSSSyntaxVisitorReturn && (CSSComponentValueVisitor && ...) && - ((CSSFunctionVisitor ? 1 : 0) + ... + 0) <= 1 && - ((CSSPreservedTokenVisitor ? 1 : 0) + ... + 0) <= 1 && +concept test::CSSUniqueComponentValueVisitors = CSSSyntaxVisitorReturn&& (CSSComponentValueVisitor && ...) && + ((CSSFunctionVisitor ? 1 : 0) + ... + 0) <= 1&& + ((CSSPreservedTokenVisitor ? 1 : 0) + ... + 0) <= 1&& ((CSSSimpleBlockVisitor ? 1 : 0) + ... + 0) <= 1; template -concept test::CSSParserSink = requires(CSSSyntaxParser &parser) { +concept test::CSSParserSink = requires(CSSSyntaxParser& parser) { { T::consume(parser) } -> std::convertible_to; }; diff --git a/scripts/cxx-api/tests/snapshots/should_handle_deprecated_msg/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_deprecated_msg/snapshot.api index 65e0334c1d0..3e8df8d033e 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_deprecated_msg/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_deprecated_msg/snapshot.api @@ -6,8 +6,8 @@ interface RCTDeprecatedInterface { } interface RCTTestInterface { - public virtual NSArray * deprecatedMethod:(id param); - public virtual void normalMethod:(NSString * name); + public virtual NSArray* deprecatedMethod:(id param); + public virtual void normalMethod:(NSString* name); } protocol RCTDeprecatedProtocol { diff --git a/scripts/cxx-api/tests/snapshots/should_handle_function_pointer_variable/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_function_pointer_variable/snapshot.api index 9ad3ff78f6b..2ca7bdec336 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_function_pointer_variable/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_function_pointer_variable/snapshot.api @@ -1,5 +1,5 @@ struct test::FunctionPointers { public int(*withReturn)(double, float); - public void *(*returnsPointer)(const char *); public void(*simple)(int); + public void*(*returnsPointer)(const char *); } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api index 01e1b9d3f9c..4293bf02625 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_block_property/snapshot.api @@ -1,5 +1,5 @@ interface RCTInterfaceWithBlockProperty : public NSObject { - public @property (copy) NSString *(^blockWithReturn)(int value); - public @property (copy) void(^eventInterceptor)(NSString *eventName, NSDictionary *event, NSNumber *reactTag); + public @property (copy) NSString*(^blockWithReturn)(int value); + public @property (copy) void(^eventInterceptor)(NSString* eventName, NSDictionary* event, NSNumber* reactTag); public @property (copy) void(^simpleBlock)(void); } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_method/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_method/snapshot.api index 09d8acf7014..df124af7b02 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_method/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_method/snapshot.api @@ -1,5 +1,5 @@ interface RCTInterfaceWithMethod { - public virtual NSString * getTitle(); + public virtual NSString* getTitle(); public virtual void doSomething(); - public virtual void processValue:withName:(int value, NSString * name); + public virtual void processValue:withName:(int value, NSString* name); } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_property/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_property/snapshot.api index b5649f46485..a478845b700 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_interface_with_property/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_interface_with_property/snapshot.api @@ -1,5 +1,5 @@ interface RCTInterfaceWithProperty { public @property (assign) BOOL enabled; - public @property (copy) NSString * title; + public @property (copy) NSString* title; public @property (weak) id delegate; } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_method_with_attribute/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_method_with_attribute/snapshot.api index bf63be61569..522f4d92cdd 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_method_with_attribute/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_method_with_attribute/snapshot.api @@ -1,4 +1,4 @@ interface RCTTestInterface { - public virtual NSArray * interfaceDeprecatedMethod:(id param); - public virtual void normalMethod:(NSString * name); + public virtual NSArray* interfaceDeprecatedMethod:(id param); + public virtual void normalMethod:(NSString* name); } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_multiple_categories/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_multiple_categories/snapshot.api index 32cebd4b82f..d3f3804fada 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_multiple_categories/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_multiple_categories/snapshot.api @@ -1,12 +1,12 @@ category RCTConvert(CategoryOne) { - public virtual static NSString * methodOne:(id json); + public virtual static NSString* methodOne:(id json); } category RCTConvert(CategoryTwo) { - public virtual static NSString * methodTwo:(id json); + public virtual static NSString* methodTwo:(id json); } interface RCTConvert : public NSObject { - public virtual static NSString * methodOne:(id json); - public virtual static NSString * methodTwo:(id json); + public virtual static NSString* methodOne:(id json); + public virtual static NSString* methodTwo:(id json); } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_method/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_method/snapshot.api index 3cd0361bbc0..3ca06a48508 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_method/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_method/snapshot.api @@ -1,5 +1,5 @@ protocol RCTProtocolWithMethod { - public virtual NSString * getTitle(); + public virtual NSString* getTitle(); public virtual void doSomething(); - public virtual void processValue:withName:(int value, NSString * name); + public virtual void processValue:withName:(int value, NSString* name); } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_property/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_property/snapshot.api index c2322a45e0b..1b95f53fce4 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_property/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_protocol_with_property/snapshot.api @@ -1,5 +1,5 @@ protocol RCTProtocolWithProperty { public @property (assign) BOOL enabled; - public @property (copy) NSString * title; + public @property (copy) NSString* title; public @property (weak) id delegate; } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_pure_virtual_trailing_return/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_pure_virtual_trailing_return/snapshot.api index ea4b88b13cd..d814c71a0dd 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_pure_virtual_trailing_return/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_pure_virtual_trailing_return/snapshot.api @@ -1,5 +1,5 @@ class test::Base { - public virtual const char * getName() = 0; + public virtual const char* getName() = 0; public virtual std::vector getMethods() = 0; } diff --git a/scripts/cxx-api/tests/snapshots/should_handle_unnamed_template_param_with_default_value/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_unnamed_template_param_with_default_value/snapshot.api index 2e9194009db..50a277c93f2 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_unnamed_template_param_with_default_value/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_unnamed_template_param_with_default_value/snapshot.api @@ -12,5 +12,5 @@ class test::Symbol { struct test::Value { template ::value || std::is_base_of::value || std::is_base_of::value || std::is_base_of::value>> - public Value(T && other); + public Value(T&& other); } diff --git a/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api index af18855b4a5..88badbbccb0 100644 --- a/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api @@ -1,7 +1,7 @@ struct other::Consumer { public ::test::inner::MyType create(); - public void process(const ::test::inner::MyType & param); - public void processPtr(::test::inner::MyType * param); + public void process(const ::test::inner::MyType& param); + public void processPtr(::test::inner::MyType* param); } diff --git a/scripts/cxx-api/tests/snapshots/should_qualify_nested_template_type_with_underscore/snapshot.api b/scripts/cxx-api/tests/snapshots/should_qualify_nested_template_type_with_underscore/snapshot.api index 616760305e9..1f67e496a5b 100644 --- a/scripts/cxx-api/tests/snapshots/should_qualify_nested_template_type_with_underscore/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_qualify_nested_template_type_with_underscore/snapshot.api @@ -1,5 +1,5 @@ template -facebook::react::detail::is_dynamic::type & facebook::react::jsArgAsDynamic(T && args, size_t n); +facebook::react::detail::is_dynamic::type& facebook::react::jsArgAsDynamic(T&& args, size_t n); template diff --git a/scripts/cxx-api/tests/snapshots/should_qualify_ptr_const_args/snapshot.api b/scripts/cxx-api/tests/snapshots/should_qualify_ptr_const_args/snapshot.api index a75e6cc67a1..ec31650e946 100644 --- a/scripts/cxx-api/tests/snapshots/should_qualify_ptr_const_args/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_qualify_ptr_const_args/snapshot.api @@ -1 +1 @@ -void test::doSomething(const Node *const node, int x); +void test::doSomething(const Node* const node, int x); diff --git a/scripts/cxx-api/tests/snapshots/should_strip_objc_macros/snapshot.api b/scripts/cxx-api/tests/snapshots/should_strip_objc_macros/snapshot.api index b0c18447476..e42d0b90b9d 100644 --- a/scripts/cxx-api/tests/snapshots/should_strip_objc_macros/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_strip_objc_macros/snapshot.api @@ -1,14 +1,14 @@ interface RCTTestMacros { public @property (strong, readonly) dispatch_queue_t methodQueue; public @property (weak, readonly) id bridge; - public virtual instancetype initWithDelegate:options:(id delegate, NSDictionary * options); - public virtual instancetype initWithName:(NSString * name); + public virtual instancetype initWithDelegate:options:(id delegate, NSDictionary* options); + public virtual instancetype initWithName:(NSString* name); public virtual static UIUserInterfaceStyle userInterfaceStyle(); public virtual void deprecatedMethod(); } protocol RCTTestProtocol { - public @property (assign, readonly) NSString * name; + public @property (assign, readonly) NSString* name; public virtual void normalMethod(); public virtual void requiredMethod(); }