Edwin Vane | 3bf14ce | 2013-08-22 13:07:14 +0000 | [diff] [blame^] | 1 | //===-- ClangReplaceMain.cpp - Main file for clang-replace tool -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file provides the main function for the clang-replace tool. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "ApplyReplacements.h" |
| 16 | #include "clang/Basic/Diagnostic.h" |
| 17 | #include "clang/Basic/DiagnosticOptions.h" |
| 18 | #include "llvm/Support/CommandLine.h" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | using namespace clang; |
| 22 | using namespace clang::replace; |
| 23 | |
| 24 | static cl::opt<std::string> Directory(cl::Positional, cl::Required, |
| 25 | cl::desc("<Search Root Directory>")); |
| 26 | |
| 27 | int main(int argc, char **argv) { |
| 28 | cl::ParseCommandLineOptions(argc, argv); |
| 29 | |
| 30 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions()); |
| 31 | DiagnosticsEngine Diagnostics( |
| 32 | IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), |
| 33 | DiagOpts.getPtr()); |
| 34 | |
| 35 | TUReplacements TUs; |
| 36 | |
| 37 | error_code ErrorCode = |
| 38 | collectReplacementsFromDirectory(Directory, TUs, Diagnostics); |
| 39 | |
| 40 | if (ErrorCode) { |
| 41 | errs() << "Trouble iterating over directory '" << Directory |
| 42 | << "': " << ErrorCode.message() << "\n"; |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | FileToReplacementsMap GroupedReplacements; |
| 47 | if (mergeAndDeduplicate(TUs, GroupedReplacements, Diagnostics)) |
| 48 | return 0; |
| 49 | return 1; |
| 50 | } |