FIR checker: refactor EventOccurrencesRange accumulation
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
b9d3578a86
commit
8eb2ae18dc
@@ -123,16 +123,25 @@ class PropertyInitializationInfoCollector(private val localProperties: Set<FirPr
|
|||||||
symbol: FirPropertySymbol
|
symbol: FirPropertySymbol
|
||||||
): PathAwarePropertyInitializationInfo {
|
): PathAwarePropertyInitializationInfo {
|
||||||
assert(dataForNode.keys.isNotEmpty())
|
assert(dataForNode.keys.isNotEmpty())
|
||||||
var resultMap = persistentMapOf<EdgeLabel, PropertyInitializationInfo>()
|
return addRange(dataForNode, symbol, EventOccurrencesRange.EXACTLY_ONCE, ::PathAwarePropertyInitializationInfo)
|
||||||
// before: { |-> { p1 |-> PI1 }, l1 |-> { p2 |-> PI2 }
|
|
||||||
for (label in dataForNode.keys) {
|
|
||||||
val dataPerLabel = dataForNode[label]!!
|
|
||||||
val existingKind = dataPerLabel[symbol] ?: EventOccurrencesRange.ZERO
|
|
||||||
val kind = existingKind + EventOccurrencesRange.EXACTLY_ONCE
|
|
||||||
resultMap = resultMap.put(label, dataPerLabel.put(symbol, kind))
|
|
||||||
}
|
|
||||||
// after (if symbol is p1):
|
|
||||||
// { |-> { p1 |-> PI1 + 1 }, l1 |-> { p1 |-> [1, 1], p2 |-> PI2 }
|
|
||||||
return PathAwarePropertyInitializationInfo(resultMap)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun <P : PathAwareControlFlowInfo<P, S>, S : ControlFlowInfo<S, K, EventOccurrencesRange>, K : Any> addRange(
|
||||||
|
info: P,
|
||||||
|
key: K,
|
||||||
|
range: EventOccurrencesRange,
|
||||||
|
constructor: (PersistentMap<EdgeLabel, S>) -> P
|
||||||
|
): P {
|
||||||
|
var resultMap = persistentMapOf<EdgeLabel, S>()
|
||||||
|
// before: { |-> { p1 |-> PI1 }, l1 |-> { p2 |-> PI2 } }
|
||||||
|
for (label in info.keys) {
|
||||||
|
val dataPerLabel = info[label]!!
|
||||||
|
val existingKind = dataPerLabel[key] ?: EventOccurrencesRange.ZERO
|
||||||
|
val kind = existingKind + range
|
||||||
|
resultMap = resultMap.put(label, dataPerLabel.put(key, kind))
|
||||||
|
}
|
||||||
|
// after (if key is p1):
|
||||||
|
// { |-> { p1 |-> PI1 + r }, l1 |-> { p1 |-> r, p2 |-> PI2 } }
|
||||||
|
return constructor(resultMap)
|
||||||
|
}
|
||||||
|
|||||||
+1
-11
@@ -289,17 +289,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
|||||||
): PathAwareLambdaInvocationInfo {
|
): PathAwareLambdaInvocationInfo {
|
||||||
val symbol = referenceToSymbol(reference)
|
val symbol = referenceToSymbol(reference)
|
||||||
return if (symbol != null) {
|
return if (symbol != null) {
|
||||||
var resultMap = persistentMapOf<EdgeLabel, LambdaInvocationInfo>()
|
addRange(this, symbol, range, ::PathAwareLambdaInvocationInfo)
|
||||||
// before: { |-> { p1 |-> PI1 }, l1 |-> { p2 |-> PI2 }
|
|
||||||
for (label in this.keys) {
|
|
||||||
val dataPerLabel = this[label]!!
|
|
||||||
val existingKind = dataPerLabel[symbol] ?: EventOccurrencesRange.ZERO
|
|
||||||
val kind = existingKind + range
|
|
||||||
resultMap = resultMap.put(label, dataPerLabel.put(symbol, kind))
|
|
||||||
}
|
|
||||||
// after (if symbol is p1):
|
|
||||||
// { |-> { p1 |-> PI1 + r }, l1 |-> { p1 |-> r, p2 |-> PI2 }
|
|
||||||
PathAwareLambdaInvocationInfo(resultMap)
|
|
||||||
} else this
|
} else this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user