Skip to content

Commit 3d512f3

Browse files
authored
Merge pull request #226 from brentdax/magical-and-evolutionary
Add syntax nodes for #fileID
2 parents 7558636 + c7126eb commit 3d512f3

12 files changed

+216
-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 isPoundFileIDExpr: Bool { return raw.kind == .poundFileIDExpr }
187+
public var asPoundFileIDExpr: PoundFileIDExprSyntax? {
188+
guard isPoundFileIDExpr else { return nil }
189+
return PoundFileIDExprSyntax(asSyntaxData)
190+
}
191+
186192
public var isPoundFilePathExpr: Bool { return raw.kind == .poundFilePathExpr }
187193
public var asPoundFilePathExpr: PoundFilePathExprSyntax? {
188194
guard isPoundFilePathExpr else { return nil }
@@ -1507,6 +1513,8 @@ extension Syntax {
15071513
return node
15081514
case .poundFileExpr(let node):
15091515
return node
1516+
case .poundFileIDExpr(let node):
1517+
return node
15101518
case .poundFilePathExpr(let node):
15111519
return node
15121520
case .poundFunctionExpr(let node):
@@ -1928,6 +1936,6 @@ extension Syntax {
19281936
extension SyntaxParser {
19291937
static func verifyNodeDeclarationHash() -> Bool {
19301938
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
1931-
"7b2f9ca5e9d7140a7fadb9bb5da4f23b1836bdf3"
1939+
"77e9551aa9f94761b9808f610830fa826cc8323a"
19321940
}
19331941
}

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: PoundFileIDExprSyntax) -> SyntaxVisitorContinueKind {
257+
return visitAny(node._syntaxNode)
258+
}
259+
260+
override open func visitPost(_ node: PoundFileIDExprSyntax) {
261+
visitAnyPost(node._syntaxNode)
262+
}
256263
override open func visit(_ node: PoundFilePathExprSyntax) -> 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
@@ -164,7 +164,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
164164
/// `nil` if the conversion is not possible.
165165
public init?(_ syntax: Syntax) {
166166
switch syntax.raw.kind {
167-
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:
167+
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .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:
168168
self._syntaxNode = syntax
169169
default:
170170
return nil
@@ -178,7 +178,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
178178
// Assert that the kind of the given data matches in debug builds.
179179
#if DEBUG
180180
switch data.raw.kind {
181-
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:
181+
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .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:
182182
break
183183
default:
184184
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 PoundFileIDExprSyntaxBuilder {
681+
private var layout =
682+
Array<RawSyntax?>(repeating: nil, count: 1)
683+
684+
internal init() {}
685+
686+
public mutating func usePoundFileID(_ node: TokenSyntax) {
687+
let idx = PoundFileIDExprSyntax.Cursor.poundFileID.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.poundFileIDKeyword)
694+
}
695+
696+
return .forRoot(RawSyntax.createAndCalcLength(kind: .poundFileIDExpr,
697+
layout: layout, presence: .present))
698+
}
699+
}
700+
701+
extension PoundFileIDExprSyntax {
702+
/// Creates a `PoundFileIDExprSyntax` 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 `PoundFileIDExprSyntaxBuilder` which you can use to
707+
/// incrementally build the structure of the node.
708+
/// - Returns: A `PoundFileIDExprSyntax` with all the fields populated in the builder
709+
/// closure.
710+
public init(_ build: (inout PoundFileIDExprSyntaxBuilder) -> Void) {
711+
var builder = PoundFileIDExprSyntaxBuilder()
712+
build(&builder)
713+
let data = builder.buildData()
714+
self.init(data)
715+
}
716+
}
717+
680718
public struct PoundFilePathExprSyntaxBuilder {
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 .poundFileIDKeyword:
290+
return .keyword
289291
case .poundFilePathKeyword:
290292
return .keyword
291293
case .poundColumnKeyword:

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 poundFileIDExpr(PoundFileIDExprSyntax)
5152
case poundFilePathExpr(PoundFilePathExprSyntax)
5253
case poundFunctionExpr(PoundFunctionExprSyntax)
5354
case poundDsohandleExpr(PoundDsohandleExprSyntax)
@@ -329,6 +330,8 @@ public extension Syntax {
329330
return .poundLineExpr(PoundLineExprSyntax(self)!)
330331
case .poundFileExpr:
331332
return .poundFileExpr(PoundFileExprSyntax(self)!)
333+
case .poundFileIDExpr:
334+
return .poundFileIDExpr(PoundFileIDExprSyntax(self)!)
332335
case .poundFilePathExpr:
333336
return .poundFilePathExpr(PoundFilePathExprSyntax(self)!)
334337
case .poundFunctionExpr:

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 makePoundFileIDExpr(poundFileID: TokenSyntax) -> PoundFileIDExprSyntax {
460+
let layout: [RawSyntax?] = [
461+
poundFileID.raw,
462+
]
463+
let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.poundFileIDExpr,
464+
layout: layout, presence: SourcePresence.present)
465+
let data = SyntaxData.forRoot(raw)
466+
return PoundFileIDExprSyntax(data)
467+
}
468+
469+
public static func makeBlankPoundFileIDExpr() -> PoundFileIDExprSyntax {
470+
let data = SyntaxData.forRoot(RawSyntax.create(kind: .poundFileIDExpr,
471+
layout: [
472+
RawSyntax.missingToken(TokenKind.poundFileIDKeyword),
473+
], length: .zero, presence: .present))
474+
return PoundFileIDExprSyntax(data)
475+
}
459476
public static func makePoundFilePathExpr(poundFilePath: TokenSyntax) -> PoundFilePathExprSyntax {
460477
let layout: [RawSyntax?] = [
461478
poundFilePath.raw,
@@ -5244,6 +5261,12 @@ public enum SyntaxFactory {
52445261
leadingTrivia: leadingTrivia,
52455262
trailingTrivia: trailingTrivia)
52465263
}
5264+
public static func makePoundFileIDKeyword(leadingTrivia: Trivia = [],
5265+
trailingTrivia: Trivia = []) -> TokenSyntax {
5266+
return makeToken(.poundFileIDKeyword, presence: .present,
5267+
leadingTrivia: leadingTrivia,
5268+
trailingTrivia: trailingTrivia)
5269+
}
52475270
public static func makePoundFilePathKeyword(leadingTrivia: Trivia = [],
52485271
trailingTrivia: Trivia = []) -> TokenSyntax {
52495272
return makeToken(.poundFilePathKeyword, 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 poundFileIDExpr = 247
5152
case poundFilePathExpr = 240
5253
case poundFunctionExpr = 36
5354
case poundDsohandleExpr = 37

Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift

Lines changed: 21 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 `PoundFileIDExprSyntax`.
216+
/// - Parameter node: the node that is being visited
217+
/// - Returns: the rewritten node
218+
open func visit(_ node: PoundFileIDExprSyntax) -> ExprSyntax {
219+
return ExprSyntax(visitChildren(node))
220+
}
221+
215222
/// Visit a `PoundFilePathExprSyntax`.
216223
/// - Parameter node: the node that is being visited
217224
/// - Returns: the rewritten node
@@ -2022,6 +2029,16 @@ open class SyntaxRewriter {
20222029
return Syntax(visit(node))
20232030
}
20242031

2032+
/// Implementation detail of visit(_:). Do not call directly.
2033+
private func visitImplPoundFileIDExprSyntax(_ data: SyntaxData) -> Syntax {
2034+
let node = PoundFileIDExprSyntax(data)
2035+
// Accessing _syntaxNode directly is faster than calling Syntax(node)
2036+
visitPre(node._syntaxNode)
2037+
defer { visitPost(node._syntaxNode) }
2038+
if let newNode = visitAny(node._syntaxNode) { return newNode }
2039+
return Syntax(visit(node))
2040+
}
2041+
20252042
/// Implementation detail of visit(_:). Do not call directly.
20262043
private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) -> Syntax {
20272044
let node = PoundFilePathExprSyntax(data)
@@ -4208,6 +4225,8 @@ open class SyntaxRewriter {
42084225
return visitImplPoundLineExprSyntax
42094226
case .poundFileExpr:
42104227
return visitImplPoundFileExprSyntax
4228+
case .poundFileIDExpr:
4229+
return visitImplPoundFileIDExprSyntax
42114230
case .poundFilePathExpr:
42124231
return visitImplPoundFilePathExprSyntax
42134232
case .poundFunctionExpr:
@@ -4701,6 +4720,8 @@ open class SyntaxRewriter {
47014720
return visitImplPoundLineExprSyntax(data)
47024721
case .poundFileExpr:
47034722
return visitImplPoundFileExprSyntax(data)
4723+
case .poundFileIDExpr:
4724+
return visitImplPoundFileIDExprSyntax(data)
47044725
case .poundFilePathExpr:
47054726
return visitImplPoundFilePathExprSyntax(data)
47064727
case .poundFunctionExpr:

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 `PoundFileIDExprSyntax` specifically.
306+
/// - Parameter node: the node we are visiting.
307+
/// - Returns: how should we continue visiting.
308+
open func visit(_ node: PoundFileIDExprSyntax) -> SyntaxVisitorContinueKind {
309+
return .visitChildren
310+
}
311+
312+
/// The function called after visiting `PoundFileIDExprSyntax` and its descendents.
313+
/// - node: the node we just finished visiting.
314+
open func visitPost(_ node: PoundFileIDExprSyntax) {}
305315
/// Visiting `PoundFilePathExprSyntax` specifically.
306316
/// - Parameter node: the node we are visiting.
307317
/// - Returns: how should we continue visiting.
@@ -2747,6 +2757,17 @@ open class SyntaxVisitor {
27472757
visitPost(node)
27482758
}
27492759

2760+
/// Implementation detail of doVisit(_:_:). Do not call directly.
2761+
private func visitImplPoundFileIDExprSyntax(_ data: SyntaxData) {
2762+
let node = PoundFileIDExprSyntax(data)
2763+
let needsChildren = (visit(node) == .visitChildren)
2764+
// Avoid calling into visitChildren if possible.
2765+
if needsChildren && node.raw.numberOfChildren > 0 {
2766+
visitChildren(node)
2767+
}
2768+
visitPost(node)
2769+
}
2770+
27502771
/// Implementation detail of doVisit(_:_:). Do not call directly.
27512772
private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) {
27522773
let node = PoundFilePathExprSyntax(data)
@@ -5108,6 +5129,8 @@ open class SyntaxVisitor {
51085129
visitImplPoundLineExprSyntax(data)
51095130
case .poundFileExpr:
51105131
visitImplPoundFileExprSyntax(data)
5132+
case .poundFileIDExpr:
5133+
visitImplPoundFileIDExprSyntax(data)
51115134
case .poundFilePathExpr:
51125135
visitImplPoundFilePathExprSyntax(data)
51135136
case .poundFunctionExpr:

0 commit comments

Comments
 (0)