Skip to content

[Macros/ASTGen] Fix deprecation warnings from SwiftSyntax #67716

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 3 commits into from
Aug 5, 2023
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
26 changes: 13 additions & 13 deletions lib/ASTGen/Sources/ASTGen/Decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import SwiftParser
import SwiftSyntax

extension ASTGenVisitor {
public func visit(_ node: TypealiasDeclSyntax) -> ASTNode {
public func visit(_ node: TypeAliasDeclSyntax) -> ASTNode {
let aliasLoc = bridgedSourceLoc(for: node.typealiasKeyword)
let equalLoc = bridgedSourceLoc(for: node.initializer.equal)
var nameText = node.identifier.text
var nameText = node.name.text
let name = nameText.withBridgedString { bridgedName in
return ASTContext_getIdentifier(ctx, bridgedName)
}
let nameLoc = bridgedSourceLoc(for: node.identifier)
let nameLoc = bridgedSourceLoc(for: node.name)
let genericParams = node.genericParameterClause.map { self.visit($0).rawValue }
let out = TypeAliasDecl_create(
self.ctx, self.declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
Expand All @@ -27,7 +27,7 @@ extension ASTGenVisitor {

public func visit(_ node: StructDeclSyntax) -> ASTNode {
let loc = bridgedSourceLoc(for: node)
var nameText = node.identifier.text
var nameText = node.name.text
let name = nameText.withBridgedString { bridgedName in
return ASTContext_getIdentifier(ctx, bridgedName)
}
Expand All @@ -50,7 +50,7 @@ extension ASTGenVisitor {

public func visit(_ node: ClassDeclSyntax) -> ASTNode {
let loc = bridgedSourceLoc(for: node)
var nameText = node.identifier.text
var nameText = node.name.text
let name = nameText.withBridgedString { bridgedName in
return ASTContext_getIdentifier(ctx, bridgedName)
}
Expand All @@ -75,7 +75,7 @@ extension ASTGenVisitor {

let loc = bridgedSourceLoc(for: node)
let isStatic = false // TODO: compute this
let isLet = node.bindingKeyword.tokenKind == .keyword(.let)
let isLet = node.bindingSpecifier.tokenKind == .keyword(.let)

// TODO: don't drop "initializer" on the floor.
return .decl(
Expand Down Expand Up @@ -118,23 +118,23 @@ extension ASTGenVisitor {
public func visit(_ node: FunctionDeclSyntax) -> ASTNode {
let staticLoc = bridgedSourceLoc(for: node)
let funcLoc = bridgedSourceLoc(for: node.funcKeyword)
let nameLoc = bridgedSourceLoc(for: node.identifier)
let rParamLoc = bridgedSourceLoc(for: node.signature.input.leftParen)
let lParamLoc = bridgedSourceLoc(for: node.signature.input.rightParen)
let nameLoc = bridgedSourceLoc(for: node.name)
let rParamLoc = bridgedSourceLoc(for: node.signature.parameterClause.leftParen)
let lParamLoc = bridgedSourceLoc(for: node.signature.parameterClause.rightParen)

var nameText = node.identifier.text
var nameText = node.name.text
let name = nameText.withBridgedString { bridgedName in
return ASTContext_getIdentifier(ctx, bridgedName)
}

let returnType: ASTNode?
if let output = node.signature.output {
returnType = visit(output.returnType)
if let output = node.signature.returnClause {
returnType = visit(output.type)
} else {
returnType = nil
}

let params = node.signature.input.parameterList.map { visit($0).rawValue }
let params = node.signature.parameterClause.parameters.map { visit($0).rawValue }
let out = params.withBridgedArrayRef { ref in
FuncDecl_create(
ctx, staticLoc, false, funcLoc, name, nameLoc, false, nil, false, nil, rParamLoc, ref,
Expand Down
17 changes: 10 additions & 7 deletions lib/ASTGen/Sources/ASTGen/Exprs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ extension ASTGenVisitor {
public func visit(_ node: FunctionCallExprSyntax) -> ASTNode {
// Transform the trailing closure into an argument.
if let trailingClosure = node.trailingClosure {
let tupleElement = TupleExprElementSyntax(
let tupleElement = LabeledExprSyntax(
label: nil, colon: nil, expression: ExprSyntax(trailingClosure), trailingComma: nil)

return visit(node.addArgument(tupleElement).with(\.trailingClosure, nil))
var node = node
node.arguments.append(tupleElement)
node.trailingClosure = nil
return visit(node)
}

let args = visit(node.argumentList).rawValue
let args = visit(node.arguments).rawValue
let callee = visit(node.calledExpression).rawValue

return .expr(FunctionCallExpr_create(self.ctx, callee, args))
}

public func visit(_ node: IdentifierExprSyntax) -> ASTNode {
public func visit(_ node: DeclReferenceExprSyntax) -> ASTNode {
let loc = bridgedSourceLoc(for: node)

var text = node.identifier.text
var text = node.baseName.text
let id = text.withBridgedString { bridgedText in
return ASTContext_getIdentifier(ctx, bridgedText)
}
Expand All @@ -54,7 +57,7 @@ extension ASTGenVisitor {
public func visit(_ node: MemberAccessExprSyntax) -> ASTNode {
let loc = bridgedSourceLoc(for: node)
let base = visit(node.base!).rawValue
var nameText = node.name.text
var nameText = node.declName.baseName.text
let name = nameText.withBridgedString { bridgedName in
return ASTContext_getIdentifier(ctx, bridgedName)
}
Expand All @@ -71,7 +74,7 @@ extension ASTGenVisitor {
return .expr(sve)
}

public func visit(_ node: TupleExprElementListSyntax) -> ASTNode {
public func visit(_ node: LabeledExprListSyntax) -> ASTNode {
let elements = node.map { self.visit($0).rawValue }
let labels: [BridgedIdentifier?] = node.map {
guard var name = $0.label?.text else {
Expand Down
22 changes: 11 additions & 11 deletions lib/ASTGen/Sources/ASTGen/Generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import SwiftSyntax

extension ASTGenVisitor {
func visit(_ node: GenericParameterClauseSyntax) -> ASTNode {
let lAngleLoc = bridgedSourceLoc(for: node.leftAngleBracket)
let lAngleLoc = bridgedSourceLoc(for: node.leftAngle)
let whereLoc = bridgedSourceLoc(for: node.genericWhereClause?.whereKeyword)
let rAngleLoc = bridgedSourceLoc(for: node.rightAngleBracket)
let rAngleLoc = bridgedSourceLoc(for: node.rightAngle)
return .misc(
self.withBridgedParametersAndRequirements(node) { params, reqs in
return GenericParamList_create(self.ctx, lAngleLoc, params, whereLoc, reqs, rAngleLoc)
Expand All @@ -19,7 +19,7 @@ extension ASTGenVisitor {
return ASTContext_getIdentifier(ctx, bridgedName)
}
let nameLoc = bridgedSourceLoc(for: node.name)
let eachLoc = bridgedSourceLoc(for: node.each)
let eachLoc = bridgedSourceLoc(for: node.eachKeyword)

var genericParameterIndex: Int?
for (index, sibling) in (node.parent?.as(GenericParameterListSyntax.self) ?? []).enumerated() {
Expand All @@ -46,7 +46,7 @@ extension ASTGenVisitor {
) -> T {
var params = [UnsafeMutableRawPointer]()
var requirements = [BridgedRequirementRepr]()
for param in node.genericParameterList {
for param in node.parameters {
let loweredParameter = self.visit(param).rawValue
params.append(loweredParameter)

Expand All @@ -58,23 +58,23 @@ extension ASTGenVisitor {
GenericTypeParamDecl_setInheritedType(self.ctx, loweredParameter, loweredRequirement.rawValue)
}

if let nodeRequirements = node.genericWhereClause?.requirementList {
if let nodeRequirements = node.genericWhereClause?.requirements {
for requirement in nodeRequirements {
switch requirement.body {
switch requirement.requirement {
case .conformanceRequirement(let conformance):
let firstType = self.visit(conformance.leftTypeIdentifier).rawValue
let firstType = self.visit(conformance.leftType).rawValue
let separatorLoc = bridgedSourceLoc(for: conformance.colon)
let secondType = self.visit(conformance.rightTypeIdentifier).rawValue
let secondType = self.visit(conformance.rightType).rawValue
requirements.append(
BridgedRequirementRepr(
SeparatorLoc: separatorLoc,
Kind: .typeConstraint,
FirstType: firstType,
SecondType: secondType))
case .sameTypeRequirement(let sameType):
let firstType = self.visit(sameType.leftTypeIdentifier).rawValue
let separatorLoc = bridgedSourceLoc(for: sameType.equalityToken)
let secondType = self.visit(sameType.rightTypeIdentifier).rawValue
let firstType = self.visit(sameType.leftType).rawValue
let separatorLoc = bridgedSourceLoc(for: sameType.equal)
let secondType = self.visit(sameType.rightType).rawValue
requirements.append(
BridgedRequirementRepr(
SeparatorLoc: separatorLoc,
Expand Down
4 changes: 2 additions & 2 deletions lib/ASTGen/Sources/ASTGen/Literals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension ASTGenVisitor {

public func visit(_ node: IntegerLiteralExprSyntax) -> ASTNode {
let loc = bridgedSourceLoc(for: node)
var segment = node.digits.text
var segment = node.literal.text
return .expr(
segment.withBridgedString { bridgedSegment in
return IntegerLiteralExpr_create(ctx, bridgedSegment, loc)
Expand All @@ -23,7 +23,7 @@ extension ASTGenVisitor {

public func visit(_ node: BooleanLiteralExprSyntax) -> ASTNode {
let loc = bridgedSourceLoc(for: node)
let value = node.booleanLiteral == .keyword(.true)
let value = node.literal == .keyword(.true)
return .expr(BooleanLiteralExpr_create(ctx, value, loc))
}

Expand Down
12 changes: 6 additions & 6 deletions lib/ASTGen/Sources/ASTGen/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ func checkMacroDefinition(
return BridgedMacroDefinitionKind.externalMacro.rawValue

case let .expansion(expansionSyntax, replacements: _)
where expansionSyntax.macro.text == "externalMacro":
where expansionSyntax.macroName.text == "externalMacro":
// Extract the identifier from the "module" argument.
guard let firstArg = expansionSyntax.argumentList.first,
guard let firstArg = expansionSyntax.arguments.first,
let firstArgLabel = firstArg.label?.text,
firstArgLabel == "module",
let module = identifierFromStringLiteral(firstArg.expression) else {
Expand All @@ -344,7 +344,7 @@ func checkMacroDefinition(
}

// Extract the identifier from the "type" argument.
guard let secondArg = expansionSyntax.argumentList.dropFirst().first,
guard let secondArg = expansionSyntax.arguments.dropFirst().first,
let secondArgLabel = secondArg.label?.text,
secondArgLabel == "type",
let type = identifierFromStringLiteral(secondArg.expression) else {
Expand Down Expand Up @@ -514,9 +514,9 @@ func expandFreestandingMacroIPC(

let macroName: String
if let exprSyntax = expansionSyntax.as(MacroExpansionExprSyntax.self) {
macroName = exprSyntax.macro.text
macroName = exprSyntax.macroName.text
} else if let declSyntax = expansionSyntax.as(MacroExpansionDeclSyntax.self) {
macroName = declSyntax.macro.text
macroName = declSyntax.macroName.text
} else {
fatalError("unknown syntax")
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ func expandAttachedMacroInProcess(
"""
let placeholderStruct = placeholderDecl.cast(StructDeclSyntax.self)
if let inheritanceClause = placeholderStruct.inheritanceClause {
conformanceListSyntax = inheritanceClause.inheritedTypeCollection
conformanceListSyntax = inheritanceClause.inheritedTypes
} else {
conformanceListSyntax = nil
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ASTGen/Sources/ASTGen/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import SwiftParser
import SwiftSyntax

extension ASTGenVisitor {
public func visit(_ node: MemberDeclListItemSyntax) -> ASTNode {
public func visit(_ node: MemberBlockItemSyntax) -> ASTNode {
visit(Syntax(node.decl))
}

public func visit(_ node: TupleExprElementSyntax) -> ASTNode {
public func visit(_ node: LabeledExprSyntax) -> ASTNode {
visit(node.expression)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ASTGen/Sources/ASTGen/SourceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ extension SourceManager {

let detached: Node
if let operatorTable = operatorTable {
detached = operatorTable.foldAll(node) { _ in }.as(Node.self)!.detach()
detached = operatorTable.foldAll(node) { _ in }.as(Node.self)!.detached
} else {
detached = node.detach()
detached = node.detached
}

detachedNodes[Syntax(detached)] = (node.root, node.position.utf8Offset)
Expand Down
Loading