- dep_cnts[name] = len({c.attr('name') for c in childs})
- for child in childs:
- child_name = child.attr('name')
- if child_name not in deps:
- deps[child_name] = set()
- deps[child_name].add(name)
- if child_name not in symbol_map:
- symbol_map[child_name] = child
- queue.append(child)
- order = []
- while dep_cnts:
- remove = []
- for name in dep_cnts:
- if dep_cnts[name] == 0:
- order.append(symbol_map[name])
- remove.append(name)
- if name in deps:
- for other in deps[name]:
- dep_cnts[other] -= 1
- for name in remove:
- del dep_cnts[name]