codegen
codegen copied to clipboard
生成 Dart 版的 Foundation
先用 Foundation 试水,遇到的问题列在这个 Issue 里,逐个解决:
- 生成代码功能问题:
- [x] 枚举优化: NS_ERROR_ENUM, NS_CLOSED_ENUM
- [ ] 区分泛型和协议,语法很相似,包含参数、返回值中的。('id<XXXProtocol>' 和
NSArray<ObjectType>分别转成XXXProtocol和List) - [ ] 生成函数指针声明(FunctionPointer), 处理含有函数指针的内容,如
@property (readonly, copy) NSArray<void (^)(void)> *executionBlocks;
@property (nullable) NSUInteger (*hashFunction)(const void *item, NSUInteger (* _Nullable size)(const void *item));
- [ ] 重构
typedef(现在写死成解析Block,应区分其他情况,比如定义函数指针) - [x] 解析
@property (readonly) const void *bytes NS_RETURNS_INNER_POINTER;时误把bytes当做类型,原因跟typeSpecifier出现多次有关。 - [x] 生成
API_DEPRECATED_WITH_REPLACEMENT等 ~- [ ] 生成常量声明,如:FOUNDATION_EXPORT double const foo;~ ~- [ ] 生成函数声明,如FOUNDATION_EXPORT NSObject * _Nullable NXReadNSObjectFromCoder(NSCoder *decoder) API_DEPRECATED("Not supported", macos(10.0,10.5), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0));~ - [ ] (可能包含上面的问题)解决
flutter format后的所有 Dart 语法报错问题
- 解析报错问题:
- [x]
NSBundle.h报错line 245:109 no viable alternative at input 'FOUNDATION_EXPORT NSNotificationName const NSBundleResourceRequestLowDiskSpaceNotification API_AVAILABLE(ios(9.0' - [x]
NSCompoundPredicate.h, NSData.h报错line 11:64 extraneous input '<' expecting {';', ','} - [x]
NSCompoundPredicate.h报错line 34:0 mismatched input '+' expecting '@end' - [x]
NSCompoundPredicate.h报错line 34:80 extraneous input ')' expecting {'BOOL', 'Class', 'bycopy', 'byref', 'id', 'IMP', 'in', 'inout', 'oneway', 'out', 'Protocol', 'SEL', 'self', 'super', 'atomic', 'nonatomic', 'retain', '__autoreleasing', '__block', '__bridge_retained', '__bridge_transfer', '__covariant', '__contravariant', '__deprecated', '__kindof', '__unused', NULL_UNSPECIFIED, NULLABLE, NONNULL, 'null_resettable', 'NS_INLINE', 'NS_ENUM', 'NS_OPTIONS', 'assign', 'copy', 'getter', 'setter', 'strong', 'readonly', 'readwrite', 'weak', 'unsafe_unretained', 'IBOutlet', 'IBOutletCollection', 'IBInspectable', 'IB_DESIGNABLE', IDENTIFIER, LP} - [x]
NSCompoundPredicate.h报错line 34:95 missing ';' at 'NS_SWIFT_NAME' - [x]
NSException.h报错line 79:39 mismatched input '(' expecting ';'
- 内存问题:
- [x] 目前针对单个大文件的 workaround 为提升老生代内存上限,多个文件开多线程并行可 fix
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: 0x101018fd1 node::Abort() (.cold.1) [/usr/local/bin/node]
2: 0x10008632b node::FatalError(char const*, char const*) [/usr/local/bin/node]
3: 0x10008646c node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
4: 0x100187727 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
5: 0x1001876c7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
6: 0x100312e75 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
7: 0x10031ae5c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
8: 0x1002f0907 v8::internal::Handle<v8::internal::TransitionArray> v8::internal::Factory::NewWeakFixedArrayWithMap<v8::internal::TransitionArray>(v8::internal::RootIndex, int, v8::internal::AllocationType) [/usr/local/bin/node]
9: 0x1002f07f9 v8::internal::Factory::NewTransitionArray(int, int) [/usr/local/bin/node]
10: 0x10055a618 v8::internal::TransitionsAccessor::Insert(v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [/usr/local/bin/node]
11: 0x10050695a v8::internal::Map::ConnectTransition(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::SimpleTransitionFlag) [/usr/local/bin/node]
12: 0x100506d08 v8::internal::Map::CopyReplaceDescriptors(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [/usr/local/bin/node]
13: 0x100501ce4 v8::internal::Map::CopyAddDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [/usr/local/bin/node]
14: 0x100501a16 v8::internal::Map::CopyWithField(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [/usr/local/bin/node]
15: 0x1005082b7 v8::internal::Map::TransitionToDataProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::StoreOrigin) [/usr/local/bin/node]
16: 0x1004fb1d9 v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::StoreOrigin) [/usr/local/bin/node]
17: 0x100527a03 v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin) [/usr/local/bin/node]
18: 0x10064933c v8::internal::Runtime::SetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin, v8::Maybe<v8::internal::ShouldThrow>) [/usr/local/bin/node]
19: 0x10064c7f5 v8::internal::Runtime_SetKeyedProperty(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
20: 0x100972e59 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
21: 0xa8066bde5ca
fish: 'codegen /Applications/Xcode.app…' terminated by signal SIGABRT (Abort)
Foundation 头文件路径:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers
已经可以 Run 起来的 Header(运行不挂掉,但生成的内容未经过 check):
- [x] Foundation.h
- [x] FoundationErrors.h
- [x] FoundationLegacySwiftCompatibility.h
- [x] NSArray.h
- [x] NSAttributedString.h
- [x] NSAutoreleasePool.h
- [x] NSBundle.h
- [x] NSByteCountFormatter.h
- [x] NSByteOrder.h
- [x] NSCache.h
- [x] NSCalendar.h
- [x] NSCharacterSet.h
- [x] NSCoder.h
- [x] NSComparisonPredicate.h
- [x] NSCompoundPredicate.h
- [x] NSData.h
- [x] NSDate.h
- [x] NSDateComponentsFormatter.h
- [x] NSDateFormatter.h
- [x] NSDateInterval.h
- [x] NSDateIntervalFormatter.h
- [x] NSDecimal.h
- [x] NSDecimalNumber.h
- [x] NSDictionary.h
- [x] NSEnergyFormatter.h
- [x] NSEnumerator.h
- [x] NSError.h
- [x] NSException.h
- [x] NSExpression.h
- [x] NSExtensionContext.h
- [x] NSExtensionItem.h
- [x] NSExtensionRequestHandling.h
- [x] NSFileCoordinator.h
- [x] NSFileHandle.h
- [x] NSFileManager.h
- [x] NSFilePresenter.h
- [x] NSFileVersion.h
- [x] NSFileWrapper.h
- [x] NSFormatter.h
- [x] NSHashTable.h
- [x] NSHTTPCookie.h
- [x] NSHTTPCookieStorage.h
- [x] NSIndexPath.h
- [x] NSIndexSet.h
- [x] NSInvocation.h
- [x] NSISO8601DateFormatter.h
- [x] NSItemProvider.h
- [x] NSItemProviderReadingWriting.h
- [x] NSJSONSerialization.h
- [x] NSKeyedArchiver.h
- [x] NSKeyValueCoding.h
- [x] NSKeyValueObserving.h
- [x] NSLengthFormatter.h
- [x] NSLinguisticTagger.h
- [x] NSListFormatter.h
- [x] NSLocale.h
- [x] NSLock.h
- [x] NSMapTable.h
- [x] NSMassFormatter.h
- [x] NSMeasurement.h
- [x] NSMeasurementFormatter.h
- [x] NSMetadata.h
- [x] NSMetadataAttributes.h
- [x] NSMethodSignature.h
- [x] NSNetServices.h
- [x] NSNotification.h
- [x] NSNotificationQueue.h
- [x] NSNull.h
- [x] NSNumberFormatter.h
- [x] NSObjCRuntime.h
- [x] NSObject.h
- [x] NSOperation.h
- [x] NSOrderedCollectionChange.h
- [x] NSOrderedCollectionDifference.h
- [x] NSOrderedSet.h
- [x] NSOrthography.h
- [x] NSPathUtilities.h
- [x] NSPersonNameComponents.h
- [x] NSPersonNameComponentsFormatter.h
- [x] NSPointerArray.h
- [x] NSPointerFunctions.h
- [x] NSPort.h
- [x] NSPredicate.h
- [x] NSProcessInfo.h
- [x] NSProgress.h
- [x] NSPropertyList.h
- [x] NSProxy.h
- [x] NSRange.h
- [x] NSRegularExpression.h
- [x] NSRelativeDateTimeFormatter.h
- [x] NSRunLoop.h
- [x] NSScanner.h
- [x] NSSet.h
- [x] NSSortDescriptor.h
- [x] NSStream.h
- [x] NSString.h
- [x] NSTextCheckingResult.h
- [x] NSThread.h
- [x] NSTimer.h
- [x] NSTimeZone.h
- [x] NSUbiquitousKeyValueStore.h
- [x] NSUndoManager.h
- [x] NSUnit.h
- [x] NSURL.h
- [x] NSURLAuthenticationChallenge.h
- [x] NSURLCache.h
- [x] NSURLConnection.h
- [x] NSURLCredential.h
- [x] NSURLCredentialStorage.h
- [x] NSURLError.h
- [x] NSURLProtectionSpace.h
- [x] NSURLProtocol.h
- [x] NSURLRequest.h
- [x] NSURLResponse.h
- [x] NSURLSession.h
- [x] NSUserActivity.h
- [x] NSUserDefaults.h
- [x] NSUUID.h
- [x] NSValue.h
- [x] NSValueTransformer.h
- [x] NSXMLParser.h
- [x] NSXPCConnection.h
- [x] NSZone.h