Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import clang.cindex
- from clang.cindex import TranslationUnit
- # Windows
- # clang.cindex.Config.set_library_path(r"C:\Program Files\LLVM\bin")
- #
- # Linux
- clang.cindex.Config.set_library_path(r"/partition1/miniconda3/pkgs/clangdev-5.0.0-default_0/lib/")
- def get_tu(source):
- return TranslationUnit.from_source('t.cpp', ['-std=c++11'], unsaved_files=[('t.cpp', source)])
- def print_recursive(node, t=''):
- print(f"{t}{node.displayname} ({node.type.kind})")
- for child_node in list(node.get_children()):
- print_recursive(child_node, t + ' ')
- # EXAMPLE 1 (Failing) =========================================================
- print_recursive(get_tu('''
- #include <vector>
- std::vector<std::vector<int>> example()
- {
- return;
- }
- ''').cursor)
- print("*" * 100)
- # EXAMPLE 2 (Working) =========================================================
- print_recursive(get_tu('''
- #include <vector>
- std::vector<int> example()
- {
- return;
- }
- ''').cursor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement