AST matcher for C++ #include

32 views Asked by At

Context: I need to write a codegen to add missing dependencies in C++ for multiple files by adding the missing #include "someheader.h". I'm thinking to use AST but I'm new to AST.

Therefore, I'm trying to make it straightforward by creating a matcher to match the #include string and add the new #include line below it. Since all my target files have their own header include, this guarantees at least one #include keyword in the cpp file.

Is the above approach feasible? If so, which matcher should I use? After adding the #include, can I re-use the matcher to find a function declaration and modify its content?

Or if there are better ways to achieve the same result without using AST?

0

There are 0 answers