Skip to content

Commit d6cea7a

Browse files
authored
Merge pull request #173 from ahoppen/remove-is-expr-etc
Remove isExpr etc. methods
2 parents b15030f + d8844b7 commit d6cea7a

File tree

4 files changed

+16
-177
lines changed

4 files changed

+16
-177
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Note: This is in reverse chronological order, so newer entries are added to the
44

55
## Swift 5.2
66

7+
- Properties `isExpr`, `isDecl`, `isStmt`, `isType` and `isPattern` removed from `SyntaxNode`
8+
9+
Use `is(ExprSyntaxProtocol.self)` etc. instead.
10+
711
- Property `uniqueIdentifier` removed from syntax nodes and `SyntaxNode` ([#164](https://github.com/apple/swift-syntax/pull/164))
812

913
Use the newly added property `id` or the conformance to `Identifiable` instead.

Sources/SwiftSyntax/Syntax.swift

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,36 +119,14 @@ public extension SyntaxProtocol {
119119
return raw.isToken
120120
}
121121

122-
/// Whether or not this node represents an Expression.
123-
var isExpr: Bool {
124-
return raw.kind.isExpr
125-
}
126-
127122
/// Whether or not this node represents an SyntaxCollection.
128123
var isCollection: Bool {
124+
// We need to provide a custom implementation for is(SyntaxCollection.self)
125+
// since SyntaxCollection has generic or self requirements and can thus
126+
// not be used as a method argument.
129127
return raw.kind.isSyntaxCollection
130128
}
131129

132-
/// Whether or not this node represents a Declaration.
133-
var isDecl: Bool {
134-
return raw.kind.isDecl
135-
}
136-
137-
/// Whether or not this node represents a Statement.
138-
var isStmt: Bool {
139-
return raw.kind.isStmt
140-
}
141-
142-
/// Whether or not this node represents a Type.
143-
var isType: Bool {
144-
return raw.kind.isType
145-
}
146-
147-
/// Whether or not this node represents a Pattern.
148-
var isPattern: Bool {
149-
return raw.kind.isPattern
150-
}
151-
152130
/// Whether or not this node represents an unknown node.
153131
var isUnknown: Bool {
154132
return raw.kind.isUnknown

Sources/SwiftSyntax/SyntaxKind.swift.gyb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
%{
22
from gyb_syntax_support import *
33
from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS
4-
grouped_nodes = { kind: [] for kind in SYNTAX_BASE_KINDS }
5-
for node in SYNTAX_NODES:
6-
grouped_nodes[node.base_kind].append(node)
74
# -*- mode: Swift -*-
85
# Ignore the following admonition; it applies to the resulting .swift file only
96
}%
@@ -29,23 +26,21 @@ internal enum SyntaxKind: CSyntaxKind {
2926
case ${node.swift_syntax_kind} = ${SYNTAX_NODE_SERIALIZATION_CODES[node.syntax_kind]}
3027
% end
3128

32-
% for name, nodes in grouped_nodes.items():
33-
% if name not in ["Syntax"]:
34-
/// Whether the underlying kind is a sub-kind of ${name}Syntax.
35-
var is${name}: Bool {
29+
var isSyntaxCollection: Bool {
3630
switch self {
37-
% for node in nodes:
31+
% for node in SYNTAX_NODES:
32+
% if node.base_kind == "SyntaxCollection":
3833
case .${node.swift_syntax_kind}: return true
39-
% end
34+
% end
35+
% end
36+
case .unknown: return true
4037
default: return false
4138
}
4239
}
43-
% end
44-
% end
4540

4641
var isUnknown: Bool {
4742
switch self {
48-
% for name, nodes in grouped_nodes.items():
43+
% for name in SYNTAX_BASE_KINDS:
4944
% if name not in ["Syntax", "SyntaxCollection"]:
5045
case .unknown${name}: return true
5146
% end

Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift

Lines changed: 2 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -243,109 +243,6 @@ internal enum SyntaxKind: CSyntaxKind {
243243
case availabilityVersionRestriction = 161
244244
case versionTuple = 162
245245

246-
/// Whether the underlying kind is a sub-kind of DeclSyntax.
247-
var isDecl: Bool {
248-
switch self {
249-
case .unknownDecl: return true
250-
case .typealiasDecl: return true
251-
case .associatedtypeDecl: return true
252-
case .ifConfigDecl: return true
253-
case .poundErrorDecl: return true
254-
case .poundWarningDecl: return true
255-
case .poundSourceLocation: return true
256-
case .classDecl: return true
257-
case .structDecl: return true
258-
case .protocolDecl: return true
259-
case .extensionDecl: return true
260-
case .functionDecl: return true
261-
case .initializerDecl: return true
262-
case .deinitializerDecl: return true
263-
case .subscriptDecl: return true
264-
case .importDecl: return true
265-
case .accessorDecl: return true
266-
case .variableDecl: return true
267-
case .enumCaseDecl: return true
268-
case .enumDecl: return true
269-
case .operatorDecl: return true
270-
case .precedenceGroupDecl: return true
271-
default: return false
272-
}
273-
}
274-
/// Whether the underlying kind is a sub-kind of ExprSyntax.
275-
var isExpr: Bool {
276-
switch self {
277-
case .unknownExpr: return true
278-
case .inOutExpr: return true
279-
case .poundColumnExpr: return true
280-
case .tryExpr: return true
281-
case .identifierExpr: return true
282-
case .superRefExpr: return true
283-
case .nilLiteralExpr: return true
284-
case .discardAssignmentExpr: return true
285-
case .assignmentExpr: return true
286-
case .sequenceExpr: return true
287-
case .poundLineExpr: return true
288-
case .poundFileExpr: return true
289-
case .poundFunctionExpr: return true
290-
case .poundDsohandleExpr: return true
291-
case .symbolicReferenceExpr: return true
292-
case .prefixOperatorExpr: return true
293-
case .binaryOperatorExpr: return true
294-
case .arrowExpr: return true
295-
case .floatLiteralExpr: return true
296-
case .tupleExpr: return true
297-
case .arrayExpr: return true
298-
case .dictionaryExpr: return true
299-
case .integerLiteralExpr: return true
300-
case .booleanLiteralExpr: return true
301-
case .ternaryExpr: return true
302-
case .memberAccessExpr: return true
303-
case .isExpr: return true
304-
case .asExpr: return true
305-
case .typeExpr: return true
306-
case .closureExpr: return true
307-
case .unresolvedPatternExpr: return true
308-
case .functionCallExpr: return true
309-
case .subscriptExpr: return true
310-
case .optionalChainingExpr: return true
311-
case .forcedValueExpr: return true
312-
case .postfixUnaryExpr: return true
313-
case .specializeExpr: return true
314-
case .stringLiteralExpr: return true
315-
case .keyPathExpr: return true
316-
case .keyPathBaseExpr: return true
317-
case .objcKeyPathExpr: return true
318-
case .objcSelectorExpr: return true
319-
case .editorPlaceholderExpr: return true
320-
case .objectLiteralExpr: return true
321-
default: return false
322-
}
323-
}
324-
/// Whether the underlying kind is a sub-kind of StmtSyntax.
325-
var isStmt: Bool {
326-
switch self {
327-
case .unknownStmt: return true
328-
case .continueStmt: return true
329-
case .whileStmt: return true
330-
case .deferStmt: return true
331-
case .expressionStmt: return true
332-
case .repeatWhileStmt: return true
333-
case .guardStmt: return true
334-
case .forInStmt: return true
335-
case .switchStmt: return true
336-
case .doStmt: return true
337-
case .returnStmt: return true
338-
case .yieldStmt: return true
339-
case .fallthroughStmt: return true
340-
case .breakStmt: return true
341-
case .declarationStmt: return true
342-
case .throwStmt: return true
343-
case .ifStmt: return true
344-
case .poundAssertStmt: return true
345-
default: return false
346-
}
347-
}
348-
/// Whether the underlying kind is a sub-kind of SyntaxCollectionSyntax.
349246
var isSyntaxCollection: Bool {
350247
switch self {
351248
case .codeBlockItemList: return true
@@ -386,42 +283,7 @@ internal enum SyntaxKind: CSyntaxKind {
386283
case .genericArgumentList: return true
387284
case .tuplePatternElementList: return true
388285
case .availabilitySpecList: return true
389-
default: return false
390-
}
391-
}
392-
/// Whether the underlying kind is a sub-kind of PatternSyntax.
393-
var isPattern: Bool {
394-
switch self {
395-
case .unknownPattern: return true
396-
case .enumCasePattern: return true
397-
case .isTypePattern: return true
398-
case .optionalPattern: return true
399-
case .identifierPattern: return true
400-
case .asTypePattern: return true
401-
case .tuplePattern: return true
402-
case .wildcardPattern: return true
403-
case .expressionPattern: return true
404-
case .valueBindingPattern: return true
405-
default: return false
406-
}
407-
}
408-
/// Whether the underlying kind is a sub-kind of TypeSyntax.
409-
var isType: Bool {
410-
switch self {
411-
case .unknownType: return true
412-
case .simpleTypeIdentifier: return true
413-
case .memberTypeIdentifier: return true
414-
case .classRestrictionType: return true
415-
case .arrayType: return true
416-
case .dictionaryType: return true
417-
case .metatypeType: return true
418-
case .optionalType: return true
419-
case .someType: return true
420-
case .implicitlyUnwrappedOptionalType: return true
421-
case .compositionType: return true
422-
case .tupleType: return true
423-
case .functionType: return true
424-
case .attributedType: return true
286+
case .unknown: return true
425287
default: return false
426288
}
427289
}
@@ -430,8 +292,8 @@ internal enum SyntaxKind: CSyntaxKind {
430292
switch self {
431293
case .unknownDecl: return true
432294
case .unknownExpr: return true
433-
case .unknownStmt: return true
434295
case .unknownPattern: return true
296+
case .unknownStmt: return true
435297
case .unknownType: return true
436298
case .unknown: return true
437299
default: return false

0 commit comments

Comments
 (0)