C++: Fix joins in 'AV Rule 145'.

This commit is contained in:
Mathias Vorreiter Pedersen
2023-12-15 13:08:13 +00:00
parent 1ea1130271
commit 1cbe01923d

View File

@@ -32,18 +32,39 @@ predicate hasReferenceInitializer(EnumConstant c) {
)
}
/**
* Gets the `rnk`'th (1-based) enumeration constant in `e` that does not have a
* reference initializer (i.e., an initializer that refers to an enumeration
* constant from the same enumeration).
*/
EnumConstant getNonReferenceInitializedEnumConstantByRank(Enum e, int rnk) {
result =
rank[rnk](EnumConstant cand, int pos |
e.getEnumConstant(pos) = cand and not hasReferenceInitializer(cand)
|
cand order by pos
)
}
/**
* Holds if `ec` is not the last enumeration constant in `e` that has a non-
* reference initializer.
*/
predicate hasNextWithoutReferenceInitializer(Enum e, EnumConstant ec) {
exists(int rnk |
ec = getNonReferenceInitializedEnumConstantByRank(e, rnk) and
exists(getNonReferenceInitializedEnumConstantByRank(e, rnk + 1))
)
}
// There exists another constant whose value is implicit, but it's
// not the last one: the last value is okay to use to get the highest
// enum value automatically. It can be followed by aliases though.
predicate enumThatHasConstantWithImplicitValue(Enum e) {
exists(EnumConstant ec, int pos |
ec = e.getEnumConstant(pos) and
exists(EnumConstant ec |
ec = e.getAnEnumConstant() and
not hasInitializer(ec) and
exists(EnumConstant ec2, int pos2 |
ec2 = e.getEnumConstant(pos2) and
pos2 > pos and
not hasReferenceInitializer(ec2)
)
hasNextWithoutReferenceInitializer(e, ec)
)
}