Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref foundry-rs/foundry#4034. ## Solution solang-parser AST was not sufficient to rename stuff, because it doesn't collect IDs of declarations and we can't match specific identifier to the declaration. Native solc AST gives such ability, so I've implemented native solc AST visitor. The implementation of flattening itself consits of several steps: 1. Find all sources that are needed for target (imports of any depth). 2. Expore ASTs for all sources and find all top-level declarations (contracts, events, structs, etc). 3. Find if any top-level declarations names are same 4. If any duplicates are found, figure out new names for them (e.g. 2 `OracleLike` interfaces become `OracleLike_0` and `OracleLike_1`) 5. Walk AST and find all references to top-level declarations. Replace every reference with declaration name. We should update names even for unchanged declarations to deal with aliased imports. 6. Collect and remove all import directives. 7. Collect and remove all pragmas and license identifiers. This flattener implementation can be a full replacer of the current impl for all cases when source being flattened can be compiled via solc.
- Loading branch information