Guest User

example1

a guest
Oct 26th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import clang.cindex
  2. from clang.cindex import TranslationUnit
  3. clang.cindex.Config.set_library_path(r"C:\Program Files\LLVM\bin")
  4.  
  5. def get_tu(source):
  6.     return TranslationUnit.from_source('t.cpp', ['-std=c++11'], unsaved_files=[('t.cpp', source)])
  7.  
  8. def print_recursive(node, t=''):
  9.     print(f"{t}{node.displayname} ({node.type.kind})")
  10.     for child_node in list(node.get_children()):
  11.         print_recursive(child_node, t + ' ')
  12.  
  13. # EXAMPLE 1 (Failing) =========================================================
  14. print_recursive(get_tu('''
  15. std::vector<std::vector<int>> example()
  16. {
  17.    return;
  18. }
  19. ''').cursor)
  20.  
  21. print("*" * 100)
  22.  
  23. # EXAMPLE 2 (Working) =========================================================
  24. print_recursive(get_tu('''
  25. std::vector<int> example()
  26. {
  27.    return;
  28. }
  29. ''').cursor)
Add Comment
Please, Sign In to add comment