Skip to content

Commit ac32267

Browse files
committed
[ASTGen] Adjust for modeling of type specifiers as separate type nodes
Companion of swiftlang/swift-syntax#2433
1 parent 23519be commit ac32267

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

lib/ASTGen/Sources/ASTGen/Types.swift

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func isTypeMigrated(_ node: TypeSyntax) -> Bool {
3333
while true {
3434
switch current.kind {
3535
// Known implemented kinds.
36-
case .arrayType, .attributedType, .classRestrictionType, .compositionType,
36+
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constType,
3737
.someOrAnyType, .dictionaryType, .functionType, .identifierType,
38-
.implicitlyUnwrappedOptionalType, .memberType, .metatypeType,
38+
.implicitlyUnwrappedOptionalType, .isolatedType, .lifetimeSpecifiedType, .memberType, .metatypeType,
3939
.namedOpaqueReturnType, .optionalType, .packElementType,
40-
.packExpansionType, .suppressedType, .tupleType:
40+
.packExpansionType, .resultDependsOnType, .suppressedType, .tupleType:
4141
break
4242

4343
// Known unimplemented kinds.
@@ -73,6 +73,8 @@ extension ASTGenVisitor {
7373
return self.generate(classRestrictionType: node).asTypeRepr
7474
case .compositionType(let node):
7575
return self.generate(compositionType: node).asTypeRepr
76+
case .constType(let node):
77+
return self.generateTypeWithSpecifier(specifier: node.constKeyword, baseType: node.baseType)
7678
case .dictionaryType(let node):
7779
return self.generate(dictionaryType: node).asTypeRepr
7880
case .functionType(let node):
@@ -81,6 +83,12 @@ extension ASTGenVisitor {
8183
return self.generate(identifierType: node)
8284
case .implicitlyUnwrappedOptionalType(let node):
8385
return self.generate(implicitlyUnwrappedOptionalType: node).asTypeRepr
86+
case .isolatedType(let node):
87+
return self.generateTypeWithSpecifier(specifier: node.isolatedKeyword, baseType: node.baseType)
88+
case .lifetimeDependenceType(let node):
89+
preconditionFailure("TODO: Implement")
90+
case .lifetimeSpecifiedType(let node):
91+
return self.generateTypeWithSpecifier(specifier: node.lifetimeSpecifier, baseType: node.baseType)
8492
case .memberType(let node):
8593
return self.generate(memberType: node)
8694
case .metatypeType(let node):
@@ -95,6 +103,8 @@ extension ASTGenVisitor {
95103
return self.generate(packElementType: node).asTypeRepr
96104
case .packExpansionType(let node):
97105
return self.generate(packExpansionType: node).asTypeRepr
106+
case .resultDependsOnType(let node):
107+
return self.generateTypeWithSpecifier(specifier: node.resultDependsOnKeyword, baseType: node.baseType)
98108
case .someOrAnyType(let node):
99109
return self.generate(someOrAnyType: node)
100110
case .suppressedType(let node):
@@ -369,23 +379,24 @@ extension BridgedAttributedTypeSpecifier {
369379
}
370380

371381
extension ASTGenVisitor {
372-
func generate(attributedType node: AttributedTypeSyntax) -> BridgedTypeRepr {
373-
var type = generate(type: node.baseType)
382+
func generateTypeWithSpecifier(specifier: TokenSyntax, baseType: TypeSyntax) -> BridgedTypeRepr {
383+
var type = generate(type: baseType)
374384

375-
// Handle specifiers.
376-
if let specifier = node.specifier {
377-
if let kind = BridgedAttributedTypeSpecifier(from: specifier.keywordKind) {
378-
type =
379-
BridgedSpecifierTypeRepr.createParsed(
380-
self.ctx,
381-
base: type,
382-
specifier: kind,
383-
specifierLoc: self.generateSourceLoc(specifier)
384-
).asTypeRepr
385-
} else {
386-
self.diagnose(Diagnostic(node: specifier, message: UnexpectedTokenKindError(token: specifier)))
387-
}
385+
if let kind = BridgedAttributedTypeSpecifier(from: specifier.keywordKind) {
386+
return BridgedSpecifierTypeRepr.createParsed(
387+
self.ctx,
388+
base: type,
389+
specifier: kind,
390+
specifierLoc: self.generateSourceLoc(specifier)
391+
).asTypeRepr
392+
} else {
393+
self.diagnose(Diagnostic(node: specifier, message: UnexpectedTokenKindError(token: specifier)))
394+
return type
388395
}
396+
}
397+
398+
func generate(attributedType node: AttributedTypeSyntax) -> BridgedTypeRepr {
399+
var type = generate(type: node.baseType)
389400

390401
// Handle type attributes.
391402
if !node.attributes.isEmpty {

0 commit comments

Comments
 (0)