From ecb08169bd66bb670d37e4242013f8c6a7dca85a Mon Sep 17 00:00:00 2001 From: Brent Royal-Gordon Date: Thu, 9 Jul 2020 23:47:13 -0700 Subject: [PATCH] Update PoundFileIDExprSyntax --- Sources/SwiftSyntax/gyb_generated/Misc.swift | 10 ++- .../gyb_generated/SyntaxAnyVisitor.swift | 7 ++ .../gyb_generated/SyntaxBaseNodes.swift | 4 +- .../gyb_generated/SyntaxBuilders.swift | 38 ++++++++++ .../gyb_generated/SyntaxClassification.swift | 2 + .../gyb_generated/SyntaxEnum.swift | 3 + .../gyb_generated/SyntaxFactory.swift | 23 ++++++ .../gyb_generated/SyntaxKind.swift | 1 + .../gyb_generated/SyntaxRewriter.swift | 21 ++++++ .../gyb_generated/SyntaxVisitor.swift | 23 ++++++ .../SwiftSyntax/gyb_generated/TokenKind.swift | 14 ++++ .../syntax_nodes/SyntaxExprNodes.swift | 73 +++++++++++++++++++ 12 files changed, 216 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftSyntax/gyb_generated/Misc.swift b/Sources/SwiftSyntax/gyb_generated/Misc.swift index 085d2bd4ba8..44a3f44c556 100644 --- a/Sources/SwiftSyntax/gyb_generated/Misc.swift +++ b/Sources/SwiftSyntax/gyb_generated/Misc.swift @@ -183,6 +183,12 @@ extension SyntaxNode { return PoundFileExprSyntax(asSyntaxData) } + public var isPoundFileIDExpr: Bool { return raw.kind == .poundFileIDExpr } + public var asPoundFileIDExpr: PoundFileIDExprSyntax? { + guard isPoundFileIDExpr else { return nil } + return PoundFileIDExprSyntax(asSyntaxData) + } + public var isPoundFilePathExpr: Bool { return raw.kind == .poundFilePathExpr } public var asPoundFilePathExpr: PoundFilePathExprSyntax? { guard isPoundFilePathExpr else { return nil } @@ -1507,6 +1513,8 @@ extension Syntax { return node case .poundFileExpr(let node): return node + case .poundFileIDExpr(let node): + return node case .poundFilePathExpr(let node): return node case .poundFunctionExpr(let node): @@ -1928,6 +1936,6 @@ extension Syntax { extension SyntaxParser { static func verifyNodeDeclarationHash() -> Bool { return String(cString: swiftparse_syntax_structure_versioning_identifier()!) == - "3723395330444835342" + "-5760816212802424482" } } diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift index e1c5f28308a..f26dc08958f 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift @@ -253,6 +253,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor { override open func visitPost(_ node: PoundFileExprSyntax) { visitAnyPost(node._syntaxNode) } + override open func visit(_ node: PoundFileIDExprSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + override open func visitPost(_ node: PoundFileIDExprSyntax) { + visitAnyPost(node._syntaxNode) + } override open func visit(_ node: PoundFilePathExprSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift index 30bfffeef4d..6d5877f3eee 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift @@ -164,7 +164,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable { /// `nil` if the conversion is not possible. public init?(_ syntax: Syntax) { switch syntax.raw.kind { - 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: + 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: self._syntaxNode = syntax default: return nil @@ -178,7 +178,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable { // Assert that the kind of the given data matches in debug builds. #if DEBUG switch data.raw.kind { - 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: + 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: break default: fatalError("Unable to create ExprSyntax from \(data.raw.kind)") diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift index 92ec227e984..26b9d90e7f1 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift @@ -677,6 +677,44 @@ extension PoundFileExprSyntax { } } +public struct PoundFileIDExprSyntaxBuilder { + private var layout = + Array(repeating: nil, count: 1) + + internal init() {} + + public mutating func usePoundFileID(_ node: TokenSyntax) { + let idx = PoundFileIDExprSyntax.Cursor.poundFileID.rawValue + layout[idx] = node.raw + } + + internal mutating func buildData() -> SyntaxData { + if (layout[0] == nil) { + layout[0] = RawSyntax.missingToken(TokenKind.poundFileIDKeyword) + } + + return .forRoot(RawSyntax.createAndCalcLength(kind: .poundFileIDExpr, + layout: layout, presence: .present)) + } +} + +extension PoundFileIDExprSyntax { + /// Creates a `PoundFileIDExprSyntax` using the provided build function. + /// - Parameter: + /// - build: A closure that wil be invoked in order to initialize + /// the fields of the syntax node. + /// This closure is passed a `PoundFileIDExprSyntaxBuilder` which you can use to + /// incrementally build the structure of the node. + /// - Returns: A `PoundFileIDExprSyntax` with all the fields populated in the builder + /// closure. + public init(_ build: (inout PoundFileIDExprSyntaxBuilder) -> Void) { + var builder = PoundFileIDExprSyntaxBuilder() + build(&builder) + let data = builder.buildData() + self.init(data) + } +} + public struct PoundFilePathExprSyntaxBuilder { private var layout = Array(repeating: nil, count: 1) diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxClassification.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxClassification.swift index 23860778ccc..3d3d07d7e0c 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxClassification.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxClassification.swift @@ -286,6 +286,8 @@ extension RawTokenKind { return .keyword case .poundFileKeyword: return .keyword + case .poundFileIDKeyword: + return .keyword case .poundFilePathKeyword: return .keyword case .poundColumnKeyword: diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift index 03e7e2cf1ff..9d6c73f1803 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift @@ -48,6 +48,7 @@ public enum SyntaxEnum { case exprList(ExprListSyntax) case poundLineExpr(PoundLineExprSyntax) case poundFileExpr(PoundFileExprSyntax) + case poundFileIDExpr(PoundFileIDExprSyntax) case poundFilePathExpr(PoundFilePathExprSyntax) case poundFunctionExpr(PoundFunctionExprSyntax) case poundDsohandleExpr(PoundDsohandleExprSyntax) @@ -329,6 +330,8 @@ public extension Syntax { return .poundLineExpr(PoundLineExprSyntax(self)!) case .poundFileExpr: return .poundFileExpr(PoundFileExprSyntax(self)!) + case .poundFileIDExpr: + return .poundFileIDExpr(PoundFileIDExprSyntax(self)!) case .poundFilePathExpr: return .poundFilePathExpr(PoundFilePathExprSyntax(self)!) case .poundFunctionExpr: diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift index 4ae0807b20f..487a5083c2c 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift @@ -456,6 +456,23 @@ public enum SyntaxFactory { ], length: .zero, presence: .present)) return PoundFileExprSyntax(data) } + public static func makePoundFileIDExpr(poundFileID: TokenSyntax) -> PoundFileIDExprSyntax { + let layout: [RawSyntax?] = [ + poundFileID.raw, + ] + let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.poundFileIDExpr, + layout: layout, presence: SourcePresence.present) + let data = SyntaxData.forRoot(raw) + return PoundFileIDExprSyntax(data) + } + + public static func makeBlankPoundFileIDExpr() -> PoundFileIDExprSyntax { + let data = SyntaxData.forRoot(RawSyntax.create(kind: .poundFileIDExpr, + layout: [ + RawSyntax.missingToken(TokenKind.poundFileIDKeyword), + ], length: .zero, presence: .present)) + return PoundFileIDExprSyntax(data) + } public static func makePoundFilePathExpr(poundFilePath: TokenSyntax) -> PoundFilePathExprSyntax { let layout: [RawSyntax?] = [ poundFilePath.raw, @@ -5240,6 +5257,12 @@ public enum SyntaxFactory { leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia) } + public static func makePoundFileIDKeyword(leadingTrivia: Trivia = [], + trailingTrivia: Trivia = []) -> TokenSyntax { + return makeToken(.poundFileIDKeyword, presence: .present, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia) + } public static func makePoundFilePathKeyword(leadingTrivia: Trivia = [], trailingTrivia: Trivia = []) -> TokenSyntax { return makeToken(.poundFilePathKeyword, presence: .present, diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift index 664bbe1ad87..e75013764c7 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift @@ -48,6 +48,7 @@ internal enum SyntaxKind: CSyntaxKind { case exprList = 170 case poundLineExpr = 34 case poundFileExpr = 35 + case poundFileIDExpr = 247 case poundFilePathExpr = 240 case poundFunctionExpr = 36 case poundDsohandleExpr = 37 diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift index 33d5851fb3a..7f343da93fe 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift @@ -212,6 +212,13 @@ open class SyntaxRewriter { return ExprSyntax(visitChildren(node)) } + /// Visit a `PoundFileIDExprSyntax`. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + open func visit(_ node: PoundFileIDExprSyntax) -> ExprSyntax { + return ExprSyntax(visitChildren(node)) + } + /// Visit a `PoundFilePathExprSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -2022,6 +2029,16 @@ open class SyntaxRewriter { return Syntax(visit(node)) } + /// Implementation detail of visit(_:). Do not call directly. + private func visitImplPoundFileIDExprSyntax(_ data: SyntaxData) -> Syntax { + let node = PoundFileIDExprSyntax(data) + // Accessing _syntaxNode directly is faster than calling Syntax(node) + visitPre(node._syntaxNode) + defer { visitPost(node._syntaxNode) } + if let newNode = visitAny(node._syntaxNode) { return newNode } + return Syntax(visit(node)) + } + /// Implementation detail of visit(_:). Do not call directly. private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) -> Syntax { let node = PoundFilePathExprSyntax(data) @@ -4208,6 +4225,8 @@ open class SyntaxRewriter { return visitImplPoundLineExprSyntax case .poundFileExpr: return visitImplPoundFileExprSyntax + case .poundFileIDExpr: + return visitImplPoundFileIDExprSyntax case .poundFilePathExpr: return visitImplPoundFilePathExprSyntax case .poundFunctionExpr: @@ -4701,6 +4720,8 @@ open class SyntaxRewriter { return visitImplPoundLineExprSyntax(data) case .poundFileExpr: return visitImplPoundFileExprSyntax(data) + case .poundFileIDExpr: + return visitImplPoundFileIDExprSyntax(data) case .poundFilePathExpr: return visitImplPoundFilePathExprSyntax(data) case .poundFunctionExpr: diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift index 9e70be23cc4..08e05c3b32c 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift @@ -302,6 +302,16 @@ open class SyntaxVisitor { /// The function called after visiting `PoundFileExprSyntax` and its descendents. /// - node: the node we just finished visiting. open func visitPost(_ node: PoundFileExprSyntax) {} + /// Visiting `PoundFileIDExprSyntax` specifically. + /// - Parameter node: the node we are visiting. + /// - Returns: how should we continue visiting. + open func visit(_ node: PoundFileIDExprSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting `PoundFileIDExprSyntax` and its descendents. + /// - node: the node we just finished visiting. + open func visitPost(_ node: PoundFileIDExprSyntax) {} /// Visiting `PoundFilePathExprSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -2747,6 +2757,17 @@ open class SyntaxVisitor { visitPost(node) } + /// Implementation detail of doVisit(_:_:). Do not call directly. + private func visitImplPoundFileIDExprSyntax(_ data: SyntaxData) { + let node = PoundFileIDExprSyntax(data) + let needsChildren = (visit(node) == .visitChildren) + // Avoid calling into visitChildren if possible. + if needsChildren && node.raw.numberOfChildren > 0 { + visitChildren(node) + } + visitPost(node) + } + /// Implementation detail of doVisit(_:_:). Do not call directly. private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) { let node = PoundFilePathExprSyntax(data) @@ -5108,6 +5129,8 @@ open class SyntaxVisitor { visitImplPoundLineExprSyntax(data) case .poundFileExpr: visitImplPoundFileExprSyntax(data) + case .poundFileIDExpr: + visitImplPoundFileIDExprSyntax(data) case .poundFilePathExpr: visitImplPoundFilePathExprSyntax(data) case .poundFunctionExpr: diff --git a/Sources/SwiftSyntax/gyb_generated/TokenKind.swift b/Sources/SwiftSyntax/gyb_generated/TokenKind.swift index 2359195efa3..a39b53c6667 100644 --- a/Sources/SwiftSyntax/gyb_generated/TokenKind.swift +++ b/Sources/SwiftSyntax/gyb_generated/TokenKind.swift @@ -105,6 +105,7 @@ public enum TokenKind { case poundLineKeyword case poundSelectorKeyword case poundFileKeyword + case poundFileIDKeyword case poundFilePathKeyword case poundColumnKeyword case poundFunctionKeyword @@ -231,6 +232,7 @@ public enum TokenKind { case .poundLineKeyword: return "#line" case .poundSelectorKeyword: return "#selector" case .poundFileKeyword: return "#file" + case .poundFileIDKeyword: return "#fileID" case .poundFilePathKeyword: return "#filePath" case .poundColumnKeyword: return "#column" case .poundFunctionKeyword: return "#function" @@ -358,6 +360,7 @@ public enum TokenKind { case .poundLineKeyword: return true case .poundSelectorKeyword: return true case .poundFileKeyword: return true + case .poundFileIDKeyword: return true case .poundFilePathKeyword: return true case .poundColumnKeyword: return true case .poundFunctionKeyword: return true @@ -485,6 +488,7 @@ public enum TokenKind { case .poundLineKeyword: return "pound_line" case .poundSelectorKeyword: return "pound_selector" case .poundFileKeyword: return "pound_file" + case .poundFileIDKeyword: return "pound_fileID" case .poundFilePathKeyword: return "pound_filePath" case .poundColumnKeyword: return "pound_column" case .poundFunctionKeyword: return "pound_function" @@ -612,6 +616,7 @@ public enum TokenKind { case .poundLineKeyword: return SourceLength(utf8Length: 5) case .poundSelectorKeyword: return SourceLength(utf8Length: 9) case .poundFileKeyword: return SourceLength(utf8Length: 5) + case .poundFileIDKeyword: return SourceLength(utf8Length: 7) case .poundFilePathKeyword: return SourceLength(utf8Length: 9) case .poundColumnKeyword: return SourceLength(utf8Length: 7) case .poundFunctionKeyword: return SourceLength(utf8Length: 9) @@ -741,6 +746,7 @@ extension TokenKind: Equatable { case (.poundLineKeyword, .poundLineKeyword): return true case (.poundSelectorKeyword, .poundSelectorKeyword): return true case (.poundFileKeyword, .poundFileKeyword): return true + case (.poundFileIDKeyword, .poundFileIDKeyword): return true case (.poundFilePathKeyword, .poundFilePathKeyword): return true case (.poundColumnKeyword, .poundColumnKeyword): return true case (.poundFunctionKeyword, .poundFunctionKeyword): return true @@ -975,6 +981,8 @@ extension TokenKind { return .poundSelectorKeyword case 68: return .poundFileKeyword + case 122: + return .poundFileIDKeyword case 121: return .poundFilePathKeyword case 70: @@ -1233,6 +1241,8 @@ extension TokenKind { return false case 68: return false + case 122: + return false case 121: return false case 70: @@ -1394,6 +1404,7 @@ internal enum RawTokenKind: CTokenKind { case poundLineKeyword = 69 case poundSelectorKeyword = 73 case poundFileKeyword = 68 + case poundFileIDKeyword = 122 case poundFilePathKeyword = 121 case poundColumnKeyword = 70 case poundFunctionKeyword = 72 @@ -1708,6 +1719,9 @@ extension TokenKind { case .poundFileKeyword: let length = 5 return body(.init(kind: .poundFileKeyword, length: length)) + case .poundFileIDKeyword: + let length = 7 + return body(.init(kind: .poundFileIDKeyword, length: length)) case .poundFilePathKeyword: let length = 9 return body(.init(kind: .poundFilePathKeyword, length: length)) diff --git a/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift b/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift index 6e259172435..ad7bf8bd315 100644 --- a/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift +++ b/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift @@ -1002,6 +1002,79 @@ extension PoundFileExprSyntax: CustomReflectable { } } +// MARK: - PoundFileIDExprSyntax + +public struct PoundFileIDExprSyntax: ExprSyntaxProtocol, SyntaxHashable { + enum Cursor: Int { + case poundFileID + } + + public let _syntaxNode: Syntax + + /// Converts the given `Syntax` node to a `PoundFileIDExprSyntax` if possible. Returns + /// `nil` if the conversion is not possible. + public init?(_ syntax: Syntax) { + guard syntax.raw.kind == .poundFileIDExpr else { return nil } + self._syntaxNode = syntax + } + + /// Creates a `PoundFileIDExprSyntax` node from the given `SyntaxData`. This assumes + /// that the `SyntaxData` is of the correct kind. If it is not, the behaviour + /// is undefined. + internal init(_ data: SyntaxData) { + assert(data.raw.kind == .poundFileIDExpr) + self._syntaxNode = Syntax(data) + } + + public var syntaxNodeType: SyntaxProtocol.Type { + return Swift.type(of: self) + } + + public var poundFileID: TokenSyntax { + get { + let childData = data.child(at: Cursor.poundFileID, + parent: Syntax(self)) + return TokenSyntax(childData!) + } + set(value) { + self = withPoundFileID(value) + } + } + + /// Returns a copy of the receiver with its `poundFileID` replaced. + /// - param newChild: The new `poundFileID` to replace the node's + /// current `poundFileID`, if present. + public func withPoundFileID( + _ newChild: TokenSyntax?) -> PoundFileIDExprSyntax { + let raw = newChild?.raw ?? RawSyntax.missingToken(TokenKind.poundFileIDKeyword) + let newData = data.replacingChild(raw, at: Cursor.poundFileID) + return PoundFileIDExprSyntax(newData) + } + + + public func _validateLayout() { + let rawChildren = Array(RawSyntaxChildren(Syntax(self))) + assert(rawChildren.count == 1) + // Check child #0 child is TokenSyntax + assert(rawChildren[0].raw != nil) + if let raw = rawChildren[0].raw { + let info = rawChildren[0].syntaxInfo + let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info) + let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self)) + let syntaxChild = Syntax(syntaxData) + assert(syntaxChild.is(TokenSyntax.self)) + } + } +} + +extension PoundFileIDExprSyntax: CustomReflectable { + public var customMirror: Mirror { + return Mirror(self, children: [ + "poundFileID": Syntax(poundFileID).asProtocol(SyntaxProtocol.self), + ]) + } +} + // MARK: - PoundFilePathExprSyntax public struct PoundFilePathExprSyntax: ExprSyntaxProtocol, SyntaxHashable {