class TopoSorter {
  /** Actually perform the topological sort on the PAG. */
  public void sort() {<FILL_FUNCTION_BODY>}

  public TopoSorter(PAG pag, boolean ignoreTypes) {
    this.pag = pag;
    this.ignoreTypes = ignoreTypes;
    // this.visited = new NumberedSet( pag.getVarNodeNumberer() );
    this.visited = new HashSet<VarNode>();
  }

  /* End of public methods. */
  /* End of package methods. */

  protected boolean ignoreTypes;
  protected PAG pag;
  protected int nextFinishNumber = 1;
  protected HashSet<VarNode> visited;

  protected void dfsVisit(VarNode n) {
    if (visited.contains(n)) {
      return;
    }
    List<VarNode> stack = new ArrayList<>();
    List<VarNode> all = new ArrayList<>();
    stack.add(n);
    while (!stack.isEmpty()) {
      VarNode s = stack.remove(stack.size() - 1);
      if (visited.add(s)) {
        all.add(s);
        Node[] succs = pag.simpleLookup(s);
        for (Node element : succs) {
          if (ignoreTypes || pag.getTypeManager().castNeverFails(n.getType(), element.getType())) {
            stack.add((VarNode) element);
          }
        }
      }
    }
    for (int i = all.size() - 1; i >= 0; i--) {
      all.get(i).setFinishingNumber(nextFinishNumber++);
    }
  }
}

    for (VarNode v : pag.getVarNodeNumberer()) {
      dfsVisit(v);
    }
    visited = null;
  
<no_super_class>