Skip to content

Commit 6b40a09

Browse files
authored
Move the actual Obj-C parts of ReflectionMirror.mm into a separate file, make ReflectionMirror.mm a .cpp file (swiftlang#34025)
1 parent 360afd6 commit 6b40a09

File tree

4 files changed

+53
-21
lines changed

4 files changed

+53
-21
lines changed

stdlib/public/runtime/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ set(swift_runtime_objc_sources
2222
ErrorObject.mm
2323
SwiftObject.mm
2424
SwiftValue.mm
25-
ReflectionMirror.mm
25+
ReflectionMirrorObjC.mm
2626
ObjCRuntimeGetImageNameFromClass.mm)
2727

2828
set(swift_runtime_sources
@@ -63,6 +63,7 @@ set(swift_runtime_sources
6363
Portability.cpp
6464
ProtocolConformance.cpp
6565
RefCount.cpp
66+
ReflectionMirror.cpp
6667
RuntimeInvocationsTracking.cpp
6768
SwiftDtoa.cpp)
6869

stdlib/public/runtime/Private.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,13 @@ class TypeInfo {
632632
const Metadata *assocType,
633633
const ProtocolRequirement *reqBase,
634634
const ProtocolRequirement *assocConformance);
635+
636+
#if SWIFT_OBJC_INTEROP
637+
/// Returns a retained Quick Look representation object an Obj-C object.
638+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
639+
id _quickLookObjectForPointer(void *value);
640+
#endif
641+
635642
} // end namespace swift
636643

637644
#endif /* SWIFT_RUNTIME_PRIVATE_H */

stdlib/public/runtime/ReflectionMirror.mm renamed to stdlib/public/runtime/ReflectionMirror.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#if SWIFT_OBJC_INTEROP
3535
#include "swift/Runtime/ObjCBridge.h"
3636
#include "SwiftObject.h"
37-
#include <Foundation/Foundation.h>
38-
#include <objc/objc.h>
39-
#include <objc/runtime.h>
4037
#endif
4138

4239
#if defined(_WIN32)
@@ -80,13 +77,6 @@ int asprintf(char **strp, const char *fmt, ...) {
8077

8178
using namespace swift;
8279

83-
#if SWIFT_OBJC_INTEROP
84-
// Declare the debugQuickLookObject selector.
85-
@interface DeclareSelectors
86-
- (id)debugQuickLookObject;
87-
@end
88-
#endif
89-
9080
namespace {
9181

9282
class FieldType {
@@ -751,16 +741,8 @@ AnyReturn subscript(intptr_t i, const char **outName,
751741
}
752742

753743
#if SWIFT_OBJC_INTEROP
754-
id quickLookObject() {
755-
id object = [*reinterpret_cast<const id *>(value) retain];
756-
if ([object respondsToSelector:@selector(debugQuickLookObject)]) {
757-
id quickLookObject = [object debugQuickLookObject];
758-
[quickLookObject retain];
759-
[object release];
760-
return quickLookObject;
761-
}
762-
763-
return object;
744+
id quickLookObject() override {
745+
return _quickLookObjectForPointer(value);
764746
}
765747
#endif
766748
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "swift/Runtime/Config.h"
14+
15+
#if SWIFT_OBJC_INTEROP
16+
17+
#include "Private.h"
18+
#include <Foundation/Foundation.h>
19+
#include <objc/objc.h>
20+
#include <objc/runtime.h>
21+
22+
using namespace swift;
23+
24+
// Declare the debugQuickLookObject selector.
25+
@interface DeclareSelectors
26+
- (id)debugQuickLookObject;
27+
@end
28+
29+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
30+
id swift::_quickLookObjectForPointer(void *value) {
31+
id object = [*reinterpret_cast<const id *>(value) retain];
32+
if ([object respondsToSelector:@selector(debugQuickLookObject)]) {
33+
id quickLookObject = [object debugQuickLookObject];
34+
[quickLookObject retain];
35+
[object release];
36+
return quickLookObject;
37+
}
38+
39+
return object;
40+
}
41+
42+
#endif

0 commit comments

Comments
 (0)