I have a simple Scala function in which I want to increment a class variable every time a statement is executed.
class C {
var cnt: Int: 0
def fun(): Unit = {
var a: Int = 0
var b: Int = -10
var sum: Int = 0
sum = a + b
return sum
}
}
I want the function to be like this:
class C {
var cnt: Int: 0
def fun(): Unit = {
var a: Int = 0
cnt = cnt + 1
var b: Int = -10
cnt = cnt + 1
var sum: Int = 0
cnt = cnt + 1
sum = a + b
cnt = cnt + 1
return sum
}
}
But doing so at the software level makes the code messy. Can I use bytecode manipulation to implement this or I should intervene in other levels of compilation?