Skip to content

Commit c182790

Browse files
authored
Merge pull request #185 from brentdax/file-name-basis
SwiftSyntax update for "Shorten #file and add #filePath (behind an experimental flag)" (swiftlang/swift#25656)
2 parents 04a6d41 + d876fe1 commit c182790

12 files changed

+210
-3
lines changed

Sources/SwiftSyntax/gyb_generated/Misc.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ extension SyntaxNode {
183183
return PoundFileExprSyntax(asSyntaxData)
184184
}
185185

186+
public var isPoundFilePathExpr: Bool { return raw.kind == .poundFilePathExpr }
187+
public var asPoundFilePathExpr: PoundFilePathExprSyntax? {
188+
guard isPoundFilePathExpr else { return nil }
189+
return PoundFilePathExprSyntax(asSyntaxData)
190+
}
191+
186192
public var isPoundFunctionExpr: Bool { return raw.kind == .poundFunctionExpr }
187193
public var asPoundFunctionExpr: PoundFunctionExprSyntax? {
188194
guard isPoundFunctionExpr else { return nil }
@@ -1471,6 +1477,8 @@ extension Syntax {
14711477
return node
14721478
case .poundFileExpr(let node):
14731479
return node
1480+
case .poundFilePathExpr(let node):
1481+
return node
14741482
case .poundFunctionExpr(let node):
14751483
return node
14761484
case .poundDsohandleExpr(let node):
@@ -1880,6 +1888,6 @@ extension Syntax {
18801888
extension SyntaxParser {
18811889
static func verifyNodeDeclarationHash() -> Bool {
18821890
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
1883-
"3924247553615556843"
1891+
"7184602491276114819"
18841892
}
18851893
}

Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift

+7
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
253253
override open func visitPost(_ node: PoundFileExprSyntax) {
254254
visitAnyPost(node._syntaxNode)
255255
}
256+
override open func visit(_ node: PoundFilePathExprSyntax) -> SyntaxVisitorContinueKind {
257+
return visitAny(node._syntaxNode)
258+
}
259+
260+
override open func visitPost(_ node: PoundFilePathExprSyntax) {
261+
visitAnyPost(node._syntaxNode)
262+
}
256263
override open func visit(_ node: PoundFunctionExprSyntax) -> SyntaxVisitorContinueKind {
257264
return visitAny(node._syntaxNode)
258265
}

Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
146146
/// `nil` if the conversion is not possible.
147147
public init?(_ syntax: Syntax) {
148148
switch syntax.raw.kind {
149-
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .editorPlaceholderExpr, .objectLiteralExpr:
149+
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .editorPlaceholderExpr, .objectLiteralExpr:
150150
self._syntaxNode = syntax
151151
default:
152152
return nil
@@ -160,7 +160,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
160160
// Assert that the kind of the given data matches in debug builds.
161161
#if DEBUG
162162
switch data.raw.kind {
163-
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .editorPlaceholderExpr, .objectLiteralExpr:
163+
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .editorPlaceholderExpr, .objectLiteralExpr:
164164
break
165165
default:
166166
fatalError("Unable to create ExprSyntax from \(data.raw.kind)")

Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift

+38
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,44 @@ extension PoundFileExprSyntax {
677677
}
678678
}
679679

680+
public struct PoundFilePathExprSyntaxBuilder {
681+
private var layout =
682+
Array<RawSyntax?>(repeating: nil, count: 1)
683+
684+
internal init() {}
685+
686+
public mutating func usePoundFilePath(_ node: TokenSyntax) {
687+
let idx = PoundFilePathExprSyntax.Cursor.poundFilePath.rawValue
688+
layout[idx] = node.raw
689+
}
690+
691+
internal mutating func buildData() -> SyntaxData {
692+
if (layout[0] == nil) {
693+
layout[0] = RawSyntax.missingToken(TokenKind.poundFilePathKeyword)
694+
}
695+
696+
return .forRoot(RawSyntax.createAndCalcLength(kind: .poundFilePathExpr,
697+
layout: layout, presence: .present))
698+
}
699+
}
700+
701+
extension PoundFilePathExprSyntax {
702+
/// Creates a `PoundFilePathExprSyntax` using the provided build function.
703+
/// - Parameter:
704+
/// - build: A closure that wil be invoked in order to initialize
705+
/// the fields of the syntax node.
706+
/// This closure is passed a `PoundFilePathExprSyntaxBuilder` which you can use to
707+
/// incrementally build the structure of the node.
708+
/// - Returns: A `PoundFilePathExprSyntax` with all the fields populated in the builder
709+
/// closure.
710+
public init(_ build: (inout PoundFilePathExprSyntaxBuilder) -> Void) {
711+
var builder = PoundFilePathExprSyntaxBuilder()
712+
build(&builder)
713+
let data = builder.buildData()
714+
self.init(data)
715+
}
716+
}
717+
680718
public struct PoundFunctionExprSyntaxBuilder {
681719
private var layout =
682720
Array<RawSyntax?>(repeating: nil, count: 1)

Sources/SwiftSyntax/gyb_generated/SyntaxClassification.swift

+2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ extension RawTokenKind {
286286
return .keyword
287287
case .poundFileKeyword:
288288
return .keyword
289+
case .poundFilePathKeyword:
290+
return .keyword
289291
case .poundColumnKeyword:
290292
return .keyword
291293
case .poundFunctionKeyword:

Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public enum SyntaxEnum {
4848
case exprList(ExprListSyntax)
4949
case poundLineExpr(PoundLineExprSyntax)
5050
case poundFileExpr(PoundFileExprSyntax)
51+
case poundFilePathExpr(PoundFilePathExprSyntax)
5152
case poundFunctionExpr(PoundFunctionExprSyntax)
5253
case poundDsohandleExpr(PoundDsohandleExprSyntax)
5354
case symbolicReferenceExpr(SymbolicReferenceExprSyntax)
@@ -323,6 +324,8 @@ public extension Syntax {
323324
return .poundLineExpr(PoundLineExprSyntax(self)!)
324325
case .poundFileExpr:
325326
return .poundFileExpr(PoundFileExprSyntax(self)!)
327+
case .poundFilePathExpr:
328+
return .poundFilePathExpr(PoundFilePathExprSyntax(self)!)
326329
case .poundFunctionExpr:
327330
return .poundFunctionExpr(PoundFunctionExprSyntax(self)!)
328331
case .poundDsohandleExpr:

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

+23
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,23 @@ public enum SyntaxFactory {
456456
], length: .zero, presence: .present))
457457
return PoundFileExprSyntax(data)
458458
}
459+
public static func makePoundFilePathExpr(poundFilePath: TokenSyntax) -> PoundFilePathExprSyntax {
460+
let layout: [RawSyntax?] = [
461+
poundFilePath.raw,
462+
]
463+
let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.poundFilePathExpr,
464+
layout: layout, presence: SourcePresence.present)
465+
let data = SyntaxData.forRoot(raw)
466+
return PoundFilePathExprSyntax(data)
467+
}
468+
469+
public static func makeBlankPoundFilePathExpr() -> PoundFilePathExprSyntax {
470+
let data = SyntaxData.forRoot(RawSyntax.create(kind: .poundFilePathExpr,
471+
layout: [
472+
RawSyntax.missingToken(TokenKind.poundFilePathKeyword),
473+
], length: .zero, presence: .present))
474+
return PoundFilePathExprSyntax(data)
475+
}
459476
public static func makePoundFunctionExpr(poundFunction: TokenSyntax) -> PoundFunctionExprSyntax {
460477
let layout: [RawSyntax?] = [
461478
poundFunction.raw,
@@ -5130,6 +5147,12 @@ public enum SyntaxFactory {
51305147
leadingTrivia: leadingTrivia,
51315148
trailingTrivia: trailingTrivia)
51325149
}
5150+
public static func makePoundFilePathKeyword(leadingTrivia: Trivia = [],
5151+
trailingTrivia: Trivia = []) -> TokenSyntax {
5152+
return makeToken(.poundFilePathKeyword, presence: .present,
5153+
leadingTrivia: leadingTrivia,
5154+
trailingTrivia: trailingTrivia)
5155+
}
51335156
public static func makePoundColumnKeyword(leadingTrivia: Trivia = [],
51345157
trailingTrivia: Trivia = []) -> TokenSyntax {
51355158
return makeToken(.poundColumnKeyword, presence: .present,

Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal enum SyntaxKind: CSyntaxKind {
4848
case exprList = 170
4949
case poundLineExpr = 34
5050
case poundFileExpr = 35
51+
case poundFilePathExpr = 240
5152
case poundFunctionExpr = 36
5253
case poundDsohandleExpr = 37
5354
case symbolicReferenceExpr = 38

Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift

+19
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ open class SyntaxRewriter {
212212
return ExprSyntax(visitChildren(node))
213213
}
214214

215+
/// Visit a `PoundFilePathExprSyntax`.
216+
/// - Parameter node: the node that is being visited
217+
/// - Returns: the rewritten node
218+
open func visit(_ node: PoundFilePathExprSyntax) -> ExprSyntax {
219+
return ExprSyntax(visitChildren(node))
220+
}
221+
215222
/// Visit a `PoundFunctionExprSyntax`.
216223
/// - Parameter node: the node that is being visited
217224
/// - Returns: the rewritten node
@@ -1980,6 +1987,16 @@ open class SyntaxRewriter {
19801987
return Syntax(visit(node))
19811988
}
19821989

1990+
/// Implementation detail of visit(_:). Do not call directly.
1991+
private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) -> Syntax {
1992+
let node = PoundFilePathExprSyntax(data)
1993+
// Accessing _syntaxNode directly is faster than calling Syntax(node)
1994+
visitPre(node._syntaxNode)
1995+
defer { visitPost(node._syntaxNode) }
1996+
if let newNode = visitAny(node._syntaxNode) { return newNode }
1997+
return Syntax(visit(node))
1998+
}
1999+
19832000
/// Implementation detail of visit(_:). Do not call directly.
19842001
private func visitImplPoundFunctionExprSyntax(_ data: SyntaxData) -> Syntax {
19852002
let node = PoundFunctionExprSyntax(data)
@@ -4075,6 +4092,8 @@ open class SyntaxRewriter {
40754092
return visitImplPoundLineExprSyntax(data)
40764093
case .poundFileExpr:
40774094
return visitImplPoundFileExprSyntax(data)
4095+
case .poundFilePathExpr:
4096+
return visitImplPoundFilePathExprSyntax(data)
40784097
case .poundFunctionExpr:
40794098
return visitImplPoundFunctionExprSyntax(data)
40804099
case .poundDsohandleExpr:

Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift

+23
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ open class SyntaxVisitor {
302302
/// The function called after visiting `PoundFileExprSyntax` and its descendents.
303303
/// - node: the node we just finished visiting.
304304
open func visitPost(_ node: PoundFileExprSyntax) {}
305+
/// Visiting `PoundFilePathExprSyntax` specifically.
306+
/// - Parameter node: the node we are visiting.
307+
/// - Returns: how should we continue visiting.
308+
open func visit(_ node: PoundFilePathExprSyntax) -> SyntaxVisitorContinueKind {
309+
return .visitChildren
310+
}
311+
312+
/// The function called after visiting `PoundFilePathExprSyntax` and its descendents.
313+
/// - node: the node we just finished visiting.
314+
open func visitPost(_ node: PoundFilePathExprSyntax) {}
305315
/// Visiting `PoundFunctionExprSyntax` specifically.
306316
/// - Parameter node: the node we are visiting.
307317
/// - Returns: how should we continue visiting.
@@ -2687,6 +2697,17 @@ open class SyntaxVisitor {
26872697
visitPost(node)
26882698
}
26892699

2700+
/// Implementation detail of doVisit(_:_:). Do not call directly.
2701+
private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) {
2702+
let node = PoundFilePathExprSyntax(data)
2703+
let needsChildren = (visit(node) == .visitChildren)
2704+
// Avoid calling into visitChildren if possible.
2705+
if needsChildren && node.raw.numberOfChildren > 0 {
2706+
visitChildren(node)
2707+
}
2708+
visitPost(node)
2709+
}
2710+
26902711
/// Implementation detail of doVisit(_:_:). Do not call directly.
26912712
private func visitImplPoundFunctionExprSyntax(_ data: SyntaxData) {
26922713
let node = PoundFunctionExprSyntax(data)
@@ -4982,6 +5003,8 @@ open class SyntaxVisitor {
49825003
visitImplPoundLineExprSyntax(data)
49835004
case .poundFileExpr:
49845005
visitImplPoundFileExprSyntax(data)
5006+
case .poundFilePathExpr:
5007+
visitImplPoundFilePathExprSyntax(data)
49855008
case .poundFunctionExpr:
49865009
visitImplPoundFunctionExprSyntax(data)
49875010
case .poundDsohandleExpr:

Sources/SwiftSyntax/gyb_generated/TokenKind.swift

+14
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public enum TokenKind {
105105
case poundLineKeyword
106106
case poundSelectorKeyword
107107
case poundFileKeyword
108+
case poundFilePathKeyword
108109
case poundColumnKeyword
109110
case poundFunctionKeyword
110111
case poundDsohandleKeyword
@@ -230,6 +231,7 @@ public enum TokenKind {
230231
case .poundLineKeyword: return "#line"
231232
case .poundSelectorKeyword: return "#selector"
232233
case .poundFileKeyword: return "#file"
234+
case .poundFilePathKeyword: return "#filePath"
233235
case .poundColumnKeyword: return "#column"
234236
case .poundFunctionKeyword: return "#function"
235237
case .poundDsohandleKeyword: return "#dsohandle"
@@ -356,6 +358,7 @@ public enum TokenKind {
356358
case .poundLineKeyword: return true
357359
case .poundSelectorKeyword: return true
358360
case .poundFileKeyword: return true
361+
case .poundFilePathKeyword: return true
359362
case .poundColumnKeyword: return true
360363
case .poundFunctionKeyword: return true
361364
case .poundDsohandleKeyword: return true
@@ -482,6 +485,7 @@ public enum TokenKind {
482485
case .poundLineKeyword: return "pound_line"
483486
case .poundSelectorKeyword: return "pound_selector"
484487
case .poundFileKeyword: return "pound_file"
488+
case .poundFilePathKeyword: return "pound_filePath"
485489
case .poundColumnKeyword: return "pound_column"
486490
case .poundFunctionKeyword: return "pound_function"
487491
case .poundDsohandleKeyword: return "pound_dsohandle"
@@ -608,6 +612,7 @@ public enum TokenKind {
608612
case .poundLineKeyword: return SourceLength(utf8Length: 5)
609613
case .poundSelectorKeyword: return SourceLength(utf8Length: 9)
610614
case .poundFileKeyword: return SourceLength(utf8Length: 5)
615+
case .poundFilePathKeyword: return SourceLength(utf8Length: 9)
611616
case .poundColumnKeyword: return SourceLength(utf8Length: 7)
612617
case .poundFunctionKeyword: return SourceLength(utf8Length: 9)
613618
case .poundDsohandleKeyword: return SourceLength(utf8Length: 10)
@@ -736,6 +741,7 @@ extension TokenKind: Equatable {
736741
case (.poundLineKeyword, .poundLineKeyword): return true
737742
case (.poundSelectorKeyword, .poundSelectorKeyword): return true
738743
case (.poundFileKeyword, .poundFileKeyword): return true
744+
case (.poundFilePathKeyword, .poundFilePathKeyword): return true
739745
case (.poundColumnKeyword, .poundColumnKeyword): return true
740746
case (.poundFunctionKeyword, .poundFunctionKeyword): return true
741747
case (.poundDsohandleKeyword, .poundDsohandleKeyword): return true
@@ -969,6 +975,8 @@ extension TokenKind {
969975
return .poundSelectorKeyword
970976
case 68:
971977
return .poundFileKeyword
978+
case 121:
979+
return .poundFilePathKeyword
972980
case 70:
973981
return .poundColumnKeyword
974982
case 72:
@@ -1225,6 +1233,8 @@ extension TokenKind {
12251233
return false
12261234
case 68:
12271235
return false
1236+
case 121:
1237+
return false
12281238
case 70:
12291239
return false
12301240
case 72:
@@ -1384,6 +1394,7 @@ internal enum RawTokenKind: CTokenKind {
13841394
case poundLineKeyword = 69
13851395
case poundSelectorKeyword = 73
13861396
case poundFileKeyword = 68
1397+
case poundFilePathKeyword = 121
13871398
case poundColumnKeyword = 70
13881399
case poundFunctionKeyword = 72
13891400
case poundDsohandleKeyword = 71
@@ -1697,6 +1708,9 @@ extension TokenKind {
16971708
case .poundFileKeyword:
16981709
let length = 5
16991710
return body(.init(kind: .poundFileKeyword, length: length))
1711+
case .poundFilePathKeyword:
1712+
let length = 9
1713+
return body(.init(kind: .poundFilePathKeyword, length: length))
17001714
case .poundColumnKeyword:
17011715
let length = 7
17021716
return body(.init(kind: .poundColumnKeyword, length: length))

0 commit comments

Comments
 (0)