Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::map<std::string, std::set<std::string>> funcs;
- CXChildVisitResult visitor(CXCursor cursor, CXCursor, CXClientData) {
- CXCursorKind kind = clang_getCursorKind(cursor);
- if (kind == CXCursorKind::CXCursor_FunctionDecl) {
- std::string _namespace = std::string(clang_getCString(clang_getCursorDisplayName(clang_getCursorSemanticParent(cursor))));
- std::string _function = std::string(clang_getCString(clang_getCursorDisplayName(cursor)));
- funcs[_namespace].emplace(_function);
- }
- return CXChildVisit_Recurse;
- }
- int main(int argc, char **argv) {
- if (argc < 2) {
- return 1;
- }
- // Command line arguments required for parsing the TU
- constexpr const char *ARGUMENTS[] = {};
- // Create an index with excludeDeclsFromPCH = 1, displayDiagnostics = 0
- CXIndex index = clang_createIndex(1, 0);
- // Speed up parsing by skipping function bodies
- CXTranslationUnit translationUnit = clang_parseTranslationUnit(
- index, argv[1], ARGUMENTS, std::extent<decltype(ARGUMENTS)>::value,
- nullptr, 0, CXTranslationUnit_SkipFunctionBodies);
- // Visit all the nodes in the AST
- CXCursor cursor = clang_getTranslationUnitCursor(translationUnit);
- clang_visitChildren(cursor, visitor, 0);
- // Release memory
- clang_disposeTranslationUnit(translationUnit);
- clang_disposeIndex(index);
- for (auto n : funcs) {
- std::cout << "namespace: " << n.first << std::endl;
- for (auto f : n.second) {
- std::cout << " " << f << std::endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement