Skip to content

Commit

Permalink
Remove extern_category!
Browse files Browse the repository at this point in the history
Instead, emit a sealed trait inline, and use the next `extern_methods!`
syntax inside of that trait.

The macro was never public, so I have not added a changelog entry.
  • Loading branch information
madsmtm committed Jan 22, 2025
1 parent 8e09826 commit 03e253f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 63 deletions.
69 changes: 43 additions & 26 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,13 @@ pub enum Stmt {
methods: Vec<Method>,
documentation: Option<Documentation>,
},
/// @interface class_name (category_name) <protocols*>
/// @interface class_name (category_name)
/// ->
/// extern_category!
/// impl trait category_name {
/// extern_methods!(...)
/// }
///
/// impl trait category_name for class_name {}
ExternCategory {
id: ItemIdentifier,
actual_name: Option<String>,
Expand Down Expand Up @@ -940,7 +944,7 @@ impl Stmt {
.chain(protocol_impls)
.collect()
} else {
// extern_category!
// external category

if !generics.is_empty() {
panic!("external category: cannot handle generics");
Expand Down Expand Up @@ -2146,25 +2150,33 @@ impl Stmt {
methods,
documentation,
} => {
let cfg = self.cfg_gate_ln_for([ItemTree::objc("extern_category")], config);
write!(f, "{cfg}")?;
writeln!(f, "extern_category!(")?;
// Helper module to seal the trait.
writeln!(f, "mod private_{} {{", id.name)?;
writeln!(f, " pub trait Sealed {{}}")?;
writeln!(f, "}}")?;

writeln!(f)?;

if let Some(actual_name) = actual_name {
if *actual_name != id.name {
writeln!(f, " /// Category \"{actual_name}\" on [`{}`].", cls.name)?;
writeln!(f, " #[doc(alias = \"{actual_name}\")]")?;
writeln!(f, "/// Category \"{actual_name}\" on [`{}`].", cls.name)?;
writeln!(f, "#[doc(alias = \"{actual_name}\")]")?;
} else {
writeln!(f, " /// Category on [`{}`].", cls.name)?;
writeln!(f, "/// Category on [`{}`].", cls.name)?;
}
} else {
writeln!(f, " /// Category on [`{}`].", cls.name)?;
writeln!(f, "/// Category on [`{}`].", cls.name)?;
}
write!(f, "{}", documentation.fmt(None))?;

write!(f, " {}", self.cfg_gate_ln(config))?;
write!(f, " {availability}")?;
writeln!(f, " pub unsafe trait {} {{", id.name)?;
write!(f, "{}", self.cfg_gate_ln(config))?;
write!(f, "{availability}")?;
writeln!(
f,
"pub unsafe trait {}: ClassType + Sized + private_{}::Sealed {{",
id.name, id.name
)?;
writeln!(f, " extern_methods!(")?;
for method in methods {
write!(
f,
Expand All @@ -2173,29 +2185,34 @@ impl Stmt {
)?;
writeln!(f, "{method}")?;
}
writeln!(f, " }}")?;
writeln!(f, " );")?;
writeln!(f, "}}")?;

writeln!(f)?;

write!(
let impl_cfg = self.cfg_gate_ln_for(
[ItemTree::new(
cls.clone(),
superclasses_required_items(cls_superclasses.iter().cloned()),
)],
config,
);

write!(f, "{impl_cfg}")?;
writeln!(
f,
" {}",
self.cfg_gate_ln_for(
[ItemTree::new(
cls.clone(),
superclasses_required_items(cls_superclasses.iter().cloned())
)],
config,
)
"impl private_{}::Sealed for {} {{}}",
id.name,
cls.path_in_relation_to(id.location()),
)?;

write!(f, "{impl_cfg}")?;
writeln!(
f,
" unsafe impl {} for {} {{}}",
"unsafe impl {} for {} {{}}",
id.name,
cls.path_in_relation_to(id.location()),
)?;

writeln!(f, ");")?;
}
Self::ProtocolImpl {
location: id,
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/__framework_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pub use crate::runtime::{
AnyClass, AnyObject, AnyProtocol, Bool, Imp, NSObject, NSObjectProtocol, ProtocolObject, Sel,
};
pub use crate::{
extern_category, extern_class, extern_methods, extern_protocol, ClassType, MainThreadMarker,
MainThreadOnly, Message, ProtocolType,
extern_class, extern_methods, extern_protocol, ClassType, MainThreadMarker, MainThreadOnly,
Message, ProtocolType,
};
33 changes: 0 additions & 33 deletions crates/objc2/src/macros/extern_category.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/objc2/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod __msg_send_parse;
mod __rewrite_self_param;
mod available;
mod define_class;
mod extern_category;
mod extern_class;
mod extern_methods;
mod extern_protocol;
Expand Down
2 changes: 1 addition & 1 deletion generated
Submodule generated updated 79 files
+13 −6 AVFoundation/AVGeometry.rs
+27 −13 AVFoundation/AVTime.rs
+15 −8 AppKit/NSAccessibility.rs
+13 −6 AppKit/NSAdaptiveImageGlyph.rs
+14 −7 AppKit/NSAffineTransform.rs
+14 −7 AppKit/NSAppleScriptExtensions.rs
+135 −65 AppKit/NSAttributedString.rs
+18 −9 AppKit/NSCIImageRep.rs
+28 −14 AppKit/NSCollectionView.rs
+18 −9 AppKit/NSColor.rs
+14 −7 AppKit/NSFileWrapperExtensions.rs
+13 −6 AppKit/NSHelpManager.rs
+13 −6 AppKit/NSImage.rs
+14 −7 AppKit/NSItemProvider.rs
+14 −7 AppKit/NSKeyValueBinding.rs
+14 −7 AppKit/NSNibLoading.rs
+14 −7 AppKit/NSPasteboard.rs
+14 −7 AppKit/NSSharingService.rs
+13 −6 AppKit/NSSound.rs
+83 −41 AppKit/NSStringDrawing.rs
+26 −12 AppKit/NSTextAttachment.rs
+14 −7 AppKit/NSWorkspace.rs
+14 −7 ClassKit/NSUserActivity_CLSDeepLinks.rs
+14 −7 CloudKit/NSItemProvider_CKSharingSupport.rs
+14 −7 CoreImage/CIBarcodeDescriptor.rs
+15 −8 CoreImage/CIImageProvider.rs
+14 −7 ExceptionHandling/NSExceptionHandler.rs
+14 −7 FileProvider/NSFileProviderError.rs
+15 −8 Foundation/NSArchiver.rs
+14 −7 Foundation/NSClassDescription.rs
+14 −7 Foundation/NSError.rs
+14 −7 Foundation/NSKeyValueCoding.rs
+56 −28 Foundation/NSKeyValueObserving.rs
+14 −7 Foundation/NSKeyValueSharedObservers.rs
+28 −14 Foundation/NSKeyedArchiver.rs
+29 −15 Foundation/NSObject.rs
+14 −7 Foundation/NSObjectScripting.rs
+15 −8 Foundation/NSRunLoop.rs
+14 −7 Foundation/NSScriptClassDescription.rs
+14 −7 Foundation/NSScriptKeyValueCoding.rs
+14 −7 Foundation/NSScriptObjectSpecifiers.rs
+28 −14 Foundation/NSScriptWhoseTests.rs
+14 −7 Foundation/NSThread.rs
+12 −7 GameController/GCTypes.rs
+31 −24 InputMethodKit/IMKInputController.rs
+13 −8 LocalAuthenticationEmbeddedUI/LARight_UI.rs
+13 −6 MapKit/MKGeometry.rs
+14 −7 MapKit/NSUserActivity_MKMapItem.rs
+42 −20 MediaPlayer/AVFoundation_MPNowPlayingInfoLanguageOptionAdditions.rs
+16 −8 MediaPlayer/AVPlayerItem_MediaPlayerAdditions.rs
+14 −7 MediaPlayer/NSUserActivity_MediaPlayerAdditions.rs
+14 −7 Metal/MTLDeviceCertification.rs
+17 −10 NetworkExtension/mod.rs
+14 −7 QuartzCore/CATransform3D.rs
+126 −63 SceneKit/ModelIO.rs
+19 −10 SceneKit/SCNCAAnimationExtensions.rs
+15 −8 SceneKit/SceneKitTypes.rs
+18 −9 SpriteKit/SKNode.rs
+13 −6 UIKit/NSAdaptiveImageGlyph.rs
+54 −26 UIKit/NSAttributedString.rs
+14 −7 UIKit/NSIndexPath_UIKitAdditions.rs
+14 −7 UIKit/NSItemProvider_UIKitAdditions.rs
+55 −27 UIKit/NSStringDrawing.rs
+13 −6 UIKit/NSTextAttachment.rs
+98 −49 UIKit/UIAccessibility.rs
+14 −7 UIKit/UIAccessibilityContainer.rs
+14 −7 UIKit/UIAccessibilityCustomRotor.rs
+18 −9 UIKit/UIColor.rs
+27 −13 UIKit/UIGeometry.rs
+18 −9 UIKit/UIImage.rs
+14 −7 UIKit/UISceneActivationConditions.rs
+16 −8 UIKit/UNNotificationResponse_UIKitAdditions.rs
+14 −7 UniformTypeIdentifiers/NSItemProvider_UTType.rs
+28 −14 UniformTypeIdentifiers/UTAdditions.rs
+14 −7 UserNotifications/NSString_UserNotifications.rs
+21 −14 WebKit/NSAttributedString.rs
+16 −9 WebKit/WebPlugin.rs
+16 −9 WebKit/WebPluginContainer.rs
+14 −7 WebKit/WebScriptObject.rs

0 comments on commit 03e253f

Please sign in to comment.