-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This replaces most use case of `keyPathInParent` and `SyntaxNodeStructure.layout`. Since getting and comparing `KeyPath` is not trivial, `keyPathInParent` were suffered from performance issue, Newly introduced `SyntaxProtocol.propertyInParent` is trivial, and comparing it with a SyntaxLayoutProperty is also trivial.
- Loading branch information
Showing
35 changed files
with
13,356 additions
and
4,196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
...eration/Sources/generate-swift-syntax/templates/swiftsyntax/ChildNameForKeyPathFile.swift
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
...tion/Sources/generate-swift-syntax/templates/swiftsyntax/ConcreteSyntaxPropertyFile.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SyntaxSupport | ||
import Utils | ||
|
||
let concreteSyntaxPropertyFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { | ||
DeclSyntax( | ||
""" | ||
extension ConcreteSyntaxProperty { | ||
fileprivate init(_ index: Int) { | ||
self.index = .init(index) | ||
} | ||
} | ||
""" | ||
) | ||
|
||
for node in NON_BASE_SYNTAX_NODES { | ||
if let layoutNode = node.layoutNode { | ||
try! ExtensionDeclSyntax( | ||
"\(node.apiAttributes())extension ConcreteSyntaxProperty where Base == \(node.kind.syntaxType)" | ||
) { | ||
for (index, child) in layoutNode.children.enumerated() { | ||
let childType: TypeSyntax = | ||
child.kind.isNodeChoicesEmpty | ||
? child.syntaxNodeKind.syntaxType | ||
: "\(node.kind.syntaxType).\(child.syntaxChoicesType)" | ||
let type = child.isOptional ? TypeSyntax("\(childType)?") : TypeSyntax("\(childType)") | ||
DeclSyntax( | ||
""" | ||
public static var \(child.varDeclName): ConcreteSyntaxProperty<\(node.kind.syntaxType), \(type)> { | ||
.init(\(raw: index)) | ||
} | ||
""" | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxLayoutPropertyName.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SyntaxSupport | ||
import Utils | ||
|
||
let syntaxLayoutPropertyNameFile = try! SourceFileSyntax(leadingTrivia: copyrightHeader) { | ||
try ExtensionDeclSyntax("extension SyntaxLayoutProperty") { | ||
try VariableDeclSyntax( | ||
""" | ||
/// Property name if this is a valid property. | ||
/// 'nil' if the `syntaxKind` is not a layout syntax, or the index is out of range. | ||
@_spi(RawSyntax) | ||
public var name: String? | ||
""" | ||
) { | ||
try SwitchExprSyntax("switch (self.syntaxKind, self.index.value)") { | ||
for node in NON_BASE_SYNTAX_NODES { | ||
if let layoutNode = node.layoutNode { | ||
for (index, child) in layoutNode.children.enumerated() { | ||
SwitchCaseSyntax("case (.\(node.enumCaseCallName), \(literal: index)):") { | ||
StmtSyntax("return \(literal: child.identifier.description)") | ||
} | ||
} | ||
} | ||
} | ||
SwitchCaseSyntax("default: return nil") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.