Skip to content

Commit

Permalink
Parse typedefs that map to other typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 19, 2022
1 parent 2a8ae5c commit 075c18c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 25 deletions.
43 changes: 26 additions & 17 deletions header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clang::{Entity, EntityKind, EntityVisitResult};
use clang::{Entity, EntityKind, EntityVisitResult, TypeKind};
use proc_macro2::TokenStream;
use quote::{format_ident, quote, ToTokens, TokenStreamExt};

Expand Down Expand Up @@ -43,7 +43,7 @@ pub enum Stmt {
methods: Vec<Method>,
},
/// typedef Type TypedefName;
AliasDecl { name: String, type_name: String },
AliasDecl { name: String, type_: RustType },
// /// typedef struct Name { fields } TypedefName;
// X,
}
Expand Down Expand Up @@ -270,18 +270,28 @@ impl Stmt {
let underlying_ty = entity
.get_typedef_underlying_type()
.expect("typedef underlying type");
if let Some(type_name) = RustType::typedef_is_id(underlying_ty) {
// println!("typedef: {:?}, {:?}", name, type_name);
Some(Self::AliasDecl { name, type_name })
} else {
// println!(
// "typedef: {:?}, {:?}, {:?}, {:?}",
// entity.get_display_name(),
// entity.has_attributes(),
// entity.get_children(),
// underlying_ty,
// );
None
match underlying_ty.get_kind() {
TypeKind::ObjCObjectPointer => {
let type_name = RustType::typedef_is_id(underlying_ty).expect("typedef id");
Some(Self::AliasDecl {
name,
type_: RustType::TypeDef { name: type_name },
})
}
TypeKind::Typedef => {
let type_ = RustType::parse(underlying_ty, false, false);
Some(Self::AliasDecl { name, type_ })
}
_ => {
// println!(
// "typedef: {:#?}, {:#?}, {:#?}, {:#?}",
// entity.get_display_name(),
// entity.has_attributes(),
// entity.get_children(),
// underlying_ty,
// );
None
}
}
}
EntityKind::StructDecl => {
Expand Down Expand Up @@ -422,11 +432,10 @@ impl ToTokens for Stmt {
// }
quote!(pub type #name = NSObject;)
}
Self::AliasDecl { name, type_name } => {
Self::AliasDecl { name, type_ } => {
let name = format_ident!("{}", name);
let type_name = format_ident!("{}", type_name);

quote!(pub type #name = #type_name;)
quote!(pub type #name = #type_;)
}
};
tokens.append_all(result);
Expand Down
5 changes: 4 additions & 1 deletion icrate/src/generated/Foundation/NSGeometry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::__exported::NSString;
use crate::CoreGraphics::generated::CGBase::*;
use crate::CoreGraphics::generated::CGGeometry::*;
use crate::Foundation::generated::NSCoder::*;
Expand All @@ -7,6 +6,10 @@ use crate::Foundation::generated::NSValue::*;
use objc2::rc::{Id, Shared};
#[allow(unused_imports)]
use objc2::{extern_class, msg_send, msg_send_id, ClassType};
pub type NSPoint = CGPoint;
pub type NSSize = CGSize;
pub type NSRect = CGRect;
use super::__exported::NSString;
#[doc = "NSValueGeometryExtensions"]
impl NSValue {
pub unsafe fn valueWithPoint(point: NSPoint) -> Id<NSValue, Shared> {
Expand Down
1 change: 1 addition & 0 deletions icrate/src/generated/Foundation/NSHashTable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::Foundation::generated::NSString::*;
use objc2::rc::{Id, Shared};
#[allow(unused_imports)]
use objc2::{extern_class, msg_send, msg_send_id, ClassType};
pub type NSHashTableOptions = NSUInteger;
__inner_extern_class!(
#[derive(Debug)]
pub struct NSHashTable<ObjectType: Message>;
Expand Down
1 change: 1 addition & 0 deletions icrate/src/generated/Foundation/NSMapTable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::Foundation::generated::NSString::*;
use objc2::rc::{Id, Shared};
#[allow(unused_imports)]
use objc2::{extern_class, msg_send, msg_send_id, ClassType};
pub type NSMapTableOptions = NSUInteger;
__inner_extern_class!(
#[derive(Debug)]
pub struct NSMapTable<KeyType: Message, ObjectType: Message>;
Expand Down
2 changes: 2 additions & 0 deletions icrate/src/generated/Foundation/NSPropertyList.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::Foundation::generated::NSObject::*;
use objc2::rc::{Id, Shared};
#[allow(unused_imports)]
use objc2::{extern_class, msg_send, msg_send_id, ClassType};
pub type NSPropertyListReadOptions = NSPropertyListMutabilityOptions;
pub type NSPropertyListWriteOptions = NSUInteger;
extern_class!(
#[derive(Debug)]
pub struct NSPropertyListSerialization;
Expand Down
1 change: 1 addition & 0 deletions icrate/src/generated/Foundation/NSString.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::Foundation::generated::NSRange::*;
use objc2::rc::{Id, Shared};
#[allow(unused_imports)]
use objc2::{extern_class, msg_send, msg_send_id, ClassType};
pub type NSStringEncoding = NSUInteger;
extern_class!(
#[derive(Debug)]
pub struct NSString;
Expand Down
1 change: 1 addition & 0 deletions icrate/src/generated/Foundation/NSTextCheckingResult.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::Foundation::generated::NSRange::*;
use objc2::rc::{Id, Shared};
#[allow(unused_imports)]
use objc2::{extern_class, msg_send, msg_send_id, ClassType};
pub type NSTextCheckingTypes = u64;
pub type NSTextCheckingKey = NSString;
extern_class!(
#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions icrate/src/generated/Foundation/NSURL.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub type NSURLFileProtectionType = NSString;
pub type NSURLUbiquitousItemDownloadingStatus = NSString;
pub type NSURLUbiquitousSharedItemRole = NSString;
pub type NSURLUbiquitousSharedItemPermissions = NSString;
pub type NSURLBookmarkFileCreationOptions = NSUInteger;
extern_class!(
#[derive(Debug)]
pub struct NSURL;
Expand Down
19 changes: 12 additions & 7 deletions icrate/src/generated/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ mod __exported {
pub use super::NSFileWrapper::NSFileWrapper;
pub use super::NSFormatter::NSFormatter;
pub use super::NSGarbageCollector::NSGarbageCollector;
pub use super::NSGeometry::{NSPoint, NSRect, NSSize};
pub use super::NSHTTPCookie::{
NSHTTPCookie, NSHTTPCookiePropertyKey, NSHTTPCookieStringPolicy,
};
pub use super::NSHTTPCookieStorage::NSHTTPCookieStorage;
pub use super::NSHashTable::NSHashTable;
pub use super::NSHashTable::{NSHashTable, NSHashTableOptions};
pub use super::NSHost::NSHost;
pub use super::NSISO8601DateFormatter::NSISO8601DateFormatter;
pub use super::NSIndexPath::NSIndexPath;
Expand All @@ -248,7 +249,7 @@ mod __exported {
pub use super::NSListFormatter::NSListFormatter;
pub use super::NSLocale::{NSLocale, NSLocaleKey};
pub use super::NSLock::{NSCondition, NSConditionLock, NSLock, NSLocking, NSRecursiveLock};
pub use super::NSMapTable::NSMapTable;
pub use super::NSMapTable::{NSMapTable, NSMapTableOptions};
pub use super::NSMassFormatter::NSMassFormatter;
pub use super::NSMeasurement::NSMeasurement;
pub use super::NSMeasurementFormatter::NSMeasurementFormatter;
Expand Down Expand Up @@ -294,7 +295,9 @@ mod __exported {
NSProgress, NSProgressFileOperationKind, NSProgressKind, NSProgressReporting,
NSProgressUserInfoKey,
};
pub use super::NSPropertyList::NSPropertyListSerialization;
pub use super::NSPropertyList::{
NSPropertyListReadOptions, NSPropertyListSerialization, NSPropertyListWriteOptions,
};
pub use super::NSProtocolChecker::NSProtocolChecker;
pub use super::NSProxy::NSProxy;
pub use super::NSRegularExpression::{NSDataDetector, NSRegularExpression};
Expand Down Expand Up @@ -326,11 +329,13 @@ mod __exported {
NSStreamSocketSecurityLevel,
};
pub use super::NSString::{
NSConstantString, NSMutableString, NSSimpleCString, NSString,
NSConstantString, NSMutableString, NSSimpleCString, NSString, NSStringEncoding,
NSStringEncodingDetectionOptionsKey, NSStringTransform,
};
pub use super::NSTask::NSTask;
pub use super::NSTextCheckingResult::{NSTextCheckingKey, NSTextCheckingResult};
pub use super::NSTextCheckingResult::{
NSTextCheckingKey, NSTextCheckingResult, NSTextCheckingTypes,
};
pub use super::NSThread::NSThread;
pub use super::NSTimeZone::NSTimeZone;
pub use super::NSTimer::NSTimer;
Expand Down Expand Up @@ -393,8 +398,8 @@ mod __exported {
NSXPCListenerEndpoint, NSXPCProxyCreating,
};
pub use super::NSURL::{
NSFileSecurity, NSURLComponents, NSURLFileProtectionType, NSURLFileResourceType,
NSURLQueryItem, NSURLResourceKey, NSURLThumbnailDictionaryItem,
NSFileSecurity, NSURLBookmarkFileCreationOptions, NSURLComponents, NSURLFileProtectionType,
NSURLFileResourceType, NSURLQueryItem, NSURLResourceKey, NSURLThumbnailDictionaryItem,
NSURLUbiquitousItemDownloadingStatus, NSURLUbiquitousSharedItemPermissions,
NSURLUbiquitousSharedItemRole, NSURL,
};
Expand Down

0 comments on commit 075c18c

Please sign in to comment.