Skip to content

Commit 66b3ca4

Browse files
committed
[ASTGen] Use SWIFT_NAME in some more places
1 parent 395ac55 commit 66b3ca4

File tree

6 files changed

+49
-39
lines changed

6 files changed

+49
-39
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,26 +291,32 @@ extern "C" {
291291
///
292292
/// \returns a diagnostic instance that can be extended with additional
293293
/// information and then must be finished via \c SwiftDiagnostic_finish.
294-
BridgedDiagnostic Diagnostic_create(BridgedDiagnosticEngine cDiags,
294+
SWIFT_NAME("BridgedDiagnostic.init(at:message:severity:engine:)")
295+
BridgedDiagnostic Diagnostic_create(BridgedSourceLoc cLoc, BridgedString cText,
295296
BridgedDiagnosticSeverity severity,
296-
BridgedSourceLoc cLoc, BridgedString cText);
297+
BridgedDiagnosticEngine cDiags);
297298

298299
/// Highlight a source range as part of the diagnostic.
300+
SWIFT_NAME("BridgedDiagnostic.highlight(self:start:end:)")
299301
void Diagnostic_highlight(BridgedDiagnostic cDiag, BridgedSourceLoc cStartLoc,
300302
BridgedSourceLoc cEndLoc);
301303

302304
/// Add a Fix-It to replace a source range as part of the diagnostic.
305+
SWIFT_NAME("BridgedDiagnostic.fixItReplace(self:start:end:replacement:)")
303306
void Diagnostic_fixItReplace(BridgedDiagnostic cDiag,
304307
BridgedSourceLoc cStartLoc,
305308
BridgedSourceLoc cEndLoc,
306309
BridgedString cReplaceText);
307310

308311
/// Finish the given diagnostic and emit it.
312+
SWIFT_NAME("BridgedDiagnostic.finish(self:)")
309313
void Diagnostic_finish(BridgedDiagnostic cDiag);
310314

315+
SWIFT_NAME("BridgedASTContext.getIdentifier(self:_:)")
311316
BridgedIdentifier ASTContext_getIdentifier(BridgedASTContext cContext,
312317
BridgedString cStr);
313318

319+
SWIFT_NAME("BridgedASTContext.langOptsHasFeature(self:_:)")
314320
_Bool ASTContext_langOptsHasFeature(BridgedASTContext cContext,
315321
BridgedFeature feature);
316322

@@ -339,6 +345,7 @@ SWIFT_NAME("BridgedSequenceExpr.createParsed(_:exprs:)")
339345
BridgedSequenceExpr SequenceExpr_createParsed(BridgedASTContext cContext,
340346
BridgedArrayRef exprs);
341347

348+
SWIFT_NAME("BridgedSourceLoc.advanced(self:by:)")
342349
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, size_t len);
343350

344351
SWIFT_NAME("BridgedTupleExpr.createParsed(_:leftParenLoc:exprs:labels:"

lib/AST/CASTBridging.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,9 @@ static TypeAttrKind convertTypeAttrKind(BridgedTypeAttrKind kind) {
167167
}
168168
}
169169

