-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a mechanism for pregenerated types in WindowsRuntime.
Add basic support for sequences.
- Loading branch information
1 parent
dd5548e
commit a5af8f7
Showing
31 changed files
with
708 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Generator/Sources/CodeWriters/Swift/SyntaxWriters/SwiftImportKind.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public enum SwiftImportKind: Hashable { | ||
case `typealias` | ||
case `struct` | ||
case `class` | ||
case `enum` | ||
case `protocol` | ||
case `let` | ||
case `var` | ||
case `func` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Generator/Sources/SwiftWinRT/Writing/InterfaceExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import CodeWriters | ||
import DotNetMetadata | ||
import WindowsMetadata | ||
import ProjectionModel | ||
|
||
internal func writeInterfaceExtensions(_ interface: InterfaceDefinition, projection: SwiftProjection, to writer: SwiftSourceFileWriter) throws { | ||
switch interface.namespace { | ||
case "Windows.Foundation": | ||
let typeName = try projection.toProtocolName(interface) | ||
switch interface.name { | ||
case "IAsyncAction", "IAsyncActionWithProgress`1": | ||
try writeIAsyncExtensions(protocolName: typeName, resultType: nil, to: writer) | ||
case "IAsyncOperation`1", "IAsyncOperationWithProgress`2": | ||
try writeIAsyncExtensions( | ||
protocolName: typeName, | ||
resultType: .identifier(name: String(interface.genericParams[0].name)), | ||
to: writer) | ||
default: break | ||
} | ||
default: break | ||
} | ||
} | ||
|
||
internal func writeIAsyncExtensions(protocolName: String, resultType: SwiftType?, to writer: SwiftSourceFileWriter) throws { | ||
writer.writeExtension(type: .identifier(protocolName)) { writer in | ||
// public get() async throws | ||
writer.writeFunc(visibility: .public, name: "get", async: true, throws: true, returnType: resultType) { writer in | ||
writer.output.writeIndentedBlock(header: "if try _status() == .started {", footer: "}") { | ||
// We can't await if the completed handler is already set | ||
writer.writeStatement("guard try \(SupportModules.COM.nullResult).catch(_completed()) == nil else { throw \(SupportModules.COM.hresult).Error.illegalMethodCall }") | ||
writer.writeStatement("let awaiter = WindowsRuntime.AsyncAwaiter()") | ||
writer.writeStatement("try _completed({ _, _ in _Concurrency.Task { await awaiter.signal() } })") | ||
writer.writeStatement("await awaiter.wait()") | ||
} | ||
|
||
// Handles exceptions and cancelation | ||
writer.writeStatement("return try getResults()") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.