You’ve asked many variations of this question, and you haven’t gotten an answer because it isn’t a standard thing to do, and there’s an enormous amount of “it depends”. In traditional Scala 2, for example, it’s meaningless to talk about “the syntax tree of a compiled source”, because Scala 2 (until recently) compiles to JVM bytecode, and that’s the level you would need to instrument. In Scala 3, you could in principle modify the TASTy files, but it’s very hard to say whether that fits your problem, since you haven’t given much information.
As someone mentioned a while ago, this just plain isn’t the way that you would normally do this in Scala. Typically, you would instead write a function that wraps around
! and does the extra stuff before calling it, and call that instead, which doesn’t require any fancy features. If that’s insufficient, then you have a real research project, and the right solution is going to depend on the details of what you are trying to do – there probably aren’t any answers that are both general and correct.