Skip to content

[ASTGen] Handle metatypes and simple generic types. #62092

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

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
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
25 changes: 24 additions & 1 deletion lib/ASTGen/Sources/ASTGen/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,33 @@ extension ASTGenVisitor {
return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count)
}

return .type(SimpleIdentTypeRepr_create(ctx, loc, id))
guard let generics = node.genericArgumentClause else {
return .type(SimpleIdentTypeRepr_create(ctx, loc, id))
}

let lAngle = self.base.advanced(by: generics.leftAngleBracket.position.utf8Offset).raw
let rAngle = self.base.advanced(by: generics.rightAngleBracket.position.utf8Offset).raw
return .type(
generics.arguments.map({
self.visit($0.argumentType)
}).withBridgedArrayRef {
genericArgs in
GenericIdentTypeRepr_create(
self.ctx, id, loc, genericArgs, lAngle, rAngle)
})
}

public func visit(_ node: MemberTypeIdentifierSyntax) -> ASTNode {
// Handle metatypes.
// FIXME: We might want to do this in the parser instead?
if node.name.tokenKind == .identifier("Type") &&
node.genericArgumentClause == nil {
let baseType = visit(node.baseType).rawValue
let nameLoc = self.base.advanced(by: node.name.position.utf8Offset).raw
return .type(
MetatypeTypeRepr_create(self.ctx, baseType, nameLoc))
}

var path = [(TokenSyntax, GenericArgumentClauseSyntax?)]()
var memberRef: Syntax? = Syntax(node)
while let nestedMember = memberRef?.as(MemberTypeIdentifierSyntax.self) {
Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/TypeCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ getMacroSignature(
*mod, SourceFileKind::Library, macroBufferID);
mod->addAuxiliaryFile(*macroSourceFile);

// FIXME: Inject imports, which we don't yet have everywhere.

// Parse the struct declaration used for the macro evaluation context.
auto *start = sourceMgr.getLocForBufferStart(macroBufferID)
.getOpaquePointerValue();
Expand Down