|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift.org project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of Swift.org project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import SwiftSyntax |
| 16 | +import SwiftSyntaxBuilder |
| 17 | + |
| 18 | +enum SwiftKnownModule: String { |
| 19 | + case swift = "Swift" |
| 20 | + case foundation = "Foundation" |
| 21 | + |
| 22 | + var name: String { |
| 23 | + return self.rawValue |
| 24 | + } |
| 25 | + |
| 26 | + var symbolTable: SwiftModuleSymbolTable { |
| 27 | + return switch self { |
| 28 | + case .swift: swiftSymbolTable |
| 29 | + case .foundation: foundationSymbolTable |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + var sourceFile: SourceFileSyntax { |
| 34 | + return switch self { |
| 35 | + case .swift: swiftSourceFile |
| 36 | + case .foundation: foundationSourceFile |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +private var swiftSymbolTable: SwiftModuleSymbolTable { |
| 42 | + var builder = SwiftParsedModuleSymbolTableBuilder(moduleName: "Swift", importedModules: [:]) |
| 43 | + builder.handle(sourceFile: swiftSourceFile) |
| 44 | + return builder.finalize() |
| 45 | +} |
| 46 | + |
| 47 | +private var foundationSymbolTable: SwiftModuleSymbolTable { |
| 48 | + var builder = SwiftParsedModuleSymbolTableBuilder(moduleName: "Foundation", importedModules: ["Swift": swiftSymbolTable]) |
| 49 | + builder.handle(sourceFile: foundationSourceFile) |
| 50 | + return builder.finalize() |
| 51 | +} |
| 52 | + |
| 53 | +private let swiftSourceFile: SourceFileSyntax = """ |
| 54 | + public struct Bool {} |
| 55 | + public struct Int {} |
| 56 | + public struct UInt {} |
| 57 | + public struct Int8 {} |
| 58 | + public struct UInt8 {} |
| 59 | + public struct Int16 {} |
| 60 | + public struct UInt16 {} |
| 61 | + public struct Int32 {} |
| 62 | + public struct UInt32 {} |
| 63 | + public struct Int64 {} |
| 64 | + public struct UInt64 {} |
| 65 | + public struct Float {} |
| 66 | + public struct Double {} |
| 67 | + |
| 68 | + public struct UnsafeRawPointer {} |
| 69 | + public struct UnsafeMutableRawPointer {} |
| 70 | + public struct UnsafeRawBufferPointer {} |
| 71 | + public struct UnsafeMutableRawBufferPointer {} |
| 72 | +
|
| 73 | + public struct UnsafePointer<Pointee> {} |
| 74 | + public struct UnsafeMutablePointer<Pointee> {} |
| 75 | +
|
| 76 | + public struct UnsafeBufferPointer<Element> {} |
| 77 | + public struct UnsafeMutableBufferPointer<Element> {} |
| 78 | + |
| 79 | + public struct Void {} // FIXME: Support 'typealias Void = ()' |
| 80 | + |
| 81 | + public struct String { |
| 82 | + public init(cString: UnsafePointer<Int8>) |
| 83 | + public func withCString(body: (UnsafePointer<Int8>) -> Void) |
| 84 | + } |
| 85 | + """ |
| 86 | + |
| 87 | +private let foundationSourceFile: SourceFileSyntax = """ |
| 88 | + public struct Data { |
| 89 | + public init(bytes: UnsafeRawPointer, count: Int) |
| 90 | + public func withUnsafeBytes(body: (UnsafeRawBufferPointer) -> Void) |
| 91 | + } |
| 92 | + """ |
0 commit comments