[FIR] Add "can be val" extended checker

This commit is contained in:
vldf
2020-07-21 16:24:21 +03:00
committed by Mikhail Glukhikh
parent da6e96f4f1
commit d7b3a86f5e
19 changed files with 709 additions and 104 deletions
@@ -12,16 +12,22 @@ enum class EventOccurrencesRange(private val left: Int, private val right: Int)
ZERO(0, 0), // 0..0
AT_MOST_ONCE(0, 1), // 0..1
EXACTLY_ONCE(1, 1), // 1..1
AT_LEAST_ONCE(1, 2), // 1..*
UNKNOWN(0, 2); // 0..*
AT_LEAST_ONCE(1, 3), // 1..*
MORE_THAN_ONCE(2, 3), // 2..*
UNKNOWN(0, 3); // 0..*
companion object {
private fun fromRange(left: Int, right: Int): EventOccurrencesRange = when (min(left, 1) to min(right, 2)) {
private fun fromRange(left: Int, right: Int): EventOccurrencesRange = when (min(left, 2) to min(right, 3)) {
0 to 0 -> ZERO
0 to 1 -> AT_MOST_ONCE
0 to 2 -> UNKNOWN
0 to 3 -> UNKNOWN
1 to 1 -> EXACTLY_ONCE
1 to 2 -> AT_LEAST_ONCE
0 to 2 -> UNKNOWN
1 to 3 -> AT_LEAST_ONCE
2 to 2 -> MORE_THAN_ONCE
2 to 3 -> MORE_THAN_ONCE
3 to 3 -> MORE_THAN_ONCE
else -> throw IllegalArgumentException()
}
@@ -34,5 +40,5 @@ enum class EventOccurrencesRange(private val left: Int, private val right: Int)
operator fun plus(other: EventOccurrencesRange): EventOccurrencesRange = Companion.plus(this, other)
}
fun EventOccurrencesRange.isDefinitelyVisited(): Boolean = this == EventOccurrencesRange.EXACTLY_ONCE || this == EventOccurrencesRange.AT_LEAST_ONCE
fun EventOccurrencesRange.canBeRevisited(): Boolean = this == EventOccurrencesRange.UNKNOWN || this == EventOccurrencesRange.AT_LEAST_ONCE
fun EventOccurrencesRange.isDefinitelyVisited(): Boolean = this == EventOccurrencesRange.EXACTLY_ONCE || this == EventOccurrencesRange.AT_LEAST_ONCE || this == EventOccurrencesRange.MORE_THAN_ONCE
fun EventOccurrencesRange.canBeRevisited(): Boolean = this == EventOccurrencesRange.UNKNOWN || this == EventOccurrencesRange.AT_LEAST_ONCE || this == EventOccurrencesRange.MORE_THAN_ONCE