-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathBridgeJSSkeleton.swift
More file actions
103 lines (82 loc) · 2.36 KB
/
BridgeJSSkeleton.swift
File metadata and controls
103 lines (82 loc) · 2.36 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
// This file is shared between BridgeTool and BridgeJSLink
// MARK: - Types
enum BridgeType: Codable, Equatable {
case int, float, double, string, bool, jsObject(String?), swiftHeapObject(String), void
}
enum WasmCoreType: String, Codable {
case i32, i64, f32, f64, pointer
}
struct Parameter: Codable {
let label: String?
let name: String
let type: BridgeType
}
struct Effects: Codable {
var isAsync: Bool
var isThrows: Bool
}
// MARK: - Exported Skeleton
struct ExportedFunction: Codable {
var name: String
var abiName: String
var parameters: [Parameter]
var returnType: BridgeType
var effects: Effects
}
struct ExportedClass: Codable {
var name: String
var constructor: ExportedConstructor?
var methods: [ExportedFunction]
}
struct ExportedConstructor: Codable {
var abiName: String
var parameters: [Parameter]
var effects: Effects
}
struct ExportedSkeleton: Codable {
let functions: [ExportedFunction]
let classes: [ExportedClass]
}
// MARK: - Imported Skeleton
struct ImportedFunctionSkeleton: Codable {
let name: String
let parameters: [Parameter]
let returnType: BridgeType
let documentation: String?
func abiName(context: ImportedTypeSkeleton?) -> String {
return context.map { "bjs_\($0.name)_\(name)" } ?? "bjs_\(name)"
}
}
struct ImportedConstructorSkeleton: Codable {
let parameters: [Parameter]
func abiName(context: ImportedTypeSkeleton) -> String {
return "bjs_\(context.name)_init"
}
}
struct ImportedPropertySkeleton: Codable {
let name: String
let isReadonly: Bool
let type: BridgeType
let documentation: String?
func getterAbiName(context: ImportedTypeSkeleton) -> String {
return "bjs_\(context.name)_\(name)_get"
}
func setterAbiName(context: ImportedTypeSkeleton) -> String {
return "bjs_\(context.name)_\(name)_set"
}
}
struct ImportedTypeSkeleton: Codable {
let name: String
let constructor: ImportedConstructorSkeleton?
let methods: [ImportedFunctionSkeleton]
let properties: [ImportedPropertySkeleton]
let documentation: String?
}
struct ImportedFileSkeleton: Codable {
let functions: [ImportedFunctionSkeleton]
let types: [ImportedTypeSkeleton]
}
struct ImportedModuleSkeleton: Codable {
let moduleName: String
var children: [ImportedFileSkeleton]
}