Skip to content

Commit ea1c73b

Browse files
committed
Remove CanImportExprSyntax as its related codes
1 parent bb0091f commit ea1c73b

21 files changed

+22
-1125
lines changed

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -192,61 +192,6 @@ public let EXPR_NODES: [Node] = [
192192
]
193193
),
194194

195-
// the canImport expr in if config expression
196-
Node(
197-
kind: .canImportExpr,
198-
base: .expr,
199-
nameForDiagnostics: "'canImport' expression",
200-
children: [
201-
Child(
202-
name: "CanImportKeyword",
203-
kind: .token(choices: [.keyword(text: "canImport")])
204-
),
205-
Child(
206-
name: "LeftParen",
207-
kind: .token(choices: [.token(.leftParen)])
208-
),
209-
Child(
210-
name: "ImportPath",
211-
kind: .token(choices: [.token(.identifier)])
212-
),
213-
Child(
214-
name: "VersionInfo",
215-
kind: .node(kind: .canImportVersionInfo),
216-
isOptional: true
217-
),
218-
Child(
219-
name: "RightParen",
220-
kind: .token(choices: [.token(.rightParen)])
221-
),
222-
]
223-
),
224-
225-
Node(
226-
kind: .canImportVersionInfo,
227-
base: .expr,
228-
nameForDiagnostics: nil,
229-
children: [
230-
Child(
231-
name: "Comma",
232-
kind: .token(choices: [.token(.comma)])
233-
),
234-
Child(
235-
name: "Label",
236-
kind: .token(choices: [.keyword(text: "_version"), .keyword(text: "_underlyingVersion")])
237-
),
238-
Child(
239-
name: "Colon",
240-
kind: .token(choices: [.token(.colon)])
241-
),
242-
Child(
243-
name: "Version",
244-
deprecatedName: "VersionTuple",
245-
kind: .node(kind: .versionTuple)
246-
),
247-
]
248-
),
249-
250195
// case-item -> pattern where-clause? ','?
251196
Node(
252197
kind: .switchCaseItem,

Sources/SwiftParser/Expressions.swift

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ extension Parser {
580580
forDirective: Bool,
581581
pattern: PatternContext
582582
) -> RawExprSyntax {
583-
let head = self.parsePrimaryExpression(pattern: pattern, forDirective: forDirective, flavor: flavor)
583+
let head = self.parsePrimaryExpression(pattern: pattern, flavor: flavor)
584584
guard !head.is(RawMissingExprSyntax.self) else {
585585
return head
586586
}
@@ -1079,15 +1079,8 @@ extension Parser {
10791079
/// Swift expression grammar.
10801080
mutating func parsePrimaryExpression(
10811081
pattern: PatternContext,
1082-
forDirective: Bool,
10831082
flavor: ExprFlavor
10841083
) -> RawExprSyntax {
1085-
if forDirective == true,
1086-
let directiveExpr = self.parsePrimaryExprForDirective()
1087-
{
1088-
return RawExprSyntax(directiveExpr)
1089-
}
1090-
10911084
switch self.at(anyIn: PrimaryExpressionStart.self) {
10921085
case (.integerLiteral, let handle)?:
10931086
let literal = self.eat(handle)
@@ -1229,18 +1222,6 @@ extension Parser {
12291222
return RawExprSyntax(RawMissingExprSyntax(arena: self.arena))
12301223
}
12311224
}
1232-
1233-
// try to parse a primary expression for a directive
1234-
mutating func parsePrimaryExprForDirective() -> RawExprSyntax? {
1235-
switch self.at(anyIn: CompilationCondition.self) {
1236-
case (.canImport, let handle)?:
1237-
return RawExprSyntax(self.parseCanImportExpression(handle))
1238-
1239-
// TODO: add case `swift` and `compiler` here
1240-
default:
1241-
return nil
1242-
}
1243-
}
12441225
}
12451226

12461227
extension Parser {
@@ -2348,52 +2329,6 @@ extension Parser {
23482329
}
23492330
}
23502331

2351-
// MARK: Platform Condition
2352-
extension Parser {
2353-
mutating func parseCanImportExpression(_ handle: TokenConsumptionHandle) -> RawExprSyntax {
2354-
let canImportKeyword = self.eat(handle)
2355-
2356-
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
2357-
2358-
let (unexpectedBeforeImportPath, importPath) = self.expect(.identifier)
2359-
2360-
var versionInfo: RawCanImportVersionInfoSyntax?
2361-
2362-
if let comma = self.consume(if: .comma) {
2363-
let (unexpectedBeforeLabel, label) = self.expect(anyIn: CanImportVersionInfoSyntax.LabelOptions.self, default: ._version)
2364-
let (unexpectedBeforeColon, colon) = self.expect(.colon)
2365-
2366-
let version = self.parseVersionTuple(maxComponentCount: 4)
2367-
2368-
versionInfo = RawCanImportVersionInfoSyntax(
2369-
comma: comma,
2370-
unexpectedBeforeLabel,
2371-
label: label,
2372-
unexpectedBeforeColon,
2373-
colon: colon,
2374-
version: version,
2375-
arena: self.arena
2376-
)
2377-
}
2378-
2379-
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
2380-
2381-
return RawExprSyntax(
2382-
RawCanImportExprSyntax(
2383-
canImportKeyword: canImportKeyword,
2384-
unexpectedBeforeLeftParen,
2385-
leftParen: leftParen,
2386-
unexpectedBeforeImportPath,
2387-
importPath: importPath,
2388-
versionInfo: versionInfo,
2389-
unexpectedBeforeRightParen,
2390-
rightParen: rightParen,
2391-
arena: self.arena
2392-
)
2393-
)
2394-
}
2395-
}
2396-
23972332
// MARK: Lookahead
23982333

23992334
extension Parser.Lookahead {

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -393,47 +393,6 @@ extension BooleanLiteralExprSyntax {
393393
}
394394
}
395395

396-
extension CanImportVersionInfoSyntax {
397-
@_spi(Diagnostics)
398-
public enum LabelOptions: TokenSpecSet {
399-
case _version
400-
case _underlyingVersion
401-
402-
init?(lexeme: Lexer.Lexeme) {
403-
switch PrepareForKeywordMatch(lexeme) {
404-
case TokenSpec(._version):
405-
self = ._version
406-
case TokenSpec(._underlyingVersion):
407-
self = ._underlyingVersion
408-
default:
409-
return nil
410-
}
411-
}
412-
413-
var spec: TokenSpec {
414-
switch self {
415-
case ._version:
416-
return .keyword(._version)
417-
case ._underlyingVersion:
418-
return .keyword(._underlyingVersion)
419-
}
420-
}
421-
422-
/// Returns a token that satisfies the `TokenSpec` of this case.
423-
///
424-
/// If the token kind of this spec has variable text, e.g. for an identifier, this returns a token with empty text.
425-
@_spi(Diagnostics)
426-
public var tokenSyntax: TokenSyntax {
427-
switch self {
428-
case ._version:
429-
return .keyword(._version)
430-
case ._underlyingVersion:
431-
return .keyword(._underlyingVersion)
432-
}
433-
}
434-
}
435-
}
436-
437396
extension ClosureCaptureSpecifierSyntax {
438397
@_spi(Diagnostics)
439398
public enum SpecifierOptions: TokenSpecSet {

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -610,50 +610,6 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
610610
return .visitChildren
611611
}
612612

613-
public override func visit(_ node: CanImportExprSyntax) -> SyntaxVisitorContinueKind {
614-
if shouldSkip(node) {
615-
return .skipChildren
616-
}
617-
618-
if let versionTuple = node.versionInfo?.version,
619-
let unexpectedVersionTuple = node.unexpectedBetweenVersionInfoAndRightParen
620-
{
621-
if versionTuple.major.isMissing {
622-
addDiagnostic(
623-
versionTuple,
624-
CannotParseVersionTuple(versionTuple: unexpectedVersionTuple),
625-
handledNodes: [versionTuple.id, unexpectedVersionTuple.id]
626-
)
627-
} else {
628-
addDiagnostic(
629-
unexpectedVersionTuple,
630-
.canImportWrongNumberOfParameter,
631-
handledNodes: [unexpectedVersionTuple.id]
632-
)
633-
}
634-
}
635-
636-
return .visitChildren
637-
}
638-
639-
public override func visit(_ node: CanImportVersionInfoSyntax) -> SyntaxVisitorContinueKind {
640-
if shouldSkip(node) {
641-
return .skipChildren
642-
}
643-
644-
if node.label.isMissing {
645-
addDiagnostic(
646-
node.label,
647-
.canImportWrongSecondParameterLabel,
648-
handledNodes: [node.label.id]
649-
)
650-
651-
handledNodes.append(contentsOf: [node.unexpectedBetweenLabelAndColon?.id, node.colon.id, node.version.id].compactMap { $0 })
652-
}
653-
654-
return .visitChildren
655-
}
656-
657613
public override func visit(_ node: ConditionElementSyntax) -> SyntaxVisitorContinueKind {
658614
if shouldSkip(node) {
659615
return .skipChildren

Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ extension DiagnosticMessage where Self == StaticParserError {
9393
public static var associatedTypeCannotUsePack: Self {
9494
.init("associated types cannot be variadic")
9595
}
96-
public static var canImportWrongSecondParameterLabel: Self {
97-
.init("2nd parameter of canImport should be labeled as _version or _underlyingVersion")
98-
}
99-
public static var canImportWrongNumberOfParameter: Self {
100-
.init("canImport can take only two parameters")
101-
}
10296
public static var caseOutsideOfSwitchOrEnum: Self {
10397
.init("'case' can only appear inside a 'switch' statement or 'enum' declaration")
10498
}

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ extension SyntaxKind {
6161
return "'_borrow' expression"
6262
case .breakStmt:
6363
return "'break' statement"
64-
case .canImportExpr:
65-
return "'canImport' expression"
6664
case .catchClauseList:
6765
return "'catch' clause"
6866
case .catchClause:

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
101101
- <doc:SwiftSyntax/BinaryOperatorExprSyntax>
102102
- <doc:SwiftSyntax/BooleanLiteralExprSyntax>
103103
- <doc:SwiftSyntax/BorrowExprSyntax>
104-
- <doc:SwiftSyntax/CanImportExprSyntax>
105-
- <doc:SwiftSyntax/CanImportVersionInfoSyntax>
106104
- <doc:SwiftSyntax/ClosureExprSyntax>
107105
- <doc:SwiftSyntax/ConsumeExprSyntax>
108106
- <doc:SwiftSyntax/CopyExprSyntax>

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -351,46 +351,6 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
351351
return "label"
352352
case \BreakStmtSyntax.unexpectedAfterLabel:
353353
return "unexpectedAfterLabel"
354-
case \CanImportExprSyntax.unexpectedBeforeCanImportKeyword:
355-
return "unexpectedBeforeCanImportKeyword"
356-
case \CanImportExprSyntax.canImportKeyword:
357-
return "canImportKeyword"
358-
case \CanImportExprSyntax.unexpectedBetweenCanImportKeywordAndLeftParen:
359-
return "unexpectedBetweenCanImportKeywordAndLeftParen"
360-
case \CanImportExprSyntax.leftParen:
361-
return "leftParen"
362-
case \CanImportExprSyntax.unexpectedBetweenLeftParenAndImportPath:
363-
return "unexpectedBetweenLeftParenAndImportPath"
364-
case \CanImportExprSyntax.importPath:
365-
return "importPath"
366-
case \CanImportExprSyntax.unexpectedBetweenImportPathAndVersionInfo:
367-
return "unexpectedBetweenImportPathAndVersionInfo"
368-
case \CanImportExprSyntax.versionInfo:
369-
return "versionInfo"
370-
case \CanImportExprSyntax.unexpectedBetweenVersionInfoAndRightParen:
371-
return "unexpectedBetweenVersionInfoAndRightParen"
372-
case \CanImportExprSyntax.rightParen:
373-
return "rightParen"
374-
case \CanImportExprSyntax.unexpectedAfterRightParen:
375-
return "unexpectedAfterRightParen"
376-
case \CanImportVersionInfoSyntax.unexpectedBeforeComma:
377-
return "unexpectedBeforeComma"
378-
case \CanImportVersionInfoSyntax.comma:
379-
return "comma"
380-
case \CanImportVersionInfoSyntax.unexpectedBetweenCommaAndLabel:
381-
return "unexpectedBetweenCommaAndLabel"
382-
case \CanImportVersionInfoSyntax.label:
383-
return "label"
384-
case \CanImportVersionInfoSyntax.unexpectedBetweenLabelAndColon:
385-
return "unexpectedBetweenLabelAndColon"
386-
case \CanImportVersionInfoSyntax.colon:
387-
return "colon"
388-
case \CanImportVersionInfoSyntax.unexpectedBetweenColonAndVersion:
389-
return "unexpectedBetweenColonAndVersion"
390-
case \CanImportVersionInfoSyntax.version:
391-
return "version"
392-
case \CanImportVersionInfoSyntax.unexpectedAfterVersion:
393-
return "unexpectedAfterVersion"
394354
case \CatchClauseSyntax.unexpectedBeforeCatchKeyword:
395355
return "unexpectedBeforeCatchKeyword"
396356
case \CatchClauseSyntax.catchKeyword:

0 commit comments

Comments
 (0)