Skip to content

Commit ab0a161

Browse files
authored
Merge pull request #401 from tayloraswift/custom-conditions
implement a way to pass custom defines from SSGC.CompileCommand down to SSGC.Linker.Tables
2 parents 9765cfd + 4c1040a commit ab0a161

33 files changed

+664
-197
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let package:Package = .init(
9595
.package(url: "https://github.com/tayloraswift/swift-png", .upToNextMinor(
9696
from: "4.4.9")),
9797
.package(url: "https://github.com/tayloraswift/swift-ucf", .upToNextMinor(
98-
from: "0.1.0")),
98+
from: "0.2.0")),
9999
.package(url: "https://github.com/tayloraswift/swift-unixtime", .upToNextMinor(
100100
from: "0.2.0")),
101101

Sources/LinkResolution/Codelinks/UCF.ConditionFilter (ext).swift

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import UCF
2+
3+
extension UCF
4+
{
5+
@frozen @usableFromInline
6+
enum ConditionError:Error
7+
{
8+
case value(Condition, String)
9+
case valueExpected(Condition)
10+
}
11+
}
12+
extension UCF.ConditionError:CustomStringConvertible
13+
{
14+
@usableFromInline
15+
var description:String
16+
{
17+
switch self
18+
{
19+
case .value(let condition, let value):
20+
"value '\(value)' is invalid for condition '\(condition)'"
21+
case .valueExpected(let condition):
22+
"value expected for condition '\(condition)'"
23+
}
24+
}
25+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import UCF
2+
3+
extension UCF.ConditionFilter
4+
{
5+
@inlinable public
6+
func value<T>(as _:T.Type = T.self) throws -> T where T:LosslessStringConvertible
7+
{
8+
guard
9+
let value:String = self.value
10+
else
11+
{
12+
throw UCF.ConditionError.valueExpected(self.label)
13+
}
14+
15+
guard
16+
let result:T = .init(value)
17+
else
18+
{
19+
throw UCF.ConditionError.value(self.label, value)
20+
}
21+
22+
return result
23+
}
24+
25+
func callAsFunction<T>(as _:T.Type = T.self,
26+
default:T) throws -> (UCF.Condition, T) where T:LosslessStringConvertible
27+
{
28+
guard
29+
let value:String = self.value
30+
else
31+
{
32+
return (self.label, `default`)
33+
}
34+
35+
guard
36+
let result:T = .init(value)
37+
else
38+
{
39+
throw UCF.ConditionError.value(self.label, value)
40+
}
41+
42+
return (self.label, result)
43+
}
44+
}

Sources/LinkResolution/UCF.DisambiguationTraits.swift

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -14,111 +14,22 @@ extension UCF
1414
public
1515
let kinks:Phylum.Decl.Kinks
1616
public
17+
let async:Bool
18+
public
1719
let hash:FNV24
1820

1921
@inlinable public
2022
init(autograph:Autograph?,
2123
phylum:Phylum.Decl,
2224
kinks:Phylum.Decl.Kinks,
25+
async:Bool,
2326
hash:FNV24)
2427
{
2528
self.autograph = autograph
2629
self.phylum = phylum
2730
self.kinks = kinks
31+
self.async = async
2832
self.hash = hash
2933
}
3034
}
3135
}
32-
extension UCF.DisambiguationTraits
33-
{
34-
static func ~= (predicate:UCF.Predicate, self:Self) -> Bool
35-
{
36-
if case nil = predicate.seal
37-
{
38-
// Macros are currently the only kind of declaration that *must* be spelled with
39-
// trailing parentheses.
40-
switch self.phylum
41-
{
42-
case .actor: break
43-
case .associatedtype: break
44-
case .case: break
45-
case .class: break
46-
case .deinitializer: break
47-
case .enum: break
48-
case .func: break
49-
case .initializer: break
50-
case .macro: return false
51-
case .operator: break
52-
case .protocol: break
53-
case .struct: break
54-
case .subscript: break
55-
case .typealias: break
56-
case .var: break
57-
}
58-
}
59-
else
60-
{
61-
switch self.phylum
62-
{
63-
case .actor: return false
64-
case .associatedtype: return false
65-
case .case: break
66-
case .class: return false
67-
case .deinitializer: return false
68-
case .enum: return false
69-
case .func: break
70-
case .initializer: break
71-
case .macro: break
72-
case .operator: break
73-
case .protocol: return false
74-
case .struct: return false
75-
case .subscript: break
76-
case .typealias: return false
77-
case .var: return false
78-
}
79-
}
80-
81-
guard
82-
let suffix:UCF.Selector.Suffix = predicate.suffix
83-
else
84-
{
85-
return true
86-
}
87-
88-
switch suffix
89-
{
90-
case .unidoc(let filter):
91-
if let signature:UCF.SignatureFilter = filter.signature
92-
{
93-
// If a signature filter is present, the declaration must have an autograph.
94-
guard
95-
let autograph:UCF.Autograph = self.autograph, signature ~= autograph
96-
else
97-
{
98-
return false
99-
}
100-
}
101-
102-
let decl:(Phylum.Decl, Phylum.Decl.Kinks) = (self.phylum, self.kinks)
103-
for condition:UCF.ConditionFilter in filter.conditions
104-
{
105-
guard condition ~= decl
106-
else
107-
{
108-
return false
109-
}
110-
}
111-
112-
return true
113-
114-
case .legacy(let filter, nil):
115-
return filter ~= self.phylum
116-
117-
case .legacy(_, let hash?):
118-
return hash == self.hash
119-
120-
case .hash(let hash):
121-
return hash == self.hash
122-
}
123-
}
124-
}

0 commit comments

Comments
 (0)