def get_arguments(cursor: clang.Cursor) -> typing.Generator[clang.Cursor, None, None]: """ Retrieves the argument dependencies from the AST node pointed to by the given cursor. :param cursor: The cursor pointing to the node. :return: The cursors of the nodes of the arguments of the node. """ # If the cursor has arguments, yield them yield from cursor.get_arguments() # If the cursor is an enum, yield all children if cursor.kind == clang.CursorKind.ENUM_DECL: for arg_cursor in cursor.walk_preorder(): yield arg_cursor
def cursors_in_same_file(cursor: Cursor) -> List[Cursor]: """ get all child cursors which are pointing to the same file as the input cursor Args: cursor: cursor of parsing result of target source code by libclang Returns: a list of cursor """ cursors = [] for descendant in cursor.walk_preorder(): # We don't want Cursors from files other than the input file, # otherwise we get definitions for every file included # when clang parsed the input file (i.e. if we don't limit descendant location, # it will check definitions from included headers and get class definitions like std::string) if descendant.location.file is None: continue if descendant.location.file.name != cursor.displayname: continue cursors.append(descendant) return cursors