Skip to content

Move the actual Obj-C parts of ReflectionMirror.mm into a separate file, make ReflectionMirror.mm a .cpp file #34025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(swift_runtime_objc_sources
ErrorObject.mm
SwiftObject.mm
SwiftValue.mm
ReflectionMirror.mm
ReflectionMirrorObjC.mm
ObjCRuntimeGetImageNameFromClass.mm)

set(swift_runtime_sources
Expand Down Expand Up @@ -63,6 +63,7 @@ set(swift_runtime_sources
Portability.cpp
ProtocolConformance.cpp
RefCount.cpp
ReflectionMirror.cpp
RuntimeInvocationsTracking.cpp
SwiftDtoa.cpp)

Expand Down
7 changes: 7 additions & 0 deletions stdlib/public/runtime/Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,13 @@ class TypeInfo {
const Metadata *assocType,
const ProtocolRequirement *reqBase,
const ProtocolRequirement *assocConformance);

#if SWIFT_OBJC_INTEROP
/// Returns a retained Quick Look representation object an Obj-C object.
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
id _quickLookObjectForPointer(void *value);
#endif

} // end namespace swift

#endif /* SWIFT_RUNTIME_PRIVATE_H */
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#if SWIFT_OBJC_INTEROP
#include "swift/Runtime/ObjCBridge.h"
#include "SwiftObject.h"
#include <Foundation/Foundation.h>
#include <objc/objc.h>
#include <objc/runtime.h>
#endif

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

using namespace swift;

#if SWIFT_OBJC_INTEROP
// Declare the debugQuickLookObject selector.
@interface DeclareSelectors
- (id)debugQuickLookObject;
@end
#endif

namespace {

class FieldType {
Expand Down Expand Up @@ -751,16 +741,8 @@ AnyReturn subscript(intptr_t i, const char **outName,
}

#if SWIFT_OBJC_INTEROP
id quickLookObject() {
id object = [*reinterpret_cast<const id *>(value) retain];
if ([object respondsToSelector:@selector(debugQuickLookObject)]) {
id quickLookObject = [object debugQuickLookObject];
[quickLookObject retain];
[object release];
return quickLookObject;
}

return object;
id quickLookObject() override {
return _quickLookObjectForPointer(value);
}
#endif
};
Expand Down
42 changes: 42 additions & 0 deletions stdlib/public/runtime/ReflectionMirrorObjC.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/Runtime/Config.h"

#if SWIFT_OBJC_INTEROP

#include "Private.h"
#include <Foundation/Foundation.h>
#include <objc/objc.h>
#include <objc/runtime.h>

using namespace swift;

// Declare the debugQuickLookObject selector.
@interface DeclareSelectors
- (id)debugQuickLookObject;
@end

SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
id swift::_quickLookObjectForPointer(void *value) {
id object = [*reinterpret_cast<const id *>(value) retain];
if ([object respondsToSelector:@selector(debugQuickLookObject)]) {
id quickLookObject = [object debugQuickLookObject];
[quickLookObject retain];
[object release];
return quickLookObject;
}

return object;
}

#endif