Make all necessary refactoring after merge
1) Removed all unnecessary sessions 2) Added delegation converter 3) Moved property accessor initialization to apply block instead of constructor 4) Removed unnecessary AnotationContainer class
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f3a7db2428
commit
00f880a5a0
+1
-1
@@ -25,7 +25,7 @@ open class BaseConverter(
|
||||
private val tree: FlyweightCapableTreeStructure<LighterASTNode>,
|
||||
context: Context = Context()
|
||||
) : BaseFirBuilder<LighterASTNode>(session, context) {
|
||||
protected val implicitType = FirImplicitTypeRefImpl(session, null)
|
||||
protected val implicitType = FirImplicitTypeRefImpl(null)
|
||||
|
||||
override val LighterASTNode.elementType: IElementType
|
||||
get() = this.tokenType
|
||||
|
||||
+13
-25
@@ -9,42 +9,29 @@ import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.KtNodeType
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirFunctionTarget
|
||||
import org.jetbrains.kotlin.fir.FirLabel
|
||||
import org.jetbrains.kotlin.fir.FirReference
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.addDefaultBoundIfNecessary
|
||||
import org.jetbrains.kotlin.fir.builder.generateResolvedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterContainer
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirVariableImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirBlockImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirCallWithArgumentList
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirComponentCallImpl
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.DestructuringDeclaration
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.TypeConstraint
|
||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirExplicitThisReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
|
||||
import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.*
|
||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.parsing.KotlinExpressionParsing
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStringTemplateExpressionElementType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
private val expressionSet = listOf(
|
||||
REFERENCE_EXPRESSION,
|
||||
@@ -93,6 +80,7 @@ fun FirTypeParameterContainer.joinTypeParameters(typeConstraints: List<TypeConst
|
||||
typeParameter.annotations += typeConstraint.firTypeRef.annotations
|
||||
typeParameter.annotations += typeConstraint.annotations
|
||||
}
|
||||
(typeParameter as FirTypeParameterImpl).addDefaultBoundIfNecessary()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,7 +119,7 @@ fun generateDestructuringBlock(
|
||||
container: FirVariable<*>,
|
||||
tmpVariable: Boolean
|
||||
): FirExpression {
|
||||
return FirBlockImpl(session, null).apply {
|
||||
return FirBlockImpl(null).apply {
|
||||
if (tmpVariable) {
|
||||
statements += container
|
||||
}
|
||||
@@ -140,7 +128,7 @@ fun generateDestructuringBlock(
|
||||
statements += FirVariableImpl(
|
||||
session, null, entry.name,
|
||||
entry.returnTypeRef, isVar,
|
||||
FirComponentCallImpl(session, null, index + 1, generateResolvedAccessExpression(session, null, container)),
|
||||
FirComponentCallImpl(null, index + 1, generateResolvedAccessExpression(null, container)),
|
||||
FirVariableSymbol(entry.name) // TODO?
|
||||
).apply {
|
||||
annotations += entry.annotations
|
||||
|
||||
+62
-61
@@ -7,16 +7,15 @@ package org.jetbrains.kotlin.fir.lightTree.converter
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.TokenType
|
||||
import com.intellij.psi.tree.IFileElementType
|
||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.Context
|
||||
import org.jetbrains.kotlin.fir.builder.generateAccessorsByDelegate
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
@@ -104,7 +103,7 @@ class DeclarationsConverter(
|
||||
else -> if (node.isExpression()) container += expressionConverter.getAsFirExpression<FirStatement>(node)
|
||||
}
|
||||
}
|
||||
return FirBlockImpl(session, null).apply {
|
||||
return FirBlockImpl(null).apply {
|
||||
firStatements.forEach { firStatement ->
|
||||
if (firStatement !is FirBlock || firStatement.annotations.isNotEmpty()) {
|
||||
statements += firStatement
|
||||
@@ -156,7 +155,6 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
return FirImportImpl(
|
||||
session,
|
||||
null,
|
||||
importedFqName,
|
||||
isAllUnder,
|
||||
@@ -180,7 +178,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseModifierList
|
||||
*/
|
||||
private fun convertModifierList(modifiers: LighterASTNode): Modifier {
|
||||
val modifier = Modifier(session)
|
||||
val modifier = Modifier()
|
||||
modifiers.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
ANNOTATION -> modifier.annotations += convertAnnotation(it)
|
||||
@@ -195,7 +193,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeModifierList
|
||||
*/
|
||||
private fun convertTypeModifierList(modifiers: LighterASTNode): TypeModifier {
|
||||
val typeModifierList = TypeModifier(session)
|
||||
val typeModifierList = TypeModifier()
|
||||
modifiers.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
ANNOTATION -> typeModifierList.annotations += convertAnnotation(it)
|
||||
@@ -210,7 +208,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeArgumentModifierList
|
||||
*/
|
||||
private fun convertTypeArgumentModifierList(modifiers: LighterASTNode): TypeProjectionModifier {
|
||||
val typeArgumentModifierList = TypeProjectionModifier(session)
|
||||
val typeArgumentModifierList = TypeProjectionModifier()
|
||||
modifiers.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
ANNOTATION -> typeArgumentModifierList.annotations += convertAnnotation(it)
|
||||
@@ -225,7 +223,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeArgumentModifierList
|
||||
*/
|
||||
private fun convertTypeParameterModifiers(modifiers: LighterASTNode): TypeParameterModifier {
|
||||
val modifier = TypeParameterModifier(session)
|
||||
val modifier = TypeParameterModifier()
|
||||
modifiers.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
ANNOTATION -> modifier.annotations += convertAnnotation(it)
|
||||
@@ -301,7 +299,6 @@ class DeclarationsConverter(
|
||||
}
|
||||
}
|
||||
return FirAnnotationCallImpl(
|
||||
session,
|
||||
null,
|
||||
annotationUseSiteTarget ?: defaultAnnotationUseSiteTarget,
|
||||
constructorCalleePair.first
|
||||
@@ -313,7 +310,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseClassOrObject
|
||||
*/
|
||||
private fun convertClass(classNode: LighterASTNode): FirDeclaration {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var classKind: ClassKind = ClassKind.CLASS //TODO
|
||||
var identifier: String? = null
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
@@ -382,10 +379,10 @@ class DeclarationsConverter(
|
||||
firClass.superTypeRefs += superTypeRefs
|
||||
|
||||
val classWrapper = ClassWrapper(
|
||||
session, className, modifiers, classKind,
|
||||
primaryConstructor != null,
|
||||
className, modifiers, classKind, primaryConstructor != null,
|
||||
classBody.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(),
|
||||
null.toDelegatedSelfType(firClass), delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef, superTypeCallEntry
|
||||
null.toDelegatedSelfType(firClass),
|
||||
delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef, superTypeCallEntry
|
||||
)
|
||||
//parse primary constructor
|
||||
val primaryConstructorWrapper = convertPrimaryConstructor(primaryConstructor, classWrapper)
|
||||
@@ -410,7 +407,9 @@ class DeclarationsConverter(
|
||||
if (modifiers.isDataClass() && firPrimaryConstructor != null) {
|
||||
val zippedParameters = MutableList(properties.size) { null }.zip(properties)
|
||||
zippedParameters.generateComponentFunctions(session, firClass, context.packageFqName, context.className)
|
||||
zippedParameters.generateCopyFunction(session, null, firClass, context.packageFqName, context.className, firPrimaryConstructor)
|
||||
zippedParameters.generateCopyFunction(
|
||||
session, null, firClass, context.packageFqName, context.className, firPrimaryConstructor
|
||||
)
|
||||
// TODO: equals, hashCode, toString
|
||||
}
|
||||
|
||||
@@ -423,7 +422,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitObjectLiteralExpression
|
||||
*/
|
||||
fun convertObjectLiteral(objectLiteral: LighterASTNode): FirElement {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var primaryConstructor: LighterASTNode? = null
|
||||
val superTypeRefs = mutableListOf<FirTypeRef>()
|
||||
val superTypeCallEntry = mutableListOf<FirExpression>()
|
||||
@@ -445,14 +444,13 @@ class DeclarationsConverter(
|
||||
superTypeRefs.ifEmpty { superTypeRefs += implicitAnyType }
|
||||
val delegatedType = delegatedSuperTypeRef ?: implicitAnyType
|
||||
|
||||
return FirAnonymousObjectImpl(session, null).apply {
|
||||
return FirAnonymousObjectImpl(null).apply {
|
||||
annotations += modifiers.annotations
|
||||
this.superTypeRefs += superTypeRefs
|
||||
this.typeRef = superTypeRefs.first()
|
||||
|
||||
val classWrapper = ClassWrapper(
|
||||
this@DeclarationsConverter.session, SpecialNames.NO_NAME_PROVIDED, modifiers, ClassKind.OBJECT,
|
||||
hasPrimaryConstructor = false,
|
||||
SpecialNames.NO_NAME_PROVIDED, modifiers, ClassKind.OBJECT, hasPrimaryConstructor = false,
|
||||
hasSecondaryConstructor = classBody.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(),
|
||||
delegatedSelfTypeRef = delegatedType,
|
||||
delegatedSuperTypeRef = delegatedType,
|
||||
@@ -472,7 +470,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseEnumEntry
|
||||
*/
|
||||
private fun convertEnumEntry(enumEntry: LighterASTNode, classWrapper: ClassWrapper): FirEnumEntryImpl {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
lateinit var identifier: String
|
||||
var hasInitializerList = false
|
||||
val enumSuperTypeCallEntry = mutableListOf<FirExpression>()
|
||||
@@ -507,8 +505,7 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
val enumClassWrapper = ClassWrapper(
|
||||
session, enumEntryName, modifiers, ClassKind.ENUM_ENTRY,
|
||||
hasPrimaryConstructor = true,
|
||||
enumEntryName, modifiers, ClassKind.ENUM_ENTRY, hasPrimaryConstructor = true,
|
||||
hasSecondaryConstructor = classBodyNode.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(),
|
||||
delegatedSelfTypeRef = null.toDelegatedSelfType(firEnumEntry),
|
||||
delegatedSuperTypeRef = if (hasInitializerList) classWrapper.getFirUserTypeFromClassName() else defaultDelegatedSuperTypeRef,
|
||||
@@ -566,7 +563,7 @@ class DeclarationsConverter(
|
||||
if (primaryConstructor == null && classWrapper.hasSecondaryConstructor) return null
|
||||
if (classWrapper.isInterface()) return null
|
||||
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
val valueParameters = mutableListOf<ValueParameter>()
|
||||
primaryConstructor?.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -577,7 +574,6 @@ class DeclarationsConverter(
|
||||
|
||||
val defaultVisibility = classWrapper.defaultConstructorVisibility()
|
||||
val firDelegatedCall = FirDelegatedConstructorCallImpl(
|
||||
session,
|
||||
null,
|
||||
classWrapper.delegatedSuperTypeRef,
|
||||
isThis = false
|
||||
@@ -616,7 +612,7 @@ class DeclarationsConverter(
|
||||
return FirAnonymousInitializerImpl(
|
||||
session,
|
||||
null,
|
||||
if (stubMode) FirEmptyExpressionBlock(session) else firBlock
|
||||
if (stubMode) FirEmptyExpressionBlock() else firBlock
|
||||
)
|
||||
}
|
||||
|
||||
@@ -624,7 +620,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseSecondaryConstructor
|
||||
*/
|
||||
private fun convertSecondaryConstructor(secondaryConstructor: LighterASTNode, classWrapper: ClassWrapper): FirConstructor {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
val firValueParameters = mutableListOf<ValueParameter>()
|
||||
var constructorDelegationCall: FirDelegatedConstructorCall? = null
|
||||
var block: LighterASTNode? = null
|
||||
@@ -639,7 +635,7 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
val delegatedSelfTypeRef =
|
||||
if (classWrapper.isObjectLiteral()) FirErrorTypeRefImpl(session, null, "Constructor in object")
|
||||
if (classWrapper.isObjectLiteral()) FirErrorTypeRefImpl(null, "Constructor in object")
|
||||
else classWrapper.delegatedSelfTypeRef
|
||||
|
||||
val firConstructor = FirConstructorImpl(
|
||||
@@ -683,8 +679,8 @@ class DeclarationsConverter(
|
||||
val isThis = (isImplicit && classWrapper.hasPrimaryConstructor) || thisKeywordPresent
|
||||
val delegatedType =
|
||||
if (classWrapper.isObjectLiteral() || classWrapper.isInterface()) when {
|
||||
isThis -> FirErrorTypeRefImpl(session, null, "Constructor in object")
|
||||
else -> FirErrorTypeRefImpl(session, null, "No super type")
|
||||
isThis -> FirErrorTypeRefImpl(null, "Constructor in object")
|
||||
else -> FirErrorTypeRefImpl(null, "No super type")
|
||||
}
|
||||
else when {
|
||||
isThis -> classWrapper.delegatedSelfTypeRef
|
||||
@@ -692,7 +688,6 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
return FirDelegatedConstructorCallImpl(
|
||||
session,
|
||||
null,
|
||||
delegatedType,
|
||||
isThis
|
||||
@@ -703,7 +698,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeAlias
|
||||
*/
|
||||
private fun convertTypeAlias(typeAlias: LighterASTNode): FirDeclaration {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var identifier: String? = null
|
||||
lateinit var firType: FirTypeRef
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
@@ -738,7 +733,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseProperty
|
||||
*/
|
||||
fun convertPropertyDeclaration(property: LighterASTNode): FirDeclaration {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var identifier: String? = null
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
var isReturnType = false
|
||||
@@ -780,9 +775,14 @@ class DeclarationsConverter(
|
||||
returnType,
|
||||
isVar,
|
||||
firExpression,
|
||||
delegate = delegateExpression?.let { expressionConverter.getAsFirExpression(it, "Incorrect delegate expression") }
|
||||
delegate = delegateExpression?.let {
|
||||
FirWrappedDelegateExpressionImpl(
|
||||
null, expressionConverter.getAsFirExpression(it, "Incorrect delegate expression")
|
||||
)
|
||||
}
|
||||
).apply {
|
||||
annotations += modifiers.annotations
|
||||
this.generateAccessorsByDelegate(this@DeclarationsConverter.session, member = false, stubMode = stubMode)
|
||||
}
|
||||
} else {
|
||||
FirMemberPropertyImpl(
|
||||
@@ -801,13 +801,21 @@ class DeclarationsConverter(
|
||||
returnType,
|
||||
isVar,
|
||||
firExpression,
|
||||
getter ?: FirDefaultPropertyGetter(session, null, returnType, modifiers.getVisibility()),
|
||||
if (isVar) setter ?: FirDefaultPropertySetter(session, null, returnType, modifiers.getVisibility()) else null,
|
||||
delegateExpression?.let { expressionConverter.getAsFirExpression(it, "Should have delegate") }
|
||||
delegateExpression?.let {
|
||||
FirWrappedDelegateExpressionImpl(
|
||||
null,
|
||||
expressionConverter.getAsFirExpression(it, "Should have delegate")
|
||||
)
|
||||
}
|
||||
).apply {
|
||||
this.typeParameters += firTypeParameters
|
||||
this.joinTypeParameters(typeConstraints)
|
||||
annotations += modifiers.annotations
|
||||
this.getter = getter ?: FirDefaultPropertyGetter(session, null, returnType, modifiers.getVisibility())
|
||||
this.setter = if (isVar) setter ?: FirDefaultPropertySetter(session, null, returnType, modifiers.getVisibility()) else null
|
||||
generateAccessorsByDelegate(
|
||||
this@DeclarationsConverter.session, member = parentNode?.tokenType != KT_FILE, stubMode = stubMode
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -818,7 +826,7 @@ class DeclarationsConverter(
|
||||
private fun convertDestructingDeclaration(destructingDeclaration: LighterASTNode): DestructuringDeclaration {
|
||||
var isVar = false
|
||||
val entries = mutableListOf<FirVariable<*>>()
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, "Destructuring declaration without initializer")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "Destructuring declaration without initializer")
|
||||
destructingDeclaration.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
VAR_KEYWORD -> isVar = true
|
||||
@@ -835,7 +843,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseMultiDeclarationName
|
||||
*/
|
||||
private fun convertDestructingDeclarationEntry(entry: LighterASTNode): FirVariable<*> {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var identifier: String? = null
|
||||
var firType: FirTypeRef? = null
|
||||
entry.forEachChildren {
|
||||
@@ -857,7 +865,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyGetterOrSetter
|
||||
*/
|
||||
private fun convertGetterOrSetter(getterOrSetter: LighterASTNode, propertyTypeRef: FirTypeRef): FirPropertyAccessor {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var isGetter = true
|
||||
var returnType: FirTypeRef? = null
|
||||
var firValueParameters: FirValueParameter = FirDefaultSetterValueParameter(session, null, propertyTypeRef)
|
||||
@@ -901,7 +909,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.toFirValueParameter
|
||||
*/
|
||||
private fun convertSetterParameter(setterParameter: LighterASTNode, propertyTypeRef: FirTypeRef): FirValueParameter {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
lateinit var firValueParameter: FirValueParameter
|
||||
setterParameter.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -928,7 +936,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunction
|
||||
*/
|
||||
fun convertFunctionDeclaration(functionDeclaration: LighterASTNode): FirDeclaration {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var identifier: String? = null
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
var valueParametersList: LighterASTNode? = null
|
||||
@@ -1009,7 +1017,6 @@ class DeclarationsConverter(
|
||||
return when {
|
||||
blockNode != null -> return convertBlock(blockNode)
|
||||
expression != null -> FirSingleExpressionBlock(
|
||||
session,
|
||||
expressionConverter.getAsFirExpression<FirExpression>(expression, "Function has no body (but should)").toReturn()
|
||||
)
|
||||
else -> null
|
||||
@@ -1020,10 +1027,9 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseBlock
|
||||
*/
|
||||
fun convertBlock(block: LighterASTNode?): FirBlock {
|
||||
if (block == null) return FirEmptyExpressionBlock(session)
|
||||
if (block == null) return FirEmptyExpressionBlock()
|
||||
if (block.tokenType != BLOCK) {
|
||||
return FirSingleExpressionBlock(
|
||||
session,
|
||||
expressionConverter.getAsFirExpression(block)
|
||||
)
|
||||
}
|
||||
@@ -1032,8 +1038,7 @@ class DeclarationsConverter(
|
||||
return DeclarationsConverter(session, stubMode, blockTree, context).convertBlockExpression(blockTree.root)
|
||||
} else {
|
||||
FirSingleExpressionBlock(
|
||||
session,
|
||||
FirExpressionStub(session, null).toReturn()
|
||||
FirExpressionStub(null).toReturn()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1093,7 +1098,7 @@ class DeclarationsConverter(
|
||||
*/
|
||||
private fun convertExplicitDelegation(explicitDelegation: LighterASTNode): FirDelegatedTypeRef {
|
||||
lateinit var firTypeRef: FirTypeRef
|
||||
var firExpression: FirExpression? = FirErrorExpressionImpl(session, null, "Should have delegate")
|
||||
var firExpression: FirExpression? = FirErrorExpressionImpl(null, "Should have delegate")
|
||||
explicitDelegation.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
TYPE_REFERENCE -> firTypeRef = convertType(it)
|
||||
@@ -1102,7 +1107,6 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
return FirDelegatedTypeRefImpl(
|
||||
session,
|
||||
firTypeRef,
|
||||
firExpression
|
||||
)
|
||||
@@ -1154,7 +1158,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeParameter
|
||||
*/
|
||||
private fun convertTypeParameter(typeParameter: LighterASTNode): FirTypeParameter {
|
||||
var typeParameterModifiers = TypeParameterModifier(session)
|
||||
var typeParameterModifiers = TypeParameterModifier()
|
||||
var identifier: String? = null
|
||||
var firType: FirTypeRef? = null
|
||||
typeParameter.forEachChildren {
|
||||
@@ -1184,10 +1188,10 @@ class DeclarationsConverter(
|
||||
*/
|
||||
fun convertType(type: LighterASTNode): FirTypeRef {
|
||||
if (type.asText.isEmpty()) {
|
||||
return FirErrorTypeRefImpl(session, null, "Unwrapped type is null")
|
||||
return FirErrorTypeRefImpl(null, "Unwrapped type is null")
|
||||
}
|
||||
var typeModifiers = TypeModifier(session) //TODO what with suspend?
|
||||
var firType: FirTypeRef = FirErrorTypeRefImpl(session, null, "Incomplete code")
|
||||
var typeModifiers = TypeModifier() //TODO what with suspend?
|
||||
var firType: FirTypeRef = FirErrorTypeRefImpl(null, "Incomplete code")
|
||||
var afterLPar = false
|
||||
type.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -1197,8 +1201,8 @@ class DeclarationsConverter(
|
||||
USER_TYPE -> firType = convertUserType(it)
|
||||
NULLABLE_TYPE -> firType = convertNullableType(it)
|
||||
FUNCTION_TYPE -> firType = convertFunctionType(it)
|
||||
DYNAMIC_TYPE -> firType = FirDynamicTypeRefImpl(session, null, false)
|
||||
TokenType.ERROR_ELEMENT -> firType = FirErrorTypeRefImpl(session, null, "Unwrapped type is null")
|
||||
DYNAMIC_TYPE -> firType = FirDynamicTypeRefImpl(null, false)
|
||||
TokenType.ERROR_ELEMENT -> firType = FirErrorTypeRefImpl(null, "Unwrapped type is null")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1230,7 +1234,7 @@ class DeclarationsConverter(
|
||||
convertUserType(it, true)
|
||||
FUNCTION_TYPE -> firType = convertFunctionType(it, true)
|
||||
NULLABLE_TYPE -> firType = convertNullableType(it)
|
||||
DYNAMIC_TYPE -> firType = FirDynamicTypeRefImpl(session, null, true)
|
||||
DYNAMIC_TYPE -> firType = FirDynamicTypeRefImpl(null, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1253,14 +1257,13 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
if (identifier == null)
|
||||
return FirErrorTypeRefImpl(session, null, "Incomplete user type")
|
||||
return FirErrorTypeRefImpl(null, "Incomplete user type")
|
||||
|
||||
val qualifier = FirQualifierPartImpl(
|
||||
identifier.nameAsSafeName()
|
||||
).apply { typeArguments += firTypeArguments }
|
||||
|
||||
return FirUserTypeRefImpl(
|
||||
session,
|
||||
null,
|
||||
isNullable
|
||||
).apply {
|
||||
@@ -1284,7 +1287,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.tryParseTypeArgumentList
|
||||
*/
|
||||
private fun convertTypeProjection(typeProjection: LighterASTNode): FirTypeProjection {
|
||||
var modifiers = TypeProjectionModifier(session)
|
||||
var modifiers = TypeProjectionModifier()
|
||||
lateinit var firType: FirTypeRef
|
||||
var isStarProjection = false
|
||||
typeProjection.forEachChildren {
|
||||
@@ -1296,9 +1299,8 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
//annotations from modifiers must be ignored
|
||||
return if (isStarProjection) FirStarProjectionImpl(session, null)
|
||||
return if (isStarProjection) FirStarProjectionImpl(null)
|
||||
else FirTypeProjectionWithVarianceImpl(
|
||||
session,
|
||||
null,
|
||||
modifiers.getVariance(),
|
||||
firType
|
||||
@@ -1321,7 +1323,6 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
return FirFunctionTypeRefImpl(
|
||||
session,
|
||||
null,
|
||||
isNullable,
|
||||
receiverTypeReference,
|
||||
@@ -1344,7 +1345,7 @@ class DeclarationsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseValueParameter
|
||||
*/
|
||||
fun convertValueParameter(valueParameter: LighterASTNode): ValueParameter {
|
||||
var modifiers = Modifier(session)
|
||||
var modifiers = Modifier()
|
||||
var isVal = false
|
||||
var isVar = false
|
||||
var identifier: String? = null
|
||||
|
||||
+87
-89
@@ -46,7 +46,7 @@ class ExpressionsConverter(
|
||||
) : BaseConverter(session, tree, context) {
|
||||
|
||||
inline fun <reified R : FirElement> getAsFirExpression(expression: LighterASTNode?, errorReason: String = ""): R {
|
||||
return expression?.let { convertExpression(it, errorReason) } as? R ?: (FirErrorExpressionImpl(session, null, errorReason) as R)
|
||||
return expression?.let { convertExpression(it, errorReason) } as? R ?: (FirErrorExpressionImpl(null, errorReason) as R)
|
||||
}
|
||||
|
||||
/***** EXPRESSIONS *****/
|
||||
@@ -94,11 +94,11 @@ class ExpressionsConverter(
|
||||
|
||||
OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression)
|
||||
FUN -> declarationsConverter.convertFunctionDeclaration(expression)
|
||||
else -> FirErrorExpressionImpl(session, null, errorReason)
|
||||
else -> FirErrorExpressionImpl(null, errorReason)
|
||||
}
|
||||
}
|
||||
|
||||
return FirExpressionStub(session, null)
|
||||
return FirExpressionStub(null)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +123,7 @@ class ExpressionsConverter(
|
||||
valueParameters += if (multiDeclaration != null) {
|
||||
val multiParameter = FirValueParameterImpl(
|
||||
this@ExpressionsConverter.session, null, Name.special("<destruct>"),
|
||||
FirImplicitTypeRefImpl(this@ExpressionsConverter.session, null),
|
||||
FirImplicitTypeRefImpl(null),
|
||||
defaultValue = null, isCrossinline = false, isNoinline = false, isVararg = false
|
||||
)
|
||||
destructuringBlock = generateDestructuringBlock(
|
||||
@@ -138,13 +138,13 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
label = context.firLabels.pop() ?: context.firFunctionCalls.lastOrNull()?.calleeReference?.name?.let {
|
||||
FirLabelImpl(this@ExpressionsConverter.session, null, it.asString())
|
||||
FirLabelImpl(null, it.asString())
|
||||
}
|
||||
val bodyExpression = block?.let { declarationsConverter.convertBlockExpression(it) }
|
||||
?: FirErrorExpressionImpl(this@ExpressionsConverter.session, null, "Lambda has no body")
|
||||
?: FirErrorExpressionImpl(null, "Lambda has no body")
|
||||
body = if (bodyExpression is FirBlockImpl) {
|
||||
if (bodyExpression.statements.isEmpty()) {
|
||||
bodyExpression.statements.add(FirUnitExpression(this@ExpressionsConverter.session, null))
|
||||
bodyExpression.statements.add(FirUnitExpression(null))
|
||||
}
|
||||
if (destructuringBlock is FirBlock) {
|
||||
for ((index, statement) in destructuringBlock.statements.withIndex()) {
|
||||
@@ -153,7 +153,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
bodyExpression
|
||||
} else {
|
||||
FirSingleExpressionBlock(this@ExpressionsConverter.session, bodyExpression.toReturn())
|
||||
FirSingleExpressionBlock(bodyExpression.toReturn())
|
||||
}
|
||||
|
||||
context.firFunctions.removeLast()
|
||||
@@ -168,7 +168,7 @@ class ExpressionsConverter(
|
||||
var isLeftArgument = true
|
||||
lateinit var operationTokenName: String
|
||||
var leftArgNode: LighterASTNode? = null
|
||||
var rightArgAsFir: FirExpression = FirErrorExpressionImpl(session, null, "No right operand")
|
||||
var rightArgAsFir: FirExpression = FirErrorExpressionImpl(null, "No right operand")
|
||||
binaryExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
OPERATION_REFERENCE -> {
|
||||
@@ -193,19 +193,18 @@ class ExpressionsConverter(
|
||||
)
|
||||
ANDAND, OROR ->
|
||||
return getAsFirExpression<FirExpression>(leftArgNode, "No left operand").generateLazyLogicalOperation(
|
||||
session, rightArgAsFir, operationToken == ANDAND, null
|
||||
rightArgAsFir, operationToken == ANDAND, null
|
||||
)
|
||||
in OperatorConventions.IN_OPERATIONS ->
|
||||
return rightArgAsFir.generateContainsOperation(
|
||||
session, getAsFirExpression(leftArgNode, "No left operand"), operationToken == NOT_IN, null, null
|
||||
getAsFirExpression(leftArgNode, "No left operand"), operationToken == NOT_IN, null, null
|
||||
)
|
||||
}
|
||||
val conventionCallName = operationToken.toBinaryName()
|
||||
return if (conventionCallName != null || operationToken == IDENTIFIER) {
|
||||
FirFunctionCallImpl(session, null).apply {
|
||||
FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(
|
||||
this@ExpressionsConverter.session, null,
|
||||
conventionCallName ?: operationTokenName.nameAsSafeName()
|
||||
null, conventionCallName ?: operationTokenName.nameAsSafeName()
|
||||
)
|
||||
explicitReceiver = getAsFirExpression(leftArgNode, "No left operand")
|
||||
arguments += rightArgAsFir
|
||||
@@ -215,7 +214,7 @@ class ExpressionsConverter(
|
||||
if (firOperation in FirOperation.ASSIGNMENTS) {
|
||||
return leftArgNode.generateAssignment(null, rightArgAsFir, firOperation) { getAsFirExpression(this) }
|
||||
} else {
|
||||
FirOperatorCallImpl(session, null, firOperation).apply {
|
||||
FirOperatorCallImpl(null, firOperation).apply {
|
||||
arguments += getAsFirExpression<FirExpression>(leftArgNode, "No left operand")
|
||||
arguments += rightArgAsFir
|
||||
}
|
||||
@@ -233,7 +232,7 @@ class ExpressionsConverter(
|
||||
toFirOperation: String.() -> FirOperation
|
||||
): FirTypeOperatorCall {
|
||||
lateinit var operationTokenName: String
|
||||
var leftArgAsFir: FirExpression = FirErrorExpressionImpl(session, null, "No left operand")
|
||||
var leftArgAsFir: FirExpression = FirErrorExpressionImpl(null, "No left operand")
|
||||
lateinit var firType: FirTypeRef
|
||||
binaryExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -244,7 +243,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
val operation = operationTokenName.toFirOperation()
|
||||
return FirTypeOperatorCallImpl(session, null, operation, firType).apply {
|
||||
return FirTypeOperatorCallImpl(null, operation, firType).apply {
|
||||
arguments += leftArgAsFir
|
||||
}
|
||||
}
|
||||
@@ -258,7 +257,7 @@ class ExpressionsConverter(
|
||||
var firExpression: FirElement? = null
|
||||
labeledExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
LABEL_QUALIFIER -> context.firLabels += FirLabelImpl(session, null, it.toString().replace("@", ""))
|
||||
LABEL_QUALIFIER -> context.firLabels += FirLabelImpl(null, it.toString().replace("@", ""))
|
||||
BLOCK -> firExpression = declarationsConverter.convertBlock(it)
|
||||
PROPERTY -> firExpression = declarationsConverter.convertPropertyDeclaration(it)
|
||||
else -> if (it.isExpression()) firExpression = getAsFirExpression(it)
|
||||
@@ -269,7 +268,7 @@ class ExpressionsConverter(
|
||||
context.firLabels.removeLast()
|
||||
//println("Unused label: ${labeledExpression.getAsString()}")
|
||||
}
|
||||
return firExpression ?: FirErrorExpressionImpl(session, null, "Empty label")
|
||||
return firExpression ?: FirErrorExpressionImpl(null, "Empty label")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,13 +301,13 @@ class ExpressionsConverter(
|
||||
prefix = unaryExpression.tokenType == PREFIX_EXPRESSION
|
||||
) { getAsFirExpression(this) }
|
||||
}
|
||||
FirFunctionCallImpl(session, null).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@ExpressionsConverter.session, null, conventionCallName)
|
||||
FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(null, conventionCallName)
|
||||
explicitReceiver = getAsFirExpression(argument, "No operand")
|
||||
}
|
||||
} else {
|
||||
val firOperation = operationToken.toFirOperation()
|
||||
FirOperatorCallImpl(session, null, firOperation).apply {
|
||||
FirOperatorCallImpl(null, firOperation).apply {
|
||||
arguments += getAsFirExpression<FirExpression>(argument, "No operand")
|
||||
}
|
||||
}
|
||||
@@ -331,7 +330,7 @@ class ExpressionsConverter(
|
||||
|
||||
return (firExpression as? FirAbstractAnnotatedElement)?.apply {
|
||||
annotations += firAnnotationList
|
||||
} ?: FirErrorExpressionImpl(session, null, "Strange annotated expression: ${firExpression?.render()}")
|
||||
} ?: FirErrorExpressionImpl(null, "Strange annotated expression: ${firExpression?.render()}")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,12 +338,12 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitClassLiteralExpression
|
||||
*/
|
||||
private fun convertClassLiteralExpression(classLiteralExpression: LighterASTNode): FirExpression {
|
||||
var firReceiverExpression: FirExpression = FirErrorExpressionImpl(session, null, "No receiver in class literal")
|
||||
var firReceiverExpression: FirExpression = FirErrorExpressionImpl(null, "No receiver in class literal")
|
||||
classLiteralExpression.forEachChildren {
|
||||
if (it.isExpression()) firReceiverExpression = getAsFirExpression(it, "No receiver in class literal")
|
||||
}
|
||||
|
||||
return FirGetClassCallImpl(session, null).apply {
|
||||
return FirGetClassCallImpl(null).apply {
|
||||
arguments += firReceiverExpression
|
||||
}
|
||||
}
|
||||
@@ -370,7 +369,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirCallableReferenceAccessImpl(session, null).apply {
|
||||
return FirCallableReferenceAccessImpl(null).apply {
|
||||
calleeReference = firCallableReference.calleeReference
|
||||
explicitReceiver = firReceiverExpression
|
||||
}
|
||||
@@ -383,7 +382,7 @@ class ExpressionsConverter(
|
||||
private fun convertQualifiedExpression(dotQualifiedExpression: LighterASTNode): FirExpression {
|
||||
var isSelector = false
|
||||
var isSafe = false
|
||||
var firSelector: FirExpression = FirErrorExpressionImpl(session, null, "Qualified expression without selector") //after dot
|
||||
var firSelector: FirExpression = FirErrorExpressionImpl(null, "Qualified expression without selector") //after dot
|
||||
var firReceiver: FirExpression? = null //before dot
|
||||
dotQualifiedExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -427,14 +426,14 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirFunctionCallImpl(session, null).apply {
|
||||
return FirFunctionCallImpl(null).apply {
|
||||
this.calleeReference = when {
|
||||
name != null -> FirSimpleNamedReference(this@ExpressionsConverter.session, null, name.nameAsSafeName())
|
||||
name != null -> FirSimpleNamedReference(null, name.nameAsSafeName())
|
||||
additionalArgument != null -> {
|
||||
arguments += additionalArgument!!
|
||||
FirSimpleNamedReference(this@ExpressionsConverter.session, null, OperatorNameConventions.INVOKE)
|
||||
FirSimpleNamedReference(null, OperatorNameConventions.INVOKE)
|
||||
}
|
||||
else -> FirErrorNamedReference(this@ExpressionsConverter.session, null, "Call has no callee")
|
||||
else -> FirErrorNamedReference(null, "Call has no callee")
|
||||
}
|
||||
|
||||
context.firFunctionCalls += this
|
||||
@@ -452,7 +451,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
private fun LighterASTNode?.convertShortOrLongStringTemplate(errorReason: String): FirExpression {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, errorReason)
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, errorReason)
|
||||
this?.forEachChildren(LONG_TEMPLATE_ENTRY_START, LONG_TEMPLATE_ENTRY_END) {
|
||||
firExpression = getAsFirExpression(it, errorReason)
|
||||
}
|
||||
@@ -493,7 +492,7 @@ class ExpressionsConverter(
|
||||
subjectExpression = subjectVariable?.initializer ?: subjectExpression
|
||||
val hasSubject = subjectExpression != null
|
||||
val subject = FirWhenSubject()
|
||||
return FirWhenExpressionImpl(session, null, subjectExpression, subjectVariable).apply {
|
||||
return FirWhenExpressionImpl(null, subjectExpression, subjectVariable).apply {
|
||||
if (hasSubject) {
|
||||
subject.bind(this)
|
||||
}
|
||||
@@ -501,15 +500,15 @@ class ExpressionsConverter(
|
||||
val branch = entry.firBlock
|
||||
branches += if (!entry.isElse) {
|
||||
if (hasSubject) {
|
||||
val firCondition = entry.toFirWhenCondition(this@ExpressionsConverter.session, subject)
|
||||
FirWhenBranchImpl(this@ExpressionsConverter.session, null, firCondition, branch)
|
||||
val firCondition = entry.toFirWhenCondition(subject)
|
||||
FirWhenBranchImpl(null, firCondition, branch)
|
||||
} else {
|
||||
val firCondition = entry.toFirWhenConditionWithoutSubject(this@ExpressionsConverter.session)
|
||||
FirWhenBranchImpl(this@ExpressionsConverter.session, null, firCondition, branch)
|
||||
val firCondition = entry.toFirWhenConditionWithoutSubject()
|
||||
FirWhenBranchImpl(null, firCondition, branch)
|
||||
}
|
||||
} else {
|
||||
FirWhenBranchImpl(
|
||||
this@ExpressionsConverter.session, null, FirElseIfTrueCondition(this@ExpressionsConverter.session, null), branch
|
||||
null, FirElseIfTrueCondition(null), branch
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -522,7 +521,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertWhenEntry(whenEntry: LighterASTNode): WhenEntry {
|
||||
var isElse = false
|
||||
var firBlock: FirBlock = FirEmptyExpressionBlock(session)
|
||||
var firBlock: FirBlock = FirEmptyExpressionBlock()
|
||||
val conditions = mutableListOf<FirExpression>()
|
||||
whenEntry.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -539,21 +538,21 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
private fun convertWhenConditionExpression(whenCondition: LighterASTNode): FirExpression {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, "No expression in condition with expression")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "No expression in condition with expression")
|
||||
whenCondition.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
else -> if (it.isExpression()) firExpression = getAsFirExpression(it, "No expression in condition with expression")
|
||||
}
|
||||
}
|
||||
|
||||
return FirOperatorCallImpl(session, null, FirOperation.EQ).apply {
|
||||
return FirOperatorCallImpl(null, FirOperation.EQ).apply {
|
||||
arguments += firExpression
|
||||
}
|
||||
}
|
||||
|
||||
private fun convertWhenConditionInRange(whenCondition: LighterASTNode): FirExpression {
|
||||
var isNegate = false
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, "No range in condition with range")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "No range in condition with range")
|
||||
whenCondition.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
NOT_IN -> isNegate = true
|
||||
@@ -562,8 +561,8 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
val name = if (isNegate) OperatorNameConventions.NOT else SpecialNames.NO_NAME_PROVIDED
|
||||
return FirFunctionCallImpl(session, null).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@ExpressionsConverter.session, null, name)
|
||||
return FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(null, name)
|
||||
explicitReceiver = firExpression
|
||||
}
|
||||
}
|
||||
@@ -579,7 +578,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirTypeOperatorCallImpl(session, null, firOperation, firType)
|
||||
return FirTypeOperatorCallImpl(null, firOperation, firType)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +586,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitArrayAccessExpression
|
||||
*/
|
||||
private fun convertArrayAccessExpression(arrayAccess: LighterASTNode): FirFunctionCall {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, "No array expression")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "No array expression")
|
||||
val indices: MutableList<FirExpression> = mutableListOf()
|
||||
arrayAccess.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -595,8 +594,8 @@ class ExpressionsConverter(
|
||||
else -> if (it.isExpression()) firExpression = getAsFirExpression(it, "No array expression")
|
||||
}
|
||||
}
|
||||
return FirFunctionCallImpl(session, null).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@ExpressionsConverter.session, null, OperatorNameConventions.GET)
|
||||
return FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(null, OperatorNameConventions.GET)
|
||||
explicitReceiver = firExpression
|
||||
arguments += indices
|
||||
}
|
||||
@@ -611,7 +610,7 @@ class ExpressionsConverter(
|
||||
if (it.isExpression()) firExpressionList += getAsFirExpression<FirExpression>(it, "Incorrect collection literal argument")
|
||||
}
|
||||
|
||||
return FirArrayOfCallImpl(session, null).apply {
|
||||
return FirArrayOfCallImpl(null).apply {
|
||||
arguments += firExpressionList
|
||||
}
|
||||
}
|
||||
@@ -633,9 +632,9 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitSimpleNameExpression
|
||||
*/
|
||||
private fun convertSimpleNameExpression(referenceExpression: LighterASTNode): FirQualifiedAccessExpression {
|
||||
return FirQualifiedAccessExpressionImpl(session, null).apply {
|
||||
return FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference =
|
||||
FirSimpleNamedReference(this@ExpressionsConverter.session, null, referenceExpression.asText.nameAsSafeName())
|
||||
FirSimpleNamedReference(null, referenceExpression.asText.nameAsSafeName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,7 +644,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertDoWhile(doWhileLoop: LighterASTNode): FirElement {
|
||||
var block: LighterASTNode? = null
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(session, null, "No condition in do-while loop")
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, "No condition in do-while loop")
|
||||
doWhileLoop.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
BODY -> block = it
|
||||
@@ -653,7 +652,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirDoWhileLoopImpl(session, null, firCondition).configure { convertLoopBody(block) }
|
||||
return FirDoWhileLoopImpl(null, firCondition).configure { convertLoopBody(block) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -662,7 +661,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertWhile(whileLoop: LighterASTNode): FirElement {
|
||||
var block: LighterASTNode? = null
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(session, null, "No condition in while loop")
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, "No condition in while loop")
|
||||
whileLoop.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
BODY -> block = it
|
||||
@@ -670,7 +669,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirWhileLoopImpl(session, null, firCondition).configure { convertLoopBody(block) }
|
||||
return FirWhileLoopImpl(null, firCondition).configure { convertLoopBody(block) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -679,7 +678,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertFor(forLoop: LighterASTNode): FirElement {
|
||||
var parameter: ValueParameter? = null
|
||||
var rangeExpression: FirExpression = FirErrorExpressionImpl(session, null, "No range in for loop")
|
||||
var rangeExpression: FirExpression = FirErrorExpressionImpl(null, "No range in for loop")
|
||||
var blockNode: LighterASTNode? = null
|
||||
forLoop.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -689,28 +688,27 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
//TODO psi must be null
|
||||
return FirBlockImpl(session, null).apply {
|
||||
return FirBlockImpl(null).apply {
|
||||
val rangeVal =
|
||||
generateTemporaryVariable(this@ExpressionsConverter.session, null, Name.special("<range>"), rangeExpression)
|
||||
statements += rangeVal
|
||||
val iteratorVal = generateTemporaryVariable(
|
||||
this@ExpressionsConverter.session, null, Name.special("<iterator>"),
|
||||
FirFunctionCallImpl(this@ExpressionsConverter.session, null).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@ExpressionsConverter.session, null, Name.identifier("iterator"))
|
||||
explicitReceiver = generateResolvedAccessExpression(this@ExpressionsConverter.session, null, rangeVal)
|
||||
FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(null, Name.identifier("iterator"))
|
||||
explicitReceiver = generateResolvedAccessExpression(null, rangeVal)
|
||||
}
|
||||
)
|
||||
statements += iteratorVal
|
||||
statements += FirWhileLoopImpl(
|
||||
this@ExpressionsConverter.session, null,
|
||||
FirFunctionCallImpl(this@ExpressionsConverter.session, null).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@ExpressionsConverter.session, null, Name.identifier("hasNext"))
|
||||
explicitReceiver = generateResolvedAccessExpression(this@ExpressionsConverter.session, null, iteratorVal)
|
||||
null,
|
||||
FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(null, Name.identifier("hasNext"))
|
||||
explicitReceiver = generateResolvedAccessExpression(null, iteratorVal)
|
||||
}
|
||||
).configure {
|
||||
// NB: just body.toFirBlock() isn't acceptable here because we need to add some statements
|
||||
val block = FirBlockImpl(this@ExpressionsConverter.session, null).apply {
|
||||
val block = FirBlockImpl(null).apply {
|
||||
statements += convertLoopBody(blockNode).statements
|
||||
}
|
||||
if (parameter != null) {
|
||||
@@ -718,9 +716,9 @@ class ExpressionsConverter(
|
||||
val firLoopParameter = generateTemporaryVariable(
|
||||
this@ExpressionsConverter.session, null,
|
||||
if (multiDeclaration != null) Name.special("<destruct>") else parameter!!.firValueParameter.name,
|
||||
FirFunctionCallImpl(this@ExpressionsConverter.session, null).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@ExpressionsConverter.session, null, Name.identifier("next"))
|
||||
explicitReceiver = generateResolvedAccessExpression(this@ExpressionsConverter.session, null, iteratorVal)
|
||||
FirFunctionCallImpl(null).apply {
|
||||
calleeReference = FirSimpleNamedReference(null, Name.identifier("next"))
|
||||
explicitReceiver = generateResolvedAccessExpression(null, iteratorVal)
|
||||
}
|
||||
)
|
||||
if (multiDeclaration != null) {
|
||||
@@ -759,8 +757,8 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
return when {
|
||||
firStatement != null -> FirSingleExpressionBlock(session, firStatement!!)
|
||||
firBlock == null -> FirEmptyExpressionBlock(session)
|
||||
firStatement != null -> FirSingleExpressionBlock(firStatement!!)
|
||||
firBlock == null -> FirEmptyExpressionBlock()
|
||||
else -> firBlock!!
|
||||
}
|
||||
}
|
||||
@@ -780,10 +778,10 @@ class ExpressionsConverter(
|
||||
FINALLY -> finallyBlock = convertFinally(it)
|
||||
}
|
||||
}
|
||||
return FirTryExpressionImpl(session, null, tryBlock, finallyBlock).apply {
|
||||
return FirTryExpressionImpl(null, tryBlock, finallyBlock).apply {
|
||||
for ((parameter, block) in catchClauses) {
|
||||
if (parameter == null) continue
|
||||
catches += FirCatchImpl(this@ExpressionsConverter.session, null, parameter.firValueParameter, block)
|
||||
catches += FirCatchImpl(null, parameter.firValueParameter, block)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -823,7 +821,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitIfExpression
|
||||
*/
|
||||
private fun convertIfExpression(ifExpression: LighterASTNode): FirExpression {
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(session, null, "If statement should have condition")
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, "If statement should have condition")
|
||||
var thenBlock: LighterASTNode? = null
|
||||
var elseBlock: LighterASTNode? = null
|
||||
ifExpression.forEachChildren {
|
||||
@@ -834,12 +832,12 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirWhenExpressionImpl(session, null).apply {
|
||||
return FirWhenExpressionImpl(null).apply {
|
||||
val trueBranch = convertLoopBody(thenBlock)
|
||||
branches += FirWhenBranchImpl(this@ExpressionsConverter.session, null, firCondition, trueBranch)
|
||||
branches += FirWhenBranchImpl(null, firCondition, trueBranch)
|
||||
val elseBranch = convertLoopBody(elseBlock)
|
||||
branches += FirWhenBranchImpl(
|
||||
this@ExpressionsConverter.session, null, FirElseIfTrueCondition(this@ExpressionsConverter.session, null), elseBranch
|
||||
null, FirElseIfTrueCondition(null), elseBranch
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -858,7 +856,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return (if (isBreak) FirBreakExpressionImpl(session, null) else FirContinueExpressionImpl(session, null)).bindLabel(jump)
|
||||
return (if (isBreak) FirBreakExpressionImpl(null) else FirContinueExpressionImpl(null)).bindLabel(jump)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -867,7 +865,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertReturn(returnExpression: LighterASTNode): FirExpression {
|
||||
var labelName: String? = null
|
||||
var firExpression: FirExpression = FirUnitExpression(session, null)
|
||||
var firExpression: FirExpression = FirUnitExpression(null)
|
||||
returnExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
LABEL_QUALIFIER -> labelName = it.getAsStringWithoutBacktick().replace("@", "")
|
||||
@@ -883,12 +881,12 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitThrowExpression
|
||||
*/
|
||||
private fun convertThrow(throwExpression: LighterASTNode): FirExpression {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, "Nothing to throw")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "Nothing to throw")
|
||||
throwExpression.forEachChildren {
|
||||
if (it.isExpression()) firExpression = getAsFirExpression(it, "Nothing to throw")
|
||||
}
|
||||
|
||||
return FirThrowExpressionImpl(session, null, firExpression)
|
||||
return FirThrowExpressionImpl(null, firExpression)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -898,8 +896,8 @@ class ExpressionsConverter(
|
||||
private fun convertThisExpression(thisExpression: LighterASTNode): FirQualifiedAccessExpression {
|
||||
val label: String? = thisExpression.getLabelName()
|
||||
|
||||
return FirQualifiedAccessExpressionImpl(session, null).apply {
|
||||
calleeReference = FirExplicitThisReference(this@ExpressionsConverter.session, null, label)
|
||||
return FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference = FirExplicitThisReference(null, label)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,8 +913,8 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
return FirQualifiedAccessExpressionImpl(session, null).apply {
|
||||
calleeReference = FirExplicitSuperReference(this@ExpressionsConverter.session, null, superTypeRef)
|
||||
return FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference = FirExplicitSuperReference(null, superTypeRef)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -929,7 +927,7 @@ class ExpressionsConverter(
|
||||
VALUE_ARGUMENT -> container += convertValueArgument(node)
|
||||
LAMBDA_EXPRESSION,
|
||||
LABELED_EXPRESSION,
|
||||
ANNOTATED_EXPRESSION -> container += FirLambdaArgumentExpressionImpl(session, null, getAsFirExpression(node))
|
||||
ANNOTATED_EXPRESSION -> container += FirLambdaArgumentExpressionImpl(null, getAsFirExpression(node))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -941,7 +939,7 @@ class ExpressionsConverter(
|
||||
private fun convertValueArgument(valueArgument: LighterASTNode): FirExpression {
|
||||
var identifier: String? = null
|
||||
var isSpread = false
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(session, null, "Argument is absent")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "Argument is absent")
|
||||
valueArgument.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
VALUE_ARGUMENT_NAME -> identifier = it.asText
|
||||
@@ -952,8 +950,8 @@ class ExpressionsConverter(
|
||||
}
|
||||
}
|
||||
return when {
|
||||
identifier != null -> FirNamedArgumentExpressionImpl(session, null, identifier.nameAsSafeName(), isSpread, firExpression)
|
||||
isSpread -> FirSpreadArgumentExpressionImpl(session, null, firExpression)
|
||||
identifier != null -> FirNamedArgumentExpressionImpl(null, identifier.nameAsSafeName(), isSpread, firExpression)
|
||||
isSpread -> FirSpreadArgumentExpressionImpl(null, firExpression)
|
||||
else -> firExpression
|
||||
}
|
||||
}
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.lightTree.fir
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
||||
|
||||
class AnnotationContainer(
|
||||
session: FirSession,
|
||||
psi: PsiElement? = null
|
||||
) : FirAbstractAnnotatedElement(session, psi) {
|
||||
constructor(session: FirSession, annotations: List<FirAnnotationCall>) : this(session, null) {
|
||||
super.annotations += annotations
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
@@ -20,7 +19,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
|
||||
class ClassWrapper(
|
||||
private val session: FirSession,
|
||||
private val className: Name,
|
||||
private val modifiers: Modifier,
|
||||
private val classKind: ClassKind,
|
||||
@@ -63,7 +61,6 @@ class ClassWrapper(
|
||||
)
|
||||
|
||||
return FirUserTypeRefImpl(
|
||||
session,
|
||||
null,
|
||||
false
|
||||
).apply {
|
||||
|
||||
-2
@@ -7,10 +7,8 @@ package org.jetbrains.kotlin.fir.lightTree.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.generateTemporaryVariable
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.fir.lightTree.converter.generateDestructuringBlock
|
||||
|
||||
data class DestructuringDeclaration(
|
||||
|
||||
+8
-11
@@ -37,7 +37,7 @@ class ValueParameter(
|
||||
val name = this.firValueParameter.name
|
||||
var type = this.firValueParameter.returnTypeRef
|
||||
if (type is FirImplicitTypeRef) {
|
||||
type = FirErrorTypeRefImpl(session, null, "Incomplete code")
|
||||
type = FirErrorTypeRefImpl(null, "Incomplete code")
|
||||
}
|
||||
|
||||
return FirMemberPropertyImpl(
|
||||
@@ -55,19 +55,16 @@ class ValueParameter(
|
||||
receiverTypeRef = null,
|
||||
returnTypeRef = type,
|
||||
isVar = this.isVar,
|
||||
initializer = FirQualifiedAccessExpressionImpl(session, null).apply {
|
||||
initializer = FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference = FirPropertyFromParameterCallableReference(
|
||||
session, null, name, this@ValueParameter.firValueParameter.symbol
|
||||
null, name, this@ValueParameter.firValueParameter.symbol
|
||||
)
|
||||
},
|
||||
getter = FirDefaultPropertyGetter(session, null, type, modifiers.getVisibility()),
|
||||
setter = if (this.isVar) FirDefaultPropertySetter(
|
||||
session,
|
||||
null,
|
||||
type,
|
||||
modifiers.getVisibility()
|
||||
) else null,
|
||||
delegate = null
|
||||
).apply { annotations += this@ValueParameter.firValueParameter.annotations }
|
||||
).apply {
|
||||
annotations += this@ValueParameter.firValueParameter.annotations
|
||||
getter = FirDefaultPropertyGetter(session, null, type, modifiers.getVisibility())
|
||||
setter = if (this.isVar) FirDefaultPropertySetter(session, null, type, modifiers.getVisibility()) else null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.lightTree.fir
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirWhenSubject
|
||||
import org.jetbrains.kotlin.fir.builder.generateContainsOperation
|
||||
import org.jetbrains.kotlin.fir.builder.generateLazyLogicalOperation
|
||||
@@ -24,20 +20,20 @@ data class WhenEntry(
|
||||
val firBlock: FirBlock,
|
||||
val isElse: Boolean = false
|
||||
) {
|
||||
fun toFirWhenCondition(session: FirSession, subject: FirWhenSubject): FirExpression {
|
||||
fun toFirWhenCondition(subject: FirWhenSubject): FirExpression {
|
||||
var firCondition: FirExpression? = null
|
||||
for (condition in conditions) {
|
||||
val firConditionElement = condition.toFirWhenCondition(session, subject)
|
||||
val firConditionElement = condition.toFirWhenCondition(subject)
|
||||
firCondition = when (firCondition) {
|
||||
null -> firConditionElement
|
||||
else -> firCondition.generateLazyLogicalOperation(session, firConditionElement, false, null)
|
||||
else -> firCondition.generateLazyLogicalOperation(firConditionElement, false, null)
|
||||
}
|
||||
}
|
||||
return firCondition!!
|
||||
}
|
||||
|
||||
private fun FirExpression.toFirWhenCondition(session: FirSession, subject: FirWhenSubject): FirExpression {
|
||||
val firSubjectExpression = FirWhenSubjectExpressionImpl(session, null, subject)
|
||||
private fun FirExpression.toFirWhenCondition(subject: FirWhenSubject): FirExpression {
|
||||
val firSubjectExpression = FirWhenSubjectExpressionImpl(null, subject)
|
||||
return when (this) {
|
||||
is FirOperatorCallImpl -> {
|
||||
this.apply {
|
||||
@@ -47,7 +43,7 @@ data class WhenEntry(
|
||||
is FirFunctionCall -> {
|
||||
val firExpression = this.explicitReceiver!!
|
||||
val isNegate = this.calleeReference.name == OperatorNameConventions.NOT
|
||||
firExpression.generateContainsOperation(session, firSubjectExpression, isNegate, null, null)
|
||||
firExpression.generateContainsOperation(firSubjectExpression, isNegate, null, null)
|
||||
}
|
||||
is FirTypeOperatorCallImpl -> {
|
||||
this.apply {
|
||||
@@ -55,18 +51,15 @@ data class WhenEntry(
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
FirErrorExpressionImpl(session, null, "Unsupported when condition: ${this.javaClass}")
|
||||
FirErrorExpressionImpl(null, "Unsupported when condition: ${this.javaClass}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toFirWhenConditionWithoutSubject(session: FirSession): FirExpression {
|
||||
val condition = conditions.first()
|
||||
return when (condition) {
|
||||
fun toFirWhenConditionWithoutSubject(): FirExpression {
|
||||
return when (val condition = conditions.first()) {
|
||||
is FirOperatorCallImpl -> condition.arguments.first()
|
||||
//is FirFunctionCall -> condition.explicitReceiver!!
|
||||
//is FirTypeOperatorCallImpl -> condition
|
||||
else -> FirErrorExpressionImpl(session, null, "No expression in condition with expression")
|
||||
else -> FirErrorExpressionImpl(null, "No expression in condition with expression")
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -10,7 +10,6 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.CLASS_MODIFIER
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.FUNCTION_MODIFIER
|
||||
@@ -22,9 +21,7 @@ import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.PROPERTY_MOD
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.VISIBILITY_MODIFIER
|
||||
|
||||
class Modifier(
|
||||
session: FirSession,
|
||||
psi: PsiElement? = null,
|
||||
|
||||
private val classModifiers: MutableList<ClassModifier> = mutableListOf(),
|
||||
private val memberModifiers: MutableList<MemberModifier> = mutableListOf(),
|
||||
private val visibilityModifiers: MutableList<VisibilityModifier> = mutableListOf(),
|
||||
@@ -33,7 +30,7 @@ class Modifier(
|
||||
private val inheritanceModifiers: MutableList<InheritanceModifier> = mutableListOf(),
|
||||
private val parameterModifiers: MutableList<ParameterModifier> = mutableListOf(),
|
||||
private val platformModifiers: MutableList<PlatformModifier> = mutableListOf()
|
||||
) : FirAbstractAnnotatedElement(session, psi) {
|
||||
) : FirAbstractAnnotatedElement(psi) {
|
||||
fun addModifier(modifier: LighterASTNode) {
|
||||
val tokenType = modifier.tokenType
|
||||
when {
|
||||
|
||||
+1
-4
@@ -7,16 +7,13 @@ package org.jetbrains.kotlin.fir.lightTree.fir.modifier
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
class TypeModifier(
|
||||
session: FirSession,
|
||||
psi: PsiElement? = null,
|
||||
|
||||
var hasSuspend: Boolean = false
|
||||
) : FirAbstractAnnotatedElement(session, psi) {
|
||||
) : FirAbstractAnnotatedElement(psi) {
|
||||
fun addModifier(modifier: LighterASTNode) {
|
||||
when (modifier.tokenType) {
|
||||
KtTokens.SUSPEND_KEYWORD -> this.hasSuspend = true
|
||||
|
||||
+2
-4
@@ -7,19 +7,17 @@ package org.jetbrains.kotlin.fir.lightTree.fir.modifier
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.REIFICATION_MODIFIER
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.VARIANCE_MODIFIER
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class TypeParameterModifier(
|
||||
session: FirSession,
|
||||
psi: PsiElement? = null,
|
||||
|
||||
private val varianceModifiers: MutableList<VarianceModifier> = mutableListOf(),
|
||||
|
||||
private var reificationModifier: ReificationModifier? = null
|
||||
) : FirAbstractAnnotatedElement(session, psi) {
|
||||
) : FirAbstractAnnotatedElement(psi) {
|
||||
fun addModifier(modifier: LighterASTNode) {
|
||||
val tokenType = modifier.tokenType
|
||||
when {
|
||||
|
||||
+1
-4
@@ -7,17 +7,14 @@ package org.jetbrains.kotlin.fir.lightTree.fir.modifier
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.ModifierSets.VARIANCE_MODIFIER
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class TypeProjectionModifier(
|
||||
session: FirSession,
|
||||
psi: PsiElement? = null,
|
||||
|
||||
private val varianceModifiers: MutableList<VarianceModifier> = mutableListOf()
|
||||
) : FirAbstractAnnotatedElement(session, psi) {
|
||||
) : FirAbstractAnnotatedElement(psi) {
|
||||
fun addModifier(modifier: LighterASTNode) {
|
||||
val tokenType = modifier.tokenType
|
||||
when {
|
||||
|
||||
@@ -46,10 +46,10 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
//T can be either PsiElement, or LighterASTNode
|
||||
abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context = Context()) {
|
||||
|
||||
protected val implicitUnitType = FirImplicitUnitTypeRef(session, null)
|
||||
protected val implicitAnyType = FirImplicitAnyTypeRef(session, null)
|
||||
protected val implicitEnumType = FirImplicitEnumTypeRef(session, null)
|
||||
protected val implicitAnnotationType = FirImplicitAnnotationTypeRef(session, null)
|
||||
protected val implicitUnitType = FirImplicitUnitTypeRef(null)
|
||||
protected val implicitAnyType = FirImplicitAnyTypeRef(null)
|
||||
protected val implicitEnumType = FirImplicitEnumTypeRef(null)
|
||||
protected val implicitAnnotationType = FirImplicitAnnotationTypeRef(null)
|
||||
|
||||
abstract val T.elementType: IElementType
|
||||
abstract val T.asText: String
|
||||
@@ -100,7 +100,6 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
|
||||
fun FirExpression.toReturn(basePsi: PsiElement? = psi, labelName: String? = null): FirReturnExpression {
|
||||
return FirReturnExpressionImpl(
|
||||
this@BaseFirBuilder.session,
|
||||
basePsi,
|
||||
this
|
||||
).apply {
|
||||
@@ -138,10 +137,10 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
val typeParameters = firClass.typeParameters.map {
|
||||
FirTypeParameterImpl(session, it.psi, FirTypeParameterSymbol(), it.name, Variance.INVARIANT, false).apply {
|
||||
this.bounds += it.bounds
|
||||
addDefaultBoundIfNecessary()
|
||||
}
|
||||
}
|
||||
return FirResolvedTypeRefImpl(
|
||||
session,
|
||||
this,
|
||||
ConeClassTypeImpl(
|
||||
firClass.symbol.toLookupTag(),
|
||||
@@ -162,8 +161,8 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
return this.convert("No operand").generateNotNullOrOther(
|
||||
session,
|
||||
FirThrowExpressionImpl(
|
||||
session, parent.getPsiOrNull(), FirFunctionCallImpl(session, parent.getPsiOrNull()).apply {
|
||||
calleeReference = FirSimpleNamedReference(this@BaseFirBuilder.session, parent, KNPE)
|
||||
parent.getPsiOrNull(), FirFunctionCallImpl(parent.getPsiOrNull()).apply {
|
||||
calleeReference = FirSimpleNamedReference(parent, KNPE)
|
||||
}
|
||||
), "bangbang", parent
|
||||
)
|
||||
@@ -185,7 +184,7 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
if (lastLoop != null) {
|
||||
target.bind(lastLoop)
|
||||
} else {
|
||||
target.bind(FirErrorLoop(this@BaseFirBuilder.session, expression.getPsiOrNull(), "Cannot bind unlabeled jump to a loop"))
|
||||
target.bind(FirErrorLoop(expression.getPsiOrNull(), "Cannot bind unlabeled jump to a loop"))
|
||||
}
|
||||
} else {
|
||||
for (firLoop in context.firLoops.asReversed()) {
|
||||
@@ -194,7 +193,7 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
return this
|
||||
}
|
||||
}
|
||||
target.bind(FirErrorLoop(this@BaseFirBuilder.session, expression.getPsiOrNull(), "Cannot bind label $labelName to a loop"))
|
||||
target.bind(FirErrorLoop(expression.getPsiOrNull(), "Cannot bind label $labelName to a loop"))
|
||||
}
|
||||
return this
|
||||
}
|
||||
@@ -219,34 +218,34 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
convertedText > Int.MAX_VALUE || convertedText < Int.MIN_VALUE)
|
||||
) {
|
||||
FirConstExpressionImpl(
|
||||
session, expression.getPsiOrNull(), IrConstKind.Long, convertedText, "Incorrect long: $text"
|
||||
expression.getPsiOrNull(), IrConstKind.Long, convertedText, "Incorrect long: $text"
|
||||
)
|
||||
} else if (convertedText is Number) {
|
||||
// TODO: support byte / short
|
||||
FirConstExpressionImpl(
|
||||
session, expression.getPsiOrNull(), IrConstKind.Int, convertedText.toInt(), "Incorrect int: $text"
|
||||
expression.getPsiOrNull(), IrConstKind.Int, convertedText.toInt(), "Incorrect int: $text"
|
||||
)
|
||||
} else {
|
||||
FirErrorExpressionImpl(session, expression.getPsiOrNull(), reason = "Incorrect constant expression: $text")
|
||||
FirErrorExpressionImpl(expression.getPsiOrNull(), reason = "Incorrect constant expression: $text")
|
||||
}
|
||||
FLOAT_CONSTANT ->
|
||||
if (convertedText is Float) {
|
||||
FirConstExpressionImpl(
|
||||
session, expression.getPsiOrNull(), IrConstKind.Float, convertedText, "Incorrect float: $text"
|
||||
expression.getPsiOrNull(), IrConstKind.Float, convertedText, "Incorrect float: $text"
|
||||
)
|
||||
} else {
|
||||
FirConstExpressionImpl(
|
||||
session, expression.getPsiOrNull(), IrConstKind.Double, convertedText as Double, "Incorrect double: $text"
|
||||
expression.getPsiOrNull(), IrConstKind.Double, convertedText as Double, "Incorrect double: $text"
|
||||
)
|
||||
}
|
||||
CHARACTER_CONSTANT ->
|
||||
FirConstExpressionImpl(
|
||||
session, expression.getPsiOrNull(), IrConstKind.Char, text.parseCharacter(), "Incorrect character: $text"
|
||||
expression.getPsiOrNull(), IrConstKind.Char, text.parseCharacter(), "Incorrect character: $text"
|
||||
)
|
||||
BOOLEAN_CONSTANT ->
|
||||
FirConstExpressionImpl(session, expression.getPsiOrNull(), IrConstKind.Boolean, convertedText as Boolean)
|
||||
FirConstExpressionImpl(expression.getPsiOrNull(), IrConstKind.Boolean, convertedText as Boolean)
|
||||
NULL ->
|
||||
FirConstExpressionImpl(session, expression.getPsiOrNull(), IrConstKind.Null, null)
|
||||
FirConstExpressionImpl(expression.getPsiOrNull(), IrConstKind.Null, null)
|
||||
else ->
|
||||
throw AssertionError("Unknown literal type: $type, $text")
|
||||
}
|
||||
@@ -267,11 +266,11 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
OPEN_QUOTE, CLOSING_QUOTE -> continue@L
|
||||
LITERAL_STRING_TEMPLATE_ENTRY -> {
|
||||
sb.append(entry.asText)
|
||||
FirConstExpressionImpl(session, entry.getPsiOrNull(), IrConstKind.String, entry.asText)
|
||||
FirConstExpressionImpl(entry.getPsiOrNull(), IrConstKind.String, entry.asText)
|
||||
}
|
||||
ESCAPE_STRING_TEMPLATE_ENTRY -> {
|
||||
sb.append(entry.unescapedValue)
|
||||
FirConstExpressionImpl(session, entry.getPsiOrNull(), IrConstKind.String, entry.unescapedValue)
|
||||
FirConstExpressionImpl(entry.getPsiOrNull(), IrConstKind.String, entry.unescapedValue)
|
||||
}
|
||||
SHORT_STRING_TEMPLATE_ENTRY, LONG_STRING_TEMPLATE_ENTRY -> {
|
||||
hasExpressions = true
|
||||
@@ -280,7 +279,7 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
else -> {
|
||||
hasExpressions = true
|
||||
FirErrorExpressionImpl(
|
||||
session, entry.getPsiOrNull(), "Incorrect template entry: ${entry.asText}"
|
||||
entry.getPsiOrNull(), "Incorrect template entry: ${entry.asText}"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -291,14 +290,14 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
}
|
||||
else -> {
|
||||
callCreated = true
|
||||
FirStringConcatenationCallImpl(session, base).apply {
|
||||
FirStringConcatenationCallImpl(base).apply {
|
||||
arguments += result!!
|
||||
arguments += nextArgument
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return if (hasExpressions) result!! else FirConstExpressionImpl(session, base, IrConstKind.String, sb.toString())
|
||||
return if (hasExpressions) result!! else FirConstExpressionImpl(base, IrConstKind.String, sb.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,22 +332,22 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
convert: T.() -> FirExpression
|
||||
): FirExpression {
|
||||
if (argument == null) {
|
||||
return FirErrorExpressionImpl(session, argument, "Inc/dec without operand")
|
||||
return FirErrorExpressionImpl(argument, "Inc/dec without operand")
|
||||
}
|
||||
return FirBlockImpl(session, baseExpression).apply {
|
||||
return FirBlockImpl(baseExpression).apply {
|
||||
val tempName = Name.special("<unary>")
|
||||
val temporaryVariable = generateTemporaryVariable(this@BaseFirBuilder.session, baseExpression, tempName, argument.convert())
|
||||
statements += temporaryVariable
|
||||
val resultName = Name.special("<unary-result>")
|
||||
val resultInitializer = FirFunctionCallImpl(this@BaseFirBuilder.session, baseExpression).apply {
|
||||
this.calleeReference = FirSimpleNamedReference(this@BaseFirBuilder.session, baseExpression?.operationReference, callName)
|
||||
this.explicitReceiver = generateResolvedAccessExpression(this@BaseFirBuilder.session, baseExpression, temporaryVariable)
|
||||
val resultInitializer = FirFunctionCallImpl(baseExpression).apply {
|
||||
this.calleeReference = FirSimpleNamedReference(baseExpression?.operationReference, callName)
|
||||
this.explicitReceiver = generateResolvedAccessExpression(baseExpression, temporaryVariable)
|
||||
}
|
||||
val resultVar = generateTemporaryVariable(this@BaseFirBuilder.session, baseExpression, resultName, resultInitializer)
|
||||
val assignment = argument.generateAssignment(
|
||||
baseExpression,
|
||||
if (prefix && argument.elementType != REFERENCE_EXPRESSION)
|
||||
generateResolvedAccessExpression(this@BaseFirBuilder.session, baseExpression, resultVar)
|
||||
generateResolvedAccessExpression(baseExpression, resultVar)
|
||||
else
|
||||
resultInitializer,
|
||||
FirOperation.ASSIGN, convert
|
||||
@@ -366,14 +365,14 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
if (argument.elementType != REFERENCE_EXPRESSION) {
|
||||
statements += resultVar
|
||||
appendAssignment()
|
||||
statements += generateResolvedAccessExpression(this@BaseFirBuilder.session, baseExpression, resultVar)
|
||||
statements += generateResolvedAccessExpression(baseExpression, resultVar)
|
||||
} else {
|
||||
appendAssignment()
|
||||
statements += generateAccessExpression(this@BaseFirBuilder.session, baseExpression, argument.getReferencedNameAsName())
|
||||
statements += generateAccessExpression(baseExpression, argument.getReferencedNameAsName())
|
||||
}
|
||||
} else {
|
||||
appendAssignment()
|
||||
statements += generateResolvedAccessExpression(this@BaseFirBuilder.session, baseExpression, temporaryVariable)
|
||||
statements += generateResolvedAccessExpression(baseExpression, temporaryVariable)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -386,10 +385,10 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
if (left != null) {
|
||||
when (tokenType) {
|
||||
REFERENCE_EXPRESSION -> {
|
||||
return FirSimpleNamedReference(this@BaseFirBuilder.session, left.getPsiOrNull(), left.getReferencedNameAsName())
|
||||
return FirSimpleNamedReference(left.getPsiOrNull(), left.getReferencedNameAsName())
|
||||
}
|
||||
THIS_EXPRESSION -> {
|
||||
return FirExplicitThisReference(this@BaseFirBuilder.session, left.getPsiOrNull(), left.getLabelName())
|
||||
return FirExplicitThisReference(left.getPsiOrNull(), left.getLabelName())
|
||||
}
|
||||
DOT_QUALIFIED_EXPRESSION, SAFE_ACCESS_EXPRESSION -> {
|
||||
val firMemberAccess = left.convertQualified()
|
||||
@@ -399,7 +398,7 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
firMemberAccess.calleeReference
|
||||
} else {
|
||||
FirErrorNamedReference(
|
||||
this@BaseFirBuilder.session, left.getPsiOrNull(), "Unsupported qualified LValue: ${left.asText}"
|
||||
left.getPsiOrNull(), "Unsupported qualified LValue: ${left.asText}"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -408,7 +407,7 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
}
|
||||
}
|
||||
}
|
||||
return FirErrorNamedReference(this@BaseFirBuilder.session, left.getPsiOrNull(), "Unsupported LValue: $tokenType")
|
||||
return FirErrorNamedReference(left.getPsiOrNull(), "Unsupported LValue: $tokenType")
|
||||
}
|
||||
|
||||
fun T?.generateAssignment(
|
||||
@@ -424,12 +423,12 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
if (tokenType == ARRAY_ACCESS_EXPRESSION) {
|
||||
val firArrayAccess = this!!.convert() as FirFunctionCallImpl
|
||||
val arraySet = if (operation != FirOperation.ASSIGN) {
|
||||
FirArraySetCallImpl(session, psi, value, operation).apply {
|
||||
FirArraySetCallImpl(psi, value, operation).apply {
|
||||
indexes += firArrayAccess.arguments
|
||||
}
|
||||
} else {
|
||||
return firArrayAccess.apply {
|
||||
calleeReference = FirSimpleNamedReference(this@BaseFirBuilder.session, psi, OperatorNameConventions.SET)
|
||||
calleeReference = FirSimpleNamedReference(psi, OperatorNameConventions.SET)
|
||||
arguments += value
|
||||
}
|
||||
}
|
||||
@@ -439,31 +438,32 @@ abstract class BaseFirBuilder<T>(val session: FirSession, val context: Context =
|
||||
lValue = initializeLValue(arrayExpression) { convert() as? FirQualifiedAccess }
|
||||
}
|
||||
}
|
||||
return FirBlockImpl(session, arrayExpression).apply {
|
||||
val psiArrayExpression = firArrayAccess.explicitReceiver?.psi
|
||||
return FirBlockImpl(psiArrayExpression).apply {
|
||||
val name = Name.special("<array-set>")
|
||||
statements += generateTemporaryVariable(
|
||||
this@BaseFirBuilder.session, this@generateAssignment.getPsiOrNull(), name, firArrayAccess.explicitReceiver!!
|
||||
)
|
||||
statements += arraySet.apply { lValue = FirSimpleNamedReference(this@BaseFirBuilder.session, arrayExpression, name) }
|
||||
statements += arraySet.apply { lValue = FirSimpleNamedReference(psiArrayExpression, name) }
|
||||
}
|
||||
}
|
||||
if (operation != FirOperation.ASSIGN &&
|
||||
tokenType != REFERENCE_EXPRESSION && tokenType != THIS_EXPRESSION &&
|
||||
((tokenType != DOT_QUALIFIED_EXPRESSION && tokenType != SAFE_ACCESS_EXPRESSION) || this.selectorExpression?.elementType != REFERENCE_EXPRESSION)
|
||||
) {
|
||||
return FirBlockImpl(session, this.getPsiOrNull()).apply {
|
||||
return FirBlockImpl(this.getPsiOrNull()).apply {
|
||||
val name = Name.special("<complex-set>")
|
||||
statements += generateTemporaryVariable(
|
||||
this@BaseFirBuilder.session, this@generateAssignment.getPsiOrNull(), name,
|
||||
this@generateAssignment?.convert()
|
||||
?: FirErrorExpressionImpl(this@BaseFirBuilder.session, this.getPsiOrNull(), "No LValue in assignment")
|
||||
?: FirErrorExpressionImpl(this.getPsiOrNull(), "No LValue in assignment")
|
||||
)
|
||||
statements += FirVariableAssignmentImpl(this@BaseFirBuilder.session, psi, value, operation).apply {
|
||||
lValue = FirSimpleNamedReference(this@BaseFirBuilder.session, this.getPsiOrNull(), name)
|
||||
statements += FirVariableAssignmentImpl(psi, value, operation).apply {
|
||||
lValue = FirSimpleNamedReference(this.getPsiOrNull(), name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return FirVariableAssignmentImpl(session, psi, value, operation).apply {
|
||||
return FirVariableAssignmentImpl(psi, value, operation).apply {
|
||||
lValue = initializeLValue(this@generateAssignment) { convert() as? FirQualifiedAccess }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,14 @@ import org.jetbrains.kotlin.fir.FirFunctionTarget
|
||||
import org.jetbrains.kotlin.fir.FirReference
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirWhenSubject
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirModifiableAccessorsOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirPropertyAccessorImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirValueParameterImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirVariableImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.fir.references.*
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeStarProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBooleanTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitKPropertyTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitUnitTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstKind
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -134,6 +128,12 @@ fun IElementType.toFirOperation(): FirOperation =
|
||||
else -> throw AssertionError(this.toString())
|
||||
}
|
||||
|
||||
fun FirTypeParameterImpl.addDefaultBoundIfNecessary() {
|
||||
if (bounds.isEmpty()) {
|
||||
bounds += FirImplicitNullableAnyTypeRef(null)
|
||||
}
|
||||
}
|
||||
|
||||
fun FirExpression.generateNotNullOrOther(
|
||||
session: FirSession, other: FirExpression, caseId: String, basePsi: KtElement?
|
||||
): FirWhenExpression {
|
||||
@@ -299,3 +299,74 @@ fun generateTemporaryVariable(
|
||||
fun generateTemporaryVariable(
|
||||
session: FirSession, psi: PsiElement?, specialName: String, initializer: FirExpression
|
||||
): FirVariable<*> = generateTemporaryVariable(session, psi, Name.special("<$specialName>"), initializer)
|
||||
|
||||
fun FirModifiableAccessorsOwner.generateAccessorsByDelegate(session: FirSession, member: Boolean, stubMode: Boolean) {
|
||||
val variable = this as FirVariable<*>
|
||||
val delegateFieldSymbol = delegateFieldSymbol ?: return
|
||||
val delegate = delegate as? FirWrappedDelegateExpressionImpl ?: return
|
||||
fun delegateAccess() = FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference = FirDelegateFieldReferenceImpl(null, delegateFieldSymbol)
|
||||
}
|
||||
|
||||
fun thisRef() =
|
||||
if (member) FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference = FirExplicitThisReference(null, null)
|
||||
}
|
||||
else FirConstExpressionImpl(null, IrConstKind.Null, null)
|
||||
|
||||
fun propertyRef() = FirCallableReferenceAccessImpl(null).apply {
|
||||
calleeReference = FirResolvedCallableReferenceImpl(null, variable.name, variable.symbol)
|
||||
typeRef = FirImplicitKPropertyTypeRef(null, ConeStarProjection)
|
||||
}
|
||||
|
||||
delegate.delegateProvider = if (stubMode) FirExpressionStub(null) else FirFunctionCallImpl(null).apply {
|
||||
explicitReceiver = delegate.expression
|
||||
calleeReference = FirSimpleNamedReference(null, PROVIDE_DELEGATE)
|
||||
arguments += thisRef()
|
||||
arguments += propertyRef()
|
||||
}
|
||||
if (stubMode) return
|
||||
getter = (getter as? FirPropertyAccessorImpl)
|
||||
?: FirPropertyAccessorImpl(session, null, true, Visibilities.UNKNOWN, FirImplicitTypeRefImpl(null)).apply Accessor@{
|
||||
body = FirSingleExpressionBlock(
|
||||
FirReturnExpressionImpl(
|
||||
null,
|
||||
FirFunctionCallImpl(null).apply {
|
||||
explicitReceiver = delegateAccess()
|
||||
calleeReference = FirSimpleNamedReference(null, GET_VALUE)
|
||||
arguments += thisRef()
|
||||
arguments += propertyRef()
|
||||
}
|
||||
).apply {
|
||||
target = FirFunctionTarget(null)
|
||||
target.bind(this@Accessor)
|
||||
}
|
||||
)
|
||||
}
|
||||
setter = (setter as? FirPropertyAccessorImpl)
|
||||
?: FirPropertyAccessorImpl(session, null, false, Visibilities.UNKNOWN, FirImplicitUnitTypeRef(null)).apply {
|
||||
val parameter = FirValueParameterImpl(
|
||||
session, null, DELEGATED_SETTER_PARAM,
|
||||
FirImplicitTypeRefImpl(null),
|
||||
defaultValue = null, isCrossinline = false,
|
||||
isNoinline = false, isVararg = false
|
||||
)
|
||||
valueParameters += parameter
|
||||
body = FirSingleExpressionBlock(
|
||||
FirFunctionCallImpl(null).apply {
|
||||
explicitReceiver = delegateAccess()
|
||||
calleeReference = FirSimpleNamedReference(null, SET_VALUE)
|
||||
arguments += thisRef()
|
||||
arguments += propertyRef()
|
||||
arguments += FirQualifiedAccessExpressionImpl(null).apply {
|
||||
calleeReference = FirResolvedCallableReferenceImpl(psi, DELEGATED_SETTER_PARAM, parameter.symbol)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val GET_VALUE = Name.identifier("getValue")
|
||||
private val SET_VALUE = Name.identifier("setValue")
|
||||
private val PROVIDE_DELEGATE = Name.identifier("provideDelegate")
|
||||
private val DELEGATED_SETTER_PARAM = Name.special("<set-?>")
|
||||
|
||||
Reference in New Issue
Block a user