def get_outline(libclang, translation_unit, contents):
    root_cursor = translation_unit.cursor
    callback_type = ctypes.CFUNCTYPE(ctypes.c_int, Cursor, Cursor, ctypes.py_object)

    def visitor(child, parent, result):
        child._tu = translation_unit
        child_outline = visit_cursor(libclang, child)
        if (child_outline is not None):
            result.append(child_outline)
        return 1
    result = []
    libclang.clang_visitChildren(root_cursor, callback_type(visitor), result)
    line = 0
    lastpos = 0
    pragma_marks = []
    for mark in PRAGMA_MARK_REGEX.finditer(contents):
        while (lastpos < mark.start()):
            if (contents[lastpos] == '\n'):
                line += 1
            lastpos += 1
        pragma_marks.append({'name': mark.group(1), 'cursor_kind': 'PRAGMA_MARK', 'extent': {'start': {'row': line, 'column': 0}, 'end': {'row': (line + 1), 'column': 0}}})
    result = sorted(result, key=(lambda x: (x['extent']['start']['row'], x['extent']['start']['column'], x['extent']['end']['row'], x['extent']['end']['column'])))
    pragma_marks.reverse()
    return insert_pragma_marks(pragma_marks, result)
def get_outline(libclang, translation_unit, contents):
    root_cursor = translation_unit.cursor
    callback_type = ctypes.CFUNCTYPE(ctypes.c_int, Cursor, Cursor, ctypes.py_object)

    def visitor(child, parent, result):
        child._tu = translation_unit
        child_outline = visit_cursor(libclang, child)
        if (child_outline is not None):
            result.append(child_outline)
        return 1
    result = []
    libclang.clang_visitChildren(root_cursor, callback_type(visitor), result)
    line = 0
    lastpos = 0
    pragma_marks = []
    for mark in PRAGMA_MARK_REGEX.finditer(contents):
        while (lastpos < mark.start()):
            if (contents[lastpos] == '\n'):
                line += 1
            lastpos += 1
        pragma_marks.append({'name': mark.group(1), 'cursor_kind': 'PRAGMA_MARK', 'extent': {'start': {'row': line, 'column': 0}, 'end': {'row': (line + 1), 'column': 0}}})
    result = sorted(result, key=(lambda x: (x['extent']['start']['row'], x['extent']['start']['column'], x['extent']['end']['row'], x['extent']['end']['column'])))
    pragma_marks.reverse()
    return insert_pragma_marks(pragma_marks, result)