Normalize pointer and reference spacing in parser output (#55901)

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
This commit is contained in:
Dawid Małecki authored and meta-codesync[bot] committed 2026-03-05 07:21:42 -08:00
1 parent 6558d0d374
commit f2ea073857
21 files changed
+75 -35

No files matched your search

+4 -1
View File
@@ -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(
+1
View File
@@ -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
@@ -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<id<RCTBridgeMethod>> *"
e.g. "NSArray< id< RCTBridgeMethod > > *" -> "NSArray<id<RCTBridgeMethod>>*"
"""
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:
@@ -10,7 +10,7 @@ class test::Clss {
public void fn7(std::vector<std::vector<std::pair<int, int>>> v);
public void fn8(std::map<K, std::function<void(A, B)>> 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<void()> f = nullptr);
@@ -1,4 +1,4 @@
template <typename T, typename ReturnT = std::any>
concept test::CSSParserSink = requires(CSSSyntaxParser &parser) {
concept test::CSSParserSink = requires(CSSSyntaxParser& parser) {
{ T::consume(parser) } -> std::convertible_to<ReturnT>;
};
@@ -1,9 +1,9 @@
template <typename ReturnT, typename... VisitorsT>
concept test::CSSUniqueComponentValueVisitors = CSSSyntaxVisitorReturn<ReturnT> && (CSSComponentValueVisitor<VisitorsT, ReturnT> && ...) &&
((CSSFunctionVisitor<VisitorsT, ReturnT> ? 1 : 0) + ... + 0) <= 1 &&
((CSSPreservedTokenVisitor<VisitorsT, ReturnT> ? 1 : 0) + ... + 0) <= 1 &&
concept test::CSSUniqueComponentValueVisitors = CSSSyntaxVisitorReturn<ReturnT>&& (CSSComponentValueVisitor<VisitorsT, ReturnT> && ...) &&
((CSSFunctionVisitor<VisitorsT, ReturnT> ? 1 : 0) + ... + 0) <= 1&&
((CSSPreservedTokenVisitor<VisitorsT, ReturnT> ? 1 : 0) + ... + 0) <= 1&&
((CSSSimpleBlockVisitor<VisitorsT, ReturnT> ? 1 : 0) + ... + 0) <= 1;
template <typename T, typename ReturnT = std::any>
concept test::CSSParserSink = requires(CSSSyntaxParser &parser) {
concept test::CSSParserSink = requires(CSSSyntaxParser& parser) {
{ T::consume(parser) } -> std::convertible_to<ReturnT>;
};
@@ -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 {
@@ -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 *);
}
@@ -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);
}
@@ -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);
}
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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;
}
@@ -1,5 +1,5 @@
class test::Base {
public virtual const char * getName() = 0;
public virtual const char* getName() = 0;
public virtual std::vector<test::Method> getMethods() = 0;
}
@@ -12,5 +12,5 @@ class test::Symbol {
struct test::Value {
template <typename T, typename = std::enable_if_t<std::is_base_of<test::Symbol, T>::value || std::is_base_of<test::BigInt, T>::value || std::is_base_of<test::String, T>::value || std::is_base_of<test::Object, T>::value>>
public Value(T && other);
public Value(T&& other);
}
@@ -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);
}
@@ -1,5 +1,5 @@
template <typename T>
facebook::react::detail::is_dynamic<T>::type & facebook::react::jsArgAsDynamic(T && args, size_t n);
facebook::react::detail::is_dynamic<T>::type& facebook::react::jsArgAsDynamic(T&& args, size_t n);
template <typename T>
@@ -1 +1 @@
void test::doSomething(const Node *const node, int x);
void test::doSomething(const Node* const node, int x);
@@ -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();
}