[][src]Module c2rust_refactor::collapse

Macro collapsing - the opposite of macro expansion.

There are four ASTs we care about:

  1. Unexpanded: the original AST before macro expansion
  2. Expanded: the immediate result of macro expansion, with no further edits
  3. Transformed: the result of applying an arbitrary AST transformation to expanded
  4. Collapsed: transformed, but with macro-generated code turned back into macro invocations

The general idea here is to compute some kind of delta between unexpanded and expanded, then apply that in reverse to turn transformed into collapsed, with some adjustments so we don't lose all the changes that were made to turn expanded into transformed.

Though most of the code and comments talk about "macros", we really mean everything that gets processed during macro expansion, which includes regular macros, proc macros (format!, etc.), certain attributes (#[derive], #[cfg]), and std/prelude injection.

Structs

CollapseInfo
MacInfo
MacTable

Functions

collapse_injected

Reverse the effect of std/prelude injection, by deleting the injected items.

collapse_macros
collect_cfg_attrs
collect_deleted_nodes

Collect info on all nodes deleted from (unexpanded) krate by macro expansion.

collect_macro_invocations
match_nonterminal_ids

Match up IDs of pre-expansion Nonterminal tokens with post-expansion AST nodes. Matching is performed by first checking for equal spans and then by comparing with ast_equiv. This can match multiple new IDs to a single old ID.

restore_cfg_attrs
restore_deleted_nodes

Restore deleted nodes into the collapsed krate.