LL API: always create FirFile with lazy bodies

This commit is contained in:
Ilya Kirillov
2022-01-20 19:01:35 +01:00
parent 75ae37fcbf
commit c7729689c4
28 changed files with 403 additions and 3683 deletions
@@ -453,7 +453,7 @@ class DeclarationsConverter(
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints, classSymbol) }
withCapturedTypeParameters(status.isInner || isLocal, firTypeParameters) {
withCapturedTypeParameters(status.isInner || isLocal, classNode.toFirSourceElement(), firTypeParameters) {
var delegatedFieldsMap: Map<Int, FirFieldSymbol>? = null
buildRegularClass {
source = classNode.toFirSourceElement()
@@ -1141,7 +1141,7 @@ class DeclarationsConverter(
this.isLocal = false
receiverTypeRef = receiverType
dispatchReceiverType = currentDispatchReceiverType()
withCapturedTypeParameters(true, firTypeParameters) {
withCapturedTypeParameters(true, propertySource, firTypeParameters) {
typeParameters += firTypeParameters
val delegateBuilder = delegateExpression?.let {
@@ -1619,7 +1619,7 @@ class DeclarationsConverter(
listOf()
}
withCapturedTypeParameters(true, actualTypeParameters) {
withCapturedTypeParameters(true, functionSource, actualTypeParameters) {
valueParametersList?.let { list ->
valueParameters += convertValueParameters(
list,
@@ -534,7 +534,10 @@ open class RawFirBuilder(
this.name = name
symbol = FirValueParameterSymbol(name)
defaultValue = if (hasDefaultValue()) {
{ this@toFirValueParameter.defaultValue }.toFirExpression("Should have default value")
disabledLazyMode {
// TODO build lazy initializers here
{ this@toFirValueParameter.defaultValue }.toFirExpression("Should have default value")
}
} else null
isCrossinline = hasModifier(CROSSINLINE_KEYWORD)
isNoinline = hasModifier(NOINLINE_KEYWORD)
@@ -726,7 +729,7 @@ open class RawFirBuilder(
val argumentList = buildArgumentList {
source = valueArgumentList?.toFirSourceElement()
for (argument in valueArguments) {
val argumentExpression = argument.toFirExpression()
val argumentExpression = disabledLazyMode { argument.toFirExpression() }
arguments += when (argument) {
is KtLambdaArgument -> buildLambdaArgumentExpression {
source = argument.toFirSourceElement()
@@ -1044,7 +1047,7 @@ open class RawFirBuilder(
isExternal = classOrObject.hasModifier(EXTERNAL_KEYWORD)
}
withCapturedTypeParameters(status.isInner || isLocal, listOf()) {
withCapturedTypeParameters(status.isInner || isLocal, classOrObject.toFirSourceElement(), listOf()) {
var delegatedFieldsMap: Map<Int, FirFieldSymbol>?
buildRegularClass {
source = classOrObject.toFirSourceElement()
@@ -1281,7 +1284,7 @@ open class RawFirBuilder(
this.typeParameters
else
listOf()
withCapturedTypeParameters(true, actualTypeParameters) {
withCapturedTypeParameters(true, functionSource, actualTypeParameters) {
val outerContractDescription = function.obtainContractDescription()
val bodyWithContractDescription = function.buildFirBody()
this.body = bodyWithContractDescription.first
@@ -1569,7 +1572,7 @@ open class RawFirBuilder(
symbol = FirPropertySymbol(callableIdForName(propertyName))
dispatchReceiverType = currentDispatchReceiverType()
extractTypeParametersTo(this, symbol)
withCapturedTypeParameters(true, this.typeParameters) {
withCapturedTypeParameters(true, propertySource, this.typeParameters) {
backingField = this@toFirProperty.fieldDeclaration.toFirBackingField(
this@toFirProperty,
propertySymbol = symbol,
@@ -102,8 +102,13 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
context.dispatchReceiverTypesStack.add(selfType.type as ConeClassLikeType)
}
inline fun <T> withCapturedTypeParameters(status: Boolean, currentFirTypeParameters: List<FirTypeParameterRef>, block: () -> T): T {
context.pushFirTypeParameters(status, currentFirTypeParameters)
protected inline fun <T> withCapturedTypeParameters(
status: Boolean,
declarationSource: KtSourceElement? = null,
currentFirTypeParameters: List<FirTypeParameterRef>,
block: () -> T
): T {
addCapturedTypeParameters(status, declarationSource, currentFirTypeParameters)
return try {
block()
} finally {
@@ -111,6 +116,14 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
}
}
protected open fun addCapturedTypeParameters(
status: Boolean,
declarationSource: KtSourceElement?,
currentFirTypeParameters: List<FirTypeParameterRef>
) {
context.pushFirTypeParameters(status, currentFirTypeParameters)
}
fun callableIdForName(name: Name) =
when {
context.className.shortNameOrSpecial() == SpecialNames.ANONYMOUS -> CallableId(ANONYMOUS_CLASS_ID, name)