Skip to content

Commit e3df5af

Browse files
coadofacebook-github-bot
authored andcommitted
Fix parsing of Objective-C interface generic inheritance (facebook#55775)
Summary: Doxygen incorrectly parses Objective-C interface declarations with protocol conformance. For example: ```objc interface RCTAppearance : RCTEventEmitter <RCTBridgeModule> ``` Doxygen splits this into **two separate base classes** in the XML: ```xml <basecompoundref>RCTEventEmitter</basecompoundref> <basecompoundref>&lt;RCTBridgeModule&gt;</basecompoundref> ``` This caused the parser to output: ``` interface RCTAppearance : public RCTEventEmitter, public <RCTBridgeModule> { ``` Instead of the expected: ``` interface RCTAppearance : public RCTEventEmitter <RCTBridgeModule> { ``` The fix detects when a "base class" name starts and ends with `<...>` (indicating it's a protocol conformance) and combines it with the preceding actual base class name. Also for multiple generics like: ``` interface RCTAlertManager : NSObject <RCTBridgeModule, RCTInvalidating> end ``` The output should be ``` interface RCTAlertManager : public NSObject <RCTBridgeModule, RCTInvalidating> end ``` Reviewed By: cipolleschi Differential Revision: D94351731
1 parent b49b79f commit e3df5af

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

scripts/cxx-api/parser/builders.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,24 @@ def create_interface_scope(
471471

472472
interface_scope = snapshot.create_interface(interface_name)
473473
base_classes = get_base_classes(scope_def, base_class=InterfaceScopeKind.Base)
474-
interface_scope.kind.add_base(base_classes)
474+
475+
# Doxygen incorrectly splits "Foo <Protocol1, Protocol2>" into separate base classes:
476+
# "Foo", "<Protocol1>", "<Protocol2>". Combine them back into "Foo <Protocol1, Protocol2>".
477+
combined_bases = []
478+
for base in base_classes:
479+
if base.name.startswith("<") and base.name.endswith(">") and combined_bases:
480+
prev_name = combined_bases[-1].name
481+
protocol = base.name[1:-1] # Strip < and >
482+
if "<" in prev_name and prev_name.endswith(">"):
483+
# Previous base already has protocols, merge inside the brackets
484+
combined_bases[-1].name = f"{prev_name[:-1]}, {protocol}>"
485+
else:
486+
# First protocol for this base class
487+
combined_bases[-1].name = f"{prev_name} <{protocol}>"
488+
else:
489+
combined_bases.append(base)
490+
491+
interface_scope.kind.add_base(combined_bases)
475492
interface_scope.location = scope_def.location.file
476493

477494
_process_objc_sections(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface RCTAppearance : public RCTEventEmitter <RCTBridgeModule> {
2+
public virtual instancetype init();
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace test {
11+
12+
@interface RCTAppearance : RCTEventEmitter <RCTBridgeModule>
13+
- (instancetype)init;
14+
@end
15+
16+
} // namespace test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
interface RCTAlertManager : public NSObject <RCTBridgeModule, RCTInvalidating> {
2+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace test {
11+
12+
@interface RCTAlertManager : NSObject <RCTBridgeModule, RCTInvalidating>
13+
14+
@end
15+
16+
} // namespace test

0 commit comments

Comments
 (0)