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

Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
This commit is contained in:
Geoffrey White
2023-05-19 14:55:39 +01:00
committed by GitHub
parent d26a86185f
commit 5ffde7a762

View File

@@ -14,32 +14,17 @@ private import codeql.swift.elements.decl.Decl
* ```
*/
class EnumDecl extends Generated::EnumDecl {
/**
* Gets the number of `EnumElementDecl`s in this enumeration before the `memberIndex`th member. Some
* of the members of an `EnumDecl` are `EnumCaseDecls` (representing the `case` lines), each of
* which holds one or more `EnumElementDecl`s.
*/
private int countEnumElementsTo(int memberIndex) {
memberIndex = 0 and result = 0
or
exists(Decl prev | prev = this.getMember(memberIndex - 1) |
result = this.countEnumElementsTo(memberIndex - 1) + prev.(EnumCaseDecl).getNumberOfElements()
or
not prev instanceof EnumCaseDecl and
result = this.countEnumElementsTo(memberIndex - 1)
)
}
/**
* Gets the `index`th enumeration element of this enumeration (0-based).
*/
final EnumElementDecl getEnumElement(int index) {
exists(int memberIndex |
result =
this.getMember(memberIndex)
.(EnumCaseDecl)
.getElement(index - this.countEnumElementsTo(memberIndex))
)
result =
rank[index + 1](int memberIndex, Decl d |
d = this.getMember(memberIndex) and
d instanceof EnumElementDecl
|
d order by memberIndex
)
}
/**