-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename some internal APIs in preparation for class specialization
Rename 'variant' to 'specialization'. Rename 'BurstRewriter' to 'FunctionSpecializer'. Start adding new declarations in-place, rather than using a mix of side-effects and return values. Use exceptions to report syntax errors.
- Loading branch information
1 parent
2719db0
commit b0958ad
Showing
6 changed files
with
146 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
burst-kotlin-plugin/src/main/kotlin/app/cash/burst/kotlin/Argument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2024 Cash App | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.burst.kotlin | ||
|
||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext | ||
import org.jetbrains.kotlin.ir.IrElement | ||
import org.jetbrains.kotlin.ir.declarations.IrEnumEntry | ||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter | ||
import org.jetbrains.kotlin.ir.expressions.IrExpression | ||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetEnumValueImpl | ||
import org.jetbrains.kotlin.ir.types.IrType | ||
import org.jetbrains.kotlin.ir.types.getClass | ||
import org.jetbrains.kotlin.ir.util.classId | ||
import org.jetbrains.kotlin.ir.util.isEnumClass | ||
|
||
internal class Argument( | ||
private val original: IrElement, | ||
private val type: IrType, | ||
internal val value: IrEnumEntry, | ||
) { | ||
/** Returns an expression that looks up this argument. */ | ||
fun get(): IrExpression { | ||
return IrGetEnumValueImpl(original.startOffset, original.endOffset, type, value.symbol) | ||
} | ||
} | ||
|
||
/** Returns a name like `orderCoffee_Decaf_Oat` with each argument value inline. */ | ||
internal fun name( | ||
prefix: String, | ||
arguments: List<Argument> | ||
): String { | ||
return arguments.joinToString( | ||
prefix = prefix, | ||
separator = "_", | ||
) { argument -> | ||
argument.value.name.identifier | ||
} | ||
} | ||
|
||
/** Returns null if we can't compute all possible arguments for this parameter. */ | ||
internal fun IrPluginContext.allPossibleArguments( | ||
parameter: IrValueParameter | ||
): List<Argument>? { | ||
val classId = parameter.type.getClass()?.classId ?: return null | ||
val referenceClass = referenceClass(classId)?.owner ?: return null | ||
if (!referenceClass.isEnumClass) return null | ||
val enumEntries = referenceClass.declarations.filterIsInstance<IrEnumEntry>() | ||
return enumEntries.map { Argument(parameter, parameter.type, it) } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.