Shelving for now. Various in-progress attempts all muddled together are at https://github.com/asutherland/mozsearch/tree/expand-macros
The main complication seemed to be that:
- Macro expansion hooks fired prior to the actual work of the expansion.
- The preprocessing record that was potentially supposed to exist no longer existed at the end of the file analysis pass.
- I didn't quite intuitively understand what the sourcemanager was up to.
The branch has some hacks that know how to produce a post-macro expansion pretty print of impacted code, but that doesn't really suffice for our use-cases.
I think a way that might work would basically be to:
- Scan the sourcemanager's data structure for the file and for any line that experienced a macro expansion, emit a new record type that provides the post-expansion version of the line.
- When emitting any token that was also present in macro expansions, provide the post-expansion location(s?) of the token as secondary metadata on the normal records. Right now we normalize to pre-expansion locations (so the argument), but I think we'd want to be able to provide at least clickability even if we can't syntax highlight. (Although we probably could syntax highlight if we view macro expansions as an alternate parse stream. Also, it's probably fine if macro expansion syntax highlighting is super buggy.)
- When rendering to HTML, put the macro expanded lines in collapsible divs with an alternate presentation.