Skip to content

Commit f77fd81

Browse files
committed
Swift: add predicates to MacroRole
1 parent 197e5d0 commit f77fd81

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed
Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,73 @@
1-
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1+
/**
2+
* This module provides a hand-modifiable wrapper around the generated class `MacroRole`.
3+
*/
4+
5+
private import codeql.swift.generated.MacroRole
6+
27
/**
38
* The role of a macro, for example #freestanding(declaration) or @attached(member).
49
*/
510
class MacroRole extends Generated::MacroRole {
6-
/**
7-
* String representation of the role kind.
8-
*/
11+
// String representation of the role kind.
912
string getKindName() {
10-
this.getKind() = 1 and result = "expression"
13+
this.isExpressionKind() and result = "expression"
1114
or
12-
this.getKind() = 2 and result = "declaration"
15+
this.isDeclarationKind() and result = "declaration"
1316
or
14-
this.getKind() = 4 and result = "accessor"
17+
this.isAccessorKind() and result = "accessor"
1518
or
16-
this.getKind() = 8 and result = "memberAttribute"
19+
this.isMemberAttributeKind() and result = "memberAttribute"
1720
or
18-
this.getKind() = 16 and result = "member"
21+
this.isMemberKind() and result = "member"
1922
or
20-
this.getKind() = 32 and result = "peer"
23+
this.isPeerKind() and result = "peer"
2124
or
22-
this.getKind() = 64 and result = "conformance"
25+
this.isConformanceKind() and result = "conformance"
2326
or
24-
this.getKind() = 128 and result = "codeItem"
27+
this.isCodeItemKind() and result = "codeItem"
2528
or
26-
this.getKind() = 256 and result = "extension"
29+
this.isExtensionKind() and result = "extension"
2730
}
2831

29-
/**
30-
* String representation of the syntax kind.
31-
*/
32+
// Holds for `expression` roles.
33+
predicate isExpressionKind() { this.getKind() = 1 }
34+
35+
// Holds for `declaration` roles.
36+
predicate isDeclarationKind() { this.getKind() = 2 }
37+
38+
// Holds for `accessor` roles.
39+
predicate isAccessorKind() { this.getKind() = 4 }
40+
41+
// Holds for `memberAttribute` roles.
42+
predicate isMemberAttributeKind() { this.getKind() = 8 }
43+
44+
// Holds for `member` roles.
45+
predicate isMemberKind() { this.getKind() = 16 }
46+
47+
// Holds for `peer` roles.
48+
predicate isPeerKind() { this.getKind() = 32 }
49+
50+
// Holds for `conformance` roles.
51+
predicate isConformanceKind() { this.getKind() = 64 }
52+
53+
// Holds for `codeItem` roles.
54+
predicate isCodeItemKind() { this.getKind() = 128 }
55+
56+
// Holds for `extension` roles.
57+
predicate isExtensionKind() { this.getKind() = 256 }
58+
59+
// String representation of the syntax kind.
3260
string getMacroSyntaxName() {
33-
this.getMacroSyntax() = 0 and result = "#freestanding"
61+
this.isFreestandingMacroSyntax() and result = "#freestanding"
3462
or
35-
this.getMacroSyntax() = 1 and result = "@attached"
63+
this.isAttachedMacroSyntax() and result = "@attached"
3664
}
3765

66+
// Holds for #freestanding macros.
67+
predicate isFreestandingMacroSyntax() { this.getMacroSyntax() = 0 }
68+
69+
// Holds for @attached macros.
70+
predicate isAttachedMacroSyntax() { this.getMacroSyntax() = 1 }
71+
3872
override string toString() { result = this.getMacroSyntaxName() + "(" + this.getKindName() + ")" }
3973
}

0 commit comments

Comments
 (0)