Skip to content

Commit dccff39

Browse files
author
Enrico Granata
committed
Adjust for latest round of code review; change PrintForDebugger to _DebuggerSupport and stringForPrintObject; minor indentation and label fixups
1 parent fadc368 commit dccff39

File tree

4 files changed

+52
-53
lines changed

4 files changed

+52
-53
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(SWIFTLIB_ESSENTIAL
4242
ContiguousArrayBuffer.swift
4343
CString.swift
4444
CTypes.swift
45+
DebuggerSupport.swift
4546
EmptyCollection.swift
4647
ErrorType.swift
4748
Existential.swift
@@ -78,7 +79,6 @@ set(SWIFTLIB_ESSENTIAL
7879
Pointer.swift
7980
Policy.swift
8081
Print.swift
81-
PrintForDebugger.swift
8282
RandomAccessCollection.swift
8383
Range.swift.gyb
8484
RangeReplaceableCollection.swift.gyb

stdlib/public/core/PrintForDebugger.swift renamed to stdlib/public/core/DebuggerSupport.swift

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public enum _PrintForDebugger {
14-
13+
public enum _DebuggerSupport {
1514
internal enum CollectionStatus {
1615
case NotACollection
1716
case CollectionOfElements
@@ -39,15 +38,15 @@ public enum _PrintForDebugger {
3938
}
4039
}
4140

42-
internal static func asObjectIdentifier(value: Any) -> ObjectIdentifier? {
41+
internal static func asObjectIdentifier(_ value: Any) -> ObjectIdentifier? {
4342
if let ao = value as? AnyObject {
4443
return ObjectIdentifier(ao)
4544
} else {
4645
return nil
4746
}
4847
}
4948

50-
internal static func asNumericValue(value: Any) -> Int {
49+
internal static func asNumericValue(_ value: Any) -> Int {
5150
if let ao = value as? AnyObject {
5251
return unsafeBitCast(ao, to: Int.self)
5352
} else {
@@ -62,54 +61,54 @@ public enum _PrintForDebugger {
6261
) -> String? {
6362
let ds = mirror.displayStyle ?? .`struct`
6463
switch ds {
65-
case .optional:
64+
case .optional:
6665
if count > 0 {
67-
return "\(mirror.subjectType)"
66+
return "\(mirror.subjectType)"
6867
}
6968
else {
70-
if let x = value {
71-
return String(reflecting: x)
72-
}
69+
if let x = value {
70+
return String(reflecting: x)
71+
}
7372
}
74-
case .collection:
73+
case .collection:
7574
fallthrough
76-
case .dictionary:
75+
case .dictionary:
7776
fallthrough
78-
case .set:
77+
case .set:
7978
fallthrough
80-
case .tuple:
79+
case .tuple:
8180
return "\(Int(mirror.children.count)) elements"
82-
case .`struct`:
81+
case .`struct`:
8382
fallthrough
84-
case .`enum`:
83+
case .`enum`:
8584
if let x = value {
86-
if let cdsc = (x as? CustomDebugStringConvertible) {
87-
return cdsc.debugDescription
88-
}
89-
if let csc = (x as? CustomStringConvertible) {
90-
return csc.description
91-
}
85+
if let cdsc = (x as? CustomDebugStringConvertible) {
86+
return cdsc.debugDescription
87+
}
88+
if let csc = (x as? CustomStringConvertible) {
89+
return csc.description
90+
}
9291
}
9392
if count > 0 {
9493
return "\(mirror.subjectType)"
9594
}
96-
case .`class`:
95+
case .`class`:
9796
if let x = value {
98-
if let cdsc = (x as? CustomDebugStringConvertible) {
99-
return cdsc.debugDescription
100-
}
101-
if let csc = (x as? CustomStringConvertible) {
102-
return csc.description
103-
}
104-
// for a Class with no custom summary, mimic the Foundation default
105-
return "<\(x.dynamicType): 0x\(String(asNumericValue(value: x), radix: 16, uppercase: false))>"
97+
if let cdsc = (x as? CustomDebugStringConvertible) {
98+
return cdsc.debugDescription
99+
}
100+
if let csc = (x as? CustomStringConvertible) {
101+
return csc.description
102+
}
103+
// for a Class with no custom summary, mimic the Foundation default
104+
return "<\(x.dynamicType): 0x\(String(asNumericValue(x), radix: 16, uppercase: false))>"
106105
} else {
107-
// but if I can't provide a value, just use the type anyway
108-
return "\(mirror.subjectType)"
106+
// but if I can't provide a value, just use the type anyway
107+
return "\(mirror.subjectType)"
109108
}
110109
}
111110
if let x = value {
112-
return String(reflecting: x)
111+
return String(reflecting: x)
113112
}
114113
return nil
115114
}
@@ -139,7 +138,7 @@ public enum _PrintForDebugger {
139138
}
140139
}
141140

142-
internal static func printForDebuggerImpl<StreamType: OutputStream>(
141+
internal static func printForDebuggerImpl<StreamType : OutputStream>(
143142
value: Any?,
144143
mirror: Mirror,
145144
name: String?,
@@ -204,7 +203,7 @@ public enum _PrintForDebugger {
204203
}
205204

206205
if let x = value {
207-
if let valueIdentifier = asObjectIdentifier(value: x) {
206+
if let valueIdentifier = asObjectIdentifier(x) {
208207
if refsAlreadySeen.contains(valueIdentifier) {
209208
print(" { ... }", to: &targetStream)
210209
return
@@ -266,7 +265,7 @@ public enum _PrintForDebugger {
266265
}
267266
}
268267

269-
public static func printForDebugger(value: Any) -> String {
268+
public static func stringForPrintObject(_ value: Any) -> String {
270269
var maxItemCounter = Int.max
271270
var refs = Set<ObjectIdentifier>()
272271
var targetStream = ""

stdlib/public/core/GroupInfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,6 @@
142142
"Tuple.swift",
143143
"NewtypeWrapper.swift",
144144
"UnsafeBitMap.swift",
145-
"PrintForDebugger.swift"
145+
"DebuggerSupport.swift"
146146
]
147147
}

test/1_stdlib/PrintForDebugger.swift renamed to test/1_stdlib/DebuggerSupport.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,39 @@ class ClassWithMirror: CustomReflectable {
1919
}
2020
}
2121

22-
let PrintForDebuggerTests = TestSuite("PrintForDebugger")
23-
PrintForDebuggerTests.test("StructWithMembers") {
24-
let printed = _PrintForDebugger.printForDebugger(value: StructWithMembers())
22+
let StringForPrintObjectTests = TestSuite("StringForPrintObject")
23+
StringForPrintObjectTests.test("StructWithMembers") {
24+
let printed = _DebuggerSupport.stringForPrintObject(StructWithMembers())
2525
expectEqual(printed, "▿ StructWithMembers\n - a : 1\n - b : \"Hello World\"\n")
2626
}
2727

28-
PrintForDebuggerTests.test("ClassWithMembers") {
29-
let printed = _PrintForDebugger.printForDebugger(value: ClassWithMembers())
28+
StringForPrintObjectTests.test("ClassWithMembers") {
29+
let printed = _DebuggerSupport.stringForPrintObject(ClassWithMembers())
3030
expectTrue(printed.hasPrefix("<ClassWithMembers: 0x"))
3131
}
3232

33-
PrintForDebuggerTests.test("ClassWithMirror") {
34-
let printed = _PrintForDebugger.printForDebugger(value: ClassWithMirror())
33+
StringForPrintObjectTests.test("ClassWithMirror") {
34+
let printed = _DebuggerSupport.stringForPrintObject(ClassWithMirror())
3535
expectEqual(printed, "▿ ClassWithMirror\n - a : 1\n - b : \"Hello World\"\n")
3636
}
3737

38-
PrintForDebuggerTests.test("Array") {
39-
let printed = _PrintForDebugger.printForDebugger(value: [1,2,3,4])
38+
StringForPrintObjectTests.test("Array") {
39+
let printed = _DebuggerSupport.stringForPrintObject([1,2,3,4])
4040
expectEqual(printed, "▿ 4 elements\n - 0 : 1\n - 1 : 2\n - 2 : 3\n - 3 : 4\n")
4141
}
4242

43-
PrintForDebuggerTests.test("Dictionary") {
44-
let printed = _PrintForDebugger.printForDebugger(value: [1:2])
43+
StringForPrintObjectTests.test("Dictionary") {
44+
let printed = _DebuggerSupport.stringForPrintObject([1:2])
4545
expectEqual(printed, "▿ 1 elements\n ▿ 0 : 2 elements\n - .0 : 1\n - .1 : 2\n")
4646
}
4747

48-
PrintForDebuggerTests.test("NilOptional") {
49-
let printed = _PrintForDebugger.printForDebugger(value: nil as Int?)
48+
StringForPrintObjectTests.test("NilOptional") {
49+
let printed = _DebuggerSupport.stringForPrintObject(nil as Int?)
5050
expectTrue(printed.hasPrefix("nil"))
5151
}
5252

53-
PrintForDebuggerTests.test("SomeOptional") {
54-
let printed = _PrintForDebugger.printForDebugger(value: 3 as Int?)
53+
StringForPrintObjectTests.test("SomeOptional") {
54+
let printed = _DebuggerSupport.stringForPrintObject(3 as Int?)
5555
expectEqual(printed, "▿ Optional<Int>\n - some : 3\n")
5656
}
5757

0 commit comments

Comments
 (0)