Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1414e12

Browse filesBrowse files
committed
Update for Swift 4.1
1 parent c5bc81a commit 1414e12
Copy full SHA for 1414e12

File tree

Expand file treeCollapse file tree

8 files changed

+33
-22
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+33
-22
lines changed
Open diff view settings
Collapse file

‎Reflection.podspec‎

Copy file name to clipboardExpand all lines: Reflection.podspec
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Pod::Spec.new do |s|
22
s.name = "Reflection"
3-
s.version = "0.15.0"
3+
s.version = "0.16.0"
44
s.summary = "Advanced Swift Reflection"
55
s.description = <<-DESC
66
Reflection enables advanced runtime features like dynamic construction of types and manipulating instance properties.
77
DESC
88
s.homepage = "https://github.com/Zewo/Reflection"
99
s.license = { :type => "MIT", :file => "LICENSE" }
1010
s.author = { "Brad Hilton" => "brad@skyvive.com" }
11-
s.source = { :git => "https://github.com/Zewo/Reflection.git", :tag => "0.15.0" }
11+
s.source = { :git => "https://github.com/Zewo/Reflection.git", :tag => "0.16.0" }
1212

1313
s.ios.deployment_target = "8.0"
1414
s.tvos.deployment_target = "9.0"
Collapse file

‎Sources/Reflection/Construct.swift‎

Copy file name to clipboardExpand all lines: Sources/Reflection/Construct.swift
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public func construct(_ type: Any.Type, constructor: (Property.Description) thro
1919
private func constructValueType<T>(_ constructor: (Property.Description) throws -> Any) throws -> T {
2020
guard Metadata(type: T.self)?.kind == .struct else { throw ReflectionError.notStruct(type: T.self) }
2121
let pointer = UnsafeMutablePointer<T>.allocate(capacity: 1)
22-
defer { pointer.deallocate(capacity: 1) }
22+
defer { pointer.deallocate() }
2323
var values: [Any] = []
2424
try constructType(storage: UnsafeMutableRawPointer(pointer), values: &values, properties: properties(T.self), constructor: constructor)
2525
return pointer.move()
Collapse file

‎Sources/Reflection/Metadata+Class.swift‎

Copy file name to clipboardExpand all lines: Sources/Reflection/Metadata+Class.swift
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ extension Metadata {
33

44
static let kind: Kind? = .class
55
var pointer: UnsafePointer<_Metadata._Class>
6+
7+
var nominalTypeDescriptor: NominalTypeDescriptor {
8+
return pointer.withMemoryRebound(to: NominalTypeDescriptor.self, capacity: 15, { $0[nominalTypeDescriptorLocation] })
9+
}
610

7-
var nominalTypeDescriptorOffsetLocation: Int {
11+
var nominalTypeDescriptorLocation: Int {
812
return is64BitPlatform ? 8 : 11
913
}
1014

Collapse file

‎Sources/Reflection/Metadata+Struct.swift‎

Copy file name to clipboardExpand all lines: Sources/Reflection/Metadata+Struct.swift
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ extension Metadata {
22
struct Struct : NominalType {
33
static let kind: Kind? = .struct
44
var pointer: UnsafePointer<_Metadata._Struct>
5-
var nominalTypeDescriptorOffsetLocation: Int {
6-
return 1
5+
var nominalTypeDescriptor: NominalTypeDescriptor {
6+
return pointer.pointee.nominalTypeDescriptor
77
}
88
}
99
}
1010

1111
extension _Metadata {
1212
struct _Struct {
1313
var kind: Int
14-
var nominalTypeDescriptorOffset: Int
14+
var nominalTypeDescriptor: NominalTypeDescriptor
1515
var parent: Metadata?
1616
}
1717
}
Collapse file

‎Sources/Reflection/NominalType.swift‎

Copy file name to clipboardExpand all lines: Sources/Reflection/NominalType.swift
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
protocol NominalType : MetadataType {
2-
var nominalTypeDescriptorOffsetLocation: Int { get }
2+
var nominalTypeDescriptor: NominalTypeDescriptor { get }
33
}
44

55
extension NominalType {
6-
var nominalTypeDescriptor: NominalTypeDescriptor {
7-
let pointer = UnsafePointer<Int>(self.pointer)
8-
let base = pointer.advanced(by: nominalTypeDescriptorOffsetLocation)
9-
return NominalTypeDescriptor(pointer: relativePointer(base: base, offset: base.pointee))
10-
}
116

127
var fieldTypes: [Any.Type]? {
138
guard let function = nominalTypeDescriptor.fieldTypesAccessor else { return nil }
Collapse file

‎Sources/Reflection/NominalTypeDescriptor.swift‎

Copy file name to clipboardExpand all lines: Sources/Reflection/NominalTypeDescriptor.swift
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
struct NominalTypeDescriptor : PointerType {
2+
typealias Pointee = _NominalTypeDescriptor
3+
24
var pointer: UnsafePointer<_NominalTypeDescriptor>
35

46
var mangledName: String {
5-
return String(cString: relativePointer(base: pointer, offset: pointer.pointee.mangledName) as UnsafePointer<CChar>)
7+
// return String(cString: pointer.pointee.mangledName)
8+
return String(cString: relativePointer(base: pointer, offset: pointer.pointee.mangledName) as UnsafePointer<UInt8>)
69
}
710

811
var numberOfFields: Int {
Collapse file

‎Sources/Reflection/ValueWitnessTable.swift‎

Copy file name to clipboardExpand all lines: Sources/Reflection/ValueWitnessTable.swift
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ struct _ValueWitnessTable {
2929
let initializeWithCopy: Int
3030
let assignWithCopy: Int
3131
let initializeBufferWithTake: Int
32-
let initializeWithTake: Int
33-
let assignWithTake: Int
34-
let allocateBuffer: Int
35-
let initializeBufferWithTakeOrBuffer: Int
36-
let destroyArray: Int
37-
let initializeArrayWithCopy: Int
38-
let initializeArrayWithTakeFrontToBack: Int
39-
let initializeArrayWithTakeBackToFront: Int
4032
let size: Int
4133
let align: Int
4234
let stride: Int
Collapse file

‎Tests/ReflectionTests/InternalTests.swift‎

Copy file name to clipboardExpand all lines: Tests/ReflectionTests/InternalTests.swift
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ import XCTest
33

44
public class InternalTests : XCTestCase {
55

6+
func testDumbedDownTest() {
7+
struct NominalTypeDescriptor {
8+
let something: Int32
9+
let numberOfProperties: Int32
10+
}
11+
12+
struct StructMetadata {
13+
let kind: Int
14+
let nominalTypeDescriptor: UnsafePointer<NominalTypeDescriptor>
15+
}
16+
17+
let type: Any.Type = Person.self
18+
let numberOfProperties = unsafeBitCast(type, to: UnsafePointer<StructMetadata>.self).pointee.nominalTypeDescriptor.pointee.numberOfProperties
19+
print(numberOfProperties)
20+
}
21+
22+
623
func testShallowMetadata() {
724
func testShallowMetadata<T>(type: T.Type, expectedKind: Metadata.Kind) {
825
let shallowMetadata = Metadata(type: type)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.