From d876fe185a355594cfbcdea294071a26be4158b9 Mon Sep 17 00:00:00 2001 From: Brent Royal-Gordon Date: Wed, 4 Dec 2019 16:58:30 -0800 Subject: [PATCH] Add new syntax nodes for #filePath --- 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 | 19 +++++ .../gyb_generated/SyntaxVisitor.swift | 23 +++++++ .../SwiftSyntax/gyb_generated/TokenKind.swift | 14 ++++ .../syntax_nodes/SyntaxExprNodes.swift | 69 +++++++++++++++++++ 12 files changed, 210 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftSyntax/gyb_generated/Misc.swift b/Sources/SwiftSyntax/gyb_generated/Misc.swift index 19f5bf5fded..9b6820d3b38 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 isPoundFilePathExpr: Bool { return raw.kind == .poundFilePathExpr } + public var asPoundFilePathExpr: PoundFilePathExprSyntax? { + guard isPoundFilePathExpr else { return nil } + return PoundFilePathExprSyntax(asSyntaxData) + } + public var isPoundFunctionExpr: Bool { return raw.kind == .poundFunctionExpr } public var asPoundFunctionExpr: PoundFunctionExprSyntax? { guard isPoundFunctionExpr else { return nil } @@ -1471,6 +1477,8 @@ extension Syntax { return node case .poundFileExpr(let node): return node + case .poundFilePathExpr(let node): + return node case .poundFunctionExpr(let node): return node case .poundDsohandleExpr(let node): @@ -1880,6 +1888,6 @@ extension Syntax { extension SyntaxParser { static func verifyNodeDeclarationHash() -> Bool { return String(cString: swiftparse_syntax_structure_versioning_identifier()!) == - "3924247553615556843" + "7184602491276114819" } } diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift index 60b42c48b19..4749dd3ed6d 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: PoundFilePathExprSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + override open func visitPost(_ node: PoundFilePathExprSyntax) { + visitAnyPost(node._syntaxNode) + } override open func visit(_ node: PoundFunctionExprSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift index d525f091203..a29b53fe15b 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift @@ -146,7 +146,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, .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, .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 @@ -160,7 +160,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, .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, .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 16a9ae4b87c..1326bbec37b 100644 --- a/Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift +++ b/Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift @@ -677,6 +677,44 @@ extension PoundFileExprSyntax { } } +public struct PoundFilePathExprSyntaxBuilder { + private var layout = + Array(repeating: nil, count: 1) + + internal init() {} + + public mutating func usePoundFilePath(_ node: TokenSyntax) { + let idx = PoundFilePathExprSyntax.Cursor.poundFilePath.rawValue + layout[idx] = node.raw + } + + internal mutating func buildData() -> SyntaxData { + if (layout[0] == nil) { + layout[0] = RawSyntax.missingToken(TokenKind.poundFilePathKeyword) + } + + return .forRoot(RawSyntax.createAndCalcLength(kind: .poundFilePathExpr, + layout: layout, presence: .present)) + } +} + +extension PoundFilePathExprSyntax { + /// Creates a `PoundFilePathExprSyntax` 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 `PoundFilePathExprSyntaxBuilder` which you can use to + /// incrementally build the structure of the node. + /// - Returns: A `PoundFilePathExprSyntax` with all the fields populated in the builder + /// closure. + public init(_ build: (inout PoundFilePathExprSyntaxBuilder) -> Void) { + var builder = PoundFilePathExprSyntaxBuilder() + build(&builder) + let data = builder.buildData() + self.init(data) + } +} + public struct PoundFunctionExprSyntaxBuilder { 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 b9156831b5b..23860778ccc 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 .poundFilePathKeyword: + return .keyword case .poundColumnKeyword: return .keyword case .poundFunctionKeyword: diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift index f042e716627..be451b86f6f 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 poundFilePathExpr(PoundFilePathExprSyntax) case poundFunctionExpr(PoundFunctionExprSyntax) case poundDsohandleExpr(PoundDsohandleExprSyntax) case symbolicReferenceExpr(SymbolicReferenceExprSyntax) @@ -323,6 +324,8 @@ public extension Syntax { return .poundLineExpr(PoundLineExprSyntax(self)!) case .poundFileExpr: return .poundFileExpr(PoundFileExprSyntax(self)!) + case .poundFilePathExpr: + return .poundFilePathExpr(PoundFilePathExprSyntax(self)!) case .poundFunctionExpr: return .poundFunctionExpr(PoundFunctionExprSyntax(self)!) case .poundDsohandleExpr: diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift index e5f734381e4..fced1b6d07e 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 makePoundFilePathExpr(poundFilePath: TokenSyntax) -> PoundFilePathExprSyntax { + let layout: [RawSyntax?] = [ + poundFilePath.raw, + ] + let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.poundFilePathExpr, + layout: layout, presence: SourcePresence.present) + let data = SyntaxData.forRoot(raw) + return PoundFilePathExprSyntax(data) + } + + public static func makeBlankPoundFilePathExpr() -> PoundFilePathExprSyntax { + let data = SyntaxData.forRoot(RawSyntax.create(kind: .poundFilePathExpr, + layout: [ + RawSyntax.missingToken(TokenKind.poundFilePathKeyword), + ], length: .zero, presence: .present)) + return PoundFilePathExprSyntax(data) + } public static func makePoundFunctionExpr(poundFunction: TokenSyntax) -> PoundFunctionExprSyntax { let layout: [RawSyntax?] = [ poundFunction.raw, @@ -5130,6 +5147,12 @@ public enum SyntaxFactory { leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia) } + public static func makePoundFilePathKeyword(leadingTrivia: Trivia = [], + trailingTrivia: Trivia = []) -> TokenSyntax { + return makeToken(.poundFilePathKeyword, presence: .present, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia) + } public static func makePoundColumnKeyword(leadingTrivia: Trivia = [], trailingTrivia: Trivia = []) -> TokenSyntax { return makeToken(.poundColumnKeyword, presence: .present, diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift index c6c532d6b87..671784a2ecb 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 poundFilePathExpr = 240 case poundFunctionExpr = 36 case poundDsohandleExpr = 37 case symbolicReferenceExpr = 38 diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift index 1c06e75d1af..060e9c31072 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 `PoundFilePathExprSyntax`. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + open func visit(_ node: PoundFilePathExprSyntax) -> ExprSyntax { + return ExprSyntax(visitChildren(node)) + } + /// Visit a `PoundFunctionExprSyntax`. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -1980,6 +1987,16 @@ open class SyntaxRewriter { return Syntax(visit(node)) } + /// Implementation detail of visit(_:). Do not call directly. + private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) -> Syntax { + let node = PoundFilePathExprSyntax(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 visitImplPoundFunctionExprSyntax(_ data: SyntaxData) -> Syntax { let node = PoundFunctionExprSyntax(data) @@ -4075,6 +4092,8 @@ open class SyntaxRewriter { return visitImplPoundLineExprSyntax(data) case .poundFileExpr: return visitImplPoundFileExprSyntax(data) + case .poundFilePathExpr: + return visitImplPoundFilePathExprSyntax(data) case .poundFunctionExpr: return visitImplPoundFunctionExprSyntax(data) case .poundDsohandleExpr: diff --git a/Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift index 0a42e6131f8..748f9dab416 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 `PoundFilePathExprSyntax` specifically. + /// - Parameter node: the node we are visiting. + /// - Returns: how should we continue visiting. + open func visit(_ node: PoundFilePathExprSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting `PoundFilePathExprSyntax` and its descendents. + /// - node: the node we just finished visiting. + open func visitPost(_ node: PoundFilePathExprSyntax) {} /// Visiting `PoundFunctionExprSyntax` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -2687,6 +2697,17 @@ open class SyntaxVisitor { visitPost(node) } + /// Implementation detail of doVisit(_:_:). Do not call directly. + private func visitImplPoundFilePathExprSyntax(_ data: SyntaxData) { + let node = PoundFilePathExprSyntax(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 visitImplPoundFunctionExprSyntax(_ data: SyntaxData) { let node = PoundFunctionExprSyntax(data) @@ -4982,6 +5003,8 @@ open class SyntaxVisitor { visitImplPoundLineExprSyntax(data) case .poundFileExpr: visitImplPoundFileExprSyntax(data) + case .poundFilePathExpr: + visitImplPoundFilePathExprSyntax(data) case .poundFunctionExpr: visitImplPoundFunctionExprSyntax(data) case .poundDsohandleExpr: diff --git a/Sources/SwiftSyntax/gyb_generated/TokenKind.swift b/Sources/SwiftSyntax/gyb_generated/TokenKind.swift index af1a10206d5..2359195efa3 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 poundFilePathKeyword case poundColumnKeyword case poundFunctionKeyword case poundDsohandleKeyword @@ -230,6 +231,7 @@ public enum TokenKind { case .poundLineKeyword: return "#line" case .poundSelectorKeyword: return "#selector" case .poundFileKeyword: return "#file" + case .poundFilePathKeyword: return "#filePath" case .poundColumnKeyword: return "#column" case .poundFunctionKeyword: return "#function" case .poundDsohandleKeyword: return "#dsohandle" @@ -356,6 +358,7 @@ public enum TokenKind { case .poundLineKeyword: return true case .poundSelectorKeyword: return true case .poundFileKeyword: return true + case .poundFilePathKeyword: return true case .poundColumnKeyword: return true case .poundFunctionKeyword: return true case .poundDsohandleKeyword: return true @@ -482,6 +485,7 @@ public enum TokenKind { case .poundLineKeyword: return "pound_line" case .poundSelectorKeyword: return "pound_selector" case .poundFileKeyword: return "pound_file" + case .poundFilePathKeyword: return "pound_filePath" case .poundColumnKeyword: return "pound_column" case .poundFunctionKeyword: return "pound_function" case .poundDsohandleKeyword: return "pound_dsohandle" @@ -608,6 +612,7 @@ public enum TokenKind { case .poundLineKeyword: return SourceLength(utf8Length: 5) case .poundSelectorKeyword: return SourceLength(utf8Length: 9) case .poundFileKeyword: return SourceLength(utf8Length: 5) + case .poundFilePathKeyword: return SourceLength(utf8Length: 9) case .poundColumnKeyword: return SourceLength(utf8Length: 7) case .poundFunctionKeyword: return SourceLength(utf8Length: 9) case .poundDsohandleKeyword: return SourceLength(utf8Length: 10) @@ -736,6 +741,7 @@ extension TokenKind: Equatable { case (.poundLineKeyword, .poundLineKeyword): return true case (.poundSelectorKeyword, .poundSelectorKeyword): return true case (.poundFileKeyword, .poundFileKeyword): return true + case (.poundFilePathKeyword, .poundFilePathKeyword): return true case (.poundColumnKeyword, .poundColumnKeyword): return true case (.poundFunctionKeyword, .poundFunctionKeyword): return true case (.poundDsohandleKeyword, .poundDsohandleKeyword): return true @@ -969,6 +975,8 @@ extension TokenKind { return .poundSelectorKeyword case 68: return .poundFileKeyword + case 121: + return .poundFilePathKeyword case 70: return .poundColumnKeyword case 72: @@ -1225,6 +1233,8 @@ extension TokenKind { return false case 68: return false + case 121: + return false case 70: return false case 72: @@ -1384,6 +1394,7 @@ internal enum RawTokenKind: CTokenKind { case poundLineKeyword = 69 case poundSelectorKeyword = 73 case poundFileKeyword = 68 + case poundFilePathKeyword = 121 case poundColumnKeyword = 70 case poundFunctionKeyword = 72 case poundDsohandleKeyword = 71 @@ -1697,6 +1708,9 @@ extension TokenKind { case .poundFileKeyword: let length = 5 return body(.init(kind: .poundFileKeyword, length: length)) + case .poundFilePathKeyword: + let length = 9 + return body(.init(kind: .poundFilePathKeyword, length: length)) case .poundColumnKeyword: let length = 7 return body(.init(kind: .poundColumnKeyword, length: length)) diff --git a/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift b/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift index 71f5d52754e..eb8202e9d46 100644 --- a/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift +++ b/Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift @@ -954,6 +954,75 @@ extension PoundFileExprSyntax: CustomReflectable { } } +// MARK: - PoundFilePathExprSyntax + +public struct PoundFilePathExprSyntax: ExprSyntaxProtocol, SyntaxHashable { + enum Cursor: Int { + case poundFilePath + } + + public let _syntaxNode: Syntax + + /// Converts the given `Syntax` node to a `PoundFilePathExprSyntax` if possible. Returns + /// `nil` if the conversion is not possible. + public init?(_ syntax: Syntax) { + guard syntax.raw.kind == .poundFilePathExpr else { return nil } + self._syntaxNode = syntax + } + + /// Creates a `PoundFilePathExprSyntax` 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 == .poundFilePathExpr) + self._syntaxNode = Syntax(data) + } + + public var poundFilePath: TokenSyntax { + get { + let childData = data.child(at: Cursor.poundFilePath, + parent: Syntax(self)) + return TokenSyntax(childData!) + } + set(value) { + self = withPoundFilePath(value) + } + } + + /// Returns a copy of the receiver with its `poundFilePath` replaced. + /// - param newChild: The new `poundFilePath` to replace the node's + /// current `poundFilePath`, if present. + public func withPoundFilePath( + _ newChild: TokenSyntax?) -> PoundFilePathExprSyntax { + let raw = newChild?.raw ?? RawSyntax.missingToken(TokenKind.poundFilePathKeyword) + let newData = data.replacingChild(raw, at: Cursor.poundFilePath) + return PoundFilePathExprSyntax(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 PoundFilePathExprSyntax: CustomReflectable { + public var customMirror: Mirror { + return Mirror(self, children: [ + "poundFilePath": Syntax(poundFilePath).asProtocol(SyntaxProtocol.self), + ]) + } +} + // MARK: - PoundFunctionExprSyntax public struct PoundFunctionExprSyntax: ExprSyntaxProtocol, SyntaxHashable {