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" |
Edwin Vane | 1106ef2 | 2013-08-22 13:40:32 +0000 | [diff] [blame^] | 18 | #include "clang/Basic/SourceManager.h" |
Edwin Vane | 3bf14ce | 2013-08-22 13:07:14 +0000 | [diff] [blame] | 19 | #include "llvm/Support/CommandLine.h" |
| 20 | |
| 21 | using namespace llvm; |
| 22 | using namespace clang; |
| 23 | using namespace clang::replace; |
| 24 | |
| 25 | static cl::opt<std::string> Directory(cl::Positional, cl::Required, |
| 26 | cl::desc("<Search Root Directory>")); |
| 27 | |
| 28 | int main(int argc, char **argv) { |
| 29 | cl::ParseCommandLineOptions(argc, argv); |
| 30 | |
| 31 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions()); |
| 32 | DiagnosticsEngine Diagnostics( |
| 33 | IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), |
| 34 | DiagOpts.getPtr()); |
| 35 | |
| 36 | TUReplacements TUs; |
| 37 | |
| 38 | error_code ErrorCode = |
| 39 | collectReplacementsFromDirectory(Directory, TUs, Diagnostics); |
| 40 | |
| 41 | if (ErrorCode) { |
| 42 | errs() << "Trouble iterating over directory '" << Directory |
| 43 | << "': " << ErrorCode.message() << "\n"; |
| 44 | return false; |
| 45 | } |
| 46 | |
Edwin Vane | 1106ef2 | 2013-08-22 13:40:32 +0000 | [diff] [blame^] | 47 | FileManager Files((FileSystemOptions())); |
| 48 | SourceManager SM(Diagnostics, Files); |
| 49 | |
Edwin Vane | 3bf14ce | 2013-08-22 13:07:14 +0000 | [diff] [blame] | 50 | FileToReplacementsMap GroupedReplacements; |
Edwin Vane | 1106ef2 | 2013-08-22 13:40:32 +0000 | [diff] [blame^] | 51 | if (!mergeAndDeduplicate(TUs, GroupedReplacements, SM)) |
| 52 | return 1; |
| 53 | |
| 54 | if (!applyReplacements(GroupedReplacements, SM)) |
| 55 | return 1; |
Edwin Vane | 3bf14ce | 2013-08-22 13:07:14 +0000 | [diff] [blame] | 56 | } |