|
| 1 | +//===--- LegacyEntrypoints.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 | +/* |
| 14 | + LLDB contains references to the following functions: |
| 15 | + |
| 16 | + @_silgen_name ("playground_logger_initialize") func $builtin_logger_initialize() -> Void |
| 17 | + @_silgen_name ("playground_log_hidden") func $builtin_log_with_id<T>(_ object : T, _ name : String, _ id : Int, _ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject |
| 18 | + @_silgen_name ("playground_log_scope_entry") func $builtin_log_scope_entry(_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject |
| 19 | + @_silgen_name ("playground_log_scope_exit") func $builtin_log_scope_exit(_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject |
| 20 | + @_silgen_name ("playground_log_postprint") func $builtin_postPrint(_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject |
| 21 | + |
| 22 | + where the `AnyObject` returned by each function is actually an `NSData` instance. |
| 23 | + |
| 24 | + To maintain compatibility with current and previous LLDB, we need to export these functions as well. |
| 25 | + */ |
| 26 | + |
| 27 | +@_silgen_name("playground_logger_initialize") |
| 28 | +@available(*, deprecated, message: "Use modern PlaygroundLogger initialization instead") |
| 29 | +public func legacyInitializePlaygroundLogger() -> Void { |
| 30 | + Swift._playgroundPrintHook = printHook |
| 31 | + sendData = legacySendDataStub |
| 32 | +} |
| 33 | + |
| 34 | +fileprivate func legacySendDataStub(_: NSData) -> Void { |
| 35 | + fatalError("A legacy-initialized PlaygroundLogger should not use the sendData function pointer!") |
| 36 | +} |
| 37 | + |
| 38 | +@_silgen_name("playground_log_hidden") |
| 39 | +@available(*, deprecated, message: "Use modern PlaygroundLogger log function instead") |
| 40 | +public func legacyLog<T>(instance: T, name: String, id: Int, startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject { |
| 41 | + let packet = LogPacket(describingResult: instance, named: name, startLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn) |
| 42 | + |
| 43 | + let data = packet.encode() |
| 44 | + |
| 45 | + return data as NSData |
| 46 | +} |
| 47 | + |
| 48 | +@_silgen_name ("playground_log_scope_entry") |
| 49 | +@available(*, deprecated, message: "Use modern PlaygroundLogger log scope entry function instead") |
| 50 | +public func legacyLogScopeEntry(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject { |
| 51 | + let packet = LogPacket(scopeEntryWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn) |
| 52 | + |
| 53 | + let data = packet.encode() |
| 54 | + |
| 55 | + return data as NSData |
| 56 | +} |
| 57 | + |
| 58 | +@_silgen_name ("playground_log_scope_exit") |
| 59 | +@available(*, deprecated, message: "Use modern PlaygroundLogger log scope exit function instead") |
| 60 | +public func legacyLogScopeExit(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject { |
| 61 | + let packet = LogPacket(scopeExitWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn) |
| 62 | + |
| 63 | + let data = packet.encode() |
| 64 | + |
| 65 | + return data as NSData |
| 66 | +} |
| 67 | + |
| 68 | +@_silgen_name ("playground_log_postprint") |
| 69 | +@available(*, deprecated, message: "Use modern PlaygroundLogger postprint function instead") |
| 70 | +func legacyLogPostPrint(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject { |
| 71 | + let printedString = Thread.current.threadDictionary[printedStringThreadDictionaryKey] as! String? ?? "" |
| 72 | + |
| 73 | + Thread.current.threadDictionary.removeObject(forKey: printedStringThreadDictionaryKey) |
| 74 | + |
| 75 | + let packet = LogPacket(printedString: printedString, startLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn) |
| 76 | + |
| 77 | + let data = packet.encode() |
| 78 | + |
| 79 | + return data as NSData |
| 80 | +} |
0 commit comments