简体   繁体   中英

Detect Macro Expansion in Scala AST

I have a compiler plugin that operates after the typer phase. The plugin needs to ignore any code that was generated from a macro. (I am having some problem with range positioning, and the easiest fix I think is to just ignore macro code, I don't need to process it in my plugin anyway).

So, what I would like to do is detect whether some code was macro expanded. Is that possible? Is there some flag hidden in the tree somewhere?

Or alternatively, I would be happy with the ability in a previous phase to detect if some code is going to be macro expanded, and then I could annotate it so I can detect later.

There is a MacroExpansionAttachment .

A sample usage , as I recall.

While waiting for a better solution, my current workaround is to detect any Trees that do not have a range position (I have Yrangepos enabled). This detects generated code, including macros.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM