Example #1
0
Error DiffStyle::diffStreamDirectory() {
  DiffPrinter D(2, "Stream Directory", 30, 20, opts::diff::PrintResultColumn,
                opts::diff::PrintValueColumns, outs());
  D.printExplicit("File", DiffResult::UNSPECIFIED,
                  truncateStringFront(File1.getFilePath(), 18),
                  truncateStringFront(File2.getFilePath(), 18));

  SmallVector<StreamInfo, 32> P;
  SmallVector<StreamInfo, 32> Q;
  discoverStreamPurposes(File1, P);
  discoverStreamPurposes(File2, Q);
  D.print("Stream Count", File1.getNumStreams(), File2.getNumStreams());
  auto PI = to_vector<32>(enumerate(P));
  auto QI = to_vector<32>(enumerate(Q));

  // Scan all streams in the left hand side, looking for ones that are also
  // in the right.  Each time we find one, remove it.  When we're done, Q
  // should contain all the streams that are in the right but not in the left.
  StreamPurposeProvider StreamProvider(28);
  for (const auto &P : PI) {
    typedef decltype(PI) ContainerType;
    typedef typename ContainerType::value_type value_type;

    auto Iter = llvm::find_if(QI, [P, &StreamProvider](const value_type &V) {
      DiffResult Result = StreamProvider.compare(P.value(), V.value());
      return Result == DiffResult::EQUIVALENT ||
             Result == DiffResult::IDENTICAL;
    });

    if (Iter == QI.end()) {
      D.printExplicit(StreamProvider.format(P.value(), false),
                      DiffResult::DIFFERENT, P.index(), "(not present)");
      continue;
    }

    D.print<EquivalentDiffProvider>(StreamProvider.format(P.value(), false),
                                    P.index(), Iter->index());
    QI.erase(Iter);
  }

  for (const auto &Q : QI) {
    D.printExplicit(StreamProvider.format(Q.value(), true),
                    DiffResult::DIFFERENT, "(not present)", Q.index());
  }

  return Error::success();
}