org.jetbrains.kotlin.contracts.description.KtEffects.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.contracts.description
/**
* Effect with condition attached to it.
*
* [condition] is some expression, which result-type is Boolean, and clause should
* be interpreted as: "if [effect] took place then [condition]-expression is
* guaranteed to be true"
*
* NB. [effect] and [condition] connected with implication in math logic sense:
* [effect] => [condition]. In particular this means that:
* - there can be multiple ways how [effect] can be produced, but for any of them
* [condition] holds.
* - if [effect] wasn't observed, we *can't* reason that [condition] is false
* - if [condition] is true, we *can't* reason that [effect] will be observed.
*/
class KtConditionalEffectDeclaration(
val effect: KtEffectDeclaration,
val condition: KtBooleanExpression
) : KtEffectDeclaration() {
override val erroneous: Boolean
get() = effect.erroneous || condition.erroneous
override fun accept(contractDescriptionVisitor: KtContractDescriptionVisitor, data: D): R =
contractDescriptionVisitor.visitConditionalEffectDeclaration(this, data)
}
/**
* Effect which specifies that subroutine returns some particular value
*/
class KtReturnsEffectDeclaration(val value: KtConstantReference) :
KtEffectDeclaration() {
override val erroneous: Boolean
get() = value.erroneous
override fun accept(contractDescriptionVisitor: KtContractDescriptionVisitor, data: D): R =
contractDescriptionVisitor.visitReturnsEffectDeclaration(this, data)
}
/**
* Effect which specifies, that during execution of subroutine, callable [valueParameterReference] will be invoked
* [kind] amount of times, and will never be invoked after subroutine call is finished.
*/
open class KtCallsEffectDeclaration(
val valueParameterReference: KtValueParameterReference,
val kind: EventOccurrencesRange
) : KtEffectDeclaration() {
override val erroneous: Boolean
get() = valueParameterReference.erroneous
override fun accept(contractDescriptionVisitor: KtContractDescriptionVisitor, data: D): R =
contractDescriptionVisitor.visitCallsEffectDeclaration(this, data)
}
class KtErroneousCallsEffectDeclaration(
valueParameterReference: KtValueParameterReference,
val diagnostic: Diagnostic
) : KtCallsEffectDeclaration(valueParameterReference, EventOccurrencesRange.UNKNOWN) {
override val erroneous: Boolean
get() = true
override fun accept(contractDescriptionVisitor: KtContractDescriptionVisitor, data: D): R =
contractDescriptionVisitor.visitErroneousCallsEffectDeclaration(this, data)
}