Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. std::map<std::string, std::set<std::string>> funcs;
  2.  
  3.  
  4. CXChildVisitResult visitor(CXCursor cursor, CXCursor, CXClientData) {
  5. CXCursorKind kind = clang_getCursorKind(cursor);
  6.  
  7. if (kind == CXCursorKind::CXCursor_FunctionDecl) {
  8. std::string _namespace = std::string(clang_getCString(clang_getCursorDisplayName(clang_getCursorSemanticParent(cursor))));
  9. std::string _function = std::string(clang_getCString(clang_getCursorDisplayName(cursor)));
  10.  
  11. funcs[_namespace].emplace(_function);
  12.  
  13. }
  14.  
  15. return CXChildVisit_Recurse;
  16. }
  17.  
  18. int main(int argc, char **argv) {
  19. if (argc < 2) {
  20. return 1;
  21. }
  22.  
  23. // Command line arguments required for parsing the TU
  24. constexpr const char *ARGUMENTS[] = {};
  25.  
  26. // Create an index with excludeDeclsFromPCH = 1, displayDiagnostics = 0
  27. CXIndex index = clang_createIndex(1, 0);
  28.  
  29. // Speed up parsing by skipping function bodies
  30. CXTranslationUnit translationUnit = clang_parseTranslationUnit(
  31. index, argv[1], ARGUMENTS, std::extent<decltype(ARGUMENTS)>::value,
  32. nullptr, 0, CXTranslationUnit_SkipFunctionBodies);
  33.  
  34. // Visit all the nodes in the AST
  35. CXCursor cursor = clang_getTranslationUnitCursor(translationUnit);
  36. clang_visitChildren(cursor, visitor, 0);
  37.  
  38. // Release memory
  39. clang_disposeTranslationUnit(translationUnit);
  40. clang_disposeIndex(index);
  41.  
  42. for (auto n : funcs) {
  43. std::cout << "namespace: " << n.first << std::endl;
  44. for (auto f : n.second) {
  45. std::cout << " " << f << std::endl;
  46. }
  47. }
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement