def _build_tree(file_path, compiler_parameters): file_path = os.path.abspath(file_path) def build_tree_recursive(cursor, parent, access): node = Node(cursor, parent, access) for child in cursor.get_children(): if child.kind == CursorKind.COMPOUND_STMT: # Ignore nodes defining code logic continue if not child.location.file or os.path.abspath( child.location.file.name) != file_path: # Ignore nodes from other files continue child_access = child.access_specifier if child_access == AccessSpecifier.INVALID: child_access = access child_node = build_tree_recursive(child, node, child_access) node.children.append(child_node) assert child_node.parent == node return node index = Index(conf.lib.clang_createIndex(False, True)) translation_unit = index.parse( file_path, compiler_parameters, options=TranslationUnit.PARSE_INCOMPLETE | TranslationUnit.PARSE_SKIP_FUNCTION_BODIES | TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION) return build_tree_recursive(translation_unit.cursor, None, AccessSpecifier.NONE)