Automatic C++ source code generation with clang
summary
Shows how to write a custom C++ source-generation tool using clang 3.9 and its libTooling library to analyze existing code and emit new C++ (examples include enum-to-string converters). Covers building the tool from scratch: argument handling, invoking clang, walking the AST to find targets, producing generated code, and integrating the tool into a CMake build. Uses simple, concrete examples to illustrate the approach.
AI-written summary · about
chapters (12)
- 0:00Start
- 4:59Introduction
- 9:25Brief tour to Clang C++ API - Infrastructure
- 13:08Brief tour to Clang C++ API - AST
- 17:21Brief tour to Clang C++ API - Utilities
- 20:30Generation tool implementation - Enum2 String
- 21:12Generation tool implementation - Preparations
- 28:31Generation tool implementation - AST analysis
- 35:38Generation tool implementation - Generation
- 39:07Generation tool implementation - Build
- 41:11Generation tool usage
- 45:55References
related talks
58mC++ Insights: See your source code with the eyes of a compiler
32mTeaching Old Compilers New Tricks: Transpiling C++17 to C++11
51mCompile-time tools supporting generic programming in C++
01h 01mMake Friends with the Clang Static Analysis Tools
16mTailored static tooling using Clang: Clazy
01h 48m“Meta: Thoughts on generative C++”
46mBuilding a C++ Reflection System in One Weekend Using Clang and LLVM
01h 04mC++ Insights: Peek behind the curtains of your C++ compiler
