Skip to content

Commit eaa856d

Browse files
authored
ASTGen: adjust for type changes
The type definitions do not uniformly import as `Swift.Int` and `Swift.UInt`. Add some casts to accommodate the type conversions.
1 parent 4553385 commit eaa856d

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

lib/ASTGen/Sources/ASTGen/ASTGen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CASTBridging
2+
import CBasicBridging
23
import SwiftParser
34

45
// Needed to use SyntaxTransformVisitor's visit method.
@@ -8,7 +9,7 @@ import SwiftSyntax
89
extension Array {
910
public func withBridgedArrayRef<T>(_ c: (BridgedArrayRef) -> T) -> T {
1011
withUnsafeBytes { buf in
11-
c(BridgedArrayRef(data: buf.baseAddress!, numElements: count))
12+
c(BridgedArrayRef(data: buf.baseAddress!, numElements: SwiftInt(count)))
1213
}
1314
}
1415
}

lib/ASTGen/Sources/ASTGen/Generics.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CASTBridging
2+
import CBasicBridging
23
import SwiftParser
34

45
// Needed to use SyntaxTransformVisitor's visit method.
@@ -37,7 +38,7 @@ extension ASTGenVisitor {
3738

3839
return .decl(
3940
GenericTypeParamDecl_create(
40-
self.ctx, self.declContext, name, nameLoc, eachLoc, genericParameterIndex,
41+
self.ctx, self.declContext, name, nameLoc, eachLoc, SwiftInt(genericParameterIndex),
4142
eachLoc.raw != nil))
4243
}
4344
}

lib/ASTGen/Sources/ASTGen/Macros.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func checkMacroDefinition(
281281
if module == "Builtin" {
282282
switch type {
283283
case "ExternalMacro":
284-
return BridgedMacroDefinitionKind.builtinExternalMacro.rawValue
284+
return Int(BridgedMacroDefinitionKind.builtinExternalMacro.rawValue)
285285

286286
default:
287287
// Warn about the unknown builtin.
@@ -326,7 +326,7 @@ func checkMacroDefinition(
326326
]
327327
)
328328
)
329-
return BridgedMacroDefinitionKind.externalMacro.rawValue
329+
return Int(BridgedMacroDefinitionKind.externalMacro.rawValue)
330330

331331
case let .expansion(expansionSyntax, replacements: _)
332332
where expansionSyntax.macroName.text == "externalMacro":
@@ -365,7 +365,7 @@ func checkMacroDefinition(
365365
// Form the "ModuleName.TypeName" result string.
366366
(externalMacroPointer.pointee, externalMacroLength.pointee) =
367367
allocateUTF8String("\(module).\(type)", nullTerminated: true)
368-
return BridgedMacroDefinitionKind.externalMacro.rawValue
368+
return Int(BridgedMacroDefinitionKind.externalMacro.rawValue)
369369

370370
case let .expansion(expansionSyntax, replacements: replacements):
371371
// Provide the expansion syntax.
@@ -376,7 +376,7 @@ func checkMacroDefinition(
376376

377377
// If there are no replacements, we're done.
378378
if replacements.isEmpty {
379-
return BridgedMacroDefinitionKind.expandedMacro.rawValue
379+
return Int(BridgedMacroDefinitionKind.expandedMacro.rawValue)
380380
}
381381

382382
// The replacements are triples: (startOffset, endOffset, parameter index).
@@ -391,7 +391,7 @@ func checkMacroDefinition(
391391

392392
replacementsPtr.pointee = replacementBuffer.baseAddress
393393
numReplacementsPtr.pointee = replacements.count
394-
return BridgedMacroDefinitionKind.expandedMacro.rawValue
394+
return Int(BridgedMacroDefinitionKind.expandedMacro.rawValue)
395395
}
396396
} catch let errDiags as DiagnosticsError {
397397
let srcMgr = SourceManager(cxxDiagnosticEngine: diagEnginePtr)

lib/ASTGen/Sources/ASTGen/Misc.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CASTBridging
2+
import CBasicBridging
23
import SwiftParser
34

45
// Needed to use SyntaxTransformVisitor's visit method.
@@ -65,7 +66,7 @@ extension BridgedSourceLoc {
6566
) {
6667
if let start = buffer.baseAddress,
6768
position.utf8Offset >= 0 && position.utf8Offset < buffer.count {
68-
self = SourceLoc_advanced(BridgedSourceLoc(raw: start), position.utf8Offset)
69+
self = SourceLoc_advanced(BridgedSourceLoc(raw: start), SwiftInt(position.utf8Offset))
6970
} else {
7071
self = nil
7172
}
@@ -75,7 +76,7 @@ extension BridgedSourceLoc {
7576
extension String {
7677
mutating func withBridgedString<R>(_ body: (BridgedString) throws -> R) rethrows -> R {
7778
try withUTF8 { buffer in
78-
try body(BridgedString(data: buffer.baseAddress, length: buffer.count))
79+
try body(BridgedString(data: buffer.baseAddress, length: SwiftInt(buffer.count)))
7980
}
8081
}
8182
}

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct CompilerPlugin {
121121

122122
private func sendMessage(_ message: HostToPluginMessage) throws {
123123
let hadError = try LLVMJSON.encoding(message) { (data) -> Bool in
124-
return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, size: UInt(data.count)))
124+
return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, size: SwiftUInt(data.count)))
125125
}
126126
if hadError {
127127
throw PluginError.failedToSendMessage
@@ -339,7 +339,7 @@ class PluginDiagnosticsEngine {
339339
guard let bufferBaseAddress = exportedSourceFile.pointee.buffer.baseAddress else {
340340
return nil
341341
}
342-
return SourceLoc_advanced(BridgedSourceLoc(raw: bufferBaseAddress), offset)
342+
return SourceLoc_advanced(BridgedSourceLoc(raw: bufferBaseAddress), SwiftInt(offset))
343343
}
344344

345345
/// C++ source location from a position value from a plugin.

0 commit comments

Comments
 (0)