Skip to content

[ASTGen] Adjust for modeling of type specifiers as separate type nodes #71408

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

Closed
Closed
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
47 changes: 29 additions & 18 deletions lib/ASTGen/Sources/ASTGen/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func isTypeMigrated(_ node: TypeSyntax) -> Bool {
while true {
switch current.kind {
// Known implemented kinds.
case .arrayType, .attributedType, .classRestrictionType, .compositionType,
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constType,
.someOrAnyType, .dictionaryType, .functionType, .identifierType,
.implicitlyUnwrappedOptionalType, .memberType, .metatypeType,
.implicitlyUnwrappedOptionalType, .isolatedType, .lifetimeSpecifiedType, .memberType, .metatypeType,
.namedOpaqueReturnType, .optionalType, .packElementType,
.packExpansionType, .suppressedType, .tupleType:
.packExpansionType, .resultDependsOnType, .suppressedType, .tupleType:
break

// Known unimplemented kinds.
Expand Down Expand Up @@ -73,6 +73,8 @@ extension ASTGenVisitor {
return self.generate(classRestrictionType: node).asTypeRepr
case .compositionType(let node):
return self.generate(compositionType: node).asTypeRepr
case .constType(let node):
return self.generateTypeWithSpecifier(specifier: node.constKeyword, baseType: node.baseType)
case .dictionaryType(let node):
return self.generate(dictionaryType: node).asTypeRepr
case .functionType(let node):
Expand All @@ -81,6 +83,12 @@ extension ASTGenVisitor {
return self.generate(identifierType: node)
case .implicitlyUnwrappedOptionalType(let node):
return self.generate(implicitlyUnwrappedOptionalType: node).asTypeRepr
case .isolatedType(let node):
return self.generateTypeWithSpecifier(specifier: node.isolatedKeyword, baseType: node.baseType)
case .lifetimeDependenceType(let node):
preconditionFailure("TODO: Implement")
case .lifetimeSpecifiedType(let node):
return self.generateTypeWithSpecifier(specifier: node.lifetimeSpecifier, baseType: node.baseType)
case .memberType(let node):
return self.generate(memberType: node)
case .metatypeType(let node):
Expand All @@ -95,6 +103,8 @@ extension ASTGenVisitor {
return self.generate(packElementType: node).asTypeRepr
case .packExpansionType(let node):
return self.generate(packExpansionType: node).asTypeRepr
case .resultDependsOnType(let node):
return self.generateTypeWithSpecifier(specifier: node.resultDependsOnKeyword, baseType: node.baseType)
case .someOrAnyType(let node):
return self.generate(someOrAnyType: node)
case .suppressedType(let node):
Expand Down Expand Up @@ -369,23 +379,24 @@ extension BridgedAttributedTypeSpecifier {
}

extension ASTGenVisitor {
func generate(attributedType node: AttributedTypeSyntax) -> BridgedTypeRepr {
var type = generate(type: node.baseType)
func generateTypeWithSpecifier(specifier: TokenSyntax, baseType: TypeSyntax) -> BridgedTypeRepr {
var type = generate(type: baseType)

// Handle specifiers.
if let specifier = node.specifier {
if let kind = BridgedAttributedTypeSpecifier(from: specifier.keywordKind) {
type =
BridgedSpecifierTypeRepr.createParsed(
self.ctx,
base: type,
specifier: kind,
specifierLoc: self.generateSourceLoc(specifier)
).asTypeRepr
} else {
self.diagnose(Diagnostic(node: specifier, message: UnexpectedTokenKindError(token: specifier)))
}
if let kind = BridgedAttributedTypeSpecifier(from: specifier.keywordKind) {
return BridgedSpecifierTypeRepr.createParsed(
self.ctx,
base: type,
specifier: kind,
specifierLoc: self.generateSourceLoc(specifier)
).asTypeRepr
} else {
self.diagnose(Diagnostic(node: specifier, message: UnexpectedTokenKindError(token: specifier)))
return type
}
}

func generate(attributedType node: AttributedTypeSyntax) -> BridgedTypeRepr {
var type = generate(type: node.baseType)

// Handle type attributes.
if !node.attributes.isEmpty {
Expand Down