it.unibo.collektive.utils.stack.StackFunctionCall.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler-plugin Show documentation
Show all versions of compiler-plugin Show documentation
A Kotlin compiler plugin performing transparent aggregate alignment
The newest version!
package it.unibo.collektive.utils.stack
/**
* A stack that keeps track of the function calls in the code.
*/
class StackFunctionCall {
private val stack = ArrayDeque()
private val occurrences = mutableMapOf()
/**
* Pushes a new function call to the stack.
*/
fun push(name: String) {
val counter = occurrences[name]?.let { it + 1 } ?: 1
occurrences[name] = counter
val candidateToken = "$name.$counter"
stack.addFirst(candidateToken)
}
/**
* Pops the last function call from the stack.
*/
fun pop(): String? = stack.removeFirstOrNull()
override fun toString(): String = stack.joinToString(separator = ",")
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy