FIR: introduce BodyResolveContext.forFunctionBody
This commit is contained in:
+39
-31
@@ -379,7 +379,6 @@ class BodyResolveContext(
|
|||||||
|
|
||||||
inline fun <T> withSimpleFunction(
|
inline fun <T> withSimpleFunction(
|
||||||
simpleFunction: FirSimpleFunction,
|
simpleFunction: FirSimpleFunction,
|
||||||
holder: SessionHolder,
|
|
||||||
crossinline f: () -> T
|
crossinline f: () -> T
|
||||||
): T {
|
): T {
|
||||||
if (containerIfAny !is FirClass<*>) {
|
if (containerIfAny !is FirClass<*>) {
|
||||||
@@ -387,12 +386,45 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return withTypeParametersOf(simpleFunction) {
|
return withTypeParametersOf(simpleFunction) {
|
||||||
|
withContainer(simpleFunction, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> forFunctionBody(
|
||||||
|
function: FirFunction<*>,
|
||||||
|
holder: SessionHolder,
|
||||||
|
crossinline f: () -> T
|
||||||
|
): T {
|
||||||
|
return withTowerDataCleanup {
|
||||||
|
addLocalScope(FirLocalScope())
|
||||||
|
if (function is FirSimpleFunction) {
|
||||||
|
val receiverTypeRef = function.receiverTypeRef
|
||||||
|
withLabelAndReceiverType(function.name, function, receiverTypeRef?.coneType, holder, f)
|
||||||
|
} else {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> forConstructorBody(
|
||||||
|
constructor: FirConstructor,
|
||||||
|
parametersScope: FirLocalScope?,
|
||||||
|
crossinline f: () -> T
|
||||||
|
): T {
|
||||||
|
return if (constructor.isPrimary) {
|
||||||
|
/*
|
||||||
|
* Primary constructor may have body only if class delegates implementation to some property
|
||||||
|
* In it's body we don't have this receiver for building class, so we need to use
|
||||||
|
* special towerDataContext
|
||||||
|
*/
|
||||||
|
withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
||||||
|
parametersScope?.let { addLocalScope(it) }
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
withTowerDataCleanup {
|
withTowerDataCleanup {
|
||||||
addLocalScope(FirLocalScope())
|
parametersScope?.let { addLocalScope(it) }
|
||||||
val receiverTypeRef = simpleFunction.receiverTypeRef
|
f()
|
||||||
withContainer(simpleFunction) {
|
|
||||||
withLabelAndReceiverType(simpleFunction.name, simpleFunction, receiverTypeRef?.coneType, holder, f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -584,8 +616,7 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forDelegatedConstructor(
|
inline fun <T> forDelegatedConstructor(
|
||||||
constructor: FirConstructor,
|
parametersScope: FirLocalScope?,
|
||||||
parametersScope: FirLocalScope? = buildConstructorParametersScope(constructor),
|
|
||||||
crossinline f: () -> T
|
crossinline f: () -> T
|
||||||
): T {
|
): T {
|
||||||
if (parametersScope == null) return f()
|
if (parametersScope == null) return f()
|
||||||
@@ -595,29 +626,6 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forConstructorBody(
|
|
||||||
constructor: FirConstructor,
|
|
||||||
parametersScope: FirLocalScope? = buildConstructorParametersScope(constructor),
|
|
||||||
crossinline f: () -> T
|
|
||||||
): T {
|
|
||||||
return if (constructor.isPrimary) {
|
|
||||||
/*
|
|
||||||
* Primary constructor may have body only if class delegates implementation to some property
|
|
||||||
* In it's body we don't have this receiver for building class, so we need to use
|
|
||||||
* special towerDataContext
|
|
||||||
*/
|
|
||||||
withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
|
||||||
parametersScope?.let { addLocalScope(it) }
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
withTowerDataCleanup {
|
|
||||||
parametersScope?.let { addLocalScope(it) }
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun buildConstructorParametersScope(constructor: FirConstructor): FirLocalScope? =
|
fun buildConstructorParametersScope(constructor: FirConstructor): FirLocalScope? =
|
||||||
if (constructor.isPrimary) getPrimaryConstructorAllParametersScope()
|
if (constructor.isPrimary) getPrimaryConstructorAllParametersScope()
|
||||||
else constructor.valueParameters.fold(FirLocalScope()) { acc, param -> acc.storeVariable(param) }
|
else constructor.valueParameters.fold(FirLocalScope()) { acc, param -> acc.storeVariable(param) }
|
||||||
|
|||||||
+12
-11
@@ -456,19 +456,19 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
|||||||
}
|
}
|
||||||
|
|
||||||
doTransformTypeParameters(simpleFunction)
|
doTransformTypeParameters(simpleFunction)
|
||||||
// TODO: I think it worth creating something like runAllPhasesForLocalFunction
|
|
||||||
context.withTypeParametersOf(simpleFunction) {
|
val containingDeclaration = context.containerIfAny
|
||||||
val containingDeclaration = context.containerIfAny
|
return context.withSimpleFunction(simpleFunction) {
|
||||||
|
// TODO: I think it worth creating something like runAllPhasesForLocalFunction
|
||||||
if (containingDeclaration != null && containingDeclaration !is FirClass<*>) {
|
if (containingDeclaration != null && containingDeclaration !is FirClass<*>) {
|
||||||
// For class members everything should be already prepared
|
// For class members everything should be already prepared
|
||||||
prepareSignatureForBodyResolve(simpleFunction)
|
prepareSignatureForBodyResolve(simpleFunction)
|
||||||
simpleFunction.transformStatus(this, simpleFunction.resolveStatus().mode())
|
simpleFunction.transformStatus(this, simpleFunction.resolveStatus().mode())
|
||||||
}
|
}
|
||||||
}
|
context.forFunctionBody(simpleFunction, components) {
|
||||||
|
withFullBodyResolve {
|
||||||
return withFullBodyResolve {
|
transformFunctionWithGivenSignature(simpleFunction, ResolutionMode.ContextIndependent)
|
||||||
context.withSimpleFunction(simpleFunction, components) {
|
}
|
||||||
transformFunctionWithGivenSignature(simpleFunction, ResolutionMode.ContextIndependent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,7 +553,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
|||||||
constructor.transformValueParameters(transformer, data)
|
constructor.transformValueParameters(transformer, data)
|
||||||
}
|
}
|
||||||
val parametersScope = context.buildConstructorParametersScope(constructor)
|
val parametersScope = context.buildConstructorParametersScope(constructor)
|
||||||
context.forDelegatedConstructor(constructor, parametersScope) {
|
context.forDelegatedConstructor(parametersScope) {
|
||||||
constructor.transformDelegatedConstructor(transformer, data)
|
constructor.transformDelegatedConstructor(transformer, data)
|
||||||
}
|
}
|
||||||
context.forConstructorBody(constructor, parametersScope) {
|
context.forConstructorBody(constructor, parametersScope) {
|
||||||
@@ -587,8 +587,9 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
|||||||
valueParameter.replaceReturnTypeRef(
|
valueParameter.replaceReturnTypeRef(
|
||||||
valueParameter.returnTypeRef.errorTypeFromPrototype(ConeSimpleDiagnostic("Unresolved value parameter type"))
|
valueParameter.returnTypeRef.errorTypeFromPrototype(ConeSimpleDiagnostic("Unresolved value parameter type"))
|
||||||
)
|
)
|
||||||
context.storeVariable(valueParameter)
|
return context.withValueParameter(valueParameter) {
|
||||||
return valueParameter.compose()
|
valueParameter.compose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dataFlowAnalyzer.enterValueParameter(valueParameter)
|
dataFlowAnalyzer.enterValueParameter(valueParameter)
|
||||||
|
|||||||
+4
-2
@@ -66,8 +66,10 @@ open class FirContractResolveTransformer(
|
|||||||
return simpleFunction.compose()
|
return simpleFunction.compose()
|
||||||
}
|
}
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return context.withSimpleFunction(simpleFunction, components) {
|
return context.withSimpleFunction(simpleFunction) {
|
||||||
transformContractDescriptionOwner(simpleFunction)
|
context.forFunctionBody(simpleFunction, components) {
|
||||||
|
transformContractDescriptionOwner(simpleFunction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user