swift-reflection-test: Make it possible to call reflect multiple times

This allows you to test multiple class instances in the same file.
This commit is contained in:
David Farler
2016-05-02 12:57:46 -07:00
parent 8b8811f73e
commit b8cb128a17
3 changed files with 37 additions and 20 deletions

View File

@@ -26,7 +26,7 @@ let RequestReflectionInfos = "r"
let RequestReadBytes = "b";
let RequestSymbolAddress = "s"
let RequestStringLength = "l"
let RequestExit = "e"
let RequestDone = "d"
let RequestPointerSize = "p"
internal func debugLog(_ message: String) {
@@ -255,6 +255,10 @@ internal func sendPointerSize() {
/// - Get the pointer size of this process, which affects assumptions about the
/// the layout of runtime structures with pointer-sized fields.
/// - Read raw bytes out of this process's address space.
///
/// The parent sends a Done message to indicate that it's done
/// looking at this instance. It will continue to ask for instances,
/// so call doneReflecting() when you don't have any more instances.
public func reflect(_ instance: AnyObject) {
while let command = readLine(strippingNewline: true) {
switch command {
@@ -270,14 +274,20 @@ public func reflect(_ instance: AnyObject) {
sendStringLength()
case String(validatingUTF8: RequestPointerSize)!:
sendPointerSize();
case String(validatingUTF8: RequestExit)!:
exit(EXIT_SUCCESS)
case String(validatingUTF8: RequestDone)!:
return;
default:
fatalError("Unknown request received!")
}
}
}
/// Call this function to indicate to the parent that there are
/// no more instances to look at.
public func doneReflecting() {
sendValue(UInt(0))
}
/* Example usage
public protocol P {