1
1
import SwiftSemantics
2
2
3
- public protocol API : Declaration {
4
- var attributes : [ Attribute ] { get }
5
- var keyword : String { get }
6
- var context : String ? { get }
7
- var name : String { get }
8
- var isPublic : Bool { get }
3
+ public protocol Generic {
4
+ var genericParameters : [ GenericParameter ] { get }
5
+ var genericRequirements : [ GenericRequirement ] { get }
9
6
}
10
7
11
- extension API {
12
- public var qualifiedName : String {
13
- guard let context = context else { return name }
14
- return " \( context) . \( name) "
15
- }
16
-
17
- public func hash( into hasher: inout Hasher ) {
18
- switch self {
19
- case let api as AssociatedType :
20
- hasher. combine ( api)
21
- case let api as Class :
22
- hasher. combine ( api)
23
- case let api as Enumeration :
24
- hasher. combine ( api)
25
- case let api as Enumeration . Case :
26
- hasher. combine ( api)
27
- case let api as Function :
28
- hasher. combine ( api)
29
- case let api as Initializer :
30
- hasher. combine ( api)
31
- case let api as Operator :
32
- hasher. combine ( api)
33
- case let api as PrecedenceGroup :
34
- hasher. combine ( api)
35
- case let api as Protocol :
36
- hasher. combine ( api)
37
- case let api as Structure :
38
- hasher. combine ( api)
39
- case let api as Subscript :
40
- hasher. combine ( api)
41
- case let api as Typealias :
42
- hasher. combine ( api)
43
- case let api as Variable :
44
- hasher. combine ( api)
45
- default :
46
- assertionFailure ( " unhandled type: \( self ) " )
47
- return
48
- }
49
- }
50
- }
51
-
52
- public func == ( lhs: API , rhs: API ) -> Bool {
53
- switch ( lhs, rhs) {
54
- case let ( lhs, rhs) as ( AssociatedType , AssociatedType ) :
55
- return lhs == rhs
56
- case let ( lhs, rhs) as ( Class , Class ) :
57
- return lhs == rhs
58
- case let ( lhs, rhs) as ( Enumeration , Enumeration ) :
59
- return lhs == rhs
60
- case let ( lhs, rhs) as ( Enumeration . Case , Enumeration . Case ) :
61
- return lhs == rhs
62
- case let ( lhs, rhs) as ( Function , Function ) :
63
- return lhs == rhs
64
- case let ( lhs, rhs) as ( Initializer , Initializer ) :
65
- return lhs == rhs
66
- case let ( lhs, rhs) as ( Operator , Operator ) :
67
- return lhs == rhs
68
- case let ( lhs, rhs) as ( PrecedenceGroup , PrecedenceGroup ) :
69
- return lhs == rhs
70
- case let ( lhs, rhs) as ( Protocol , Protocol ) :
71
- return lhs == rhs
72
- case let ( lhs, rhs) as ( Structure , Structure ) :
73
- return lhs == rhs
74
- case let ( lhs, rhs) as ( Subscript , Subscript ) :
75
- return lhs == rhs
76
- case let ( lhs, rhs) as ( Typealias , Typealias ) :
77
- return lhs == rhs
78
- case let ( lhs, rhs) as ( Variable , Variable ) :
79
- return lhs == rhs
80
- default :
81
- return false
82
- }
83
- }
84
-
85
- extension AssociatedType : API { }
86
-
87
- extension Class : API { }
88
-
89
- extension Enumeration : API { }
90
-
91
- extension Enumeration . Case : API {
92
- public var isPublic : Bool { return true }
93
- }
94
-
95
- extension Function : API {
96
- public var name : String {
97
- " \( identifier) ( \( signature. input. map { ( $0. firstName ?? " _ " ) + " : " } . joined ( ) ) ) "
98
- }
99
- }
100
-
101
- extension Initializer : API {
102
- public var name : String {
103
- " \( keyword) \( optional ? " ? " : " " ) ( \( parameters. map { ( $0. firstName ?? " _ " ) + " : " } . joined ( ) ) ) "
104
- }
105
- }
106
-
107
- extension Operator : API {
108
- public var isPublic : Bool { return true }
109
- }
110
-
111
- extension PrecedenceGroup : API {
112
- public var context : String ? { return nil }
113
- }
114
-
115
- extension Protocol : API {
116
- public var context : String ? { return nil }
117
- }
118
-
119
- extension Structure : API { }
120
-
121
- extension Subscript : API {
122
- public var name : String {
123
- " \( keyword) ( \( indices. map { ( $0. firstName ?? " _ " ) + " : " } . joined ( ) ) ) "
124
- }
125
- }
126
-
127
- extension Typealias : API { }
128
-
129
- extension Variable : API { }
130
-
131
- // MARK: -
132
-
133
- public protocol Modifiable : Declaration {
134
- var modifiers : [ Modifier ] { get }
135
- }
136
-
137
- extension AssociatedType : Modifiable { }
138
- extension Class : Modifiable { }
139
- extension Enumeration : Modifiable { }
140
- extension Extension : Modifiable { }
141
- extension Function : Modifiable { }
142
- extension Initializer : Modifiable { }
143
- extension PrecedenceGroup : Modifiable { }
144
- extension Protocol : Modifiable { }
145
- extension Structure : Modifiable { }
146
- extension Subscript : Modifiable { }
147
- extension Typealias : Modifiable { }
148
- extension Variable : Modifiable { }
149
-
150
- extension Modifiable {
151
- public var isPublic : Bool {
152
- return modifiers. contains { $0. name == " public " || $0. name == " open " }
153
- }
154
- }
8
+ extension Class : Generic { }
9
+ extension Enumeration : Generic { }
10
+ extension Function : Generic { }
11
+ extension Initializer : Generic { }
12
+ extension Structure : Generic { }
13
+ extension Subscript : Generic { }
14
+ extension Typealias : Generic { }
155
15
156
16
// MARK: -
157
17
@@ -164,3 +24,6 @@ extension Class: Type {}
164
24
extension Enumeration : Type { }
165
25
extension Protocol : Type { }
166
26
extension Structure : Type { }
27
+ extension Unknown : Type {
28
+ public var inheritance : [ String ] { return [ ] }
29
+ }
0 commit comments