Refactoring Legacy Codebases with LibTooling
summary
Describes using LibTooling with Clang AST matchers to write automated refactors that run on large legacy codebases, including creating a compile_commands database (CMake or Bear), running regressions on open‑source code (~2 million lines in LLVM/Clang) to catalog edge cases, and testing via unit tests plus binary diffing for nonbehavioral changes. Shows a concrete tool that adds const qualifiers to lvalue references by matching AST nodes, emitting replacements, and running multi‑pass or cross‑TU steps; full runs take hours.
AI-written summary · about
chapters (11)
- 0:00Introduction to legacy refactoring
- 1:09What is LibTooling
- 1:52Legacy code challenges
- 3:16Mitigating risk without tests
- 6:10Testing tools on open source
- 7:41Making code Clang-compatible
- 8:48Building your first tool
- 15:12Multi-translation unit changes
- 17:17Atomic vs non-atomic refactoring
- 19:34Tool development workflow
- 20:19Q&A session
related talks
01h 01mHow to Refactor Millions of Line of Code Without Alienating your Colleagues
56mHow to Refactor Millions of Line of Code Without Alienating Colleagues
01h 03mHow to Build Your First C++ Automated Refactoring Tool
49mPets, Cattle and Automatic Clang Operations with C++ Code
01h 00mUsing Clang LibASTMatchers for Compliance in Codebases
59mMechanical C++ Refactoring in the Present and in the Future
29mUsing the Clang developer tools
55mSo, you inherited a large code base...
