1 //===- ARCMigrate.cpp - Clang-C ARC Migration Library ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the main API hooks in the Clang-C ARC Migration library.
12 //===----------------------------------------------------------------------===//
14 #include "clang-c/Index.h"
17 #include "clang/ARCMigrate/ARCMT.h"
18 #include "clang/Frontend/TextDiagnosticBuffer.h"
19 #include "llvm/Support/FileSystem.h"
21 using namespace clang;
22 using namespace arcmt;
27 std::vector<std::pair<std::string, std::string> > Vec;
30 } // anonymous namespace.
32 //===----------------------------------------------------------------------===//
33 // libClang public APIs.
34 //===----------------------------------------------------------------------===//
38 CXRemapping clang_getRemappings(const char *migrate_dir_path) {
39 bool Logging = ::getenv("LIBCLANG_LOGGING");
41 if (!migrate_dir_path) {
43 llvm::errs() << "clang_getRemappings was called with NULL parameter\n";
48 llvm::sys::fs::exists(migrate_dir_path, exists);
51 llvm::errs() << "Error by clang_getRemappings(\"" << migrate_dir_path
53 llvm::errs() << "\"" << migrate_dir_path << "\" does not exist\n";
58 TextDiagnosticBuffer diagBuffer;
59 OwningPtr<Remap> remap(new Remap());
61 bool err = arcmt::getFileRemappings(remap->Vec, migrate_dir_path,&diagBuffer);
65 llvm::errs() << "Error by clang_getRemappings(\"" << migrate_dir_path
67 for (TextDiagnosticBuffer::const_iterator
68 I = diagBuffer.err_begin(), E = diagBuffer.err_end(); I != E; ++I)
69 llvm::errs() << I->second << '\n';
77 CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
79 bool Logging = ::getenv("LIBCLANG_LOGGING");
81 OwningPtr<Remap> remap(new Remap());
85 llvm::errs() << "clang_getRemappingsFromFileList was called with "
92 llvm::errs() << "clang_getRemappingsFromFileList was called with "
97 TextDiagnosticBuffer diagBuffer;
98 SmallVector<StringRef, 32> Files;
99 for (unsigned i = 0; i != numFiles; ++i)
100 Files.push_back(filePaths[i]);
102 bool err = arcmt::getFileRemappingsFromFileList(remap->Vec, Files,
107 llvm::errs() << "Error by clang_getRemappingsFromFileList\n";
108 for (TextDiagnosticBuffer::const_iterator
109 I = diagBuffer.err_begin(), E = diagBuffer.err_end(); I != E; ++I)
110 llvm::errs() << I->second << '\n';
118 unsigned clang_remap_getNumFiles(CXRemapping map) {
119 return static_cast<Remap *>(map)->Vec.size();
123 void clang_remap_getFilenames(CXRemapping map, unsigned index,
124 CXString *original, CXString *transformed) {
126 *original = cxstring::createCXString(
127 static_cast<Remap *>(map)->Vec[index].first,
128 /*DupString =*/ true);
130 *transformed = cxstring::createCXString(
131 static_cast<Remap *>(map)->Vec[index].second,
132 /*DupString =*/ true);
135 void clang_remap_dispose(CXRemapping map) {
136 delete static_cast<Remap *>(map);