├── CODE_OWNERS.md
├── CONTRIBUTING.md
├── Experimental
└── PlaygroundRuntime
│ ├── PlaygroundRuntime.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ └── PlaygroundRuntime
│ ├── Info.plist
│ ├── PCMacroRuntime.swift
│ └── PlaygroundTransformRuntime.swift
├── LICENSE.txt
├── Legacy
└── PlaygroundLogger
│ ├── Documentation
│ ├── LoggerAPI.md
│ └── LoggerFormat.md
│ ├── PlaygroundLogger.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── PlaygroundLogger
│ ├── BytesStorage.swift
│ ├── BytesStream.swift
│ ├── Common.swift
│ ├── Environment.swift
│ ├── ExceptionSafety.m
│ ├── ExtensionBool.swift
│ ├── ExtensionCGColorRef.swift
│ ├── ExtensionDouble.swift
│ ├── ExtensionFloat.swift
│ ├── ExtensionMirrorDisplayStyle.swift
│ ├── ExtensionQuickLookObject.swift
│ ├── ExtensionString.swift
│ ├── ExtensionUInt64.swift
│ ├── ImageHandler.swift
│ ├── KeyedArchiver.swift
│ ├── KeyedUnarchiver.swift
│ ├── LoggerDecoderAPI.swift
│ ├── LoggerDecoderImpl.swift
│ ├── LoggerDefaults.swift
│ ├── LoggerInit.swift
│ ├── LoggerMirror.swift
│ ├── LoggingPolicyStack.swift
│ ├── PlaygroundGapWriter.swift
│ ├── PlaygroundLog.swift
│ ├── PlaygroundLogGap.swift
│ ├── PlaygroundLogPolicy.swift
│ ├── PlaygroundLogPrint.swift
│ ├── PlaygroundLogScope.swift
│ ├── PlaygroundLogger-Info.plist
│ ├── PlaygroundLogger-linux.bom
│ ├── PlaygroundLogger.h
│ ├── PlaygroundLogger.modulemap
│ ├── PlaygroundLogger.private.modulemap
│ ├── PlaygroundObjectWriter.swift
│ ├── PlaygroundRepresentation.swift
│ ├── PlaygroundScopeWriter.swift
│ ├── PlaygroundWriter.swift
│ ├── QuickLookEncodedObject.swift
│ ├── QuickLookEncoder.swift
│ ├── Regex.swift
│ ├── ScopeEvent.swift
│ ├── Stack.swift
│ ├── SwiftExceptionSafety.swift
│ ├── TestCases.swift
│ ├── TestInfrastructure.swift
│ ├── ThreadLocalStorage.swift
│ ├── ViewRenderer.swift
│ └── Woodchuck.swift
│ ├── PlaygroundLogger_TestDriver
│ └── main.swift
│ ├── PlaygroundLogger_iOS
│ ├── PlaygroundLogger_iOS-Info.plist
│ └── en.lproj
│ │ └── InfoPlist.strings
│ ├── PlaygroundLogger_tvOS
│ ├── PlaygroundLogger_tvOS-Info.plist
│ └── en.lproj
│ │ └── InfoPlist.strings
│ └── build.py
├── PlaygroundLogger
├── PlaygroundLogger.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── PlaygroundLogger (iOS).xcscheme
│ │ ├── PlaygroundLogger (macOS).xcscheme
│ │ └── PlaygroundLogger (tvOS).xcscheme
├── PlaygroundLogger
│ ├── CustomLoggable
│ │ ├── AppKit
│ │ │ ├── NSBezierPath+CustomOpaqueLoggable.swift
│ │ │ ├── NSBitmapImageRep+CustomOpaqueLoggable.swift
│ │ │ ├── NSColor+CustomOpaqueLoggable.swift
│ │ │ ├── NSCursor+CustomOpaqueLoggable.swift
│ │ │ ├── NSImage+CustomOpaqueLoggable.swift
│ │ │ └── NSView+CustomOpaqueLoggable.swift
│ │ ├── CoreGraphics
│ │ │ ├── CGColor+OpaquePlaygroundLoggable.swift
│ │ │ ├── CGFloat+CustomOpaqueLoggable.swift
│ │ │ ├── CGGeometry+CustomOpaqueLoggable.swift
│ │ │ └── CGImage+CustomOpaqueLoggable.swift
│ │ ├── CoreImage
│ │ │ ├── CIColor+CustomOpaqueLoggable.swift
│ │ │ └── CIImage+CustomOpaqueLoggable.swift
│ │ ├── CustomOpaqueLoggable.swift
│ │ ├── Foundation
│ │ │ ├── Date+CustomOpaqueLoggable.swift
│ │ │ ├── NSAttributedString+CustomOpaqueLoggable.swift
│ │ │ ├── NSNumber+CustomOpaqueLoggable.swift
│ │ │ ├── NSRange+CustomOpaqueLoggable.swift
│ │ │ ├── NSString+CustomOpaqueLoggable.swift
│ │ │ └── URL+CustomOpaqueLoggable.swift
│ │ ├── SpriteKit
│ │ │ └── SpriteKitOpaqueLoggable.swift
│ │ ├── Swift
│ │ │ ├── Bool+CustomOpaqueLoggable.swift
│ │ │ ├── FloatingPoint+CustomOpaqueLoggable.swift
│ │ │ ├── Integers+CustomOpaqueLoggable.swift
│ │ │ ├── String+CustomOpaqueLoggable.swift
│ │ │ └── UnsafePointers+CustomPlaygroundLoggable.swift
│ │ └── UIKit
│ │ │ ├── UIBezierPath+CustomOpaqueLoggable.swift
│ │ │ ├── UIColor+CustomOpaqueLoggable.swift
│ │ │ ├── UIImage+CustomOpaqueLoggable.swift
│ │ │ └── UIView+CustomOpaqueLoggable.swift
│ ├── Info.plist
│ ├── LegacySupport
│ │ ├── LegacyEntrypoints.swift
│ │ └── PlaygroundQuickLook+OpaqueRepresentationSupport.swift
│ ├── LogEncoder.swift
│ ├── LogEntry+Encoding.swift
│ ├── LogEntry+Reflection.swift
│ ├── LogEntry.swift
│ ├── LogPacket+Encoding.swift
│ ├── LogPacket.swift
│ ├── LogPolicy.swift
│ ├── LoggerEntrypoints.swift
│ ├── LoggerInitialization.swift
│ ├── OpaqueRepresentations
│ │ ├── AppKit
│ │ │ ├── NSBezierPath+KeyedArchiveOpaqueRepresentation.swift
│ │ │ ├── NSBezierPath+PGLKeyedArchivingUtilities.h
│ │ │ ├── NSBezierPath+PGLKeyedArchivingUtilities.m
│ │ │ ├── NSBitmapImageRep+OpaqueImageRepresentable.swift
│ │ │ ├── NSImage+OpaqueImageRepresentable.swift
│ │ │ └── NSView+OpaqueImageRepresentable.swift
│ │ ├── CoreGraphics
│ │ │ ├── CGColor+KeyedArchiveOpaqueRepresentation.swift
│ │ │ ├── CGGeometry+KeyedArchiveOpaqueRepresentation.swift
│ │ │ └── CGImage+OpaqueImageRepresentable.swift
│ │ ├── Foundation
│ │ │ ├── NSAttributedString+KeyedArchiveOpaqueRepresentation.swift
│ │ │ ├── NSAttributedString+PGLKeyedArchivingUtilities.h
│ │ │ ├── NSAttributedString+PGLKeyedArchivingUtilities.m
│ │ │ ├── NSRange+KeyedArchiveOpaqueRepresentation.swift
│ │ │ └── URL+TaggedOpaqueRepresentation.swift
│ │ ├── ImageOpaqueRepresentation.swift
│ │ ├── KeyedArchiveOpaqueRepresentation.swift
│ │ ├── Swift
│ │ │ ├── Bool+TaggedOpaqueRepresentation.swift
│ │ │ ├── Double+TaggedOpaqueRepresentation.swift
│ │ │ ├── Float+TaggedOpaqueRepresentation.swift
│ │ │ ├── Int64+TaggedOpaqueRepresentation.swift
│ │ │ ├── String+TaggedOpaqueRepresentation.swift
│ │ │ └── UInt64+TaggedOpaqueRepresentation.swift
│ │ ├── TaggedOpaqueRepresentation.swift
│ │ └── UIKit
│ │ │ ├── UIBezierPath+KeyedArchiveOpaqueRepresentation.swift
│ │ │ ├── UIBezierPath+PGLKeyedArchivingUtilities.h
│ │ │ ├── UIBezierPath+PGLKeyedArchivingUtilities.m
│ │ │ ├── UIImage+OpaqueImageRepresentable.swift
│ │ │ └── UIView+OpaqueImageRepresentable.swift
│ ├── PlaygroundLogger.h
│ ├── SendData.swift
│ ├── TypeName.swift
│ └── Utilities
│ │ ├── LoggingError.swift
│ │ ├── PGLConcurrentMap.h
│ │ ├── PGLConcurrentMap.swift
│ │ ├── PGLConcurrentMap_MRR.m
│ │ ├── PGLThreadIsLogging.h
│ │ └── PGLThreadIsLogging.m
├── PlaygroundLoggerTestHost_iOS
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ ├── Info.plist
│ └── ViewController.swift
├── PlaygroundLoggerTestHost_tvOS
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ │ └── Main.storyboard
│ ├── Info.plist
│ └── ViewController.swift
├── PlaygroundLoggerTests
│ ├── CustomPlaygroundDisplayConvertibleTests.swift
│ ├── LegacyEntrypointTests.swift
│ ├── LegacyPlaygroundLoggerTests.swift
│ ├── LogEntryTests.swift
│ ├── LogPolicyTests.swift
│ ├── LoggerEntrypointTests.swift
│ ├── PGLNilObject.h
│ ├── PGLNilObject.m
│ └── PlaygroundLoggerTests-Bridging-Header.h
├── PlaygroundLoggerTests_iOS
│ └── Info.plist
├── PlaygroundLoggerTests_macOS
│ └── Info.plist
└── PlaygroundLoggerTests_tvOS
│ └── Info.plist
├── PlaygroundSupport
├── PlaygroundSupport.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── PlaygroundSupport (iOS).xcscheme
│ │ ├── PlaygroundSupport (macOS).xcscheme
│ │ ├── PlaygroundSupport (tvOS).xcscheme
│ │ ├── XCPlayground (iOS).xcscheme
│ │ ├── XCPlayground (macOS).xcscheme
│ │ └── XCPlayground (tvOS).xcscheme
├── PlaygroundSupport
│ ├── PlaygroundPage.swift
│ ├── PlaygroundSupport-Info.plist
│ └── PlaygroundSupport.h
├── PlaygroundSupportTests
│ ├── Info.plist
│ └── LiveViewTests.swift
├── XCPlayground
│ ├── XCPExecutionShouldContinue.swift
│ ├── XCPSharedDataDirectory.swift
│ ├── XCPShowView.swift
│ ├── XCPValueHistory.swift
│ ├── XCPlayground-Info.plist
│ └── XCPlaygroundPage.swift
└── XCPlaygroundTests
│ ├── CaptureValueTests.swift
│ ├── Info.plist
│ └── LiveViewTests.swift
├── README.md
├── XcodeConfig
├── Common.xcconfig
├── Debug.xcconfig
├── Packaging.xcconfig
├── Release.xcconfig
└── XcodeToolchainPackage.xcconfig
└── swift-xcode-playground-support.xcworkspace
├── contents.xcworkspacedata
└── xcshareddata
├── IDEWorkspaceChecks.plist
└── xcschemes
├── BuildScript-Test-PlaygroundLogger-macOS.xcscheme
├── BuildScript-iOS.xcscheme
├── BuildScript-macOS.xcscheme
└── BuildScript-tvOS.xcscheme
/CODE_OWNERS.md:
--------------------------------------------------------------------------------
1 | This file is a list of the people responsible for ensuring that patches for a
2 | particular part of Swift Xcode Playground Supportt are reviewed, either by
3 | themselves or by someone else. They are also the gatekeepers for their part
4 | of the project, with the final word on what goes in or not.
5 |
6 | The list is sorted by surname and formatted to allow easy grepping and
7 | beautification by scripts. The fields are: name (N), email (E), web-address
8 | (W), description (D).
9 |
10 | N: Connor Wakamo
11 | E: cwakamo@apple.com
12 | D: PlaygroundLogger
13 |
14 | N: Sam Page
15 | E: pages@apple.com
16 | D: PlaygroundSupport/XCPlayground
17 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | By submitting a pull request, you represent that you have the right to license
2 | your contribution to Apple and the community, and agree by submitting the patch
3 | that your contributions are licensed under the [Swift
4 | license](https://swift.org/LICENSE.txt).
5 |
6 | ---
7 |
8 | Before submitting the pull request, please make sure you have tested your
9 | changes and that they follow the Swift project [guidelines for contributing
10 | code](https://swift.org/contributing/#contributing-code).
11 |
--------------------------------------------------------------------------------
/Experimental/PlaygroundRuntime/PlaygroundRuntime.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Experimental/PlaygroundRuntime/PlaygroundRuntime.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Experimental/PlaygroundRuntime/PlaygroundRuntime/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSPrincipalClass
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Experimental/PlaygroundRuntime/PlaygroundRuntime/PCMacroRuntime.swift:
--------------------------------------------------------------------------------
1 | //===--- PCMacroRuntime.swift ---------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate func unsetPCFunction(_: Int, _: Int, _: Int, _: Int) {
14 | fatalError("PC macro runtime uninitialized")
15 | }
16 |
17 | public var __builtin_pc_before: @convention(thin) (Int, Int, Int, Int) -> Void = unsetPCFunction
18 | public var __builtin_pc_after: @convention(thin) (Int, Int, Int, Int) -> Void = unsetPCFunction
19 |
--------------------------------------------------------------------------------
/Experimental/PlaygroundRuntime/PlaygroundRuntime/PlaygroundTransformRuntime.swift:
--------------------------------------------------------------------------------
1 | //===--- PlaygroundTransformRuntime.swift ---------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate func unsetResultFunction(_: Any, _: String, _: Int, _: Int, _: Int, _: Int, _: Int) {
14 | fatalError("Playground transform runtime uninitialized")
15 | }
16 |
17 | fileprivate func unsetEventFunction(_: Int, _: Int, _: Int, _: Int) {
18 | fatalError("Playground transform runtime uninitialized")
19 | }
20 |
21 | public var $builtin_log_with_id: @convention(thin) (Any, String, Int, Int, Int, Int, Int) -> Void = unsetResultFunction
22 | public var $builtin_log_scope_entry: @convention(thin) (Int, Int, Int, Int) -> Void = unsetEventFunction
23 | public var $builtin_log_scope_exit: @convention(thin) (Int, Int, Int, Int) -> Void = unsetEventFunction
24 | public var $builtin_postPrint: @convention(thin) (Int, Int, Int, Int) -> Void = unsetEventFunction
25 |
26 | // TODO: remove this once it's no longer necessary
27 | public func $builtin_send_data(_ : Void) {}
28 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/Documentation/LoggerAPI.md:
--------------------------------------------------------------------------------
1 | # The PlaygroundLogger API
2 |
3 | This document briefly describes the API vended by PlaygroundLogger.
4 |
5 | It should be noted that the logger is free to implement more than whatever
6 | is specified in this document - but consumers should **not** rely on anything
7 | to be available for their use except what is accounted for in this document.
8 |
9 | ## `playground_logger_initialize`
10 |
11 | Whenever you want to use PlaygroundLogger in a new process, it is your duty
12 | to initialize the logger. To do so call `func playground_logger_initialize()`
13 |
14 | This function sets up whatever state is required for the logger to operate safely
15 | and is a prerequisite for using any other logger call
16 |
17 | ## `playground_log`
18 |
19 | The main API call provided by the logger is, quite obviously, the log call.
20 | Its signature is:
21 |
22 | `func playground_log(_ object: T,
23 | _ name: String,
24 | _ ID: Int,
25 | _ startline: Int,
26 | _ endline: Int,
27 | _ startcolumn: Int,
28 | _ endcolumn: Int) -> NSData`
29 |
30 | It is a generic function over an unspecified T, which means any Swift object
31 | can be passed as an argument. The arguments are as follows:
32 |
33 | * object. This is the object to be stored by the logger. This call generates
34 | an NSData whose contents are in the format specified in the format document.
35 |
36 | * name. This is the name of the object. It does not need to be syntactically
37 | correct, it is mostly useful for visualization purposes. Anything, including
38 | an empty string is valid here. No checks are performed on this argument.
39 |
40 | * ID. This is the unique identifier of the log call site. It is only required
41 | to be unique across a logging session, and no meaning should be attached to
42 | the specific value. It is also not an object identifier, so much as an identifier
43 | for the location in code in which the log call is being executed.
44 |
45 | * startline, endline, startcolumn, endcolumn. This is the range of source code text that produces the object being logged.
46 |
47 | It should be noted that this, and other log functions, explicitly do not follow proper Swift API guidelines (e.g. argument labels) in order to make it easier to insert calls to them via computer-generated instrumentation. The details of how these calls would be inserted are outside the scope of this document.
48 |
49 | ## `playground_log_postprint`
50 |
51 | The logger has the ability - in sync with the Swift standard library - to store
52 | the last thing that has been print()-ed (or debugPrint()-ed) and return it on request
53 |
54 | The function that does that is `func playground_log_postprint (_ startline: Int,
55 | _ endline: Int,
56 | _ startcolumn: Int,
57 | _ endcolumn: Int) -> NSData`
58 |
59 | This API promises to return an NSData that contains the same output as-if playground_log
60 | were called passing the printed string as the object to log.
61 |
62 | It is to be noted that there is no explicit provision in the logger for wrapping print(), so
63 | in order for playground_log_postprint to do anything useful, it is the duty of the user to make
64 | it so that the logger has access to the printed content.
65 |
66 | The way this works is an implementation detail between the logger and the standard library and should not
67 | be considered a part of the contract.
68 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/BytesStorage.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class BytesStorage {
16 | let data: NSData // hold on to the NSData so it doesn't go away from under us
17 | let bytes: UnsafeMutablePointer // but a pointer is good enough to actually index bytes by
18 | var index: Int
19 |
20 | init(_ _bytes: NSData) {
21 | data = _bytes
22 | bytes = UnsafeMutablePointer(mutating: data.bytes.bindMemory(to: UInt8.self, capacity: data.length))
23 | index = 0
24 | }
25 |
26 | func get() -> UInt8 {
27 | let i = index
28 | index += 1
29 | return bytes[i]
30 | }
31 |
32 | func peek() -> UInt8 {
33 | return bytes[index]
34 | }
35 |
36 | func eof() -> Bool {
37 | return index >= count
38 | }
39 |
40 | var count: Int {
41 | get { return data.length }
42 | }
43 |
44 | subscript (i: UInt64) -> UInt8 {
45 | get {
46 | return bytes[index+Int(i)]
47 | }
48 | }
49 |
50 | func has(_ nBytes: UInt64) -> Bool {
51 | return (index+Int(nBytes) <= count)
52 | }
53 |
54 | func dumpBytes() {
55 | count.doFor { (idx: Int) -> () in
56 | let byte : UInt8 = self.bytes[idx]
57 | print("\(byte) ", terminator: "")
58 | }
59 | print("")
60 | }
61 |
62 | func subset(len: UInt64, consume: Bool) -> BytesStorage {
63 | let copydata = NSData(bytesNoCopy:bytes+index, length: Int(len), freeWhenDone: false)
64 | if consume {
65 | index = index + Int(len)
66 | }
67 | return BytesStorage(copydata)
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/BytesStream.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class BytesStream {
16 | var data : NSMutableData
17 |
18 | init() {
19 | data = NSMutableData()
20 | }
21 |
22 | @discardableResult
23 | func write(_ x : UInt8) -> BytesStream {
24 | var ptr_x = UnsafeMutablePointer.allocate(capacity: 1)
25 | defer { ptr_x.deallocate(capacity: 1) }
26 | ptr_x.pointee = x
27 | data.append(ptr_x, length: 1)
28 | return self
29 | }
30 |
31 | @discardableResult
32 | func write(_ xs : [UInt8]) -> BytesStream {
33 | let ptr = xs
34 | let len = xs.count // we actually want the byte size here - this is xs.count*sizeof(elementType)-elementType==UInt8-->size=1, so here it is
35 | data.append(ptr, length: len)
36 | return self
37 | }
38 |
39 | // seems redundant, but is actually necessary
40 | // see rdar://19808714 and do not remove
41 | // without talking to me first
42 | @discardableResult
43 | func write(_ s : String) -> BytesStream {
44 | write(UInt64(s.byteLength))
45 | write(s.toBytes())
46 | return self
47 | }
48 |
49 | @discardableResult
50 | func write(_ bs : Serializable) -> BytesStream {
51 | write(bs.toBytes())
52 | return self
53 | }
54 |
55 | @discardableResult
56 | func write(_ d : NSData) -> BytesStream {
57 | return write(d as Data)
58 | }
59 |
60 | @discardableResult
61 | func write(_ d : Data) -> BytesStream {
62 | data.append(d)
63 | return self
64 | }
65 |
66 | var size: Int {
67 | return data.length
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/Common.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | typealias SourceLocation = (line: UInt64, col: UInt64)
16 | typealias SourceRange = (begin: SourceLocation, end: SourceLocation)
17 |
18 | protocol Serializable {
19 | func toBytes() -> [UInt8]
20 | init? (storage: BytesStorage)
21 | }
22 |
23 | typealias ChildrenRange = CountableRange
24 | typealias QuickLookObject = Swift.PlaygroundQuickLook
25 |
26 | // given a disparate array of ranges, return a possibly smaller such array such that
27 | // no two ranges overlap and ranges are sorted by their startIndex
28 | func generateNonOverlappingUnion(_ ranges : [ChildrenRange]) -> [ChildrenRange] {
29 | // less than 2 ranges can't overlap now can they
30 | if (ranges.count < 2) {
31 | return ranges
32 | }
33 | let sorted = ranges.sorted {
34 | $0.startIndex < $1.startIndex
35 | }
36 | var actual_ranges = Array()
37 | var current_range = sorted[0]
38 | for i in 1..= upper_bound
54 | func boundCheckRanges(_ ranges : [ChildrenRange], _ upper_bound : UInt64) -> [ChildrenRange] {
55 | var actual_ranges = Array()
56 | for range in ranges {
57 | if range.startIndex >= upper_bound {
58 | // the upper_bound cannot be the startIndex since the startIndex is inclusive
59 | break
60 | }
61 | else if range.endIndex > upper_bound {
62 | // the upper_bound can be the endIndex since the endIndex is exclusive
63 | actual_ranges.append(range.startIndex.. ()) {
72 | for x in CountableRange(uncheckedBounds: (lower: 0 as Self, upper:self)) {
73 | f(x)
74 | }
75 | }
76 |
77 | func doFor (f: () -> ()) {
78 | for _ in CountableRange(uncheckedBounds: (lower: 0 as Self, upper:self)) {
79 | f()
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/Environment.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class Environment {
16 | class func get(variable: String, defaultValue: String? = nil) -> String? {
17 | let env = ProcessInfo.processInfo.environment
18 | if let index = env.index(forKey: variable) {
19 | return env[index].1
20 | }
21 | return defaultValue
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExceptionSafety.m:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import "PlaygroundLogger.h"
14 |
15 | @implementation SwiftExceptionSafety
16 | + (NSException *)doTry: (void(^)(void))block {
17 | @try {
18 | block();
19 | } @catch (NSException *err) {
20 | return err;
21 | }
22 | return nil;
23 | }
24 | - (id)init {
25 | return nil;
26 | }
27 | @end
28 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExtensionBool.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Bool : Serializable {
14 | func toBytes() -> [UInt8] {
15 | return [self ? 1 : 0]
16 | }
17 |
18 | init? (storage: BytesStorage) {
19 | let b = storage.get()
20 | if b == 1 { self = true }
21 | else if b == 0 { self = false }
22 | else { return nil }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExtensionDouble.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Double : Serializable {
14 |
15 | func toBytes() -> [UInt8] {
16 | var udPtr = UnsafeMutablePointer.allocate(capacity: 1)
17 | defer { udPtr.deallocate(capacity: 1) }
18 | udPtr.pointee = self
19 | let ubPtr = UnsafeMutableRawPointer(udPtr)
20 | var arr = Array(repeating: 0, count: 8)
21 | 8.doFor {
22 | arr[$0] = ubPtr.load(fromByteOffset: $0, as: UInt8.self)
23 | }
24 | return arr
25 | }
26 |
27 |
28 | init? (storage: BytesStorage) {
29 | var ubPtr = UnsafeMutablePointer.allocate(capacity: 8)
30 | defer { ubPtr.deallocate(capacity: 8) }
31 | 8.doFor {
32 | ubPtr[$0] = storage.get()
33 | }
34 | let udPtr = UnsafeMutableRawPointer(ubPtr).bindMemory(
35 | to: Double.self, capacity: 1)
36 | self = udPtr.pointee
37 | }
38 |
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExtensionFloat.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Float : Serializable {
14 |
15 | func toBytes() -> [UInt8] {
16 | var udPtr = UnsafeMutablePointer.allocate(capacity: 1)
17 | defer { udPtr.deallocate(capacity: 1) }
18 | udPtr.pointee = self
19 | let ubPtr = UnsafeMutableRawPointer(udPtr)
20 | var arr = Array(repeating: 0, count: 4)
21 | 4.doFor {
22 | arr[$0] = ubPtr.load(fromByteOffset: $0, as: UInt8.self)
23 | }
24 | return arr
25 | }
26 |
27 |
28 | init? (storage: BytesStorage) {
29 | var ubPtr = UnsafeMutablePointer.allocate(capacity: 4)
30 | defer { ubPtr.deallocate(capacity: 4) }
31 | 4.doFor {
32 | ubPtr[$0] = storage.get()
33 | }
34 | let udPtr = UnsafeMutableRawPointer(ubPtr).bindMemory(
35 | to: Float.self, capacity: 1)
36 | self = udPtr.pointee
37 | }
38 |
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExtensionMirrorDisplayStyle.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Mirror.DisplayStyle {
14 | func getConsumedDepthLevels() -> UInt64 {
15 | switch self {
16 | // Dictionaries contain (key,value) tuples, and we don't want those tuples to consume a level of depth
17 | // as the effect we want to achieve is that the dictionary directly contains those keys and values
18 | // The easiest way to achieve that effect is to have the dictionary not consume depth rather than keep track
19 | // of being in a dictionary as we encode the tuples and have the nested tuples not consume depth
20 | case .dictionary: return 0
21 | // Optionals are interesting, but having an optional consume one of our precious levels of depths causes
22 | // unpleasant displays when we run out too soon, and end up showing "..." instead of contained data
23 | // Attempt to fix this by making the optional case not consume a level
24 | case .optional: return 0
25 | default: return 1
26 | }
27 | }
28 | }
29 |
30 | extension Mirror.DisplayStyle : CustomStringConvertible {
31 | public var description: String {
32 | switch self {
33 | case .class: return "class"
34 | case .struct: return "struct"
35 | case .tuple: return "tuple"
36 | case .enum: return "enum"
37 | case .optional: return "optional"
38 | case .collection: return "collection"
39 | case .dictionary: return "dictionary"
40 | case .set: return "set"
41 | default: return "unknown"
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExtensionQuickLookObject.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension QuickLookObject {
14 | // checks the rules for the "prefer summary" flag to be set
15 | func shouldPreferSummary(mirror: LoggerMirror) -> Bool {
16 | #if APPLE_FRAMEWORKS_AVAILABLE
17 | if let obj = mirror.value as? AnyObject {
18 | if obj.responds(to: Selector(("debugQuickLookObject"))) {
19 | switch self {
20 | case .text(_), .attributedString(_), .int(_), .uInt(_), .float(_): return false
21 | default: return true
22 | }
23 | }
24 | }
25 | #endif
26 | return false
27 | }
28 | }
29 |
30 | extension QuickLookObject {
31 | func getStringIfAny() -> String? {
32 | switch self {
33 | case .text(let str): return str
34 | default: return nil
35 | }
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ExtensionUInt64.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension UInt64 : Serializable {
14 | static let largeNumMarker : UInt8 = 0xFF
15 |
16 | func toBytes() -> [UInt8] {
17 | if (self < UInt64(UInt64.largeNumMarker)) {
18 | return [ UInt8(self) ]
19 | }
20 |
21 | var ret = Array()
22 | ret.append(UInt64.largeNumMarker)
23 | var up_int = UnsafeMutablePointer.allocate(capacity: 1)
24 | defer { up_int.deallocate(capacity: 1) }
25 | up_int.pointee = self
26 | var up_byte = UnsafeRawPointer(up_int)
27 | 8.doFor {
28 | ret.append(up_byte.load(as: UInt8.self))
29 | up_byte += 1
30 | }
31 | return ret
32 | }
33 |
34 | func toEightBytes() -> [UInt8] {
35 | var ret = Array()
36 | var up_int = UnsafeMutablePointer.allocate(capacity: 1)
37 | defer { up_int.deallocate(capacity: 1) }
38 | up_int.pointee = self
39 | var up_byte = UnsafeRawPointer(up_int)
40 | 8.doFor {
41 | ret.append(up_byte.load(as: UInt8.self))
42 | up_byte += 1
43 | }
44 | return ret
45 | }
46 |
47 | init? (storage : BytesStorage) {
48 | let byte0 = storage.get()
49 | if (byte0 == UInt64.largeNumMarker) {
50 | if let x = UInt64(eightBytesStorage: storage) {
51 | self = x
52 | } else {
53 | return nil
54 | }
55 | } else {
56 | self = UInt64(byte0)
57 | }
58 | }
59 |
60 | init? (eightBytesStorage: BytesStorage) {
61 | if !eightBytesStorage.has(8) { return nil }
62 | var up_byte = UnsafeMutablePointer.allocate(capacity: 8)
63 | defer { up_byte.deallocate(capacity: 8) }
64 | 8.doFor {
65 | up_byte[$0] = eightBytesStorage.get()
66 | }
67 | let up_int: UnsafePointer = UnsafeRawPointer(up_byte).bindMemory(
68 | to: UInt64.self, capacity: 1)
69 | self = up_int.pointee
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/KeyedArchiver.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class LoggerArchiver {
16 | var archiver: NSKeyedArchiver
17 | var data: NSMutableData
18 | var exception: NSException?
19 |
20 | enum ArchiverState {
21 | case Buffer(Data)
22 | case Exception(NSException)
23 | }
24 |
25 | init() {
26 | data = NSMutableData()
27 | archiver = NSKeyedArchiver(forWritingWith:data)
28 | exception = nil
29 | }
30 |
31 | func archive(object: AnyObject) {
32 | archive(key: "root", object: object)
33 | }
34 |
35 | func archive(key: String, object: AnyObject) {
36 | self.exception = SwiftExceptionSafety.doTry {
37 | self.archiver.encode(object, forKey: key)
38 | }
39 | }
40 |
41 | func archive(double: Double) {
42 | archive(key: "root", double: double)
43 | }
44 |
45 | func archive(key: String, double: Double) {
46 | self.exception = SwiftExceptionSafety.doTry {
47 | self.archiver.encode(double, forKey: key)
48 | }
49 | }
50 |
51 | func archive(bool: Bool) {
52 | archive(key: "root", bool: bool)
53 | }
54 |
55 | func archive(key: String, bool: Bool) {
56 | self.exception = SwiftExceptionSafety.doTry {
57 | self.archiver.encode(bool, forKey: key)
58 | }
59 | }
60 |
61 | func archive(int64: Int64) {
62 | archive(key: "root", int64: int64)
63 | }
64 |
65 | func archive(key: String, int64: Int64) {
66 | self.exception = SwiftExceptionSafety.doTry {
67 | self.archiver.encode(int64, forKey: key)
68 | }
69 | }
70 |
71 | func archive(uint64: UInt64) {
72 | archive(key: "root", uint64: uint64)
73 | }
74 |
75 | func archive(key: String, uint64: UInt64) {
76 | self.exception = SwiftExceptionSafety.doTry {
77 | self.archiver.encode(Int64(uint64), forKey: key)
78 | }
79 | }
80 |
81 | func archive(storage: BytesStorage) {
82 | archive(key: "root", storage: storage)
83 | }
84 |
85 | func archive(key: String, storage: BytesStorage) {
86 | self.exception = SwiftExceptionSafety.doTry {
87 | self.archiver.encodeBytes(storage.bytes, length: storage.count, forKey: key)
88 | }
89 | }
90 |
91 | func finalize() {
92 | archiver.finishEncoding()
93 | }
94 |
95 | func getData() -> NSData {
96 | finalize()
97 | return data
98 | }
99 |
100 | func getException() -> NSException? {
101 | finalize()
102 | return exception
103 | }
104 |
105 | // preferred accessor unless you know for sure that you did/did not cause an exception
106 | func getState() -> ArchiverState {
107 | finalize()
108 | if let except = exception {
109 | return .Exception(except)
110 | }
111 | return .Buffer(data as Data)
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/KeyedUnarchiver.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class LoggerUnarchiver {
16 | var unarchiver : NSKeyedUnarchiver
17 | let storage : BytesStorage
18 |
19 | init(_ stg : BytesStorage) {
20 | storage = stg
21 | unarchiver = NSKeyedUnarchiver(forReadingWith: NSData(bytes: storage.bytes + storage.index, length: storage.count - storage.index) as Data)
22 | }
23 |
24 | func get(double: String) -> Double {
25 | return unarchiver.decodeDouble(forKey: double)
26 | }
27 |
28 | func get(bool : String) -> Bool {
29 | return unarchiver.decodeBool(forKey: bool)
30 | }
31 |
32 | func get(int64 : String) -> Int64 {
33 | return unarchiver.decodeInt64(forKey: int64)
34 | }
35 |
36 | func get(uint64 : String) -> UInt64 {
37 | return UInt64(unarchiver.decodeInt64(forKey: uint64))
38 | }
39 |
40 | func get(object : String) -> Any! {
41 | return unarchiver.decodeObject(forKey: object)
42 | }
43 |
44 | func has(_ key : String) -> Bool {
45 | switch unarchiver.decodeObject(forKey: key) {
46 | case nil: return false
47 | default: return true
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/LoggerDecoderAPI.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | // LoggerDecoder is not meant for public consumption, is not complete
14 | // and is distinct from the decoder logic used by Xcode - the purpose
15 | // of this decoding API is to enable testing of PlaygroundLogger
16 |
17 | import Foundation
18 |
19 | public class PlaygroundDecodedLogEntry {
20 | let version: UInt64
21 | let range: SourceRange
22 | let header: [String: String]
23 | let object: PlaygroundDecodedObject
24 |
25 | init (version: UInt64,
26 | startLine: UInt64,
27 | startColumn: UInt64,
28 | endLine: UInt64,
29 | endColumn: UInt64,
30 | header: [String: String],
31 | object: PlaygroundDecodedObject) {
32 | self.version = version
33 | self.range = SourceRange(begin: (line: startLine, col: startColumn), end: (line: endLine, col: endColumn))
34 | self.header = header
35 | self.object = object
36 | }
37 |
38 | func print(to stream: inout T) {
39 | Swift.print("Version: \(version)", to: &stream)
40 | Swift.print("\(header.count) header entries", to: &stream)
41 | for (key,value) in header {
42 | Swift.print("\t\(key) = \(value)", to: &stream)
43 | }
44 | object.print(&stream,0)
45 | }
46 |
47 | public func toString() -> String {
48 | var s = ""
49 | print(to: &s)
50 | return s
51 | }
52 | }
53 |
54 | @_silgen_name("playground_log_decode") public
55 | func playground_log_decode(_ object : NSData) -> PlaygroundDecodedLogEntry? {
56 | return PlaygroundDecoder(BytesStorage(object)).decode()
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/LoggerInit.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | /***
14 | * Call this API before calling anything else in PlaygroundLogger
15 | * If you fail to do that, then whatever fails to work is well deserved pain
16 | ***/
17 | @_silgen_name("playground_logger_initialize") public
18 | func playground_logger_initialize() {
19 | Swift._playgroundPrintHook = playground_logger_print_hook
20 | Woodchuck.chuck {
21 | return Woodchuck.LogEntry("PlaygroundLogger initialized correctly")
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/LoggingPolicyStack.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | final class LoggingPolicyStack {
14 | class func get() -> LoggingPolicyStack {
15 | let tls = ThreadLocalStorage(key: "PlaygroundLogger_StackLoggingLevelPolicy")
16 | if let stk = tls.Data { return stk }
17 | let stk = LoggingPolicyStack()
18 | stk.push(LoggingLevelPolicy_Default()) // we always want a default policy at the bottom - an empty stack is a critical failure
19 | tls.Data = stk
20 | return stk
21 | }
22 |
23 | private var stack = Stack()
24 |
25 | @discardableResult
26 | func push (_ p: LoggingLevelPolicy) -> LoggingPolicyStack {
27 | stack.push(p)
28 | return self
29 | }
30 |
31 | @discardableResult
32 | func pop() -> LoggingPolicyStack {
33 | _ = stack.pop()
34 | return self
35 | }
36 |
37 | func peek() -> LoggingLevelPolicy {
38 | return stack.peek()
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundGapWriter.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | class PlaygroundGapWriter : PlaygroundWriter {
14 | func encode(gap: String, range: SourceRange) {
15 | encode(header: range)
16 | stream.write(gap) // this might not mean a lot for a gap.. but anyway, it's not forbidden
17 | stream.write(PlaygroundRepresentation.Gap.toBytes())
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLog.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | func playground_log_impl(_ object : T, _ name : String, _ range: SourceRange) -> NSData {
16 | Woodchuck.chuck {
17 | return Woodchuck.LogEntry("LoggerDefaults.MaxLevelsOfDepth = \(LoggerDefaults.MaxLevelsOfDepth), LoggerDefaults.Capping_Aggregates = \(LoggerDefaults.Capping_Aggregates), LoggerDefaults.Capping_Containers = \(LoggerDefaults.Capping_Containers)")
18 | }
19 | let encoder = PlaygroundObjectWriter(LoggerDefaults.MaxLevelsOfDepth, LoggerDefaults.Capping_Aggregates, LoggerDefaults.Capping_Containers)
20 | _ = encoder.encodeObject(object, name, range)
21 | return encoder.stream.data
22 | }
23 |
24 | @_silgen_name("playground_log_hidden") public
25 | func playground_log(_ object: T,
26 | _ name: String,
27 | _ ID: Int,
28 | _ startline: Int,
29 | _ endline: Int,
30 | _ startcolumn: Int,
31 | _ endcolumn: Int) -> NSData {
32 |
33 | let range = (begin: (line: UInt64(startline), col: UInt64(startcolumn)), end: (line: UInt64(endline), col: UInt64(endcolumn)))
34 |
35 | let policy = LoggingPolicyStack.get().peek()
36 | if policy.proceed(ID) {
37 | Woodchuck.chuck {
38 | return Woodchuck.LogEntry("logging policy \(policy) allows logging to proceed")
39 | }
40 | return policy.update(ID,playground_log_impl(object, name, range))
41 | }
42 | else {
43 | Woodchuck.chuck {
44 | return Woodchuck.LogEntry("logging policy \(policy) prevents logging - gap emitted instead")
45 | }
46 | return playground_log_gap(name, range)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogGap.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | func playground_log_gap(_ name: String,
16 | _ range: SourceRange) -> NSData {
17 | let encoder = PlaygroundGapWriter()
18 | encoder.encode(gap: name, range: range)
19 | return encoder.stream.data
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogPolicy.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | public typealias LoggerClosure = () -> ()
14 |
15 | private
16 | func playgroundLogWithPolicy(_ policy: LoggingLevelPolicy, _ f : LoggerClosure) {
17 | LoggingPolicyStack.get().push(policy)
18 | f()
19 | LoggingPolicyStack.get().pop()
20 | }
21 |
22 | public
23 | func playground_log_default (_ f: LoggerClosure) {
24 | playgroundLogWithPolicy(LoggingLevelPolicy_Default(), f)
25 | }
26 |
27 | public
28 | func playground_log_never (_ f : LoggerClosure) {
29 | playgroundLogWithPolicy(LoggingLevelPolicy_Never(), f)
30 | }
31 |
32 | public
33 | func playground_log_adaptive (_ f : LoggerClosure) {
34 | playgroundLogWithPolicy(LoggingLevelPolicy_Adaptive(), f)
35 | }
36 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogPrint.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | // this does not need @_silgen_name() nor public, since it will be fed to the stdlib via a function pointer
16 | func playground_logger_print_hook(_ x: String) -> Void {
17 | let buffer = ThreadLocalStorage(key: "swiftPrintBuffer")
18 | buffer.Data = NSString(string: x)
19 | }
20 |
21 | @_silgen_name("playground_log_postprint") public
22 | func playground_log_postprint (_ startline: Int,
23 | _ endline: Int,
24 | _ startcolumn: Int,
25 | _ endcolumn: Int) -> NSData {
26 | let range = (begin: (line: UInt64(startline), col: UInt64(startcolumn)), end: (line: UInt64(endline), col: UInt64(endcolumn)))
27 | let buffer = ThreadLocalStorage(key: "swiftPrintBuffer")
28 | if let string = buffer.Data {
29 | #if APPLE_FRAMEWORKS_AVAILABLE
30 | let logdata = playground_log_impl(string, "", range)
31 | #else
32 | let logdata = playground_log_impl(string.bridge(), "", range)
33 | #endif
34 | buffer.Data = nil
35 | return logdata
36 | }
37 | // return an empty string if nothing interesting can be said here
38 | return playground_log_impl(LoggerDefaults.DefaultPostprintResult,"", range)
39 | }
40 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogScope.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 | //
13 |
14 | import Foundation
15 |
16 | @_silgen_name("playground_log_scope_entry") public
17 | func playground_log_scope_entry(_ startline: Int,
18 | _ endline: Int,
19 | _ startcolumn: Int,
20 | _ endcolumn: Int) -> NSData {
21 | let range = (begin: (line: UInt64(startline), col: UInt64(startcolumn)), end: (line: UInt64(endline), col: UInt64(endcolumn)))
22 | let encoder = PlaygroundScopeWriter()
23 | encoder.encode(scope: .ScopeEntry, range: range)
24 | return encoder.stream.data
25 | }
26 |
27 | @_silgen_name("playground_log_scope_exit") public
28 | func playground_log_scope_exit(_ startline: Int,
29 | _ endline: Int,
30 | _ startcolumn: Int,
31 | _ endcolumn: Int) -> NSData {
32 | let range = (begin: (line: UInt64(startline), col: UInt64(startcolumn)), end: (line: UInt64(endline), col: UInt64(endcolumn)))
33 | let encoder = PlaygroundScopeWriter()
34 | encoder.encode(scope: .ScopeExit, range: range)
35 | return encoder.stream.data
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogger-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(CURRENT_PROJECT_VERSION)
25 | NSHumanReadableCopyright
26 | Copyright © 2014 Apple Inc. All rights reserved.
27 | NSPrincipalClass
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogger-linux.bom:
--------------------------------------------------------------------------------
1 | # this file contains the exclusion list, i.e. files in this list will not be compiled
2 |
3 | ExtensionCGColorRef.swift
4 | ImageHandler.swift
5 | ViewRenderer.swift
6 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogger.h:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | @import Foundation;
14 | @import CoreGraphics;
15 |
16 | @interface SwiftExceptionSafety : NSObject
17 | - (id)init;
18 | + (NSException *)doTry:(void (^)(void))block;
19 | @end
20 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogger.modulemap:
--------------------------------------------------------------------------------
1 | framework module PlaygroundLogger {
2 | }
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundLogger.private.modulemap:
--------------------------------------------------------------------------------
1 | framework module PlaygroundLogger.Private {
2 | umbrella header "PlaygroundLogger.h"
3 | export *
4 | }
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | enum PlaygroundRepresentation : UInt8, Hashable, Serializable, CustomStringConvertible, Equatable {
14 | case Class = 1
15 | case Struct = 2
16 | case Tuple = 3
17 | case Enum = 4
18 | case Aggregate = 5
19 | case Container = 6
20 | case IDERepr = 7
21 | case Gap = 8
22 | case ScopeEntry = 9
23 | case ScopeExit = 10
24 | case Error = 11
25 | case IndexContainer = 12
26 | case KeyContainer = 13
27 | case MembershipContainer = 14
28 | case Unknown = 0xFF
29 |
30 | func toBytes() -> [UInt8] {
31 | return [ self.rawValue ]
32 | }
33 |
34 | init (byte: UInt8) {
35 | if let repr = PlaygroundRepresentation(rawValue: byte) {
36 | self = repr
37 | } else {
38 | self = .Unknown
39 | }
40 | }
41 |
42 | init? (storage : BytesStorage) {
43 | self = PlaygroundRepresentation(byte: storage.get())
44 | }
45 |
46 | var hashValue : Int {
47 | return Int(self.rawValue)
48 | }
49 |
50 | var description: String {
51 | switch self {
52 | case .Class: return "Class"
53 | case .Struct: return "Struct"
54 | case .Tuple: return "Tuple"
55 | case .Enum: return "Enum"
56 | case .Aggregate: return "Aggregate"
57 | case .Container: return "Container"
58 | case .IDERepr: return "IDERepr"
59 | case .Gap: return "Gap"
60 | case .ScopeEntry: return "ScopeEntry"
61 | case .ScopeExit: return "ScopeExit"
62 | case .Error: return "Error"
63 | case .IndexContainer: return "IndexContainer"
64 | case .KeyContainer: return "KeyContainer"
65 | case .MembershipContainer: return "MembershipContainer"
66 | default: return "Unknown"
67 | }
68 | }
69 |
70 | init(_ x: Mirror.DisplayStyle)
71 | {
72 | switch (x) {
73 | case .`class`: self = .Class
74 | case .`struct`: self = .Struct
75 | case .tuple: self = .Tuple
76 | case .`enum`: self = .Enum
77 | case .optional: self = .Aggregate
78 | case .collection: self = .IndexContainer
79 | case .dictionary: self = .KeyContainer
80 | case .set: self = .MembershipContainer
81 | default: self = .Unknown
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundScopeWriter.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | class PlaygroundScopeWriter : PlaygroundWriter {
14 | func encode(scope: ScopeEvent, range: SourceRange) {
15 | encode(header: range)
16 | stream.write("") // empty name field - maybe we can use it some day, just keep it consistent for now
17 | stream.write(PlaygroundRepresentation(scope: scope))
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundWriter.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | class PlaygroundWriter {
14 | var stream : BytesStream
15 |
16 | // this is the version of the PlaygroundLogger protocol
17 | // this needs to be changed if anyhthing in the encoding changes
18 | // in such a way that it would break existing consumers
19 | static let version : UInt8 = 10
20 |
21 | init() {
22 | stream = BytesStream()
23 | }
24 |
25 | func encode(range: SourceRange) {
26 | stream.write(range.begin.line.toEightBytes())
27 | stream.write(range.begin.col.toEightBytes())
28 | stream.write(range.end.line.toEightBytes())
29 | stream.write(range.end.col.toEightBytes())
30 | }
31 |
32 | func encodeConfigInfo() {
33 | #if os(OSX) || os(iOS) || os(tvOS)
34 | stream.write(UInt8(1))
35 | let tid : mach_port_t = pthread_mach_thread_np(pthread_self())
36 | stream.write("tid").write("\(tid)")
37 | #else
38 | stream.write(UInt8(0))
39 | #endif
40 | }
41 |
42 | func encode(header: SourceRange) {
43 | stream.write(PlaygroundWriter.version)
44 | encode(range: header)
45 | encodeConfigInfo()
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/QuickLookEncodedObject.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | enum QuickLookEncoding {
16 | case Array([UInt8]) // Swift objects are very well stored as array of bytes
17 | case Buffer(Data) // ObjC objects usually are easy to write to an NSData
18 |
19 | var count : UInt64 {
20 | get {
21 | switch (self) {
22 | case .Array(let x): return UInt64(x.count)
23 | case .Buffer(let x): return UInt64(x.count)
24 | }
25 | }
26 | }
27 | }
28 |
29 | struct QuickLookEncodedObject : CustomStringConvertible
30 | {
31 | var repr_type : String
32 | var repr_data : QuickLookEncoding
33 |
34 | init(_ repr_type: String, _ repr_data: QuickLookEncoding) {
35 | self.repr_type = repr_type
36 | self.repr_data = repr_data
37 | }
38 |
39 | var description: String {
40 | return "repr_type: \(repr_type) worth \(repr_data.count) bytes"
41 | }
42 | }
43 |
44 | enum QuickLookingResult : CustomStringConvertible {
45 | case Success(QuickLookEncodedObject) // we succeeded: here's the data
46 | case Failure(String?) // we failed: I might have more to say about it
47 |
48 | init(_ ql: QuickLookEncodedObject) {
49 | self = .Success(ql)
50 | }
51 |
52 | init (_ ex: NSException) {
53 | self = .Failure(ex.description)
54 | }
55 |
56 | init () {
57 | self = .Failure(nil)
58 | }
59 |
60 | init (_ m: String) {
61 | self = .Failure(m)
62 | }
63 |
64 | init (_ r: String, _ d: QuickLookEncoding) {
65 | self = .Success(QuickLookEncodedObject(r,d))
66 | }
67 |
68 | init (_ r: String, _ d: NSData) {
69 | self = .Success(QuickLookEncodedObject(r,.Buffer(d as Data)))
70 | }
71 |
72 | init (_ r: String, _ d: Data) {
73 | self = .Success(QuickLookEncodedObject(r,.Buffer(d)))
74 | }
75 |
76 | init (_ r: String, _ a: [UInt8]) {
77 | self = .Success(QuickLookEncodedObject(r,.Array(a)))
78 | }
79 |
80 | init (_ r: String, _ a: LoggerArchiver.ArchiverState) {
81 | switch (a) {
82 | case .Buffer(let d): self = .Success(QuickLookEncodedObject(r,.Buffer(d)))
83 | case .Exception(let except): self = .Failure(except.description)
84 | }
85 | }
86 |
87 | var description: String {
88 | switch self {
89 | case .Success(let ql_obj): return "Success(\(ql_obj))"
90 | case .Failure(let msg): return "Failure(\(msg))"
91 | }
92 | }
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/Regex.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | struct Regex {
16 | typealias FoundationRegex = NSRegularExpression
17 | var rgx: FoundationRegex
18 |
19 | init? (pattern: String) {
20 | do {
21 | let r = try FoundationRegex(pattern: pattern, options: FoundationRegex.Options.useUnicodeWordBoundaries)
22 | self.rgx = r
23 | } catch {
24 | return nil
25 | }
26 | }
27 |
28 | func replace(in: String, with: String) -> String {
29 | return rgx.stringByReplacingMatches(in: `in`, options: [], range: `in`.range, withTemplate: with)
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ScopeEvent.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | // this enum is not actually used to store and retrieve state
14 | // all that matters is that the values in here are correctly
15 | // translated to their PlaygroundRepresentation equivalents
16 | enum ScopeEvent : UInt8, Equatable {
17 | case ScopeEntry = 9
18 | case ScopeExit = 10
19 |
20 | var hashValue : Int {
21 | return Int(self.rawValue)
22 | }
23 | }
24 |
25 | extension PlaygroundRepresentation {
26 | init (scope: ScopeEvent) {
27 | switch scope {
28 | case .ScopeEntry: self = .ScopeEntry
29 | case .ScopeExit: self = .ScopeExit
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/Stack.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | final class Stack {
14 | private var impl: [T]
15 | private var pos: Int
16 |
17 | init() {
18 | impl = []
19 | pos = 0
20 | }
21 |
22 | func push(_ x: T) {
23 | let i = pos
24 | pos += 1
25 | impl.insert(x, at: i)
26 | }
27 |
28 | func pop() -> T {
29 | assert(pos > 0, "Cannot pop out of an empty stack")
30 | pos -= 1
31 | return impl[pos]
32 | }
33 |
34 | func tryPop() -> T? {
35 | if pos == 0 { return nil }
36 | return pop()
37 | }
38 |
39 | func peek() -> T {
40 | assert(pos > 0, "Cannot peek out of an empty stack")
41 | return impl[pos-1]
42 | }
43 |
44 | func tryPeek() -> T? {
45 | if pos == 0 { return nil }
46 | return peek()
47 | }
48 |
49 | var empty: Bool { return pos == 0 }
50 | }
51 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/SwiftExceptionSafety.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | // On Apple platforms, SwiftExceptionSafety is used to turn ObjC-based throws into an exception return which Swift code then can handle without crashing
14 | // On non-Apple platforms, there is no ObjC runtime throwing things around, so provide a hollow stub to keep other code happy with minimal #ifs
15 |
16 | class NSException {
17 | var description: String {
18 | return "NSException"
19 | }
20 | }
21 |
22 | class SwiftExceptionSafety {
23 | class func doTry (_ f: () -> ()) -> NSException? {
24 | f()
25 | return nil
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ThreadLocalStorage.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class ThreadLocalStorage {
16 | private let key: NSString
17 |
18 | init (key: String) {
19 | self.key = NSString(string: key)
20 | }
21 |
22 | var Data: T? {
23 | get {
24 | let dict = Thread.current.threadDictionary
25 | #if APPLE_FRAMEWORKS_AVAILABLE
26 | return dict.object(forKey: key) as? T
27 | #else
28 | if let index = dict.indexForKey(key) {
29 | return dict[index].1 as? T
30 | }
31 | return nil
32 | #endif
33 | }
34 | set (value) {
35 | Thread.current.threadDictionary[key] = value
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/ViewRenderer.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(OSX)
14 | import Cocoa
15 |
16 | final class NSViewRenderer {
17 | static var views = NSMutableSet()
18 |
19 | static func render(_ _v: NSView) -> AnyObject? {
20 | var result: AnyObject? = nil
21 | switch NSViewRenderer.views.member(_v) {
22 | case nil:
23 | NSViewRenderer.views.add(_v)
24 |
25 | let bounds = _v.bounds
26 | if let b = _v.bitmapImageRepForCachingDisplay(in: bounds) {
27 | _v.cacheDisplay(in: bounds, to: b)
28 | result = b
29 | }
30 |
31 | NSViewRenderer.views.remove(_v)
32 | default: ()
33 | }
34 |
35 | return result
36 | }
37 | }
38 | #endif
39 |
40 | #if os(iOS) || os(tvOS)
41 | import UIKit
42 |
43 | // FIXME: rdar://22317321
44 | func getGraphicsContext() -> CGContext? {
45 | return UIGraphicsGetCurrentContext()
46 | }
47 |
48 | final class UIViewRenderer {
49 | static var _views = NSMutableSet()
50 |
51 | static func render(_ _v: UIView) -> AnyObject? {
52 | var result: AnyObject? = nil
53 |
54 | switch UIViewRenderer._views.member(_v) {
55 | case nil:
56 | UIViewRenderer._views.add(_v)
57 |
58 | let bounds = _v.bounds
59 | // in case of an empty rectangle abort the logging
60 | if (bounds.size.width == 0) || (bounds.size.height == 0) {
61 | return nil
62 | }
63 |
64 | UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
65 |
66 | if let ctx = getGraphicsContext() {
67 | UIColor(white:1.0, alpha:0.0).set()
68 | ctx.fill(bounds)
69 | _v.layer.render(in: ctx)
70 |
71 | let image = UIGraphicsGetImageFromCurrentImageContext()
72 |
73 | UIGraphicsEndImageContext()
74 |
75 | result = image
76 | }
77 |
78 | UIViewRenderer._views.remove(_v)
79 |
80 | default: ()
81 | }
82 |
83 | return result
84 | }
85 | }
86 | #endif
87 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger/Woodchuck.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | // “How much logging could a PlaygroundLogger log if a PlaygroundLogger could log logs"
14 |
15 | import Foundation
16 |
17 | private extension NSDate {
18 | func toShortString() -> String {
19 | let f = DateFormatter()
20 | f.locale = nil
21 | f.dateFormat = "yyyy-MM-dd HH:mm"
22 | return f.string(from: self as Date)
23 | }
24 | }
25 |
26 | enum Woodchuck {
27 | struct LogEntry: CustomStringConvertible {
28 | let message: String
29 |
30 | var description: String {
31 | return "[\(getpid())] @ \(NSDate().toShortString()): \(message)"
32 | }
33 |
34 | init (_ message: String) {
35 | self.message = message
36 | }
37 | }
38 |
39 | typealias LogClosure = () -> LogEntry
40 |
41 | struct OutputStream_Stdout : WoodchuckOutputStream {
42 | func write(_ s: Woodchuck.LogClosure)
43 | {
44 | print(s().description)
45 | }
46 | }
47 |
48 | struct OutputStream_DevNull : WoodchuckOutputStream {
49 | func write(_ s: Woodchuck.LogClosure)
50 | {
51 | }
52 | }
53 |
54 | static func chuck (_ s: LogClosure)
55 | {
56 | LoggerDefaults.LoggerLogger.output.write(s)
57 | }
58 |
59 | class InstanceData {
60 | var output: WoodchuckOutputStream
61 |
62 | init() {
63 | if Environment.get(variable: "PLAYGROUNDLOGGER_WOODCHUCK") != nil {
64 | self.output = OutputStream_Stdout()
65 | } else {
66 | self.output = OutputStream_DevNull()
67 | }
68 | }
69 | }
70 | }
71 |
72 | protocol WoodchuckOutputStream {
73 | func write (_ s: Woodchuck.LogClosure)
74 | }
75 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger_TestDriver/main.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if NOTEST
14 | #else
15 | import PlaygroundLogger
16 |
17 | print("--- Running PlaygroundLogger Tests ---")
18 |
19 | playground_logger_test()
20 | #endif
21 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger_iOS/PlaygroundLogger_iOS-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(CURRENT_PROJECT_VERSION)
25 | NSHumanReadableCopyright
26 | Copyright © 2014 Apple Inc. All rights reserved.
27 | NSPrincipalClass
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger_iOS/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger_tvOS/PlaygroundLogger_tvOS-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(CURRENT_PROJECT_VERSION)
25 | NSHumanReadableCopyright
26 | Copyright © 2014 Apple Inc. All rights reserved.
27 | NSPrincipalClass
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Legacy/PlaygroundLogger/PlaygroundLogger_tvOS/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/AppKit/NSBezierPath+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSBezierPath+CustomOpaqueLoggable.swift --------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSBezierPath: CustomOpaqueLoggable {}
17 | #endif
18 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/AppKit/NSBitmapImageRep+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSBitmapImageRep+CustomOpaqueLoggable.swift ----------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSBitmapImageRep: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return ImageOpaqueRepresentation(kind: .image, backedBy: self)
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/AppKit/NSColor+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSColor+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSColor: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return self.cgColor
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/AppKit/NSCursor+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSCursor+CustomOpaqueLoggable.swift ------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSCursor: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return ImageOpaqueRepresentation(kind: .image, backedBy: self.image)
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/AppKit/NSImage+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSImage+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSImage: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return ImageOpaqueRepresentation(kind: .image, backedBy: self)
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/AppKit/NSView+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSView+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSView: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return ImageOpaqueRepresentation(kind: .view, backedBy: self)
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CoreGraphics/CGColor+OpaquePlaygroundLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CGColor+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 |
15 | extension CGColor: CustomOpaqueLoggable {}
16 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CoreGraphics/CGFloat+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CGFloat+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 |
15 | extension CGFloat: CustomOpaqueLoggable {
16 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
17 | return self.native
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CoreGraphics/CGGeometry+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CGGeometry+CustomOpaqueLoggable.swift ----------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 |
15 | extension CGPoint: CustomOpaqueLoggable {}
16 | extension CGSize: CustomOpaqueLoggable {}
17 | extension CGRect: CustomOpaqueLoggable {}
18 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CoreGraphics/CGImage+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CGImage+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 |
15 | extension CGImage: CustomOpaqueLoggable {
16 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
17 | return ImageOpaqueRepresentation(kind: .image, backedBy: self)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CoreImage/CIColor+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CIColor+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreImage
14 |
15 | extension CIColor: CustomOpaqueLoggable {
16 | func opaqueRepresentation() throws -> LogEntry.OpaqueRepresentation {
17 | guard let color = CGColor(colorSpace: self.colorSpace, components: self.components) else {
18 | throw LoggingError.failedToGenerateOpaqueRepresentation(reason: "Unable to convert this CIColor to a CGColor")
19 | }
20 |
21 | return color
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CoreImage/CIImage+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CIImage+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreImage
14 | import CoreGraphics
15 |
16 | #if os(macOS)
17 | import AppKit
18 | #elseif os(iOS) || os(tvOS)
19 | import UIKit
20 | #endif
21 |
22 | extension CIImage: CustomOpaqueLoggable {
23 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
24 | if #available(macOS 10.12, *), let cgImage = self.cgImage {
25 | return ImageOpaqueRepresentation(kind: .image, backedBy: cgImage)
26 | }
27 | else {
28 | #if os(macOS)
29 | let imageRep = NSCIImageRep(ciImage: self)
30 | let image = NSImage(size: imageRep.size)
31 | image.addRepresentation(imageRep)
32 | #elseif os(iOS) || os(tvOS)
33 | let image = UIImage(ciImage: self)
34 | #endif
35 |
36 | return ImageOpaqueRepresentation(kind: .image, backedBy: image)
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- CustomOpaqueLoggable.swift ---------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | protocol CustomOpaqueLoggable {
14 | func opaqueRepresentation() throws -> LogEntry.OpaqueRepresentation
15 | }
16 |
17 | extension CustomOpaqueLoggable where Self: LogEntry.OpaqueRepresentation {
18 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
19 | return self
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Foundation/Date+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- Date+CustomOpaqueLoggable.swift ----------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | fileprivate let dateLoggingFormatter: DateFormatter = {
16 | let formatter = DateFormatter()
17 | formatter.dateStyle = .medium
18 | formatter.timeStyle = .short
19 | return formatter
20 | }()
21 |
22 | extension Date: CustomOpaqueLoggable {
23 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
24 | return dateLoggingFormatter.string(from: self)
25 | }
26 | }
27 |
28 | extension NSDate: CustomOpaqueLoggable {
29 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
30 | return (self as Date).opaqueRepresentation()
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Foundation/NSAttributedString+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSAttributedString+CustomOpaqueLoggable.swift --------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | extension NSAttributedString: CustomOpaqueLoggable {}
16 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Foundation/NSNumber+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSNumber+CustomOpaqueLoggable.swift ------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | extension NSNumber: CustomOpaqueLoggable {
16 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
17 | switch UInt8(self.objCType.pointee) {
18 | case UInt8(ascii: "c"), UInt8(ascii: "s"), UInt8(ascii: "i"), UInt8(ascii: "l"), UInt8(ascii: "q"):
19 | return self.int64Value
20 | case UInt8(ascii: "C"), UInt8(ascii: "S"), UInt8(ascii: "I"), UInt8(ascii: "L"), UInt8(ascii: "Q"):
21 | return self.uint64Value
22 | case UInt8(ascii: "f"):
23 | return self.floatValue
24 | case UInt8(ascii: "d"):
25 | return self.doubleValue
26 | case UInt8(ascii: "B"):
27 | return self.boolValue
28 | default:
29 | return self.int64Value
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Foundation/NSRange+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSRange+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | extension NSRange: CustomOpaqueLoggable {}
16 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Foundation/NSString+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSString+CustomOpaqueLoggable.swift ------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | extension NSString: CustomOpaqueLoggable {
16 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
17 | return self as String
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Foundation/URL+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- URL+CustomOpaqueLoggable.swift -----------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | extension URL: CustomOpaqueLoggable {}
16 |
17 | extension NSURL: CustomOpaqueLoggable {
18 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
19 | return self as URL
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/SpriteKit/SpriteKitOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- SpriteKitOpaqueLoggable.swift ------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import SpriteKit
14 |
15 | @objc fileprivate class SpriteKitCopyImageDataHook: NSObject {
16 | @objc(_copyImageData) func _copyImageData() -> Data? {
17 | fatalError("This stub _copyImageData should not be called!")
18 | }
19 | }
20 |
21 | fileprivate protocol SpriteKitOpaqueLoggable: AnyObject, OpaqueImageRepresentable, CustomOpaqueLoggable {}
22 |
23 | extension SpriteKitOpaqueLoggable {
24 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws {
25 | guard let copyImageDataMethod = (self as AnyObject)._copyImageData, let imageData = copyImageDataMethod() else {
26 | throw LoggingError.encodingFailure(reason: "Unable to get image data for \(type(of: self))")
27 | }
28 |
29 | encoder.encode(number: UInt64(imageData.count))
30 | encoder.encode(data: imageData)
31 | }
32 |
33 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
34 | return ImageOpaqueRepresentation(kind: .sprite, backedBy: self)
35 | }
36 | }
37 |
38 | extension SKShapeNode: SpriteKitOpaqueLoggable {}
39 | extension SKSpriteNode: SpriteKitOpaqueLoggable {}
40 | extension SKTextureAtlas: SpriteKitOpaqueLoggable {}
41 | extension SKTexture: SpriteKitOpaqueLoggable {}
42 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Swift/Bool+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- Bool+CustomOpaqueLoggable.swift ----------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Bool: CustomOpaqueLoggable {}
14 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Swift/FloatingPoint+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- FloatingPoint+CustomOpaqueLoggable.swift -------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Float: CustomOpaqueLoggable {}
14 | extension Double: CustomOpaqueLoggable {}
15 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Swift/Integers+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- Integers+CustomOpaqueLoggable.swift ------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension Int: CustomOpaqueLoggable {
14 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
15 | return Int64(self)
16 | }
17 | }
18 |
19 | extension Int8: CustomOpaqueLoggable {
20 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
21 | return Int64(self)
22 | }
23 | }
24 |
25 | extension Int16: CustomOpaqueLoggable {
26 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
27 | return Int64(self)
28 | }
29 | }
30 |
31 | extension Int32: CustomOpaqueLoggable {
32 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
33 | return Int64(self)
34 | }
35 | }
36 |
37 | extension Int64: CustomOpaqueLoggable {}
38 |
39 | extension UInt: CustomOpaqueLoggable {
40 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
41 | return UInt64(self)
42 | }
43 | }
44 |
45 | extension UInt8: CustomOpaqueLoggable {
46 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
47 | return UInt64(self)
48 | }
49 | }
50 |
51 | extension UInt16: CustomOpaqueLoggable {
52 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
53 | return UInt64(self)
54 | }
55 | }
56 |
57 | extension UInt32: CustomOpaqueLoggable {
58 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
59 | return UInt64(self)
60 | }
61 | }
62 |
63 | extension UInt64: CustomOpaqueLoggable {}
64 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Swift/String+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- String+CustomOpaqueLoggable.swift --------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension String: CustomOpaqueLoggable {}
14 |
15 | extension Character: CustomOpaqueLoggable {
16 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
17 | return String(self)
18 | }
19 | }
20 |
21 | extension UnicodeScalar: CustomOpaqueLoggable {
22 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
23 | return UInt64(self)
24 | }
25 | }
26 |
27 | extension String.UnicodeScalarView: CustomOpaqueLoggable {
28 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
29 | return self.description
30 | }
31 | }
32 |
33 | extension String.UTF16View: CustomOpaqueLoggable {
34 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
35 | return self.description
36 | }
37 | }
38 |
39 | extension String.UTF8View: CustomOpaqueLoggable {
40 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
41 | return self.description
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/Swift/UnsafePointers+CustomPlaygroundLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- UnsafePointers+CustomOpaqueLoggable.swift ------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension UnsafePointer: CustomOpaqueLoggable {
14 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
15 | let uintValue = UInt64(UInt(bitPattern: self))
16 | return "UnsafePointer(\(uintValue == 0 ? "nil" : String(uintValue, radix: 16, uppercase: true)))"
17 | }
18 | }
19 |
20 | extension UnsafeRawPointer: CustomOpaqueLoggable {
21 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
22 | let uintValue = UInt64(UInt(bitPattern: self))
23 | return "UnsafeRawPointer(\(uintValue == 0 ? "nil" : String(uintValue, radix: 16, uppercase: true)))"
24 | }
25 | }
26 |
27 | extension UnsafeMutablePointer: CustomOpaqueLoggable {
28 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
29 | let uintValue = UInt64(UInt(bitPattern: self))
30 | return "UnsafeMutablePointer(\(uintValue == 0 ? "nil" : String(uintValue, radix: 16, uppercase: true)))"
31 | }
32 | }
33 |
34 | extension UnsafeMutableRawPointer: CustomOpaqueLoggable {
35 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
36 | let uintValue = UInt64(UInt(bitPattern: self))
37 | return "UnsafeMutableRawPointer(\(uintValue == 0 ? "nil" : String(uintValue, radix: 16, uppercase: true)))"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/UIKit/UIBezierPath+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- UIBezierPath+CustomOpaqueLoggable.swift --------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import UIKit
15 |
16 | extension UIBezierPath: CustomOpaqueLoggable {}
17 | #endif
18 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/UIKit/UIColor+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- UIColor+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import UIKit
15 |
16 | extension UIColor: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return self.cgColor
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/UIKit/UIImage+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- UIImage+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import UIKit
15 |
16 | extension UIImage: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return ImageOpaqueRepresentation(kind: .image, backedBy: self)
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/CustomLoggable/UIKit/UIView+CustomOpaqueLoggable.swift:
--------------------------------------------------------------------------------
1 | //===--- UIView+CustomOpaqueLoggable.swift -------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import UIKit
15 |
16 | extension UIView: CustomOpaqueLoggable {
17 | func opaqueRepresentation() -> LogEntry.OpaqueRepresentation {
18 | return ImageOpaqueRepresentation(kind: .view, backedBy: self)
19 | }
20 | }
21 | #endif
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSHumanReadableCopyright
22 | Copyright © 2017 Swift project. All rights reserved.
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/LogEncoder.swift:
--------------------------------------------------------------------------------
1 | //===--- LogEncoder.swift -------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | final class LogEncoder {
16 | enum Format: UInt64 {
17 | case ten = 10
18 |
19 | static let current = Format.ten
20 | }
21 |
22 | private let buffer = NSMutableData()
23 |
24 | init() {}
25 |
26 | var encodedData: Data { return buffer as Data }
27 |
28 | func encode(byte: UInt8) {
29 | var byte = byte
30 | buffer.append(&byte, length: 1)
31 | }
32 |
33 | func encode(bytes: UnsafePointer, length: Int) {
34 | buffer.append(bytes, length: length)
35 | }
36 |
37 | func encode(number: UInt64, allowShortEncoding: Bool = true) {
38 | if allowShortEncoding && number < 255 {
39 | var byte = UInt8(number)
40 | buffer.append(&byte, length: 1)
41 | return
42 | }
43 |
44 | if allowShortEncoding {
45 | // If we allow the short encoding, but our number is too large, we need to include a marker.
46 | // If we don't allow the short encoding, we don't need to include the marker.
47 | var marker: UInt8 = 255
48 | buffer.append(&marker, length: 1)
49 | }
50 |
51 | var littleEndianNumber = number.littleEndian
52 | buffer.append(&littleEndianNumber, length: MemoryLayout.size)
53 | }
54 |
55 | func encode(string: String) {
56 | let utf8Count = string.utf8.count
57 | encode(number: UInt64(utf8Count))
58 | buffer.append(string, length: utf8Count)
59 | }
60 |
61 | func encode(boolean: Bool) {
62 | var byte: UInt8 = boolean ? 1 : 0
63 | buffer.append(&byte, length: 1)
64 | }
65 |
66 | func encode(float: Float) {
67 | var float = float
68 | buffer.append(&float, length: MemoryLayout.size)
69 | }
70 |
71 | func encode(double: Double) {
72 | var double = double
73 | buffer.append(&double, length: MemoryLayout.size)
74 | }
75 |
76 | func encode(data: Data) {
77 | buffer.append(data)
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/LogEntry.swift:
--------------------------------------------------------------------------------
1 | //===--- LogEntry.swift ---------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | enum LogEntry {
14 | typealias OpaqueRepresentation = OpaqueLogEntryRepresentation
15 |
16 | enum StructuredDisposition {
17 | case `class`
18 | case `struct`
19 | case tuple
20 | case `enum`
21 | case aggregate
22 | case container
23 | case indexContainer
24 | case keyContainer
25 | case membershipContainer
26 | }
27 |
28 | case structured(name: String, typeName: String, summary: String, totalChildrenCount: Int, children: [LogEntry], disposition: StructuredDisposition)
29 | case opaque(name: String, typeName: String, summary: String, preferBriefSummary: Bool, representation: OpaqueRepresentation)
30 | case gap
31 | case scopeEntry, scopeExit
32 | case error(reason: String)
33 | }
34 |
35 | protocol OpaqueLogEntryRepresentation {
36 | func encode(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) throws
37 | }
38 |
39 | private let emptyName = ""
40 |
41 | extension LogEntry {
42 | var name: String {
43 | switch self {
44 | case let .structured(name, _, _, _, _, _):
45 | return name
46 | case let .opaque(name, _, _, _, _):
47 | return name
48 | case .gap, .scopeEntry, .scopeExit, .error:
49 | return emptyName
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/LogPacket+Encoding.swift:
--------------------------------------------------------------------------------
1 | //===--- LogPacket+Encoding.swift -----------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | extension LogPacket {
16 | func encode(inFormat format: LogEncoder.Format = .current) throws -> Data {
17 | let encoder = LogEncoder()
18 |
19 | // Encode the format version.
20 | encoder.encode(number: format.rawValue)
21 |
22 | // Encode the source location.
23 | encoder.encode(number: UInt64(startLine), allowShortEncoding: false)
24 | encoder.encode(number: UInt64(startColumn), allowShortEncoding: false)
25 | encoder.encode(number: UInt64(endLine), allowShortEncoding: false)
26 | encoder.encode(number: UInt64(endColumn), allowShortEncoding: false)
27 |
28 | // Encode the thread ID.
29 | encoder.encode(number: 1)
30 | encoder.encode(string: "tid")
31 | encoder.encode(string: threadID)
32 |
33 | // Encode our top-level log entry. (This will add any child entries automatically.)
34 | try logEntry.encode(with: encoder, format: format)
35 |
36 | return encoder.encodedData
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/LogPolicy.swift:
--------------------------------------------------------------------------------
1 | //===--- LogPolicy.swift --------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018-2021 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | struct LogPolicy {
14 | static let `default`: LogPolicy = LogPolicy()
15 |
16 | /// The policy for the maximum depth level for log entries.
17 | var maximumDepth: Int
18 |
19 | enum ChildPolicy {
20 | /// Indicates that all children should be logged.
21 | case all
22 | /// Indicates that no more than the first `count` children should be logged.
23 | case head(count: Int)
24 | /// Indicates that no more than the first `headCount` and last `tailCount` children should be logged.
25 | case headTail(headCount: Int, tailCount: Int)
26 | /// Indicates that no children should be logged.
27 | case none
28 | }
29 |
30 | /// The policy for logging children of aggregates (e.g. classes, structs, enums, tuples).
31 | var aggregateChildPolicy: ChildPolicy
32 |
33 | /// The policy for logging children of containers (e.g. optionals, collections, dictionaries, sets).
34 | var containerChildPolicy: ChildPolicy
35 |
36 | /// Initializes a new `LogPolicy`.
37 | ///
38 | /// - parameter maximumDepth: The maximum depth level for logging children of children. Defaults to 2, but the default can be overridden with the `LOGGER_DEPTH` environment variable.
39 | /// - parameter aggregateChildPolicy: The policy to use for logging children of aggregates. Defaults to logging no more than the first 10,000 children.
40 | /// - parameter containerChildPolicy: The policy to use for logging children of collections. Defaults to logging no more than the first 80 children plus the last 20 children.
41 | init(maximumDepth: Int = (LogPolicy.environmentMaxDepth ?? 2),
42 | aggregateChildPolicy: ChildPolicy = .head(count: 10_000),
43 | containerChildPolicy: ChildPolicy = .headTail(headCount: 80, tailCount: 20)) {
44 | self.maximumDepth = maximumDepth
45 | self.aggregateChildPolicy = aggregateChildPolicy
46 | self.containerChildPolicy = containerChildPolicy
47 | }
48 |
49 | /// Read and return the `LOGGER_DEPTH` from the environment.
50 | static let loggerDepthEnvironmentKey = "LOGGER_DEPTH"
51 | private static var environmentMaxDepth: Int? {
52 | guard let envDepth = ProcessInfo.processInfo.environment[loggerDepthEnvironmentKey] else {
53 | return nil
54 | }
55 | return Int(envDepth)
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/LoggerInitialization.swift:
--------------------------------------------------------------------------------
1 | //===--- LoggerInitialization.swift ---------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | /// Initializes the PlaygroundLogger framework.
16 | ///
17 | /// - note: This function is invoked by host stubs via dlsym.
18 | @_cdecl("PGLInitializePlaygroundLogger")
19 | public func initializePlaygroundLogger(clientVersion: Int, sendData: @escaping SendDataFunction) -> Void {
20 | Swift._playgroundPrintHook = printHook
21 | PlaygroundLogger.sendData = sendData
22 |
23 | // TODO: take clientVersion and use to customize PlaygroundLogger behavior.
24 | }
25 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/AppKit/NSBezierPath+KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- NSBezierPath+KeyedArchiveOpaqueRepresentation.swift --------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import Foundation
15 | import AppKit
16 |
17 | fileprivate let bezierPathTag = "BEZP"
18 |
19 | extension NSBezierPath: KeyedArchiveOpaqueRepresentation {
20 | var tag: String { return bezierPathTag }
21 |
22 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) throws {
23 | do {
24 | try self.encodeForLogEntry(using: encoder)
25 | }
26 | catch {
27 | throw LoggingError.encodingFailure(reason: "Failed to encode NSBezierPath using NSKeyedArchiver")
28 | }
29 | }
30 | }
31 | #endif
32 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/AppKit/NSBezierPath+PGLKeyedArchivingUtilities.h:
--------------------------------------------------------------------------------
1 | //===--- NSBezierPath+PGLKeyedArchivingUtilities.h ------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | #if TARGET_OS_OSX
16 |
17 | #import
18 |
19 | NS_ASSUME_NONNULL_BEGIN
20 |
21 | @interface NSBezierPath (PGLKeyedArchivingUtilities)
22 |
23 | - (BOOL)pgl_encodeForLogEntryUsingEncoder:(NSCoder *)coder error:(NSError **)outError NS_SWIFT_NAME(encodeForLogEntry(using:));
24 |
25 | @end
26 |
27 | NS_ASSUME_NONNULL_END
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/AppKit/NSBezierPath+PGLKeyedArchivingUtilities.m:
--------------------------------------------------------------------------------
1 | //===--- NSBezierPath+PGLKeyedArchivingUtilities.h ------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | #if TARGET_OS_OSX
16 |
17 | @implementation NSBezierPath (PGLKeyedArchivingUtilities)
18 |
19 | - (BOOL)pgl_encodeForLogEntryUsingEncoder:(NSCoder *)coder error:(NSError **)outError {
20 | @try {
21 | [coder encodeObject:self forKey:@"root"];
22 | }
23 | @catch (...) {
24 | if (outError) {
25 | *outError = [NSError errorWithDomain:@"PGLErrorDomain" code:-1 userInfo:@{
26 | NSLocalizedFailureReasonErrorKey: @"Encountered an exception when encoding an NSBezierPath",
27 | }];
28 | }
29 | return NO;
30 | }
31 |
32 | return YES;
33 | }
34 |
35 | @end
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/AppKit/NSBitmapImageRep+OpaqueImageRepresentable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSBitmapImageRep+OpaqueImageRepresentable.swift ------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSBitmapImageRep: OpaqueImageRepresentable {
17 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws {
18 | guard let pngData = self.representation(using: .png, properties: [:]) else {
19 | throw LoggingError.encodingFailure(reason: "Failed to generate PNG data for the bitmap representation")
20 | }
21 |
22 | encoder.encode(number: UInt64(pngData.count))
23 | encoder.encode(data: pngData)
24 | }
25 | }
26 | #endif
27 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/AppKit/NSImage+OpaqueImageRepresentable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSImage+OpaqueImageRepresentable.swift ---------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSImage: OpaqueImageRepresentable {
17 | private var bestBitmapRepresentation: NSBitmapImageRep? {
18 | guard let bestRep = self.bestRepresentation(for: NSRect(origin: .zero, size: size).integral, context: nil, hints: nil) else {
19 | // We don't have a best representation, so we can't convert it to a bitmap image rep.
20 | return nil
21 | }
22 |
23 | if let bitmapRep = bestRep as? NSBitmapImageRep {
24 | return bitmapRep
25 | }
26 | else {
27 | guard let cgImage = bestRep.cgImage(forProposedRect: nil, context: nil, hints: nil) else {
28 | return nil
29 | }
30 |
31 | return NSBitmapImageRep(cgImage: cgImage)
32 | }
33 | }
34 |
35 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws {
36 | guard let bitmapRep = self.bestBitmapRepresentation else {
37 | if (size == .zero) || self.representations.isEmpty {
38 | // If we couldn't get a bitmap representation because the image was empty, encode empty PNG data.
39 | encoder.encode(number: 0)
40 | return
41 | }
42 | else {
43 | throw LoggingError.encodingFailure(reason: "Failed to get a bitmap representation of this NSImage")
44 | }
45 | }
46 |
47 | try bitmapRep.encodeImage(into: encoder, withFormat: format)
48 | }
49 | }
50 | #endif
51 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/AppKit/NSView+OpaqueImageRepresentable.swift:
--------------------------------------------------------------------------------
1 | //===--- NSView+OpaqueImageRepresentable.swift ----------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2019 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(macOS)
14 | import AppKit
15 |
16 | extension NSView: OpaqueImageRepresentable {
17 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws {
18 | guard Thread.isMainThread else {
19 | // If we're not on the main thread, then just encode empty PNG data.
20 | encoder.encode(number: 0)
21 | return
22 | }
23 |
24 | guard let bitmapRep = self.bitmapImageRepForCachingDisplay(in: self.bounds) else {
25 | if self.bounds == .zero {
26 | // If we couldn't get a bitmap representation because the view is zero-sized, encode empty PNG data.
27 | encoder.encode(number: 0)
28 | return
29 | }
30 | else {
31 | throw LoggingError.encodingFailure(reason: "Unable to create a bitmap representation of this NSView")
32 | }
33 | }
34 |
35 | self.cacheDisplay(in: self.bounds, to: bitmapRep)
36 |
37 | try bitmapRep.encodeImage(into: encoder, withFormat: format)
38 | }
39 | }
40 | #endif
41 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/CoreGraphics/CGColor+KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- CGColor+KeyedArchiveOpaqueRepresentation.swift -------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 | import Foundation
15 |
16 | fileprivate let colorTag = "COLR"
17 |
18 | fileprivate let colorSpaceKey = "IDEColorSpaceKey"
19 | fileprivate let colorComponentsKey = "IDEColorComponentsKey"
20 |
21 | extension CGColor: KeyedArchiveOpaqueRepresentation {
22 | var tag: String { return colorTag }
23 |
24 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) throws {
25 | guard let colorSpace = self.colorSpace else {
26 | throw LoggingError.encodingFailure(reason: "Unable to encode a color which does not have a color space")
27 | }
28 |
29 | guard colorSpace.model != .pattern else {
30 | // TODO: implement support for encoding pattern colors.
31 | throw LoggingError.encodingFailure(reason: "Unable to encode pattern colors at this time")
32 | }
33 |
34 | guard let colorSpaceName = colorSpace.name, let components = self.components else {
35 | throw LoggingError.encodingFailure(reason: "Unable to encode a color which is in an unnamed color space or is missing components")
36 | }
37 |
38 | encoder.encode(colorSpaceName as NSString, forKey: colorSpaceKey)
39 | encoder.encode(components.map { $0 as NSNumber } as NSArray, forKey: colorComponentsKey)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/CoreGraphics/CGGeometry+KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- CGGeometry+KeyedArchiveOpaqueRepresentation.swift ----------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 | import Foundation
15 |
16 | fileprivate let pointTag = "PONT"
17 | fileprivate let sizeTag = "SIZE"
18 | fileprivate let rectTag = "RECT"
19 |
20 | extension CGPoint: KeyedArchiveOpaqueRepresentation {
21 | var tag: String { return pointTag }
22 |
23 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) {
24 | encoder.encode(Double(self.x), forKey: "x")
25 | encoder.encode(Double(self.y), forKey: "y")
26 | }
27 | }
28 |
29 | extension CGSize: KeyedArchiveOpaqueRepresentation {
30 | var tag: String { return sizeTag }
31 |
32 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) {
33 | encoder.encode(Double(self.width), forKey: "w")
34 | encoder.encode(Double(self.height), forKey: "h")
35 | }
36 | }
37 |
38 | extension CGRect: KeyedArchiveOpaqueRepresentation {
39 | var tag: String { return rectTag }
40 |
41 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) {
42 | encoder.encode(Double(self.origin.x), forKey: "x")
43 | encoder.encode(Double(self.origin.y), forKey: "y")
44 | encoder.encode(Double(self.size.width), forKey: "w")
45 | encoder.encode(Double(self.size.height), forKey: "h")
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/CoreGraphics/CGImage+OpaqueImageRepresentable.swift:
--------------------------------------------------------------------------------
1 | //===--- CGImage+OpaqueImageRepresentable.swift ---------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import CoreGraphics
14 |
15 | #if os(macOS)
16 | import AppKit
17 | #elseif os(iOS) || os(tvOS)
18 | import UIKit
19 | #endif
20 |
21 | extension CGImage: OpaqueImageRepresentable {
22 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws {
23 | #if os(macOS)
24 | // On macOS, simply create an NSBitmapImageRep with the receiver and use that.
25 | let bitmapRep = NSBitmapImageRep(cgImage: self)
26 | try bitmapRep.encodeImage(into: encoder, withFormat: format)
27 | #elseif os(iOS) || os(tvOS)
28 | let uiImage = UIImage(cgImage: self)
29 | try uiImage.encodeImage(into: encoder, withFormat: format)
30 | #endif
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Foundation/NSAttributedString+KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- NSAttributedString+KeyedArchiveOpaqueRepresentation.swift --------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | fileprivate let attributedStringTag = "ASTR"
16 |
17 | extension NSAttributedString: KeyedArchiveOpaqueRepresentation {
18 | var tag: String { return attributedStringTag }
19 |
20 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) throws {
21 | do {
22 | try self.encodeForLogEntry(using: encoder)
23 | }
24 | catch {
25 | throw LoggingError.encodingFailure(reason: "Failed to encode NSAttributedString using NSKeyedArchiver")
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Foundation/NSAttributedString+PGLKeyedArchivingUtilities.h:
--------------------------------------------------------------------------------
1 | //===--- NSAttributedString+PGLKeyedArchivingUtilities.h ------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | NS_ASSUME_NONNULL_BEGIN
16 |
17 | @interface NSAttributedString (PGLKeyedArchivingUtilities)
18 |
19 | - (BOOL)pgl_encodeForLogEntryUsingEncoder:(NSCoder *)coder error:(NSError **)outError NS_SWIFT_NAME(encodeForLogEntry(using:));
20 |
21 | @end
22 |
23 | NS_ASSUME_NONNULL_END
24 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Foundation/NSAttributedString+PGLKeyedArchivingUtilities.m:
--------------------------------------------------------------------------------
1 | //===--- NSAttributedString+PGLKeyedArchivingUtilities.m ------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | @implementation NSAttributedString (PGLKeyedArchivingUtilities)
16 |
17 | - (BOOL)pgl_encodeForLogEntryUsingEncoder:(NSCoder *)coder error:(NSError **)outError {
18 | @try {
19 | [coder encodeObject:self forKey:@"root"];
20 | }
21 | @catch (...) {
22 | if (outError) {
23 | *outError = [NSError errorWithDomain:@"PGLErrorDomain" code:-1 userInfo:@{
24 | NSLocalizedFailureReasonErrorKey: @"Encountered an exception when encoding an NSAttributedString",
25 | }];
26 | }
27 | return NO;
28 | }
29 |
30 | return YES;
31 | }
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Foundation/NSRange+KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- NSRange+KeyedArchiveOpaqueRepresentation.swift -------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | fileprivate let rangeTag = "RANG"
16 |
17 | extension NSRange: KeyedArchiveOpaqueRepresentation {
18 | var tag: String { return rangeTag }
19 |
20 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) {
21 | encoder.encode(Int64(self.location), forKey: "loc")
22 | encoder.encode(Int64(self.length), forKey: "len")
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Foundation/URL+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- URL+TaggedOpaqueRepresentation.swift -----------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | fileprivate let urlTag = "URL"
16 |
17 | extension URL: TaggedOpaqueRepresentation {
18 | var tag: String { return urlTag }
19 |
20 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
21 | let urlString = self.absoluteString
22 | let utf8Count = urlString.utf8.count
23 | encoder.encode(number: UInt64(utf8Count))
24 | encoder.encode(bytes: urlString, length: utf8Count)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/ImageOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- ImageOpaqueRepresentation.swift ----------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | protocol OpaqueImageRepresentable {
16 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws
17 | }
18 |
19 | struct ImageOpaqueRepresentation: TaggedOpaqueRepresentation {
20 | enum Kind: String {
21 | case image = "IMAG"
22 | case view = "VIEW"
23 | case sprite = "SKIT"
24 | }
25 |
26 | private let kind: Kind
27 | private let imageEncoder: (LogEncoder, LogEncoder.Format) throws -> Void
28 |
29 | init(kind: Kind, backedBy implementation: Implementation) {
30 | self.kind = kind
31 | self.imageEncoder = { try implementation.encodeImage(into: $0, withFormat: $1) }
32 | }
33 |
34 | var tag: String { return kind.rawValue }
35 |
36 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) throws {
37 | try imageEncoder(encoder, format)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- KeyedArchiveOpaqueRepresentation.swift ---------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | protocol KeyedArchiveOpaqueRepresentation: TaggedOpaqueRepresentation {
16 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) throws
17 | }
18 |
19 | extension KeyedArchiveOpaqueRepresentation {
20 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) throws {
21 | let archivedData = NSMutableData()
22 | let archiver = NSKeyedArchiver(forWritingWith: archivedData)
23 |
24 | try self.encodeOpaqueRepresentation(with: archiver, usingFormat: format)
25 |
26 | archiver.finishEncoding()
27 |
28 | encoder.encode(number: UInt64(archivedData.length))
29 | encoder.encode(data: archivedData as Data)
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Swift/Bool+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- Bool+TaggedOpaqueRepresentation.swift ----------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let boolTag = "BOOL"
14 |
15 | extension Bool: TaggedOpaqueRepresentation {
16 | var tag: String { return boolTag }
17 |
18 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
19 | encoder.encode(number: 1)
20 | encoder.encode(boolean: self)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Swift/Double+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- Double+TaggedOpaqueRepresentation.swift --------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let doubleTag = "DOBL"
14 |
15 | extension Double: TaggedOpaqueRepresentation {
16 | var tag: String { return doubleTag }
17 |
18 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
19 | encoder.encode(number: UInt64(MemoryLayout.size))
20 | encoder.encode(double: self)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Swift/Float+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- Float+TaggedOpaqueRepresentation.swift ---------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let floatTag = "FLOT"
14 |
15 | extension Float: TaggedOpaqueRepresentation {
16 | var tag: String { return floatTag }
17 |
18 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
19 | encoder.encode(number: UInt64(MemoryLayout.size))
20 | encoder.encode(float: self)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Swift/Int64+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- Int64+TaggedOpaqueRepresentation.swift ---------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let signedIntegerTag = "SINT"
14 |
15 | extension Int64: TaggedOpaqueRepresentation {
16 | var tag: String { return signedIntegerTag }
17 |
18 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
19 | let description = String(self)
20 | let utf8Count = description.utf8.count
21 | encoder.encode(number: UInt64(utf8Count))
22 | encoder.encode(bytes: description, length: utf8Count)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Swift/String+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- String+TaggedOpaqueRepresentation.swift --------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let stringTag = "STRN"
14 |
15 | extension String: TaggedOpaqueRepresentation {
16 | var tag: String { return stringTag }
17 |
18 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
19 | let utf8Count = self.utf8.count
20 | encoder.encode(number: UInt64(utf8Count))
21 | encoder.encode(bytes: self, length: utf8Count)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/Swift/UInt64+TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- UInt64+TaggedOpaqueRepresentation.swift --------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let unsignedIntegerTag = "SINT"
14 |
15 | extension UInt64: TaggedOpaqueRepresentation {
16 | var tag: String { return unsignedIntegerTag }
17 |
18 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) {
19 | let description = String(self)
20 | let utf8Count = description.utf8.count
21 | encoder.encode(number: UInt64(utf8Count))
22 | encoder.encode(bytes: description, length: utf8Count)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/TaggedOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- TaggedOpaqueRepresentation.swift ---------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | protocol TaggedOpaqueRepresentation: LogEntry.OpaqueRepresentation {
14 | var tag: String { get }
15 |
16 | func encodePayload(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) throws
17 | }
18 |
19 | extension TaggedOpaqueRepresentation {
20 | func encode(into encoder: LogEncoder, usingFormat format: LogEncoder.Format) throws {
21 | encoder.encode(string: tag)
22 | try self.encodePayload(into: encoder, usingFormat: format)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/UIKit/UIBezierPath+KeyedArchiveOpaqueRepresentation.swift:
--------------------------------------------------------------------------------
1 | //===--- UIBezierPath+KeyedArchiveOpaqueRepresentation.swift --------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import Foundation
15 | import UIKit
16 |
17 | fileprivate let bezierPathTag = "BEZP"
18 |
19 | extension UIBezierPath: KeyedArchiveOpaqueRepresentation {
20 | var tag: String { return bezierPathTag }
21 |
22 | func encodeOpaqueRepresentation(with encoder: NSCoder, usingFormat format: LogEncoder.Format) throws {
23 | do {
24 | try self.encodeForLogEntry(using: encoder)
25 | }
26 | catch {
27 | throw LoggingError.encodingFailure(reason: "Failed to encode UIBezierPath using NSKeyedArchiver")
28 | }
29 | }
30 | }
31 | #endif
32 |
33 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/UIKit/UIBezierPath+PGLKeyedArchivingUtilities.h:
--------------------------------------------------------------------------------
1 | //===--- UIBezierPath+PGLKeyedArchivingUtilities.h ------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | #if TARGET_OS_IOS || TARGET_OS_TV
16 |
17 | #import
18 |
19 | NS_ASSUME_NONNULL_BEGIN
20 |
21 | @interface UIBezierPath (PGLKeyedArchivingUtilities)
22 |
23 | - (BOOL)pgl_encodeForLogEntryUsingEncoder:(NSCoder *)coder error:(NSError **)outError NS_SWIFT_NAME(encodeForLogEntry(using:));
24 |
25 | @end
26 |
27 | NS_ASSUME_NONNULL_END
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/UIKit/UIBezierPath+PGLKeyedArchivingUtilities.m:
--------------------------------------------------------------------------------
1 | //===--- UIBezierPath+PGLKeyedArchivingUtilities.m ------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | #if TARGET_OS_IOS || TARGET_OS_TV
16 |
17 | @implementation UIBezierPath (PGLKeyedArchivingUtilities)
18 |
19 | - (BOOL)pgl_encodeForLogEntryUsingEncoder:(NSCoder *)coder error:(NSError **)outError {
20 | @try {
21 | [coder encodeObject:self forKey:@"root"];
22 | }
23 | @catch (...) {
24 | if (outError) {
25 | *outError = [NSError errorWithDomain:@"PGLErrorDomain" code:-1 userInfo:@{
26 | NSLocalizedFailureReasonErrorKey: @"Encountered an exception when encoding an UIBezierPath",
27 | }];
28 | }
29 | return NO;
30 | }
31 |
32 | return YES;
33 | }
34 |
35 | @end
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/UIKit/UIImage+OpaqueImageRepresentable.swift:
--------------------------------------------------------------------------------
1 | //===--- UIImage+OpaqueImageRepresentable.swift ---------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import UIKit
15 |
16 | extension UIImage: OpaqueImageRepresentable {
17 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) throws {
18 | guard let pngData = self.pngData() else {
19 | if size == .zero {
20 | // We tried encoding an empty image, so it understandably failed.
21 | // In this case, simply encode empty PNG data.
22 | encoder.encode(number: 0)
23 | return
24 | }
25 | else {
26 | throw LoggingError.encodingFailure(reason: "Failed to convert UIImage to PNG")
27 | }
28 | }
29 |
30 | encoder.encode(number: UInt64(pngData.count))
31 | encoder.encode(data: pngData)
32 | }
33 | }
34 | #endif
35 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/OpaqueRepresentations/UIKit/UIView+OpaqueImageRepresentable.swift:
--------------------------------------------------------------------------------
1 | //===--- UIView+OpaqueImageRepresentable.swift ----------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2019 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(iOS) || os(tvOS)
14 | import UIKit
15 |
16 | extension UIView: OpaqueImageRepresentable {
17 | func encodeImage(into encoder: LogEncoder, withFormat format: LogEncoder.Format) {
18 | guard Thread.isMainThread else {
19 | // If we're not on the main thread, then just encode empty PNG data.
20 | encoder.encode(number: 0)
21 | return
22 | }
23 |
24 | let ir = UIGraphicsImageRenderer(size: bounds.size)
25 | let pngData = ir.pngData { _ in
26 | self.drawHierarchy(in: bounds, afterScreenUpdates: true)
27 | }
28 |
29 | encoder.encode(number: UInt64(pngData.count))
30 | encoder.encode(data: pngData)
31 | }
32 | }
33 | #endif
34 |
35 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/PlaygroundLogger.h:
--------------------------------------------------------------------------------
1 | //===--- PlaygroundLogger.h -----------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | //! Project version number for PlaygroundLogger.
16 | FOUNDATION_EXPORT double PlaygroundLoggerVersionNumber;
17 |
18 | //! Project version string for PlaygroundLogger.
19 | FOUNDATION_EXPORT const unsigned char PlaygroundLoggerVersionString[];
20 |
21 | #import
22 | #import
23 |
24 | #import
25 | #import
26 | #import
27 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/SendData.swift:
--------------------------------------------------------------------------------
1 | //===--- SendData.swift ---------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import Foundation
14 |
15 | internal /*testable*/ func unsetSendData(_: NSData) {
16 | fatalError("PlaygroundLogger not initialized")
17 | }
18 |
19 | // Declared public for use in initialization.
20 | public typealias SendDataFunction = @convention(c) (NSData) -> Void
21 |
22 | var sendData: SendDataFunction = unsetSendData
23 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/TypeName.swift:
--------------------------------------------------------------------------------
1 | //===--- TypeName.swift ---------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014-2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | fileprivate let typeNameCache = PGLConcurrentMap()
14 |
15 | private let swiftStdlibModuleNameRegex = try! NSRegularExpression(pattern: "(? String {
18 | return swiftStdlibModuleNameRegex.stringByReplacingMatches(in: typeName, options: [], range: NSRange(location: 0, length: typeName.utf16.count), withTemplate: "")
19 | }
20 |
21 | /// Returns the normalized name of the given `Any.Type`.
22 | ///
23 | /// - note: This function caches type names, as normalization (and type name generation in general) can be expensive.
24 | func normalizedName(of type: Any.Type) -> String {
25 | let key = Int(bitPattern: ObjectIdentifier(type))
26 | let (object, _) = typeNameCache.object(forKey: key, insertingIfNecessary: normalizeTypeName(_typeName(type)))
27 | return object as! String
28 | }
29 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/Utilities/LoggingError.swift:
--------------------------------------------------------------------------------
1 | //===--- LoggingError.swift -----------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | enum LoggingError: Error {
14 | case failedToGenerateOpaqueRepresentation(reason: String)
15 | case encodingFailure(reason: String)
16 | case otherFailure(reason: String)
17 | }
18 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/Utilities/PGLConcurrentMap.h:
--------------------------------------------------------------------------------
1 | //===--- PGLConcurrentMap.h -----------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 | //
13 | // PGLConcurrentMap provides an insertion-only map which allows for concurrent
14 | // accesses with minimal overhead. Since this is extremely limited, the keys
15 | // into this map are integers. (The values are arbitrary objects.)
16 | //
17 | //===----------------------------------------------------------------------===//
18 |
19 | #import
20 |
21 | NS_ASSUME_NONNULL_BEGIN
22 |
23 | @interface PGLConcurrentMap : NSObject
24 |
25 | - (instancetype)init NS_DESIGNATED_INITIALIZER;
26 |
27 | - (BOOL)containsObjectForKey:(NSInteger)key;
28 |
29 | - (nullable id)objectForKey:(NSInteger)key;
30 |
31 | - (id)objectForKey:(NSInteger)key insertingObjectProvidedByBlockIfNotPresent:(id(^ NS_NOESCAPE)(void))objectProvider didInsert:(BOOL *)outDidInsert NS_REFINED_FOR_SWIFT;
32 |
33 | - (id)objectForKey:(NSInteger)key insertingObjectIfNotPresent:(id)object didInsert:(BOOL *)outDidInsert NS_REFINED_FOR_SWIFT;
34 |
35 | @end
36 |
37 | NS_ASSUME_NONNULL_END
38 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/Utilities/PGLConcurrentMap.swift:
--------------------------------------------------------------------------------
1 | //===--- PGLConcurrentMap.swift -------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | extension PGLConcurrentMap {
14 | func object(forKey key: Int, insertingIfNecessary object: @autoclosure () -> Any) -> (Any, didInsert: Bool) {
15 | var didInsert: ObjCBool = false
16 | let returnedObject = self.__object(forKey: key, insertingObjectProvidedByBlockIfNotPresent: object, didInsert: &didInsert)
17 | return (returnedObject, didInsert: didInsert.boolValue)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/Utilities/PGLThreadIsLogging.h:
--------------------------------------------------------------------------------
1 | //===--- PGLThreadIsLogging.h ---------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 | #import
15 |
16 | __BEGIN_DECLS
17 |
18 | /// A thread-local `bool` which indicates whether or not the current thread is
19 | /// logging.
20 | ///
21 | /// This is used by the functions in LoggerEntrypoints.swift and
22 | /// LegacyEntrypoints.swift to prevent generating log packets while already
23 | /// generating a log packet. It means the side-effects of logging are not
24 | /// themselves logged.
25 | extern __thread bool PGLThreadIsLogging;
26 |
27 | /// A helper function to get the value of `PGLThreadIsLogging` safely from Swift.
28 | static inline bool PGLGetThreadIsLogging(void) {
29 | return PGLThreadIsLogging;
30 | }
31 |
32 | /// A helper function to set the value of `PGLThreadIsLogging` safely from Swift.
33 | static inline void PGLSetThreadIsLogging(bool threadIsLogging) {
34 | PGLThreadIsLogging = threadIsLogging;
35 | }
36 |
37 | __END_DECLS
38 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLogger/Utilities/PGLThreadIsLogging.m:
--------------------------------------------------------------------------------
1 | //===--- PGLThreadIsLogging.m ---------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | __thread bool PGLThreadIsLogging = false;
16 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_iOS/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //===--- AppDelegate.swift ------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import UIKit
14 |
15 | @UIApplicationMain
16 | class AppDelegate: UIResponder, UIApplicationDelegate {
17 | var window: UIWindow?
18 |
19 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
20 | return true
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_iOS/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_iOS/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | arm64
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_iOS/ViewController.swift:
--------------------------------------------------------------------------------
1 | //===--- ViewController.swift ---------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import UIKit
14 |
15 | class ViewController: UIViewController {}
16 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_tvOS/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //===--- AppDelegate.swift ------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import UIKit
14 |
15 | @UIApplicationMain
16 | class AppDelegate: UIResponder, UIApplicationDelegate {
17 | var window: UIWindow?
18 |
19 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
20 | return true
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_tvOS/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_tvOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UIMainStoryboardFile
24 | Main
25 | UIRequiredDeviceCapabilities
26 |
27 | arm64
28 |
29 | UIUserInterfaceStyle
30 | Automatic
31 |
32 |
33 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTestHost_tvOS/ViewController.swift:
--------------------------------------------------------------------------------
1 | //===--- ViewController.swift ---------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import UIKit
14 |
15 | class ViewController: UIViewController {}
16 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests/CustomPlaygroundDisplayConvertibleTests.swift:
--------------------------------------------------------------------------------
1 | //===--- CustomPlaygroundDisplayConvertibleTests.swift --------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import XCTest
14 | @testable import PlaygroundLogger
15 |
16 | import CoreGraphics
17 |
18 | class CustomPlaygroundDisplayConvertibleTests: XCTestCase {
19 | func testBasicConformance() throws {
20 | struct MyPoint: CustomPlaygroundDisplayConvertible {
21 | let x: Int
22 | let y: Int
23 |
24 | var playgroundDescription: Any {
25 | return CGPoint(x: x, y: y)
26 | }
27 | }
28 |
29 | let point = MyPoint(x: 4, y: 3)
30 |
31 | let logEntry = try LogEntry(describing: point, name: "point", policy: .default)
32 |
33 | guard case let .opaque(name, typeName, _, _, representation) = logEntry else {
34 | XCTFail("Expected an instance of MyPoint to generate an opaque log entry")
35 | return
36 | }
37 |
38 | XCTAssertEqual(name, "point")
39 | XCTAssert(typeName.hasSuffix(".MyPoint"))
40 |
41 | guard let pointRepresentation = representation as? CGPoint else {
42 | XCTFail("Expected an instance of MyPoint to generate a CGPoint as its opaque representation")
43 | return
44 | }
45 |
46 | XCTAssertEqual(pointRepresentation, CGPoint(x: 4, y: 3))
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests/LegacyEntrypointTests.swift:
--------------------------------------------------------------------------------
1 | //===--- LegacyEntrypointTests.swift --------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import XCTest
14 | @testable import PlaygroundLogger
15 |
16 | class LegacyEntrypointTests: XCTestCase {
17 | func testRecursiveLogging() {
18 | // Create a struct which, as a side effect of being logged, tries to log itself.
19 | // This is representative of a playground where `self` is logged in places like a CustomStringConvertible conformance.
20 | struct Struct: CustomStringConvertible {
21 | let x: Int
22 | let y: Int
23 |
24 | var description: String {
25 | // This direct call to the logger mirrors what would happen if this property were instrumented by the playground logger and there were a bare reference to `self`.
26 | let logData = legacyLog(instance: self, name: "self", id: 0, startLine: 1, endLine: 1, startColumn: 1, endColumn: 1)
27 |
28 | // Since `description` is only ever called by logging, we can assert that we have nil.
29 | // If we called `description` by other means we'd need to vary this assertion to match.
30 | XCTAssertNil(logData)
31 |
32 | return "(\(x), \(y))"
33 | }
34 | }
35 |
36 | let subject = Struct(x: 0, y: 0)
37 |
38 | // Log an instance of `Struct`. This should succeed (i.e. return data).
39 | let logData = legacyLog(instance: subject, name: "subject", id: 0, startLine: 1, endLine: 1, startColumn: 1, endColumn: 1)
40 |
41 | XCTAssertNotNil(logData)
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests/LoggerEntrypointTests.swift:
--------------------------------------------------------------------------------
1 | //===--- LoggerEntrypointTests.swift --------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import XCTest
14 | @testable import PlaygroundLogger
15 |
16 | fileprivate var numberOfDataSent: Int = 0
17 |
18 | fileprivate func countData(_: NSData) -> Void {
19 | numberOfDataSent += 1
20 | }
21 |
22 | class LoggerEntrypointTests: XCTestCase {
23 | override class func setUp() {
24 | super.setUp()
25 |
26 | // Tell PlaygroundLogger to use our function for counting data.
27 | PlaygroundLogger.sendData = countData
28 | }
29 |
30 | override class func tearDown() {
31 | super.tearDown()
32 |
33 | // Reset PlaygroundLogger.
34 | PlaygroundLogger.sendData = unsetSendData
35 | }
36 |
37 | override func setUp() {
38 | // Reset the data counter.
39 | numberOfDataSent = 0
40 |
41 | super.setUp()
42 | }
43 |
44 | func testRecursiveLogging() {
45 | // Create a struct which, as a side effect of being logged, tries to log itself.
46 | // This is representative of a playground where `self` is logged in places like a CustomStringConvertible conformance.
47 | struct Struct: CustomStringConvertible {
48 | let x: Int
49 | let y: Int
50 |
51 | var description: String {
52 | // Capture the previous number of data sent so we can check against it later.
53 | let previousNumberOfDataSent = numberOfDataSent
54 |
55 | // This direct call to the logger mirrors what would happen if this property were instrumented by the playground logger and there were a bare reference to `self`.
56 | PlaygroundLogger.logResult(self, named: "self", withIdentifier: 0, startLine: 1, endLine: 1, startColumn: 1, endColumn: 1)
57 |
58 | // Since `description` is only ever called by logging, we can assert that no additional data was sent.
59 | // If we called `description` by other means we'd need to vary this assertion to match.
60 | XCTAssertEqual(previousNumberOfDataSent, numberOfDataSent, "We don't expect any more data to be sent by that previous log line!")
61 |
62 | return "(\(x), \(y))"
63 | }
64 | }
65 |
66 | let subject = Struct(x: 0, y: 0)
67 |
68 | PlaygroundLogger.logResult(subject, named: "subject", withIdentifier: 0, startLine: 1, endLine: 1, startColumn: 1, endColumn: 1)
69 |
70 | XCTAssertEqual(numberOfDataSent, 1, "We expect only one data to be sent over the course of this test")
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests/PGLNilObject.h:
--------------------------------------------------------------------------------
1 | //===--- PGLNilObject.h ---------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import
14 |
15 | NS_ASSUME_NONNULL_BEGIN
16 |
17 | /// \c PGLNilObject is a test class which includes a \c -init method which is intentionally mis-annotated.
18 | /// It returns \c nil instead of an instance of \c PGLNilObject to allow PlaygroundLogger's tests to exercise logging this sort of broken value.
19 | ///
20 | /// See also: \c LogEntryTests.testNonOptionalNilObject()
21 | @interface PGLNilObject : NSObject
22 |
23 | - (instancetype)init;
24 |
25 | @end
26 |
27 | NS_ASSUME_NONNULL_END
28 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests/PGLNilObject.m:
--------------------------------------------------------------------------------
1 | //===--- PGLNilObject.m ---------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import "PGLNilObject.h"
14 |
15 | @implementation PGLNilObject
16 |
17 | - (instancetype)init {
18 | return nil;
19 | }
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests/PlaygroundLoggerTests-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //===--- PlaygroundLoggerTests-Bridging-Header.h --------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2020 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #import "PGLNilObject.h"
14 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests_iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests_macOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/PlaygroundLogger/PlaygroundLoggerTests_tvOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/PlaygroundSupport/PlaygroundSupport.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PlaygroundSupport/PlaygroundSupport.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/PlaygroundSupport/PlaygroundSupport/PlaygroundSupport-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | ${CURRENT_PROJECT_VERSION}
25 | NSHumanReadableCopyright
26 | Copyright © 2014 Apple Inc. All rights reserved.
27 | NSPrincipalClass
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/PlaygroundSupport/PlaygroundSupport/PlaygroundSupport.h:
--------------------------------------------------------------------------------
1 | //===--- PlaygroundSupport.h ----------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 | //
13 | // This header is intentionally left blank.
14 | // It exists for the aid of code completion, which currently can only complete
15 | // Clang modules.
16 | //
17 | //===----------------------------------------------------------------------===//
18 |
--------------------------------------------------------------------------------
/PlaygroundSupport/PlaygroundSupportTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlayground/XCPExecutionShouldContinue.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | /// This function has been deprecated. Instead, set `PlaygroundPage.current.needsIndefiniteExecution` to the appropriate value.
14 | @available(*,deprecated,message:"Set 'PlaygroundPage.current.needsIndefiniteExecution' from the 'PlaygroundSupport' module instead")
15 | public func XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: Bool = true) {
16 | XCPlaygroundPage.currentPage.needsIndefiniteExecution = continueIndefinitely
17 | }
18 |
19 | /// This function has been deprecated. Instead, check `PlaygroundPage.current.needsIndefiniteExecution` to see if indefinite execution has been requested.
20 | @available(*,deprecated,message:"Use 'PlaygroundPage.current.needsIndefiniteExecution' from the 'PlaygroundSupport' module instead")
21 | public func XCPExecutionShouldContinueIndefinitely() -> Bool {
22 | return XCPlaygroundPage.currentPage.needsIndefiniteExecution
23 | }
24 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlayground/XCPSharedDataDirectory.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | /// `XCPSharedDataDirectoryPath` has been deprecated. Use `XCPlaygroundSharedDataDirectoryURL` instead.
14 | @available(*,deprecated,message:"Use 'PlaygroundSharedDataDirectoryURL' from the 'PlaygroundSupport' module instead")
15 | public var XCPSharedDataDirectoryPath: String {
16 | return XCPlaygroundSharedDataDirectoryURL.path!
17 | }
18 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlayground/XCPShowView.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #if os(OSX)
14 | import AppKit
15 | #elseif os(iOS) || os(tvOS)
16 | import UIKit
17 | #endif
18 |
19 | /// `XCPShowView` has been deprecated. Instead, set `XCPlaygroundPage.liveView` to the appropriate value.
20 | #if os(OSX)
21 | @available(*,deprecated,message:"Set 'PlaygroundPage.current.liveView' from the 'PlaygroundSupport' module instead")
22 | public func XCPShowView(identifier: String, view: NSView) {
23 | guard XCPlaygroundPage.currentPage.liveView == nil else { fatalError("Presenting multiple live views is not supported") }
24 | XCPlaygroundPage.currentPage.liveView = view
25 | }
26 | #elseif os(iOS) || os(tvOS)
27 | @available(*,deprecated,message:"Set 'PlaygroundPage.current.liveView' from the 'PlaygroundSupport' module instead")
28 | public func XCPShowView(identifier: String, view: UIView) {
29 | guard XCPlaygroundPage.currentPage.liveView == nil else { fatalError("Presenting multiple live views is not supported") }
30 | XCPlaygroundPage.currentPage.liveView = view
31 | }
32 | #endif
33 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlayground/XCPValueHistory.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | /// This function has been deprecated.
14 | @available(*,deprecated) public func XCPCaptureValue(identifier: String, value: T) {
15 | XCPlaygroundPage.currentPage.captureValue(value: value, withIdentifier: identifier)
16 | }
17 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlayground/XCPlayground-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | ${CURRENT_PROJECT_VERSION}
25 | NSHumanReadableCopyright
26 | Copyright © 2014 Apple Inc. All rights reserved.
27 | NSPrincipalClass
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlaygroundTests/CaptureValueTests.swift:
--------------------------------------------------------------------------------
1 | //===----------------------------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | import XCTest
14 | import XCPlayground
15 |
16 | // This is intentionally redefined here in the tests, as this string cannot change as it has clients which refer to it by the string value rather than by symbol.
17 | let captureValueNotification = Notification.Name(rawValue: "XCPCaptureValue")
18 |
19 | class CaptureValueTests: XCTestCase {
20 |
21 | // MARK: Deprected XCPlaygroundPage
22 |
23 | func testPlaygroundPageCaptureValue() {
24 | let value = 321
25 | let identifier = "My Identifier 101"
26 | expectation(forNotification: captureValueNotification, object: XCPlaygroundPage.currentPage) { (notification) in
27 | guard let userInfoValue = notification.userInfo?["value"] as? Int else { return false }
28 | XCTAssertEqual(userInfoValue, value)
29 |
30 | guard let userInfoIdentifier = notification.userInfo?["identifier"] as? String else { return false }
31 | XCTAssertEqual(userInfoIdentifier, identifier)
32 |
33 | return true
34 | }
35 | XCPlaygroundPage.currentPage.captureValue(value: value, withIdentifier: identifier)
36 | waitForExpectations(timeout: 0.1, handler: nil)
37 | }
38 |
39 | // MARK: Deprecated Functions
40 |
41 | func testLegacyCaptureValue() {
42 | let value = 123
43 | let identifier = "My Identifier"
44 | expectation(forNotification: captureValueNotification, object: XCPlaygroundPage.currentPage) { (notification) in
45 | guard let userInfoValue = notification.userInfo?["value"] as? Int else { return false }
46 | XCTAssertEqual(userInfoValue, value)
47 |
48 | guard let userInfoIdentifier = notification.userInfo?["identifier"] as? String else { return false }
49 | XCTAssertEqual(userInfoIdentifier, identifier)
50 | return true
51 | }
52 | XCPCaptureValue(identifier: identifier, value: value)
53 | waitForExpectations(timeout: 0.1, handler: nil)
54 | }
55 |
56 | func testXCPExecutionShouldContinueIndefinitely() {
57 | XCTAssertEqual(XCPlaygroundPage.currentPage.needsIndefiniteExecution, XCPExecutionShouldContinueIndefinitely())
58 | XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: !XCPlaygroundPage.currentPage.needsIndefiniteExecution)
59 | XCTAssertEqual(XCPlaygroundPage.currentPage.needsIndefiniteExecution, XCPExecutionShouldContinueIndefinitely())
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/PlaygroundSupport/XCPlaygroundTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/XcodeConfig/Common.xcconfig:
--------------------------------------------------------------------------------
1 | //===--- Common.xcconfig --------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #include "Packaging.xcconfig"
14 |
15 | // Enable Clang modules.
16 | CLANG_ENABLE_MODULES = YES
17 |
18 | // Set the macOS, iOS, and tvOS deployment targets to reasonable values.
19 | MACOSX_DEPLOYMENT_TARGET = 10.11
20 | IPHONEOS_DEPLOYMENT_TARGET = 10.0
21 | TVOS_DEPLOYMENT_TARGET = 10.0
22 |
23 | // Prefer to use the default toolchain when building (unless an overriding toolchain has been provided, in which case this build setting override will effectively be ignored).
24 | TOOLCHAINS = default
25 |
--------------------------------------------------------------------------------
/XcodeConfig/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | //===--- Debug.xcconfig ---------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #include "Common.xcconfig"
14 |
15 | // Only build the active architecture when building for Debug.
16 | ONLY_ACTIVE_ARCH = YES
17 |
18 | // Enable testability when building for Debug.
19 | ENABLE_TESTABILITY = YES
20 |
21 | // Compile Swift code at -Onone in Debug.
22 | SWIFT_OPTIMIZATION_LEVEL = -Onone
23 |
24 | // Compile C/Objective-C/C++ code at -O0 in Debug.
25 | GCC_OPTIMIZATION_LEVEL = 0
26 |
--------------------------------------------------------------------------------
/XcodeConfig/Packaging.xcconfig:
--------------------------------------------------------------------------------
1 | //===--- Packaging.xcconfig -----------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2018 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 | //
13 | // This file provides build settings which support packaging the products
14 | // delivered in swift-xcode-playground-support.
15 | //
16 | // Although there's only a single kind of supported package at this time,
17 | // this provides an easy-to-extend mechanism by which other packaging schemes
18 | // can be added.
19 | //
20 | // Packages should provide the following build settings:
21 | //
22 | // - PGS__FRAMEWORKS_DIR_FOR_INSTALL
23 | // - PGS__PRIVATEFRAMEWORKS_DIR_FOR_INSTALL
24 | // - PGS__SHALLOW_FRAMEWORK_RUNPATH_SEARCH_PATHS
25 | // - PGS__VERSIONED_FRAMEWORK_RUNPATH_SEARCH_PATHS
26 | // - PGS__SHALLOW_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS
27 | // - PGS__VERSIONED_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS
28 | //
29 | // Targets may use the following build settings which abstract over the active
30 | // package in their configuration:
31 | //
32 | // - PGS_FRAMEWORKS_DIR_FOR_INSTALL
33 | // - PGS_PRIVATEFRAMEWORKS_DIR_FOR_INSTALL
34 | // - PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS
35 | // - PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS
36 | //
37 | // Targets should **not** use the PGS_PACKAGE build setting directly.
38 | //
39 | //===----------------------------------------------------------------------===//
40 |
41 | // PGS_PACKAGE: The name of the active package. (This is only used in build settings; it is not, by default, exposed anywhere.)
42 | PGS_PACKAGE = XcodeToolchain
43 |
44 | // PGS_FRAMEWORKS_DIR_FOR_INSTALL: The Frameworks directory in the current package into which content may be installed.
45 | PGS_FRAMEWORKS_DIR_FOR_INSTALL = $(PGS_$(PGS_PACKAGE)_FRAMEWORKS_DIR_FOR_INSTALL)
46 |
47 | // PGS_PRIVATEFRAMEWORKS_DIR_FOR_INSTALL: The PrivateFrameworks directory in the current package into which content may be installed.
48 | PGS_PRIVATEFRAMEWORKS_DIR_FOR_INSTALL = $(PGS_$(PGS_PACKAGE)_PRIVATEFRAMEWORKS_DIR_FOR_INSTALL)
49 |
50 | // PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS: The runpath search paths for frameworks installed in the Frameworks directory in the current package.
51 | PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS = $(PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS_$(SHALLOW_BUNDLE))
52 | PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS_YES = $(PGS_$(PGS_PACKAGE)_SHALLOW_FRAMEWORK_RUNPATH_SEARCH_PATHS)
53 | PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS_NO = $(PGS_$(PGS_PACKAGE)_VERSIONED_FRAMEWORK_RUNPATH_SEARCH_PATHS)
54 | PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS_ = $(PGS_FRAMEWORK_RUNPATH_SEARCH_PATHS_NO)
55 |
56 | // PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS: The runpath search paths for frameworks installed in the PrivateFrameworks directory in the current package.
57 | PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS = $(PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS_$(SHALLOW_BUNDLE))
58 | PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS_YES = $(PGS_$(PGS_PACKAGE)_SHALLOW_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS)
59 | PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS_NO = $(PGS_$(PGS_PACKAGE)_VERSIONED_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS)
60 | PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS_ = $(PGS_PRIVATE_FRAMEWORK_RUNPATH_SEARCH_PATHS_NO)
61 |
62 | // Include support for the XcodeToolchain package.
63 | #include "XcodeToolchainPackage.xcconfig"
64 |
--------------------------------------------------------------------------------
/XcodeConfig/Release.xcconfig:
--------------------------------------------------------------------------------
1 | //===--- Release.xcconfig -------------------------------------------------===//
2 | //
3 | // This source file is part of the Swift.org open source project
4 | //
5 | // Copyright (c) 2017 Apple Inc. and the Swift project authors
6 | // Licensed under Apache License v2.0 with Runtime Library Exception
7 | //
8 | // See http://swift.org/LICENSE.txt for license information
9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #include "Common.xcconfig"
14 |
15 | // Compile Swift code at -O with WMO enabled in Release.
16 | SWIFT_OPTIMIZATION_LEVEL = -O
17 | SWIFT_COMPILATION_MODE = wholemodule
18 |
19 | // Compile C/Objective-C/C++ code at -Os in Release.
20 | GCC_OPTIMIZATION_LEVEL = s
21 |
--------------------------------------------------------------------------------
/swift-xcode-playground-support.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/swift-xcode-playground-support.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/swift-xcode-playground-support.xcworkspace/xcshareddata/xcschemes/BuildScript-Test-PlaygroundLogger-macOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
14 |
15 |
17 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
42 |
43 |
49 |
50 |
52 |
53 |
56 |
57 |
58 |
--------------------------------------------------------------------------------