Skip to content

Commit 019a02d

Browse files
committed
redo parsing so it's within parseType to match C++ parser
1 parent 3e3bd6a commit 019a02d

File tree

20 files changed

+390
-93
lines changed

20 files changed

+390
-93
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,14 +1029,6 @@ public let DECL_NODES: [Node] = [
10291029
"WithTrailingComma"
10301030
],
10311031
children: [
1032-
/// Indicates whether the 'without' operator was applied to the type to
1033-
/// indicate the suppression of implicit conformance to this type.
1034-
/// This child stores the token representing the 'without' operator.
1035-
Child(
1036-
name: "WithoutTilde",
1037-
kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")]),
1038-
isOptional: true
1039-
),
10401032
Child(
10411033
name: "TypeName",
10421034
kind: .node(kind: "Type")

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,23 @@ public let TYPE_NODES: [Node] = [
349349
]
350350
),
351351

352+
// suppressed-type -> '~' type
353+
Node(
354+
name: "SuppressedType",
355+
nameForDiagnostics: "suppressed type conformance",
356+
kind: "Type",
357+
children: [
358+
Child(
359+
name: "WithoutTilde",
360+
kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")])
361+
),
362+
Child(
363+
name: "PatternType",
364+
kind: .node(kind: "Type")
365+
),
366+
]
367+
),
368+
352369
// pack-expansion-type -> type '...'
353370
Node(
354371
name: "PackExpansionType",

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ extension Parser {
497497
let unexpectedBeforeInherited: RawUnexpectedNodesSyntax?
498498
let inherited: RawTypeSyntax?
499499
if colon != nil {
500-
if self.at(.identifier, .keyword(.protocol), .keyword(.Any)) {
500+
if self.at(.identifier, .keyword(.protocol), .keyword(.Any)) || self.atContextualPunctuator("~") {
501501
unexpectedBeforeInherited = nil
502502
inherited = self.parseType()
503503
} else if let classKeyword = self.consume(if: .keyword(.class)) {

Sources/SwiftParser/Nominals.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ extension Parser {
279279
var keepGoing: RawTokenSyntax? = nil
280280
var loopProgress = LoopProgressCondition()
281281
repeat {
282-
var withoutToken: RawTokenSyntax? = nil
283282
let type: RawTypeSyntax
284283
if let classKeyword = self.consume(if: .keyword(.class)) {
285284
type = RawTypeSyntax(
@@ -289,14 +288,12 @@ extension Parser {
289288
)
290289
)
291290
} else {
292-
withoutToken = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator)
293291
type = self.parseType()
294292
}
295293

296294
keepGoing = self.consume(if: .comma)
297295
elements.append(
298296
RawInheritedTypeSyntax(
299-
withoutTilde: withoutToken,
300297
typeName: type,
301298
trailingComma: keepGoing,
302299
arena: self.arena

Sources/SwiftParser/Types.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ extension Parser {
3737
)
3838
}
3939

40+
// Parse without operator preceding a type '~ T'.
41+
if let withoutTilde = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator) {
42+
let type = self.parseTypeScalar(misplacedSpecifiers: misplacedSpecifiers)
43+
return RawTypeSyntax(
44+
RawSuppressedTypeSyntax(
45+
withoutTilde: withoutTilde,
46+
patternType: type,
47+
arena: self.arena
48+
)
49+
)
50+
}
51+
4052
return self.parseTypeScalar(misplacedSpecifiers: misplacedSpecifiers)
4153
}
4254

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ extension SyntaxKind {
341341
return "subscript"
342342
case .subscriptExpr:
343343
return "subscript"
344+
case .suppressedType:
345+
return "suppressed type conformance"
344346
case .switchCase:
345347
return "switch case"
346348
case .switchExpr:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
186186
- <doc:SwiftSyntax/PackExpansionTypeSyntax>
187187
- <doc:SwiftSyntax/PackReferenceTypeSyntax>
188188
- <doc:SwiftSyntax/SimpleTypeIdentifierSyntax>
189+
- <doc:SwiftSyntax/SuppressedTypeSyntax>
189190
- <doc:SwiftSyntax/TupleTypeSyntax>
190191

191192
### Collections

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,12 +1712,8 @@ internal func childName(_ keyPath: AnyKeyPath) -> String? {
17121712
return "rightOperand"
17131713
case \InfixOperatorExprSyntax.unexpectedAfterRightOperand:
17141714
return "unexpectedAfterRightOperand"
1715-
case \InheritedTypeSyntax.unexpectedBeforeWithoutTilde:
1716-
return "unexpectedBeforeWithoutTilde"
1717-
case \InheritedTypeSyntax.withoutTilde:
1718-
return "withoutTilde"
1719-
case \InheritedTypeSyntax.unexpectedBetweenWithoutTildeAndTypeName:
1720-
return "unexpectedBetweenWithoutTildeAndTypeName"
1715+
case \InheritedTypeSyntax.unexpectedBeforeTypeName:
1716+
return "unexpectedBeforeTypeName"
17211717
case \InheritedTypeSyntax.typeName:
17221718
return "typeName"
17231719
case \InheritedTypeSyntax.unexpectedBetweenTypeNameAndTrailingComma:
@@ -2848,6 +2844,16 @@ internal func childName(_ keyPath: AnyKeyPath) -> String? {
28482844
return "superKeyword"
28492845
case \SuperRefExprSyntax.unexpectedAfterSuperKeyword:
28502846
return "unexpectedAfterSuperKeyword"
2847+
case \SuppressedTypeSyntax.unexpectedBeforeWithoutTilde:
2848+
return "unexpectedBeforeWithoutTilde"
2849+
case \SuppressedTypeSyntax.withoutTilde:
2850+
return "withoutTilde"
2851+
case \SuppressedTypeSyntax.unexpectedBetweenWithoutTildeAndPatternType:
2852+
return "unexpectedBetweenWithoutTildeAndPatternType"
2853+
case \SuppressedTypeSyntax.patternType:
2854+
return "patternType"
2855+
case \SuppressedTypeSyntax.unexpectedAfterPatternType:
2856+
return "unexpectedAfterPatternType"
28512857
case \SwitchCaseLabelSyntax.unexpectedBeforeCaseKeyword:
28522858
return "unexpectedBeforeCaseKeyword"
28532859
case \SwitchCaseLabelSyntax.caseKeyword:

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
18691869
visitAnyPost(node._syntaxNode)
18701870
}
18711871

1872+
override open func visit(_ node: SuppressedTypeSyntax) -> SyntaxVisitorContinueKind {
1873+
return visitAny(node._syntaxNode)
1874+
}
1875+
1876+
override open func visitPost(_ node: SuppressedTypeSyntax) {
1877+
visitAnyPost(node._syntaxNode)
1878+
}
1879+
18721880
override open func visit(_ node: SwitchCaseLabelSyntax) -> SyntaxVisitorContinueKind {
18731881
return visitAny(node._syntaxNode)
18741882
}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
610610

611611
public init?<S: SyntaxProtocol>(_ node: S) {
612612
switch node.raw.kind {
613-
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .tupleType:
613+
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .suppressedType, .tupleType:
614614
self._syntaxNode = node._syntaxNode
615615
default:
616616
return nil
@@ -622,7 +622,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
622622
/// is undefined.
623623
internal init(_ data: SyntaxData) {
624624
switch data.raw.kind {
625-
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .tupleType:
625+
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .suppressedType, .tupleType:
626626
break
627627
default:
628628
preconditionFailure("Unable to create TypeSyntax from \(data.raw.kind)")
@@ -674,6 +674,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
674674
.node(PackExpansionTypeSyntax.self),
675675
.node(PackReferenceTypeSyntax.self),
676676
.node(SimpleTypeIdentifierSyntax.self),
677+
.node(SuppressedTypeSyntax.self),
677678
.node(TupleTypeSyntax.self)
678679
])
679680
}
@@ -910,6 +911,7 @@ extension Syntax {
910911
.node(SubscriptDeclSyntax.self),
911912
.node(SubscriptExprSyntax.self),
912913
.node(SuperRefExprSyntax.self),
914+
.node(SuppressedTypeSyntax.self),
913915
.node(SwitchCaseLabelSyntax.self),
914916
.node(SwitchCaseListSyntax.self),
915917
.node(SwitchCaseSyntax.self),

0 commit comments

Comments
 (0)