Advertisement
Guest User

python-clang test 3

a guest
Oct 28th, 2018
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import clang.cindex
  2. from clang.cindex import TranslationUnit
  3.  
  4. # Windows
  5. # clang.cindex.Config.set_library_path(r"C:\Program Files\LLVM\bin")
  6. #
  7. # Linux
  8. clang.cindex.Config.set_library_path(r"/partition1/miniconda3/pkgs/clangdev-5.0.0-default_0/lib/")
  9.  
  10. def get_tu(source):
  11.     return TranslationUnit.from_source('t.cpp', ['-std=c++11'], unsaved_files=[('t.cpp', source)])
  12.  
  13. def print_recursive(node, t=''):
  14.     print(f"{t}{node.displayname} ({node.type.kind})")
  15.     for child_node in list(node.get_children()):
  16.         print_recursive(child_node, t + ' ')
  17.  
  18. # EXAMPLE 1 (Failing) =========================================================
  19. print_recursive(get_tu('''
  20. #include <vector>
  21.  
  22. std::vector<std::vector<int>> example()
  23. {
  24.   return;
  25. }
  26. ''').cursor)
  27.  
  28. print("*" * 100)
  29.  
  30. # EXAMPLE 2 (Working) =========================================================
  31. print_recursive(get_tu('''
  32. #include <vector>
  33.  
  34. std::vector<int> example()
  35. {
  36.   return;
  37. }
  38. ''').cursor)
Advertisement
RAW Paste Data Copied
Advertisement