Skip to content

Commit 5ffde7a

Browse files
geoffw0MathiasVP
andauthored
Update swift/ql/lib/codeql/swift/elements/decl/EnumDecl.qll
Co-authored-by: Mathias Vorreiter Pedersen <[email protected]>
1 parent d26a861 commit 5ffde7a

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

swift/ql/lib/codeql/swift/elements/decl/EnumDecl.qll

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,17 @@ private import codeql.swift.elements.decl.Decl
1414
* ```
1515
*/
1616
class EnumDecl extends Generated::EnumDecl {
17-
/**
18-
* Gets the number of `EnumElementDecl`s in this enumeration before the `memberIndex`th member. Some
19-
* of the members of an `EnumDecl` are `EnumCaseDecls` (representing the `case` lines), each of
20-
* which holds one or more `EnumElementDecl`s.
21-
*/
22-
private int countEnumElementsTo(int memberIndex) {
23-
memberIndex = 0 and result = 0
24-
or
25-
exists(Decl prev | prev = this.getMember(memberIndex - 1) |
26-
result = this.countEnumElementsTo(memberIndex - 1) + prev.(EnumCaseDecl).getNumberOfElements()
27-
or
28-
not prev instanceof EnumCaseDecl and
29-
result = this.countEnumElementsTo(memberIndex - 1)
30-
)
31-
}
32-
3317
/**
3418
* Gets the `index`th enumeration element of this enumeration (0-based).
3519
*/
3620
final EnumElementDecl getEnumElement(int index) {
37-
exists(int memberIndex |
38-
result =
39-
this.getMember(memberIndex)
40-
.(EnumCaseDecl)
41-
.getElement(index - this.countEnumElementsTo(memberIndex))
42-
)
21+
result =
22+
rank[index + 1](int memberIndex, Decl d |
23+
d = this.getMember(memberIndex) and
24+
d instanceof EnumElementDecl
25+
|
26+
d order by memberIndex
27+
)
4328
}
4429

4530
/**

0 commit comments

Comments
 (0)