I am writing compiler plugin which adds ability to...
# compiler
f
I am writing compiler plugin which adds ability to get code as string value at runtime, e.g.
codeOf(2 + 2)
should return
2 + 2
. I’m trying to use implementation of
IrElementTransformerVoidWithContext
and
dumpKotlinLike
function to get desired code but
dumpKotlinLike
returns: 1. for
2 + 2
:
2.plus(other = 2)
2. for
{ 2 }
:
Copy code
local fun <anonymous>(): Int {
  return 2
}
I think that I shouldn’t use IR to get exact code but I don’t know what I can use instead of it. Are there any options?
b
You can get sourceFile path and line and just parse what you need from the string. Should be a lot simpler than trying to deal with ir
Then just do ir replacement