@@ -0,0 +1,1622 @@
+from itertools import ifilter, islice%0Aimport model%0A%0Adef get_include_deps(include):%0A    return %5B%5D%0A%0Adef get_constant_deps(constant):%0A    return filter(lambda x: not x.isdigit(),%0A                  reduce(lambda x, y: x.replace(y, %22 %22), %22()+-%22, constant.value).split())%0A%0Adef get_typedef_deps(typedef):%0A    return %5Btypedef.type%5D%0A%0Adef get_enum_deps(enum):%0A    return %5B%5D%0A%0Adef get_struct_deps(struct):%0A    return %5Bmember.type for member in struct.members%5D%0A%0Adef get_union_deps(union):%0A    return %5Bmember.type for member in union.members%5D%0A%0Adef get_deps(node):%0A    return deps_visitor%5Btype(node)%5D(node)%0A%0Adeps_visitor = %7Bmodel.Include: get_include_deps,%0A                model.Constant: get_constant_deps,%0A                model.Typedef: get_typedef_deps,%0A                model.Enum: get_enum_deps,%0A                model.Struct: get_struct_deps,%0A                model.Union: get_union_deps%7D%0A%0Adef dependency_sort_rotate(nodes, known, available, index):%0A    node = nodes%5Bindex%5D%0A    for dep in get_deps(node):%0A        if dep not in known and dep in available:%0A            found = next(ifilter(lambda x: x.name == dep, islice(nodes, index + 1, None)))%0A            found_index = nodes.index(found)%0A            nodes.insert(index, nodes.pop(found_index))%0A            return True%0A    known.add(node.name)%0A    return False%0A%0Adef dependency_sort(nodes):%0A    known = set(x + y for x in %22uir%22 for y in %5B%228%22, %2216%22, %2232%22, %2264%22%5D)%0A    available = set(node.name for node in nodes)%0A%0A    index = 0%0A    max_index = len(nodes)%0A%0A    while index %3C max_index:%0A        if not dependency_sort_rotate(nodes, known, available, index):%0A            index = index + 1

add model_dependecy