There are a few resources on the web that are instructive in writing Scala compiler plugins that pattern-match against the code, but these don't help in generating code (constructing symbol trees). Where should I start to figure out how to do this? (If there's an easier way than to manually build symbol trees, I'd be interested as well.)
For instance, I'd like write a plugin that replaces some code with a simple AST for this expression, where the variables (extracted from the original program code) could be of any type:
"" + hello + ", " + world + "!"
I realize this may be tricky because of boxing and toString
, e.g. if
hello
were an object and world
were an int, this should really be
something like:
"".+(hello.toString().+(", ".+(new Integer(world).toString().+("!"))))