Advertisement
Guest User

python-clang test 2

a guest
Oct 28th, 2018
110
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. std::vector<std::vector<int> > example()
  21. {
  22.   return;
  23. }
  24. ''').cursor)
  25.  
  26. print("*" * 100)
  27.  
  28. # EXAMPLE 2 (Working) =========================================================
  29. print_recursive(get_tu('''
  30. std::vector<int> example()
  31. {
  32.   return;
  33. }
  34. ''').cursor)
Advertisement
RAW Paste Data Copied
Advertisement