diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt new file mode 100644 index 00000000000..742d5ac2ada --- /dev/null +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -0,0 +1,375 @@ +/* + * 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.builder + +import com.intellij.psi.PsiElement +import com.intellij.psi.tree.IElementType +import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.fir.FirReference +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration +import org.jetbrains.kotlin.fir.declarations.impl.FirVariableImpl +import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.impl.* +import org.jetbrains.kotlin.fir.references.FirErrorNamedReference +import org.jetbrains.kotlin.fir.references.FirExplicitThisReference +import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeImpl +import org.jetbrains.kotlin.ir.expressions.IrConstKind +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.resolve.constants.evaluate.* +import org.jetbrains.kotlin.types.expressions.OperatorConventions + +internal fun String.parseCharacter(): Char? { + // Strip the quotes + if (length < 2 || this[0] != '\'' || this[length - 1] != '\'') { + return null + } + val text = substring(1, length - 1) // now there're no quotes + + if (text.isEmpty()) { + return null + } + + return if (text[0] != '\\') { + // No escape + if (text.length == 1) { + text[0] + } else { + null + } + } else { + escapedStringToCharacter(text) + } +} + +internal fun escapedStringToCharacter(text: String): Char? { + assert(text.isNotEmpty() && text[0] == '\\') { + "Only escaped sequences must be passed to this routine: $text" + } + + // Escape + val escape = text.substring(1) // strip the slash + when (escape.length) { + 0 -> { + // bare slash + return null + } + 1 -> { + // one-char escape + return translateEscape(escape[0]) ?: return null + } + 5 -> { + // unicode escape + if (escape[0] == 'u') { + try { + val intValue = Integer.valueOf(escape.substring(1), 16) + return intValue.toInt().toChar() + } catch (e: NumberFormatException) { + // Will be reported below + } + } + } + } + return null +} + +internal fun translateEscape(c: Char): Char? = + when (c) { + 't' -> '\t' + 'b' -> '\b' + 'n' -> '\n' + 'r' -> '\r' + '\'' -> '\'' + '\"' -> '\"' + '\\' -> '\\' + '$' -> '$' + else -> null + } + +internal fun generateConstantExpressionByLiteral(session: FirSession, expression: KtConstantExpression): FirExpression { + val type = expression.node.elementType + val text: String = expression.text + val convertedText: Any? = when (type) { + KtNodeTypes.INTEGER_CONSTANT, KtNodeTypes.FLOAT_CONSTANT -> parseNumericLiteral(text, type) + KtNodeTypes.BOOLEAN_CONSTANT -> parseBoolean(text) + else -> null + } + return when (type) { + KtNodeTypes.INTEGER_CONSTANT -> + if (convertedText is Long && + (hasLongSuffix(text) || hasUnsignedLongSuffix(text) || hasUnsignedSuffix(text) || + convertedText > Int.MAX_VALUE || convertedText < Int.MIN_VALUE) + ) { + FirConstExpressionImpl( + session, expression, IrConstKind.Long, convertedText, "Incorrect long: $text" + ) + } else { + // TODO: support byte / short + FirConstExpressionImpl(session, expression, IrConstKind.Int, (convertedText as Number).toInt(), "Incorrect int: $text") + } + KtNodeTypes.FLOAT_CONSTANT -> + if (convertedText is Float) { + FirConstExpressionImpl( + session, expression, IrConstKind.Float, convertedText, "Incorrect float: $text" + ) + } else { + FirConstExpressionImpl( + session, expression, IrConstKind.Double, convertedText as Double, "Incorrect double: $text" + ) + } + KtNodeTypes.CHARACTER_CONSTANT -> + FirConstExpressionImpl( + session, expression, IrConstKind.Char, text.parseCharacter(), "Incorrect character: $text" + ) + KtNodeTypes.BOOLEAN_CONSTANT -> + FirConstExpressionImpl(session, expression, IrConstKind.Boolean, convertedText as Boolean) + KtNodeTypes.NULL -> + FirConstExpressionImpl(session, expression, IrConstKind.Null, null) + else -> + throw AssertionError("Unknown literal type: $type, $text") + } + +} + +internal fun IElementType.toBinaryName(): Name? { + return OperatorConventions.BINARY_OPERATION_NAMES[this] +} + +internal fun IElementType.toUnaryName(): Name? { + return OperatorConventions.UNARY_OPERATION_NAMES[this] +} + +internal fun IElementType.toFirOperation(): FirOperation = + when (this) { + KtTokens.LT -> FirOperation.LT + KtTokens.GT -> FirOperation.GT + KtTokens.LTEQ -> FirOperation.LT_EQ + KtTokens.GTEQ -> FirOperation.GT_EQ + KtTokens.EQEQ -> FirOperation.EQ + KtTokens.EXCLEQ -> FirOperation.NOT_EQ + KtTokens.EQEQEQ -> FirOperation.IDENTITY + KtTokens.EXCLEQEQEQ -> FirOperation.NOT_IDENTITY + KtTokens.ANDAND -> FirOperation.AND + KtTokens.OROR -> FirOperation.OR + KtTokens.IN_KEYWORD -> FirOperation.IN + KtTokens.NOT_IN -> FirOperation.NOT_IN + KtTokens.RANGE -> FirOperation.RANGE + + KtTokens.EQ -> FirOperation.ASSIGN + KtTokens.PLUSEQ -> FirOperation.PLUS_ASSIGN + KtTokens.MINUSEQ -> FirOperation.MINUS_ASSIGN + KtTokens.MULTEQ -> FirOperation.TIMES_ASSIGN + KtTokens.DIVEQ -> FirOperation.DIV_ASSIGN + KtTokens.PERCEQ -> FirOperation.REM_ASSIGN + + KtTokens.AS_KEYWORD -> FirOperation.AS + KtTokens.AS_SAFE -> FirOperation.SAFE_AS + + else -> throw AssertionError(this.toString()) + } + +internal fun FirExpression.generateNotNullOrOther(other: FirExpression, caseId: String, basePsi: KtElement): FirWhenExpression { + val subjectName = Name.special("<$caseId>") + val subjectVariable = generateTemporaryVariable(session, psi, subjectName, this) + val subjectExpression = FirWhenSubjectExpression(session, psi) + return FirWhenExpressionImpl( + session, basePsi, this, subjectVariable + ).apply { + branches += FirWhenBranchImpl( + session, psi, + FirOperatorCallImpl(session, psi, FirOperation.NOT_EQ).apply { + arguments += subjectExpression + arguments += FirConstExpressionImpl(session, psi, IrConstKind.Null, null) + }, + FirSingleExpressionBlock( + session, + generateAccessExpression(session, psi, subjectName) + ) + ) + branches += FirWhenBranchImpl( + session, other.psi, FirElseIfTrueCondition(session, psi), + FirSingleExpressionBlock(session, other) + ) + } +} + +internal fun generateIncrementOrDecrementBlock( + session: FirSession, + baseExpression: KtUnaryExpression, + argument: KtExpression?, + callName: Name, + prefix: Boolean, + convert: KtExpression.() -> FirExpression +): FirExpression { + if (argument == null) { + return FirErrorExpressionImpl(session, argument, "Inc/dec without operand") + } + return FirBlockImpl(session, baseExpression).apply { + val tempName = Name.special("") + statements += generateTemporaryVariable(session, baseExpression, tempName, argument.convert()) + val resultName = Name.special("") + val resultInitializer = FirFunctionCallImpl(session, baseExpression).apply { + this.calleeReference = FirSimpleNamedReference(session, baseExpression.operationReference, callName) + this.arguments += generateAccessExpression(session, baseExpression, tempName) + } + val resultVar = generateTemporaryVariable(session, baseExpression, resultName, resultInitializer) + val assignment = argument.generateAssignment( + session, baseExpression, + if (prefix && argument !is KtSimpleNameExpression) + generateAccessExpression(session, baseExpression, resultName) + else + resultInitializer, + FirOperation.ASSIGN, convert + ) + + fun appendAssignment() { + if (assignment is FirBlock) { + statements += assignment.statements + } else { + statements += assignment + } + } + + if (prefix) { + if (argument !is KtSimpleNameExpression) { + statements += resultVar + appendAssignment() + statements += generateAccessExpression(session, baseExpression, resultName) + } else { + appendAssignment() + statements += generateAccessExpression(session, baseExpression, argument.getReferencedNameAsName()) + } + } else { + appendAssignment() + statements += generateAccessExpression(session, baseExpression, tempName) + } + } +} + +internal fun generateAccessExpression(session: FirSession, psi: PsiElement?, name: Name): FirAccessExpression = + FirAccessExpressionImpl(session, psi).apply { + calleeReference = FirSimpleNamedReference(session, psi, name) + } + +internal fun generateDestructuringBlock( + session: FirSession, + multiDeclaration: KtDestructuringDeclaration, + container: FirNamedDeclaration, + extractAnnotationsTo: KtAnnotated.(FirAbstractAnnotatedElement) -> Unit, + toFirOrImplicitType: KtTypeReference?.() -> FirType +): FirExpression { + return FirBlockImpl(session, multiDeclaration).apply { + if (container is FirVariable) { + statements += container + } + val isVar = multiDeclaration.isVar + for ((index, entry) in multiDeclaration.entries.withIndex()) { + statements += FirVariableImpl( + session, entry, entry.nameAsSafeName, + entry.typeReference.toFirOrImplicitType(), isVar, + FirComponentCallImpl(session, entry, index + 1).apply { + arguments += generateAccessExpression(session, entry, container.name) + } + ).apply { + entry.extractAnnotationsTo(this) + } + } + } +} + +internal fun generateTemporaryVariable( + session: FirSession, psi: PsiElement?, name: Name, initializer: FirExpression +): FirVariable = FirVariableImpl(session, psi, name, FirImplicitTypeImpl(session, psi), false, initializer) + +internal fun generateTemporaryVariable( + session: FirSession, psi: PsiElement?, specialName: String, initializer: FirExpression +): FirVariable = generateTemporaryVariable(session, psi, Name.special("<$specialName>"), initializer) + +private fun FirModifiableAccess.initializeLValue( + session: FirSession, + left: KtExpression?, + convertQualified: KtQualifiedExpression.() -> FirAccess? +): FirReference { + return when (left) { + is KtSimpleNameExpression -> { + FirSimpleNamedReference(session, left, left.getReferencedNameAsName()) + } + is KtThisExpression -> { + FirExplicitThisReference(session, left, left.getLabelName()) + } + is KtQualifiedExpression -> { + val firMemberAccess = left.convertQualified() + if (firMemberAccess != null) { + explicitReceiver = firMemberAccess.explicitReceiver + safe = firMemberAccess.safe + firMemberAccess.calleeReference + } else { + FirErrorNamedReference(session, left, "Unsupported qualified LValue: ${left.text}") + } + } + is KtParenthesizedExpression -> { + initializeLValue(session, left.expression, convertQualified) + } + else -> { + FirErrorNamedReference(session, left, "Unsupported LValue: ${left?.javaClass}") + } + } +} + +internal fun KtExpression?.generateAssignment( + session: FirSession, + psi: PsiElement?, + value: FirExpression, + operation: FirOperation, + convert: KtExpression.() -> FirExpression +): FirStatement { + if (this is KtParenthesizedExpression) { + return expression.generateAssignment(session, psi, value, operation, convert) + } + if (this is KtArrayAccessExpression) { + val arrayExpression = this.arrayExpression + val arraySet = FirArraySetCallImpl(session, psi, value, operation).apply { + for (indexExpression in indexExpressions) { + arguments += indexExpression.convert() + } + } + if (arrayExpression is KtSimpleNameExpression) { + return arraySet.apply { + calleeReference = initializeLValue(session, arrayExpression) { convert() as? FirAccess } + } + } + return FirBlockImpl(session, arrayExpression).apply { + val name = Name.special("") + statements += generateTemporaryVariable( + session, this@generateAssignment, name, + arrayExpression?.convert() ?: FirErrorExpressionImpl(session, arrayExpression, "No array expression") + ) + statements += arraySet.apply { calleeReference = FirSimpleNamedReference(session, arrayExpression, name) } + } + } + if (operation != FirOperation.ASSIGN && + this !is KtSimpleNameExpression && this !is KtThisExpression && + (this !is KtQualifiedExpression || selectorExpression !is KtSimpleNameExpression) + ) { + return FirBlockImpl(session, this).apply { + val name = Name.special("") + statements += generateTemporaryVariable( + session, this@generateAssignment, name, + this@generateAssignment?.convert() ?: FirErrorExpressionImpl(session, this@generateAssignment, "No LValue in assignment") + ) + statements += FirPropertyAssignmentImpl(session, psi, value, operation).apply { + calleeReference = FirSimpleNamedReference(session, this@generateAssignment, name) + } + } + } + return FirPropertyAssignmentImpl(session, psi, value, operation).apply { + calleeReference = initializeLValue(session, this@generateAssignment) { convert() as? FirAccess } + } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 1f6111eaed9..34de59fbed1 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -5,20 +5,21 @@ package org.jetbrains.kotlin.fir.builder -import org.jetbrains.kotlin.KtNodeTypes +import com.intellij.psi.PsiElement 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.FirElement -import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.impl.* -import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall -import org.jetbrains.kotlin.fir.expressions.FirBody -import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall -import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.impl.* +import org.jetbrains.kotlin.fir.labels.FirLabelImpl +import org.jetbrains.kotlin.fir.references.FirErrorNamedReference +import org.jetbrains.kotlin.fir.references.FirExplicitSuperReference +import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference +import org.jetbrains.kotlin.fir.references.FirExplicitThisReference import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol @@ -32,11 +33,14 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.types.expressions.OperatorConventions +import org.jetbrains.kotlin.util.OperatorNameConventions -class RawFirBuilder(val session: FirSession) { +class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { private val implicitUnitType = FirImplicitUnitType(session, null) @@ -86,133 +90,102 @@ class RawFirBuilder(val session: FirSession) { private fun KtTypeReference?.toFirOrErrorType(): FirType = convertSafe() ?: FirErrorTypeImpl(session, this, if (this == null) "Incomplete code" else "Conversion failed") - private fun KtDeclarationWithBody.buildFirBody(): FirBody? = - when { - !hasBody() -> null - hasBlockBody() -> FirBlockBodyImpl(session, this) - else -> FirExpressionBodyImpl(session, FirExpressionStub(session, null)) + // Here we accept lambda as receiver to prevent expression calculation in stub mode + private fun (() -> KtExpression?).toFirExpression(errorReason: String): FirExpression = + if (stubMode) FirExpressionStub(session, null) + else with(this()) { + convertSafe() ?: FirErrorExpressionImpl(session, this, errorReason) } - private fun String.parseCharacter(): Char? { - // Strip the quotes - if (length < 2 || this[0] != '\'' || this[length - 1] != '\'') { - return null - } - val text = substring(1, length - 1) // now there're no quotes + private fun KtExpression.toFirExpression(): FirExpression = + if (stubMode) FirExpressionStub(session, null) else convert() - if (text.isEmpty()) { - return null + private fun KtExpression?.toFirExpression(errorReason: String): FirExpression = + if (stubMode) FirExpressionStub(session, null) + else convertSafe() ?: FirErrorExpressionImpl(session, this, errorReason) + + private fun KtExpression.toFirStatement(errorReason: String): FirStatement = + convertSafe() ?: FirErrorExpressionImpl(session, this, errorReason) + + private fun KtExpression.toFirStatement(): FirStatement = + convert() + + private fun KtExpression?.toFirBlock(): FirBlock = + when (this) { + is KtBlockExpression -> + accept(this@Visitor, Unit) as FirBlock + null -> + FirEmptyExpressionBlock(session) + else -> + FirSingleExpressionBlock( + session, + convert() + ) } - return if (text[0] != '\\') { - // No escape - if (text.length == 1) { - text[0] + private fun FirExpression.toReturn(basePsi: PsiElement? = psi, labelName: String? = null): FirReturnExpression { + return FirReturnExpressionImpl( + session, + basePsi, + this + ).apply { + target = FirFunctionTarget(labelName) + if (labelName == null) { + target.bind(firFunctions.last()) } else { - null - } - } else { - escapedStringToCharacter(text) - } - } - - private fun escapedStringToCharacter(text: String): Char? { - assert(text.isNotEmpty() && text[0] == '\\') { - "Only escaped sequences must be passed to this routine: $text" - } - - // Escape - val escape = text.substring(1) // strip the slash - when (escape.length) { - 0 -> { - // bare slash - return null - } - 1 -> { - // one-char escape - return translateEscape(escape[0]) ?: return null - } - 5 -> { - // unicode escape - if (escape[0] == 'u') { - try { - val intValue = Integer.valueOf(escape.substring(1), 16) - return intValue.toInt().toChar() - } catch (e: NumberFormatException) { - // Will be reported below + for (firFunction in firFunctions.asReversed()) { + when (firFunction) { + is FirAnonymousFunction -> { + if (firFunction.label?.name == labelName) { + target.bind(firFunction) + return@apply + } + } + is FirNamedFunction -> { + if (firFunction.name.asString() == labelName) { + target.bind(firFunction) + return@apply + } + } } } + target.bind(FirErrorFunction(session, psi, "Cannot bind label $labelName to a function")) } } - return null } - private fun translateEscape(c: Char): Char? = - when (c) { - 't' -> '\t' - 'b' -> '\b' - 'n' -> '\n' - 'r' -> '\r' - '\'' -> '\'' - '\"' -> '\"' - '\\' -> '\\' - '$' -> '$' - else -> null + private fun KtDeclarationWithBody.buildFirBody(): FirBlock? = + when { + !hasBody() -> + null + hasBlockBody() -> if (!stubMode) { + bodyBlockExpression?.accept(this@Visitor, Unit) as? FirBlock + } else { + FirSingleExpressionBlock( + session, + FirExpressionStub(session, this).toReturn() + ) + } + else -> { + val result = { bodyExpression }.toFirExpression("Function has no body (but should)") + FirSingleExpressionBlock( + session, + result.toReturn() + ) + } } private fun ValueArgument?.toFirExpression(): FirExpression { this ?: return FirErrorExpressionImpl(session, this as? KtElement, "No argument given") val expression = this.getArgumentExpression() - when (expression) { - is KtConstantExpression -> { - val type = expression.node.elementType - val text: String = expression.text - return when (type) { - KtNodeTypes.INTEGER_CONSTANT -> - if (text.last() == 'l' || text.last() == 'L') { - FirConstExpressionImpl( - session, expression, IrConstKind.Long, text.dropLast(1).toLongOrNull(), "Incorrect long: $text" - ) - } else { - // TODO: support byte / short - FirConstExpressionImpl(session, expression, IrConstKind.Int, text.toIntOrNull(), "Incorrect int: $text") - } - KtNodeTypes.FLOAT_CONSTANT -> - if (text.last() == 'f' || text.last() == 'F') { - FirConstExpressionImpl( - session, expression, IrConstKind.Float, text.dropLast(1).toFloatOrNull(), "Incorrect float: $text" - ) - } else { - FirConstExpressionImpl( - session, expression, IrConstKind.Double, text.toDoubleOrNull(), "Incorrect double: $text" - ) - } - KtNodeTypes.CHARACTER_CONSTANT -> - FirConstExpressionImpl( - session, expression, IrConstKind.Char, text.parseCharacter(), "Incorrect character: $text" - ) - KtNodeTypes.BOOLEAN_CONSTANT -> - FirConstExpressionImpl(session, expression, IrConstKind.Boolean, text.toBoolean()) - KtNodeTypes.NULL -> - FirConstExpressionImpl(session, expression, IrConstKind.Null, null) - else -> - throw AssertionError("Unknown literal type: $type, $text") - } + return when (expression) { + is KtConstantExpression, is KtStringTemplateExpression -> { + expression.accept(this@Visitor, Unit) as FirExpression } - is KtStringTemplateExpression -> { - val sb = StringBuilder() - for (entry in expression.entries) { - when (entry) { - is KtLiteralStringTemplateEntry -> sb.append(entry.text) - is KtEscapeStringTemplateEntry -> sb.append(entry.unescapedValue) - else -> return FirErrorExpressionImpl(session, expression, "Incorrect template entry: ${entry.text}") - } - } - return FirConstExpressionImpl(session, expression, IrConstKind.String, sb.toString()) + else -> { + { expression }.toFirExpression("Argument is absent") } - - else -> return FirExpressionStub(session, this as? KtElement) } } @@ -237,14 +210,16 @@ class RawFirBuilder(val session: FirSession) { returnTypeReference?.convertSafe() ?: propertyType } else { returnTypeReference.toFirOrUnitType() - }, - this.buildFirBody() + } ) + firFunctions += firAccessor extractAnnotationsTo(firAccessor) extractValueParametersTo(firAccessor, propertyType) if (!isGetter && firAccessor.valueParameters.isEmpty()) { firAccessor.valueParameters += FirDefaultSetterValueParameter(session, this, propertyType) } + firAccessor.body = this.buildFirBody() + firFunctions.removeLast() return firAccessor } @@ -258,7 +233,9 @@ class RawFirBuilder(val session: FirSession) { defaultType != null -> defaultType else -> null.toFirOrErrorType() }, - if (hasDefaultValue()) FirExpressionStub(session, this) else null, + if (hasDefaultValue()) { + { defaultValue }.toFirExpression("Should have default value") + } else null, isCrossinline = hasModifier(KtTokens.CROSSINLINE_KEYWORD), isNoinline = hasModifier(KtTokens.NOINLINE_KEYWORD), isVararg = isVarArg @@ -293,7 +270,7 @@ class RawFirBuilder(val session: FirSession) { return firProperty } - private fun KtModifierListOwner.extractAnnotationsTo(container: FirAbstractAnnotatedDeclaration) { + private fun KtAnnotated.extractAnnotationsTo(container: FirAbstractAnnotatedElement) { for (annotationEntry in annotationEntries) { container.annotations += annotationEntry.convert() } @@ -321,7 +298,7 @@ class RawFirBuilder(val session: FirSession) { } private fun KtClassOrObject.extractSuperTypeListEntriesTo( - container: FirClassImpl, delegatedSelfType: FirType + container: FirModifiableClass, delegatedSelfType: FirType ): FirType? { var superTypeCallEntry: KtSuperTypeCallEntry? = null var delegatedSuperType: FirType? = null @@ -339,7 +316,7 @@ class RawFirBuilder(val session: FirSession) { val type = superTypeListEntry.typeReference.toFirOrErrorType() container.superTypes += FirDelegatedTypeImpl( type, - FirExpressionStub(session, superTypeListEntry) + { superTypeListEntry.delegateExpression }.toFirExpression("Should have delegate") ) } } @@ -375,8 +352,9 @@ class RawFirBuilder(val session: FirSession) { delegatedSuperType, isThis = false ).apply { - // TODO: arguments are not needed for light classes, but will be needed later - //superTypeCallEntry.extractArgumentsTo(this) + if (!stubMode) { + superTypeCallEntry?.extractArgumentsTo(this) + } } val firConstructor = FirPrimaryConstructorImpl( session, @@ -509,6 +487,19 @@ class RawFirBuilder(val session: FirSession) { } } + override fun visitObjectLiteralExpression(expression: KtObjectLiteralExpression, data: Unit): FirElement { + val objectDeclaration = expression.objectDeclaration + return FirAnonymousObjectImpl(session, expression).apply { + objectDeclaration.extractAnnotationsTo(this) + val delegatedSelfType = objectDeclaration.toDelegatedSelfType() + objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType) + + for (declaration in objectDeclaration.declarations) { + declarations += declaration.convert() + } + } + } + override fun visitTypeAlias(typeAlias: KtTypeAlias, data: Unit): FirElement { return withChildClassName(typeAlias.nameAsSafeName) { val firTypeAlias = FirTypeAliasImpl( @@ -527,44 +518,101 @@ class RawFirBuilder(val session: FirSession) { } } - override fun visitNamedFunction(function: KtNamedFunction, data: Unit): FirElement { - if (function.name == null) { - // TODO: return anonymous function here - // TODO: what if name is not null but we're in expression position? - return FirExpressionStub(session, function) + private val firFunctions = mutableListOf() + + private fun MutableList.removeLast() { + removeAt(size - 1) + } + + private fun MutableList.pop(): T? { + val result = lastOrNull() + if (result != null) { + removeAt(size - 1) } + return result + } + + override fun visitNamedFunction(function: KtNamedFunction, data: Unit): FirElement { val typeReference = function.typeReference - val firFunction = FirMemberFunctionImpl( - session, - function, - function.nameAsSafeName, - function.visibility, - function.modality, - function.hasExpectModifier(), - function.hasActualModifier(), - function.hasModifier(KtTokens.OVERRIDE_KEYWORD), - function.hasModifier(KtTokens.OPERATOR_KEYWORD), - function.hasModifier(KtTokens.INFIX_KEYWORD), - function.hasModifier(KtTokens.INLINE_KEYWORD), - function.hasModifier(KtTokens.TAILREC_KEYWORD), - function.hasModifier(KtTokens.EXTERNAL_KEYWORD), - function.hasModifier(KtTokens.SUSPEND_KEYWORD), - function.receiverTypeReference.convertSafe(), - if (function.hasBlockBody()) { - typeReference.toFirOrUnitType() - } else { - typeReference.toFirOrImplicitType() - }, - function.buildFirBody() - ) + val returnType = if (function.hasBlockBody()) { + typeReference.toFirOrUnitType() + } else { + typeReference.toFirOrImplicitType() + } + val receiverType = function.receiverTypeReference.convertSafe() + val firFunction = if (function.name == null) { + FirAnonymousFunctionImpl(session, function, returnType, receiverType) + } else { + FirMemberFunctionImpl( + session, + function, + function.nameAsSafeName, + function.visibility, + function.modality, + function.hasExpectModifier(), + function.hasActualModifier(), + function.hasModifier(KtTokens.OVERRIDE_KEYWORD), + function.hasModifier(KtTokens.OPERATOR_KEYWORD), + function.hasModifier(KtTokens.INFIX_KEYWORD), + function.hasModifier(KtTokens.INLINE_KEYWORD), + function.hasModifier(KtTokens.TAILREC_KEYWORD), + function.hasModifier(KtTokens.EXTERNAL_KEYWORD), + function.hasModifier(KtTokens.SUSPEND_KEYWORD), + receiverType, + returnType + ) + } + firFunctions += firFunction function.extractAnnotationsTo(firFunction) - function.extractTypeParametersTo(firFunction) + if (firFunction is FirMemberFunctionImpl) { + function.extractTypeParametersTo(firFunction) + } for (valueParameter in function.valueParameters) { firFunction.valueParameters += valueParameter.convert() } + firFunction.body = function.buildFirBody() + firFunctions.removeLast() return firFunction } + override fun visitLambdaExpression(expression: KtLambdaExpression, data: Unit): FirElement { + val literal = expression.functionLiteral + val returnType = FirImplicitTypeImpl(session, literal) + val receiverType = FirImplicitTypeImpl(session, literal) + return FirAnonymousFunctionImpl(session, literal, returnType, receiverType).apply { + firFunctions += this + var destructuringBlock: FirExpression? = null + for (valueParameter in literal.valueParameters) { + val multiDeclaration = valueParameter.destructuringDeclaration + valueParameters += if (multiDeclaration != null) { + val multiParameter = FirValueParameterImpl( + session, valueParameter, Name.special(""), + FirImplicitTypeImpl(session, multiDeclaration), + defaultValue = null, isCrossinline = false, isNoinline = false, isVararg = false + ) + destructuringBlock = generateDestructuringBlock( + session, multiDeclaration, multiParameter, { extractAnnotationsTo(it) } + ) { toFirOrImplicitType() } + multiParameter + } else { + valueParameter.convert() + } + } + label = firLabels.pop() ?: firFunctionCalls.lastOrNull()?.calleeReference?.name?.let { + FirLabelImpl(session, expression, it.asString()) + } + val bodyExpression = literal.bodyExpression.toFirExpression("Lambda has no body") + if (destructuringBlock is FirBlock && bodyExpression is FirBlockImpl) { + for ((index, statement) in destructuringBlock.statements.withIndex()) { + bodyExpression.statements.add(index, statement) + } + } + body = FirSingleExpressionBlock(session, bodyExpression.toReturn()) + + firFunctions.removeLast() + } + } + private fun KtSecondaryConstructor.toFirConstructor( delegatedSuperType: FirType?, delegatedSelfType: FirType, @@ -577,11 +625,13 @@ class RawFirBuilder(val session: FirSession) { hasExpectModifier(), hasActualModifier(), delegatedSelfType, - getDelegationCall().convert(delegatedSuperType, delegatedSelfType, hasPrimaryConstructor), - buildFirBody() + getDelegationCall().convert(delegatedSuperType, delegatedSelfType, hasPrimaryConstructor) ) + firFunctions += firConstructor extractAnnotationsTo(firConstructor) extractValueParametersTo(firConstructor) + firConstructor.body = buildFirBody() + firFunctions.removeLast() return firConstructor } @@ -595,48 +645,69 @@ class RawFirBuilder(val session: FirSession) { isThis -> delegatedSelfType else -> delegatedSuperType ?: FirErrorTypeImpl(session, this, "No super type") } - val firConstructorCall = FirDelegatedConstructorCallImpl( + return FirDelegatedConstructorCallImpl( session, this, delegatedType, isThis - ) - // TODO: arguments are not needed for light classes, but will be needed later - // call.extractArgumentsTo(firConstructorCall) - return firConstructorCall + ).apply { + if (!stubMode) { + extractArgumentsTo(this) + } + } } override fun visitAnonymousInitializer(initializer: KtAnonymousInitializer, data: Unit): FirElement { return FirAnonymousInitializerImpl( session, initializer, - FirBlockBodyImpl(session, initializer) + if (stubMode) FirEmptyExpressionBlock(session) else initializer.body.toFirBlock() ) } override fun visitProperty(property: KtProperty, data: Unit): FirElement { val propertyType = property.typeReference.toFirOrImplicitType() - val firProperty = FirMemberPropertyImpl( - session, - property, - property.nameAsSafeName, - property.visibility, - property.modality, - property.hasExpectModifier(), - property.hasActualModifier(), - property.hasModifier(KtTokens.OVERRIDE_KEYWORD), - property.hasModifier(KtTokens.CONST_KEYWORD), - property.hasModifier(KtTokens.LATEINIT_KEYWORD), - property.receiverTypeReference.convertSafe(), - propertyType, - property.isVar, - if (property.hasInitializer()) FirExpressionStub(session, property) else null, - property.getter.toFirPropertyAccessor(property, propertyType, isGetter = true), - property.setter.toFirPropertyAccessor(property, propertyType, isGetter = false), - if (property.hasDelegate()) FirExpressionStub(session, property) else null - ) + val name = property.nameAsSafeName + val isVar = property.isVar + val initializer = if (property.hasInitializer()) { + { property.initializer }.toFirExpression("Should have initializer") + } else null + val firProperty = if (property.isLocal) { + FirVariableImpl( + session, + property, + name, + propertyType, + isVar, + initializer, + property.delegate?.expression?.toFirExpression() + ) + } else { + FirMemberPropertyImpl( + session, + property, + name, + property.visibility, + property.modality, + property.hasExpectModifier(), + property.hasActualModifier(), + property.hasModifier(KtTokens.OVERRIDE_KEYWORD), + property.hasModifier(KtTokens.CONST_KEYWORD), + property.hasModifier(KtTokens.LATEINIT_KEYWORD), + property.receiverTypeReference.convertSafe(), + propertyType, + isVar, + initializer, + property.getter.toFirPropertyAccessor(property, propertyType, isGetter = true), + property.setter.toFirPropertyAccessor(property, propertyType, isGetter = false), + if (property.hasDelegate()) { + { property.delegate?.expression }.toFirExpression("Should have delegate") + } else null + ).apply { + property.extractTypeParametersTo(this) + } + } property.extractAnnotationsTo(firProperty) - property.extractTypeParametersTo(firProperty) return firProperty } @@ -711,20 +782,27 @@ class RawFirBuilder(val session: FirSession) { } override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit): FirElement { + val parameterName = parameter.nameAsSafeName val firTypeParameter = FirTypeParameterImpl( session, parameter, FirTypeParameterSymbol(), - parameter.nameAsSafeName, + parameterName, parameter.variance, parameter.hasModifier(KtTokens.REIFIED_KEYWORD) ) parameter.extractAnnotationsTo(firTypeParameter) val extendsBound = parameter.extendsBound - // TODO: handle where, here or (preferable) in parent if (extendsBound != null) { firTypeParameter.bounds += extendsBound.convert() } + val owner = parameter.getStrictParentOfType() ?: return firTypeParameter + for (typeConstraint in owner.typeConstraints) { + val subjectName = typeConstraint.subjectTypeParameterName?.getReferencedNameAsName() + if (subjectName == parameterName) { + firTypeParameter.bounds += typeConstraint.boundTypeReference.toFirOrErrorType() + } + } return firTypeParameter } @@ -752,11 +830,514 @@ class RawFirBuilder(val session: FirSession) { parameter.toFirValueParameter() override fun visitBlockExpression(expression: KtBlockExpression, data: Unit): FirElement { - return FirBlockBodyImpl(session, expression) + return FirBlockImpl(session, expression).apply { + for (statement in expression.statements) { + val firStatement = statement.toFirStatement("Statement expected: ${statement.text}") + if (firStatement !is FirBlock || firStatement.annotations.isNotEmpty()) { + statements += firStatement + } else { + statements += firStatement.statements + } + } + } + } + + override fun visitSimpleNameExpression(expression: KtSimpleNameExpression, data: Unit): FirElement { + return generateAccessExpression(session, expression, expression.getReferencedNameAsName()) + } + + override fun visitConstantExpression(expression: KtConstantExpression, data: Unit): FirElement = + generateConstantExpressionByLiteral(session, expression) + + override fun visitStringTemplateExpression(expression: KtStringTemplateExpression, data: Unit): FirElement { + val sb = StringBuilder() + var hasExpressions = false + val interpolatingCall = FirFunctionCallImpl(session, expression).apply { + calleeReference = FirSimpleNamedReference(session, expression, OperatorNameConventions.PLUS) + for (entry in expression.entries) { + when (entry) { + is KtLiteralStringTemplateEntry -> { + sb.append(entry.text) + arguments += FirConstExpressionImpl(session, entry, IrConstKind.String, entry.text) + } + is KtEscapeStringTemplateEntry -> { + sb.append(entry.unescapedValue) + arguments += FirConstExpressionImpl(session, entry, IrConstKind.String, entry.unescapedValue) + } + is KtStringTemplateEntryWithExpression -> { + val innerExpression = entry.expression + if (innerExpression != null) { + arguments += innerExpression.toFirExpression() + hasExpressions = true + } + } + else -> { + arguments += FirErrorExpressionImpl(session, expression, "Incorrect template entry: ${entry.text}") + hasExpressions = true + } + } + } + } + return if (hasExpressions) { + interpolatingCall + } else { + FirConstExpressionImpl(session, expression, IrConstKind.String, sb.toString()) + } + } + + override fun visitReturnExpression(expression: KtReturnExpression, data: Unit): FirElement { + val result = expression.returnedExpression?.toFirExpression() ?: FirUnitExpression(session, expression) + return result.toReturn(expression, expression.getTargetLabel()?.getReferencedName()) + } + + override fun visitTryExpression(expression: KtTryExpression, data: Unit): FirElement { + val tryBlock = expression.tryBlock.toFirBlock() + val finallyBlock = expression.finallyBlock?.finalExpression?.toFirBlock() + return FirTryExpressionImpl(session, expression, tryBlock, finallyBlock).apply { + for (clause in expression.catchClauses) { + val parameter = clause.catchParameter?.toFirValueParameter() ?: continue + val block = clause.catchBody.toFirBlock() + catches += FirCatchImpl(session, clause, parameter, block) + } + } + } + + override fun visitIfExpression(expression: KtIfExpression, data: Unit): FirElement { + return FirWhenExpressionImpl( + session, + expression + ).apply { + val condition = expression.condition + val firCondition = condition.toFirExpression("If statement should have condition") + val trueBranch = expression.then.toFirBlock() + branches += FirWhenBranchImpl(session, condition, firCondition, trueBranch) + val elseBranch = expression.`else`.toFirBlock() + branches += FirWhenBranchImpl(session, null, FirElseIfTrueCondition(session, null), elseBranch) + } + } + + private fun KtWhenCondition.toFirWhenCondition(firSubjectExpression: FirExpression): FirExpression { + return when (this) { + is KtWhenConditionWithExpression -> { + FirOperatorCallImpl( + session, + expression, + FirOperation.EQ + ).apply { + arguments += firSubjectExpression + arguments += expression.toFirExpression("No expression in condition with expression") + } + } + is KtWhenConditionInRange -> { + FirOperatorCallImpl( + session, + rangeExpression, + if (isNegated) FirOperation.NOT_IN else FirOperation.IN + ).apply { + arguments += firSubjectExpression + arguments += rangeExpression.toFirExpression("No range in condition with range") + } + } + is KtWhenConditionIsPattern -> { + FirTypeOperatorCallImpl( + session, typeReference, if (isNegated) FirOperation.NOT_IS else FirOperation.IS, + typeReference.toFirOrErrorType() + ).apply { + arguments += firSubjectExpression + } + } + else -> { + FirErrorExpressionImpl(session, this, "Unsupported when condition: ${this.javaClass}") + } + } + } + + override fun visitWhenExpression(expression: KtWhenExpression, data: Unit): FirElement { + val subjectExpression = expression.subjectExpression + val subject = when (subjectExpression) { + is KtVariableDeclaration -> subjectExpression.initializer + else -> subjectExpression + }?.toFirExpression() + val subjectVariable = when (subjectExpression) { + is KtVariableDeclaration -> FirVariableImpl( + session, subjectExpression, subjectExpression.nameAsSafeName, + subjectExpression.typeReference.toFirOrImplicitType(), + isVar = false, initializer = subject + ) + else -> null + } + val hasSubject = subject != null + return FirWhenExpressionImpl( + session, + expression, + subject, + subjectVariable + ).apply { + for (entry in expression.entries) { + val branch = entry.expression.toFirBlock() + branches += if (!entry.isElse) { + if (hasSubject) { + var firCondition: FirExpression? = null + for (condition in entry.conditions) { + val firConditionElement = condition.toFirWhenCondition(FirWhenSubjectExpression(session, condition)) + when { + firCondition == null -> firCondition = firConditionElement + firCondition is FirOperatorCallImpl && firCondition.operation == FirOperation.OR -> { + firCondition.arguments += firConditionElement + } + else -> { + firCondition = FirOperatorCallImpl(session, entry, FirOperation.OR).apply { + arguments += firCondition!! + arguments += firConditionElement + } + } + } + } + FirWhenBranchImpl(session, entry, firCondition!!, branch) + } else { + val condition = entry.conditions.first() as KtWhenConditionWithExpression + val firCondition = condition.expression.toFirExpression("No expression in condition with expression") + FirWhenBranchImpl(session, entry, firCondition, branch) + } + } else { + FirWhenBranchImpl(session, entry, FirElseIfTrueCondition(session, null), branch) + } + } + } + } + + private val firLoops = mutableListOf() + + private fun FirAbstractLoop.configure(generateBlock: () -> FirBlock): FirAbstractLoop { + label = firLabels.pop() + firLoops += this + block = generateBlock() + firLoops.removeLast() + return this + } + + override fun visitDoWhileExpression(expression: KtDoWhileExpression, data: Unit): FirElement { + return FirDoWhileLoopImpl( + session, expression, expression.condition.toFirExpression("No condition in do-while loop") + ).configure { expression.body.toFirBlock() } + } + + override fun visitWhileExpression(expression: KtWhileExpression, data: Unit): FirElement { + return FirWhileLoopImpl( + session, expression, expression.condition.toFirExpression("No condition in while loop") + ).configure { expression.body.toFirBlock() } + } + + override fun visitForExpression(expression: KtForExpression, data: Unit?): FirElement { + val rangeExpression = expression.loopRange.toFirExpression("No range in for loop") + val parameter = expression.loopParameter + return FirBlockImpl(session, expression).apply { + val rangeName = Name.special("") + statements += generateTemporaryVariable(session, expression.loopRange, rangeName, rangeExpression) + val iteratorName = Name.special("") + statements += generateTemporaryVariable( + session, expression.loopRange, iteratorName, + FirFunctionCallImpl(session, expression).apply { + calleeReference = FirSimpleNamedReference(session, expression, Name.identifier("iterator")) + explicitReceiver = generateAccessExpression(session, expression.loopRange, rangeName) + } + ) + statements += FirWhileLoopImpl( + session, expression, + FirFunctionCallImpl(session, expression).apply { + calleeReference = FirSimpleNamedReference(session, expression, Name.identifier("hasNext")) + explicitReceiver = generateAccessExpression(session, expression, iteratorName) + } + ).configure { + val body = expression.body + // NB: just body.toFirBlock() isn't acceptable here because we need to add some statements + val block = when (body) { + is KtBlockExpression -> body.accept(this@Visitor, Unit) as FirBlockImpl + null -> FirBlockImpl(session, body) + else -> FirBlockImpl(session, body).apply { statements += body.toFirStatement() } + } + if (parameter != null) { + val multiDeclaration = parameter.destructuringDeclaration + val firLoopParameter = generateTemporaryVariable( + session, expression.loopParameter, + if (multiDeclaration != null) Name.special("") else parameter.nameAsSafeName, + FirFunctionCallImpl(session, expression).apply { + calleeReference = FirSimpleNamedReference(session, expression, Name.identifier("next")) + explicitReceiver = generateAccessExpression(session, expression, iteratorName) + } + ) + if (multiDeclaration != null) { + val destructuringBlock = generateDestructuringBlock( + session, multiDeclaration, firLoopParameter, { extractAnnotationsTo(it) } + ) { toFirOrImplicitType() } + if (destructuringBlock is FirBlock) { + for ((index, statement) in destructuringBlock.statements.withIndex()) { + block.statements.add(index, statement) + } + } + } else { + block.statements.add(0, firLoopParameter) + } + } + block + } + } + } + + private fun FirAbstractLoopJump.bindLabel(expression: KtExpressionWithLabel): FirAbstractLoopJump { + val labelName = expression.getLabelName() + target = FirLoopTarget(labelName) + if (labelName == null) { + target.bind(firLoops.last()) + } else { + for (firLoop in firLoops.asReversed()) { + if (firLoop.label?.name == labelName) { + target.bind(firLoop) + return this + } + } + target.bind(FirErrorLoop(session, psi, "Cannot bind label $labelName to a loop")) + } + return this + } + + override fun visitBreakExpression(expression: KtBreakExpression, data: Unit): FirElement { + return FirBreakExpressionImpl(session, expression).bindLabel(expression) + } + + override fun visitContinueExpression(expression: KtContinueExpression, data: Unit): FirElement { + return FirContinueExpressionImpl(session, expression).bindLabel(expression) + } + + private fun KtBinaryExpression.elvisToWhen(): FirWhenExpression { + val rightArgument = right.toFirExpression("No right operand") + val leftArgument = left.toFirExpression("No left operand") + return leftArgument.generateNotNullOrOther(rightArgument, "elvis", this) + } + + private fun KtUnaryExpression.bangBangToWhen(): FirWhenExpression { + return baseExpression.toFirExpression("No operand").generateNotNullOrOther( + FirThrowExpressionImpl( + session, this, FirFunctionCallImpl(session, this).apply { + calleeReference = FirSimpleNamedReference(session, this@bangBangToWhen, KNPE) + } + ), "bangbang", this + ) + } + + override fun visitBinaryExpression(expression: KtBinaryExpression, data: Unit): FirElement { + val operationToken = expression.operationToken + val rightArgument = expression.right.toFirExpression("No right operand") + if (operationToken == KtTokens.ELVIS) { + return expression.elvisToWhen() + } + val conventionCallName = operationToken.toBinaryName() + return if (conventionCallName != null || operationToken == KtTokens.IDENTIFIER) { + FirFunctionCallImpl( + session, expression + ).apply { + calleeReference = FirSimpleNamedReference( + session, expression.operationReference, + conventionCallName ?: expression.operationReference.getReferencedNameAsName() + ) + } + } else { + val firOperation = operationToken.toFirOperation() + if (firOperation in FirOperation.ASSIGNMENTS) { + return expression.left.generateAssignment(session, expression, rightArgument, firOperation) { toFirExpression() } + } else { + FirOperatorCallImpl(session, expression, firOperation) + } + }.apply { + arguments += expression.left.toFirExpression("No left operand") + arguments += rightArgument + } + } + + override fun visitBinaryWithTypeRHSExpression(expression: KtBinaryExpressionWithTypeRHS, data: Unit): FirElement { + val operation = expression.operationReference.getReferencedNameElementType().toFirOperation() + return FirTypeOperatorCallImpl( + session, expression, operation, expression.right.toFirOrErrorType() + ).apply { + arguments += expression.left.toFirExpression("No left operand") + } + } + + override fun visitIsExpression(expression: KtIsExpression, data: Unit): FirElement { + return FirTypeOperatorCallImpl( + session, expression, if (expression.isNegated) FirOperation.NOT_IS else FirOperation.IS, + expression.typeReference.toFirOrErrorType() + ).apply { + arguments += expression.leftHandSide.toFirExpression("No left operand") + } + } + + override fun visitUnaryExpression(expression: KtUnaryExpression, data: Unit): FirElement { + val operationToken = expression.operationToken + val argument = expression.baseExpression + if (operationToken == KtTokens.EXCLEXCL) { + return expression.bangBangToWhen() + } + val conventionCallName = operationToken.toUnaryName() + return if (conventionCallName != null) { + if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) { + return generateIncrementOrDecrementBlock( + session, expression, argument, + callName = conventionCallName, + prefix = expression is KtPrefixExpression + ) { toFirExpression() } + } + FirFunctionCallImpl( + session, expression + ).apply { + calleeReference = FirSimpleNamedReference( + session, expression.operationReference, conventionCallName + ) + } + } else { + val firOperation = operationToken.toFirOperation() + FirOperatorCallImpl( + session, expression, firOperation + ) + }.apply { + arguments += argument.toFirExpression("No operand") + } + } + + private val firFunctionCalls = mutableListOf() + + override fun visitCallExpression(expression: KtCallExpression, data: Unit): FirElement { + val calleeExpression = expression.calleeExpression + return FirFunctionCallImpl(session, expression).apply { + val calleeReference = when (calleeExpression) { + is KtSimpleNameExpression -> FirSimpleNamedReference( + session, calleeExpression, calleeExpression.getReferencedNameAsName() + ) + null -> FirErrorNamedReference( + session, calleeExpression, "Call has no callee" + ) + else -> { + arguments += calleeExpression.toFirExpression() + FirSimpleNamedReference( + session, expression, OperatorNameConventions.INVOKE + ) + } + } + this.calleeReference = calleeReference + firFunctionCalls += this + for (argument in expression.valueArguments) { + arguments += argument.getArgumentExpression().toFirExpression("No argument expression") + } + for (typeArgument in expression.typeArguments) { + typeArguments += typeArgument.convert() + } + firFunctionCalls.removeLast() + } + } + + override fun visitArrayAccessExpression(expression: KtArrayAccessExpression, data: Unit): FirElement { + val arrayExpression = expression.arrayExpression + return FirArrayGetCallImpl(session, expression, arrayExpression.toFirExpression("No array expression")).apply { + for (indexExpression in expression.indexExpressions) { + arguments += indexExpression.toFirExpression() + } + } + } + + override fun visitQualifiedExpression(expression: KtQualifiedExpression, data: Unit): FirElement { + val selector = expression.selectorExpression + ?: return FirErrorExpressionImpl(session, expression, "Qualified expression without selector") + val firSelector = selector.toFirExpression() as FirModifiableAccess + firSelector.safe = expression is KtSafeQualifiedExpression + firSelector.explicitReceiver = expression.receiverExpression.toFirExpression() + return firSelector + } + + override fun visitThisExpression(expression: KtThisExpression, data: Unit): FirElement { + val labelName = expression.getLabelName() + return FirAccessExpressionImpl(session, expression).apply { + calleeReference = FirExplicitThisReference(session, expression, labelName) + } + } + + override fun visitSuperExpression(expression: KtSuperExpression, data: Unit): FirElement { + val superType = expression.superTypeQualifier + return FirAccessExpressionImpl(session, expression).apply { + calleeReference = FirExplicitSuperReference(session, expression, superType.toFirOrImplicitType()) + } + } + + override fun visitParenthesizedExpression(expression: KtParenthesizedExpression, data: Unit): FirElement { + return expression.expression?.accept(this, data) ?: FirErrorExpressionImpl(session, expression, "Empty parentheses") + } + + private val firLabels = mutableListOf() + + override fun visitLabeledExpression(expression: KtLabeledExpression, data: Unit): FirElement { + val labelName = expression.getLabelName() + val size = firLabels.size + if (labelName != null) { + firLabels += FirLabelImpl(session, expression, labelName) + } + val result = expression.baseExpression?.accept(this, data) ?: FirErrorExpressionImpl(session, expression, "Empty label") + if (size != firLabels.size) { + firLabels.removeLast() + println("Unused label: ${expression.text}") + } + return result + } + + override fun visitAnnotatedExpression(expression: KtAnnotatedExpression, data: Unit): FirElement { + val rawResult = expression.baseExpression?.accept(this, data) + val result = rawResult as? FirAbstractAnnotatedElement + ?: FirErrorExpressionImpl(session, expression, "Strange annotated expression: ${rawResult?.render()}") + expression.extractAnnotationsTo(result) + return result + } + + override fun visitThrowExpression(expression: KtThrowExpression, data: Unit): FirElement { + return FirThrowExpressionImpl(session, expression, expression.thrownExpression.toFirExpression("Nothing to throw")) + } + + override fun visitDestructuringDeclaration(multiDeclaration: KtDestructuringDeclaration, data: Unit): FirElement { + val baseVariable = generateTemporaryVariable( + session, multiDeclaration, "destruct", + multiDeclaration.initializer.toFirExpression("Destructuring declaration without initializer") + ) + return generateDestructuringBlock(session, multiDeclaration, baseVariable, { extractAnnotationsTo(it) }) { + toFirOrImplicitType() + } + } + + override fun visitClassLiteralExpression(expression: KtClassLiteralExpression, data: Unit): FirElement { + return FirGetClassCallImpl(session, expression).apply { + arguments += expression.receiverExpression.toFirExpression("No receiver in class literal") + } + } + + override fun visitCallableReferenceExpression(expression: KtCallableReferenceExpression, data: Unit): FirElement { + return FirCallableReferenceAccessImpl(session, expression).apply { + calleeReference = FirSimpleNamedReference( + session, expression.callableReference, expression.callableReference.getReferencedNameAsName() + ) + explicitReceiver = expression.receiverExpression?.toFirExpression() + } + } + + override fun visitCollectionLiteralExpression(expression: KtCollectionLiteralExpression, data: Unit): FirElement { + return FirArrayOfCallImpl(session, expression).apply { + for (innerExpression in expression.getInnerExpressions()) { + arguments += innerExpression.toFirExpression() + } + } } override fun visitExpression(expression: KtExpression, data: Unit): FirElement { return FirExpressionStub(session, expression) } } + + companion object { + val KNPE = Name.identifier("KotlinNullPointerException") + } } \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.txt index eafe374800b..22d905e029d 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.txt @@ -7,9 +7,9 @@ FILE: derivedClass.kt } public? final? class Derived : Base { - public? constructor(x: T): super>() + public? constructor(x: T): super>(x#) } public? final? function create(x: T): Derived { - STUB + return@@@create Derived#(x#) } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.txt index 7b4d11d639b..83037f0d3ee 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.txt @@ -28,30 +28,33 @@ FILE: enums.kt internal get(): Double public? final enum entry MERCURY : Planet { - public? constructor(): super() + public? constructor(): super(Double(1.0), Double(2.0)) public? open? override function sayHello(): kotlin.Unit { + println#(String(Hello!!!)) } } public? final enum entry VENERA : Planet { - public? constructor(): super() + public? constructor(): super(Double(3.0), Double(4.0)) public? open? override function sayHello(): kotlin.Unit { + println#(String(Ola!!!)) } } public? final enum entry EARTH : Planet { - public? constructor(): super() + public? constructor(): super(Double(5.0), Double(6.0)) public? open? override function sayHello(): kotlin.Unit { + println#(String(Privet!!!)) } } - public? final? property g(val): Double = STUB + public? final? property g(val): Double = div#(times#(G#, m#), times#(r#, r#)) public? get(): Double public? abstract function sayHello(): kotlin.Unit @@ -59,7 +62,7 @@ FILE: enums.kt public? final? companion object Companion { public? constructor(): super() - public? final? const property G(val): = STUB + public? final? const property G(val): = Double(6.67E-11) public? get(): } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.txt index 8ae53bee10d..536314b905a 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.txt @@ -16,19 +16,19 @@ FILE: enums2.kt public? get(): Some public? final enum entry FIRST : SomeEnum { - public? constructor(): super() + public? constructor(): super(O1#) public? open? override function check(y: Some): Boolean { - STUB + return@@@check Boolean(true) } } public? final enum entry SECOND : SomeEnum { - public? constructor(): super() + public? constructor(): super(O2#) public? open? override function check(y: Some): Boolean { - STUB + return@@@check ==(y#, O2#) } } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.txt index 632cb484a76..c7204becf41 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.txt @@ -11,7 +11,7 @@ FILE: expectActual.kt } public? final? actual function foo(): { - STUB + return@@@foo String(Hello) } - public? final? actual property x(val): = STUB + public? final? actual property x(val): = Int(42) public? get(): diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.txt index 085722eb6ea..2ad7c65a925 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.txt @@ -1,9 +1,9 @@ FILE: functionTypes.kt public? final? function simpleRun(f: ( (T) -> Unit )): Unit { - STUB + return@@@simpleRun f#() } public? final? function simpleMap List.(f: ( (T) -> R )): R { } public? final? function simpleWith(t: T, f: ( T.() -> Unit )): Unit { - STUB + return@@@simpleWith t#.f#() } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.txt index d7add662bdb..69430fc9c32 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.txt @@ -2,7 +2,7 @@ FILE: genericFunctions.kt public? final? interface Any { } public? final? inline function safeAs Any.(): T? { - STUB + return@@@safeAs as?/T(this#) } public? abstract class Summator { public? constructor(): super() diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.txt index 2c601955c9d..c11bae7af87 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.txt @@ -10,12 +10,12 @@ FILE: nestedClass.kt public? constructor(): super() public? final? class Derived : Base { - public? constructor(s: String): super() + public? constructor(s: String): super(s#) } public? final? object Obj : Base { - public? constructor(): super() + public? constructor(): super(String()) } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.txt index fb1263f5289..1d5a93fcc82 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.txt @@ -4,8 +4,9 @@ FILE: noPrimaryConstructor.kt public? get(): String public? constructor(x: String): super() { + this#.x# = x# } - public? constructor(): this() + public? constructor(): this(String()) } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.txt index d635b61313c..4f5c848d801 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.txt @@ -9,15 +9,16 @@ FILE: simpleClass.kt public? final? class SomeClass : SomeInterface { public? constructor(): super() - private final? property baz(val): = STUB + private final? property baz(val): = Int(42) private get(): public? open? override function foo(x: Int, y: String): String { + return@@@foo plus#(plus#(y#, x#), baz#) } public? open? override property bar(var): Boolean public? get(): Boolean { - STUB + return Boolean(true) } public? set(value: Boolean): kotlin.Unit { } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.txt index d5b135e2721..d02666f76ca 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.txt @@ -15,11 +15,11 @@ FILE: typeParameters.kt public? constructor(): super>() public? open? override function get(index: Int): Int { - STUB + return@@@get Int(42) } public? open? override function concat(other: List): List { - STUB + return@@@concat this# } } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/where.kt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/where.kt new file mode 100644 index 00000000000..ae57050bc5d --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/where.kt @@ -0,0 +1,6 @@ +interface A +interface B + +class C where T : A, T : B { + +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/declarations/where.txt b/compiler/fir/psi2fir/testData/rawBuilder/declarations/where.txt new file mode 100644 index 00000000000..17c1c68008a --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/declarations/where.txt @@ -0,0 +1,9 @@ +FILE: where.kt + public? final? interface A { + } + public? final? interface B { + } + public? final? class C { + public? constructor(): super() + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.kt new file mode 100644 index 00000000000..5d6132423ff --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.kt @@ -0,0 +1,19 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun foo(arg: Int): Int { + if (@Ann arg == 0) { + @Ann return 1 + } + @Ann if (arg == 1) { + return (@Ann 1) + } + return 42 +} + +data class Two(x: Int, y: Int) + +fun bar(two: Two) { + val (@Ann x, @Ann y) = two +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.txt new file mode 100644 index 00000000000..408d9936ba4 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.txt @@ -0,0 +1,33 @@ +FILE: annotated.kt + @Target(AnnotationTarget#.EXPRESSION#) @Retention(AnnotationRetention#.SOURCE#) public? final? annotation class Ann { + public? constructor(): super() + + } + public? final? function foo(arg: Int): Int { + when () { + ==(@Ann() arg#, Int(0)) -> { + @Ann() return@@@foo Int(1) + } + else -> { + } + } + + @Ann() when () { + ==(arg#, Int(1)) -> { + return@@@foo @Ann() Int(1) + } + else -> { + } + } + + return@@@foo Int(42) + } + public? final? data class Two { + public? constructor(x: Int, y: Int): super() + + } + public? final? function bar(two: Two): kotlin.Unit { + val : = two# + @Ann() val x: = component1(#) + @Ann() val y: = component2(#) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.kt new file mode 100644 index 00000000000..13cfbf1c29c --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.kt @@ -0,0 +1,6 @@ +val p = 0 +fun foo() = 1 + +class Wrapper(val v: IntArray) + +fun test(a: IntArray, w: Wrapper) = a[0] + a[p] + a[foo()] + w.v[0] \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.txt new file mode 100644 index 00000000000..e2415508d1e --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.txt @@ -0,0 +1,16 @@ +FILE: arrayAccess.kt + public? final? property p(val): = Int(0) + public? get(): + public? final? function foo(): { + return@@@foo Int(1) + } + public? final? class Wrapper { + public? constructor(v: IntArray): super() + + public? final? property v(val): IntArray + public? get(): IntArray + + } + public? final? function test(a: IntArray, w: Wrapper): { + return@@@test plus#(plus#(plus#(a#[Int(0)], a#[p#]), a#[foo#()]), w#.v#[Int(0)]) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.kt new file mode 100644 index 00000000000..26fec9c8b2b --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.kt @@ -0,0 +1,10 @@ +fun test() { + val x = intArrayOf(1, 2, 3) + x[1] = 0 +} + +fun foo() = 1 + +fun test2() { + intArrayOf(1, 2, 3)[foo()] = 1 +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.txt new file mode 100644 index 00000000000..8e4792d0263 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.txt @@ -0,0 +1,12 @@ +FILE: arrayAssignment.kt + public? final? function test(): kotlin.Unit { + val x: = intArrayOf#(Int(1), Int(2), Int(3)) + x#[Int(1)] = Int(0) + } + public? final? function foo(): { + return@@@foo Int(1) + } + public? final? function test2(): kotlin.Unit { + val : = intArrayOf#(Int(1), Int(2), Int(3)) + #[foo#()] = Int(1) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.kt new file mode 100644 index 00000000000..6348056c2f7 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.kt @@ -0,0 +1,33 @@ +fun foo(a: Int, b: Int) = if (a > b) a else b + +fun bar(a: Double, b: Double): Double { + if (a > b) { + println(a) + return a + } else { + println(b) + return b + } +} + +fun baz(a: Long, b: Long): Long { + when { + a > b -> { + println(a) + return a + } + else -> return b + } +} + +fun grade(g: Int): String { + return when (g) { + 6, 7 -> "Outstanding" + 5 -> "Excellent" + 4 -> "Good" + 3 -> "Mediocre" + in 1..2 -> "Fail" + is Number -> "Number" + else -> "Unknown" + } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.txt new file mode 100644 index 00000000000..fb222bb64a5 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.txt @@ -0,0 +1,63 @@ +FILE: branches.kt + public? final? function foo(a: Int, b: Int): { + return@@@foo when () { + >(a#, b#) -> { + a# + } + else -> { + b# + } + } + + } + public? final? function bar(a: Double, b: Double): Double { + when () { + >(a#, b#) -> { + println#(a#) + return@@@bar a# + } + else -> { + println#(b#) + return@@@bar b# + } + } + + } + public? final? function baz(a: Long, b: Long): Long { + when () { + >(a#, b#) -> { + println#(a#) + return@@@baz a# + } + else -> { + return@@@baz b# + } + } + + } + public? final? function grade(g: Int): String { + return@@@grade when (g#) { + ||(==($subj$, Int(6)), ==($subj$, Int(7))) -> { + String(Outstanding) + } + ==($subj$, Int(5)) -> { + String(Excellent) + } + ==($subj$, Int(4)) -> { + String(Good) + } + ==($subj$, Int(3)) -> { + String(Mediocre) + } + in($subj$, rangeTo#(Int(1), Int(2))) -> { + String(Fail) + } + is/Number($subj$) -> { + String(Number) + } + else -> { + String(Unknown) + } + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.kt new file mode 100644 index 00000000000..5903db92f16 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.kt @@ -0,0 +1,22 @@ +class A { + fun foo() {} + val bar = 0 +} + +fun A.qux() {} + +fun baz() {} + +val test1 = A()::foo + +val test2 = A()::bar + +val test3 = A()::qux + +val test4 = A::foo + +val test5 = A::bar + +val test6 = A::qux + +val test7 = ::baz diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.txt new file mode 100644 index 00000000000..b1072db4e80 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.txt @@ -0,0 +1,29 @@ +FILE: callableReferences.kt + public? final? class A { + public? constructor(): super() + + public? final? function foo(): kotlin.Unit { + } + + public? final? property bar(val): = Int(0) + public? get(): + + } + public? final? function qux A.(): kotlin.Unit { + } + public? final? function baz(): kotlin.Unit { + } + public? final? property test1(val): = A#()::foo# + public? get(): + public? final? property test2(val): = A#()::bar# + public? get(): + public? final? property test3(val): = A#()::qux# + public? get(): + public? final? property test4(val): = A#::foo# + public? get(): + public? final? property test5(val): = A#::bar# + public? get(): + public? final? property test6(val): = A#::qux# + public? get(): + public? final? property test7(val): = ::baz# + public? get(): diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.kt new file mode 100644 index 00000000000..dc78862d379 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.kt @@ -0,0 +1,24 @@ +infix fun distance(x: Int, y: Int) = x + y + +fun test(): Int = 3 distance 4 + +fun testRegular(): Int = distance(3, 4) + +class My(var x: Int) { + operator fun invoke() = x + + fun foo() {} + + fun copy() = My(x) +} + +fun testInvoke(): Int = My(13)() + +fun testQualified(first: My, second: My?) { + println(first.x) + println(second?.x) + first.foo() + second?.foo() + first.copy().foo() + first.x = 42 +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt new file mode 100644 index 00000000000..8a45e0c915c --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt @@ -0,0 +1,40 @@ +FILE: calls.kt + public? final? infix function distance(x: Int, y: Int): { + return@@@distance plus#(x#, y#) + } + public? final? function test(): Int { + return@@@test distance#(Int(3), Int(4)) + } + public? final? function testRegular(): Int { + return@@@testRegular distance#(Int(3), Int(4)) + } + public? final? class My { + public? constructor(x: Int): super() + + public? final? property x(var): Int + public? get(): Int + public? set(value: Int): kotlin.Unit + + public? final? operator function invoke(): { + return@@@invoke x# + } + + public? final? function foo(): kotlin.Unit { + } + + public? final? function copy(): { + return@@@copy My#(x#) + } + + } + public? final? function testInvoke(): Int { + return@@@testInvoke invoke#(My#(Int(13))) + } + public? final? function testQualified(first: My, second: My?): kotlin.Unit { + println#(first#.x#) + println#(second#?.x#) + first#.foo#() + second#?.foo#() + first#.copy#().foo#() + first#.x# = Int(42) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.kt new file mode 100644 index 00000000000..a3512198c8c --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.kt @@ -0,0 +1,14 @@ +//WITH_RUNTIME +package test + +class A + +fun test() { + A::class + test.A::class + A()::class + + A::class.java + test.A::class.java + A()::class.java +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.txt new file mode 100644 index 00000000000..cb61c193f85 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.txt @@ -0,0 +1,13 @@ +FILE: classReference.kt + public? final? class A { + public? constructor(): super() + + } + public? final? function test(): kotlin.Unit { + (A#) + (test#.A#) + (A#()) + (A#).java# + (test#.A#).java# + (A#()).java# + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.kt new file mode 100644 index 00000000000..1b8b745f734 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.kt @@ -0,0 +1,19 @@ +annotation class Ann1(val arr: IntArray) + +annotation class Ann2(val arr: DoubleArray) + +annotation class Ann3(val arr: Array) + +@Ann1([]) +@Ann2([]) +@Ann3([]) +class Zero + +@Ann1([1, 2]) +class First + +@Ann2([3.14]) +class Second + +@Ann3(["Alpha", "Omega"]) +class Third diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.txt new file mode 100644 index 00000000000..6b12991f8c9 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.txt @@ -0,0 +1,38 @@ +FILE: collectionLiterals.kt + public? final? annotation class Ann1 { + public? constructor(arr: IntArray): super() + + public? final? property arr(val): IntArray + public? get(): IntArray + + } + public? final? annotation class Ann2 { + public? constructor(arr: DoubleArray): super() + + public? final? property arr(val): DoubleArray + public? get(): DoubleArray + + } + public? final? annotation class Ann3 { + public? constructor(arr: Array): super() + + public? final? property arr(val): Array + public? get(): Array + + } + @Ann1(()) @Ann2(()) @Ann3(()) public? final? class Zero { + public? constructor(): super() + + } + @Ann1((Int(1), Int(2))) public? final? class First { + public? constructor(): super() + + } + @Ann2((Double(3.14))) public? final? class Second { + public? constructor(): super() + + } + @Ann3((String(Alpha), String(Omega))) public? final? class Third { + public? constructor(): super() + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.kt new file mode 100644 index 00000000000..cbd1e4c459d --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.kt @@ -0,0 +1,9 @@ +data class Some(val first: Int, val second: Double, val third: String) + +fun foo(some: Some) { + var (x, y, z: String) = some + + x++ + y *= 2.0 + z = "" +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.txt new file mode 100644 index 00000000000..dc8cd885e60 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.txt @@ -0,0 +1,25 @@ +FILE: destructuring.kt + public? final? data class Some { + public? constructor(first: Int, second: Double, third: String): super() + + public? final? property first(val): Int + public? get(): Int + + public? final? property second(val): Double + public? get(): Double + + public? final? property third(val): String + public? get(): String + + } + public? final? function foo(some: Some): kotlin.Unit { + val : = some# + var x: = component1(#) + var y: = component2(#) + var z: String = component3(#) + val : = x# + x# = inc#(#) + # + y# *= Double(2.0) + z# = String() + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.kt new file mode 100644 index 00000000000..b2940c2d127 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.kt @@ -0,0 +1,20 @@ +fun foo() { + for (i in 1..10) { + println(i) + } +} + +fun bar(list: List) { + for (element in list.subList(0, 10)) { + println(element) + } + for (element in list.subList(10, 20)) println(element) +} + +data class Some(val x: Int, val y: Int) + +fun baz(set: Set) { + for ((x, y) in set) { + println("x = $x y = $y") + } +} diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt new file mode 100644 index 00000000000..263d7bd71e7 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/for.txt @@ -0,0 +1,47 @@ +FILE: for.kt + public? final? function foo(): kotlin.Unit { + val : = rangeTo#(Int(1), Int(10)) + val : = #.iterator#() + while(#.hasNext#()) { + val i: = #.next#() + println#(i#) + } + + } + public? final? function bar(list: List): kotlin.Unit { + val : = list#.subList#(Int(0), Int(10)) + val : = #.iterator#() + while(#.hasNext#()) { + val element: = #.next#() + println#(element#) + } + + val : = list#.subList#(Int(10), Int(20)) + val : = #.iterator#() + while(#.hasNext#()) { + val element: = #.next#() + println#(element#) + } + + } + public? final? data class Some { + public? constructor(x: Int, y: Int): super() + + public? final? property x(val): Int + public? get(): Int + + public? final? property y(val): Int + public? get(): Int + + } + public? final? function baz(set: Set): kotlin.Unit { + val : = set# + val : = #.iterator#() + while(#.hasNext#()) { + val : = #.next#() + val x: = component1(#) + val y: = component2(#) + println#(plus#(String(x = ), x#, String( y = ), y#)) + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.kt new file mode 100644 index 00000000000..7514f5be9a7 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.kt @@ -0,0 +1,7 @@ +fun nullableValue(): T? = null + +fun test() { + val n = nullableValue() + val x = nullableValue() + val s = nullableValue() +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.txt new file mode 100644 index 00000000000..5559c44328f --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.txt @@ -0,0 +1,9 @@ +FILE: genericCalls.kt + public? final? function nullableValue(): T? { + return@@@nullableValue Null(null) + } + public? final? function test(): kotlin.Unit { + val n: = nullableValue#() + val x: = nullableValue#() + val s: = nullableValue#() + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt new file mode 100644 index 00000000000..09796ff15c2 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt @@ -0,0 +1,7 @@ +class WithInit(x: Int) { + val x: Int + + init { + this.x = x + } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/init.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/init.txt new file mode 100644 index 00000000000..1b113463ffa --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/init.txt @@ -0,0 +1,12 @@ +FILE: init.kt + public? final? class WithInit { + public? constructor(x: Int): super() + + public? final? property x(val): Int + public? get(): Int + + init { + this#.x# = x# + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.kt new file mode 100644 index 00000000000..9f9934e3e19 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.kt @@ -0,0 +1,29 @@ +data class Tuple(val x: Int, val y: Int) + +inline fun use(f: (Tuple) -> Int) = f(Tuple(1, 2)) + +fun foo(): Int { + val l1 = { t: Tuple -> + val x = t.x + val y = t.y + x + y + } + use { (x, y) -> x + y } + + return use { + if (it.x == 0) return@foo 0 + return@use it.y + } +} + +fun bar(): Int { + return use lambda@{ + if (it.x == 0) return@bar 0 + return@lambda it.y + } +} + +fun test(list: List) { + val map = mutableMapOf() + list.forEach { map.getOrPut(it, { mutableListOf() }) += "" } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.txt new file mode 100644 index 00000000000..73d6540a193 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.txt @@ -0,0 +1,83 @@ +FILE: lambda.kt + public? final? data class Tuple { + public? constructor(x: Int, y: Int): super() + + public? final? property x(val): Int + public? get(): Int + + public? final? property y(val): Int + public? get(): Int + + } + public? final? inline function use(f: ( (Tuple) -> Int )): { + return@@@use f#(Tuple#(Int(1), Int(2))) + } + public? final? function foo(): Int { + val l1: = function .(t: Tuple): { + return { + val x: = t#.x# + val y: = t#.y# + plus#(x#, y#) + } + + } + + use#(use@function .(: ): { + return { + val x: = component1(#) + val y: = component2(#) + plus#(x#, y#) + } + + } + ) + return@@@foo use#(use@function .(): { + return { + when () { + ==(it#.x#, Int(0)) -> { + return@@@foo Int(0) + } + else -> { + } + } + + return@@@use it#.y# + } + + } + ) + } + public? final? function bar(): Int { + return@@@bar use#(lambda@function .(): { + return { + when () { + ==(it#.x#, Int(0)) -> { + return@@@bar Int(0) + } + else -> { + } + } + + return@@@lambda it#.y# + } + + } + ) + } + public? final? function test(list: List): kotlin.Unit { + val map: = mutableMapOf#() + list#.forEach#(forEach@function .(): { + return { + val : = map#.getOrPut#(it#, getOrPut@function .(): { + return { + mutableListOf#() + } + + } + ) + # += String() + } + + } + ) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.kt new file mode 100644 index 00000000000..e002b071297 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.kt @@ -0,0 +1,17 @@ +fun withLocals(p: Int): Int { + class Local(val pp: Int) { + fun diff() = pp - p + } + + val x = Local(42).diff() + + fun sum(y: Int, z: Int, f: (Int, Int) -> Int): Int { + return x + f(y + z) + } + + val code = (object : Any() { + fun foo() = hashCode() + }).foo() + + return sum(code, Local(1).diff(), fun(x: Int, y: Int) = x + y) +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.txt new file mode 100644 index 00000000000..3d103de59e2 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.txt @@ -0,0 +1,33 @@ +FILE: locals.kt + public? final? function withLocals(p: Int): Int { + public? final? class Local { + public? constructor(pp: Int): super() + + public? final? property pp(val): Int + public? get(): Int + + public? final? function diff(): { + return@@@diff minus#(pp#, p#) + } + + } + + val x: = Local#(Int(42)).diff#() + public? final? function sum(y: Int, z: Int, f: ( (Int, Int) -> Int )): Int { + return@@@sum plus#(x#, f#(plus#(y#, z#))) + } + + val code: = object : Any { + public? constructor(): super() + + public? final? function foo(): { + return@@@foo hashCode#() + } + + } + .foo#() + return@@@withLocals sum#(code#, Local#(Int(1)).diff#(), function (x: Int, y: Int): { + return plus#(x#, y#) + } + ) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.kt new file mode 100644 index 00000000000..679dfe5b99a --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.kt @@ -0,0 +1,16 @@ +fun simple() { + var x = 10 + x += 20 + x -= 5 + x /= 5 + x *= 10 +} + +fun List.modify() { + this += "Alpha" + this += "Omega" +} + +fun Any.modify() { + (this as List) += 42 +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.txt new file mode 100644 index 00000000000..830538e87db --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.txt @@ -0,0 +1,16 @@ +FILE: modifications.kt + public? final? function simple(): kotlin.Unit { + var x: = Int(10) + x# += Int(20) + x# -= Int(5) + x# /= Int(5) + x# *= Int(10) + } + public? final? function modify List.(): kotlin.Unit { + this# += String(Alpha) + this# += String(Omega) + } + public? final? function modify Any.(): kotlin.Unit { + val : = as/List(this#) + # += Int(42) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.kt new file mode 100644 index 00000000000..31ed9591d8b --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.kt @@ -0,0 +1,3 @@ +fun orFourtyTwo(arg: Int?) = arg ?: 42 + +fun bang(arg: Int?) = arg!! \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.txt new file mode 100644 index 00000000000..bddfe4dc341 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.txt @@ -0,0 +1,23 @@ +FILE: nullability.kt + public? final? function orFourtyTwo(arg: Int?): { + return@@@orFourtyTwo when (val : = arg#) { + !=($subj$, Null(null)) -> { + # + } + else -> { + Int(42) + } + } + + } + public? final? function bang(arg: Int?): { + return@@@bang when (val : = arg#) { + !=($subj$, Null(null)) -> { + # + } + else -> { + throw KotlinNullPointerException#() + } + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.kt new file mode 100644 index 00000000000..a77577cbef4 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.kt @@ -0,0 +1,7 @@ +fun foo() { + return +} + +fun bar(): String { + return "Hello" +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.txt new file mode 100644 index 00000000000..9d3fc2c6208 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.txt @@ -0,0 +1,7 @@ +FILE: simpleReturns.kt + public? final? function foo(): kotlin.Unit { + return@@@foo Unit + } + public? final? function bar(): String { + return@@@bar String(Hello) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/super.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/super.kt new file mode 100644 index 00000000000..cf2829c4ae3 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/super.kt @@ -0,0 +1,19 @@ +interface A { + fun foo() {} +} + +interface B { + fun foo() {} + fun bar() {} +} + +class C : A, B { + override fun bar() { + super.bar() + } + + override fun foo() { + super.foo() + super.foo() + } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/super.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/super.txt new file mode 100644 index 00000000000..faa67014703 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/super.txt @@ -0,0 +1,27 @@ +FILE: super.kt + public? final? interface A { + public? final? function foo(): kotlin.Unit { + } + + } + public? final? interface B { + public? final? function foo(): kotlin.Unit { + } + + public? final? function bar(): kotlin.Unit { + } + + } + public? final? class C : A, B { + public? constructor(): super() + + public? open? override function bar(): kotlin.Unit { + super<>.bar#() + } + + public? open? override function foo(): kotlin.Unit { + super.foo#() + super.foo#() + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/these.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/these.kt new file mode 100644 index 00000000000..21749d49e07 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/these.kt @@ -0,0 +1,22 @@ +class Some { + fun foo(): Int = 1 + + fun bar(): Int { + return this.foo() + } + + val instance: Some + get() = this@Some + + fun String.extension(): Int { + return this@Some.bar() + this.length + } +} + +fun Some.extension() = this.bar() + +fun test(some: Some): Int { + return with(some) { + this.foo() + this@with.extension() + } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/these.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/these.txt new file mode 100644 index 00000000000..92624008989 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/these.txt @@ -0,0 +1,34 @@ +FILE: these.kt + public? final? class Some { + public? constructor(): super() + + public? final? function foo(): Int { + return@@@foo Int(1) + } + + public? final? function bar(): Int { + return@@@bar this#.foo#() + } + + public? final? property instance(val): Some + public? get(): Some { + return this@Some + } + + public? final? function extension String.(): Int { + return@@@extension plus#(this@Some.bar#(), this#.length#) + } + + } + public? final? function extension Some.(): { + return@@@extension this#.bar#() + } + public? final? function test(some: Some): Int { + return@@@test with#(some#, with@function .(): { + return { + plus#(this#.foo#(), this@with.extension#()) + } + + } + ) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/try.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/try.kt new file mode 100644 index 00000000000..22c640e27ab --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/try.kt @@ -0,0 +1,11 @@ +fun some() { + try { + throw KotlinNullPointerException() + } catch (e: RuntimeException) { + println("Runtime exception") + } catch (e: Exception) { + println("Some exception") + } finally { + println("finally") + } +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/try.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/try.txt new file mode 100644 index 00000000000..e43730908e4 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/try.txt @@ -0,0 +1,16 @@ +FILE: try.kt + public? final? function some(): kotlin.Unit { + try { + throw KotlinNullPointerException#() + } + catch (e: RuntimeException) { + println#(String(Runtime exception)) + } + catch (e: Exception) { + println#(String(Some exception)) + } + finally { + println#(String(finally)) + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.kt new file mode 100644 index 00000000000..cc1d67f214d --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.kt @@ -0,0 +1,6 @@ +interface IThing + +fun test1(x: Any) = x is IThing +fun test2(x: Any) = x !is IThing +fun test3(x: Any) = x as IThing +fun test4(x: Any) = x as? IThing \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.txt new file mode 100644 index 00000000000..4c906bb586b --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.txt @@ -0,0 +1,15 @@ +FILE: typeOperators.kt + public? final? interface IThing { + } + public? final? function test1(x: Any): { + return@@@test1 is/IThing(x#) + } + public? final? function test2(x: Any): { + return@@@test2 !is/IThing(x#) + } + public? final? function test3(x: Any): { + return@@@test3 as/IThing(x#) + } + public? final? function test4(x: Any): { + return@@@test4 as?/IThing(x#) + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.kt new file mode 100644 index 00000000000..3dc424f9616 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.kt @@ -0,0 +1,29 @@ +fun test() { + var x = 0 + val x1 = x++ + val x2 = ++x + val x3 = --x + val x4 = x-- + if (!(x == 0)) { + println("000") + } +} + +class X(val i: Int) + +fun test2(x: X) { + val x1 = x.i++ + val x2 = ++x.i +} + +fun test3(arr: Array) { + val x1 = arr[0]++ + val x2 = ++arr[1] +} + +class Y(val arr: Array) + +fun test4(y: Y) { + val x1 = y.arr[0]++ + val x2 = ++y.arr[1] +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.txt new file mode 100644 index 00000000000..1dc8b1c91ac --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.txt @@ -0,0 +1,97 @@ +FILE: unary.kt + public? final? function test(): kotlin.Unit { + var x: = Int(0) + val x1: = { + val : = x# + x# = inc#(#) + # + } + + val x2: = { + val : = x# + x# = inc#(#) + x# + } + + val x3: = { + val : = x# + x# = dec#(#) + x# + } + + val x4: = { + val : = x# + x# = dec#(#) + # + } + + when () { + not#(==(x#, Int(0))) -> { + println#(String(000)) + } + else -> { + } + } + + } + public? final? class X { + public? constructor(i: Int): super() + + public? final? property i(val): Int + public? get(): Int + + } + public? final? function test2(x: X): kotlin.Unit { + val x1: = { + val : = x#.i# + x#.i# = inc#(#) + # + } + + val x2: = { + val : = x#.i# + val : = inc#(#) + x#.i# = # + # + } + + } + public? final? function test3(arr: Array): kotlin.Unit { + val x1: = { + val : = arr#[Int(0)] + arr#[Int(0)] = inc#(#) + # + } + + val x2: = { + val : = arr#[Int(1)] + val : = inc#(#) + arr#[Int(1)] = # + # + } + + } + public? final? class Y { + public? constructor(arr: Array): super() + + public? final? property arr(val): Array + public? get(): Array + + } + public? final? function test4(y: Y): kotlin.Unit { + val x1: = { + val : = y#.arr#[Int(0)] + val : = y#.arr# + #[Int(0)] = inc#(#) + # + } + + val x2: = { + val : = y#.arr#[Int(1)] + val : = inc#(#) + val : = y#.arr# + #[Int(1)] = # + # + } + + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.kt new file mode 100644 index 00000000000..f8de96e5e73 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.kt @@ -0,0 +1,8 @@ +fun foo() { + val x = 1 + var y = x + 1 + val z = y * 2 + y = y + z + val w = y - x + return w +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.txt new file mode 100644 index 00000000000..3d1e1273e35 --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.txt @@ -0,0 +1,9 @@ +FILE: variables.kt + public? final? function foo(): kotlin.Unit { + val x: = Int(1) + var y: = plus#(x#, Int(1)) + val z: = times#(y#, Int(2)) + y# = plus#(y#, z#) + val w: = minus#(y#, x#) + return@@@foo w# + } diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/while.kt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/while.kt new file mode 100644 index 00000000000..d2397aa741e --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/while.kt @@ -0,0 +1,20 @@ +fun foo(limit: Int) { + var k = 0 + some@ while (k < limit) { + k++ + println(k) + while (k == 13) { + k++ + if (k < limit) break@some + if (k > limit) continue + } + } +} + +fun bar(limit: Int) { + var k = limit + do { + k-- + println(k) + } while (k >= 0) +} \ No newline at end of file diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/while.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/while.txt new file mode 100644 index 00000000000..2cb0ebc72fd --- /dev/null +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/while.txt @@ -0,0 +1,43 @@ +FILE: while.kt + public? final? function foo(limit: Int): kotlin.Unit { + var k: = Int(0) + some@while(<(k#, limit#)) { + val : = k# + k# = inc#(#) + # + println#(k#) + while(==(k#, Int(13))) { + val : = k# + k# = inc#(#) + # + when () { + <(k#, limit#) -> { + break@@@[<(k#, limit#)] + } + else -> { + } + } + + when () { + >(k#, limit#) -> { + continue@@@[==(k#, Int(13))] + } + else -> { + } + } + + } + + } + + } + public? final? function bar(limit: Int): kotlin.Unit { + var k: = limit# + do { + val : = k# + k# = dec#(#) + # + println#(k#) + } + while(>=(k#, Int(0))) + } diff --git a/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt b/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt index 185fe334311..cf79dc9d116 100644 --- a/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt +++ b/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt @@ -58,7 +58,7 @@ abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase( protected fun doRawFirTest(filePath: String) { val file = createKtFile(filePath) - val firFile = file.toFirFile() + val firFile = file.toFirFile(stubMode = false) val firFileDump = StringBuilder().also { FirRenderer(it).visitFile(firFile) }.toString() val expectedPath = filePath.replace(".kt", ".txt") KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump) @@ -71,8 +71,8 @@ abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase( } } - protected fun KtFile.toFirFile(): FirFile = - RawFirBuilder(object : FirSessionBase() {}).buildFirFile(this) + protected fun KtFile.toFirFile(stubMode: Boolean): FirFile = + RawFirBuilder(object : FirSessionBase() {}, stubMode).buildFirFile(this) private fun FirElement.traverseChildren(result: MutableSet = hashSetOf()): MutableSet { if (!result.add(this)) { diff --git a/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java b/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java index 14f3003269c..abad27890a5 100644 --- a/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java +++ b/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java @@ -130,5 +130,143 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas public void testTypeParameters() throws Exception { runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.kt"); } + + @TestMetadata("where.kt") + public void testWhere() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/where.kt"); + } + } + + @TestMetadata("compiler/fir/psi2fir/testData/rawBuilder/expressions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Expressions extends AbstractRawFirBuilderTestCase { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doRawFirTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInExpressions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("annotated.kt") + public void testAnnotated() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.kt"); + } + + @TestMetadata("arrayAccess.kt") + public void testArrayAccess() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.kt"); + } + + @TestMetadata("arrayAssignment.kt") + public void testArrayAssignment() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.kt"); + } + + @TestMetadata("branches.kt") + public void testBranches() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.kt"); + } + + @TestMetadata("callableReferences.kt") + public void testCallableReferences() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.kt"); + } + + @TestMetadata("calls.kt") + public void testCalls() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.kt"); + } + + @TestMetadata("classReference.kt") + public void testClassReference() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.kt"); + } + + @TestMetadata("collectionLiterals.kt") + public void testCollectionLiterals() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.kt"); + } + + @TestMetadata("destructuring.kt") + public void testDestructuring() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.kt"); + } + + @TestMetadata("for.kt") + public void testFor() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/for.kt"); + } + + @TestMetadata("genericCalls.kt") + public void testGenericCalls() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.kt"); + } + + @TestMetadata("init.kt") + public void testInit() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt"); + } + + @TestMetadata("lambda.kt") + public void testLambda() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.kt"); + } + + @TestMetadata("locals.kt") + public void testLocals() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.kt"); + } + + @TestMetadata("modifications.kt") + public void testModifications() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.kt"); + } + + @TestMetadata("nullability.kt") + public void testNullability() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.kt"); + } + + @TestMetadata("simpleReturns.kt") + public void testSimpleReturns() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.kt"); + } + + @TestMetadata("super.kt") + public void testSuper() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/super.kt"); + } + + @TestMetadata("these.kt") + public void testThese() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/these.kt"); + } + + @TestMetadata("try.kt") + public void testTry() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/try.kt"); + } + + @TestMetadata("typeOperators.kt") + public void testTypeOperators() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.kt"); + } + + @TestMetadata("unary.kt") + public void testUnary() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.kt"); + } + + @TestMetadata("variables.kt") + public void testVariables() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.kt"); + } + + @TestMetadata("while.kt") + public void testWhile() throws Exception { + runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/while.kt"); + } } } diff --git a/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt b/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt index 0f13576b50a..30dc8a5910f 100644 --- a/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt +++ b/compiler/fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/RawFirBuilderTotalKotlinTestCase.kt @@ -6,8 +6,19 @@ package org.jetbrains.kotlin.fir.builder import com.intellij.testFramework.TestDataPath +import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirRenderer +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.declarations.FirErrorDeclaration import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.expressions.FirErrorExpression +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirAccess +import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub +import org.jetbrains.kotlin.fir.references.FirErrorNamedReference +import org.jetbrains.kotlin.fir.render +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.test.JUnit3RunnerWithInners import org.junit.runner.RunWith import java.io.File @@ -17,11 +28,19 @@ import kotlin.system.measureNanoTime @RunWith(JUnit3RunnerWithInners::class) class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() { - fun testTotalKotlin() { + private fun testTotalKotlinWithGivenMode(stubMode: Boolean) { val root = File(testDataPath) var counter = 0 var time = 0L var totalLength = 0 + var expressionStubs = 0 + var errorExpressions = 0 + var normalExpressions = 0 + var normalStatements = 0 + var errorDeclarations = 0 + var normalDeclarations = 0 + var errorReferences = 0 + var normalReferences = 0 println("BASE PATH: $testDataPath") for (file in root.walkTopDown()) { if (file.isDirectory) continue @@ -31,12 +50,66 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() { val ktFile = createKtFile(file.toRelativeString(root)) var firFile: FirFile? = null time += measureNanoTime { - firFile = ktFile.toFirFile() + firFile = ktFile.toFirFile(stubMode) } totalLength += StringBuilder().also { FirRenderer(it).visitFile(firFile!!) }.length counter++ + firFile?.accept(object : FirVisitorVoid() { + override fun visitElement(element: FirElement) { + element.acceptChildren(this) + } + + override fun visitErrorExpression(errorExpression: FirErrorExpression) { + errorExpressions++ + println(errorExpression.render()) + errorExpression.psi?.let { println(it) } + } + + override fun visitAccess(access: FirAccess) { + val calleeReference = access.calleeReference + if (calleeReference is FirErrorNamedReference) { + errorReferences++ + println(calleeReference.errorReason) + } else { + normalReferences++ + } + super.visitAccess(access) + } + + override fun visitExpression(expression: FirExpression) { + when (expression) { + is FirExpressionStub -> { + expressionStubs++ + if (!stubMode) { + println(expression.psi?.text) + } + } + else -> normalExpressions++ + } + expression.acceptChildren(this) + } + + override fun visitStatement(statement: FirStatement) { + normalStatements++ + statement.acceptChildren(this) + } + + override fun visitErrorDeclaration(errorDeclaration: FirErrorDeclaration) { + errorDeclarations++ + println(errorDeclaration.render()) + errorDeclaration.psi?.let { println(it) } + } + + override fun visitDeclaration(declaration: FirDeclaration) { + normalDeclarations++ + declaration.acceptChildren(this) + } + }) + } catch (e: Exception) { - println("TIME PER FILE: ${(time / counter) * 1e-6} ms, COUNTER: $counter") + if (counter > 0) { + println("TIME PER FILE: ${(time / counter) * 1e-6} ms, COUNTER: $counter") + } println("EXCEPTION in: " + file.toRelativeString(root)) throw e } @@ -44,6 +117,28 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() { println("SUCCESS!") println("TOTAL LENGTH: $totalLength") println("TIME PER FILE: ${(time / counter) * 1e-6} ms, COUNTER: $counter") + println("EXPRESSION STUBS: $expressionStubs") + println("ERROR EXPRESSIONS: $errorExpressions") + println("NORMAL EXPRESSIONS: $normalExpressions") + println("NORMAL STATEMENTS: $normalStatements") + println("ERROR DECLARATIONS: $errorDeclarations") + println("NORMAL DECLARATIONS: $normalDeclarations") + println("ERROR REFERENCES: $errorReferences") + println("NORMAL REFERENCES: $normalReferences") + if (!stubMode) { + assertEquals(0, expressionStubs) + } + assertEquals(0, errorExpressions) + assertEquals(0, errorDeclarations) + assertEquals(0, errorReferences) + } + + fun testTotalKotlinWithExpressionTrees() { + testTotalKotlinWithGivenMode(stubMode = false) + } + + fun testTotalKotlinWithDeclarationsOnly() { + testTotalKotlinWithGivenMode(stubMode = true) } fun testVisitConsistency() { @@ -53,7 +148,7 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() { if (file.path.contains("testData") || file.path.contains("resources")) continue if (file.extension != "kt") continue val ktFile = createKtFile(file.toRelativeString(root)) - val firFile = ktFile.toFirFile() + val firFile = ktFile.toFirFile(stubMode = false) try { firFile.checkChildren() } catch (e: Throwable) { @@ -70,7 +165,7 @@ class RawFirBuilderTotalKotlinTestCase : AbstractRawFirBuilderTestCase() { if (file.path.contains("testData") || file.path.contains("resources")) continue if (file.extension != "kt") continue val ktFile = createKtFile(file.toRelativeString(root)) - val firFile = ktFile.toFirFile() + val firFile = ktFile.toFirFile(stubMode = false) try { firFile.checkTransformedChildren() } catch (e: Throwable) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt index 8d78591cf59..b2d643b4249 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt @@ -44,14 +44,14 @@ class FirProviderImpl(val session: FirSession) : FirProvider { var containerFqName: FqName = FqName.ROOT - override fun visitClass(klass: FirClass) { - val fqName = containerFqName.child(klass.name) + override fun visitRegularClass(regularClass: FirRegularClass) { + val fqName = containerFqName.child(regularClass.name) val classId = ClassId(packageName, fqName, false) - classifierMap[classId] = klass + classifierMap[classId] = regularClass classifierContainerFileMap[classId] = file containerFqName = fqName - klass.acceptChildren(this) + regularClass.acceptChildren(this) containerFqName = fqName.parent() } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt index 433cd3672cd..633633928e6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt @@ -24,7 +24,7 @@ class FirStatusResolveTransformer : FirTransformer() { private val declarationsWithStatuses = mutableListOf() - private val classes = mutableListOf() + private val classes = mutableListOf() private fun FirDeclaration.resolveVisibility(): Visibility { if (this is FirConstructor) { @@ -39,7 +39,7 @@ class FirStatusResolveTransformer : FirTransformer() { private fun FirDeclaration.resolveModality(): Modality { return when (this) { is FirEnumEntry -> Modality.FINAL - is FirClass -> if (classKind == ClassKind.INTERFACE) Modality.ABSTRACT else Modality.FINAL + is FirRegularClass -> if (classKind == ClassKind.INTERFACE) Modality.ABSTRACT else Modality.FINAL is FirCallableMember -> { val containingClass = classes.lastOrNull() when { @@ -94,7 +94,7 @@ class FirStatusResolveTransformer : FirTransformer() { } private inline fun storeClass( - klass: FirClass, + klass: FirRegularClass, computeResult: () -> CompositeTransformResult ): CompositeTransformResult { classes += klass @@ -103,9 +103,9 @@ class FirStatusResolveTransformer : FirTransformer() { return result } - override fun transformClass(klass: FirClass, data: Nothing?): CompositeTransformResult { - return storeClass(klass) { - super.transformClass(klass, data) + override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult { + return storeClass(regularClass) { + super.transformRegularClass(regularClass, data) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index 67b1fe4e0b4..f4877b540f5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -50,7 +50,7 @@ open class FirTypeResolveTransformer( return super.transformFile(file, data) } - private fun lookupSuperTypes(klass: FirClass): List { + private fun lookupSuperTypes(klass: FirRegularClass): List { return mutableListOf().also { klass.symbol.collectSuperTypes(it) } } @@ -63,28 +63,28 @@ open class FirTypeResolveTransformer( } } - override fun transformClass(klass: FirClass, data: Nothing?): CompositeTransformResult { + override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult { return withScopeCleanup { - klass.withTypeParametersScope { - resolveSuperTypesAndExpansions(klass) + regularClass.withTypeParametersScope { + resolveSuperTypesAndExpansions(regularClass) - val firProvider = FirProvider.getInstance(klass.session) - val classId = klass.symbol.classId + val firProvider = FirProvider.getInstance(regularClass.session) + val classId = regularClass.symbol.classId scope.scopes += FirNestedClassifierScope(classId, firProvider) - val companionObjects = klass.declarations.filterIsInstance().filter { it.isCompanion } + val companionObjects = regularClass.declarations.filterIsInstance().filter { it.isCompanion } for (companionObject in companionObjects) { scope.scopes += FirNestedClassifierScope(companionObject.symbol.classId, firProvider) } - lookupSuperTypes(klass).mapTo(scope.scopes) { + lookupSuperTypes(regularClass).mapTo(scope.scopes) { val symbol = it.symbol if (symbol is FirBasedSymbol<*>) { FirNestedClassifierScope(symbol.classId, FirProvider.getInstance(symbol.fir.session)) } else { - FirNestedClassifierScope(symbol.classId, FirSymbolProvider.getInstance(klass.session)) + FirNestedClassifierScope(symbol.classId, FirSymbolProvider.getInstance(regularClass.session)) } } - super.transformClass(klass, data) + super.transformRegularClass(regularClass, data) } } } diff --git a/compiler/fir/resolve/testData/resolve/builtins/lists.txt b/compiler/fir/resolve/testData/resolve/builtins/lists.txt index 12d841a2ea0..e55468d26ab 100644 --- a/compiler/fir/resolve/testData/resolve/builtins/lists.txt +++ b/compiler/fir/resolve/testData/resolve/builtins/lists.txt @@ -8,8 +8,8 @@ FILE: lists.kt } public final function convert R|kotlin/collections/List|.(): R|MyStringList| { - STUB + return@@@convert STUB } public final function ret(l: R|kotlin/collections/MutableList|): R|MyMutableStringList| { - STUB + return@@@ret STUB } diff --git a/compiler/fir/resolve/testData/resolve/derivedClass.txt b/compiler/fir/resolve/testData/resolve/derivedClass.txt index 4f22951e1a9..2a55b76ffaf 100644 --- a/compiler/fir/resolve/testData/resolve/derivedClass.txt +++ b/compiler/fir/resolve/testData/resolve/derivedClass.txt @@ -11,5 +11,5 @@ FILE: derivedClass.kt } public final function create(x: R|T|): R|Derived| { - STUB + return@@@create STUB } diff --git a/compiler/fir/resolve/testData/resolve/enum.txt b/compiler/fir/resolve/testData/resolve/enum.txt index 3b47887abd6..093f91e2a82 100644 --- a/compiler/fir/resolve/testData/resolve/enum.txt +++ b/compiler/fir/resolve/testData/resolve/enum.txt @@ -19,7 +19,7 @@ FILE: enum.kt public constructor(): super() public final override function check(y: R|Some|): R|kotlin/Boolean| { - STUB + return@@@check STUB } } @@ -28,7 +28,7 @@ FILE: enum.kt public constructor(): super() public final override function check(y: R|Some|): R|kotlin/Boolean| { - STUB + return@@@check STUB } } diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt index ae684564a38..cf47b36e80c 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt @@ -31,6 +31,7 @@ FILE: enums.kt public constructor(): super() public final override function sayHello(): R|kotlin/Unit| { + return@@@sayHello STUB } } @@ -39,6 +40,7 @@ FILE: enums.kt public constructor(): super() public final override function sayHello(): R|kotlin/Unit| { + return@@@sayHello STUB } } @@ -47,6 +49,7 @@ FILE: enums.kt public constructor(): super() public final override function sayHello(): R|kotlin/Unit| { + return@@@sayHello STUB } } diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt index 3d36c220922..566222a51c2 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt @@ -4,6 +4,7 @@ FILE: noPrimaryConstructor.kt public get(): R|kotlin/String| public constructor(x: R|kotlin/String|): super() { + return STUB } public constructor(): this() diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt index 1269a7ac2e0..fc6be87ea0b 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt @@ -13,13 +13,15 @@ FILE: simpleClass.kt private get(): R|error: Not supported: FirImplicitTypeImpl| public final override function foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String| { + return@@@foo STUB } public final override property bar(var): R|kotlin/Boolean| public get(): R|kotlin/Boolean| { - STUB + return STUB } public set(value: R|kotlin/Boolean|): R|kotlin/Unit| { + return STUB } public final lateinit property fau(var): R|kotlin/Double| diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt index 45f9164f338..0ddf2b1259d 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt @@ -15,11 +15,11 @@ FILE: typeParameters.kt public constructor(): super|>() public final override function get(index: R|kotlin/Int|): R|kotlin/Int| { - STUB + return@@@get STUB } public final override function concat(other: R|List|): R|List| { - STUB + return@@@concat STUB } } diff --git a/compiler/fir/resolve/testData/resolve/functionTypes.txt b/compiler/fir/resolve/testData/resolve/functionTypes.txt index 9d140cad0eb..5603052cfac 100644 --- a/compiler/fir/resolve/testData/resolve/functionTypes.txt +++ b/compiler/fir/resolve/testData/resolve/functionTypes.txt @@ -1,11 +1,12 @@ FILE: functionTypes.kt public final function simpleRun(f: R|(T) -> kotlin/Unit|): R|kotlin/Unit| { - STUB + return@@@simpleRun STUB } public final function simpleMap R|kotlin/collections/List|.(f: R|(T) -> R|): R|R| { + return@@@simpleMap STUB } public final function simpleWith(t: R|T|, f: R|T.() -> kotlin/Unit|): R|kotlin/Unit| { - STUB + return@@@simpleWith STUB } public abstract interface KMutableProperty1 : R|KProperty1|, R|KMutableProperty| { } diff --git a/compiler/fir/resolve/testData/resolve/genericFunctions.txt b/compiler/fir/resolve/testData/resolve/genericFunctions.txt index 15712ca671d..9e25f2c20b0 100644 --- a/compiler/fir/resolve/testData/resolve/genericFunctions.txt +++ b/compiler/fir/resolve/testData/resolve/genericFunctions.txt @@ -2,7 +2,7 @@ FILE: genericFunctions.kt public abstract interface Any { } public final inline function safeAs R|Any|.(): R|T| { - STUB + return@@@safeAs STUB } public abstract class Summator { public constructor(): super() diff --git a/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt b/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt index d3493744dbb..540cca203bf 100644 --- a/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt +++ b/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt @@ -16,11 +16,12 @@ FILE: Annotations.kt public get(): R|kotlin/Char| public final override function foo(arg: R|kotlin/Double|): R|kotlin/Unit| { + return@@@foo STUB } public final override property v(val): R|kotlin/String| @R|annotations/Simple|() public get(): R|kotlin/String| { - STUB + return STUB } @R|annotations/WithString|(String(constructor)) public constructor(): this() diff --git a/compiler/fir/resolve/testData/resolve/simpleClass.txt b/compiler/fir/resolve/testData/resolve/simpleClass.txt index bbb5a939c7b..84a13e7e64d 100644 --- a/compiler/fir/resolve/testData/resolve/simpleClass.txt +++ b/compiler/fir/resolve/testData/resolve/simpleClass.txt @@ -13,13 +13,15 @@ FILE: simpleClass.kt private get(): R|error: Not supported: FirImplicitTypeImpl| public final override function foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String| { + return@@@foo STUB } public final override property bar(var): R|kotlin/Boolean| public get(): R|kotlin/Boolean| { - STUB + return STUB } public set(value: R|kotlin/Boolean|): R|kotlin/Unit| { + return STUB } public final property fau(var): R|kotlin/Double| diff --git a/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt b/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt index 56c76b72003..5f121b779a2 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt @@ -3,4 +3,5 @@ FILE: concurrent.kt public get(): R|kotlin/Int| public set(value: R|kotlin/Int|): R|kotlin/Unit| @R|kotlin/jvm/Synchronized|() public final function foo(): R|kotlin/Unit| { + return@@@foo STUB } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt b/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt index a07bf62009d..baea075697b 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt @@ -7,6 +7,7 @@ FILE: functionX.kt public constructor(): super() public final override function invoke(p1: R|kotlin/Int|, p2: R|kotlin/String|): R|kotlin/Unit| { + return@@@invoke STUB } } diff --git a/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt b/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt index 9f2587eb46f..520fefa426d 100644 --- a/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt +++ b/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt @@ -1,5 +1,5 @@ FILE: typeParameterInPropertyReceiver.kt public final property self R|T|.(val): R|T| public get(): R|T| { - STUB + return STUB } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt index ff809537aee..47b1d26e188 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt @@ -29,7 +29,7 @@ abstract class AbstractFirResolveTestCase : AbstractFirResolveWithSessionTestCas .uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project)) val session = createSession(scope) - val builder = RawFirBuilder(session) + val builder = RawFirBuilder(session, stubMode = true) val transformer = FirTotalResolveTransformer() return ktFiles.map { diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestTotalKotlin.kt b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestTotalKotlin.kt index bd7ebaba35a..8f83f279b57 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestTotalKotlin.kt +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestTotalKotlin.kt @@ -65,7 +65,7 @@ class FirResolveTestTotalKotlin : AbstractFirResolveWithSessionTestCase() { val scope = ProjectScope.getContentScope(project) val session = createSession(scope) - val builder = RawFirBuilder(session) + val builder = RawFirBuilder(session, stubMode = true) val totalTransformer = FirTotalResolveTransformer() val firFiles = ktFiles.map { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirAbstractElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirAbstractElement.kt new file mode 100644 index 00000000000..25efbc668a1 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirAbstractElement.kt @@ -0,0 +1,15 @@ +/* + * 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 + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression + +abstract class FirAbstractElement( + final override val session: FirSession, + final override val psi: PsiElement? +) : FirElement \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirAbstractTarget.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirAbstractTarget.kt new file mode 100644 index 00000000000..f45b9bdce1b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirAbstractTarget.kt @@ -0,0 +1,16 @@ +/* + * 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 + +abstract class FirAbstractTarget( + override val labelName: String? +) : FirTarget { + override lateinit var labeledElement: E + + override fun bind(element: E) { + labeledElement = element + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirFunctionTarget.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirFunctionTarget.kt new file mode 100644 index 00000000000..182a20496c7 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirFunctionTarget.kt @@ -0,0 +1,12 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.declarations.FirFunction + +class FirFunctionTarget( + labelName: String? +) : FirAbstractTarget(labelName) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLabel.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLabel.kt new file mode 100644 index 00000000000..39ba3e405e5 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLabel.kt @@ -0,0 +1,15 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirLabel : FirElement { + val name: String + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitLabel(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLabeledElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLabeledElement.kt new file mode 100644 index 00000000000..6a1f893fdfe --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLabeledElement.kt @@ -0,0 +1,21 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +// Target element which may have label +interface FirLabeledElement : FirTargetElement { + val label: FirLabel? get() = null + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitLabeledElement(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + label?.accept(visitor, data) + } + +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLoopTarget.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLoopTarget.kt new file mode 100644 index 00000000000..aedd233273d --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLoopTarget.kt @@ -0,0 +1,12 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.expressions.FirLoop + +class FirLoopTarget( + labelName: String? +) : FirAbstractTarget(labelName) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt new file mode 100644 index 00000000000..1a29ef7e308 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt @@ -0,0 +1,16 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.visitors.FirVisitor +import org.jetbrains.kotlin.name.Name + +interface FirNamedReference : FirReference { + val name: Name + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitNamedReference(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirReference.kt new file mode 100644 index 00000000000..04e6d707b87 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirReference.kt @@ -0,0 +1,13 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirReference : FirElement { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitReference(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index 6ffe6c83a96..e8d3ba76508 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.impl.* import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol @@ -141,7 +142,7 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { if (memberDeclaration is FirCallableMember && memberDeclaration.isOverride) { print("override ") } - if (memberDeclaration is FirClass) { + if (memberDeclaration is FirRegularClass) { if (memberDeclaration.isInner) { print("inner ") } @@ -193,35 +194,62 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { override fun visitDeclaration(declaration: FirDeclaration) { print( when (declaration) { - is FirClass -> declaration.classKind.name.toLowerCase().replace("_", " ") + is FirRegularClass -> declaration.classKind.name.toLowerCase().replace("_", " ") is FirTypeAlias -> "typealias" is FirNamedFunction -> "function" is FirProperty -> "property" + is FirVariable -> if (declaration.isVal) "val" else "var" else -> "unknown" } ) } override fun visitEnumEntry(enumEntry: FirEnumEntry) { - visitClass(enumEntry) + visitRegularClass(enumEntry) } - override fun visitClass(klass: FirClass) { - visitMemberDeclaration(klass) - if (klass.superTypes.isNotEmpty()) { - print(" : ") - klass.superTypes.renderSeparated() - } + private fun FirDeclarationContainer.renderDeclarations() { println(" {") pushIndent() - for (declaration in klass.declarations) { - declaration.accept(this) + for (declaration in declarations) { + declaration.accept(this@FirRenderer) println() } popIndent() println("}") } + override fun visitRegularClass(regularClass: FirRegularClass) { + visitMemberDeclaration(regularClass) + if (regularClass.superTypes.isNotEmpty()) { + print(" : ") + regularClass.superTypes.renderSeparated() + } + regularClass.renderDeclarations() + } + + override fun visitAnonymousObject(anonymousObject: FirAnonymousObject) { + anonymousObject.annotations.renderAnnotations() + print("object : ") + anonymousObject.superTypes.renderSeparated() + anonymousObject.renderDeclarations() + } + + override fun visitVariable(variable: FirVariable) { + variable.annotations.renderAnnotations() + visitNamedDeclaration(variable) + print(": ") + variable.returnType.accept(this) + variable.initializer?.let { + print(" = ") + it.accept(this) + } + variable.delegate?.let { + print("by ") + it.accept(this) + } + } + override fun visitProperty(property: FirProperty) { visitCallableMember(property) property.initializer?.let { @@ -276,6 +304,26 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { propertyAccessor.body?.accept(this) } + override fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction) { + anonymousFunction.annotations.renderAnnotations() + val label = anonymousFunction.label + if (label != null) { + print("${label.name}@") + } + print("function ") + val receiverType = anonymousFunction.receiverType + if (receiverType != null) { + print(" ") + receiverType.accept(this) + print(".") + } + print("") + anonymousFunction.valueParameters.renderParameters() + print(": ") + anonymousFunction.returnType.accept(this) + anonymousFunction.body?.accept(this) + } + override fun visitFunction(function: FirFunction) { function.valueParameters.renderParameters() visitDeclarationWithBody(function) @@ -291,10 +339,10 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { declarationWithBody.body?.accept(this) } - override fun visitBody(body: FirBody) { + override fun visitBlock(block: FirBlock) { println(" {") pushIndent() - for (statement in body.statements) { + for (statement in block.statements) { statement.accept(this) println() } @@ -348,10 +396,6 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { } } - override fun visitVariable(variable: FirVariable) { - visitDeclaration(variable) - } - override fun visitImport(import: FirImport) { visitElement(import) } @@ -360,11 +404,128 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { visitElement(statement) } + override fun visitReturnExpression(returnExpression: FirReturnExpression) { + returnExpression.annotations.renderAnnotations() + print("return") + val target = returnExpression.target + val labeledElement = target.labeledElement + if (labeledElement is FirNamedFunction) { + print("@@@${labeledElement.name}") + } else { + val labelName = target.labelName + if (labelName != null) { + if (labeledElement is FirAnonymousFunction) { + print("@@") + } + print("@$labelName") + } + } + print(" ") + returnExpression.result.accept(this) + } + + override fun visitWhenBranch(whenBranch: FirWhenBranch) { + val condition = whenBranch.condition + if (condition is FirElseIfTrueCondition) { + print("else") + } else { + condition.accept(this) + } + print(" -> ") + whenBranch.result.accept(this) + } + + override fun visitWhenExpression(whenExpression: FirWhenExpression) { + whenExpression.annotations.renderAnnotations() + print("when (") + val subjectVariable = whenExpression.subjectVariable + if (subjectVariable != null) { + subjectVariable.accept(this) + } else { + whenExpression.subject?.accept(this) + } + println(") {") + pushIndent() + for (branch in whenExpression.branches) { + branch.accept(this) + } + popIndent() + println("}") + } + + override fun visitTryExpression(tryExpression: FirTryExpression) { + tryExpression.annotations.renderAnnotations() + print("try") + tryExpression.tryBlock.accept(this) + for (catchClause in tryExpression.catches) { + print("catch (") + catchClause.parameter.accept(this) + print(")") + catchClause.block.accept(this) + } + val finallyBlock = tryExpression.finallyBlock ?: return + print("finally") + finallyBlock.accept(this) + } + + override fun visitDoWhileLoop(doWhileLoop: FirDoWhileLoop) { + val label = doWhileLoop.label + if (label != null) { + print("${label.name}@") + } + print("do") + doWhileLoop.block.accept(this) + print("while(") + doWhileLoop.condition.accept(this) + print(")") + } + + override fun visitWhileLoop(whileLoop: FirWhileLoop) { + val label = whileLoop.label + if (label != null) { + print("${label.name}@") + } + print("while(") + whileLoop.condition.accept(this) + print(")") + whileLoop.block.accept(this) + } + + private fun visitLoopJump(jump: FirJump) { + val target = jump.target + val labeledElement = target.labeledElement + print("@@@[") + labeledElement.condition.accept(this) + print("] ") + } + + override fun visitBreakExpression(breakExpression: FirBreakExpression) { + breakExpression.annotations.renderAnnotations() + print("break") + visitLoopJump(breakExpression) + } + + override fun visitContinueExpression(continueExpression: FirContinueExpression) { + continueExpression.annotations.renderAnnotations() + print("continue") + visitLoopJump(continueExpression) + } + override fun visitExpression(expression: FirExpression) { - print("STUB") + expression.annotations.renderAnnotations() + print( + when (expression) { + is FirExpressionStub -> "STUB" + is FirUnitExpression -> "Unit" + is FirWhenSubjectExpression -> "\$subj\$" + is FirElseIfTrueCondition -> "else" + else -> "??? ${expression.javaClass}" + } + ) } override fun visitConstExpression(constExpression: FirConstExpression) { + constExpression.annotations.renderAnnotations() print("${constExpression.kind}(${constExpression.value})") } @@ -406,7 +567,7 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { } override fun visitDelegatedType(delegatedType: FirDelegatedType) { - delegatedType.accept(this) + delegatedType.type.accept(this) print(" by ") delegatedType.delegate?.accept(this) } @@ -460,7 +621,7 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { val sb = StringBuilder() sb.append(symbol.classId.asString()) if (typeArguments.isNotEmpty()) { - sb.append(typeArguments.joinToString(prefix = "<", postfix = ">") { it -> + sb.append(typeArguments.joinToString(prefix = "<", postfix = ">") { when (it) { StarProjection -> "*" is ConeKotlinTypeProjectionIn -> "in ${it.type.asString()}" @@ -530,4 +691,130 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { print("*") } + override fun visitNamedReference(namedReference: FirNamedReference) { + print("${namedReference.name}#") + } + + override fun visitThisReference(thisReference: FirThisReference) { + print("this") + val labelName = thisReference.labelName + if (labelName != null) { + print("@$labelName") + } else { + print("#") + } + } + + override fun visitSuperReference(superReference: FirSuperReference) { + print("super<") + superReference.superType.accept(this) + print(">") + } + + override fun visitAccess(access: FirAccess) { + val explicitReceiver = access.explicitReceiver + if (explicitReceiver != null) { + explicitReceiver.accept(this) + if (access.safe) { + print("?.") + } else { + print(".") + } + } + } + + override fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess) { + callableReferenceAccess.annotations.renderAnnotations() + callableReferenceAccess.explicitReceiver?.accept(this) + print("::") + callableReferenceAccess.calleeReference.accept(this) + } + + override fun visitAccessExpression(accessExpression: FirAccessExpression) { + accessExpression.annotations.renderAnnotations() + visitAccess(accessExpression) + accessExpression.calleeReference.accept(this) + } + + override fun visitAssignment(assignment: FirAssignment) { + print(assignment.operation.operator) + print(" ") + assignment.value.accept(this) + } + + override fun visitPropertyAssignment(propertyAssignment: FirPropertyAssignment) { + propertyAssignment.annotations.renderAnnotations() + visitAccess(propertyAssignment) + propertyAssignment.calleeReference.accept(this) + print(" ") + visitAssignment(propertyAssignment) + } + + override fun visitArraySetCall(arraySetCall: FirArraySetCall) { + arraySetCall.annotations.renderAnnotations() + visitAccess(arraySetCall) + arraySetCall.calleeReference.accept(this) + print("[") + arraySetCall.arguments.renderSeparated() + print("] ") + visitAssignment(arraySetCall) + } + + override fun visitFunctionCall(functionCall: FirFunctionCall) { + functionCall.annotations.renderAnnotations() + visitAccess(functionCall) + functionCall.calleeReference.accept(this) + if (functionCall.typeArguments.isNotEmpty()) { + print("<") + functionCall.typeArguments.renderSeparated() + print(">") + } + visitCall(functionCall) + } + + override fun visitOperatorCall(operatorCall: FirOperatorCall) { + operatorCall.annotations.renderAnnotations() + print(operatorCall.operation.operator) + if (operatorCall is FirTypeOperatorCall) { + print("/") + operatorCall.type.accept(this) + } + visitCall(operatorCall) + } + + override fun visitArrayGetCall(arrayGetCall: FirArrayGetCall) { + arrayGetCall.annotations.renderAnnotations() + arrayGetCall.array.accept(this) + print("[") + arrayGetCall.arguments.renderSeparated() + print("]") + } + + override fun visitComponentCall(componentCall: FirComponentCall) { + componentCall.annotations.renderAnnotations() + print("component${componentCall.componentIndex}") + visitCall(componentCall) + } + + override fun visitGetClassCall(getClassCall: FirGetClassCall) { + getClassCall.annotations.renderAnnotations() + print("") + visitCall(getClassCall) + } + + override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall) { + arrayOfCall.annotations.renderAnnotations() + print("") + visitCall(arrayOfCall) + } + + override fun visitThrowExpression(throwExpression: FirThrowExpression) { + throwExpression.annotations.renderAnnotations() + print("throw ") + throwExpression.exception.accept(this) + } + + override fun visitErrorExpression(errorExpression: FirErrorExpression) { + print("ERROR_EXPR(${errorExpression.reason})") + } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSuperReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSuperReference.kt new file mode 100644 index 00000000000..2d97a6945db --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSuperReference.kt @@ -0,0 +1,20 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirSuperReference : FirReference { + val superType: FirType + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitSuperReference(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + superType.accept(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirTarget.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirTarget.kt new file mode 100644 index 00000000000..eb87a437655 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirTarget.kt @@ -0,0 +1,15 @@ +/* + * 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 + +// Reference to some label +interface FirTarget { + val labelName: String? + + val labeledElement: E + + fun bind(element: E) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirTargetElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirTargetElement.kt new file mode 100644 index 00000000000..e55987a2d2e --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirTargetElement.kt @@ -0,0 +1,9 @@ +/* + * 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 + +// Any target of return / break / continue (some targets may have labels, some never have them) +interface FirTargetElement : FirElement \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirThisReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirThisReference.kt new file mode 100644 index 00000000000..05ad9b0e283 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirThisReference.kt @@ -0,0 +1,15 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirThisReference : FirReference { + val labelName: String? + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitThisReference(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirAnonymousFunction.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirAnonymousFunction.kt new file mode 100644 index 00000000000..a2b12ea617b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirAnonymousFunction.kt @@ -0,0 +1,30 @@ +/* + * 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.declarations + +import org.jetbrains.kotlin.fir.FirLabeledElement +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirAnonymousFunction : @VisitedSupertype FirFunction, FirExpression, FirTypedDeclaration, FirLabeledElement { + val receiverType: FirType? + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitAnonymousFunction(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + super.acceptChildren(visitor, data) + super.acceptChildren(visitor, data) + receiverType?.accept(visitor, data) + for (parameter in valueParameters) { + parameter.accept(visitor, data) + } + body?.accept(visitor, data) + // Don't call super.acceptChildren (annotations are already processed) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt new file mode 100644 index 00000000000..21c2f88f07a --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt @@ -0,0 +1,24 @@ +/* + * 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.declarations + +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirAnonymousObject : @VisitedSupertype FirClass, FirExpression { + override val classKind: ClassKind + get() = ClassKind.OBJECT + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitAnonymousObject(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + super.acceptChildren(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirClass.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirClass.kt index ed1ef422e75..0f70e9e2bcb 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirClass.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirClass.kt @@ -1,41 +1,26 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * 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.declarations import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.fir.BaseTransformedType -import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner -import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol +import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer +import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.visitors.FirVisitor -// May be all containers should be properties and not base classes -// About descriptors: introduce something like FirDescriptor which is FirUnresolved at the beginning and FirSymbol(descriptor) at the end -@BaseTransformedType -interface FirClass : FirDeclarationContainer, FirMemberDeclaration, FirSymbolOwner { +interface FirClass : FirDeclarationContainer, FirStatement, FirAnnotationContainer { // including delegated types val superTypes: List val classKind: ClassKind - val isInner: Boolean get() = status.isInner - - val isCompanion: Boolean get() = status.isCompanion - - val isData: Boolean get() = status.isData - - val isInline: Boolean get() = status.isInline - - override val symbol: FirClassSymbol - override fun accept(visitor: FirVisitor, data: D): R = visitor.visitClass(this, data) override fun acceptChildren(visitor: FirVisitor, data: D) { - super.acceptChildren(visitor, data) for (superType in superTypes) { superType.accept(visitor, data) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationWithBody.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationWithBody.kt index 695a068c638..9d6f99802c2 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationWithBody.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationWithBody.kt @@ -5,11 +5,11 @@ package org.jetbrains.kotlin.fir.declarations -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.visitors.FirVisitor interface FirDeclarationWithBody : FirDeclaration { - val body: FirBody? + val body: FirBlock? override fun accept(visitor: FirVisitor, data: D): R = visitor.visitDeclarationWithBody(this, data) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirEnumEntry.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirEnumEntry.kt index 5c201693376..298be249bca 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirEnumEntry.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirEnumEntry.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.expressions.FirCall import org.jetbrains.kotlin.fir.visitors.FirVisitor @BaseTransformedType -interface FirEnumEntry : @VisitedSupertype FirClass, FirCall { +interface FirEnumEntry : @VisitedSupertype FirRegularClass, FirCall { override fun accept(visitor: FirVisitor, data: D): R = visitor.visitEnumEntry(this, data) @@ -19,6 +19,6 @@ interface FirEnumEntry : @VisitedSupertype FirClass, FirCall { for (argument in arguments) { argument.accept(visitor, data) } - super.acceptChildren(visitor, data) + super.acceptChildren(visitor, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirErrorDeclaration.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirErrorDeclaration.kt index 4148fa13064..4422981c69f 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirErrorDeclaration.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirErrorDeclaration.kt @@ -9,6 +9,8 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitor // Is it necessary? interface FirErrorDeclaration : FirDeclaration { + val reason: String + override fun accept(visitor: FirVisitor, data: D): R = visitor.visitErrorDeclaration(this, data) } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirFunction.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirFunction.kt index e98fa19b916..4a08c3313f3 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirFunction.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirFunction.kt @@ -5,11 +5,14 @@ package org.jetbrains.kotlin.fir.declarations +import org.jetbrains.kotlin.fir.FirTargetElement +import org.jetbrains.kotlin.fir.VisitedSupertype import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer +import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.visitors.FirVisitor // May be should inherit FirTypeParameterContainer -interface FirFunction : FirDeclarationWithBody, FirAnnotationContainer { +interface FirFunction : @VisitedSupertype FirDeclarationWithBody, FirAnnotationContainer, FirTargetElement, FirStatement { val valueParameters: List override fun accept(visitor: FirVisitor, data: D): R = @@ -20,6 +23,6 @@ interface FirFunction : FirDeclarationWithBody, FirAnnotationContainer { for (parameter in valueParameters) { parameter.accept(visitor, data) } - super.acceptChildren(visitor, data) + super.acceptChildren(visitor, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirProperty.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirProperty.kt index 0713f7ce7e9..e364092b753 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirProperty.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirProperty.kt @@ -23,8 +23,6 @@ interface FirProperty : @VisitedSupertype FirDeclaration, FirCallableMember, Fir val setter: FirPropertyAccessor - val delegate: FirExpression? - override fun accept(visitor: FirVisitor, data: D): R = visitor.visitProperty(this, data) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt new file mode 100644 index 00000000000..3dd6682163b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2018 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.declarations + +import org.jetbrains.kotlin.fir.BaseTransformedType +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner +import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +// May be all containers should be properties and not base classes +// About descriptors: introduce something like FirDescriptor which is FirUnresolved at the beginning and FirSymbol(descriptor) at the end +@BaseTransformedType +interface FirRegularClass : FirClass, @VisitedSupertype FirMemberDeclaration, FirSymbolOwner { + val isInner: Boolean get() = status.isInner + + val isCompanion: Boolean get() = status.isCompanion + + val isData: Boolean get() = status.isData + + val isInline: Boolean get() = status.isInline + + override val symbol: FirClassSymbol + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitRegularClass(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + super.acceptChildren(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractAnnotatedDeclaration.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractAnnotatedDeclaration.kt index 4578c66387f..a6e6f48097b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractAnnotatedDeclaration.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractAnnotatedDeclaration.kt @@ -8,12 +8,9 @@ package org.jetbrains.kotlin.fir.declarations.impl import com.intellij.psi.PsiElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirDeclaration -import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall -import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer +import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement abstract class FirAbstractAnnotatedDeclaration( - final override val session: FirSession, - final override val psi: PsiElement? -) : FirAnnotationContainer, FirDeclaration { - final override val annotations = mutableListOf() -} \ No newline at end of file + session: FirSession, + psi: PsiElement? +) : FirAbstractAnnotatedElement(session, psi), FirDeclaration \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractFunction.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractFunction.kt index a00d4979446..4428acaf5cd 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractFunction.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractFunction.kt @@ -10,21 +10,23 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.declarations.FirValueParameter -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.visitors.FirTransformer abstract class FirAbstractFunction( session: FirSession, - psi: PsiElement?, - final override val body: FirBody? + psi: PsiElement? ) : FirAbstractAnnotatedDeclaration(session, psi), FirFunction { final override val valueParameters = mutableListOf() - override fun transformChildren(transformer: FirTransformer, data: D): FirElement { - annotations.transformInplace(transformer, data) - valueParameters.transformInplace(transformer, data) + final override var body: FirBlock? = null - return this + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + valueParameters.transformInplace(transformer, data) + body = body?.transformSingle(transformer, data) + + return super.transformChildren(transformer, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractNamedAnnotatedDeclaration.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractNamedAnnotatedDeclaration.kt index a29ad8bea5a..fd5c359a1b3 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractNamedAnnotatedDeclaration.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractNamedAnnotatedDeclaration.kt @@ -6,21 +6,12 @@ package org.jetbrains.kotlin.fir.declarations.impl import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration -import org.jetbrains.kotlin.fir.transformInplace -import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.name.Name abstract class FirAbstractNamedAnnotatedDeclaration( session: FirSession, psi: PsiElement?, final override val name: Name -) : FirAbstractAnnotatedDeclaration(session, psi), FirNamedDeclaration { - override fun transformChildren(transformer: FirTransformer, data: D): FirElement { - annotations.transformInplace(transformer, data) - - return this - } -} \ No newline at end of file +) : FirAbstractAnnotatedDeclaration(session, psi), FirNamedDeclaration \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt new file mode 100644 index 00000000000..55ad10dc9de --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt @@ -0,0 +1,31 @@ +/* + * 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.declarations.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirLabel +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirAnonymousFunctionImpl( + session: FirSession, + psi: PsiElement?, + override var returnType: FirType, + override var receiverType: FirType? +) : FirAbstractFunction(session, psi), FirAnonymousFunction, FirModifiableFunction { + override var label: FirLabel? = null + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + returnType = returnType.transformSingle(transformer, data) + receiverType = receiverType?.transformSingle(transformer, data) + label = label?.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt index 812e10e98b0..bdd4d92d5b9 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt @@ -6,12 +6,20 @@ package org.jetbrains.kotlin.fir.declarations.impl import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirAnonymousInitializer -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer class FirAnonymousInitializerImpl( override val session: FirSession, override val psi: PsiElement?, - override val body: FirBody? -) : FirAnonymousInitializer \ No newline at end of file + override var body: FirBlock? +) : FirAnonymousInitializer { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + body = body?.transformSingle(transformer, data) + return this + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt new file mode 100644 index 00000000000..3939d652769 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt @@ -0,0 +1,36 @@ +/* + * 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.declarations.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirTransformer +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +class FirAnonymousObjectImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractAnnotatedDeclaration(session, psi), FirAnonymousObject, FirModifiableClass { + override val superTypes = mutableListOf() + + override val declarations = mutableListOf() + + override fun accept(visitor: FirVisitor, data: D): R { + return super.accept(visitor, data) + } + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + superTypes.transformInplace(transformer, data) + declarations.transformInplace(transformer, data) + + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirClassImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirClassImpl.kt index f7e7b70e35a..15b3cc1a471 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirClassImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirClassImpl.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirClass +import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.transformInplace @@ -32,7 +32,7 @@ open class FirClassImpl( isCompanion: Boolean, isData: Boolean, isInline: Boolean -) : FirAbstractMemberDeclaration(session, psi, name, visibility, modality, isExpect, isActual), FirClass { +) : FirAbstractMemberDeclaration(session, psi, name, visibility, modality, isExpect, isActual), FirRegularClass, FirModifiableClass { init { symbol.bind(this) @@ -47,9 +47,9 @@ open class FirClassImpl( override val declarations = mutableListOf() - override fun transformChildren(transformer: FirTransformer, data: D): FirClass { + override fun transformChildren(transformer: FirTransformer, data: D): FirRegularClass { superTypes.transformInplace(transformer, data) - val result = super.transformChildren(transformer, data) as FirClass + val result = super.transformChildren(transformer, data) as FirRegularClass // Transform declarations in last turn declarations.transformInplace(transformer, data) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt index 2f6b53ee76a..77a390b717a 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirValueParameter -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.transformInplace import org.jetbrains.kotlin.fir.transformSingle @@ -27,17 +27,19 @@ open class FirConstructorImpl( isExpect: Boolean, isActual: Boolean, delegatedSelfType: FirType, - final override var delegatedConstructor: FirDelegatedConstructorCall?, - override val body: FirBody? + final override var delegatedConstructor: FirDelegatedConstructorCall? ) : FirAbstractCallableMember( session, psi, NAME, visibility, Modality.FINAL, isExpect, isActual, isOverride = false, receiverType = null, returnType = delegatedSelfType ), FirConstructor { override val valueParameters = mutableListOf() + override var body: FirBlock? = null + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { valueParameters.transformInplace(transformer, data) delegatedConstructor?.transformSingle(transformer, data) + body = body?.transformSingle(transformer, data) return super.transformChildren(transformer, data) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt index bdfc3cb67af..4c46b1d4c66 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt @@ -7,14 +7,13 @@ package org.jetbrains.kotlin.fir.declarations.impl 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.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.transformInplace import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType @@ -31,7 +30,7 @@ abstract class FirDefaultPropertyAccessor( session, visibility, Modality.FINAL ) - final override val body: FirBody? = + final override val body: FirBlock? = null final override val annotations: List diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunction.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunction.kt new file mode 100644 index 00000000000..98d0e0c4dfb --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunction.kt @@ -0,0 +1,34 @@ +/* + * 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.declarations.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirErrorDeclaration +import org.jetbrains.kotlin.fir.declarations.FirFunction +import org.jetbrains.kotlin.fir.declarations.FirValueParameter +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +class FirErrorFunction( + session: FirSession, + psi: PsiElement?, + override val reason: String +) : FirAbstractElement(session, psi), FirErrorDeclaration, FirFunction { + override val annotations: List + get() = emptyList() + + override val valueParameters: List + get() = emptyList() + + override val body: FirBlock? + get() = null + + override fun accept(visitor: FirVisitor, data: D): R = + super.accept(visitor, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirErrorLoop.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirErrorLoop.kt new file mode 100644 index 00000000000..41472f24008 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirErrorLoop.kt @@ -0,0 +1,34 @@ +/* + * 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.declarations.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyExpressionBlock +import org.jetbrains.kotlin.fir.expressions.impl.FirErrorExpressionImpl +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +class FirErrorLoop( + session: FirSession, + psi: PsiElement?, + override val reason: String +) : FirAbstractElement(session, psi), FirErrorExpression, FirLoop { + override val annotations: List = listOf() + + override val condition: FirExpression = FirErrorExpressionImpl(session, psi, reason) + + override val block: FirBlock = FirEmptyExpressionBlock(session) + + override fun accept(visitor: FirVisitor, data: D): R { + return super.accept(visitor, data) + } + + override fun acceptChildren(visitor: FirVisitor, data: D) { + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt index ec95bb8acfa..ce867d49f70 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt @@ -26,9 +26,8 @@ class FirFileImpl( override val declarations = mutableListOf() override fun transformChildren(transformer: FirTransformer, data: D): FirElement { - annotations.transformInplace(transformer, data) imports.transformInplace(transformer, data) declarations.transformInplace(transformer, data) - return this + return super.transformChildren(transformer, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt index 5a27df2b96b..7364178e680 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt @@ -12,8 +12,9 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirNamedFunction import org.jetbrains.kotlin.fir.declarations.FirValueParameter -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.name.Name @@ -34,12 +35,11 @@ class FirMemberFunctionImpl( isExternal: Boolean, isSuspend: Boolean, receiverType: FirType?, - returnType: FirType, - override val body: FirBody? + returnType: FirType ) : FirAbstractCallableMember( session, psi, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType -), FirNamedFunction { +), FirNamedFunction, FirModifiableFunction { init { status.isOperator = isOperator status.isInfix = isInfix @@ -51,8 +51,11 @@ class FirMemberFunctionImpl( override val valueParameters = mutableListOf() + override var body: FirBlock? = null + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { valueParameters.transformInplace(transformer, data) + body = body?.transformSingle(transformer, data) return super.transformChildren(transformer, data) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt index 444f063d98a..8c66709fdb2 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt @@ -32,10 +32,10 @@ class FirMemberPropertyImpl( receiverType: FirType?, returnType: FirType, override val isVar: Boolean, - override val initializer: FirExpression?, + override var initializer: FirExpression?, override var getter: FirPropertyAccessor, override var setter: FirPropertyAccessor, - override val delegate: FirExpression? + override var delegate: FirExpression? ) : FirAbstractCallableMember( session, psi, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType ), FirProperty { @@ -47,6 +47,8 @@ class FirMemberPropertyImpl( override fun transformChildren(transformer: FirTransformer, data: D): FirElement { getter = getter.transformSingle(transformer, data) setter = setter.transformSingle(transformer, data) + initializer = initializer?.transformSingle(transformer, data) + delegate = delegate?.transformSingle(transformer, data) return super.transformChildren(transformer, data) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirModifiableClass.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirModifiableClass.kt new file mode 100644 index 00000000000..1547642f07c --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirModifiableClass.kt @@ -0,0 +1,16 @@ +/* + * 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.declarations.impl + +import org.jetbrains.kotlin.fir.declarations.FirClass +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.types.FirType + +interface FirModifiableClass : FirClass { + override val superTypes: MutableList + + override val declarations: MutableList +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirModifiableFunction.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirModifiableFunction.kt new file mode 100644 index 00000000000..83671de475d --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirModifiableFunction.kt @@ -0,0 +1,16 @@ +/* + * 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.declarations.impl + +import org.jetbrains.kotlin.fir.declarations.FirFunction +import org.jetbrains.kotlin.fir.declarations.FirValueParameter +import org.jetbrains.kotlin.fir.expressions.FirBlock + +interface FirModifiableFunction : FirFunction { + override var body: FirBlock? + + override val valueParameters: MutableList +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt index 44ad539706d..892d95c4909 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt @@ -19,4 +19,4 @@ class FirPrimaryConstructorImpl( isActual: Boolean, delegatedSelfType: FirType, delegatedConstructor: FirDelegatedConstructorCall? -) : FirConstructorImpl(session, psi, visibility, isExpect, isActual, delegatedSelfType, delegatedConstructor, body = null) \ No newline at end of file +) : FirConstructorImpl(session, psi, visibility, isExpect, isActual, delegatedSelfType, delegatedConstructor) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt index 2b23f551b49..59be652e263 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor -import org.jetbrains.kotlin.fir.expressions.FirBody +import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.visitors.FirTransformer @@ -21,9 +21,8 @@ class FirPropertyAccessorImpl( psi: PsiElement?, override val isGetter: Boolean, visibility: Visibility, - override var returnType: FirType, - body: FirBody? -) : FirAbstractFunction(session, psi, body), FirPropertyAccessor { + override var returnType: FirType +) : FirAbstractFunction(session, psi), FirPropertyAccessor { override var status = FirDeclarationStatusImpl( session, visibility, Modality.FINAL ) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt index 3470c6bd01f..5ab08283187 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt @@ -20,13 +20,14 @@ class FirValueParameterImpl( psi: PsiElement?, name: Name, override var returnType: FirType, - override val defaultValue: FirExpression?, + override var defaultValue: FirExpression?, override val isCrossinline: Boolean, override val isNoinline: Boolean, override val isVararg: Boolean ) : FirAbstractNamedAnnotatedDeclaration(session, psi, name), FirValueParameter { override fun transformChildren(transformer: FirTransformer, data: D): FirElement { returnType = returnType.transformSingle(transformer, data) + defaultValue = defaultValue?.transformSingle(transformer, data) return super.transformChildren(transformer, data) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirVariableImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirVariableImpl.kt new file mode 100644 index 00000000000..293bbf8c618 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirVariableImpl.kt @@ -0,0 +1,34 @@ +/* + * 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.declarations.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirVariable +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirTransformer +import org.jetbrains.kotlin.name.Name + +class FirVariableImpl( + session: FirSession, + psiElement: PsiElement?, + name: Name, + override var returnType: FirType, + override val isVar: Boolean, + override var initializer: FirExpression?, + override var delegate: FirExpression? = null +) : FirAbstractNamedAnnotatedDeclaration(session, psiElement, name), FirVariable { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + returnType = returnType.transformSingle(transformer, data) + initializer = initializer?.transformSingle(transformer, data) + delegate = delegate?.transformSingle(transformer, data) + + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAccess.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAccess.kt new file mode 100644 index 00000000000..1ba5b3ceae2 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAccess.kt @@ -0,0 +1,26 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.FirReference +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirAccess : FirStatement { + val calleeReference: FirReference + + val safe: Boolean get() = false + + val explicitReceiver: FirExpression? get() = null + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitAccess(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + calleeReference.accept(visitor, data) + explicitReceiver?.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAccessExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAccessExpression.kt new file mode 100644 index 00000000000..e80b5273718 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAccessExpression.kt @@ -0,0 +1,18 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirAccessExpression : @VisitedSupertype FirAccess, FirExpression { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitAccessExpression(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArrayGetCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArrayGetCall.kt new file mode 100644 index 00000000000..caeaefd5347 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArrayGetCall.kt @@ -0,0 +1,20 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirArrayGetCall : FirCall { + val array: FirExpression + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitArrayGetCall(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + array.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArrayOfCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArrayOfCall.kt new file mode 100644 index 00000000000..19dcca8617c --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArrayOfCall.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirArrayOfCall : FirCall { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitArrayOfCall(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArraySetCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArraySetCall.kt new file mode 100644 index 00000000000..4866a7ddd4d --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirArraySetCall.kt @@ -0,0 +1,19 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirArraySetCall : @VisitedSupertype FirCall, FirAssignment { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitArraySetCall(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + super.acceptChildren(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAssignment.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAssignment.kt new file mode 100644 index 00000000000..4b307460ce0 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirAssignment.kt @@ -0,0 +1,22 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirAssignment : FirAccess { + val value: FirExpression + + val operation: FirOperation + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitAssignment(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + value.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBody.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBlock.kt similarity index 77% rename from compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBody.kt rename to compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBlock.kt index 4e19fb8997b..576d00572d9 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBody.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBlock.kt @@ -7,13 +7,11 @@ package org.jetbrains.kotlin.fir.expressions import org.jetbrains.kotlin.fir.visitors.FirVisitor -// Should we have FirBlockBody / FirExpressionBody? -// Is it FirExpression or just FirElement? -interface FirBody : FirExpression { +interface FirBlock : FirExpression { val statements: List override fun accept(visitor: FirVisitor, data: D): R = - visitor.visitBody(this, data) + visitor.visitBlock(this, data) override fun acceptChildren(visitor: FirVisitor, data: D) { for (statement in statements) { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBreakExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBreakExpression.kt new file mode 100644 index 00000000000..26892f9bb18 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirBreakExpression.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirBreakExpression : FirJump { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitBreakExpression(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirCallableReferenceAccess.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirCallableReferenceAccess.kt new file mode 100644 index 00000000000..11e7a7d7c6b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirCallableReferenceAccess.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirCallableReferenceAccess : FirAccessExpression { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitCallableReferenceAccess(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirCatch.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirCatch.kt new file mode 100644 index 00000000000..3bc791fe038 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirCatch.kt @@ -0,0 +1,24 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.declarations.FirValueParameter +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirCatch : FirElement { + val parameter: FirValueParameter + + val block: FirBlock + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitCatch(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + parameter.accept(visitor, data) + block.accept(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirComponentCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirComponentCall.kt new file mode 100644 index 00000000000..26c338f3e2e --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirComponentCall.kt @@ -0,0 +1,16 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirComponentCall : FirCall { + // Starting from 1, not from 0 + val componentIndex: Int + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitComponentCall(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirContinueExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirContinueExpression.kt new file mode 100644 index 00000000000..b3202081c38 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirContinueExpression.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirContinueExpression : FirJump { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitContinueExpression(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirDoWhileLoop.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirDoWhileLoop.kt new file mode 100644 index 00000000000..b7b7dee186a --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirDoWhileLoop.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirDoWhileLoop : FirLoop { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitDoWhileLoop(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt index d0d3fbecf20..ee4bbbfc3aa 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt @@ -5,6 +5,12 @@ package org.jetbrains.kotlin.fir.expressions +import org.jetbrains.kotlin.fir.visitors.FirVisitor + interface FirErrorExpression : FirExpression { val reason: String + + override fun accept(visitor: FirVisitor, data: D): R { + return visitor.visitErrorExpression(this, data) + } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirFunctionCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirFunctionCall.kt new file mode 100644 index 00000000000..84918761c1a --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirFunctionCall.kt @@ -0,0 +1,28 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.FirNamedReference +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.types.FirTypeProjectionContainer +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirFunctionCall : @VisitedSupertype FirCall, FirAccess, FirTypeProjectionContainer { + override val calleeReference: FirNamedReference + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitFunctionCall(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + for (argument in arguments) { + argument.accept(visitor, data) + } + for (typeArgument in typeArguments) { + typeArgument.accept(visitor, data) + } + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirGetClassCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirGetClassCall.kt new file mode 100644 index 00000000000..31a9dc8cf17 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirGetClassCall.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirGetClassCall : FirCall { + val argument: FirExpression get() = arguments.first() + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitGetClassCall(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirJump.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirJump.kt new file mode 100644 index 00000000000..9104bea0ca4 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirJump.kt @@ -0,0 +1,17 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.FirTarget +import org.jetbrains.kotlin.fir.FirTargetElement +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirJump : FirExpression { + val target: FirTarget + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitJump(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirLoop.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirLoop.kt new file mode 100644 index 00000000000..5ed5065a616 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirLoop.kt @@ -0,0 +1,25 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.FirLabeledElement +import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirLoop : @VisitedSupertype FirStatement, FirLabeledElement, FirAnnotationContainer { + val condition: FirExpression + + val block: FirBlock + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitLoop(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + condition.accept(visitor, data) + block.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirOperation.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirOperation.kt new file mode 100644 index 00000000000..c7ccde07ba1 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirOperation.kt @@ -0,0 +1,44 @@ +/* + * 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.expressions + +enum class FirOperation(val operator: String = "???") { + // Binary + RANGE(".."), + EQ("=="), + NOT_EQ("!="), + IDENTITY("==="), + NOT_IDENTITY("!=="), + LT("<"), + GT(">"), + LT_EQ("<="), + GT_EQ(">="), + AND("&&"), + OR("||"), + IN("in"), + NOT_IN("!in"), + + ASSIGN("="), + PLUS_ASSIGN("+="), + MINUS_ASSIGN("-="), + TIMES_ASSIGN("*="), + DIV_ASSIGN("/="), + REM_ASSIGN("%="), + + // Unary + EXCL("!"), + // Type + IS("is"), + NOT_IS("!is"), + AS("as"), + SAFE_AS("as?"), + // All non-standard operations (infix calls) + OTHER; + + companion object { + val ASSIGNMENTS = setOf(ASSIGN, PLUS_ASSIGN, MINUS_ASSIGN, TIMES_ASSIGN, DIV_ASSIGN, REM_ASSIGN) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirOperatorCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirOperatorCall.kt new file mode 100644 index 00000000000..9b1ac5788c7 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirOperatorCall.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirOperatorCall : FirCall { + val operation: FirOperation + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitOperatorCall(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirPropertyAssignment.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirPropertyAssignment.kt new file mode 100644 index 00000000000..1ce69b6d035 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirPropertyAssignment.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirPropertyAssignment : FirAssignment { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitPropertyAssignment(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirReturnExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirReturnExpression.kt new file mode 100644 index 00000000000..0eb619944d7 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirReturnExpression.kt @@ -0,0 +1,21 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.declarations.FirFunction +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirReturnExpression : FirJump { + val result: FirExpression + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitReturnExpression(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + result.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirStatement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirStatement.kt index 94403f4821f..7047d44bf36 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirStatement.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirStatement.kt @@ -10,7 +10,11 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.visitors.FirVisitor @BaseTransformedType -interface FirStatement : FirElement { +interface FirStatement : FirElement, FirAnnotationContainer { override fun accept(visitor: FirVisitor, data: D): R = visitor.visitStatement(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + acceptAnnotations(visitor, data) + } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirThrowExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirThrowExpression.kt new file mode 100644 index 00000000000..77f0600fd60 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirThrowExpression.kt @@ -0,0 +1,20 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirThrowExpression : FirExpression { + val exception: FirExpression + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitThrowExpression(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + exception.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirTryExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirTryExpression.kt new file mode 100644 index 00000000000..c6bd367d181 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirTryExpression.kt @@ -0,0 +1,26 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirTryExpression : FirExpression { + val tryBlock: FirBlock + + val catches: List + + val finallyBlock: FirBlock? + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitTryExpression(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + tryBlock.accept(visitor, data) + catches.forEach { it.accept(visitor, data) } + finallyBlock?.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirTypeOperatorCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirTypeOperatorCall.kt new file mode 100644 index 00000000000..203254a81e9 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirTypeOperatorCall.kt @@ -0,0 +1,24 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +// is/!is/as/as? +interface FirTypeOperatorCall : FirOperatorCall { + val argument: FirExpression get() = arguments.first() + + val type: FirType + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitTypeOperatorCall(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + type.accept(visitor, data) + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirVariable.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirVariable.kt index 7eba36870cb..831869a4c1b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirVariable.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirVariable.kt @@ -19,11 +19,14 @@ interface FirVariable : @VisitedSupertype FirDeclaration, FirTypedDeclaration, F val initializer: FirExpression? + val delegate: FirExpression? + override fun accept(visitor: FirVisitor, data: D): R = visitor.visitVariable(this, data) override fun acceptChildren(visitor: FirVisitor, data: D) { initializer?.accept(visitor, data) + delegate?.accept(visitor, data) super.acceptChildren(visitor, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhenBranch.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhenBranch.kt new file mode 100644 index 00000000000..86f325f4b59 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhenBranch.kt @@ -0,0 +1,27 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirWhenBranch : FirElement { + // NB: we can represent subject, if it's inside, as a special kind of expression + // when (mySubject) { + // $subj == 42$ -> doSmth() + // } + val condition: FirExpression + + val result: FirBlock + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitWhenBranch(this, data) + + override fun acceptChildren(visitor: FirVisitor, data: D) { + condition.accept(visitor, data) + result.accept(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhenExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhenExpression.kt new file mode 100644 index 00000000000..6d4d33f48e9 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhenExpression.kt @@ -0,0 +1,29 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirWhenExpression : FirExpression { + val subject: FirExpression? + + // when (val subjectVariable = subject()) { ... } + val subjectVariable: FirVariable? + + val branches: List + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitWhenExpression(this, data) + + + override fun acceptChildren(visitor: FirVisitor, data: D) { + subjectVariable?.accept(visitor, data) ?: subject?.accept(visitor, data) + for (branch in branches) { + branch.accept(visitor, data) + } + super.acceptChildren(visitor, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhileLoop.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhileLoop.kt new file mode 100644 index 00000000000..8b4aaceddfc --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirWhileLoop.kt @@ -0,0 +1,13 @@ +/* + * 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.expressions + +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirWhileLoop : FirLoop { + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitWhileLoop(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAccess.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAccess.kt new file mode 100644 index 00000000000..3db053656f1 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAccess.kt @@ -0,0 +1,27 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +abstract class FirAbstractAccess( + session: FirSession, + psi: PsiElement?, + final override var safe: Boolean = false +) : FirAbstractStatement(session, psi), FirModifiableAccess { + final override lateinit var calleeReference: FirReference + + final override var explicitReceiver: FirExpression? = null + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + calleeReference = calleeReference.transformSingle(transformer, data) + explicitReceiver = explicitReceiver?.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAnnotatedElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAnnotatedElement.kt new file mode 100644 index 00000000000..b09ba3b5ac1 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAnnotatedElement.kt @@ -0,0 +1,27 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer +import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +abstract class FirAbstractAnnotatedElement( + session: FirSession, + psi: PsiElement? +) : FirAbstractElement(session, psi), FirAnnotationContainer { + final override val annotations = mutableListOf() + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + annotations.transformInplace(transformer, data) + return this + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAssignment.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAssignment.kt new file mode 100644 index 00000000000..4fa71dcc2ae --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractAssignment.kt @@ -0,0 +1,28 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirOperation +import org.jetbrains.kotlin.fir.expressions.FirPropertyAssignment +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +abstract class FirAbstractAssignment( + session: FirSession, + psi: PsiElement?, + final override var value: FirExpression, + final override val operation: FirOperation, + safe: Boolean = false +) : FirAbstractAccess(session, psi, safe), FirPropertyAssignment { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + value = value.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractCall.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractCall.kt index 523afb1375a..c74ef4b8c2e 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractCall.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractCall.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir.expressions.impl import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.expressions.FirCall @@ -14,14 +15,13 @@ import org.jetbrains.kotlin.fir.transformInplace import org.jetbrains.kotlin.fir.visitors.FirTransformer abstract class FirAbstractCall( - final override val session: FirSession, - final override val psi: PsiElement? -) : FirCall { + session: FirSession, + psi: PsiElement? +) : FirAbstractExpression(session, psi), FirCall { final override val arguments = mutableListOf() override fun transformChildren(transformer: FirTransformer, data: D): FirElement { arguments.transformInplace(transformer, data) - - return this + return super.transformChildren(transformer, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractExpression.kt new file mode 100644 index 00000000000..bfe6140007c --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractExpression.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression + +abstract class FirAbstractExpression( + session: FirSession, + psi: PsiElement? +) : FirAbstractStatement(session, psi), FirExpression \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoop.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoop.kt new file mode 100644 index 00000000000..5acb763a374 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoop.kt @@ -0,0 +1,30 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirLoop +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +abstract class FirAbstractLoop( + session: FirSession, + psi: PsiElement?, + override var condition: FirExpression +) : FirAbstractStatement(session, psi), FirLoop { + override lateinit var block: FirBlock + + override var label: FirLabel? = null + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + condition = condition.transformSingle(transformer, data) + block = block.transformSingle(transformer, data) + label = label?.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt new file mode 100644 index 00000000000..704babc352b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt @@ -0,0 +1,20 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.FirTarget +import org.jetbrains.kotlin.fir.expressions.FirJump +import org.jetbrains.kotlin.fir.expressions.FirLoop + +abstract class FirAbstractLoopJump( + session: FirSession, + psi: PsiElement? +) : FirAbstractExpression(session, psi), FirJump { + override lateinit var target: FirTarget +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBlockBodyImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractStatement.kt similarity index 50% rename from compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBlockBodyImpl.kt rename to compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractStatement.kt index 08cc93d0a46..bccc0bcc199 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBlockBodyImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractStatement.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * 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. */ @@ -7,9 +7,9 @@ package org.jetbrains.kotlin.fir.expressions.impl import com.intellij.psi.PsiElement import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.expressions.FirBody import org.jetbrains.kotlin.fir.expressions.FirStatement -class FirBlockBodyImpl(override val session: FirSession, override val psi: PsiElement?) : FirBody { - override val statements = mutableListOf() -} \ No newline at end of file +abstract class FirAbstractStatement( + session: FirSession, + psi: PsiElement? +) : FirAbstractAnnotatedElement(session, psi), FirStatement \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAccessExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAccessExpressionImpl.kt new file mode 100644 index 00000000000..02e37f93104 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAccessExpressionImpl.kt @@ -0,0 +1,20 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirAccessExpression +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirAccessExpressionImpl( + session: FirSession, + psi: PsiElement?, + safe: Boolean = false +) : FirAbstractAccess(session, psi, safe), FirAccessExpression \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArrayGetCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArrayGetCallImpl.kt new file mode 100644 index 00000000000..0b5e25d1c2c --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArrayGetCallImpl.kt @@ -0,0 +1,25 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirArrayGetCall +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirArrayGetCallImpl( + session: FirSession, + psi: PsiElement?, + override var array: FirExpression +) : FirAbstractCall(session, psi), FirArrayGetCall { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + array = array.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArrayOfCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArrayOfCallImpl.kt new file mode 100644 index 00000000000..ffda72a1ec7 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArrayOfCallImpl.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall + +class FirArrayOfCallImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractCall(session, psi), FirArrayOfCall \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArraySetCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArraySetCallImpl.kt new file mode 100644 index 00000000000..3f1d79b28ed --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirArraySetCallImpl.kt @@ -0,0 +1,35 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirArraySetCall +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirOperation +import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.visitors.FirTransformer +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +class FirArraySetCallImpl( + session: FirSession, + psi: PsiElement?, + value: FirExpression, + operation: FirOperation +) : FirAbstractAssignment(session, psi, value, operation, false), FirArraySetCall { + override val arguments = mutableListOf() + + override fun accept(visitor: FirVisitor, data: D): R = + super.accept(visitor, data) + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + arguments.transformInplace(transformer, data) + + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBlockImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBlockImpl.kt new file mode 100644 index 00000000000..284a22a8c05 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBlockImpl.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2018 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirBlockImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractAnnotatedElement(session, psi), FirBlock { + override val statements = mutableListOf() + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + statements.transformInplace(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBreakExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBreakExpressionImpl.kt new file mode 100644 index 00000000000..6dec215b6ec --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirBreakExpressionImpl.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirBreakExpression + +class FirBreakExpressionImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractLoopJump(session, psi), FirBreakExpression \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirCallableReferenceAccessImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirCallableReferenceAccessImpl.kt new file mode 100644 index 00000000000..82afbbc4df3 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirCallableReferenceAccessImpl.kt @@ -0,0 +1,19 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess +import org.jetbrains.kotlin.fir.transformInplace +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirCallableReferenceAccessImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractAccess(session, psi), FirCallableReferenceAccess \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirCatchImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirCatchImpl.kt new file mode 100644 index 00000000000..59ada645a86 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirCatchImpl.kt @@ -0,0 +1,30 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirValueParameter +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.expressions.FirCatch +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirCatchImpl( + session: FirSession, + psi: PsiElement?, + override var parameter: FirValueParameter, + override var block: FirBlock +) : FirAbstractElement(session, psi), FirCatch { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + parameter = parameter.transformSingle(transformer, data) + block = block.transformSingle(transformer, data) + return this + } + +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirComponentCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirComponentCallImpl.kt new file mode 100644 index 00000000000..1fc6d4fda5d --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirComponentCallImpl.kt @@ -0,0 +1,16 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirComponentCall + +class FirComponentCallImpl( + session: FirSession, + psi: PsiElement?, + override val componentIndex: Int +) : FirAbstractCall(session, psi), FirComponentCall \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirConstExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirConstExpressionImpl.kt index 860beb2a27d..632c58bb49a 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirConstExpressionImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirConstExpressionImpl.kt @@ -11,11 +11,11 @@ import org.jetbrains.kotlin.fir.expressions.FirConstExpression import org.jetbrains.kotlin.ir.expressions.IrConstKind class FirConstExpressionImpl( - override val session: FirSession, - override val psi: PsiElement?, + session: FirSession, + psi: PsiElement?, override val kind: IrConstKind, override val value: T -) : FirConstExpression +) : FirAbstractExpression(session, psi), FirConstExpression fun FirConstExpressionImpl(session: FirSession, psi: PsiElement?, kind: IrConstKind, value: T?, errorReason: String) = value?.let { FirConstExpressionImpl(session, psi, kind, it) } ?: FirErrorExpressionImpl(session, psi, errorReason) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirContinueExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirContinueExpressionImpl.kt new file mode 100644 index 00000000000..4b05b0c5e4e --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirContinueExpressionImpl.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirContinueExpression + +class FirContinueExpressionImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractLoopJump(session, psi), FirContinueExpression \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt index 4408d935948..eaab3cf97db 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDelegatedConstructorCallImpl.kt @@ -22,6 +22,6 @@ class FirDelegatedConstructorCallImpl( override fun transformChildren(transformer: FirTransformer, data: D): FirElement { constructedType = constructedType.transformSingle(transformer, data) - return this + return super.transformChildren(transformer, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDoWhileLoopImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDoWhileLoopImpl.kt new file mode 100644 index 00000000000..09cc40cabdd --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirDoWhileLoopImpl.kt @@ -0,0 +1,17 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirDoWhileLoop +import org.jetbrains.kotlin.fir.expressions.FirExpression + +class FirDoWhileLoopImpl( + session: FirSession, + psi: PsiElement?, + condition: FirExpression +) : FirAbstractLoop(session, psi, condition), FirDoWhileLoop \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirElseIfTrueCondition.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirElseIfTrueCondition.kt new file mode 100644 index 00000000000..d69bf76f2a6 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirElseIfTrueCondition.kt @@ -0,0 +1,17 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression + +// Representation of "dummy" condition at else branch +class FirElseIfTrueCondition( + session: FirSession, + psi: PsiElement? +): FirAbstractExpression(session, psi) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirEmptyExpressionBlock.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirEmptyExpressionBlock.kt new file mode 100644 index 00000000000..ae89b855736 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirEmptyExpressionBlock.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions.impl + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirBlock + +class FirEmptyExpressionBlock( + session: FirSession +) : FirAbstractAnnotatedElement(session, null), FirBlock { + override val statements = listOf() +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt index 7f5ff0f1b91..e1a9f16a568 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.expressions.FirErrorExpression class FirErrorExpressionImpl( - override val session: FirSession, - override val psi: PsiElement?, + session: FirSession, + psi: PsiElement?, override val reason: String -) : FirErrorExpression \ No newline at end of file +) : FirAbstractExpression(session, psi), FirErrorExpression \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionBodyImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionBodyImpl.kt deleted file mode 100644 index e8fb87e2f20..00000000000 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionBodyImpl.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2000-2018 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.expressions.impl - -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.expressions.FirBody -import org.jetbrains.kotlin.fir.expressions.FirExpression - -class FirExpressionBodyImpl( - override val session: FirSession, - private val expression: FirExpression -) : FirBody { - override val statements = listOf(expression) - - override val psi: PsiElement? - get() = expression.psi -} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionStub.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionStub.kt index 258086b6de5..6aff080ca46 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionStub.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirExpressionStub.kt @@ -9,5 +9,7 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.expressions.FirExpression -@Deprecated("Temporary class until we have normal expressions") -class FirExpressionStub(override val session: FirSession, override val psi: PsiElement?) : FirExpression \ No newline at end of file +class FirExpressionStub( + session: FirSession, + psi: PsiElement? +) : FirAbstractExpression(session, psi) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirFunctionCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirFunctionCallImpl.kt new file mode 100644 index 00000000000..1e13baf0ee6 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirFunctionCallImpl.kt @@ -0,0 +1,32 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirFunctionCallImpl( + session: FirSession, + psi: PsiElement?, + override var safe: Boolean = false +) : FirAbstractCall(session, psi), FirFunctionCall, FirModifiableAccess { + override val typeArguments = mutableListOf() + + override lateinit var calleeReference: FirNamedReference + + override var explicitReceiver: FirExpression? = null + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + typeArguments.transformInplace(transformer, data) + calleeReference = calleeReference.transformSingle(transformer, data) + explicitReceiver = explicitReceiver?.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirGetClassCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirGetClassCallImpl.kt new file mode 100644 index 00000000000..0182d0463c2 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirGetClassCallImpl.kt @@ -0,0 +1,15 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirGetClassCall + +class FirGetClassCallImpl( + session: FirSession, + psi: PsiElement? +) : FirAbstractCall(session, psi), FirGetClassCall \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirModifiableAccess.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirModifiableAccess.kt new file mode 100644 index 00000000000..541fea97570 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirModifiableAccess.kt @@ -0,0 +1,19 @@ +/* + * 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.expressions.impl + +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirAccess + +interface FirModifiableAccess : FirAccess { + override var safe: Boolean + get() = super.safe + set(_) {} + + override var explicitReceiver: FirExpression? + get() = super.explicitReceiver + set(_) {} +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirOperatorCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirOperatorCallImpl.kt new file mode 100644 index 00000000000..7c4ebbeb094 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirOperatorCallImpl.kt @@ -0,0 +1,17 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirOperation +import org.jetbrains.kotlin.fir.expressions.FirOperatorCall + +class FirOperatorCallImpl( + session: FirSession, + psi: PsiElement?, + override val operation: FirOperation +) : FirAbstractCall(session, psi), FirOperatorCall \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirPropertyAssignmentImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirPropertyAssignmentImpl.kt new file mode 100644 index 00000000000..1f5b45c674d --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirPropertyAssignmentImpl.kt @@ -0,0 +1,20 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirOperation +import org.jetbrains.kotlin.fir.expressions.FirPropertyAssignment + +class FirPropertyAssignmentImpl( + session: FirSession, + psi: PsiElement?, + value: FirExpression, + operation: FirOperation, + safe: Boolean = false +) : FirAbstractAssignment(session, psi, value, operation, safe), FirPropertyAssignment \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirReturnExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirReturnExpressionImpl.kt new file mode 100644 index 00000000000..d241eea6733 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirReturnExpressionImpl.kt @@ -0,0 +1,26 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.declarations.FirFunction +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirReturnExpression +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirReturnExpressionImpl( + session: FirSession, + psi: PsiElement?, + override var result: FirExpression +) : FirAbstractExpression(session, psi), FirReturnExpression { + override lateinit var target: FirTarget + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + result = result.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirSingleExpressionBlock.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirSingleExpressionBlock.kt new file mode 100644 index 00000000000..276a2a106eb --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirSingleExpressionBlock.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2018 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.expressions.impl + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirSingleExpressionBlock( + session: FirSession, + private var statement: FirStatement +) : FirAbstractAnnotatedElement(session, statement.psi), FirBlock { + override val statements + get() = listOf(statement) + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + statement = statement.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirThrowExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirThrowExpressionImpl.kt new file mode 100644 index 00000000000..fd5e66b7ced --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirThrowExpressionImpl.kt @@ -0,0 +1,26 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirThrowExpression +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirThrowExpressionImpl( + session: FirSession, + psi: PsiElement?, + override var exception: FirExpression +) : FirAbstractExpression(session, psi), FirThrowExpression { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + exception = exception.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirTryExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirTryExpressionImpl.kt new file mode 100644 index 00000000000..5c96514ac62 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirTryExpressionImpl.kt @@ -0,0 +1,29 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.expressions.FirCatch +import org.jetbrains.kotlin.fir.expressions.FirTryExpression +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirTryExpressionImpl( + session: FirSession, + psi: PsiElement?, + override var tryBlock: FirBlock, + override var finallyBlock: FirBlock? +) : FirAbstractExpression(session, psi), FirTryExpression { + override val catches = mutableListOf() + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + tryBlock = tryBlock.transformSingle(transformer, data) + finallyBlock = finallyBlock?.transformSingle(transformer, data) + catches.transformInplace(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirTypeOperatorCallImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirTypeOperatorCallImpl.kt new file mode 100644 index 00000000000..786c93c70af --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirTypeOperatorCallImpl.kt @@ -0,0 +1,27 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirOperation +import org.jetbrains.kotlin.fir.expressions.FirTypeOperatorCall +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirTypeOperatorCallImpl( + session: FirSession, + psi: PsiElement?, + override val operation: FirOperation, + override var type: FirType +) : FirAbstractCall(session, psi), FirTypeOperatorCall { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + type = type.transformSingle(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirUnitExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirUnitExpression.kt new file mode 100644 index 00000000000..9fca7c27ba9 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirUnitExpression.kt @@ -0,0 +1,16 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression + +class FirUnitExpression( + session: FirSession, + psi: PsiElement? +): FirAbstractExpression(session, psi) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenBranchImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenBranchImpl.kt new file mode 100644 index 00000000000..cbc4ef9f509 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenBranchImpl.kt @@ -0,0 +1,29 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirWhenBranch +import org.jetbrains.kotlin.fir.transformSingle +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirWhenBranchImpl( + session: FirSession, + psi: PsiElement?, + override var condition: FirExpression, + override var result: FirBlock +) : FirAbstractElement(session, psi), FirWhenBranch { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + condition = condition.transformSingle(transformer, data) + result = result.transformSingle(transformer, data) + return this + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenExpressionImpl.kt new file mode 100644 index 00000000000..bf540097f2a --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenExpressionImpl.kt @@ -0,0 +1,33 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirVariable +import org.jetbrains.kotlin.fir.expressions.FirWhenBranch +import org.jetbrains.kotlin.fir.expressions.FirWhenExpression +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirWhenExpressionImpl( + session: FirSession, + psiElement: PsiElement?, + override var subject: FirExpression? = null, + override var subjectVariable: FirVariable? = null +) : FirAbstractExpression(session, psiElement), FirWhenExpression { + override val branches = mutableListOf() + + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + if (subjectVariable != null) { + subjectVariable = subjectVariable?.transformSingle(transformer, data) + } else { + subject = subject?.transformSingle(transformer, data) + } + branches.transformInplace(transformer, data) + return super.transformChildren(transformer, data) + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenSubjectExpression.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenSubjectExpression.kt new file mode 100644 index 00000000000..5ce28361ca4 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhenSubjectExpression.kt @@ -0,0 +1,16 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression + +class FirWhenSubjectExpression( + session: FirSession, + psi: PsiElement? +): FirAbstractExpression(session, psi) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhileLoopImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhileLoopImpl.kt new file mode 100644 index 00000000000..7b049027bd8 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirWhileLoopImpl.kt @@ -0,0 +1,17 @@ +/* + * 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.expressions.impl + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirWhileLoop + +class FirWhileLoopImpl( + session: FirSession, + psi: PsiElement?, + condition: FirExpression +) : FirAbstractLoop(session, psi, condition), FirWhileLoop \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/labels/FirLabelImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/labels/FirLabelImpl.kt new file mode 100644 index 00000000000..2cd6bb94331 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/labels/FirLabelImpl.kt @@ -0,0 +1,17 @@ +/* + * 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.labels + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirLabel +import org.jetbrains.kotlin.fir.FirSession + +class FirLabelImpl( + session: FirSession, + psi: PsiElement?, + override val name: String +) : FirAbstractElement(session, psi), FirLabel \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirErrorNamedReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirErrorNamedReference.kt new file mode 100644 index 00000000000..9c2450d0c0e --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirErrorNamedReference.kt @@ -0,0 +1,20 @@ +/* + * 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.references + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirNamedReference +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.name.Name + +class FirErrorNamedReference( + session: FirSession, + psi: PsiElement?, + val errorReason: String +) : FirAbstractElement(session, psi), FirNamedReference { + override val name: Name = Name.special("<$errorReason>") +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirExplicitSuperReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirExplicitSuperReference.kt new file mode 100644 index 00000000000..d16703a0b0b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirExplicitSuperReference.kt @@ -0,0 +1,22 @@ +/* + * 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.references + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.types.FirType +import org.jetbrains.kotlin.fir.visitors.FirTransformer + +class FirExplicitSuperReference( + session: FirSession, + psi: PsiElement?, + override var superType: FirType +) : FirAbstractElement(session, psi), FirSuperReference { + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + superType = superType.transformSingle(transformer, data) + return this + } +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirExplicitThisReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirExplicitThisReference.kt new file mode 100644 index 00000000000..55e3fe9223f --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirExplicitThisReference.kt @@ -0,0 +1,17 @@ +/* + * 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.references + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.FirThisReference + +class FirExplicitThisReference( + session: FirSession, + psi: PsiElement?, + override val labelName: String? +) : FirAbstractElement(session, psi), FirThisReference \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirSimpleNamedReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirSimpleNamedReference.kt new file mode 100644 index 00000000000..384cf8f6041 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirSimpleNamedReference.kt @@ -0,0 +1,18 @@ +/* + * 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.references + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirNamedReference +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.name.Name + +class FirSimpleNamedReference( + session: FirSession, + psi: PsiElement?, + override val name: Name +) : FirAbstractElement(session, psi), FirNamedReference \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt index 681e3ffacf4..a7e710b3082 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.fir.symbols.impl import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.fir.declarations.FirClass +import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.ConeClassSymbol import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterSymbol @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.coneTypeSafe import org.jetbrains.kotlin.name.ClassId -class FirClassSymbol(override val classId: ClassId) : ConeClassSymbol, AbstractFirBasedSymbol() { +class FirClassSymbol(override val classId: ClassId) : ConeClassSymbol, AbstractFirBasedSymbol() { override val kind: ClassKind get() = fir.classKind diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirDelegatedType.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirDelegatedType.kt index 8466df9337c..a6b329b86de 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirDelegatedType.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirDelegatedType.kt @@ -19,5 +19,6 @@ interface FirDelegatedType : FirType { override fun acceptChildren(visitor: FirVisitor, data: D) { super.acceptChildren(visitor, data) delegate?.accept(visitor, data) + type.accept(visitor, data) } } \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirFunctionType.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirFunctionType.kt index 960aededd54..42f66baa45e 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirFunctionType.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirFunctionType.kt @@ -21,6 +21,7 @@ interface FirFunctionType : FirTypeWithNullability { override fun acceptChildren(visitor: FirVisitor, data: D) { receiverType?.accept(visitor, data) + returnType.accept(visitor, data) super.acceptChildren(visitor, data) for (parameter in valueParameters) { parameter.accept(visitor, data) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirDelegatedTypeImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirDelegatedTypeImpl.kt index e6678c4f89f..5af8a3dd4f8 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirDelegatedTypeImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirDelegatedTypeImpl.kt @@ -5,21 +5,26 @@ package org.jetbrains.kotlin.fir.types.impl +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirDelegatedType import org.jetbrains.kotlin.fir.types.FirType -import org.jetbrains.kotlin.fir.visitors.FirVisitor +import org.jetbrains.kotlin.fir.visitors.FirTransformer class FirDelegatedTypeImpl( - override val type: FirType, - override val delegate: FirExpression? -) : FirType by type, FirDelegatedType { - override fun accept(visitor: FirVisitor, data: D): R { - return super.accept(visitor, data) - } + override var type: FirType, + override var delegate: FirExpression? +) : FirAbstractElement(type.session, type.psi), FirDelegatedType { + override val annotations: List + get() = type.annotations - override fun acceptChildren(visitor: FirVisitor, data: D) { - type.acceptChildren(visitor, data) - delegate?.accept(visitor, data) + override fun transformChildren(transformer: FirTransformer, data: D): FirElement { + type = type.transformSingle(transformer, data) + delegate = delegate?.transformSingle(transformer, data) + + return this } } \ No newline at end of file diff --git a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt index e0756e38e17..434af97fc41 100644 --- a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt +++ b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt @@ -6,7 +6,9 @@ package org.jetbrains.kotlin.fir.visitors import org.jetbrains.kotlin.fir.* 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.types.* @@ -14,6 +16,10 @@ import org.jetbrains.kotlin.fir.types.* abstract class FirTransformer : FirVisitor, D>() { abstract fun transformElement(element: E, data: D): CompositeTransformResult + open fun transformCatch(catch: E, data: D): CompositeTransformResult { + return transformElement(catch, data) + } + open fun transformDeclaration(declaration: FirDeclaration, data: D): CompositeTransformResult { return transformElement(declaration, data) } @@ -34,10 +40,18 @@ abstract class FirTransformer : FirVisitor { + return transformFunction(anonymousFunction, data) + } + open fun transformConstructor(constructor: FirConstructor, data: D): CompositeTransformResult { return transformFunction(constructor, data) } + open fun transformModifiableFunction(modifiableFunction: FirModifiableFunction, data: D): CompositeTransformResult { + return transformFunction(modifiableFunction, data) + } + open fun transformNamedFunction(namedFunction: FirNamedFunction, data: D): CompositeTransformResult { return transformFunction(namedFunction, data) } @@ -58,12 +72,12 @@ abstract class FirTransformer : FirVisitor { - return transformMemberDeclaration(klass, data) + open fun transformRegularClass(regularClass: FirRegularClass, data: D): CompositeTransformResult { + return transformMemberDeclaration(regularClass, data) } open fun transformEnumEntry(enumEntry: FirEnumEntry, data: D): CompositeTransformResult { - return transformClass(enumEntry, data) + return transformRegularClass(enumEntry, data) } open fun transformTypeAlias(typeAlias: FirTypeAlias, data: D): CompositeTransformResult { @@ -106,6 +120,10 @@ abstract class FirTransformer : FirVisitor transformLabel(label: E, data: D): CompositeTransformResult { + return transformElement(label, data) + } + open fun transformPackageFragment(packageFragment: E, data: D): CompositeTransformResult { return transformElement(packageFragment, data) } @@ -114,16 +132,68 @@ abstract class FirTransformer : FirVisitor transformReference(reference: E, data: D): CompositeTransformResult { + return transformElement(reference, data) + } + + open fun transformNamedReference(namedReference: E, data: D): CompositeTransformResult { + return transformReference(namedReference, data) + } + + open fun transformSuperReference(superReference: E, data: D): CompositeTransformResult { + return transformReference(superReference, data) + } + + open fun transformThisReference(thisReference: E, data: D): CompositeTransformResult { + return transformReference(thisReference, data) + } + open fun transformStatement(statement: FirStatement, data: D): CompositeTransformResult { return transformElement(statement, data) } + open fun transformAccess(access: FirAccess, data: D): CompositeTransformResult { + return transformStatement(access, data) + } + + open fun transformAccessExpression(accessExpression: FirAccessExpression, data: D): CompositeTransformResult { + return transformAccess(accessExpression, data) + } + + open fun transformCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess, data: D): CompositeTransformResult { + return transformAccessExpression(callableReferenceAccess, data) + } + + open fun transformAssignment(assignment: FirAssignment, data: D): CompositeTransformResult { + return transformAccess(assignment, data) + } + + open fun transformPropertyAssignment(propertyAssignment: FirPropertyAssignment, data: D): CompositeTransformResult { + return transformAssignment(propertyAssignment, data) + } + + open fun transformModifiableAccess(modifiableAccess: FirModifiableAccess, data: D): CompositeTransformResult { + return transformAccess(modifiableAccess, data) + } + + open fun transformClass(klass: FirClass, data: D): CompositeTransformResult { + return transformStatement(klass, data) + } + + open fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: D): CompositeTransformResult { + return transformClass(anonymousObject, data) + } + + open fun transformModifiableClass(modifiableClass: FirModifiableClass, data: D): CompositeTransformResult { + return transformClass(modifiableClass, data) + } + open fun transformExpression(expression: FirExpression, data: D): CompositeTransformResult { return transformStatement(expression, data) } - open fun transformBody(body: FirBody, data: D): CompositeTransformResult { - return transformExpression(body, data) + open fun transformBlock(block: FirBlock, data: D): CompositeTransformResult { + return transformExpression(block, data) } open fun transformCall(call: FirCall, data: D): CompositeTransformResult { @@ -134,10 +204,42 @@ abstract class FirTransformer : FirVisitor { + return transformCall(arrayGetCall, data) + } + + open fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): CompositeTransformResult { + return transformCall(arrayOfCall, data) + } + + open fun transformArraySetCall(arraySetCall: FirArraySetCall, data: D): CompositeTransformResult { + return transformCall(arraySetCall, data) + } + + open fun transformComponentCall(componentCall: FirComponentCall, data: D): CompositeTransformResult { + return transformCall(componentCall, data) + } + open fun transformDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): CompositeTransformResult { return transformCall(delegatedConstructorCall, data) } + open fun transformFunctionCall(functionCall: FirFunctionCall, data: D): CompositeTransformResult { + return transformCall(functionCall, data) + } + + open fun transformGetClassCall(getClassCall: FirGetClassCall, data: D): CompositeTransformResult { + return transformCall(getClassCall, data) + } + + open fun transformOperatorCall(operatorCall: FirOperatorCall, data: D): CompositeTransformResult { + return transformCall(operatorCall, data) + } + + open fun transformTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: D): CompositeTransformResult { + return transformOperatorCall(typeOperatorCall, data) + } + open fun transformConstExpression(constExpression: FirConstExpression, data: D): CompositeTransformResult { return transformExpression(constExpression, data) } @@ -146,6 +248,54 @@ abstract class FirTransformer : FirVisitor transformJump(jump: FirJump, data: D): CompositeTransformResult { + return transformExpression(jump, data) + } + + open fun transformBreakExpression(breakExpression: FirBreakExpression, data: D): CompositeTransformResult { + return transformJump(breakExpression, data) + } + + open fun transformContinueExpression(continueExpression: FirContinueExpression, data: D): CompositeTransformResult { + return transformJump(continueExpression, data) + } + + open fun transformReturnExpression(returnExpression: FirReturnExpression, data: D): CompositeTransformResult { + return transformJump(returnExpression, data) + } + + open fun transformThrowExpression(throwExpression: FirThrowExpression, data: D): CompositeTransformResult { + return transformExpression(throwExpression, data) + } + + open fun transformTryExpression(tryExpression: FirTryExpression, data: D): CompositeTransformResult { + return transformExpression(tryExpression, data) + } + + open fun transformWhenExpression(whenExpression: FirWhenExpression, data: D): CompositeTransformResult { + return transformExpression(whenExpression, data) + } + + open fun transformLoop(loop: FirLoop, data: D): CompositeTransformResult { + return transformStatement(loop, data) + } + + open fun transformDoWhileLoop(doWhileLoop: FirDoWhileLoop, data: D): CompositeTransformResult { + return transformLoop(doWhileLoop, data) + } + + open fun transformWhileLoop(whileLoop: FirWhileLoop, data: D): CompositeTransformResult { + return transformLoop(whileLoop, data) + } + + open fun transformTargetElement(targetElement: E, data: D): CompositeTransformResult { + return transformElement(targetElement, data) + } + + open fun transformLabeledElement(labeledElement: E, data: D): CompositeTransformResult { + return transformTargetElement(labeledElement, data) + } + open fun transformType(type: FirType, data: D): CompositeTransformResult { return transformElement(type, data) } @@ -198,16 +348,56 @@ abstract class FirTransformer : FirVisitor transformWhenBranch(whenBranch: E, data: D): CompositeTransformResult { + return transformElement(whenBranch, data) + } + + final override fun visitAccess(access: FirAccess, data: D): CompositeTransformResult { + return transformAccess(access, data) + } + + final override fun visitAccessExpression(accessExpression: FirAccessExpression, data: D): CompositeTransformResult { + return transformAccessExpression(accessExpression, data) + } + final override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: D): CompositeTransformResult { return transformAnnotationCall(annotationCall, data) } + final override fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction, data: D): CompositeTransformResult { + return transformAnonymousFunction(anonymousFunction, data) + } + final override fun visitAnonymousInitializer(anonymousInitializer: FirAnonymousInitializer, data: D): CompositeTransformResult { return transformAnonymousInitializer(anonymousInitializer, data) } - final override fun visitBody(body: FirBody, data: D): CompositeTransformResult { - return transformBody(body, data) + final override fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: D): CompositeTransformResult { + return transformAnonymousObject(anonymousObject, data) + } + + final override fun visitArrayGetCall(arrayGetCall: FirArrayGetCall, data: D): CompositeTransformResult { + return transformArrayGetCall(arrayGetCall, data) + } + + final override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): CompositeTransformResult { + return transformArrayOfCall(arrayOfCall, data) + } + + final override fun visitArraySetCall(arraySetCall: FirArraySetCall, data: D): CompositeTransformResult { + return transformArraySetCall(arraySetCall, data) + } + + final override fun visitAssignment(assignment: FirAssignment, data: D): CompositeTransformResult { + return transformAssignment(assignment, data) + } + + final override fun visitBlock(block: FirBlock, data: D): CompositeTransformResult { + return transformBlock(block, data) + } + + final override fun visitBreakExpression(breakExpression: FirBreakExpression, data: D): CompositeTransformResult { + return transformBreakExpression(breakExpression, data) } final override fun visitCall(call: FirCall, data: D): CompositeTransformResult { @@ -218,10 +408,22 @@ abstract class FirTransformer : FirVisitor { + return transformCallableReferenceAccess(callableReferenceAccess, data) + } + + final override fun visitCatch(catch: FirCatch, data: D): CompositeTransformResult { + return transformCatch(catch, data) + } + final override fun visitClass(klass: FirClass, data: D): CompositeTransformResult { return transformClass(klass, data) } + final override fun visitComponentCall(componentCall: FirComponentCall, data: D): CompositeTransformResult { + return transformComponentCall(componentCall, data) + } + final override fun visitConstExpression(constExpression: FirConstExpression, data: D): CompositeTransformResult { return transformConstExpression(constExpression, data) } @@ -230,6 +432,10 @@ abstract class FirTransformer : FirVisitor { + return transformContinueExpression(continueExpression, data) + } + final override fun visitDeclaration(declaration: FirDeclaration, data: D): CompositeTransformResult { return transformDeclaration(declaration, data) } @@ -250,6 +456,10 @@ abstract class FirTransformer : FirVisitor { + return transformDoWhileLoop(doWhileLoop, data) + } + final override fun visitDynamicType(dynamicType: FirDynamicType, data: D): CompositeTransformResult { return transformDynamicType(dynamicType, data) } @@ -282,10 +492,18 @@ abstract class FirTransformer : FirVisitor { + return transformFunctionCall(functionCall, data) + } + final override fun visitFunctionType(functionType: FirFunctionType, data: D): CompositeTransformResult { return transformFunctionType(functionType, data) } + final override fun visitGetClassCall(getClassCall: FirGetClassCall, data: D): CompositeTransformResult { + return transformGetClassCall(getClassCall, data) + } + final override fun visitImplicitType(implicitType: FirImplicitType, data: D): CompositeTransformResult { return transformImplicitType(implicitType, data) } @@ -294,10 +512,38 @@ abstract class FirTransformer : FirVisitor visitJump(jump: FirJump, data: D): CompositeTransformResult { + return transformJump(jump, data) + } + + final override fun visitLabel(label: FirLabel, data: D): CompositeTransformResult { + return transformLabel(label, data) + } + + final override fun visitLabeledElement(labeledElement: FirLabeledElement, data: D): CompositeTransformResult { + return transformLabeledElement(labeledElement, data) + } + + final override fun visitLoop(loop: FirLoop, data: D): CompositeTransformResult { + return transformLoop(loop, data) + } + final override fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration, data: D): CompositeTransformResult { return transformMemberDeclaration(memberDeclaration, data) } + final override fun visitModifiableAccess(modifiableAccess: FirModifiableAccess, data: D): CompositeTransformResult { + return transformModifiableAccess(modifiableAccess, data) + } + + final override fun visitModifiableClass(modifiableClass: FirModifiableClass, data: D): CompositeTransformResult { + return transformModifiableClass(modifiableClass, data) + } + + final override fun visitModifiableFunction(modifiableFunction: FirModifiableFunction, data: D): CompositeTransformResult { + return transformModifiableFunction(modifiableFunction, data) + } + final override fun visitNamedDeclaration(namedDeclaration: FirNamedDeclaration, data: D): CompositeTransformResult { return transformNamedDeclaration(namedDeclaration, data) } @@ -306,6 +552,14 @@ abstract class FirTransformer : FirVisitor { + return transformNamedReference(namedReference, data) + } + + final override fun visitOperatorCall(operatorCall: FirOperatorCall, data: D): CompositeTransformResult { + return transformOperatorCall(operatorCall, data) + } + final override fun visitPackageFragment(packageFragment: FirPackageFragment, data: D): CompositeTransformResult { return transformPackageFragment(packageFragment, data) } @@ -318,6 +572,18 @@ abstract class FirTransformer : FirVisitor { + return transformPropertyAssignment(propertyAssignment, data) + } + + final override fun visitReference(reference: FirReference, data: D): CompositeTransformResult { + return transformReference(reference, data) + } + + final override fun visitRegularClass(regularClass: FirRegularClass, data: D): CompositeTransformResult { + return transformRegularClass(regularClass, data) + } + final override fun visitResolvedDeclarationStatus(resolvedDeclarationStatus: FirResolvedDeclarationStatus, data: D): CompositeTransformResult { return transformResolvedDeclarationStatus(resolvedDeclarationStatus, data) } @@ -334,6 +600,10 @@ abstract class FirTransformer : FirVisitor { + return transformReturnExpression(returnExpression, data) + } + final override fun visitStarProjection(starProjection: FirStarProjection, data: D): CompositeTransformResult { return transformStarProjection(starProjection, data) } @@ -342,6 +612,26 @@ abstract class FirTransformer : FirVisitor { + return transformSuperReference(superReference, data) + } + + final override fun visitTargetElement(targetElement: FirTargetElement, data: D): CompositeTransformResult { + return transformTargetElement(targetElement, data) + } + + final override fun visitThisReference(thisReference: FirThisReference, data: D): CompositeTransformResult { + return transformThisReference(thisReference, data) + } + + final override fun visitThrowExpression(throwExpression: FirThrowExpression, data: D): CompositeTransformResult { + return transformThrowExpression(throwExpression, data) + } + + final override fun visitTryExpression(tryExpression: FirTryExpression, data: D): CompositeTransformResult { + return transformTryExpression(tryExpression, data) + } + final override fun visitType(type: FirType, data: D): CompositeTransformResult { return transformType(type, data) } @@ -350,6 +640,10 @@ abstract class FirTransformer : FirVisitor { + return transformTypeOperatorCall(typeOperatorCall, data) + } + final override fun visitTypeParameter(typeParameter: FirTypeParameter, data: D): CompositeTransformResult { return transformTypeParameter(typeParameter, data) } @@ -382,6 +676,18 @@ abstract class FirTransformer : FirVisitor { + return transformWhenBranch(whenBranch, data) + } + + final override fun visitWhenExpression(whenExpression: FirWhenExpression, data: D): CompositeTransformResult { + return transformWhenExpression(whenExpression, data) + } + + final override fun visitWhileLoop(whileLoop: FirWhileLoop, data: D): CompositeTransformResult { + return transformWhileLoop(whileLoop, data) + } + final override fun visitElement(element: FirElement, data: D): CompositeTransformResult { return transformElement(element, data) } diff --git a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt index 02f1fb2a939..622d35edc1e 100644 --- a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt +++ b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt @@ -6,7 +6,9 @@ package org.jetbrains.kotlin.fir.visitors import org.jetbrains.kotlin.fir.* 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.types.* @@ -14,6 +16,10 @@ import org.jetbrains.kotlin.fir.types.* abstract class FirVisitor { abstract fun visitElement(element: FirElement, data: D): R + open fun visitCatch(catch: FirCatch, data: D): R { + return visitElement(catch, data) + } + open fun visitDeclaration(declaration: FirDeclaration, data: D): R { return visitElement(declaration, data) } @@ -34,10 +40,18 @@ abstract class FirVisitor { return visitDeclarationWithBody(function, data) } + open fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction, data: D): R { + return visitFunction(anonymousFunction, data) + } + open fun visitConstructor(constructor: FirConstructor, data: D): R { return visitFunction(constructor, data) } + open fun visitModifiableFunction(modifiableFunction: FirModifiableFunction, data: D): R { + return visitFunction(modifiableFunction, data) + } + open fun visitNamedFunction(namedFunction: FirNamedFunction, data: D): R { return visitFunction(namedFunction, data) } @@ -58,12 +72,12 @@ abstract class FirVisitor { return visitNamedDeclaration(memberDeclaration, data) } - open fun visitClass(klass: FirClass, data: D): R { - return visitMemberDeclaration(klass, data) + open fun visitRegularClass(regularClass: FirRegularClass, data: D): R { + return visitMemberDeclaration(regularClass, data) } open fun visitEnumEntry(enumEntry: FirEnumEntry, data: D): R { - return visitClass(enumEntry, data) + return visitRegularClass(enumEntry, data) } open fun visitTypeAlias(typeAlias: FirTypeAlias, data: D): R { @@ -106,6 +120,10 @@ abstract class FirVisitor { return visitImport(resolvedImport, data) } + open fun visitLabel(label: FirLabel, data: D): R { + return visitElement(label, data) + } + open fun visitPackageFragment(packageFragment: FirPackageFragment, data: D): R { return visitElement(packageFragment, data) } @@ -114,16 +132,68 @@ abstract class FirVisitor { return visitPackageFragment(file, data) } + open fun visitReference(reference: FirReference, data: D): R { + return visitElement(reference, data) + } + + open fun visitNamedReference(namedReference: FirNamedReference, data: D): R { + return visitReference(namedReference, data) + } + + open fun visitSuperReference(superReference: FirSuperReference, data: D): R { + return visitReference(superReference, data) + } + + open fun visitThisReference(thisReference: FirThisReference, data: D): R { + return visitReference(thisReference, data) + } + open fun visitStatement(statement: FirStatement, data: D): R { return visitElement(statement, data) } + open fun visitAccess(access: FirAccess, data: D): R { + return visitStatement(access, data) + } + + open fun visitAccessExpression(accessExpression: FirAccessExpression, data: D): R { + return visitAccess(accessExpression, data) + } + + open fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess, data: D): R { + return visitAccessExpression(callableReferenceAccess, data) + } + + open fun visitAssignment(assignment: FirAssignment, data: D): R { + return visitAccess(assignment, data) + } + + open fun visitPropertyAssignment(propertyAssignment: FirPropertyAssignment, data: D): R { + return visitAssignment(propertyAssignment, data) + } + + open fun visitModifiableAccess(modifiableAccess: FirModifiableAccess, data: D): R { + return visitAccess(modifiableAccess, data) + } + + open fun visitClass(klass: FirClass, data: D): R { + return visitStatement(klass, data) + } + + open fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: D): R { + return visitClass(anonymousObject, data) + } + + open fun visitModifiableClass(modifiableClass: FirModifiableClass, data: D): R { + return visitClass(modifiableClass, data) + } + open fun visitExpression(expression: FirExpression, data: D): R { return visitStatement(expression, data) } - open fun visitBody(body: FirBody, data: D): R { - return visitExpression(body, data) + open fun visitBlock(block: FirBlock, data: D): R { + return visitExpression(block, data) } open fun visitCall(call: FirCall, data: D): R { @@ -134,10 +204,42 @@ abstract class FirVisitor { return visitCall(annotationCall, data) } + open fun visitArrayGetCall(arrayGetCall: FirArrayGetCall, data: D): R { + return visitCall(arrayGetCall, data) + } + + open fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: D): R { + return visitCall(arrayOfCall, data) + } + + open fun visitArraySetCall(arraySetCall: FirArraySetCall, data: D): R { + return visitCall(arraySetCall, data) + } + + open fun visitComponentCall(componentCall: FirComponentCall, data: D): R { + return visitCall(componentCall, data) + } + open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): R { return visitCall(delegatedConstructorCall, data) } + open fun visitFunctionCall(functionCall: FirFunctionCall, data: D): R { + return visitCall(functionCall, data) + } + + open fun visitGetClassCall(getClassCall: FirGetClassCall, data: D): R { + return visitCall(getClassCall, data) + } + + open fun visitOperatorCall(operatorCall: FirOperatorCall, data: D): R { + return visitCall(operatorCall, data) + } + + open fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: D): R { + return visitOperatorCall(typeOperatorCall, data) + } + open fun visitConstExpression(constExpression: FirConstExpression, data: D): R { return visitExpression(constExpression, data) } @@ -146,6 +248,54 @@ abstract class FirVisitor { return visitExpression(errorExpression, data) } + open fun visitJump(jump: FirJump, data: D): R { + return visitExpression(jump, data) + } + + open fun visitBreakExpression(breakExpression: FirBreakExpression, data: D): R { + return visitJump(breakExpression, data) + } + + open fun visitContinueExpression(continueExpression: FirContinueExpression, data: D): R { + return visitJump(continueExpression, data) + } + + open fun visitReturnExpression(returnExpression: FirReturnExpression, data: D): R { + return visitJump(returnExpression, data) + } + + open fun visitThrowExpression(throwExpression: FirThrowExpression, data: D): R { + return visitExpression(throwExpression, data) + } + + open fun visitTryExpression(tryExpression: FirTryExpression, data: D): R { + return visitExpression(tryExpression, data) + } + + open fun visitWhenExpression(whenExpression: FirWhenExpression, data: D): R { + return visitExpression(whenExpression, data) + } + + open fun visitLoop(loop: FirLoop, data: D): R { + return visitStatement(loop, data) + } + + open fun visitDoWhileLoop(doWhileLoop: FirDoWhileLoop, data: D): R { + return visitLoop(doWhileLoop, data) + } + + open fun visitWhileLoop(whileLoop: FirWhileLoop, data: D): R { + return visitLoop(whileLoop, data) + } + + open fun visitTargetElement(targetElement: FirTargetElement, data: D): R { + return visitElement(targetElement, data) + } + + open fun visitLabeledElement(labeledElement: FirLabeledElement, data: D): R { + return visitTargetElement(labeledElement, data) + } + open fun visitType(type: FirType, data: D): R { return visitElement(type, data) } @@ -198,4 +348,8 @@ abstract class FirVisitor { return visitTypeProjection(typeProjectionWithVariance, data) } + open fun visitWhenBranch(whenBranch: FirWhenBranch, data: D): R { + return visitElement(whenBranch, data) + } + } diff --git a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt index 1968c4784b7..c212ffa0cab 100644 --- a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt +++ b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt @@ -6,7 +6,9 @@ package org.jetbrains.kotlin.fir.visitors import org.jetbrains.kotlin.fir.* 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.types.* @@ -14,6 +16,10 @@ import org.jetbrains.kotlin.fir.types.* abstract class FirVisitorVoid : FirVisitor() { abstract fun visitElement(element: FirElement) + open fun visitCatch(catch: FirCatch) { + visitElement(catch, null) + } + open fun visitDeclaration(declaration: FirDeclaration) { visitElement(declaration, null) } @@ -34,10 +40,18 @@ abstract class FirVisitorVoid : FirVisitor() { visitDeclarationWithBody(function, null) } + open fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction) { + visitFunction(anonymousFunction, null) + } + open fun visitConstructor(constructor: FirConstructor) { visitFunction(constructor, null) } + open fun visitModifiableFunction(modifiableFunction: FirModifiableFunction) { + visitFunction(modifiableFunction, null) + } + open fun visitNamedFunction(namedFunction: FirNamedFunction) { visitFunction(namedFunction, null) } @@ -58,12 +72,12 @@ abstract class FirVisitorVoid : FirVisitor() { visitNamedDeclaration(memberDeclaration, null) } - open fun visitClass(klass: FirClass) { - visitMemberDeclaration(klass, null) + open fun visitRegularClass(regularClass: FirRegularClass) { + visitMemberDeclaration(regularClass, null) } open fun visitEnumEntry(enumEntry: FirEnumEntry) { - visitClass(enumEntry, null) + visitRegularClass(enumEntry, null) } open fun visitTypeAlias(typeAlias: FirTypeAlias) { @@ -106,6 +120,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitImport(resolvedImport, null) } + open fun visitLabel(label: FirLabel) { + visitElement(label, null) + } + open fun visitPackageFragment(packageFragment: FirPackageFragment) { visitElement(packageFragment, null) } @@ -114,16 +132,68 @@ abstract class FirVisitorVoid : FirVisitor() { visitPackageFragment(file, null) } + open fun visitReference(reference: FirReference) { + visitElement(reference, null) + } + + open fun visitNamedReference(namedReference: FirNamedReference) { + visitReference(namedReference, null) + } + + open fun visitSuperReference(superReference: FirSuperReference) { + visitReference(superReference, null) + } + + open fun visitThisReference(thisReference: FirThisReference) { + visitReference(thisReference, null) + } + open fun visitStatement(statement: FirStatement) { visitElement(statement, null) } + open fun visitAccess(access: FirAccess) { + visitStatement(access, null) + } + + open fun visitAccessExpression(accessExpression: FirAccessExpression) { + visitAccess(accessExpression, null) + } + + open fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess) { + visitAccessExpression(callableReferenceAccess, null) + } + + open fun visitAssignment(assignment: FirAssignment) { + visitAccess(assignment, null) + } + + open fun visitPropertyAssignment(propertyAssignment: FirPropertyAssignment) { + visitAssignment(propertyAssignment, null) + } + + open fun visitModifiableAccess(modifiableAccess: FirModifiableAccess) { + visitAccess(modifiableAccess, null) + } + + open fun visitClass(klass: FirClass) { + visitStatement(klass, null) + } + + open fun visitAnonymousObject(anonymousObject: FirAnonymousObject) { + visitClass(anonymousObject, null) + } + + open fun visitModifiableClass(modifiableClass: FirModifiableClass) { + visitClass(modifiableClass, null) + } + open fun visitExpression(expression: FirExpression) { visitStatement(expression, null) } - open fun visitBody(body: FirBody) { - visitExpression(body, null) + open fun visitBlock(block: FirBlock) { + visitExpression(block, null) } open fun visitCall(call: FirCall) { @@ -134,10 +204,42 @@ abstract class FirVisitorVoid : FirVisitor() { visitCall(annotationCall, null) } + open fun visitArrayGetCall(arrayGetCall: FirArrayGetCall) { + visitCall(arrayGetCall, null) + } + + open fun visitArrayOfCall(arrayOfCall: FirArrayOfCall) { + visitCall(arrayOfCall, null) + } + + open fun visitArraySetCall(arraySetCall: FirArraySetCall) { + visitCall(arraySetCall, null) + } + + open fun visitComponentCall(componentCall: FirComponentCall) { + visitCall(componentCall, null) + } + open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall) { visitCall(delegatedConstructorCall, null) } + open fun visitFunctionCall(functionCall: FirFunctionCall) { + visitCall(functionCall, null) + } + + open fun visitGetClassCall(getClassCall: FirGetClassCall) { + visitCall(getClassCall, null) + } + + open fun visitOperatorCall(operatorCall: FirOperatorCall) { + visitCall(operatorCall, null) + } + + open fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall) { + visitOperatorCall(typeOperatorCall, null) + } + open fun visitConstExpression(constExpression: FirConstExpression) { visitExpression(constExpression, null) } @@ -146,6 +248,54 @@ abstract class FirVisitorVoid : FirVisitor() { visitExpression(errorExpression, null) } + open fun visitJump(jump: FirJump) { + visitExpression(jump, null) + } + + open fun visitBreakExpression(breakExpression: FirBreakExpression) { + visitJump(breakExpression, null) + } + + open fun visitContinueExpression(continueExpression: FirContinueExpression) { + visitJump(continueExpression, null) + } + + open fun visitReturnExpression(returnExpression: FirReturnExpression) { + visitJump(returnExpression, null) + } + + open fun visitThrowExpression(throwExpression: FirThrowExpression) { + visitExpression(throwExpression, null) + } + + open fun visitTryExpression(tryExpression: FirTryExpression) { + visitExpression(tryExpression, null) + } + + open fun visitWhenExpression(whenExpression: FirWhenExpression) { + visitExpression(whenExpression, null) + } + + open fun visitLoop(loop: FirLoop) { + visitStatement(loop, null) + } + + open fun visitDoWhileLoop(doWhileLoop: FirDoWhileLoop) { + visitLoop(doWhileLoop, null) + } + + open fun visitWhileLoop(whileLoop: FirWhileLoop) { + visitLoop(whileLoop, null) + } + + open fun visitTargetElement(targetElement: FirTargetElement) { + visitElement(targetElement, null) + } + + open fun visitLabeledElement(labeledElement: FirLabeledElement) { + visitTargetElement(labeledElement, null) + } + open fun visitType(type: FirType) { visitElement(type, null) } @@ -198,16 +348,56 @@ abstract class FirVisitorVoid : FirVisitor() { visitTypeProjection(typeProjectionWithVariance, null) } + open fun visitWhenBranch(whenBranch: FirWhenBranch) { + visitElement(whenBranch, null) + } + + final override fun visitAccess(access: FirAccess, data: Nothing?) { + visitAccess(access) + } + + final override fun visitAccessExpression(accessExpression: FirAccessExpression, data: Nothing?) { + visitAccessExpression(accessExpression) + } + final override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: Nothing?) { visitAnnotationCall(annotationCall) } + final override fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction, data: Nothing?) { + visitAnonymousFunction(anonymousFunction) + } + final override fun visitAnonymousInitializer(anonymousInitializer: FirAnonymousInitializer, data: Nothing?) { visitAnonymousInitializer(anonymousInitializer) } - final override fun visitBody(body: FirBody, data: Nothing?) { - visitBody(body) + final override fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: Nothing?) { + visitAnonymousObject(anonymousObject) + } + + final override fun visitArrayGetCall(arrayGetCall: FirArrayGetCall, data: Nothing?) { + visitArrayGetCall(arrayGetCall) + } + + final override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Nothing?) { + visitArrayOfCall(arrayOfCall) + } + + final override fun visitArraySetCall(arraySetCall: FirArraySetCall, data: Nothing?) { + visitArraySetCall(arraySetCall) + } + + final override fun visitAssignment(assignment: FirAssignment, data: Nothing?) { + visitAssignment(assignment) + } + + final override fun visitBlock(block: FirBlock, data: Nothing?) { + visitBlock(block) + } + + final override fun visitBreakExpression(breakExpression: FirBreakExpression, data: Nothing?) { + visitBreakExpression(breakExpression) } final override fun visitCall(call: FirCall, data: Nothing?) { @@ -218,10 +408,22 @@ abstract class FirVisitorVoid : FirVisitor() { visitCallableMember(callableMember) } + final override fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess, data: Nothing?) { + visitCallableReferenceAccess(callableReferenceAccess) + } + + final override fun visitCatch(catch: FirCatch, data: Nothing?) { + visitCatch(catch) + } + final override fun visitClass(klass: FirClass, data: Nothing?) { visitClass(klass) } + final override fun visitComponentCall(componentCall: FirComponentCall, data: Nothing?) { + visitComponentCall(componentCall) + } + final override fun visitConstExpression(constExpression: FirConstExpression, data: Nothing?) { visitConstExpression(constExpression) } @@ -230,6 +432,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitConstructor(constructor) } + final override fun visitContinueExpression(continueExpression: FirContinueExpression, data: Nothing?) { + visitContinueExpression(continueExpression) + } + final override fun visitDeclaration(declaration: FirDeclaration, data: Nothing?) { visitDeclaration(declaration) } @@ -250,6 +456,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitDelegatedType(delegatedType) } + final override fun visitDoWhileLoop(doWhileLoop: FirDoWhileLoop, data: Nothing?) { + visitDoWhileLoop(doWhileLoop) + } + final override fun visitDynamicType(dynamicType: FirDynamicType, data: Nothing?) { visitDynamicType(dynamicType) } @@ -282,10 +492,18 @@ abstract class FirVisitorVoid : FirVisitor() { visitFunction(function) } + final override fun visitFunctionCall(functionCall: FirFunctionCall, data: Nothing?) { + visitFunctionCall(functionCall) + } + final override fun visitFunctionType(functionType: FirFunctionType, data: Nothing?) { visitFunctionType(functionType) } + final override fun visitGetClassCall(getClassCall: FirGetClassCall, data: Nothing?) { + visitGetClassCall(getClassCall) + } + final override fun visitImplicitType(implicitType: FirImplicitType, data: Nothing?) { visitImplicitType(implicitType) } @@ -294,10 +512,38 @@ abstract class FirVisitorVoid : FirVisitor() { visitImport(import) } + final override fun visitJump(jump: FirJump, data: Nothing?) { + visitJump(jump) + } + + final override fun visitLabel(label: FirLabel, data: Nothing?) { + visitLabel(label) + } + + final override fun visitLabeledElement(labeledElement: FirLabeledElement, data: Nothing?) { + visitLabeledElement(labeledElement) + } + + final override fun visitLoop(loop: FirLoop, data: Nothing?) { + visitLoop(loop) + } + final override fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration, data: Nothing?) { visitMemberDeclaration(memberDeclaration) } + final override fun visitModifiableAccess(modifiableAccess: FirModifiableAccess, data: Nothing?) { + visitModifiableAccess(modifiableAccess) + } + + final override fun visitModifiableClass(modifiableClass: FirModifiableClass, data: Nothing?) { + visitModifiableClass(modifiableClass) + } + + final override fun visitModifiableFunction(modifiableFunction: FirModifiableFunction, data: Nothing?) { + visitModifiableFunction(modifiableFunction) + } + final override fun visitNamedDeclaration(namedDeclaration: FirNamedDeclaration, data: Nothing?) { visitNamedDeclaration(namedDeclaration) } @@ -306,6 +552,14 @@ abstract class FirVisitorVoid : FirVisitor() { visitNamedFunction(namedFunction) } + final override fun visitNamedReference(namedReference: FirNamedReference, data: Nothing?) { + visitNamedReference(namedReference) + } + + final override fun visitOperatorCall(operatorCall: FirOperatorCall, data: Nothing?) { + visitOperatorCall(operatorCall) + } + final override fun visitPackageFragment(packageFragment: FirPackageFragment, data: Nothing?) { visitPackageFragment(packageFragment) } @@ -318,6 +572,18 @@ abstract class FirVisitorVoid : FirVisitor() { visitPropertyAccessor(propertyAccessor) } + final override fun visitPropertyAssignment(propertyAssignment: FirPropertyAssignment, data: Nothing?) { + visitPropertyAssignment(propertyAssignment) + } + + final override fun visitReference(reference: FirReference, data: Nothing?) { + visitReference(reference) + } + + final override fun visitRegularClass(regularClass: FirRegularClass, data: Nothing?) { + visitRegularClass(regularClass) + } + final override fun visitResolvedDeclarationStatus(resolvedDeclarationStatus: FirResolvedDeclarationStatus, data: Nothing?) { visitResolvedDeclarationStatus(resolvedDeclarationStatus) } @@ -334,6 +600,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitResolvedType(resolvedType) } + final override fun visitReturnExpression(returnExpression: FirReturnExpression, data: Nothing?) { + visitReturnExpression(returnExpression) + } + final override fun visitStarProjection(starProjection: FirStarProjection, data: Nothing?) { visitStarProjection(starProjection) } @@ -342,6 +612,26 @@ abstract class FirVisitorVoid : FirVisitor() { visitStatement(statement) } + final override fun visitSuperReference(superReference: FirSuperReference, data: Nothing?) { + visitSuperReference(superReference) + } + + final override fun visitTargetElement(targetElement: FirTargetElement, data: Nothing?) { + visitTargetElement(targetElement) + } + + final override fun visitThisReference(thisReference: FirThisReference, data: Nothing?) { + visitThisReference(thisReference) + } + + final override fun visitThrowExpression(throwExpression: FirThrowExpression, data: Nothing?) { + visitThrowExpression(throwExpression) + } + + final override fun visitTryExpression(tryExpression: FirTryExpression, data: Nothing?) { + visitTryExpression(tryExpression) + } + final override fun visitType(type: FirType, data: Nothing?) { visitType(type) } @@ -350,6 +640,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitTypeAlias(typeAlias) } + final override fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: Nothing?) { + visitTypeOperatorCall(typeOperatorCall) + } + final override fun visitTypeParameter(typeParameter: FirTypeParameter, data: Nothing?) { visitTypeParameter(typeParameter) } @@ -382,6 +676,18 @@ abstract class FirVisitorVoid : FirVisitor() { visitVariable(variable) } + final override fun visitWhenBranch(whenBranch: FirWhenBranch, data: Nothing?) { + visitWhenBranch(whenBranch) + } + + final override fun visitWhenExpression(whenExpression: FirWhenExpression, data: Nothing?) { + visitWhenExpression(whenExpression) + } + + final override fun visitWhileLoop(whileLoop: FirWhileLoop, data: Nothing?) { + visitWhileLoop(whileLoop) + } + final override fun visitElement(element: FirElement, data: Nothing?) { visitElement(element) } diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/constants/evaluate/ParseUtils.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/constants/evaluate/ParseUtils.kt new file mode 100644 index 00000000000..6e1d64c9e44 --- /dev/null +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/constants/evaluate/ParseUtils.kt @@ -0,0 +1,96 @@ +/* + * 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.resolve.constants.evaluate + +import com.intellij.psi.tree.IElementType +import com.intellij.util.text.LiteralFormatUtil +import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.utils.extractRadix + +fun hasLongSuffix(text: String) = text.endsWith('l') || text.endsWith('L') +fun hasUnsignedSuffix(text: String) = text.endsWith('u') || text.endsWith('U') +fun hasUnsignedLongSuffix(text: String) = + text.endsWith("ul") || text.endsWith("uL") || + text.endsWith("Ul") || text.endsWith("UL") + +fun parseNumericLiteral(text: String, type: IElementType): Number? { + val canonicalText = LiteralFormatUtil.removeUnderscores(text) + return when (type) { + KtNodeTypes.INTEGER_CONSTANT -> parseLong(canonicalText) + KtNodeTypes.FLOAT_CONSTANT -> parseFloatingLiteral(canonicalText) + else -> null + } +} + +private fun parseLong(text: String): Long? { + fun String.removeSuffix(i: Int): String = this.substring(0, this.length - i) + + return try { + val isUnsigned: Boolean + val numberWithoutSuffix: String + when { + hasUnsignedLongSuffix(text) -> { + isUnsigned = true + numberWithoutSuffix = text.removeSuffix(2) + } + hasUnsignedSuffix(text) -> { + isUnsigned = true + numberWithoutSuffix = text.removeSuffix(1) + } + hasLongSuffix(text) -> { + isUnsigned = false + numberWithoutSuffix = text.removeSuffix(1) + } + else -> { + isUnsigned = false + numberWithoutSuffix = text + } + } + + val (number, radix) = extractRadix(numberWithoutSuffix) + + if (isUnsigned) { + java.lang.Long.parseUnsignedLong(number, radix) + } else { + java.lang.Long.parseLong(number, radix) + } + } catch (e: NumberFormatException) { + null + } +} + +private fun parseFloatingLiteral(text: String): Number? { + if (text.toLowerCase().endsWith('f')) { + return parseFloat(text) + } + return parseDouble(text) +} + +private fun parseDouble(text: String): Double? { + try { + return java.lang.Double.parseDouble(text) + } catch (e: NumberFormatException) { + return null + } +} + +private fun parseFloat(text: String): Float? { + try { + return java.lang.Float.parseFloat(text) + } catch (e: NumberFormatException) { + return null + } +} + +fun parseBoolean(text: String): Boolean { + if ("true".equals(text)) { + return true + } else if ("false".equals(text)) { + return false + } + + throw IllegalStateException("Must not happen. A boolean literal has text: " + text) +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index f2ae5944822..5ca4badbdf7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -6,10 +6,8 @@ package org.jetbrains.kotlin.resolve.constants.evaluate import com.intellij.openapi.project.Project -import com.intellij.psi.tree.IElementType import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.TypeConversionUtil -import com.intellij.util.text.LiteralFormatUtil import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.UnsignedTypes @@ -40,7 +38,6 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.util.OperatorNameConventions -import org.jetbrains.kotlin.utils.extractRadix import java.math.BigInteger import java.util.* @@ -1054,92 +1051,6 @@ private class ConstantExpressionEvaluatorVisitor( ) } -private fun hasLongSuffix(text: String) = text.endsWith('l') || text.endsWith('L') -private fun hasUnsignedSuffix(text: String) = text.endsWith('u') || text.endsWith('U') -private fun hasUnsignedLongSuffix(text: String) = - text.endsWith("ul") || text.endsWith("uL") || - text.endsWith("Ul") || text.endsWith("UL") - -private fun parseNumericLiteral(text: String, type: IElementType): Any? { - val canonicalText = LiteralFormatUtil.removeUnderscores(text) - return when (type) { - KtNodeTypes.INTEGER_CONSTANT -> parseLong(canonicalText) - KtNodeTypes.FLOAT_CONSTANT -> parseFloatingLiteral(canonicalText) - else -> null - } -} - -private fun parseLong(text: String): Long? { - fun String.removeSuffix(i: Int): String = this.substring(0, this.length - i) - - return try { - val isUnsigned: Boolean - val numberWithoutSuffix: String - when { - hasUnsignedLongSuffix(text) -> { - isUnsigned = true - numberWithoutSuffix = text.removeSuffix(2) - } - hasUnsignedSuffix(text) -> { - isUnsigned = true - numberWithoutSuffix = text.removeSuffix(1) - } - hasLongSuffix(text) -> { - isUnsigned = false - numberWithoutSuffix = text.removeSuffix(1) - } - else -> { - isUnsigned = false - numberWithoutSuffix = text - } - } - - val (number, radix) = extractRadix(numberWithoutSuffix) - - if (isUnsigned) { - java.lang.Long.parseUnsignedLong(number, radix) - } else { - java.lang.Long.parseLong(number, radix) - } - } catch (e: NumberFormatException) { - null - } -} - -private fun parseFloatingLiteral(text: String): Any? { - if (text.toLowerCase().endsWith('f')) { - return parseFloat(text) - } - return parseDouble(text) -} - -private fun parseDouble(text: String): Double? { - try { - return java.lang.Double.parseDouble(text) - } catch (e: NumberFormatException) { - return null - } -} - -private fun parseFloat(text: String): Float? { - try { - return java.lang.Float.parseFloat(text) - } catch (e: NumberFormatException) { - return null - } -} - -private fun parseBoolean(text: String): Boolean { - if ("true".equals(text)) { - return true - } else if ("false".equals(text)) { - return false - } - - throw IllegalStateException("Must not happen. A boolean literal has text: " + text) -} - - private fun createCompileTimeConstantForEquals(result: Any?, operationReference: KtExpression): ConstantValue<*>? { if (result is Boolean) { assert(operationReference is KtSimpleNameExpression) { "This method should be called only for equals operations" } diff --git a/idea/fir-view/src/FirExplorerToolWindow.kt b/idea/fir-view/src/FirExplorerToolWindow.kt index 63067f249d7..57cb8af9fac 100644 --- a/idea/fir-view/src/FirExplorerToolWindow.kt +++ b/idea/fir-view/src/FirExplorerToolWindow.kt @@ -27,7 +27,6 @@ import com.intellij.ui.treeStructure.SimpleTreeBuilder import com.intellij.ui.treeStructure.SimpleTreeStructure import com.intellij.ui.treeStructure.Tree import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSessionBase import org.jetbrains.kotlin.fir.builder.RawFirBuilder import org.jetbrains.kotlin.idea.util.application.runReadAction @@ -73,7 +72,7 @@ class FirExplorerToolWindow(private val project: Project, private val toolWindow val psiDocumentManager = PsiDocumentManager.getInstance(project) val file = runReadAction { psiDocumentManager.getPsiFile(editor.document) as? KtFile } if (file != null) { - val firFile = runReadAction { RawFirBuilder(object : FirSessionBase() {}).buildFirFile(file) } + val firFile = runReadAction { RawFirBuilder(object : FirSessionBase() {}, stubMode = false).buildFirFile(file) } runInEdt { treeStructure.root = FirExplorerTreeNode("root = ", firFile, null) builder.updateFromRoot(!init) diff --git a/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt b/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt index b3e5c25f76e..154b1b952b1 100644 --- a/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt +++ b/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt @@ -1,4 +1,4 @@ FILE: user.kt public final function foo(hello: R|hello/Hello|): R|kotlin/String| { - STUB + return@@@foo STUB } diff --git a/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt index 4034fd2aced..b7f922f4a20 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt @@ -68,7 +68,7 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() { for (module in project.allModules().drop(1)) { val session = createSession(module, provider) - val builder = RawFirBuilder(session) + val builder = RawFirBuilder(session, stubMode = true) val psiManager = PsiManager.getInstance(project) val ideaModuleInfo = session.moduleInfo.cast()