Skip to content

Commit 84afc65

Browse files
committed
[ASTGen] Move getIdentifier logic to ASTGen side
Ideally ASTBriding should only do the neccessary work for briding. All non-trivial logic should be in ASTGen.
1 parent 9f7ebcd commit 84afc65

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/AST/ASTBridging.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,7 @@ BridgedDeclNameLoc_createParsed(BridgedSourceLoc cBaseNameLoc) {
110110

111111
BridgedIdentifier BridgedASTContext_getIdentifier(BridgedASTContext cContext,
112112
BridgedStringRef cStr) {
113-
StringRef str = cStr.unbridged();
114-
if (str.size() == 1 && str.front() == '_')
115-
return BridgedIdentifier();
116-
117-
// If this was a back-ticked identifier, drop the back-ticks.
118-
if (str.size() >= 2 && str.front() == '`' && str.back() == '`') {
119-
str = str.drop_front().drop_back();
120-
}
121-
122-
return cContext.unbridged().getIdentifier(str);
113+
return cContext.unbridged().getIdentifier(cStr.unbridged());
123114
}
124115

125116
bool BridgedASTContext_langOptsHasFeature(BridgedASTContext cContext,

lib/ASTGen/Sources/ASTGen/Bridge.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,14 @@ extension TokenSyntax {
167167
/// - Parameter astgen: The visitor providing the `ASTContext`.
168168
@inline(__always)
169169
func bridgedIdentifier(in astgen: ASTGenVisitor) -> BridgedIdentifier {
170-
var text = self.text
171-
return text.withBridgedString { bridged in
172-
astgen.ctx.getIdentifier(bridged)
170+
var text = self.rawText
171+
if rawText == "_" {
172+
return nil
173+
}
174+
if rawText.count > 2 && rawText.hasPrefix("`") && rawText.hasSuffix("`") {
175+
text = .init(rebasing: text.dropFirst().dropLast())
173176
}
177+
return astgen.ctx.getIdentifier(rawText.bridged)
174178
}
175179

176180
/// Obtains a bridged, `ASTContext`-owned copy of this token's text, and its bridged start location in the

0 commit comments

Comments
 (0)