170-
BridgedDiagnostic Diagnostic_create(BridgedDiagnosticEngine cDiags,
170+
BridgedDiagnostic Diagnostic_create(BridgedSourceLoc cLoc, BridgedString cText,
171171
BridgedDiagnosticSeverity severity,
172-
BridgedSourceLoc cLoc,
173-
BridgedString cText) {
172+
BridgedDiagnosticEngine cDiags) {
174173
StringRef origText = convertString(cText);
175174
BridgedDiagnosticImpl::Allocator alloc;
176175
StringRef text = origText.copy(alloc);

lib/ASTGen/Sources/ASTGen/Bridge.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension BridgedSourceLoc {
2121
in buffer: UnsafeBufferPointer<UInt8>
2222
) {
2323
precondition(position.utf8Offset >= 0 && position.utf8Offset <= buffer.count)
24-
self = SourceLoc_advanced(BridgedSourceLoc(raw: buffer.baseAddress!), position.utf8Offset)
24+
self = BridgedSourceLoc(raw: buffer.baseAddress!).advanced(by: position.utf8Offset)
2525
}
2626
}
2727

@@ -103,7 +103,7 @@ extension TokenSyntax {
103103
func bridgedIdentifier(in astgen: ASTGenVisitor) -> BridgedIdentifier {
104104
var text = self.text
105105
return text.withBridgedString { bridged in
106-
ASTContext_getIdentifier(astgen.ctx, bridged)
106+
astgen.ctx.getIdentifier(bridged)
107107
}
108108
}
109109

lib/ASTGen/Sources/ASTGen/DiagnosticsBridge.swift

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ fileprivate func emitDiagnosticParts(
2121
// Emit the diagnostic
2222
var mutableMessage = message
2323
let diag = mutableMessage.withBridgedString { bridgedMessage in
24-
Diagnostic_create(
25-
diagnosticEngine, bridgedSeverity, bridgedSourceLoc(at: position),
26-
bridgedMessage
24+
BridgedDiagnostic(
25+
at: bridgedSourceLoc(at: position),
26+
message: bridgedMessage,
27+
severity: bridgedSeverity,
28+
engine: diagnosticEngine
2729
)
2830
}
2931

3032
// Emit highlights
3133
for highlight in highlights {
32-
Diagnostic_highlight(
33-
diag, bridgedSourceLoc(at: highlight.positionAfterSkippingLeadingTrivia),
34-
bridgedSourceLoc(at: highlight.endPositionBeforeTrailingTrivia)
34+
diag.highlight(
35+
start: bridgedSourceLoc(at: highlight.positionAfterSkippingLeadingTrivia),
36+
end: bridgedSourceLoc(at: highlight.endPositionBeforeTrailingTrivia)
3537
)
3638
}
3739

@@ -60,14 +62,14 @@ fileprivate func emitDiagnosticParts(
6062
}
6163

6264
newText.withBridgedString { bridgedMessage in
63-
Diagnostic_fixItReplace(
64-
diag, replaceStartLoc, replaceEndLoc,
65-
bridgedMessage
65+
diag.fixItReplace(
66+
start: replaceStartLoc, end: replaceEndLoc,
67+
replacement: bridgedMessage
6668
)
6769
}
6870
}
6971

70-
Diagnostic_finish(diag);
72+
diag.finish();
7173
}
7274

7375
/// Emit the given diagnostic via the diagnostic engine.
@@ -139,19 +141,19 @@ extension SourceManager {
139141
// Emit the diagnostic
140142
var mutableMessage = message
141143
let diag = mutableMessage.withBridgedString { bridgedMessage in
142-
Diagnostic_create(
143-
bridgedDiagEngine, bridgedSeverity,
144-
bridgedSourceLoc(for: node, at: position),
145-
bridgedMessage
144+
BridgedDiagnostic(
145+
at: bridgedSourceLoc(for: node, at: position),
146+
message: bridgedMessage,
147+
severity: bridgedSeverity,
148+
engine: bridgedDiagEngine
146149
)
147150
}
148151

149152
// Emit highlights
150153
for highlight in highlights {
151-
Diagnostic_highlight(
152-
diag,
153-
bridgedSourceLoc(for: highlight, at: highlight.positionAfterSkippingLeadingTrivia),
154-
bridgedSourceLoc(for: highlight, at: highlight.endPositionBeforeTrailingTrivia)
154+
diag.highlight(
155+
start: bridgedSourceLoc(for: highlight, at: highlight.positionAfterSkippingLeadingTrivia),
156+
end: bridgedSourceLoc(for: highlight, at: highlight.endPositionBeforeTrailingTrivia)
155157
)
156158
}
157159

@@ -193,14 +195,14 @@ extension SourceManager {
193195
}
194196

195197
newText.withBridgedString { bridgedMessage in
196-
Diagnostic_fixItReplace(
197-
diag, replaceStartLoc, replaceEndLoc,
198-
bridgedMessage
198+
diag.fixItReplace(
199+
start: replaceStartLoc, end: replaceEndLoc,
200+
replacement: bridgedMessage
199201
)
200202
}
201203
}
202204

203-
Diagnostic_finish(diag);
205+
diag.finish();
204206
}
205207

206208
/// Emit a diagnostic via the C++ diagnostic engine.

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,20 @@ class PluginDiagnosticsEngine {
274274
// Emit the diagnostic
275275
var mutableMessage = message
276276
let diag = mutableMessage.withBridgedString { bridgedMessage in
277-
Diagnostic_create(
278-
bridgedDiagEngine, bridgedSeverity,
279-
bridgedSourceLoc(at: position),
280-
bridgedMessage)
277+
BridgedDiagnostic(
278+
at: bridgedSourceLoc(at: position),
279+
message: bridgedMessage,
280+
severity: bridgedSeverity,
281+
engine: bridgedDiagEngine
282+
)
281283
}
282284

283285
// Emit highlights
284286
for highlight in highlights {
285287
guard let (startLoc, endLoc) = bridgedSourceRange(for: highlight) else {
286288
continue
287289
}
288-
Diagnostic_highlight(diag, startLoc, endLoc)
290+
diag.highlight(start: startLoc, end: endLoc)
289291
}
290292

291293
// Emit changes for a Fix-It.
@@ -295,12 +297,12 @@ class PluginDiagnosticsEngine {
295297
}
296298
var newText = change.newText
297299
newText.withBridgedString { bridgedFixItText in
298-
Diagnostic_fixItReplace(
299-
diag, startLoc, endLoc, bridgedFixItText)
300+
diag.fixItReplace(
301+
start: startLoc, end: endLoc, replacement: bridgedFixItText)
300302
}
301303
}
302304

303-
Diagnostic_finish(diag)
305+
diag.finish()
304306
}
305307

306308
/// Emit diagnostics.
@@ -339,7 +341,7 @@ class PluginDiagnosticsEngine {
339341
guard let bufferBaseAddress = exportedSourceFile.pointee.buffer.baseAddress else {
340342
return nil
341343
}
342-
return SourceLoc_advanced(BridgedSourceLoc(raw: bufferBaseAddress), offset)
344+
return BridgedSourceLoc(raw: bufferBaseAddress).advanced(by: offset)
343345
}
344346

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

lib/ASTGen/Sources/ASTGen/SourceFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension Parser.ExperimentalFeatures {
3131
guard let context = context else { return }
3232

3333
func mapFeature(_ bridged: BridgedFeature, to feature: Self) {
34-
if ASTContext_langOptsHasFeature(context, bridged) {
34+
if context.langOptsHasFeature(bridged) {
3535
insert(feature)
3636
}
3737
}

0 commit comments

Comments
 (0)