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

Lines changed: 9 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 38 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 19 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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:

0 commit comments

Comments
 (0)