mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
We'll need to apply the same tricks we're using for Array to Dictionary and String, so prepare to generate base classes for those buffers as well. Actually generate and use the one for Dictionary, but don't actually bridge it yet. Swift SVN r15167
89 lines
2.4 KiB
Plaintext
89 lines
2.4 KiB
Plaintext
//===--- NSSwiftXXXBase.mm.gyb - Cocoa bases for Swift container buffers --===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines:
|
|
//
|
|
// NSSwiftArrayBase, NSSwiftDictionaryBase, and eventually,
|
|
// NSSwiftStringBase
|
|
//
|
|
// To optimize bridging between Swift containers and their Cocoa
|
|
// counterparts, we derive Swift containers' buffers from the
|
|
// corresponding Cocoa classes; that way we can just hand a buffer off
|
|
// to Cocoa when it holds bridged types.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#include <objc/NSObject.h>
|
|
#include <objc/runtime.h>
|
|
#if __has_include(<objc/objc-internal.h>)
|
|
#include <objc/objc-internal.h>
|
|
#endif
|
|
#include "swift/Runtime/HeapObject.h"
|
|
#include "swift/Runtime/Metadata.h"
|
|
#include "swift/Runtime/ObjCBridge.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include "Private.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <mutex>
|
|
#include "../shims/shims.h"
|
|
|
|
// Redeclare these just we check them.
|
|
extern "C" id _objc_rootAutorelease(id);
|
|
|
|
using namespace swift;
|
|
|
|
% for Class in ('Array','Dictionary'):
|
|
@interface NSSwift${Class}Base : NS${Class}
|
|
{
|
|
SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS;
|
|
}
|
|
@end
|
|
|
|
@implementation NSSwift${Class}Base
|
|
+ (void)load {
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
class_setSuperclass(
|
|
objc_getClass("NSSwift${Class}"),
|
|
[NSSwift${Class}Base class]);
|
|
#pragma clang diagnostic pop
|
|
}
|
|
|
|
- (id)retain {
|
|
auto SELF = reinterpret_cast<HeapObject *>(self);
|
|
swift_retain(SELF);
|
|
return self;
|
|
}
|
|
- (oneway void)release {
|
|
auto SELF = reinterpret_cast<HeapObject *>(self);
|
|
swift_release(SELF);
|
|
}
|
|
- (id)autorelease {
|
|
return _objc_rootAutorelease(self);
|
|
}
|
|
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
|
|
- (void)dealloc {
|
|
auto SELF = reinterpret_cast<HeapObject *>(self);
|
|
swift_deallocObject(SELF, 0);
|
|
}
|
|
#pragma clang diagnostic pop
|
|
|
|
- (bool) __usesNativeSwiftReferenceCounting {
|
|
return true;
|
|
}
|
|
@end
|
|
% end
|