FIR: extract BodyResolveContext.withField

This commit is contained in:
Mikhail Glukhikh
2021-03-05 12:40:28 +03:00
parent 64353f34e9
commit bd2cdf2ec9
2 changed files with 19 additions and 9 deletions
@@ -388,6 +388,20 @@ class BodyResolveContext(
} }
} }
inline fun <T> withField(
field: FirField,
crossinline f: () -> T
): T {
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
withContainer(field) {
withTowerDataCleanup {
getPrimaryConstructorAllParametersScope()?.let { addLocalScope(it) }
f()
}
}
}
}
inline fun <T> withProperty( inline fun <T> withProperty(
property: FirProperty, property: FirProperty,
crossinline f: () -> T crossinline f: () -> T
@@ -179,15 +179,11 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
} }
dataFlowAnalyzer.enterField(field) dataFlowAnalyzer.enterField(field)
return withFullBodyResolve { return withFullBodyResolve {
context.withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) { context.withField(field) {
context.withContainer(field) { field.transformChildren(transformer, withExpectedType(returnTypeRef))
withPrimaryConstructorParameters(includeProperties = true) { }
field.transformChildren(transformer, withExpectedType(returnTypeRef)) if (field.initializer != null) {
} storeVariableReturnType(field)
if (field.initializer != null) {
storeVariableReturnType(field)
}
}
} }
transformer.replaceDeclarationResolvePhaseIfNeeded(field, transformerPhase) transformer.replaceDeclarationResolvePhaseIfNeeded(field, transformerPhase)
dataFlowAnalyzer.exitField(field) dataFlowAnalyzer.exitField(field)