Extract functions as separate files from c/c++ files
Install clang from the instructions here
Create a new folder clang-split-function inside folder llvm-project/clang/tools/
and put the provided CMakeLists.txt and FindFunction.cpp in the new
folder. Edit llvm-project/clang/tools/CMakeLists.txt and add the following content into the file.
add_clang_subdirectory(clang-split-function)Return to the llvm-project/build folder and run make. After it finishes, you can test the example tool by running the following command.
clang-split-function anyfile.c/cpppython3 splitFunctions.py <source_file_dir>The output of splitFunctions.py is a json file containing the path for all available functions.
- Clang Tutorial: Finding declarations. https://xinhuang.github.io/posts/2014-10-19-clang-tutorial-finding-declarations.html
- clang-tutorial. https://github.com/loarabia/Clang-tutorial
- How to write RecursiveASTVisitor based ASTFrontendActions. https://clang.llvm.org/docs/RAVFrontendAction.html