Skip to content

SwiftSyntax update for "Shorten #file and add #filePath (behind an experimental flag)" (apple/swift#25656) #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/SwiftSyntax/gyb_generated/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -1880,6 +1888,6 @@ extension Syntax {
extension SyntaxParser {
static func verifyNodeDeclarationHash() -> Bool {
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
"3924247553615556843"
"7184602491276114819"
}
}
7 changes: 7 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)")
Expand Down
38 changes: 38 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,44 @@ extension PoundFileExprSyntax {
}
}

public struct PoundFilePathExprSyntaxBuilder {
private var layout =
Array<RawSyntax?>(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<RawSyntax?>(repeating: nil, count: 1)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxClassification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ extension RawTokenKind {
return .keyword
case .poundFileKeyword:
return .keyword
case .poundFilePathKeyword:
return .keyword
case .poundColumnKeyword:
return .keyword
case .poundFunctionKeyword:
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -4982,6 +5003,8 @@ open class SyntaxVisitor {
visitImplPoundLineExprSyntax(data)
case .poundFileExpr:
visitImplPoundFileExprSyntax(data)
case .poundFilePathExpr:
visitImplPoundFilePathExprSyntax(data)
case .poundFunctionExpr:
visitImplPoundFunctionExprSyntax(data)
case .poundDsohandleExpr:
Expand Down
14 changes: 14 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/TokenKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public enum TokenKind {
case poundLineKeyword
case poundSelectorKeyword
case poundFileKeyword
case poundFilePathKeyword
case poundColumnKeyword
case poundFunctionKeyword
case poundDsohandleKeyword
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -969,6 +975,8 @@ extension TokenKind {
return .poundSelectorKeyword
case 68:
return .poundFileKeyword
case 121:
return .poundFilePathKeyword
case 70:
return .poundColumnKeyword
case 72:
Expand Down Expand Up @@ -1225,6 +1233,8 @@ extension TokenKind {
return false
case 68:
return false
case 121:
return false
case 70:
return false
case 72:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Loading