Skip to content

Commit 7ce4981

Browse files
committed
Rework use of deprecated APIs
1 parent 83f3824 commit 7ce4981

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,35 +182,35 @@ private func evaluateIfConfig(
182182

183183
// Integer literals evaluate true if that are not "0".
184184
if let intLiteral = condition.as(IntegerLiteralExprSyntax.self) {
185-
return intLiteral.digits.text != "0"
185+
return intLiteral.literal.text != "0"
186186
}
187187

188188
// Declaration references are for custom compilation flags.
189-
if let identExpr = condition.as(IdentifierExprSyntax.self) {
189+
if let identExpr = condition.as(DeclReferenceExprSyntax.self) {
190190
// FIXME: Need a real notion of an identifier.
191-
let ident = identExpr.identifier.text
191+
let ident = identExpr.baseName.text
192192

193193
// Evaluate the custom condition. If the build configuration cannot answer this query, fail.
194194
return try configuration.isCustomConditionSet(name: ident)
195195
}
196196

197197
// Logical '!'.
198198
if let prefixOp = condition.as(PrefixOperatorExprSyntax.self),
199-
prefixOp.operatorToken?.text == "!"
199+
prefixOp.operator?.text == "!"
200200
{
201-
return try !evaluateIfConfig(condition: prefixOp.postfixExpression, configuration: configuration)
201+
return try !evaluateIfConfig(condition: prefixOp.expression, configuration: configuration)
202202
}
203203

204204
// Logical '&&' and '||'.
205205
if let binOp = condition.as(InfixOperatorExprSyntax.self),
206-
let op = binOp.operatorOperand.as(BinaryOperatorExprSyntax.self),
207-
(op.operatorToken.text == "&&" || op.operatorToken.text == "||")
206+
let op = binOp.operator.as(BinaryOperatorExprSyntax.self),
207+
(op.operator.text == "&&" || op.operator.text == "||")
208208
{
209209
// Evaluate the left-hand side.
210210
let lhsResult = try evaluateIfConfig(condition: binOp.leftOperand, configuration: configuration)
211211

212212
// Short-circuit evaluation if we know the answer.
213-
switch (lhsResult, op.operatorToken.text) {
213+
switch (lhsResult, op.operator.text) {
214214
case (true, "||"): return true
215215
case (false, "&&"): return false
216216
default: break
@@ -235,7 +235,7 @@ private func evaluateIfConfig(
235235
/// Perform a check for an operation that takes a single identifier argument.
236236
func doSingleIdentifierArgumentCheck(_ body: (String) throws -> Bool, role: String) throws -> Bool {
237237
// Ensure that we have a single argument that is a simple identifier.
238-
guard let argExpr = call.argumentList.singleUnlabeledExpression,
238+
guard let argExpr = call.arguments.singleUnlabeledExpression,
239239
let arg = argExpr.simpleIdentifierExpr
240240
else {
241241
throw IfConfigError.requiresUnlabeledArgument(name: fnName, role: role)
@@ -248,16 +248,16 @@ private func evaluateIfConfig(
248248
func doVersionComparisonCheck(_ actualVersion: VersionTuple) throws -> Bool {
249249
// Ensure that we have a single unlabeled argument that is either >= or < as a prefix
250250
// operator applied to a version.
251-
guard let argExpr = call.argumentList.singleUnlabeledExpression,
251+
guard let argExpr = call.arguments.singleUnlabeledExpression,
252252
let unaryArg = argExpr.as(PrefixOperatorExprSyntax.self),
253-
let opToken = unaryArg.operatorToken
253+
let opToken = unaryArg.operator
254254
else {
255255
throw IfConfigError.requiresUnlabeledArgument(name: fnName, role: "version comparison (>= or <= a version)")
256256
}
257257

258258
// Parse the version.
259-
guard let version = VersionTuple(parsing: unaryArg.postfixExpression.trimmedDescription) else {
260-
throw IfConfigError.invalidVersionOperand(name: fnName, syntax: unaryArg.postfixExpression)
259+
guard let version = VersionTuple(parsing: unaryArg.expression.trimmedDescription) else {
260+
throw IfConfigError.invalidVersionOperand(name: fnName, syntax: unaryArg.expression)
261261
}
262262

263263
switch opToken.text {
@@ -295,7 +295,7 @@ private func evaluateIfConfig(
295295
case ._endian:
296296
// Ensure that we have a single argument that is a simple identifier,
297297
// either "little" or "big".
298-
guard let argExpr = call.argumentList.singleUnlabeledExpression,
298+
guard let argExpr = call.arguments.singleUnlabeledExpression,
299299
let arg = argExpr.simpleIdentifierExpr,
300300
let expectedEndianness = Endianness(rawValue: arg)
301301
else {
@@ -307,7 +307,7 @@ private func evaluateIfConfig(
307307
case ._pointerBitWidth:
308308
// Ensure that we have a single argument that is a simple identifier, which
309309
// is an underscore followed by an integer.
310-
guard let argExpr = call.argumentList.singleUnlabeledExpression,
310+
guard let argExpr = call.arguments.singleUnlabeledExpression,
311311
let arg = argExpr.simpleIdentifierExpr,
312312
let argFirst = arg.first,
313313
argFirst == "_",
@@ -327,7 +327,7 @@ private func evaluateIfConfig(
327327
case ._compiler_version:
328328
// Argument is a single unlabeled argument containing a string
329329
// literal.
330-
guard let argExpr = call.argumentList.singleUnlabeledExpression,
330+
guard let argExpr = call.arguments.singleUnlabeledExpression,
331331
let stringLiteral = argExpr.as(StringLiteralExprSyntax.self),
332332
stringLiteral.segments.count == 1,
333333
let segment = stringLiteral.segments.first,
@@ -345,7 +345,7 @@ private func evaluateIfConfig(
345345
case .canImport:
346346
// Retrieve the first argument, which must not have a label. This is
347347
// the module import path.
348-
guard let firstArg = call.argumentList.first,
348+
guard let firstArg = call.arguments.first,
349349
firstArg.label == nil
350350
else {
351351
throw IfConfigError.canImportMissingModule(syntax: ExprSyntax(call))
@@ -358,7 +358,7 @@ private func evaluateIfConfig(
358358
// If there is a second argument, it shall have the label _version or
359359
// _underlyingVersion.
360360
let version: CanImportVersion
361-
if let secondArg = call.argumentList.dropFirst().first {
361+
if let secondArg = call.arguments.dropFirst().first {
362362
if secondArg.label?.text != "_version" && secondArg.label?.text != "_underlyingVersion" {
363363
throw IfConfigError.canImportLabel(syntax: secondArg.expression)
364364
}
@@ -387,7 +387,7 @@ private func evaluateIfConfig(
387387
version = .underlyingVersion(versionTuple)
388388
}
389389

390-
if call.argumentList.count > 2 {
390+
if call.arguments.count > 2 {
391391
throw IfConfigError.canImportTwoParameters(syntax: ExprSyntax(call))
392392
}
393393
} else {

Sources/SwiftIfConfig/IfConfigRewriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ActiveSyntaxRewriter<Configuration: BuildConfiguration>: SyntaxRewriter {
121121
return super.visit(rewrittenNode)
122122
}
123123

124-
override func visit(_ node: MemberDeclListSyntax) -> MemberDeclListSyntax {
124+
override func visit(_ node: MemberBlockItemListSyntax) -> MemberBlockItemListSyntax {
125125
let rewrittenNode = dropInactive(node) { element in
126126
return element.decl.as(IfConfigDeclSyntax.self)
127127
}

Sources/SwiftIfConfig/SyntaxLiteralUtils.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SwiftSyntax
1313

1414
extension BooleanLiteralExprSyntax {
1515
var literalValue: Bool {
16-
return booleanLiteral.tokenKind == .keyword(.true)
16+
return literal.tokenKind == .keyword(.true)
1717
}
1818
}
1919

@@ -24,7 +24,7 @@ extension TupleExprSyntax {
2424
}
2525
}
2626

27-
extension TupleExprElementListSyntax {
27+
extension LabeledExprListSyntax {
2828
/// If this list is a single, unlabeled expression, return it.
2929
var singleUnlabeledExpression: ExprSyntax? {
3030
guard count == 1, let element = first else { return nil }
@@ -35,13 +35,13 @@ extension TupleExprElementListSyntax {
3535
extension ExprSyntax {
3636
/// Whether this is a simple identifier expression and, if so, what the identifier string is.
3737
var simpleIdentifierExpr: String? {
38-
guard let identExpr = self.as(IdentifierExprSyntax.self),
39-
identExpr.declNameArguments == nil
38+
guard let identExpr = self.as(DeclReferenceExprSyntax.self),
39+
identExpr.argumentNames == nil
4040
else {
4141
return nil
4242
}
4343

4444
// FIXME: Handle escaping here.
45-
return identExpr.identifier.text
45+
return identExpr.baseName.text
4646
}
4747
}

Tests/SwiftIfConfigTest/VisitorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public class VisitorTests: XCTestCase {
131131
}
132132

133133
open override func visitAny(_ node: Syntax) -> SyntaxVisitorContinueKind {
134-
if let identified = node.asProtocol(IdentifiedDeclSyntax.self) {
135-
checkName(name: identified.identifier.text, node: node)
134+
if let identified = node.asProtocol(NamedDeclSyntax.self) {
135+
checkName(name: identified.name.text, node: node)
136136
} else if let identPattern = node.as(IdentifierPatternSyntax.self) {
137137
// FIXME: Should the above be an IdentifiedDeclSyntax?
138138
checkName(name: identPattern.identifier.text, node: node)

0 commit comments

Comments
 (0)