blob: dae4652e9b8cf44638ca23376899853e41d43a53 [file] [log] [blame]
Edwin Vane3bf14ce2013-08-22 13:07:14 +00001//===-- 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 Vane1106ef22013-08-22 13:40:32 +000018#include "clang/Basic/SourceManager.h"
Edwin Vane3bf14ce2013-08-22 13:07:14 +000019#include "llvm/Support/CommandLine.h"
20
21using namespace llvm;
22using namespace clang;
23using namespace clang::replace;
24
25static cl::opt<std::string> Directory(cl::Positional, cl::Required,
26 cl::desc("<Search Root Directory>"));
27
28int 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 Vane1106ef22013-08-22 13:40:32 +000047 FileManager Files((FileSystemOptions()));
48 SourceManager SM(Diagnostics, Files);
49
Edwin Vane3bf14ce2013-08-22 13:07:14 +000050 FileToReplacementsMap GroupedReplacements;
Edwin Vane1106ef22013-08-22 13:40:32 +000051 if (!mergeAndDeduplicate(TUs, GroupedReplacements, SM))
52 return 1;
53
54 if (!applyReplacements(GroupedReplacements, SM))
55 return 1;
Edwin Vane3bf14ce2013-08-22 13:07:14 +000056}