forked from swiftlang/swift-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwiftKnownModules.swift
More file actions
122 lines (103 loc) · 3.93 KB
/
SwiftKnownModules.swift
File metadata and controls
122 lines (103 loc) · 3.93 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import SwiftSyntax
import SwiftSyntaxBuilder
enum SwiftKnownModule: String {
case swift = "Swift"
case foundation = "Foundation"
case foundationEssentials = "FoundationEssentials"
var name: String {
return self.rawValue
}
var symbolTable: SwiftModuleSymbolTable {
return switch self {
case .swift: swiftSymbolTable
case .foundation: foundationSymbolTable
case .foundationEssentials: foundationEssentialsSymbolTable
}
}
var sourceFile: SourceFileSyntax {
return switch self {
case .swift: swiftSourceFile
case .foundation: foundationSourceFile
case .foundationEssentials: foundationEssentialsSourceFile
}
}
}
private var swiftSymbolTable: SwiftModuleSymbolTable {
var builder = SwiftParsedModuleSymbolTableBuilder(moduleName: "Swift", importedModules: [:])
builder.handle(sourceFile: swiftSourceFile, sourceFilePath: "SwiftStdlib.swift") // FIXME: missing path here
return builder.finalize()
}
private var foundationEssentialsSymbolTable: SwiftModuleSymbolTable {
var builder = SwiftParsedModuleSymbolTableBuilder(
moduleName: "FoundationEssentials",
requiredAvailablityOfModuleWithName: "FoundationEssentials",
alternativeModules: .init(isMainSourceOfSymbols: false, moduleNames: ["Foundation"]),
importedModules: ["Swift": swiftSymbolTable])
builder.handle(sourceFile: foundationEssentialsSourceFile, sourceFilePath: "FakeFoundation.swift")
return builder.finalize()
}
private var foundationSymbolTable: SwiftModuleSymbolTable {
var builder = SwiftParsedModuleSymbolTableBuilder(
moduleName: "Foundation",
alternativeModules: .init(isMainSourceOfSymbols: true, moduleNames: ["FoundationEssentials"]),
importedModules: ["Swift": swiftSymbolTable])
builder.handle(sourceFile: foundationSourceFile, sourceFilePath: "Foundation.swift")
return builder.finalize()
}
private let swiftSourceFile: SourceFileSyntax = """
public struct Bool {}
public struct Int {}
public struct UInt {}
public struct Int8 {}
public struct UInt8 {}
public struct Int16 {}
public struct UInt16 {}
public struct Int32 {}
public struct UInt32 {}
public struct Int64 {}
public struct UInt64 {}
public struct Float {}
public struct Double {}
public struct UnsafeRawPointer {}
public struct UnsafeMutableRawPointer {}
public struct UnsafeRawBufferPointer {}
public struct UnsafeMutableRawBufferPointer {}
public struct UnsafePointer<Pointee> {}
public struct UnsafeMutablePointer<Pointee> {}
public struct UnsafeBufferPointer<Element> {}
public struct UnsafeMutableBufferPointer<Element> {}
public struct Optional<Wrapped> {}
public struct Array<Element> {}
// FIXME: Support 'typealias Void = ()'
public struct Void {}
public struct String {
public init(cString: UnsafePointer<Int8>)
public func withCString(_ body: (UnsafePointer<Int8>) -> Void)
}
"""
private let foundationEssentialsSourceFile: SourceFileSyntax = """
public protocol DataProtocol {}
public struct Data: DataProtocol {
public init(bytes: UnsafeRawPointer, count: Int)
public var count: Int { get }
public func withUnsafeBytes(_ body: (UnsafeRawBufferPointer) -> Void)
}
"""
private var foundationSourceFile: SourceFileSyntax {
// On platforms other than Darwin, imports such as FoundationEssentials, FoundationNetworking, etc. are used,
// so this file should be created by combining the files of the aforementioned modules.
foundationEssentialsSourceFile
}