Introducing new tool clang-replace

Introducing new tool 'clang-replace' that finds files containing
serialized Replacements and applies those changes after deduplication
and detecting conflicts.

Currently the tool does not apply changes. It stops just after the
deduplication and conflict report phase. Forthcoming patches will
complete functionality.

Both build systems updated for new tool.

Includes a conflict test case.

clang-replace added to Doxygen build.

Differential Revision: http://llvm-reviews.chandlerc.com/D1424

llvm-svn: 189008
diff --git a/clang-tools-extra/clang-replace/tool/ClangReplaceMain.cpp b/clang-tools-extra/clang-replace/tool/ClangReplaceMain.cpp
new file mode 100644
index 0000000..f085ed8
--- /dev/null
+++ b/clang-tools-extra/clang-replace/tool/ClangReplaceMain.cpp
@@ -0,0 +1,50 @@
+//===-- ClangReplaceMain.cpp - Main file for clang-replace tool -----------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file provides the main function for the clang-replace tool.
+///
+//===----------------------------------------------------------------------===//
+
+#include "ApplyReplacements.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace clang::replace;
+
+static cl::opt<std::string> Directory(cl::Positional, cl::Required,
+                                      cl::desc("<Search Root Directory>"));
+
+int main(int argc, char **argv) {
+  cl::ParseCommandLineOptions(argc, argv);
+
+  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
+  DiagnosticsEngine Diagnostics(
+      IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()),
+      DiagOpts.getPtr());
+
+  TUReplacements TUs;
+
+  error_code ErrorCode =
+      collectReplacementsFromDirectory(Directory, TUs, Diagnostics);
+
+  if (ErrorCode) {
+    errs() << "Trouble iterating over directory '" << Directory
+           << "': " << ErrorCode.message() << "\n";
+    return false;
+  }
+
+  FileToReplacementsMap GroupedReplacements;
+  if (mergeAndDeduplicate(TUs, GroupedReplacements, Diagnostics))
+    return 0;
+  return 1;
+}